Page 1 of 1

[Solved]Load trampoline code

Posted: Tue Aug 28, 2012 9:50 pm
by Mano
I decided to try to make my OS support more than one processor. So I started reading the Intel manuals and some doubts appeared along the way.

As far as I could understand, at some point I'll have to send a SIPI from the BSP to the APs with the vector value "pointing" to the trampoline code, in order to set the GDT and switch the AP to pmode. If I understood correctly, when I send the SIPI, I must set the vector value, so the AP will execute the code located at the physical addres 000V V000H (where VV is the 8-bit vector value).

Because the APs are in real mode, I believe the trampoline code must be below the 1mb mark. But I can't load code under the 1mb mark using GRUB. So I'm thinking of a way to accomplish that.

I thought I could create the trampoline code, and use a linker script to generate a raw binary executable under the 1mb mark. Then I could load it as a GRUB module to a random position, and then move it (the entire module) to the 1mb below mark. Once the code was linked to run under this mark, it should work.

But I'm not pretty sure it will work. So I wonder if there's a better way to do it.

Re: Load trampoline code

Posted: Tue Aug 28, 2012 10:06 pm
by sounds
Most kernels do not send a SIPI and boot a second processor until after they are done with GRUB - completely finished and never going back.

That means the kernel is in charge of all memory, so it has control over what is below 1mb.

Re: Load trampoline code

Posted: Wed Aug 29, 2012 5:39 am
by Mano
sounds wrote:Most kernels do not send a SIPI and boot a second processor until after they are done with GRUB - completely finished and never going back.

That means the kernel is in charge of all memory, so it has control over what is below 1mb.
Thank you sounds for your reply. It really sounds the ideal sollution.

If by most kernels you mean all kernels that support MP, the then I'll have to write my own bootloader. But if there's someone who is using GRUB, and supporting multiprocessor, I'd like to know how he's doing that.

Once GRUB executes my kernel, it(the kernel) is in charge of all the memory, isn't it?

Re: Load trampoline code

Posted: Wed Aug 29, 2012 6:10 am
by gerryg400
I don't understand the problem.

Grub loads your kernel. Then your kernel takes over all of memory and can copy the trampoline code into position below 1MB.

Re: Load trampoline code

Posted: Wed Aug 29, 2012 6:45 am
by AJ
Hi,

As gerryg400 says, just copy the trampoline code to wherever you need it. If you are asking about this because GRUB is storing data structures below 1MiB, simply ensure that you have cached everything you need from GRUB before booting the AP.

Cheers,
Adam

Re: Load trampoline code

Posted: Wed Aug 29, 2012 6:55 am
by Mano
I was afraid there's something wrong with this idea, and that someone would eventually point it out. But it looks like it's no case.
Thanks once again. I'll cache the GRUB structures somewhere else before moving the trampoline then.