工作FAT16引导程序生成的实际硬件读取错误?(Working FAT16 Bootloader G

2019-09-16 08:33发布

有关过去的一周,我一直在开发一个简单的操作系统用于学习的目的和......“好玩”。 VirtualBox和NASM在拖,我居然有了一个不错的开端。 最终,我决定,我想也通过了臭名昭著的供电制定一个引导程序(命中512个字节的墙相当困难后) Brokenthorn教程 ,直到加载的文件系统,从点。

一些有心计HexFiend和一些空白FAT16图片,我终于得到了BPB制定。 随着一些额外的大会两轮牛车(基础是Brokenthorn的教程, 第6部分 ),我也得到了文件的加载与我的引导程序,它从我的虚拟磁盘加载恰当地命名为“启动”文件(做工作,如果= / dev的用dd /零= boot.img的BS = 512计数的2880 =)

那么,什么是问题呢? 这是我所看到的,当我通过USB闪存盘加载到实际硬件(在这种情况下,的/ dev /磁盘3,在编译的文件是BOOT.BIN):

dd bs=512 count=1 if=compiled/boot.bin of=/dev/disk3

这是预期的输出(在VirtualBox中):

相较于实际输出 (在一个旧的笔记本电脑)

'-' indicates a sector is being loaded
'_' indicates a sector was loaded
'!' indicates all of the desired sectors were loaded properly
'R' indicates a read error
'T' indicates the FAT table is being loaded
'D' indicates the FAT table was loaded properly
'F' means the file is being located (or Found, hence the F)
'L' means the file is being loaded

(我会用实际调试消息,但512字节的限制是相当可怕的。)

所以,不同的是一个是一个USB记忆棒,一个是(虚拟)软盘。 他们都有上都装入完全相同的信息,包括BPB。 然而,一个工作,而一个没有。 下面是我的代码加载一个扇区(使用啊02H / 13H INT,这是我听到的正常工作了USB)的主要部分:

ReadSectors:
    mov di, 0x0005                  ; How many times should we retry the read?

ReadSectors.loop:
    ; DEBUG
    push ax
    mov ah, 0eh
    mov al, '-'
    int 10h
    pop ax
    push ax
    push bx
    push cx
    call LBAToCHS
    mov ah, 02h                     ; Set the interrupt to the 
                                    ; 'read sector' function
    mov al, 1                       ; Only read one sector
    mov ch, byte[chs.track]         ; The track to read from
    mov cl, byte[chs.sector]        ; The sector to read from
    mov dh, byte[chs.head]          ; The head to read from
    mov dl, byte[_bpb.driveNumber]  ; The drive to read from
    int 13h                         ; Call our 'disk IO' interrupt
    jnc ReadSectors.success         ; If we successfully read the data, 
                                    ; we don't have to try again
    mov ah, 00h                     ; Set the interrupt to the 
                                    ; 'reset disk' function
    int 13h                         ; Call our 'disk IO' interrupt
    dec di                          ; Decrement our error counter
    pop cx
    pop bx
    pop ax
    jnz ReadSectors.loop            ; Try again if we've failed
    jmp ReadSectors.fail            ; RED ALERT

(完整的源,包括BPB,可以在引擎收录中找到( http://pastebin.com/SeUm7xu6 )

我已经克服了一些问题与大会至今,但是这一次有我难住了。 希望我能尽快得到过去的引导程序和抽象文件IO。

任何建议将不胜感激。 提前致谢!

Answer 1:

你的代码可能无法在设备启动加载程序从加载(很多时候是不是如果你通过U盘启动)驱动器号0读取。 你应该从由BIOS加载到读取的驱动器号dl寄存器。 这已经是一个回答问题的SO。



文章来源: Working FAT16 Bootloader Generates Read Error on Actual Hardware?