How to set specific stack uping IRQ

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
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

How to set specific stack uping IRQ

Post by kemosparc »

Hi,

I have a question regarding the stack upon IRQ.

What I understand is that if I am in user mode and an IRQ occurs the first thing that happens is that the processor will switch to the stack pointer address stored in my TSS(RSP0), which in this case should be set to the kernel stack pointer by me prior to switching to user mode. So I guess that the change in DPL forces this symptom to occur.

My question is , If I am not in user mode (kernel mode) is there a way that I can force the processor to do the same thing and switch to stack pointer address stored in the TSS


Thanks
Karim.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: How to set specific stack uping IRQ

Post by Candy »

On IA32 / 32-bit: No.

In AMD64/x86_64: You can't prevent it.
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: How to set specific stack uping IRQ

Post by Combuster »

On AMD64 you have an optional IST, or you can assume the same stack behaviour as 32-bit modes:
If IST field in interrupt gate is not 0, reads IST pointer into RSP.
The use of the IST is not re-entrant however, so if you get the same kind of interrupt or exception twice in a row you're overwriting the same stack and it's impossible to return. Therefore you'll probably want to limit its use to very specific cases.
"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
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: How to set specific stack uping IRQ

Post by Candy »

Combuster wrote:The use of the IST is not re-entrant however, so if you get the same kind of interrupt or exception twice in a row you're overwriting the same stack and it's impossible to return. Therefore you'll probably want to limit its use to very specific cases.
Or you disable interrupts while processing your interrupt. Doesn't help with exceptions, but you should definitely not cause exceptions while processing exceptions either.
Post Reply