调试 int 13h 02h 引导扇区的 bochs 函数



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

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

我注意到该标志重新转动0x00000046因此 CF 为 0,表示该操作没有错误。但是斧头寄存器是0x0201。啊寄存器是0x02是错误编码。我不知道为什么?

以下是我的 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

您最后s步进入中断处理程序(请注意地址f000:e3fe - 这是在 BIOS 中(。它尚未执行任何操作,因此ax保留您传递给中断的值。您需要单步执行,直到返回到代码,或者在中断后放置断点并继续。只有这样,您才应该检查CF和其他寄存器。

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

我已经用这段代码进行了测试,使用 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 个扇区(,并且数据确实在内存中。

相关内容

  • 没有找到相关文章