gpt4 book ai didi

assembly - 使用引导扇区作为 MBR 创建 FAT 分区

转载 作者:行者123 更新时间:2023-12-04 01:59:24 26 4
gpt4 key购买 nike

我正在帮助一位 friend 为他的操作系统编写引导加载程序。我已经为他写了一个引导参数 block 。这似乎是有效的,但是,当我使用 DD 将它刻录到 1.44MiB 软盘镜像的第一个扇区时,它不能作为 FAT16 文件系统挂载。然而,我没有看到代码有任何真正的问题。在这里(也有很好的评论):

BITS 16

jmp short start

iOEM db "ShapeOS"
iSectSize dw 0x200 ; bytes / sector
iClustSize db 1 ; 1 sector per cluster (for simplicity)
iResCnt dw 1 ; number of reserved sectors
iFatCnt db 2 ; # of fat copies
iRootSize dw 224 ; size of root dir
iTotalSect dw 2880 ; total sectors
iMedia db 0xF0 ; media descriptor
iFatSize dw 9 ; size of each FAT
iTrackSect dw 9 ; sectors per track
iHeadCnt dw 2 ; number of r/w heads
iHiddentSect dd 0 ; number of hidden sectors
iSect32 dd 0 ; number of > 32MB sectors
iBootDrive db 0 ; holds drive of bootsector
iReserved db 0 ; empty reserved attribute
iBootSign db 0x29 ; extended bootsig
iVolID db "seri" ; disk serial
acVolumeLabel db "MYVOLUME " ; volume label
acFSType db "FAT16 " ; fs type

start:
cli
mov ax, 0x07C0
add ax, 288
mov ss, ax
mov sp, 4096

mov ax, 0x07C0
mov ds, ax
sti

call clear_screen

mov si, intro
call puts16
mov si, loadmsg
call puts16
mov si, failed
call puts16

jmp $


intro db 'Shaper Bootloader, written by KingLuigi4932 and Kerndever', 0xD, 0xA, 0
loadmsg db 'Loading kernel... ', 0
failed db 'Failed!', 0xD, 0xA, 0


puts16:
mov ah, 0Eh

.repeat:
lodsb
cmp al, 0
je .done
int 10h
jmp .repeat

.done:
ret

clear_screen:
mov AX, 1003h
mov BL, 00h
int 10h

; Clear screen
;; Set mode to clear screen for all bioses
mov AH, 00h
int 10h

;; Fill screen with blue background
mov AH, 09h
mov AL, 20h
mov BH, 00h
mov BL, 1Eh
mov CX, 2000h
int 10h

ret

times 510-($-$$) db 0
dw 0xAA55

我用来把它放在软盘镜像的第一个扇区的命令是:

dd if=/dev/zero of=fat.img bs=512 count=2880

然后:

dd status=noxfer conv=notrunc if=bootloader.bin of=fat.img

谢谢!

最佳答案

作为commented by Shift_Left您 BPB 中的所有内容都在错误的位置。

  • BIOS 参数 block 必须从引导扇区内的偏移量 3 开始。
    偏移量 0 处的跳转指令可以是近跳转(jmp near start)或短跳转后跟填充nop 指令(jmp short start > nop).

  • BPB 包含 3 个字符串字段,并且您已将它们全部定义为短 1 个字符!

    iOEM          db "ShapeOS "     ; Must have 8 characters!
    acVolumeLabel db "MYVOLUME " ; Must have 11 characters!
    acFSType db "FAT16 " ; Must have 8 characters!

鉴于引导扇区将位于线性地址 7C00h 的内存中,并且您将 DS 段寄存器初始化为 07C0h,最好使用 ORG 0< 汇编此代码 指令在顶部。

ORG 0
BITS 16

jmp near start

iOEM db "ShapeOS "
iSectSize dw 0x200 ; bytes / sector
iClustSize db 1 ; 1 sector per cluster (for simplicity)
iResCnt dw 1 ; number of reserved sectors
iFatCnt db 2 ; # of fat copies
iRootSize dw 224 ; size of root dir
iTotalSect dw 2880 ; total sectors
iMedia db 0xF0 ; media descriptor
iFatSize dw 9 ; size of each FAT
iTrackSect dw 9 ; sectors per track
iHeadCnt dw 2 ; number of r/w heads
iHiddentSect dd 0 ; number of hidden sectors
iSect32 dd 0 ; number of > 32MB sectors
iBootDrive db 0 ; holds drive of bootsector
iReserved db 0 ; empty reserved attribute
iBootSign db 0x29 ; extended bootsig
iVolID db "seri" ; disk serial
acVolumeLabel db "MYVOLUME " ; volume label
acFSType db "FAT16 " ; fs type

start:

关于assembly - 使用引导扇区作为 MBR 创建 FAT 分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48464600/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com