error at iret

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
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

error at iret

Post by david »

I wrote a trap, but the return is error, error at iret.
the trap source code is:

Code: Select all

IDT_32	proc	near

	mov ax, GDT_Video_Sel
	mov gs, ax
	mov bx, (9 * 80 + 5) * 2	; row 9, col 5
	mov al, 'C'
	mov ah, 14
	mov gs:[bx], ax

	iret
IDT_32	endp
the call code is:

Code: Select all

	mov ax, GDT_Stack_Sel
	mov ss, ax
	mov sp, 0FFFEh

; test stack
	push eax
	push ebx
	pop ebx
	pop eax
	
	int 32
but when i debug it, it error at iret.

I found a problem when i debug it,

Code: Select all

<bochs:12> s
Next at t=2082176
(0) [0x00007de5] 0008:00000000000001e5 (unk. ctxt): int 0x20                  ;
cd20
<bochs:13> dump_cpu
eax:0x00000018, ebx:0x0000032a, ecx:0x00000000, edx:0x00000000
ebp:0x00000000, esp:0x0000fffe, esi:0xffff88ca, edi:0x00080000
eip:0x000001e5, eflags:0x00000002, inhibit_mask:0
cs:s=0x0008, dl=0x7c00ffff, dh=0x00009a00, valid=1
ss:s=0x0018, dl=0x0000ffff, dh=0x00009200, valid=7
ds:s=0x07c0, dl=0x7c00ffff, dh=0x00009300, valid=1
es:s=0x07c0, dl=0x7c00ffff, dh=0x00009300, valid=1
fs:s=0x0000, dl=0x0000ffff, dh=0x00009300, valid=1
gs:s=0x0020, dl=0x8000ffff, dh=0x0000920b, valid=5
ldtr:s=0x0000, dl=0x00000000, dh=0x00000000, valid=0
tr:s=0x0000, dl=0x00000000, dh=0x00000000, valid=0
gdtr:base=0x00007c08, limit=0x1000
idtr:base=0x00007c40, limit=0x800
dr0:0x00000000, dr1:0x00000000, dr2:0x00000000
dr3:0x00000000, dr6:0xffff0ff0, dr7:0x00000400
cr0:0x00000011, cr1:0x00000000, cr2:0x00000000
cr3:0x00000000, cr4:0x00000000
done

Code: Select all

<bochs:17> s
Next at t=2082177
(0) [0x00007d59] 0028:0000000000000000 (unk. ctxt): mov ax, 0x0020            ;
b82000
<bochs:18> x /16bx 0xfff0
[bochs]:
0x0000fff0 <bogus+       0>:    0x00    0x00    0xe7    0x01    0x00    0x00
0x08    0x00
0x0000fff8 <bogus+       8>:    0x00    0x00    0x02    0x00    0x00    0x00
0x00    0x00
the cs's value is 0x0008, but the value is 0x00000008 in the stack, why?

the stak's base address is 0, the limit is 0xFFFF, read/write.

the error information is:

Code: Select all

<bochs:20> s 6
Next at t=2082183
(0) [0x00007d68] 0028:000000000000000f (unk. ctxt): iret                      ;
cf
<bochs:21> s
00002082183e[CPU0 ] iret: return CS selector null
00002082183i[CPU0 ] protected mode
00002082183i[CPU0 ] CS.d_b = 16 bit
00002082183i[CPU0 ] SS.d_b = 16 bit
00002082183i[CPU0 ] EFER   = 0x00000000
00002082183i[CPU0 ] | RAX=0000000000000e43  RBX=00000000000005aa
00002082183i[CPU0 ] | RCX=0000000000000000  RDX=0000000000000000
00002082183i[CPU0 ] | RSP=000000000000fff2  RBP=0000000000000000
00002082183i[CPU0 ] | RSI=00000000ffff88ca  RDI=0000000000080000
00002082183i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00002082183i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00002082183i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00002082183i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00002082183i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af pf cf
00002082183i[CPU0 ] | SEG selector     base    limit G D
00002082183i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00002082183i[CPU0 ] |  CS:0028( 0005| 0|  0) 00007d59 0000ffff 0 0
00002082183i[CPU0 ] |  DS:07c0( 0005| 0|  0) 00007c00 0000ffff 0 0
00002082183i[CPU0 ] |  SS:0018( 0003| 0|  0) 00000000 0000ffff 0 0
00002082183i[CPU0 ] |  ES:07c0( 0005| 0|  0) 00007c00 0000ffff 0 0
00002082183i[CPU0 ] |  FS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00002082183i[CPU0 ] |  GS:0020( 0004| 0|  0) 000b8000 0000ffff 0 0
00002082183i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00002082183i[CPU0 ] |  MSR_GS_BASE:00000000000b8000
00002082183i[CPU0 ] | RIP=000000000000000f (000000000000000f)
00002082183i[CPU0 ] | CR0=0x00000011 CR1=0x0 CR2=0x0000000000000000
00002082183i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00002082183i[CPU0 ] >> iret  : CF
00002082183e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown
 status is 00h, resetting
