Page 1 of 1

ESP seems change itself automatically

Posted: Sun Jan 25, 2009 10:04 am
by blackoil
Hi, my test app runs at ring0, but with different stack address.

Kernel stack = 0x0009FFFF
App stack = 0x008FFFFF

before start the test app, I set ESP to 0x008FFFFF, then use INT IRET instructions to switch.

Code: Select all

InterruptHandler_42:		pop dword [_eip]
				pop ecx
				pop dword [_eflags]

				push 0         ;placeholder
				push dword [_eflags]
				push dword ecx
				push dword 0x00800000

				mov al,EOI
				out PIC8259B_Port_Command,al
				out PIC8259A_Port_Command,al
				iret
I made the app to issue the DE exception,

Code: Select all

InterruptHandler_00:		pushad
				push gs
				push fs
				push ss
				push es
				push ds
				call IDT_00      ;display registers
				pop eax
				pop eax
				pop eax
				pop eax
				pop eax
				popad
				push dword [_eflags]
				push dword 0x8
				push dword [_eip]
				iret
After the DE handler is done, I got back to kernel, but ESP value changes back to kernel stack range automatically. I expect it should be still within app stack range, since I don't performan inter-previlege switch, both ring0. Does anyone know why?

Re: ESP seems change itself automatically

Posted: Sun Jan 25, 2009 10:34 am
by CodeCat
Doesn't the CPU push ESP and SS when there is a privilege level change on interrupt? I think you might be popping them off by accident.

Re: ESP seems change itself automatically

Posted: Sun Jan 25, 2009 10:55 am
by blackoil
yes, my kernel works fine with ring3 app.

I think I just messed up the stack, and it happened the app stack address is equaled to kernel stack address.

And app should run at ring3 only.