The red zone is for...

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
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

The red zone is for...

Post 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.
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: The red zone is for...

Post 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.
"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
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: The red zone is for...

Post 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.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: The red zone is for...

Post 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 :-)
User avatar
Darwish
Posts: 21
Joined: Sat Oct 17, 2009 4:32 am

Re: The red zone is for...

Post 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.
For latest news, please check my homepage and my blog.
—Darwish
Post Reply