ESP seems change itself automatically

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
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

ESP seems change itself automatically

Post 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?
CodeCat
Member
Member
Posts: 158
Joined: Tue Sep 23, 2008 1:45 pm
Location: Eindhoven, Netherlands

Re: ESP seems change itself automatically

Post 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.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: ESP seems change itself automatically

Post 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.
Post Reply