Page 1 of 1

Passing Values from Bootloader to Kernel

Posted: Thu Dec 22, 2011 4:43 am
by mark3094
I've been trying to figure out how to pass values from the boot loader to the Kernel. Eventually I want to be able to pass information about the memory map that I can get in real mode.
I am aware that there is the multiboot standard, but for now I'm not planning on implementing it, as it looks quite complicated. I will get to it one day though.

So far, I can pass a simple integer with something like:

Code: Select all

push dword 1234
and

Code: Select all

int main(int pass) {
	printf ("%d\n", pass);
	...
Am I able to pass a pointer to a structure? For example, can I pass a pointer to the buffer where I'm getting int 0x15 to store the memory map?
As a simple test, I created a structure in the bootloader and assigned some random values to its members, but I couldn't get it to pass the correct information.

Am I barking up the wrong tree? Should I invest the time into multiboot?


Thanks

Re: Passing Values from Bootloader to Kernel

Posted: Thu Dec 22, 2011 4:47 am
by Combuster
No, you should learn what the ABI does so you can actually write code that works.

Ever tried bochs' debugger?

Re: Passing Values from Bootloader to Kernel

Posted: Thu Dec 22, 2011 11:26 am
by bluemoon
I put the boot data structure at 0000:0600, which should be safe to use. (it is usually used by MBR for relocating itself).

in the kernel, you just do:

Code: Select all

BOOTDATA* data = (BOOTDATA*)0x0600;
Depends on your bootstrap workflow, if you need to access it after enable paging, you may need to copy it or map it into address space.

EDIT: You probably do not want to have a c code as kernel entry point. Assembly is more convenient for the initial dirty work to setup proper machine states and C-friendly environment, such as ebp=0 and a valid stack

Re: Passing Values from Bootloader to Kernel

Posted: Fri Dec 23, 2011 5:35 pm
by OSwhatever
Check out Linux kernel parameters. It's a dedicated page(s) for parameters.

http://www.simtec.co.uk/products/SWLINU ... tml#d0e428

All structures are placed next to each other in this list and each structure has a size. As you have the size you can traverse the parameters like a linked list. I'm not sure why they chose this particular structure, maybe because you can traverse it unmodified regardless if it is relocated or not. Having all parameters next to each other helps as you probably allocate one page or more for all parameters, this makes it easier to return the parameter pages once kernel setup is done and not needed anymore.