I need a sugestion

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
InsightSoft
Member
Member
Posts: 76
Joined: Mon Aug 18, 2008 6:17 am

I need a sugestion

Post by InsightSoft »

This function is invoked by the machine/IDT to dispatch the event (interrupt)...
...and the according with intel manuals, this step occurs first:

Code: Select all

push the eflags of currently task
push the CS
push the EIP
(all informations needed to resume the suspended task)
Here starts my problem...
..it enters to my procedure with this values:

Code: Select all

RSP=00000000000007e8  RBP=00000000000007f0	on entry
						At this stage the stack is already have the return point (see above)

I prepare all I need to dispatch the actual interrupt
RSP=00000000000007e0  RBP=00000000000007f0	push 0 and push 32	
RSP=00000000000007c0  RBP=00000000000007f0	 pusha
RSP=00000000000007bc  RBP=00000000000007f0	  push ds
RSP=00000000000007b8  RBP=00000000000007f0	   push es
RSP=00000000000007b4  RBP=00000000000007f0	    push fs
RSP=00000000000007b0  RBP=00000000000007f0	     push gs
RSP=00000000000007ac  RBP=00000000000007f0	      push eax

RSP=00000000000007a0  RBP=00000000000007a4	       ->enter to high level irq dispatcher
RSP=00000000000007ac  RBP=00000000000007f0             <-on return

RSP=00000000000007b0  RBP=00000000000007f0	      pop eax
RSP=00000000000007b4  RBP=00000000000007f0	     pop gs
RSP=00000000000007b8  RBP=00000000000007f0	    pop fs
RSP=00000000000007bc  RBP=00000000000007f0	   pop es
RSP=00000000000007c0  RBP=00000000000007f0	  pop ds
RSP=00000000000007e0  RBP=00000000000007f0       pusha
RSP=00000000000007e8  RBP=00000000000007f0	add esp, 8
then come the IRET (to finish the interrupt live)

Code: Select all

IRET
And... the system crash
This the result:

Code: Select all

next instruction (IRET) make my system crash!!!
(0) [0x0010066b] 0008:000000000010066b (unk. ctxt): iret                      ; 66cf

00009339262e[CPU0 ] check_cs(0x0010): not a valid code segment !
00009339262i[CPU0 ] CPU is in protected mode (active)
00009339262i[CPU0 ] CS.d_b = 32 bit
00009339262i[CPU0 ] SS.d_b = 32 bit
00009339262i[CPU0 ] EFER   = 0x00000000
00009339262i[CPU0 ] | RAX=0000000000000010  RBX=0000000000000000
00009339262i[CPU0 ] | RCX=00000000000007fb  RDX=0000000007880000
00009339262i[CPU0 ] | RSP=00000000000007e8  RBP=00000000000007f0
00009339262i[CPU0 ] | RSI=0000000000092400  RDI=00000000001023d8
00009339262i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00009339262i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00009339262i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00009339262i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00009339262i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af PF cf
00009339262i[CPU0 ] | SEG selector     base    limit G D
00009339262i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00009339262i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 1 1
00009339262i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00009339262i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00009339262i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 000fffff 1 1
00009339262i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00009339262i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00009339262i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00009339262i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00009339262i[CPU0 ] | RIP=000000000010066b (000000000010066b)
00009339262i[CPU0 ] | CR0=0x60000011 CR1=0x0 CR2=0x0000000000000000
00009339262i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
(0).[9339262] [0x0010066b] 0008:000000000010066b (unk. ctxt): iret                      ; 66cf
00009339262e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00009339262i[SYS  ] bx_pc_system_c::Reset(SOFTWARE) called
00009339262i[CPU0 ] cpu software reset
00009339262i[APIC0] local apic in CPU 0 initializing
We are in the same location (in terms of stack) when the system call this function and the next instruction is iRET (as end of interrupt)
and it is suposed to pick up the pushed values from the stack and resume the task...

But... it crash!!!


But was realy the IP and CS on the stack??? Yes...

