Hi,
I don't want to create another thread about entering user mode but in my case I get immediate GPF when entering user mode.
I have set up GDT entries for user mode and TSS. I wanted to try to enter Ring 3 with interrupts disabled (just to be sure I can enter it).
Code: Select all
asm(".intel_syntax noprefix\n\t"
"cli \n"
"mov ax, 0x23 \n"
"mov ds, ax \n"
"mov es, ax \n"
"mov fs, ax \n"
"mov gs, ax \n"
"mov ebx, 0x23 \n"
"push ebx \n"
"push esp \n"
"pushfd \n"
"pop eax \n"
"and eax, 0xFFFFFDFF \n" ; turn IF flag to not generate interrupts
"push eax \n"
"mov ebx, 0x1B \n"
"push ebx \n"
"lea eax, [a] \n"
"push eax \n"
"iretd \n"
"a: \n"
"jmp a \n" ; infinite loop
"add esp, 4 \n"
"xor eax, eax \n"
"lea ebx, [testStr] \n"
"int 0x80 \n"
".att_syntax prefix");
However I get:
Code: Select all
00046662829i[CPU0 ] CPU is in protected mode (active)
00046662829i[CPU0 ] CS.mode = 32 bit
00046662829i[CPU0 ] SS.mode = 32 bit
00046662829i[CPU0 ] EFER = 0x00000000
00046662829i[CPU0 ] | EAX=c0006fbd EBX=0000001b ECX=000004b0 EDX=c000b174
00046662829i[CPU0 ] | ESP=c02ff838 EBP=c0300000 ESI=00000010 EDI=c02ffe10
00046662829i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf SF zf af PF cf
00046662829i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00046662829i[CPU0 ] | CS:001b( 0003| 0| 3) 00000000 ffffffff 1 1
00046662829i[CPU0 ] | DS:0023( 0004| 0| 3) 00000000 ffffffff 1 1
00046662829i[CPU0 ] | SS:0023( 0004| 0| 3) 00000000 ffffffff 1 1
00046662829i[CPU0 ] | ES:0023( 0004| 0| 3) 00000000 ffffffff 1 1
00046662829i[CPU0 ] | FS:0023( 0004| 0| 3) 00000000 ffffffff 1 1
00046662829i[CPU0 ] | GS:0023( 0004| 0| 3) 00000000 ffffffff 1 1
00046662829i[CPU0 ] | EIP=c0006fbd (c0006fbd)
00046662829i[CPU0 ] | CR0=0xe0000011 CR2=0xfffffffc
00046662829i[CPU0 ] | CR3=0x00132000 CR4=0x00000000
(0).[46662829] [0x0000000000406fbd] 001b:00000000c0006fbd (unk. ctxt): jmp .-2 (0xc0006fbd) ; ebfe
00046662829e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
00046662829i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
00046662829i[CPU0 ] cpu hardware reset
As you can see I have good RPL and all segments point to GDT entries for user mode.
What could cause GPF here? Or maybe I should ask: how can I check GPF error?
Bochs resets the machine after fault and I can't access registers prior to error :/