VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Boot/Windows/BootSector.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/Boot/Windows/BootSector.asm')
-rw-r--r--src/Boot/Windows/BootSector.asm35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/Boot/Windows/BootSector.asm b/src/Boot/Windows/BootSector.asm
index 833ff616..0d2bbdca 100644
--- a/src/Boot/Windows/BootSector.asm
+++ b/src/Boot/Windows/BootSector.asm
@@ -3,9 +3,9 @@
; Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
; by the TrueCrypt License 3.0.
;
; Modifications and additions to the original source code (contained in this file)
-; and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+; and all other portions of this file are Copyright (c) 2013-2017 IDRIX
; and are governed by the Apache License 2.0 the full text of which is
; contained in the file License.txt included in VeraCrypt binary and source
; code distribution packages.
;
@@ -42,25 +42,26 @@ main:
lea si, loader_name_msg
call print
skip_loader_name_msg:
- ; Determine boot loader segment
- mov ax, TC_BOOT_LOADER_SEGMENT
-
- ; Check available memory
- cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
- jge memory_ok
-
- mov ax, TC_BOOT_LOADER_SEGMENT_LOW
-
- cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT_LOW / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
- jge memory_ok
-
- ; Insufficient memory
- mov ax, TC_BOOT_LOADER_LOWMEM_SEGMENT
+ ; Determine boot loader segment
+ mov ax, word ptr [ds:413h] ;available kB from BIOS
+ sub ax, TC_BOOT_MEMORY_REQUIRED ;minus TC_BOOT_MEMORY_REQUIRED
+ jc mem_toolow
+ and ax, 0FFE0h ;32K align
+ shl ax, 6 ;convert kB to segment addr (*1024/16)
+ cmp ax, 8000h
+ jb mem_toolow ;we can't load below 8000h
+ cmp ax, TC_BOOT_LOADER_SEGMENT
+ jbe memory_ok ;don't load above TC_BOOT_LOADER_SEGMENT (9000h)
+ mov ax, TC_BOOT_LOADER_SEGMENT
+ jmp memory_ok
+
+mem_toolow:
+ mov ax, TC_BOOT_LOADER_LOWMEM_SEGMENT
memory_ok:
- mov es, ax
+ mov es, ax
; Clear BSS section
xor al, al
mov di, TC_COM_EXECUTABLE_OFFSET
@@ -137,9 +138,9 @@ checksum_ok:
push dx
; Decompress boot loader
- mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
+ mov cx, word ptr cs:[start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
sub cx, TC_GZIP_HEADER_SIZE
push cx ; Compressed data size
push TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET + TC_GZIP_HEADER_SIZE ; Compressed data
push TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE ; Output buffer size