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

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

问题描述

我正在汇编中编写第 1 阶段引导加载程序,我试图将 FAT12 文件系统加载到内存中,以便我可以加载第 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.

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

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,但x/32b 0xa200显示32个0,当我希望看到 OS.BIN 的数据时.

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 例程以同时加载 FAT 根目录(本质上是读取引导扇区后的 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 之后增加 柱面,而我应该增加磁头.这是 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天全站免登陆