无法从 QEmu 中的磁盘读取

Unable to read from Disk in QEmu

我尝试使用 QEmu 从磁盘读取以下代码:

; Read some sectors from the boot disk using our disk_read function
[org 0x7c00]
mov [BOOT_DRIVE] , dl 
; BIOS stores our boot drive in DL , so store this for later
mov bp , 0x8000
mov sp , bp
; Here we set our stack safely out of the
; way , at 0x8000
mov bx , 0x9000
; Load 5 sectors to 0 x0000 ( ES ):0 x9000 ( BX )
mov dh , 5
; from the boot disk.
mov dl , [BOOT_DRIVE]
call disk_load
jmp $
%include "print_string.asm" ; Re - use our print_string function
%include "disk_load.asm"
BOOT_DRIVE : db 0
; Bootsector padding
times 510-($-$$) db 0
dw 0xaa55
;Loading additional two sectors from the disk we booted from.
times 256 dw 0xdada
times 256 dw 0xface

包含的文件是:
print_string.asm- 打印字符串

print_string : ;Prints string stored at starting address [bx]
pusha
mov ah, 0x0e
print :
mov al, [bx]
int 0x10
add bx, 0x1
mov cl, [bx]
cmp cl, 0 ;0 marks the end of the string
jne print
mov al, 0x20 ;prints space " " at the end of the string
int 0x10
popa
ret

disk_load.asm-

; load DH sectors to ES : BX from drive DL
disk_load :
push dx
; Store DX on stack so later we can recall
; how many sectors were request to be read ,
; even if it is altered in the meantime
mov ah , 0x02
; BIOS read sector function
mov al , dh
; Read DH sectors
mov ch , 0x00
; Select cylinder 0
mov dh , 0x00
; Select head 0
mov cl , 0x02
; Start reading from second sector ( i.e.
; after the boot sector )
int 0x13
; BIOS interrupt
jc disk_error ; Jump if error ( i.e. carry flag set )
pop dx
cmp dh , al
jne disk_error
ret ; Restore DX from the stack
disk_error :
mov bx , DISK_ERROR_MSG
call print_string
jmp $
; Variables
DISK_ERROR_MSG db "Disk read error",0

在这段代码中,我无法读取磁盘,也无法在 QEmu 上打印 "Disk read error" 消息。我查看了GDB中的代码,发现使用BIOS读盘后设置了carry flag。
为什么会这样?

根据我的测试,如果您使用软盘映像,这会起作用。如果使用硬盘镜像,大小至少需要3kiB,否则qemu不会喜欢的。我想这是你的问题。