调试int bh中引导扇区的13h 02h功能

时间:2014-12-20 01:44:36

标签: assembly x86 bios bochs disk-io

我想调试引导扇区并读取软盘。我在bochs中调试它,并想检查它是否成功读取或失败。我知道AH寄存器可以返回代码,但我也想查看它读取的内容,所以我想检查物理内存中的es:bx堆栈,但它都扩展了0x00。为什么呢?

此代码由as86编写,由ld86链接。 我使用bochs磁盘映像创建工具创建了软盘映像,并使用命令dd bs=32 if=boot of=/dev/fd0 skip=1创建了这个可启动软盘映像。

我注意到该标志重新传输了0x00000046,因此CF为0表示操作没有错误。但是ax寄存器是0x0201。啊寄存器是0x02是errcode。我不知道为什么?

以下是我的bochs文件:

megs: 16

romimage: file=$BXSHARE/BIOS-bochs-latest
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest

floppya: 1_44="floppya.img", status=inserted

ata0-master: type=disk, path="hd.img", cylinders=365, heads=16, spt=63

boot: a

log: bochsout.txt

panic: action=ask
error: action=report
info: action=report
debug: action=ignore

cpu: ips=15000000
clock: sync=both

vga: extension=vbe, update_freq=15

mouse: enabled=0

这是代码:

BOOTSEG = 0x07c0
SYSSEG    = 0x1000

entry start
start:
    jmpi go, #BOOTSEG
go: mov ax, cs
    mov ds, ax
    mov ss, ax
    mov sp, #400

    mov dx, #0x0000
    mov cx, #0x0002
    mov ax, #SYSSEG
    mov es, ax
    xor   bx, bx
    mov ax, #0x201
    int 0x13

.org 510
    .word 0xAA55
    .word 0xFFFF

由as86编写的代码,我在第二个扇区的开头添加一个单词。

我将调试信息粘贴在bochs中。

========================================================================
00000000000i[      ] reading configuration from bochsrc
00000000000i[      ] installing win32 module as the Bochs GUI
00000000000i[      ] using log file bochsout.txt
Next at t=0
(0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b          ; ea5be000
f0
<bochs:1> b 0x7c00
<bochs:2> c
(0) Breakpoint 1, 0x0000000000007c00 in ?? ()
Next at t=61419250
(0) [0x000000007c00] 0000:7c00 (unk. ctxt): jmpf 0x07c0:0005          ; ea0500c0
07
    <bochs:3> s
Next at t=61419251
(0) [0x000000007c05] 07c0:0005 (unk. ctxt): mov ax, cs                ; 8cc8
<bochs:4> s
Next at t=61419252
(0) [0x000000007c07] 07c0:0007 (unk. ctxt): mov ds, ax                ; 8ed8
<bochs:5> s
Next at t=61419253
(0) [0x000000007c09] 07c0:0009 (unk. ctxt): mov ss, ax                ; 8ed0
<bochs:6> s
Next at t=61419254
(0) [0x000000007c0b] 07c0:000b (unk. ctxt): mov sp, 0x0400            ; bc0004
<bochs:7> s
Next at t=61419255
(0) [0x000000007c0e] 07c0:000e (unk. ctxt): mov dx, 0x0000            ; ba0000
<bochs:8> s
Next at t=61419256
(0) [0x000000007c11] 07c0:0011 (unk. ctxt): mov cx, 0x0002            ; b90200
<bochs:9> s
Next at t=61419257
(0) [0x000000007c14] 07c0:0014 (unk. ctxt): mov ax, 0x1000            ; b80010
<bochs:10> s
Next at t=61419258
(0) [0x000000007c17] 07c0:0017 (unk. ctxt): mov es, ax                ; 8ec0
<bochs:11> s
Next at t=61419259
(0) [0x000000007c19] 07c0:0019 (unk. ctxt): xor bx, bx                ; 31db
<bochs:12> s
Next at t=61419260
(0) [0x000000007c1b] 07c0:001b (unk. ctxt): mov ax, 0x0201            ; b80102
<bochs:13> s
Next at t=61419261
(0) [0x000000007c1e] 07c0:001e (unk. ctxt): int 0x13                  ; cd13
<bochs:14> s
Next at t=61419262
(0) [0x0000000fe3fe] f000:e3fe (unk. ctxt): jmp .-19908 (0x000f963d)  ; e93cb2
<bochs:15> r
rax: 00000000_00000201 rcx: 00000000_00090002
rdx: 00000000_00000000 rbx: 00000000_00000000
rsp: 00000000_000003fa rbp: 00000000_00000000
rsi: 00000000_000e0000 rdi: 00000000_0000ffac
r8 : 00000000_00000000 r9 : 00000000_00000000
r10: 00000000_00000000 r11: 00000000_00000000
r12: 00000000_00000000 r13: 00000000_00000000
r14: 00000000_00000000 r15: 00000000_00000000
rip: 00000000_0000e3fe
eflags 0x00000046: id vip vif ac vm rf nt IOPL=0 of df if tf sf ZF af PF cf
<bochs:16> sreg
es:0x1000, dh=0x00009301, dl=0x0000ffff, valid=1
        Data segment, base=0x00010000, limit=0x0000ffff, Read/Write, Accessed
cs:0xf000, dh=0x0000930f, dl=0x0000ffff, valid=1
        Data segment, base=0x000f0000, limit=0x0000ffff, Read/Write, Accessed
ss:0x07c0, dh=0x00009300, dl=0x7c00ffff, valid=7
        Data segment, base=0x00007c00, limit=0x0000ffff, Read/Write, Accessed
ds:0x07c0, dh=0x00009300, dl=0x7c00ffff, valid=1
        Data segment, base=0x00007c00, limit=0x0000ffff, Read/Write, Accessed
fs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=1
        Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
gs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=1
        Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
ldtr:0x0000, dh=0x00008200, dl=0x0000ffff, valid=1
tr:0x0000, dh=0x00008b00, dl=0x0000ffff, valid=1
gdtr:base=0x00000000000fa1f7, limit=0x30
idtr:base=0x0000000000000000, limit=0x3ff
<bochs:17> xp /40bx 0x10000
[bochs]:
0x0000000000010000 <bogus+       0>:    0x00    0x00    0x00    0x00    0x00
0x00    0x00    0x00
0x0000000000010008 <bogus+       8>:    0x00    0x00    0x00    0x00    0x00
0x00    0x00    0x00
0x0000000000010010 <bogus+      16>:    0x00    0x00    0x00    0x00    0x00
0x00    0x00    0x00
0x0000000000010018 <bogus+      24>:    0x00    0x00    0x00    0x00    0x00
0x00    0x00    0x00
0x0000000000010020 <bogus+      32>:    0x00    0x00    0x00    0x00    0x00
0x00    0x00    0x00

2 个答案:

答案 0 :(得分:0)

你忘了显示你尝试过的命令(也许你正在查看错误的地址),以及你加载的扇区中你的软盘映像是否还有零字节;)你也没有说你是什么汇编程序使用以及如何创建图像。

