This was done when I realized that not enough space is allocated to load
clusters. The current map is as follows (all numbers in hex):
* 600-800: MBR
* ee00-fe00: stack
* fe00-10000: VBR
* 800-1800: temporary FAT sector
* 10000-18000: temporary cluster
* 1800-fe00: LOADER.BIN
; load the FAT sector we're looking for
push di
push ebx ; offset
; load the FAT sector we're looking for
push di
push ebx ; offset
- push es ; we want to read at 0:1000, not STAGE3_SEGMENT:1000
+ push es ; we want to read at 0:800, not STAGE3_SEGMENT:800
push eax ; desired LBA
xor ax, ax
mov es, ax
pop ebx ; pop LBA into EBX
push eax ; desired LBA
xor ax, ax
mov es, ax
pop ebx ; pop LBA into EBX
mov cx, 1
call read_sectors
cmp dl, 0
mov cx, 1
call read_sectors
cmp dl, 0
mov ds, ax
mov es, ax
mov ss, ax
mov ds, ax
mov es, ax
mov ss, ax
- mov sp, 0x7c00 ; just under the soon-to-be-loaded VBR, should be more than sufficient space
+ mov sp, 0xfe00 ; just under the soon-to-be-loaded VBR, should be more than sufficient space
; perform self-relocation
cld
; perform self-relocation
cld
.load_vbr:
; load active partition's VBR
pop si
.load_vbr:
; load active partition's VBR
pop si
add si, 8
mov edx, [si]
xor bx, bx
call read_sector
; check is the VBR bootable (ends with 0x55 0xaa), if not halt
add si, 8
mov edx, [si]
xor bx, bx
call read_sector
; check is the VBR bootable (ends with 0x55 0xaa), if not halt
- cmp word [0x7dfe], 0xaa55
+ cmp word [0xfffe], 0xaa55
jne .not_bootable
mov dl, [BOOT_DRIVE]
jne .not_bootable
mov dl, [BOOT_DRIVE]
.not_bootable:
mov si, no_os
call print
.not_bootable:
mov si, no_os
call print
%include "../fat32/fat32-structs.s"
%include "../fat32/fat32-structs.s"
.a20_enabled:
print a20_enabled
call get_1st_data_sec
.a20_enabled:
print a20_enabled
call get_1st_data_sec
mov es, ax
mov eax, BPB_RootClus
xor di, di
mov es, ax
mov eax, BPB_RootClus
xor di, di
push es
push ax
xor di, di
push es
push ax
xor di, di
mov es, ax
pop ax
call read_cluster
mov es, ax
pop ax
call read_cluster
push eax
push ebx
push ecx
push eax
push ebx
push ecx
xor ebx, ebx
movzx eax, word BPB_BytsPerSec
movzx bx, byte BPB_SecPerClus
xor ebx, ebx
movzx eax, word BPB_BytsPerSec
movzx bx, byte BPB_SecPerClus
; This is what's going to be on most USB sticks and HDDs, for now
bits 16
; This is what's going to be on most USB sticks and HDDs, for now
bits 16
-STAGE3_ADDRESS equ 0x8000
+STAGE3_ADDRESS equ 0x1800
STAGE3_SEGMENT equ STAGE3_ADDRESS >> 4
STAGE3_OFFSET equ STAGE3_ADDRESS & 0xf
STAGE3_SEGMENT equ STAGE3_ADDRESS >> 4
STAGE3_OFFSET equ STAGE3_ADDRESS & 0xf
real_start:
sti
; no need to set up segments and stack again, because MBR did it for us
real_start:
sti
; no need to set up segments and stack again, because MBR did it for us
; we expect the boot drive to be in DL and our partition table entry in DS:SI
mov [BOOT_DRIVE], dl
; we expect the boot drive to be in DL and our partition table entry in DS:SI
mov [BOOT_DRIVE], dl