Page 1 of 1

The red zone is for...

Posted: Sun Aug 15, 2010 1:48 pm
by Candy
After toying with a non-reactive IOAPIC and an APIC that just won't listen, tens of different kind of ways to screw it up my most recent one is... odd, to say the least.

I compile my code with a regular (crosscompiler) GCC 4.5.0. It uses a red zone that's been specified in the x86_64 ABI. The red zone is the area of 128 bytes below your stack pointer, which is free for use without informing the interrupt handlers.

My problem is that an external interrupt will corrupt that red zone, no matter what I do (other than use IST for stack switching). How did you solve this? I just resorted to -mno-red-zone but I have the feeling there's something wrong with the whole red zone concept.

Re: The red zone is for...

Posted: Sun Aug 15, 2010 3:26 pm
by Combuster
It seems that the mainstream OSes disable the red zone for kernel mode - it works in userspace because you always get a stack switch when interrupted, but its definitely a pain in kernel mode.

Re: The red zone is for...

Posted: Sun Aug 15, 2010 4:13 pm
by Owen
It gives leafs (and non-leafs) a really cheap to access piece of stack. But yes, it doesn't work for x86(_64) kernels, because the processor is stupid and pushes data onto the stack on interrupt.

Re: The red zone is for...

Posted: Sun Aug 15, 2010 11:21 pm
by Candy
mmmkay, that's about what I expected. Thanks!

PS: Managed to send myself an INIT IPI now! Bad idea to do that from your BSP to your BSP - but it works :-)

Re: The red zone is for...

Posted: Sun Aug 22, 2010 2:43 pm
by Darwish
Candy wrote:My problem is that an external interrupt will corrupt that red zone, no matter what I do (other than use IST for stack switching). How did you solve this? I just resorted to -mno-red-zone but I have the feeling there's something wrong with the whole red zone concept.
You may like to check this thread for a very similar case.