我使用nasm

测试了此代码
    mov dx, 0x0000
    mov cx, 0x0002
    mov ax, 0x1000
    mov es, ax
    xor bx, bx
    mov ax, 0x201
    int 0x13
    jmp $

times 510 - ($-$$) db 0
dw 0xAA55 ; signature
times 512 db 0xaa ; fill 2nd sector with 0xaa
times 1474560 - ($-$$) db 0 ; fill rest of image with 00

bochs中引导创建的图像:

(0) [0x0000000000007c10] 0000:7c10 (unk. ctxt): int 0x13                  ; cd13
<bochs:9>
Next at t=13210529
(0) [0x0000000000007c12] 0000:7c12 (unk. ctxt): jmp .-2 (0x00007c12)      ; ebfe
<bochs:10> r
rax: 0x00000000_00000001 rcx: 0x00000000_00000002
rdx: 0x00000000_00000000 rbx: 0x00000000_00000000
rsp: 0x00000000_0000ffd6 rbp: 0x00000000_00000000
rsi: 0x00000000_000e91b9 rdi: 0x00000000_0000ffac
r8 : 0x00000000_00000000 r9 : 0x00000000_00000000
r10: 0x00000000_00000000 r11: 0x00000000_00000000
r12: 0x00000000_00000000 r13: 0x00000000_00000000
r14: 0x00000000_00000000 r15: 0x00000000_00000000
rip: 0x00000000_00007c12
eflags 0x00000046: id vip vif ac vm rf nt IOPL=0 of df if tf sf ZF af PF cf
<bochs:11> xp/32bx 0x10000
[bochs]:
0x0000000000010000 <bogus+       0>:    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa
0x0000000000010008 <bogus+       8>:    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa
0x0000000000010010 <bogus+      16>:    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa
0x0000000000010018 <bogus+      24>:    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa    0xaa

您可以看到AH=0(表示没有错误),AL=1(表示已加载1个扇区),实际上数据存在于内存中。

答案 1 :(得分:0)

你进入中断处理程序的最后s步骤(注意地址f000:e3fe - 这是在BIOS内部)。它还没有做任何事情,所以ax保留你传递给中断的值。您需要先步骤直到返回代码,或在中断后放置断点并继续。只有这样你才能检查CF和其他寄存器。