【问题标题】:Loading sector from boot image fails in bootloader在引导加载程序中从引导映像加载扇区失败
【发布时间】:2012-04-09 14:09:34
【问题描述】:

我正在尝试构建自己的引导加载程序,该加载程序加载然后从实模式切换到保护模式,加载 GDT 描述符,然后调用一些第 2 阶段代码。由于我无法找到调试程序的好方法,因此让事情正常运行是一场艰苦的战斗。出于某种奇怪的原因,我的代码无法将引导加载程序的第二个扇区读入位于0x1000 地址的内存中。我尝试将int 0x13 与al = 0x01 一起使用,这是一个Get Status of Last Drive Operation 中断。它返回0x01,这意味着Invalid Command,这让我更加困惑。

    mov ah, 0      ;reset drive
    int 0x13
    or ah, ah      ;check for error
    jnz err        ;error handling function (prints ASCII A)

    mov ax, 0
    mov es, ax
    mov bx, 0x1000 ;read sector into 0000:0x1000

    mov ah, 0x02   ;read sector
    mov al, 1      ;# of sectors to read = 1
    mov ch, 0      ;Cylinder = 0
    mov cl, 0x02   ;Sector to read = 2 (second as first sector is this code)
    mov dh, 0      ;head = 0

                   ;dl should equal the drive number as BIOS automatically detects it
    int 0x13
    or ah, ah
    jnz err        ;check for error again (this is where the error occurs)

当计算机启动时,我被告知 BIOS 将驱动器号放入dl 寄存器,因此我的所有中断都应该在正确的驱动器上执行。我什至尝试将dl 设置为0x00,这将等于软盘驱动器A:,在BOCHS(CPU 模拟器)中,我将软盘驱动器A: 设置为我的启动映像,但它仍然无法启动。 QEMU 和 BOCHS 不能正确模拟代码有什么原因吗?我还没有尝试将它刻录到 USB 并从实时 BIOS 启动它。我将发布我的完整代码here 以便您在必要时查看它。如果我不够清楚,我很抱歉,我是操作系统开发的初学者。非常感谢!

编辑: 操作系统:Windows 7 x64(开发中的 x32 操作系统) 仿真:运行 NASM 编译器创建的 boot.img 的 BOCHS。

【问题讨论】:

  • @Stewart 我正在重写我的引导加载程序,以便对其进行测试。一旦我将您的新代码合并到其中,我会回来并接受。别担心:)

标签: assembly kernel bootloader


【解决方案1】:

您正在错误地检查错误。 int 0x13 ah=0 例如通过设置进位标志表示错误,而不是通过报告 ah 中的内容。如果使用 jc err 设置进位,则应该跳转而不是 or 啊,啊 jnz err。

【讨论】:

    猜你喜欢
    • 2013-08-24
    • 2017-01-24
    • 2012-07-25
    • 1970-01-01
    • 2015-11-28
    • 2016-07-02
    • 1970-01-01
    • 2014-10-03
    • 2013-01-25
    相关资源
    最近更新 更多