什么会在Int 13h中导致磁盘读取错误?

Hop*_*ful 5 assembly bios nasm bootloader x86-16

我一直在用NASM编写一个测试程序,该函数用于int 13h从引导磁盘读取扇区,但每次使用sudo qemu-system-i386 load_disk.bin运行汇编程序时,它都会为我提供以下输出:

磁盘读取错误!磁盘读取错误!磁盘读取错误!*磁盘读取错误!*磁盘读取错误!*

如果设置了进位标志(CF),则可以预期。我一直在寻找答案的几天,并尝试了许多不同的解决方案(跳转到ES:BX之后jc test,将启动驱动器保存在DL...中),但似乎没有任何效果。
这是我的程序:

[bits 16]                       ;real mode 
[org 0x7c00] 

mov [DISK], dl                  ;save boot drive value 

xor ax, ax                      ;setting up stack 
cli 
mov ss, ax 
mov sp, 0x7c00 
sti 

mov di, 5       `               ;counter for number of tries 
read_disk:                      
mov ah, 0x00                    ;resetting disk 
int 0x13 
mov bx, 0x9000                  ;data buffer 
mov es, bx 
mov bx ,0x0000                   
mov ah, 0x02                    ; function number 2 of int 13h 
mov al, 0x05                    ; read 5 sectors 
mov ch, 0x00                    ; cylinder 0 
mov cl, 0x02                    ; sector 2 (1 is boot sector)   
mov dh, 0x00                    ; head 1 
mov dl, [DISK]                  ; give dl value 
int 0x13                        ; call interrupt 
jc disk_error                    ;if carry flag is set 
jmp 9000h:0000h                
mov bx, [0x9000+512]            ;print bytes as if they were strings 
call print_string 

print_string:                   ; print_string function 
push bx                         
push ax 
loop_one: 
mov ah, 0x0e 
mov al, [bx] 
int 0x10 
cmp al, 0 
je end 
inc bx 
jmp loop_one 
end: 
pop ax 
pop bx 
ret 

disk_error:                    
cmp di, 0                        ; if number of tries=0 jump to loop   
je loop            
push bx                          ;print out the error message      
mov bx, MSG 
call print_string 
pop bx 
dec di                           ;decrementing di 
jmp read_disk 

loop: 
jmp $ 

MSG: 
db 'disk read error!', 0 

DISK: 
db 0 

times 510-($-$$) db 0           ; boot sector padding and BIOS trigger 
dw 0xaa55 
times 256 dw 'D'                ; sectors supposed to be read
Run Code Online (Sandbox Code Playgroud)

感谢您考虑这个问题。我真的已经有一段时间了。

dav*_*mac 2

当我在 Qemu 中运行你的代码时,我遇到了同样的问题,直到我将扇区负载计数减少到 1(从你的 5 个):

mov al, 0x01                    ; read 1 sector
Run Code Online (Sandbox Code Playgroud)

由于您的映像只有一个附加扇区,并且模拟器将映像视为整个磁盘,因此您只能读取一个扇区。通过此更改,您的代码可以“工作”(不会打印错误消息)。