Help making a simple bootloader.

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
Edge
Posts: 6
Joined: Thu Jun 23, 2011 2:58 pm

Help making a simple bootloader.

Post by Edge »

Hi guys! I'm developing a kernel that I need to test using a custom made bootloader. I've checked out all the tutorials but I can't seem to find a good example on how to load the kernel.bin file from a certain directory and then jump to it! I'd also like to set the video mode to VGA (BIOS interrupt 0x10 I believe?) AND THEN switch to protected mode. Any suggestions?

P.S. I would like to program this in C, but it's not possible/not practical, I'll stick to good ol assembly.

Thanks in advance!
User avatar
Tobba
Posts: 21
Joined: Fri Mar 18, 2011 3:24 pm

Re: Help making a simple bootloader.

Post by Tobba »

You're (probably) not going to fit more than entering protected mode and reading sectors off the disk within 512 bytes (although, we do have a contest for that)

I suggest using a second stage loader written in C to do the file system stuff

Also, note that, you cant use BIOS interrupts for reading the disk in protected mode, so you will probably need to write your own code for that too
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Help making a simple bootloader.

Post by neon »

Hello,

Most of that can be technically done in C. I believe you also have answered your own question regarding setting the VGA mode -- just issue BIOS INT 0x10 function 0 prior to entering protected mode. I personally do not recommend going into graphics mode so early however.

Regarding your request for an example of loading a file off disk, there are plenty of resources for this. By supporting a filesystem, you can load your program file off disk which can then be executed. Because this is a filesystem detail, you have to look into tutorials for the filesystem.

Assuming you are working on a floppy disk, look for FAT12 reading tutorials--

Wiki link. Look at the external links for additional references.
Very nice info linked from Wiki.
My site, tutorial 6

Hope this helps.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Help making a simple bootloader.

Post by bluemoon »

Tobba wrote:You're (probably) not going to fit more than entering protected mode and reading sectors off the disk within 512 bytes (although, we do have a contest for that)
I can enable A20, load a kernel.bin from FAT, and copy to 1M using unreal mode, query memory map, then (re)enable protect mode and jump to kernel, all within a VBR (with is slightly less than 512 bytes with some bytes to store BIOS parameter block, and with 3 bytes to spare :shock:
Someone here may well do more things than that too.

But anyway, I agree to introduce 2nd stage as it give more room for checks, validation, and features.

If you plan to implement in C, you still need a minimal amount of assembly code, which can be inline assembly,
since in C you cannot directly assign values to registers.
Post Reply