summaryrefslogtreecommitdiff
path: root/src/stage2_real_functions.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/stage2_real_functions.asm')
-rw-r--r--src/stage2_real_functions.asm42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/stage2_real_functions.asm b/src/stage2_real_functions.asm
index f173ca3..1728b1a 100644
--- a/src/stage2_real_functions.asm
+++ b/src/stage2_real_functions.asm
@@ -9,7 +9,7 @@ SECTORS_PER_CYLINDER:
db 0x3F ; detect parameters enters the correct value here (sectors + 1)
; if detection fails, force int13 to read ahead
NOF_HEADS:
- db 0x02 ; number of heads + 1
+ db 0x01 ; number of heads + 1
SECTORS_TO_LOAD:
db NOF_LOAD_SECTORS ; load NOF_LOAD_SECTORS sectors in total
CURRENT_SECTOR:
@@ -49,31 +49,39 @@ detect_disk_geometry:
ret
probe_and_fix_disk_geometry:
- mov cl, 0xff ; from 63 down to 0
+ mov cl, 0x1 ; from 1 to 63
+ mov BYTE [SECTORS_PER_CYLINDER], cl
.loop:
+ mov dl, [BOOT_DRIVE]
mov ah, 0x02 ; read sectors from drive
mov al, 1 ; read 1 sector
+ mov cl, BYTE [SECTORS_PER_CYLINDER]
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
+ jnc .next_sector ; on error, remeber cl being the highest sector
+
+.fix_heads:
+ cmp [NOF_HEADS], BYTE 0 ; 0 heads, the BIOS is playing tricks to us!
+ je .illegal_heads
+ jmp .end
+
+.illegal_heads:
+ mov [NOF_HEADS], BYTE 1
+ jmp .end
+
+.next_sector:
+ mov cl, BYTE [SECTORS_PER_CYLINDER]
+ inc cl ; next sector
+ mov BYTE [SECTORS_PER_CYLINDER], cl
+ cmp cl, 0x40 ; to a max of 63, if so, this is the default
+ jbe .loop
+ jmp .fix_heads
+
+.end:
ret
; read the whole stage2 and kernel from the disk