:: commit b866c3fcad3cfd32f79b58251140c9cb55483747

Mintsuki <mintsuki@protonmail.com> — 2026-03-06 18:09

parents: f30afb3f34

stage1/hdd: Fix stack imbalance on int 13h/AH=48h failure in disk read

diff --git a/stage1/hdd/disk.asm b/stage1/hdd/disk.asm
index 95ac84ed..05a72458 100644
--- a/stage1/hdd/disk.asm
+++ b/stage1/hdd/disk.asm
@@ -18,8 +18,7 @@ read_sectors:
 
     mov si, .da_struct
 
-    mov word  [si],    16
-    mov word  [si+2],  1
+    mov dword [si],    0x00010010
     mov word  [si+4],  bx
     mov word  [si+6],  es
 
@@ -34,11 +33,11 @@ read_sectors:
     mov si, .drive_params
     mov word [si], 30       ; buf_size
     int 0x13
-    jc .done
+    jc .fail
     movzx ebp, word [si+24] ; bytes_per_sect
 
     ; ECX byte count to CX sector count
-    mov ax, cx
+    xchg ax, cx
     shr ecx, 16
     mov dx, cx
     xor cx, cx
@@ -54,10 +53,10 @@ read_sectors:
 
     ; EDX:EAX byte address to 64-bit LBA sector
     push eax
-    mov eax, edx
+    xchg eax, edx
     xor edx, edx
     div ebp
-    mov ebx, eax
+    xchg ebx, eax
     pop eax
     div ebp
     mov dword [si+8],  eax
@@ -78,6 +77,11 @@ read_sectors:
 
     loop .loop
 
+    jmp short .done
+
+  .fail:
+    add sp, 12
+    stc
   .done:
     popa
     ret
tab: 248 wrap: offon