bootloader question

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
nandor
Posts: 2
Joined: Sun Jan 04, 2009 12:51 pm

bootloader question

Post 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?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: bootloader question

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
nandor
Posts: 2
Joined: Sun Jan 04, 2009 12:51 pm

Re: bootloader question

Post by nandor »

but you don't know how to write to the boot sector of the memory stick?
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: bootloader question

Post 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!
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: bootloader question

Post 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
Last edited by neon on Sun Jan 04, 2009 1:27 pm, edited 3 times in total.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: bootloader question

Post by Troy Martin »

neon: I think he's talking about one of those USB sticks, not something you'd stick into a RAM slot.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: bootloader question

Post 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.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: bootloader question

Post by Dex »

Post Reply