无法从QEmu中的磁盘读取

时间:2015-02-17 15:15:19

标签: assembly x86 gdb 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上打印。我检查了GDB中的代码,发现在使用BIOS读取磁盘后设置了进位标志 为什么会这样?

1 个答案:

答案 0 :(得分:2)

根据我的测试,如果你使用软盘图像,这是有效的。如果您使用硬盘映像,它的大小至少需要3kiB,否则qemu不会喜欢它。我认为这是你的问题。