How to force stack switch in interrupt call
Posted: Wed Jul 12, 2017 2:47 am
I'm writing task switching, which must occur on timer interrupt. But some of threads are in ring 0, others - in ring 3.
So, when task switchs from ring0 to ring3: stack don't switch when entering handler, but on exit, CPU extract 2 extra words from stack and ruins it.
TSS is configured: bochs write the following info:
tr:s=0x2b, base=0x00000000ffffd000, valid=1
ss:esp(0): 0x0010:0x00800ff0
ss:esp(1): 0x0000:0x00000000
ss:esp(2): 0x0000:0x00000000
cr3: 0x00000000
eip: 0x00000000
eflags: 0x00000000
cs: 0x0000 ds: 0x0000 ss: 0x0000
es: 0x0000 fs: 0x0000 gs: 0x0000
eax: 0x00000000 ebx: 0x00000000 ecx: 0x00000000 edx: 0x00000000
esi: 0x00000000 edi: 0x00000000 ebp: 0x00000000 esp: 0x00000000
ldt: 0x0000
i/o map: 0x0000
There is written, that when TSS is configured, stack switchs in any case, not only when ring3-code interrupted. But I can't get such behaviour of CPU.
How to force stack switch even if privilege level don't change?
So, when task switchs from ring0 to ring3: stack don't switch when entering handler, but on exit, CPU extract 2 extra words from stack and ruins it.
TSS is configured: bochs write the following info:
tr:s=0x2b, base=0x00000000ffffd000, valid=1
ss:esp(0): 0x0010:0x00800ff0
ss:esp(1): 0x0000:0x00000000
ss:esp(2): 0x0000:0x00000000
cr3: 0x00000000
eip: 0x00000000
eflags: 0x00000000
cs: 0x0000 ds: 0x0000 ss: 0x0000
es: 0x0000 fs: 0x0000 gs: 0x0000
eax: 0x00000000 ebx: 0x00000000 ecx: 0x00000000 edx: 0x00000000
esi: 0x00000000 edi: 0x00000000 ebp: 0x00000000 esp: 0x00000000
ldt: 0x0000
i/o map: 0x0000
There is written, that when TSS is configured, stack switchs in any case, not only when ring3-code interrupted. But I can't get such behaviour of CPU.
How to force stack switch even if privilege level don't change?