您可以使用my boot sector loaders(ldosboot boot.asm 用于 FAT12 / FAT16 FS)和my boot image creation script 来制作一个 1440 KiB 的文件系统映像,其中预加载了您的内核可执行文件和第一个扇区中的加载程序。您还需要my macro collection。这是一个示例 shell 会话,用于克隆存储库并构建映像。这是使用hg (Mercurial) 加载repos,wget 获得我的调试器的版本作为示例程序,Info-ZIP 的解压缩来解压它,NASM 组装加载器和图像,qemu 组装后运行一切。
$ hg clone https://hg.pushbx.org/ecm/lmacros
destination directory: lmacros
requesting all changes
adding changesets
adding manifests
adding file changes
added 143 changesets with 171 changes to 38 files
new changesets 3a982025dd94:323cc150061e
updating to branch default
29 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg clone https://hg.pushbx.org/ecm/ldosboot
destination directory: ldosboot
requesting all changes
adding changesets
adding manifests
adding file changes
added 588 changesets with 650 changes to 15 files (+2 heads)
new changesets 13cf6bb0b5f5:07f4ba0ef8cd
updating to branch default
15 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg clone https://hg.pushbx.org/ecm/bootimg
destination directory: bootimg
requesting all changes
adding changesets
adding manifests
adding file changes
added 88 changesets with 88 changes to 1 files
new changesets 966f8a094eca:fa44558212e7
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ wget https://pushbx.org/ecm/download/ldebug.zip
--2021-11-18 13:05:18-- https://pushbx.org/ecm/download/ldebug.zip
Resolving pushbx.org (pushbx.org)... 2a01:488:66:1000:b01c:1258:0:1, 176.28.18.88
Connecting to pushbx.org (pushbx.org)|2a01:488:66:1000:b01c:1258:0:1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7131575 (6.8M) [application/zip]
Saving to: 'ldebug.zip'
ldebug.zip 100%[=====================>] 6.80M --.-KB/s in 0.03s
2021-11-18 13:05:18 (259 MB/s) - 'ldebug.zip' saved [7131575/7131575]
$ unzip ldebug.zip bin/ldebugu.com
Archive: ldebug.zip
inflating: bin/ldebugu.com
$ nasm -I lmacros/ -I ldosboot/ ldosboot/boot.asm -D_COMPAT_FREEDOS -D_QUERY_GEOMETRY=0 -D_LBA=0 -D_USE_PART_INFO=0 -o boot.bin
ldosboot/boot.asm:420: warning: Possibly crossing 64 KiB boundary while reading file (sector size >= 1024) [-w+user]
ldosboot/boot.asm:1851: warning: FAT12: 18 bytes still available. [-w+user]
$ nasm -I lmacros/ -I bootimg/ bootimg/bootimg.asm -D_BOOTFILE="'boot.bin'" -D_PAYLOADFILE="::rename,'bin/ldebugu.com','KERNEL.SYS'" -o diskette.img
$ qemu-system-i386 -fda diskette.img -boot order=a -curses
bootimg 的文档是in a comment at the top of the main source file。我使用_BOOTFILE 定义(设置为双引号字符串,以便 NASM 接收带引号的字符串)来指示引导扇区文件,并使用主要的 _PAYLOADFILE 定义来指定包含调试器可执行文件,将其重命名为 KERNEL.SYS 所以_COMPAT_FREEDOS 加载器使用的默认名称将找到我们的可执行文件。
除了 FreeDOS 兼容性选择之外,boot.asm 需要一些额外的开关来禁用启动 1440 KiB 软盘映像不需要的功能。这是因为与 FreeDOS 兼容的加载程序需要比我的 (lDOS) 默认值更多的空间。
最后,您指定要加载的文件(KERNEL.SYS 等默认文件或使用boot.asm 定义的_LOAD_NAME 和_LOAD_EXT 指定的文件名中的文件)需要采用正确的格式。 FreeDOS 加载协议相当简单:您的整个文件被加载到地址 600h,可使用分段地址 60h:0 寻址,并且cs:ip 被设置为 60h:0。寄存器bl 接收您从中引导的ROM-BIOS 单元,ss:bp 指向内存中某处FS 引导扇区的副本。所有其他寄存器,尤其是段寄存器,都是不确定的,如果你想使用它们,必须由你的代码初始化。
请注意,FreeDOS 加载协议与此级别的大多数其他加载协议不同,bl 设置为加载单元。根据使用的加载程序,dl 可能与bl 不同,在这种情况下bl 是正确的,dl 是不正确的。加载单元也可以在 ss:bp 指向的引导扇区副本中找到,在 FAT32 的 byte [ss:bp + 40h] 或 FAT12 和 FAT16 的 byte [ss:bp + 24h] 中。