"Fossies" - the Fresh Open Source Software Archive

Member "src/Boot/Windows/BootDebug.cpp" (10 Oct 2018, 3023 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "BootDebug.cpp" see the Fossies "Dox" file reference documentation.

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