before the iret, and to see the real values of stack, I perform some pops and the IP and CS was realy there

Code: Select all

RAX=0000000000000020 	int nr		my pushes
RAX=0000000000000000 	00000		my pushes
RAX=0000000000100c03	ip		system pushed
RAX=0000000000000008	cs		system pushed
If this values are on the stack, why the system crash? Any ideia????
Zoomby
Posts: 6
Joined: Sun Apr 26, 2009 3:36 am

Re: I need a sugestion

Post by Zoomby »

Hi InsightSoft,

Have you tried "iretd", it's the 32-Bit Version of "iret". Same with "pushad" and "popad".

Bye,
Zoomby
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: I need a sugestion

Post by xenos »

As Zoomby said, using iretd instead of iret should fix your problem (and pushad instead of pusha as well). Have a look at this line:

Code: Select all

(0) [0x0010066b] 0008:000000000010066b (unk. ctxt): iret                      ; 66cf
66 CF means you do an interrupt return (CF) with an operand size prefix (66), and since your in 32 bit mode, this causes a 16 bit interrupt return. If you use iretd instead, thare is no operand size prefix, and a 32 bit interrupt return is performed. (And the opcode changes to just CF).
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
ruisleipa
Member
Member
Posts: 46
Joined: Wed Sep 10, 2008 8:39 am
Location: Finland

Re: I need a sugestion

Post by ruisleipa »

InsightSoft wrote:

Code: Select all

...
RSP=00000000000007c0  RBP=00000000000007f0	 pusha
...
RSP=00000000000007e0  RBP=00000000000007f0       pusha
Why are you pushing the registers twice? Shouldn't you pop them instead of pushing in the end of the handler?
http://code.google.com/p/rmmtos/ - Real Mode MultiTasking Operating System
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: I need a sugestion

Post by skyking »

Stupid question(?): Why did you write "pusha" after "pop ds"?
InsightSoft
Member
Member
Posts: 76
Joined: Mon Aug 18, 2008 6:17 am

Re: I need a sugestion

Post by InsightSoft »

Thanks... IRETD works fine...

I am based on Bran's tutorial that use IRET. Why in may case I need to use IRETD??? (Anyway, I have my problem solved)



Thanks
InsightSoft
Member
Member
Posts: 76
Joined: Mon Aug 18, 2008 6:17 am

Re: I need a sugestion

Post by InsightSoft »

skyking wrote:Stupid question(?): Why did you write "pusha" after "pop ds"?
After? or before?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: I need a sugestion

Post by JamesM »

InsightSoft wrote:Thanks... IRETD works fine...

I am based on Bran's tutorial that use IRET. Why in may case I need to use IRETD??? (Anyway, I have my problem solved)



Thanks

Because you're using a different assembler. NASM assumed "iret" is the 32-bit version when you're operating in 32-bit mode. AS does not, it seems.
InsightSoft
Member
Member
Posts: 76
Joined: Mon Aug 18, 2008 6:17 am

Re: I need a sugestion

Post by InsightSoft »

mikkop92 wrote:
InsightSoft wrote:

Code: Select all

...
RSP=00000000000007c0  RBP=00000000000007f0	 pusha
...
RSP=00000000000007e0  RBP=00000000000007f0       pusha
Why are you pushing the registers twice? Shouldn't you pop them instead of pushing in the end of the handler?

the last one is POPA...
InsightSoft
Member
Member
Posts: 76
Joined: Mon Aug 18, 2008 6:17 am

Re: I need a sugestion

Post by InsightSoft »

JamesM wrote:
InsightSoft wrote:Thanks... IRETD works fine...

I am based on Bran's tutorial that use IRET. Why in may case I need to use IRETD??? (Anyway, I have my problem solved)



Thanks

Because you're using a different assembler. NASM assumed "iret" is the 32-bit version when you're operating in 32-bit mode. AS does not, it seems.

Ok James... thanks... (All of you are my hero)
Post Reply