Page 1 of 1

whats a good WORKING fat12 32bit bootsector

Posted: Mon Jul 17, 2006 12:43 am
by earlz
I was using bootf02 but now I've made the discovery its using page tables which is the apparent reason why so much of my stuff has not worked, and I just noticed this after I already have a fair amount of stuff in my OS

so now I'm looking for a boot sector, could anyone give me a recommendation?

edit:
also it needs to load the kernel at rather 1mb or 2mb



edit2:
I tried this code to disable paging but it just gives a triple fault when I do the mov to cr0 (never gets to the hlt)

Code: Select all

"mov eax,cr0\n"
"and eax,0x7FFFFFFF\n"
"mov cr0,eax\n" //and voila! no paging crap
"hlt\n"

Re:whats a good WORKING fat12 32bit bootsector

Posted: Mon Jul 17, 2006 2:13 am
by Jamethiel
If you take bootf02, and open up bootf.asm, you should be able to customize its behavior a bit.

For example, if you want your kernel to be loaded at the 1 meg mark, look for the label "read_sectors:", and you'll see a jmp dword instruction above it. Change the offset from 0xff800000 to 0x00100000. About six lines above that there's an or eax, 0x80000001. Change that to or eax, 1. Now your kernel loads at the 1 meg mark, and paging is disabled.

Loading at the 2 meg mark is only slightly trickier. Instead of using 0x00100000, use 0x00200000; and look for the label "found:". About six or seven lines below that, there's a mov esi, 0x100000-0x40000. Change the 0x100000 to a 0x200000, and you're now loading at 2 megs.

Heck, you could go in with a hex editor on the binary and make these changes. At offset 0x159 is the dword address 0xff800000, at offset 0x14a is the cr0 change constant of 0x80000001, and at offset 0xd0 is the 0xc0000 which is 0x100000-0x40000 (change it to 0x1c0000 if you want to load to the 2 meg mark).

Hope this helps.

Re:whats a good WORKING fat12 32bit bootsector

Posted: Mon Jul 17, 2006 2:19 am
by B.E
Have a go making your own

Re:whats a good WORKING fat12 32bit bootsector

Posted: Mon Jul 17, 2006 2:30 am
by Jamethiel
B.E wrote: Have a go making your own
That can be quite educational. I recently hacked up my older (non-filesystem) floppy bootsector to read the entire disk image up to the 1 meg mark and then find a kernel in the (FAT12) disk image, copy it to the 0x268000 mark, and jump to it there. I get my kernel loaded and an initialized ramdisk in one go. Means I can write a filesystem driver long before I have to write disk drivers. Now if I could just wedge a multiboot header in the bootsector as well...

Re:whats a good WORKING fat12 32bit bootsector

Posted: Mon Jul 17, 2006 9:40 am
by earlz
If you take bootf02, and open up bootf.asm, you should be able to customize its behavior a bit.

For example, if you want your kernel to be loaded at the 1 meg mark, look for the label "read_sectors:", and you'll see a jmp dword instruction above it. Change the offset from 0xff800000 to 0x00100000. About six lines above that there's an or eax, 0x80000001. Change that to or eax, 1. Now your kernel loads at the 1 meg mark, and paging is disabled.

Loading at the 2 meg mark is only slightly trickier. Instead of using 0x00100000, use 0x00200000; and look for the label "found:". About six or seven lines below that, there's a mov esi, 0x100000-0x40000. Change the 0x100000 to a 0x200000, and you're now loading at 2 megs.

Heck, you could go in with a hex editor on the binary and make these changes. At offset 0x159 is the dword address 0xff800000, at offset 0x14a is the cr0 change constant of 0x80000001, and at offset 0xd0 is the 0xc0000 which is 0x100000-0x40000 (change it to 0x1c0000 if you want to load to the 2 meg mark).

Hope this helps.
the main problem with that is that the source became broken assumingly because of changes in nasm

Re:whats a good WORKING fat12 32bit bootsector

Posted: Mon Jul 17, 2006 9:49 am
by Jamethiel
the main problem with that is that the source became broken assumingly because of changes in nasm
So it's a good thing I included instructions for making a binary patch with a hex editor, right?

(If you're on a windows box you can use DEBUG. If you're on almost any other host environment there's emacs hexl-mode. Or if you have your own preferred hex editor, you can use that.)

Re:whats a good WORKING fat12 32bit bootsector

Posted: Mon Jul 17, 2006 10:06 am
by earlz
hmmmm not much experience with opcodes but i'll give it a swing with XVI32
*prays to god that it didn't use ModR/M bytes

Re:whats a good WORKING fat12 32bit bootsector

Posted: Mon Jul 17, 2006 10:19 am
by bluecode
Jordan3 wrote:so now I'm looking for a boot sector, could anyone give me a recommendation?
I can recommend grub.

Or why don't you fix the source of bootf02 so that it compiles with the newest nasm. You might also want to give yasm a try. Perhaps this assembler can do the job.

Re:whats a good WORKING fat12 32bit bootsector

Posted: Mon Jul 17, 2006 10:24 am
by Jamethiel
the main problem with that is that the source became broken assumingly because of changes in nasm
You mean errors like this?

Code: Select all

bootf.asm:62: warning: ignoring unknown section attribute: "USE16"
bootf.asm:69: warning: uninitialised space declared in START section: zeroing
bootf.asm:325: warning: uninitialised space declared in START section: zeroing
If that's what you're seeing, try adding -f obj to the nasm command line before the source file name, and getting jloc to convert the resulting .obj to a .bin.

Re:whats a good WORKING fat12 32bit bootsector

Posted: Mon Jul 17, 2006 10:57 am
by earlz
well I got it hex edited'd so now it works fine except for now my kernel don't work fine for some reason it will not call printf but it does hlt(and jump to _main)

Re:whats a good WORKING fat12 32bit bootsector

Posted: Mon Jul 17, 2006 1:33 pm
by Ryu
Jordan3 wrote: well I got it hex edited'd so now it works fine except for now my kernel don't work fine for some reason it will not call printf but it does hlt(and jump to _main)
Most likely because CS is set wrong, causes absolute returns to return incorrectly. What you can do is use this sort of "breakpoint" cli and hlt to check if your CS is in the correct code segment base with your binary. If not, you can do a jump far before any absolute jumps or any calls is made, which allows you to correctly set CS.

Re:whats a good WORKING fat12 32bit bootsector

Posted: Wed Jul 19, 2006 11:11 pm
by earlz
its probably CS stuff but well I have to make my own bootsector anyway since I'm supporting my own FS on me so anyway