在BIOS中断的情况下尝试读取磁盘时发生磁盘错误



我正试图从磁盘读取数据,但我遇到了一个错误:

[org 0x7c00]                ; Offset to the boot sector for NASM
mov [BOOT_DRIVE], dl        ; Remember boot drive
mov bp, 0x8000              ; Set up base of the stack
mov sp, bp                  ; Set up top of the stack
mov bx, 0x0000
mov es, bx
mov bx, 0x9000
mov dh, 5
mov dl, [BOOT_DRIVE]
call disk_load
end:                        ; System end
    jmp end                 ; Endless scrolling
BOOT_DRIVE: db 0
; load DH sectors to ES:BX from drive DL
disk_load:
    pusha
    mov ah, 0x02            ; BIOS read sector
    mov al, dh          ; Read DH sectors
    mov ch, 0x00            ; Cylinder 0
    mov dh, 0x00            ; Head 0
    mov cl, 0x02            ; Sector 2
    int 0x13            ; BIOS read
    jc disk_load_error  ; If error, error <<< this jump happens
    popa
    ret
disk_load_error:
    mov ax, DISK_ERROR
    call print_string
    jmp $
DISK_ERROR: db "Disk error!", 0
; ... utility print procedures omitted
times 510-($-$$) db 0       ; Fitting into 512 bytes
dw 0xaa55                   ; Magic for the BIOS
times 256 dw 0xdada         ; Test data
times 256 dw 0xface         ; Test data

从您的代码中,我看到您考虑了DS=0和SS=0。你确定吗
你为什么不对ES做同样的假设呢?

通过将堆栈设置为0x8000,您只获得512字节的堆栈空间。这可能还不够!大多数BIOS在为您的呼叫提供服务之前不会进行堆栈切换。为什么不使用MOV SP,0x7C00初始化SP
这将消除BIOS覆盖引导扇区的可能性。

最新更新