Stack pb when CPL switching

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
pini

Stack pb when CPL switching

Post by pini »

I'm switching from CPL3 to CPL0 when I receive an IRQ0. Here's my IRQ0 handler :

Code: Select all

int_irq0:
   cli
   push   eax
   call   task_tick
   test   eax,eax
   jnz   .nosw
   mov   eax,[tss.esp0] ; (*)
   cli
   hlt
well, task_tick is a simple C function that returns 0 if the current process has running its time out and .nosw is a label defined somewhere below.

the line (*) give 0x10C1BC to EAX, which is correct according to what the TSS.ESP0 field should contain, but ESP is 0x10C1A4 (0x10C1A8 without the push eax).

Shouldn't ESP be 0x10C1B8 = 0x10C1BC - 4 (push eax) ?
Where am I wrong ?
pini

Re:Stack pb when CPL switching

Post by pini »

I got the answer : ESP is loaded with TSS.ESP0 before pushing SS, ESP, EFLAGS, CS and EIP onto the stack
Post Reply