[SOLVED] Getting to Ring 3 in Long Mode
Posted: Wed Feb 28, 2018 12:36 pm
Hi - I'm trying to enter Ring 3 from Long Mode. I have set my GDT up like so (the numbers in brackets are the start bit of that byte):
I then do this to try to enter user mode:
The instruction pointer passed is not mapped into the user-space page tables so I'd expect a page-fault, but instead I'm getting a general-protection fault on the 'iretq' with error code 0xc0 (the user code segment?).
I've checked each GDT descriptor carefully, but clearly I'm missing something?
Code: Select all
0x08 | 00000000(56)-00100000(48)-10011000(40)-00000000(32)-00000000(24)-00000000(16)-00000000(8)-00000000(0) | kernel code
0x10 | 00000000(56)-00100000(48)-10010000(40)-00000000(32)-00000000(24)-00000000(16)-00000000(8)-00000000(0) | kerrnel data
0x18 | 00000000(56)-00100000(48)-11111000(40)-00000000(32)-00000000(24)-00000000(16)-00000000(8)-00000000(0) | user code
0x20 | 00000000(56)-00100000(48)-11110000(40)-00000000(32)-00000000(24)-00000000(16)-00000000(8)-00000000(0) | user data
0x28 | {TSS}
Code: Select all
asm!("cli
push r10
push rsp
pushfq
push r12
push r13
iretq"
:
: "{r10}"(0x20 << 3 | 3), // selector for user data segment
"{r12}"(0x18 << 3 | 3), // selector for user code segment
"{r13}"(instruction_pointer)
:
: "intel", "volatile");
I've checked each GDT descriptor carefully, but clearly I'm missing something?