VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Boot
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2018-12-02 06:02:42 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2018-12-03 00:51:08 +0100
commit3e1460b61895dc35adb86d36390f3c8722b1f90b (patch)
tree6411f1212a5ed286120f358d06d58bdac33f8439 /src/Boot
parente0049f601aca32e4dd5278d3ebe70d4e031e742f (diff)
downloadVeraCrypt-3e1460b61895dc35adb86d36390f3c8722b1f90b.tar.gz
VeraCrypt-3e1460b61895dc35adb86d36390f3c8722b1f90b.zip
MBR Bootloader: dynamically determine boot loader memory segment instead of hardcoded values (proposed by neos6464 at https://sourceforge.net/p/veracrypt/tickets/240/)
Diffstat (limited to 'src/Boot')
-rw-r--r--src/Boot/Windows/BootSector.asm31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/Boot/Windows/BootSector.asm b/src/Boot/Windows/BootSector.asm
index 33674146..351b2c67 100644
--- a/src/Boot/Windows/BootSector.asm
+++ b/src/Boot/Windows/BootSector.asm
@@ -43,23 +43,24 @@ main:
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