Page 1 of 1 [ 7 posts ] 

kmem
Emu Egg
Emu Egg

User avatar

Joined: 15 Sep 2013
Age: 33
Gender: Male
Posts: 5
Location: USA

16 Nov 2013, 7:40 pm

I say I need help because I don't know where to find a programming community for unexperienced developers. The problem is that I don't want to run into the sites with professional developers that can be rude to any unexperienced developers. The problem that I have with those sites is that I'm not a professtional developer and also have bad social skills. Where I am stuck is understanding the bootloader part of an OS.



one-A-N
Veteran
Veteran

User avatar

Joined: 2 Mar 2010
Age: 69
Gender: Male
Posts: 883
Location: Sydney

16 Nov 2013, 11:03 pm

What would you like to know about boot loaders?

Are you trying to write your own? I have written a couple of boot sectors so I have a little bit of experience and know some of the theory too.



kmem
Emu Egg
Emu Egg

User avatar

Joined: 15 Sep 2013
Age: 33
Gender: Male
Posts: 5
Location: USA

17 Nov 2013, 12:40 am

Yes, I would like to write my own bootloader. I would like to know how to get into protected mode with a 2nd stage bootloader. I haven't written a bootloader yet, because I'm busy trying to understand the CPU data structures.



one-A-N
Veteran
Veteran

User avatar

Joined: 2 Mar 2010
Age: 69
Gender: Male
Posts: 883
Location: Sydney

17 Nov 2013, 3:11 am

A real mode boot loader is not so hard. The code in the boot sector has to load so many sectors from the disk into an arbitrary address in real memory, and then jump to an address in that area.

As long as the boot sector ends with the two bytes 0x55AA you can pretty much put anything you like into the assembly code of the boot sector. Of course it needs to fit inside 512 bytes, so you would typically just load some sectors and jump to the loaded code - or print a message and hang or reboot if there are any errors.

A good experiment is to start with a boot sector that just prints "Hello, world" on the console and then hangs the system (e.g. with a HLT command):

hang:
hlt
jmp hang

Your boot sector code will load into the real mode address 0000:7C00.

You can find example boot sectors online if you need them, or just experiment. You need to use BIOS function calls to write any messages to the console and to read disk sectors into memory.

Once you have a boot sector printing a message, the next thing is to attempt to load an arbitrary sector off the disk into (say) 1000:0000 and then jump to that address and see if the loaded code executes - does it print a message, say? Once you have a boot sector loading a second sector that can write to the console, you can start playing around with switching to protected mode. For that you will need to read some online resources.

You might get some ideas from the following websites:

http://www.supernovah.com/Tutorials/BootSector2.php
http://mikeos.berlios.de/write-your-own-os.html
http://linuxgazette.net/issue77/krishnakumar.html
http://prodebug.sourceforge.net/pmtut.html
http://duartes.org/gustavo/blog/post/ho ... rs-boot-up
http://www.dstoner.net/Computer_Software/ix86OSdoc.html

And this has lots of links to reference information, tutorials, etc:
http://wiki.osdev.org/Main_Page



kmem
Emu Egg
Emu Egg

User avatar

Joined: 15 Sep 2013
Age: 33
Gender: Male
Posts: 5
Location: USA

17 Nov 2013, 4:18 am

Well, I have written a simple bootloader but I haven't written a complicated one yet. I have written a simple bootloader that prints out hello world to the console and loaded disk sectors into memory. From the source code I've seen, is that there is steps to go through before entering protected mode. Where I am confused and haven't figured out yet is some thing about the stack frame and if the idt and gdt uses segments.



Kurgan
Veteran
Veteran

User avatar

Joined: 6 Apr 2012
Age: 35
Gender: Male
Posts: 4,132
Location: Scandinavia

17 Nov 2013, 12:15 pm

Be sure to test the bootloader in a virtual machine before putting it to use. Kernel programming and boot loader programming can be risky, and can crash your system--but in a virtual environment, no significant damage can be done. Virtual Box is free and easy to use.



kmem
Emu Egg
Emu Egg

User avatar

Joined: 15 Sep 2013
Age: 33
Gender: Male
Posts: 5
Location: USA

17 Nov 2013, 7:08 pm

Thank you for the advice. There is also bochs or qemu that are both free to use.