Passing Values from Bootloader to Kernel

Programming, for all ages and all languages.
Post Reply
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Passing Values from Bootloader to Kernel

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Passing Values from Bootloader to Kernel

Post by Combuster »

No, you should learn what the ABI does so you can actually write code that works.

Ever tried bochs' debugger?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Passing Values from Bootloader to Kernel

Post 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
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: Passing Values from Bootloader to Kernel

Post 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.
Post Reply