3
votes

There seems to be quite a lot of identical information on the Internet about writing the following 3 bootloaders:

  1. Infinite loop jmp $
  2. Print a single character
  3. Print "Hello World".

This is fantastic, and I've gone through these 3 variations with very little trouble.

I'd like to write some 32- or 64-bit code in C and compile it, and call that code from the bootloader... basically a bootloader that, for example, sets the computer up to run some simple numerical simulation. I'll start by listing primes, for example, and then maybe some input/output from the user to maybe compute a Fourier transform. I don't know.

I haven't found any information on how to do this, but I can already foresee some problems before I even begin.

First of all, compiling a C program compiles it into one of several different files, depending on the target. For Windows, it's a PE file. For Linux, it's a .out file. These files are both quite different. In my instance, the target isn't Windows or Linux, it's just whatever I have written in the bootloader.

Secondly, where would the actual code reside? The bootloader is exactly 512 bytes, but the program I write in C will certainly compile to something much larger. It will need to sit on my (virtual) hard disk, probably in some sort of file system (which I haven't even defined!) and I will need to load the information from this file into memory before I can even think about executing it. But from my understanding, all this is many, many orders of magnitude more complex than a 12-line "Hello World" bootloader.

So my question is: How do I call a large 32- or 64-bit program (written in C/C++) from my 16-bit bootloader.

1
I would suggest looking at wiki.osdev.org . You can use BIOS to load more data from disk, then you need to get into protected mode, or long mode for 64-bit. THen you can parse an executable file, or just create a flat binary (gcc/ld can do this) that you can jump directly into.ughoavgfhw

1 Answers

4
votes

This is a huge topic.

You should probably start by learning to enter and know protected mode.