Technical Information about the i386 Boot Loader


Segment Selectors in the GDT

All of the segments defined by the boot loader allow use of the entire 32-bit address space from 0-4GB. In the following descriptions, kernel means ring 0 and user means ring 3.

Returning to DOS

To return cleanly to DOS, you need to make sure that:

You don't need to worry about the last two items, unless you've changed the GDT or the PIC registers (you can't do this without some serious effort, so don't worry about it until we get there). However, staying out of the lower 1MB of memory is a bit tougher, even with NULL references taken care of.

The easiest way to return to DOS is simply to leave the _start() function. However, this may not be possible in an exception handler before you have context switching. So, an alternative method (and also a very messy one) is to save the frame pointer (%ebp) in the _start() function to a global variable, and then restore that value plus 4 to the stack register (%esp), immediately followed by a return. This looks like this:

where oldEBP is a global variable defined as int.

You can get a copy of the Executable and Linking Format (ELF) specification here.

Source Code

Check out the assembly source code for the boot loader.