GPF on entering usermode
Posted: Thu Feb 12, 2015 12:02 pm
Hi all
I have a problem when switching to usermode. I install the TSS as:
Which I call from the kernel_early_entry() function as:
this happens after I install the GDT. I then create a user address space, map the kernel space into user space (based on code from the BrokenThorn tutorials), and try to execute a test syscall (the syscall is number 0, which calls a twrite() function to write one letter to the screen, taking two parameters: pointer to char string, and it's length):
But it fails miserably with a GPF
I know that I am missing something, but what is it?
I have a problem when switching to usermode. I install the TSS as:
Code: Select all
void tss_install(uint16_t kernel_ss, uint16_t kernel_esp)
{
memset(&tss_entry, 0, sizeof(tss_entry));
tss_entry.ss0 = kernel_ss;
tss_entry.esp0 = kernel_esp;
tss_entry.cs = 0x0b;
tss_entry.ss = 0x13;
tss_entry.es = 0x13;
tss_entry.ds = 0x13;
tss_entry.fs = 0x13;
tss_entry.gs = 0x13;
printf("Flushing the TSS..\n");
tss_flush();
}
Code: Select all
tss_install(0x10, 0);
Code: Select all
.global task_test
task_test:
mov $0x23, %ax #user mode data selector is 0x20 + RPL 3
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
#create stack frame
push $0x23 #SS
push %ebx
push %esp
pushf
push $0x1B #CS user mode code selector is 0x18 + RPL 3
lea (a), %eax
push %eax
iret
a:
mov $0, %eax
mov $72, %ebx
mov $1, %ecx
int $0x80
mov $0, %eax
mov $69, %ebx
mov $1, %ecx
int $0x80
Code: Select all
eip=008048090 ebp=0x0804A058 esp=0x0804A058
General Protection Fault Exception
At address 0x0010F556:0x00010012 EFLAGS [0x00010023] Error [0x00000008]