为什么我的引导加载程序没有将第二个扇区加载到内存中?

Why is my bootloader not loading the second sector to memory?

我正在尝试将引导加载程序写入插入到 VirtualBox VM 中的虚拟软盘驱动器。这是我的以下代码:

org     0x7c00              ; We are loaded by BIOS at 0x7C00

bits    16                  ; We are still in 16 bit Real Mode

Start: jmp loader
        
loader:

.Reset:
    mov     ah, 0x0                 ; reset floppy disk function
    mov     dl, 0x0                 ; drive 0 is floppy drive
    int     0x13                    ; call BIOS
    jc      .Reset                  ; If Carry Flag (CF) is set, there was an error. Try resetting again

.Load:
 
    mov     ax, 0x07e0              ; we are going to read sector to into address 0x07e0:0
    mov     es, ax
    xor     bx, bx
 
    mov     ah, 0x2             ; read floppy sector function
    mov     al, 0x1                 ; read 1 sector
    mov     ch, 0x1                 ; we are reading the second sector past us, so its still on track 1
    mov     cl, 0x2                 ; sector to read (The second sector)
    mov     dh, 0x0                 ; head number
    mov     dl, 0x0                 ; drive number. Remember Drive 0 is floppy drive.
    int     0x13                    ; call BIOS - Read the sector
    jc      .Load
    
 
    jmp     0x07e0:0x0000               ; jump to execute the sector!
    
times 510 - ($-$$) db 0             ; We have to be 512 bytes. Clear the rest of the bytes with 0

dw 0xAA55                   ; Boot Signiture

它应该加载一个小程序到内存中,使用 BIOS 中断在屏幕上打印字母 'A'。该程序位于软盘的第二扇区:

org 0x07e0

    xor     bx, bx      
    mov     ah, 0x0e
    mov     al, 'A'
    int     0x10
    cli
    hlt

谁能告诉我为什么加载不出来?我试过加载到内存 0x1000 中的另一个地址,但是,这也不起作用。 VirtualBox 是否保留了虚拟内存中的某些区域?

谢谢!!

H

*编辑:

我使用 nasm for Windows (nasm -f bin -o bootS1.bin bootS1.asm) 构建我的代码,然后复制并粘贴使用名为 HxD 的程序将二进制文件中的十六进制数据写入 VFD 图像,该程序将原始十六进制数据写入磁盘。然后将磁盘插入 VM 并 运行 模拟启动过程。

您正在从磁道 1 读取,而有效负载在磁道 0 上。请记住:磁头和磁道从 0 开始计数,扇区从 1 开始计数。

请注意,不要硬编码磁盘编号,您应该使用 BIOS 在 dl 中提供的编号。

另请注意 org 0x07e0 不正确。您的负载加载的偏移量在段 0x07e0 中为 0。所以它应该是 org 0x0000 (或者根本没有 org 指令)。鉴于您没有引用有效负载中的任何地址,这不会导致您观察到的问题。