为什么我的根目录没有被加载? (FAT12) [英] Why isn't my root directory being loaded? (FAT12)

查看:121
本文介绍了为什么我的根目录没有被加载? (FAT12)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写汇编中的Stage 1引导加载程序,以尝试将FAT12文件系统加载到内存中,以便可以加载我的Stage 2引导加载程序.我已经设法将FAT加载到内存中,但是我正在努力将根目录加载到内存中.

I am writing a stage 1 bootloader in assembly with which I am attempting to load the FAT12 filesystem into memory so that I can load my stage 2 bootloader. I have managed to load the FATs into memory, however I am struggling to load the root directory into memory.

我目前正在使用作为参考,并产生了以下内容:

I am currently using this for reference and have produced the following:

.load_root:
    ;es is 0x7c0
    xor dx, dx              ; blank dx for division
    mov si, fat_loaded      ; inform user that FAT is loaded
    call print
    mov al, [FATcount]      ; calculate how many sectors into the disk must be loaded
    mul word [SectorsPerFAT]
    add al, [ReservedSectors]
    div byte [SectorsPerTrack]
    mov ch, ah              ; Store quotient in ch for cylinder number
    mov cl, al              ; Store remainder in cl for sector number

    xor dx, dx
    xor ax, ax
    mov al, ch              ; get back to "absolute" sector number
    mul byte [SectorsPerTrack]
    add al, cl
    mul word [BytesPerSector]
    mov bx,ax               ; Memory offset to load to data into memory after BOTH FATs (should be 0x2600, physical address should be 0xA200)

    xor dx, dx              ; blank dx for division
    mov ax, 32
    mul word [MaxDirEntries]
    div word [BytesPerSector] ; number of sectors root directory takes up (should be 14)

    xor dh, dh              ; head 0
    mov dl, [boot_device]   ; boot device

    mov ah, 0x02            ; select read mode

    int 13h
    cmp ah, 0
    je .load_OS
    mov si, error_text
    call print
    jmp $

但是,如果我用gdb检查0xA200处的内存,我只会看到0.我的根目录没有包含一个文件-我已经在根目录中放置了一个名为OS.BIN的文件进行测试.

However, if I inspect the memory at 0xA200 with gdb, I just see 0s. My root directory does contain a file -- I have put a file called OS.BIN in the root directory to test with.

在读取操作之后在gdb中使用info registers会给出以下输出:

Using info registers in gdb after the read operation gives the following output:

eax            0xe      14
ecx            0x101    257
edx            0x0      0
ebx            0x2600   9728
esp            0x76d0   0x76d0
ebp            0x0      0x0
esi            0x16d    365
edi            0x0      0
eip            0x7cdd   0x7cdd
eflags         0x246    [ PF ZF IF ]
cs             0x0      0
ss             0x53     83
ds             0x7c0    1984
es             0x7c0    1984
fs             0x0      0
gs             0x0      0

操作状态为0,读取的扇区数为14,es:bx指向0xA200,但是当我希望看到OS.BIN的数据时,x/32b 0xa200显示32个0.

The status of the operation is 0, the number of sectors read is 14, and es:bx points to 0xA200, but x/32b 0xa200 shows 32 0s, when I would expecting to see the data for OS.BIN.

编辑 我在中断之前做了info registers,输出如下:

EDIT I did info registers before the interrupt and the output is the following:

eax            0x20e    526
ecx            0x101    257
edx            0x0      0
ebx            0x2600   9728
esp            0x76d0   0x76d0
ebp            0x0      0x0
esi            0x161    353
edi            0x0      0
eip            0x7cc8   0x7cc8
eflags         0x246    [ PF ZF IF ]
cs             0x0      0
ss             0x53     83
ds             0x7c0    1984
es             0x7c0    1984
fs             0x0      0
gs             0x0      0

除了功能请求号已替换为状态码之外,其他与之后相同.

Which is the same as after, except the function request number has been replaced with the status code.

我要去哪里错了?我是从错误的CHS地址读取吗?还是其他一些简单的错误?而我该如何纠正呢?

Where am I going wrong? Am I reading from the wrong CHS address? Or some other simple mistake? And how can I correct this?

