diff options
-rw-r--r-- | src/boot.asm | 2 | ||||
-rw-r--r-- | src/stage2_real_functions.asm | 28 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/boot.asm b/src/boot.asm index b5febd7..73f1214 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -92,6 +92,8 @@ stage2: call print_string mov dl, [BOOT_DRIVE] call detect_disk_geometry + mov dl, [BOOT_DRIVE] + call probe_and_fix_disk_geometry call print_newline ; print a message we are now loading the kernel diff --git a/src/stage2_real_functions.asm b/src/stage2_real_functions.asm index 273d790..f173ca3 100644 --- a/src/stage2_real_functions.asm +++ b/src/stage2_real_functions.asm @@ -48,6 +48,34 @@ detect_disk_geometry: mov [SECTORS_PER_CYLINDER], BYTE cl ret +probe_and_fix_disk_geometry: + mov cl, 0xff ; from 63 down to 0 + +.loop: + mov ah, 0x02 ; read sectors from drive + mov al, 1 ; read 1 sector + mov ch, BYTE 0 + mov dh, BYTE 0 + + int 0x13 + + jc .next_try + ; no errors anymore, so it must be the correct sector + inc cl + mov [SECTORS_PER_CYLINDER], BYTE cl + + mov al, '>' + call print_char + movzx dx, byte [SECTORS_PER_CYLINDER] + call print_hex + + ret + +.next_try: + dec cl ; next sector + jnz .loop + ret + ; read the whole stage2 and kernel from the disk ; IN dl: drive to read from read_from_disk: |