什么会导致 Int 13h 中的磁盘读取错误? [英] What would cause a disk read error in Int 13h?

查看:81
本文介绍了什么会导致 Int 13h 中的磁盘读取错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在 NASM 中编写一个测试程序,该程序使用 int 13h 从引导磁盘读取扇区,除非每次我使用 sudo qemu-system 运行组装程序-i386 load_disk.bin 它给了我这个输出:

I've been writing a test program in NASM for a function that uses int 13h to read sectors off the booted disk except every time I run the assembled program with sudo qemu-system-i386 load_disk.bin it gives me this output:

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

disk read error! disk read error! disk read error!* disk read error!* disk read error!*

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

which is expected if the carry flag (CF) is set. I've been looking for answers to this for days and tried lots of different solutions (jumping to ES:BX after jc test, saving boot drive in DL...) but nothing seems to work.
Here is my program:

[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

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

Thank you for considering this question. I've really been at this for a while now.

推荐答案

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

I got the same problem when I ran your code in Qemu, until I reduced the sector load count to 1 (from the 5 you had):

mov al, 0x01                    ; read 1 sector

由于您的映像只有一个额外的扇区,并且模拟器将映像视为整个磁盘,因此您只能读取一个扇区.通过此更改,您的代码有效"(不打印错误消息).

Since your image only has one additional sector, and the emulator treats the image as the entire disk, you can't read any more than the one sector. With this change, your code "works" (doesn't print the error message).

这篇关于什么会导致 Int 13h 中的磁盘读取错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