自定义引导加载程序问题
我正在尝试为业余爱好操作系统编写一个引导加载程序,并让它运行良好。 没什么特别的,只是打印一行文本:
BITS 16
ORG 0
start: jmp main
OEM db "Test OS "
BytesPerSector: DW 512
SectorsPerCluster: DB 1
ReservedSectors: DW 1
NumberOfFATs: DB 2
RootEntries: DW 224
TotalSectors: DW 2880
Media: DB 0xf8
SectorsPerFAT: DW 9
SectorsPerTrack: DW 18
HeadsPerCylinder: DW 2
HiddenSectors: DD 0
TotalSectorsBig: DD 0
DriveNumber: DB 0
Unused: DB 0
ExtBootSignature: DB 0x29
SerialNumber: DD 0xa0a1a2a3
VolumeLabel: DB "HOBBY OS "
FileSystem: DB "FAT12 "
main:
;Adjust code Seg.
cli
mov ax, 0x07c0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
;Set up Stack
mov ax, 0x0000
mov ss, ax
mov sp, 0xFFFF
sti
mov si, msg
call print
print:
.charLoop:
lodsb
or al,al
jz .done
mov ah, 0x0E
int 0x10
.done
ret
msg db "Hello World",13,10,0
Im 编译
nasm -f bin loader.asm -o loader.bin
dd if=loader.bin of=floppy.img bs=512 count=1 seek=0
我读到前 446 字节是引导代码,字节 447 - 509 是分区表。 然后我尝试使用:
dd if=loader.bin of=floppy.img bs=446 count=1 seek=0
试图防止分区表被覆盖,但仍然没有雪茄。
我使用带有 OSX 的 Mac 并使用 VirtualBox 测试操作系统
我可以在 VBox 中运行 floppy.img 并且代码工作正常,但是当我尝试将引导加载程序安装到 FAT 16 格式化磁盘上时,OSX 似乎无法读取磁盘图像不再像未格式化一样。
磁盘实用程序发出的确切消息是无法附加映像“floppy.img。”(没有可安装的文件系统)
即使我刚刚使用 FAT 16 文件系统格式化了磁盘。
不幸的是,由于这是我的第一篇文章,我无法给你图片。
我真的很感激任何帮助。磁盘结构确实不是我的强项。
Im trying to write a bootloader for a Hobby OS and have it working great.
Nothing Special, just prints a line of text:
BITS 16
ORG 0
start: jmp main
OEM db "Test OS "
BytesPerSector: DW 512
SectorsPerCluster: DB 1
ReservedSectors: DW 1
NumberOfFATs: DB 2
RootEntries: DW 224
TotalSectors: DW 2880
Media: DB 0xf8
SectorsPerFAT: DW 9
SectorsPerTrack: DW 18
HeadsPerCylinder: DW 2
HiddenSectors: DD 0
TotalSectorsBig: DD 0
DriveNumber: DB 0
Unused: DB 0
ExtBootSignature: DB 0x29
SerialNumber: DD 0xa0a1a2a3
VolumeLabel: DB "HOBBY OS "
FileSystem: DB "FAT12 "
main:
;Adjust code Seg.
cli
mov ax, 0x07c0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
;Set up Stack
mov ax, 0x0000
mov ss, ax
mov sp, 0xFFFF
sti
mov si, msg
call print
print:
.charLoop:
lodsb
or al,al
jz .done
mov ah, 0x0E
int 0x10
.done
ret
msg db "Hello World",13,10,0
Im compiling with
nasm -f bin loader.asm -o loader.bin
dd if=loader.bin of=floppy.img bs=512 count=1 seek=0
I've read that the first 446 bytes are the boot code and bytes 447 - 509 is the partition table.
I tried then using:
dd if=loader.bin of=floppy.img bs=446 count=1 seek=0
to try to prevent the partition table from being overwritten but still no cigar.
Im using a Mac with OSX and Testing the OS with VirtualBox
I can run the floppy.img in VBox and the code works fine, but when I try to install the bootloader onto a FAT 16 Formatted disk, OSX can't seem read the disk image any more as if it became unformatted.
The exact message out of disk utility is Unable to attach image "floppy.img."(No Mountable File Systems)
Even though I just formatted the disk with a FAT 16 file system.
Unfortunatly since this is my first post, I can't give you a picture.
I would really appreciate any help. Disk structure really isn't my forte.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用
dd
时,请尝试添加conv=notrunc
选项。这迫使它不会尝试截断文件,而是仅覆盖您指定的部分。When you're using
dd
, try adding theconv=notrunc
option. This forces it to not try to truncate the file, but rather, just overwrite the parts you specified.