I am following the JamesM tutorial to switch to user mode in my kernel. The tutorial
provides the following function to switch to user mode which uses iret to jump to user mode
by pushing appropriate values on stack.
Code: Select all
void switch_to_user_mode()
{
// Set up a stack structure for switching to user mode.
asm volatile(" \
cli; \
mov $0x23, %ax; \
mov %ax, %ds; \
mov %ax, %es; \
mov %ax, %fs; \
mov %ax, %gs; \
\
mov %esp, %eax; \
pushl $0x23; \
pushl %eax; \
pushf; \
pushl $0x1B; \
push $1f; \
iret; \
1: \
");
}
I call this function directly from my main() function and as expected it fails as I did not make changes to the permissions in page-tables.
It throws a General Protection Exception. However I am unable to understand the error code pushed by the exception which is 0x87F0. According to intel manual
But I have only 5 entries in my GDT (indices 0x0, 0x8, 0x10, 0x18, 0x20). Therefore 0x87F0 does not seem to be a valid selector neither does it seem to be a valid interrupt vector number. From the description of intel manual it doesn't seem that garbage error code can be pushed.If the fault condition was detected while loading a segment descriptor, the error code contains a segment selector to or IDT
vector number for the descriptor; otherwise, the error code is 0.
Is my understanding wrong somewhere ?