Annotation of truecrypt/boot/windows/platform.cpp, revision 1.1

1.1     ! root        1: /*
        !             2:  Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
        !             3: 
        !             4:  Governed by the TrueCrypt License 2.4 the full text of which is contained
        !             5:  in the file License.txt included in TrueCrypt binary and source code
        !             6:  distribution packages.
        !             7: */
        !             8: 
        !             9: #include "Platform.h"
        !            10: 
        !            11: 
        !            12: uint64 operator+ (const uint64 &a, const uint64 &b)
        !            13: {
        !            14:        int carry = 0;
        !            15:        uint64 r;
        !            16: 
        !            17:        r.LowPart = a.LowPart + b.LowPart;
        !            18:        __asm
        !            19:        {
        !            20:                jnc nocarry
        !            21:                mov carry, 1
        !            22:        nocarry:
        !            23:        }
        !            24: 
        !            25:        r.HighPart = a.HighPart + b.HighPart + carry;
        !            26: 
        !            27:        return r;
        !            28: }
        !            29: 
        !            30: uint64 operator+ (const uint64 &a, uint32 b)
        !            31: {
        !            32:        uint64 b64;
        !            33:        b64.HighPart = 0;
        !            34:        b64.LowPart = b;
        !            35:        return a + b64;
        !            36: }
        !            37: 
        !            38: uint64 operator- (const uint64 &a, const uint64 &b)
        !            39: {
        !            40:        int carry = 0;
        !            41:        uint64 r;
        !            42: 
        !            43:        r.LowPart = a.LowPart - b.LowPart;
        !            44:        __asm
        !            45:        {
        !            46:                jnc nocarry
        !            47:                mov carry, 1
        !            48:        nocarry:
        !            49:        }
        !            50: 
        !            51:        r.HighPart = a.HighPart - b.HighPart - carry;
        !            52: 
        !            53:        return r;
        !            54: }
        !            55: 
        !            56: uint64 operator- (const uint64 &a, uint32 b)
        !            57: {
        !            58:        uint64 b64;
        !            59:        b64.HighPart = 0;
        !            60:        b64.LowPart = b;
        !            61:        return a - b64;
        !            62: }
        !            63: 
        !            64: uint64 operator>> (const uint64 &a, int shiftCount)
        !            65: {
        !            66:        uint64 r = a;
        !            67: 
        !            68:        while (shiftCount--)
        !            69:        {
        !            70:                r.LowPart >>= 1;
        !            71:                
        !            72:                if ((byte) r.HighPart & 1)
        !            73:                        r.LowPart |= 0x80000000UL;
        !            74: 
        !            75:                r.HighPart >>= 1;
        !            76:        }
        !            77: 
        !            78:        return r;
        !            79: }
        !            80: 
        !            81: uint64 operator<< (const uint64 &a, int shiftCount)
        !            82: {
        !            83:        uint64 r = a;
        !            84:        
        !            85:        while (shiftCount--)
        !            86:                r = r + r;
        !            87: 
        !            88:        return r;
        !            89: }
        !            90: 
        !            91: uint64 &operator++ (uint64 &a)
        !            92: {
        !            93:        return a = a + 1;
        !            94: }
        !            95: 
        !            96: bool operator== (const uint64 &a, const uint64 &b)
        !            97: {
        !            98:        return a.HighPart == b.HighPart && a.LowPart == b.LowPart;
        !            99: }
        !           100: 
        !           101: bool operator> (const uint64 &a, const uint64 &b)
        !           102: {
        !           103:        return (a.HighPart > b.HighPart) || (a.HighPart == b.HighPart && a.LowPart > b.LowPart);
        !           104: }
        !           105: 
        !           106: bool operator< (const uint64 &a, const uint64 &b)
        !           107: {
        !           108:        return (a.HighPart < b.HighPart) || (a.HighPart == b.HighPart && a.LowPart < b.LowPart);
        !           109: }
        !           110: 
        !           111: bool operator>= (const uint64 &a, const uint64 &b)
        !           112: {
        !           113:        return a > b || a == b;
        !           114: }
        !           115: 
        !           116: bool operator<= (const uint64 &a, const uint64 &b)
        !           117: {
        !           118:        return a < b || a == b;
        !           119: }
        !           120: 
        !           121: bool TestInt64 ()
        !           122: {
        !           123:        uint64 a, b, c;
        !           124:        a.HighPart = 0x00112233UL;
        !           125:        a.LowPart = 0xabcd1234UL;
        !           126: 
        !           127:        b.HighPart = 0x00ffeeddUL;
        !           128:        b.LowPart = 0xffffFFFFUL;
        !           129: 
        !           130:        ++a;
        !           131:        b = b + (uint32) 1UL;
        !           132: 
        !           133:        c = (a - ((a + b) >> 32) - (uint32) 1UL);
        !           134:        if (c.HighPart != 0x112233UL || c.LowPart != 0xAABC0123UL)
        !           135:                return false;
        !           136: 
        !           137:        c = c << 9;
        !           138:        return c.HighPart == 0x22446755UL && c.LowPart == 0x78024600UL;
        !           139: }
        !           140: 
        !           141: 
        !           142: void Jump (uint16 jumpSegment, uint16 jumpOffset, byte dlRegister)
        !           143: {
        !           144:        uint32 addr = (uint32 (jumpSegment) << 16) | jumpOffset;
        !           145:        __asm
        !           146:        {
        !           147:                mov dl, dlRegister
        !           148:                mov ax, jumpSegment
        !           149:                mov ds, ax
        !           150:                mov es, ax
        !           151:                mov ss, ax
        !           152:                mov sp, 0xffff
        !           153:                jmp cs:addr
        !           154:        }
        !           155: }
        !           156: 
        !           157: 
        !           158: void CopyMemory (byte *source, uint16 destSegment, uint16 destOffset, uint16 blockSize)
        !           159: {
        !           160:        __asm
        !           161:        {
        !           162:                push es
        !           163:                mov si, ss:source
        !           164:                mov es, ss:destSegment
        !           165:                mov di, ss:destOffset
        !           166:                mov cx, ss:blockSize
        !           167:                cld
        !           168:                rep movsb
        !           169:                pop es
        !           170:        }
        !           171: }
        !           172: 
        !           173: 
        !           174: void CopyMemory (uint16 sourceSegment, uint16 sourceOffset, byte *destination, uint16 blockSize)
        !           175: {
        !           176:        __asm
        !           177:        {
        !           178:                push ds
        !           179:                push es
        !           180:                mov ax, ds
        !           181:                mov es, ax
        !           182:                mov di, ss:destination
        !           183:                mov si, ss:sourceOffset
        !           184:                mov cx, ss:blockSize
        !           185:                mov ds, ss:sourceSegment
        !           186:                cld
        !           187:                rep movsb
        !           188:                pop es
        !           189:                pop ds
        !           190:        }
        !           191: }
        !           192: 
        !           193: 
        !           194: uint32 GetLinearAddress (uint16 segment, uint16 offset)
        !           195: {
        !           196:        return (uint32 (segment) << 4) + offset;
        !           197: }

unix.superglobalmegacorp.com

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