Page 1 of 1

bootloader question

Posted: Sun Jan 04, 2009 12:57 pm
by nandor
I'm new to os dev and to assembly programing.I would like to write a simple bootloader,but i have some problems.
I've got source from other tutorials,i compiled them with nasm,but i can't write them to a memory stick.Can someone tell me how to do that?And does anyone know any good PC emulators?

Re: bootloader question

Posted: Sun Jan 04, 2009 1:02 pm
by neon
You dont write the bootloader to a memory stick, you write it to sector 0 on your boot disk. If the bootloader is a multi stage bootloader, you may also need to copy the other files the bootloader relies on to disk as well.

Bochs is probably the best i86 pc emulator out there. There are also virtual machines you can use, such as VMWare, QEMU, and Virtual PC. Keep in mind that if it works on one virtual machine or emulator, it may not work on another. Thus if portability is a concern, I recommend testing it on all of them.

Re: bootloader question

Posted: Sun Jan 04, 2009 1:08 pm
by nandor
but you don't know how to write to the boot sector of the memory stick?

Re: bootloader question

Posted: Sun Jan 04, 2009 1:09 pm
by Troy Martin
Getting Started and Babystep1 will get you going. Note that you're going to need to write the bootloader and anything else you use to a floppy to get it to work!

Re: bootloader question

Posted: Sun Jan 04, 2009 1:22 pm
by neon
nandor wrote:but you don't know how to write to the boot sector of the memory stick?
No because it is not possible. Even if you write the bootloader to a location in usable physical RAM, on the next reboot you would need to rewrite it to RAM again. This defies the purpose of a boot strap program. No i86 pc does this at startup thus if you are writing an i86 pc compatible boot loader, you have no choice but to write it to disk.

*edit: If you are referring to a USB stick, then it is still the same basic concept (Write to sector 0). Thanks Troy for pointing it out :) Cant believe I messed that one :p

Re: bootloader question

Posted: Sun Jan 04, 2009 1:23 pm
by Troy Martin
neon: I think he's talking about one of those USB sticks, not something you'd stick into a RAM slot.

Re: bootloader question

Posted: Sun Jan 04, 2009 1:57 pm
by JohnnyTheDon
To write your bootloader to a USB stick in linux:

dd if=bootloader.bin of=/dev/sdc bs=512 count=x

Replace count with the number of blocks in your bootloader, and /dev/sdc with whatever device is your memory stick.

Re: bootloader question

Posted: Sun Jan 04, 2009 2:04 pm
by Dex