Annotation of truecrypt/boot/windows/bootsector.asm, 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: .MODEL tiny
        !            10: .386
        !            11: _TEXT SEGMENT
        !            12: 
        !            13: INCLUDE BootDefs.i
        !            14: 
        !            15: ORG 7C00h ; Boot sector offset
        !            16: 
        !            17: TC_PC_MEMORY_SEGMENT_SIZE = 64
        !            18: TC_PC_BASE_MEMORY_SIZE = 640
        !            19: 
        !            20: start:
        !            21:        ; BIOS executes boot sector from 0:7C00 or 7C0:0000 (default CD boot loader address).
        !            22:        ; Far jump to the next instruction ensures the offset matches the ORG directive.
        !            23:        db 0EAh                         ; jmp 0:main
        !            24:        dw main, 0
        !            25: 
        !            26:        db 'TrueCrypt'
        !            27:        
        !            28: main:  
        !            29:        mov ax, cs
        !            30:        mov ds, ax
        !            31:        
        !            32:        lea si, intro_msg
        !            33:        call print
        !            34:        
        !            35:        mov ax, TC_BOOT_LOADER_SEGMENT
        !            36:        mov es, ax ; Default load segment
        !            37:        xor si, si ; Default SP
        !            38: 
        !            39:        ; Check available memory
        !            40:        mov ax, word ptr [ds:413h]
        !            41:        
        !            42:        ; >= 640 KB?
        !            43:        mov bx, TC_PC_BASE_MEMORY_SIZE
        !            44:        cmp ax, bx
        !            45:        jge clear_memory
        !            46: 
        !            47:        ; < required memory?
        !            48:        cmp ax, TC_PC_BASE_MEMORY_SIZE - (TC_PC_MEMORY_SEGMENT_SIZE - TC_BOOT_MEMORY_REQUIRED)
        !            49:        jge s0
        !            50:        
        !            51:        ; Insufficient memory
        !            52:        mov ax, TC_BOOT_LOADER_LOWMEM_SEGMENT
        !            53:        mov es, ax
        !            54:        jmp clear_memory
        !            55:        
        !            56: s0:
        !            57:        ; SP = 0 - ((640 - *0:0413) * 1024)
        !            58:        sub bx, ax
        !            59:        shl bx, 10
        !            60:        sub si, bx
        !            61: 
        !            62:        ; Ensure clear BSS section
        !            63: clear_memory:
        !            64:        xor al, al
        !            65:        mov di, TC_BOOT_LOADER_OFFSET
        !            66:        mov cx, TC_BOOT_MEMORY_REQUIRED * 1024 - 1
        !            67:        rep stosb
        !            68:        
        !            69:        ; Read boot loader
        !            70:        mov bx, TC_BOOT_LOADER_OFFSET
        !            71:        mov ch, 0           ; Cylinder
        !            72:        mov dh, 0           ; Head
        !            73:        mov cl, 2           ; Sector
        !            74:        mov al, TC_BOOT_LOADER_AREA_SECTOR_COUNT - 2
        !            75:                                                ; DL = drive number passed from BIOS
        !            76:        mov ah, 2
        !            77:        int 13h
        !            78:        jnc exec_loader
        !            79:        
        !            80:        lea si, read_error_msg
        !            81:        call print
        !            82:        jmp $
        !            83:        
        !            84:        ; Execute boot loader
        !            85: exec_loader:
        !            86: 
        !            87:        ; DH = boot sector flags
        !            88:        mov dh, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
        !            89:        
        !            90:        mov ax, es
        !            91:        mov ds, ax
        !            92:        cli
        !            93:        mov ss, ax
        !            94:        mov sp, si
        !            95:        sti
        !            96:        
        !            97:        mov word ptr [cs:jump_seg], es
        !            98:        
        !            99:        db 0EAh                          ; jmp TC_BOOT_LOADER_SEGMENT:TC_BOOT_LOADER_OFFSET
        !           100:        dw TC_BOOT_LOADER_OFFSET
        !           101: jump_seg:
        !           102:        dw TC_BOOT_LOADER_SEGMENT
        !           103: 
        !           104:        ; Print string
        !           105: print:
        !           106:        xor bx, bx
        !           107:        mov ah, 0eh
        !           108:        
        !           109: @@:    lodsb
        !           110:        test al, al
        !           111:        jz print_end
        !           112:        
        !           113:        int 10h
        !           114:        jmp @B
        !           115: 
        !           116: print_end:
        !           117:        ret
        !           118:        
        !           119: intro_msg db 13, 10, "TrueCrypt Boot Loader", 13, 10, 0
        !           120: read_error_msg db "Disk read error", 13, 10, 7, 0
        !           121: 
        !           122:        db 508 - ($ - start) dup (0)
        !           123:        dw 0, 0AA55h            ; Boot sector signature
        !           124: 
        !           125: _TEXT ENDS
        !           126: END start

unix.superglobalmegacorp.com

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