Page 1 of 1

Bootable floppies

Posted: Sun Mar 18, 2007 11:41 am
by ehird
So I'm writing a Makefile early to automate bootable floppy creation. I have the loader.s+kernel.c-linked "kernel" ELF binary, loader.o, and kernel.o. Plus, a FAT12 blank floppy image.

Code: Select all

00000000  EB 3C 90 42 53 44 20 20 34 2E 34 00 02 01 01 00 .<.BSD  4.4.....
00000010  02 00 02 40 0B F0 09 00 20 00 10 00 00 00 00 00 ...@.... .......
00000020  00 00 00 00 00 00 29 D8 18 79 A2 4E 4F 20 4E 41 ......)..y.NO NA
00000030  4D 45 20 20 20 20 46 41 54 31 32 20 20 20 FA 31 ME    FAT12   .1
00000040  C0 8E D0 BC 00 7C FB 8E D8 E8 00 00 5E 83 C6 19 .....|......^...
00000050  BB 07 00 FC AC 84 C0 74 06 B4 0E CD 10 EB F5 30 .......t.......0
00000060  E4 CD 16 CD 19 0D 0A 4E 6F 6E 2D 73 79 73 74 65 .......Non-syste
00000070  6D 20 64 69 73 6B 0D 0A 50 72 65 73 73 20 61 6E m disk..Press an
00000080  79 20 6B 65 79 20 74 6F 20 72 65 62 6F 6F 74 0D y key to reboot.
00000090  0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000A0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000B0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000C0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000D0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000E0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000F0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000100  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000110  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000120  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000130  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000140  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000150  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000160  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000170  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000180  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000190  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001A0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001B0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001C0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001D0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001E0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001F0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA ..............U.
00000200  F0 FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
And then it's just zeroed out beyond that. Presumably, from the "non-system disk" part, around there is the boot code. But where do I inject my kernel (byte starting position) to overwrite that, but leave it a valid floppy?

Any help appreciated :)

Re: Bootable floppies

Posted: Sun Mar 18, 2007 12:20 pm
by urxae
The first 2 bytes (EB 3C) are a jump to byte <edit>#3E</edit>. Everything from there to the strings (i.e. FA 31 .. CD 19) is the boot code. The strings (plus one zero-byte after them) are data for that boot code.
So you should be able to replace bytes <edit>#3E to #1FD</edit> by your own boot code.

(edited to fix mistake, see post below)

Posted: Sun Mar 18, 2007 12:21 pm
by ehird
Thanks!

Edit: Maybe I'm stupid, but I can't find "1 FD", "1F D", etc. anywhere in that...

Edit: Oh, do you mean 1F0?

Posted: Sun Mar 18, 2007 2:44 pm
by gaf
Oh, do you mean 1F0?
Most likely he's refering to the index of the bytes in the bootsector. Byte 0x3C should be number 13 in row 4 (00000030 on the left) and 0x01FD is just before the final signature (000001F0 -> "0x55 0xAA")

regards,
gaf

Posted: Mon Mar 19, 2007 6:40 am
by urxae
gaf wrote:
Oh, do you mean 1F0?
Most likely he's refering to the index of the bytes in the bootsector. Byte 0x3C should be number 13 in row 4 (00000030 on the left) and 0x01FD is just before the final signature (000001F0 -> "0x55 0xAA")
Yes, those were indexes not values :).
Unfortunately, I also got the first one wrong. That should've been byte number 0x3E, not 0x3C. I got confused with the relative jump, it seems. (even though I disassembled that code :roll:)

Re: Bootable floppies

Posted: Mon Mar 19, 2007 12:44 pm
by Candy
ehird wrote:And then it's just zeroed out beyond that.
Shouldn't be, since you didn't see the second FAT nor the MFT.