【问题标题】:Unable to read from Disk in QEmu无法从 QEmu 中的磁盘读取
【发布时间】:2015-02-17 15:15:19
【问题描述】:

我尝试使用 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读取磁盘后设置了进位标志。
为什么会这样?

【问题讨论】:

    标签: assembly x86 gdb qemu


    【解决方案1】:

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

    【讨论】:

    • 只需使用-fda 而不是-hda(我假设你会使用它)。
    • 所以你是说如果生成的二进制文件大于 3kiB,-hda 可以工作?
    • @JaapWijnen 是的,如果您再追加 3 个扇区,代码将按原样工作。尚未查看 qemu(或 bios)源以了解该限制来自何处。
    • 我使用-drive format=raw,file=output.bin 表示Qemu 总是从INT 13h 02h 返回20 in AH,即Controller failure。切换到-fda output.bin 修复它!
    • 替代我的旧-driveqemu-system-i386 -drive file=file,index=0,if=floppy-fda 相同,根据to the manualCtrl+F for Instead of -fda)。
    猜你喜欢
    • 2014-02-13
    • 2020-10-11
    • 1970-01-01
    • 2020-03-31
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 2017-12-04
    相关资源
    最近更新 更多