Annotation of truecrypt/boot/windows/bootmemory.cpp, revision 1.1.1.4

1.1       root        1: /*
                      2:  Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
                      3: 
1.1.1.4 ! root        4:  Governed by the TrueCrypt License 2.7 the full text of which is contained
1.1       root        5:  in the file License.txt included in TrueCrypt binary and source code
                      6:  distribution packages.
                      7: */
                      8: 
1.1.1.3   root        9: #include "BootDefs.h"
1.1       root       10: #include "BootMemory.h"
                     11: 
                     12: static uint32 MemoryMapContValue;
                     13: 
                     14: static bool GetMemoryMapEntry (BiosMemoryMapEntry &entry)
                     15: {
                     16:        static const uint32 function = 0x0000E820UL;
                     17:        static const uint32 magic = 0x534D4150UL;
                     18:        static const uint32 bufferSize = sizeof (BiosMemoryMapEntry);
                     19: 
                     20:        bool carry = false;
                     21:        uint32 resultMagic;
                     22:        uint32 resultSize;
                     23: 
                     24:        __asm
                     25:        {
1.1.1.3   root       26:                push es
                     27: 
1.1       root       28:                lea di, function
                     29:                TC_ASM_MOV_EAX_DI
                     30:                lea di, MemoryMapContValue
                     31:                TC_ASM_MOV_EBX_DI
                     32:                lea di, bufferSize
                     33:                TC_ASM_MOV_ECX_DI
                     34:                lea di, magic
                     35:                TC_ASM_MOV_EDX_DI
                     36:                lea di, MemoryMapContValue
                     37:                TC_ASM_MOV_DI_ECX
                     38: 
1.1.1.3   root       39:                // Use alternative segment to prevent memory corruption caused by buggy BIOSes
                     40:                push TC_BOOT_LOADER_ALT_SEGMENT
                     41:                pop es
                     42:                mov di, 0
                     43:                
1.1       root       44:                int 0x15
                     45:                jnc no_carry
                     46:                mov carry, true
                     47:        no_carry:
                     48: 
                     49:                lea di, resultMagic
                     50:                TC_ASM_MOV_DI_EAX
                     51:                lea di, MemoryMapContValue
                     52:                TC_ASM_MOV_DI_EBX
                     53:                lea di, resultSize
                     54:                TC_ASM_MOV_DI_ECX
1.1.1.3   root       55: 
                     56:                pop es
1.1       root       57:        }
                     58: 
1.1.1.3   root       59:        CopyMemory (TC_BOOT_LOADER_ALT_SEGMENT, 0, &entry, sizeof (entry));
                     60: 
1.1       root       61:        // BIOS may set CF at the end of the list
                     62:        if (carry)
                     63:                MemoryMapContValue = 0;
                     64: 
                     65:        return resultMagic == magic && resultSize == bufferSize;
                     66: }
                     67: 
                     68: 
                     69: bool GetFirstBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
                     70: {
                     71:        MemoryMapContValue = 0;
                     72:        return GetMemoryMapEntry (entry);
                     73: }
                     74: 
                     75: 
                     76: bool GetNextBiosMemoryMapEntry (BiosMemoryMapEntry &entry)
                     77: {
                     78:        if (MemoryMapContValue == 0)
                     79:                return false;
                     80: 
                     81:        return GetMemoryMapEntry (entry);
                     82: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.