|
|
1.1 root 1: /* 1.1.1.7 ! root 2: Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved. 1.1 root 3: 1.1.1.7 ! root 4: Governed by the TrueCrypt License 2.8 the full text of which is contained in ! 5: the file License.txt included in TrueCrypt binary and source code distribution ! 6: packages. 1.1 root 7: */ 8: 9: #include "Platform.h" 10: #include "Bios.h" 11: #include "BootConsoleIo.h" 1.1.1.2 root 12: #include "BootDefs.h" 1.1 root 13: #include "BootDiskIo.h" 14: #include "BootDebug.h" 15: 16: 1.1.1.2 root 17: #ifdef TC_BOOT_TRACING_ENABLED 18: 1.1 root 19: void InitDebugPort () 20: { 21: __asm 22: { 23: mov dx, TC_DEBUG_PORT 24: mov ah, 1 25: int 0x17 26: mov dx, TC_DEBUG_PORT 27: mov ah, 0xe2 28: int 0x17 29: } 30: } 31: 32: 33: void WriteDebugPort (byte dataByte) 34: { 35: __asm 36: { 37: mov al, dataByte 38: mov dx, TC_DEBUG_PORT 39: mov ah, 0 40: int 0x17 41: } 42: } 43: 1.1.1.2 root 44: #endif // TC_BOOT_TRACING_ENABLED 45: 46: 47: #ifdef TC_BOOT_DEBUG_ENABLED 1.1 root 48: 49: extern "C" void PrintDebug (uint32 debugVal) 50: { 51: Print (debugVal); 52: PrintEndl(); 53: } 54: 55: 56: void PrintVal (const char *message, const uint32 value, bool newLine, bool hex) 57: { 58: Print (message); 59: Print (": "); 60: 61: if (hex) 62: PrintHex (value); 63: else 64: Print (value); 65: 66: if (newLine) 67: PrintEndl(); 68: } 69: 70: 71: void PrintVal (const char *message, const uint64 &value, bool newLine, bool hex) 72: { 73: Print (message); 74: Print (": "); 75: PrintHex (value); 76: if (newLine) 77: PrintEndl(); 78: } 79: 80: 81: void PrintHexDump (byte *mem, size_t size, uint16 *memSegment) 82: { 83: const size_t width = 16; 84: for (size_t pos = 0; pos < size; ) 85: { 86: for (int pass = 1; pass <= 2; ++pass) 87: { 88: size_t i; 89: for (i = 0; i < width && pos < size; ++i) 90: { 91: byte dataByte; 92: if (memSegment) 93: { 94: __asm 95: { 96: push es 97: mov si, ss:memSegment 98: mov es, ss:[si] 99: mov si, ss:mem 100: add si, pos 101: mov al, es:[si] 102: mov dataByte, al 103: pop es 104: } 105: pos++; 106: } 107: else 108: dataByte = mem[pos++]; 109: 110: if (pass == 1) 111: { 112: PrintHex (dataByte); 113: PrintChar (' '); 114: } 115: else 116: PrintChar (IsPrintable (dataByte) ? dataByte : '.'); 117: } 118: 119: if (pass == 1) 120: { 121: pos -= i; 122: PrintChar (' '); 123: } 124: } 125: 126: PrintEndl (); 127: } 128: } 129: 130: 131: void PrintHexDump (uint16 memSegment, uint16 memOffset, size_t size) 132: { 133: PrintHexDump ((byte *) memOffset, size, &memSegment); 134: } 1.1.1.2 root 135: 136: #endif // TC_BOOT_DEBUG_ENABLED 137: 138: 139: #ifdef TC_BOOT_STACK_CHECKING_ENABLED 140: 141: extern "C" char end[]; 142: 143: static void PrintStackInfo () 144: { 145: uint16 spReg; 146: __asm mov spReg, sp 147: 148: Print ("Stack: "); Print (TC_BOOT_LOADER_STACK_TOP - spReg); 149: Print ("/"); Print (TC_BOOT_LOADER_STACK_TOP - (uint16) end); 150: } 151: 152: 153: void CheckStack () 154: { 155: uint16 spReg; 156: __asm mov spReg, sp 157: 158: if (*(uint32 *) end != 0x12345678UL || spReg < (uint16) end) 159: { 160: __asm cli 161: __asm mov sp, TC_BOOT_LOADER_STACK_TOP 162: 163: PrintError ("Stack overflow"); 164: TC_THROW_FATAL_EXCEPTION; 165: } 166: } 167: 168: 169: void InitStackChecker () 170: { 171: *(uint32 *) end = 0x12345678UL; 172: 173: PrintStackInfo(); 174: PrintEndl(); 175: } 176: 177: #endif // TC_BOOT_STACK_CHECKING_ENABLED
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.