我正在使用fat_imgen制作磁盘映像.用于创建磁盘映像的命令是fat_imgen -c -f floppy.flp -F -s bootloader.bin,用于将OS.BIN添加到该映像的命令是fat_imgen -m -f floppy.flp -i OS.BIN

I am using fat_imgen to make my disk image. Command for creating the disk image is fat_imgen -c -f floppy.flp -F -s bootloader.bin and command for adding OS.BIN to the image is fat_imgen -m -f floppy.flp -i OS.BIN

我有一个 BIOS参数块(BPB),它表示使用FAT12的1.44MB软盘:

I have a BIOS Parameter Block (BPB) that represents a 1.44MB floppy using FAT12:

jmp short loader
times 9 db 0

BytesPerSector: dw 512
SectorsPerCluster: db 1
ReservedSectors: dw 1
FATcount: db 2
MaxDirEntries: dw 224
TotalSectors: dw 2880
db 0
SectorsPerFAT: dw 9
SectorsPerTrack: dw 18
NumberOfHeads: dw 2
dd 0
dd 0
dw 0
BootSignature: db 0x29
VolumeID: dd 77
VolumeLabel: db "Bum'dOS   ",0
FSType: db "FAT12   "

我还有另一个似乎可以正常工作的功能,可以将FAT12表加载到内存地址0x7c0:0x0200(物理地址0x07e00):

I have another function that appears to work that loads the FAT12 table to memory address 0x7c0:0x0200 (physical address 0x07e00):

;;;Start loading File Allocation Table (FAT)
.load_fat:
    mov ax, 0x07c0          ; address from start of programs
    mov es, ax
    mov ah, 0x02            ; set to read
    mov al, [SectorsPerFAT]   ; how many sectors to load
    xor ch, ch              ; cylinder 0
    mov cl, [ReservedSectors]  ; Load FAT1
    add cl, byte 1
    xor dh, dh              ; head 0
    mov bx, 0x0200          ; read data to 512B after start of code
    int 13h
    cmp ah, 0
    je .load_root
    mov si, error_text
    call print
    hlt

推荐答案

在加载FAT之后,我最终取消了加载根目录.最后,我修改了.load_fat例程,以同时加载FATs 根目录(本质上是在引导扇区之后读取32个扇区,但是仍然可以让我轻松地修改磁盘几何形状).

I ended up scrapping loading the root directory after loading the FATs. In the end, I modified my .load_fat routine to load both FATs and the root directory at the same time (essentially reading 32 sectors after the boot sector, but in a way that still allows me to easily modify the disk geometry).

此代码如下:

.load_fat:
    mov ax, 0x07c0          ; address from start of programs
    mov es, ax
    mov al, [SectorsPerFAT] ; how many sectors to load
    mul byte [FATcount]     ; load both FATs
    mov dx, ax
    push dx
    xor dx, dx              ; blank dx for division
    mov ax, 32
    mul word [MaxDirEntries]
    div word [BytesPerSector] ; number of sectors for root directory
    pop dx
    add ax, dx              ; add root directory length and FATs length -- load all three at once
    xor dh,dh
    mov dl, [boot_device]

    xor ch, ch              ; cylinder 0
    mov cl, [ReservedSectors]  ; Load from after boot sector
    add cl, byte 1
    xor dh, dh              ; head 0
    mov bx, 0x0200          ; read data to 512B after start of code
    mov ah, 0x02            ; set to read
    int 13h
    cmp ah, 0
    je .load_root
    mov si, error_text
    call print
    hlt

尽管不是我打算解决问题的方式,但它确实可以完成工作,我可以从此继续进行下去.

Though not the way I intended to solve the problem, it does the job and I can move on from this to continue development.

编辑

无论如何,我认为我已经弄清楚了旧代码出了什么问题.我在扇区18之后增加了 cylinder ,当时我应该一直增加头部.原因是CHS,而不是HCS!

I think I worked out where the old code was going wrong, anyway. I was incrementing the cylinder after sector 18, when I should have been incrementing the head. It's CHS, not HCS, for a reason!

这篇关于为什么我的根目录没有被加载? (FAT12)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