一些背景:
我正在开发一个基本的引导加载程序,它通过 BIOSINT 13h AH=02h
中断将辅助引导加载程序读入内存。我已经让它在模拟器(Virtualbox、Qemu 和 Bochs)中工作。
随后,我在我的引导加载程序中添加了一个 BPB(BIOS 参数块),制作了一个可引导的 USB,并在我的真机上使用 USB 软盘仿真(我在真机 BIOS 的配置屏幕中设置)对其进行了测试。它就像一个魅力。
在我自己的机器上测试引导加载程序后,我在另一台较新的机器上对其进行了测试。这台新计算机的 BIOS 配置中没有软盘仿真选项,因此无法从 USB 驱动器启动。因此,在这个osdev wikipage 之后,我在 MBR 的末尾添加了一个分区表,以便较新的机器可以从 USB 启动。
问题:
添加分区表代码后,引导加载程序无法将辅助引导加载程序加载到内存中,并且 BIOSINT 13h
失败。我不知道为什么会发生这种情况,因为我没有更改任何实际的引导加载程序代码。我刚刚添加了 64 位 MBR 分区表,将数据读入内存立即失败。
BPB(BIOS 参数块)和磁盘访问例程
bits 16
org 0x7C00
jmp start
nop
;------------------------------------------;
; Standard BIOS Parameter Block, "BPB". ;
;------------------------------------------;
bpbOEM db 'MSDOS5.0'
bpbSectSize dw 512
bpbClustSize db 1
bpbReservedSe dw 1
bpbFats db 2
bpbRootSize dw 224
bpbTotalSect dw 2880
bpbMedia db 240
bpbFatSize dw 9
bpbTrackSect dw 18
bpbHeads dw 2
bpbHiddenSect dd 0
bpbLargeSect dd 0
;---------------------------------;
; extended BPB for FAT12/FAT16 ;
;---------------------------------;
bpbDriveNo db 0
bpbReserved db 0
bpbSignature db 41
bpbID dd 1
bpbVolumeLabel db 'BOOT FLOPPY'
bpbFileSystem db 'FAT12 '
drive_n: db 0
start:
mov [drive_n], dl
; setup segments
xor ax, ax
mov ds, ax
mov es, ax
; setup stack
cli
mov ss, ax
mov sp, 0x7C00 ; stack will grow downward to lower adresses
sti
; write start string
mov si, start_str ; start_str = pointer to "Bootloader Found..."
call write_str ; routine that prints string in si register to screen
; read bootstrapper into memory
mov dl, [drive_n]; drive number
mov dh, 0x00 ; head (base = 0)
mov ch, 0x00 ; track /cylinder = 0
mov cl, 0x02 ; (1= bootloader, 2=start of bootstrapper
mov bx, 0x7E00 ; location to load bootstrapper
mov si, 0x04 ; number of attempts
; attempt read 4 times
read_floppy:
; reset floppy disk
xor ax, ax
int 0x13
; check if attempts to read remain, if not, hlt system (jmp to fail_read)
test si, si
je fail_read ; *** This jump happens only on real machines with
dec si ; USB hard drive emulation ***
; attempt read
mov ah, 0x02 ; select read
mov al, 0x0F ; num sectors
int 0x13
jc read_floppy
... ; continue onward happily! (without any errors)
MBR 分区表
; 0x1b4
db "12345678", 0x0, 0x0 ; 10 byte unique id
; 0x1be ; Partition 1 -- create one big partition that spans the whole disk (2880 sectors, 1.44mb)
db 0x80 ; boot indicator flag = on
; start sector
db 0 ; starting head = 0
db 0b00000001 ; cyilinder = 0, sector = 1 (2 cylinder high bits, and sector. 00 000001 = high bits db 0x00)
db 0 ; 7-0 bits of cylinder (insgesamt 9 bits)
; filesystem type
db 1 ; filesystem type = fat12
; end sector = 2880th sector (because a floppy disk is 1.44mb)
db 1 ; ending head = 1
db 18 ; cyilinder = 79, sector = 18 (2 cylinder high bits, and sector. 00 000001 = high bits db 0x00)
db 79 ; 7-0 bits of cylinder (insgesamt 9 bits)
dd 0 ; 32 bit value of number of sectors between MBR and partition
dd 2880 ; 32 bit value of total number of sectors
; 0x1ce ; Partition 2
times 16 db 0
; 0x1de ; Partition 3
times 16 db 0
; 0x1ee ; Parititon 4
times 16 db 0
; 0x1fe ; Signature
dw 0xAA55
问题
当且仅当在 BIOS 中启用 USB 硬盘驱动器仿真时,导致读取磁盘失败的原因是什么?我已经尝试更改分区表和 BPB,但似乎没有任何效果。我敢打赌,这与计算机处理软盘和硬盘信息的方式不同有关,但很难找到任何相关信息。
任何帮助将不胜感激。我不打算让这个问题这么长。它只是积累。