00002082183i[SYS  ] bx_pc_system_c::Reset(SOFTWARE) called
00002082183i[APIC0] local apic in CPU 0 initializing
00002082183e[CPU0 ] CPU_LOOP bx_guard.interrupt_requested=1
Next at t=2082183
(0) [0x00007d68] 0028:000f (unk. ctxt): iret                      ; cf
Just For Fun
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: error at iret

Post by System123 »

david wrote:00002082183e[CPU0 ] iret: return CS selector null
There it states your problem. Your CS value is 0x00 after iret, I think it is a stack problem. Make sure you are pushing and popping the right number of values. And make sure that the values are the correct length.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

Re: error at iret

Post by david »

yes, you are right, I think so,
but i tested stack before int 32, it's OK,

Code: Select all

; test stack
   push eax
   push ebx
   pop ebx
   pop eax
   
   int 32
Just For Fun
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

Re: error at iret

Post by david »

the cs's value is 0x0008 before int 32.(cs:s=0x0008, dl=0x7c00ffff, dh=0x00009a00, valid=1)
but the value in stack is 0x00000008, I can't understand it.

you know, it will push eflags、 CS and EIP before int interrupt,

Code: Select all

eflags:0x00000002
cs:s=0x0008
eip:0x000001e5


but the value in stack is:

Code: Select all

0x00    0x00    0xe7    0x01    0x00    0x00     0x08    0x00    0x00    0x00    0x02    0x00    0x00    0x00     0x00    0x00
the eflags's and EIP's value are right, but the cs's value is wrong.
Just For Fun
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: error at iret

Post by Combuster »

The stack is 32 bits, hence, CS is pushed as a 32-bits integer to maintain stack alignment (even though its 16 bit)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
frazzledjazz
Posts: 7
Joined: Tue Mar 03, 2009 3:52 pm

Re: error at iret

Post by frazzledjazz »

...resulting in stack overflow. happens with older crt unit in bp7 on faster than 200mhz.

[crt has a 'timing' issue, here its 'stack is too large']
the issues are similar. the crt unit computes 55ms math for timing usage that on 200mhz cpus produces a result that will not fit in a 16bit register, causing RT200.

either use 32 bits registers and use something similar to the realintr() procedure in FPC's dos unit, or maybe C's sysutils or similar unit, or do 16bit math. It looks like the math is too big to fit into your 'container' in the register.
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

Re: error at iret

Post by david »

it's OK now.
IRET changes to IRETD.

when i use int interrupt to call a trap:
Volume 2A_ Instruction Set Reference, A-M.pdf wrote: IF 32-bit gate
THEN
Push(far pointer to old stack);
(* Old SS and ESP, 3 words padded to 4 *)
Push(EFLAGS);
Push(far pointer to return instruction);
(* Old CS and EIP, 3 words padded to 4 *)
Push(ErrorCode); (* If needed, 4 bytes *)
so cs's value in stack is 0x00000008.
Volume 2A_ Instruction Set Reference, A-M.pdf wrote: Opcode Instruction 64-Bit Mode Compat/Leg Mode Description
CF IRET Valid Valid Interrupt return (16-bit operand size).
CF IRETD Valid Valid Interrupt return (32-bit operand size).
REX.W + CF IRETQ Valid N.E. Interrupt return (64-bit operand size).
so i must use IRETD in protected-mode.
Just For Fun
Post Reply