[Solved]Load trampoline code

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
User avatar
Mano
Posts: 8
Joined: Mon Jan 09, 2012 4:52 am
Location: Brazil

[Solved]Load trampoline code

Post 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.
Last edited by Mano on Wed Aug 29, 2012 6:55 am, edited 1 time in total.
sounds
Member
Member
Posts: 112
Joined: Sat Feb 04, 2012 5:03 pm

Re: Load trampoline code

Post 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.
User avatar
Mano
Posts: 8
Joined: Mon Jan 09, 2012 4:52 am
Location: Brazil

Re: Load trampoline code

Post 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?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Load trampoline code

Post 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.
If a trainstation is where trains stop, what is a workstation ?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Load trampoline code

Post 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
User avatar
Mano
Posts: 8
Joined: Mon Jan 09, 2012 4:52 am
Location: Brazil

Re: Load trampoline code

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