Writing Floppy Images On a Mac

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Writing Floppy Images On a Mac

Post by Nathan »

Hello,
I'm using Mac OS X 10.6.6(at a Macbook Pro) to develop my OS now, but I have two files that I've compiled with NASM, one that is the boot loader, so it needs to be wrote at 0x7C00 and another that is the OS, which should be placed at 0x1000. How can I make this?

Best Regards,
Nathan Paulino Campos
Yargh
Member
Member
Posts: 56
Joined: Sat Jun 12, 2010 9:04 pm
Location: Somewhere else.

Re: Writing Floppy Images On a Mac

Post by Yargh »

I believe that the dd utility comes preinstalled on 10.6 (it did on 10.5 iirc). If not, download the latest Xcode and it should install it. Also, http://wiki.osdev.org/Linker_Scripts
Wait... What?
User avatar
Nathan
Member
Member
Posts: 201
Joined: Sun Jul 19, 2009 1:48 pm
Location: Brazil
Contact:

Re: Writing Floppy Images On a Mac

Post by Nathan »

But how to use dd as I need?
Yargh
Member
Member
Posts: 56
Joined: Sat Jun 12, 2010 9:04 pm
Location: Somewhere else.

Re: Writing Floppy Images On a Mac

Post by Yargh »

If you already have the bootloader set up to load the OS to a certain address, all you have to do is, assuming your bootloader is 512 bytes:

Code: Select all

dd if=<bootloader> of=floppy.img bs=512
dd if=<OS> of=floppy.img seek=1 conv=notrunc bs=512
as far as I can remember.
Wait... What?
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Writing Floppy Images On a Mac

Post by turdus »

Nathan wrote:Hello,
I'm using Mac OS X 10.6.6(at a Macbook Pro) to develop my OS now, but I have two files that I've compiled with NASM, one that is the boot loader, so it needs to be wrote at 0x7C00 and another that is the OS, which should be placed at 0x1000. How can I make this?

Best Regards,
Nathan Paulino Campos
Some confusion:
1st: don't assume floppy image position is the same as memory position.
2st: the 1st sector (512 bytes) of your image will be loaded at 0x7C00 by the bios, everything else has to be done.

So basically you'll have to do:
1. relocate your boot loader from 0x7C00 to let's say 0x800, otherwise your kernel would be limited in size to 29k (0x1000-0x7C00)
2. your boot loader has to load your kernel from disk to 0x1000 (could be tricky)
3. your boot loader has to parse the kernel header at 0x1000 to find the entry point and jump to it

Because it's quite a challange to put all of this in a few bytes (~400 bytes), it's quite common to use a stage2 boot loader. So bios loads the stage1 boot loader (512 bytes) to 7C00, and it loads a bigger stage2 (usually less than 64k) that it smart enough to browse a filesystem to find and load the real kernel. I say that it's difficult, but not impossible, old DOS boot loaders parsed the FAT12/16/32 filesystem for io.sys and msdos.sys (the kernel) with a code less than 512 bytes. WinXP and above uses the stage2 scheme, and stage2 is called NTLDR in M$ terminology.
Post Reply