Switching Segments Causes Page Fault
Posted: Mon Nov 14, 2005 6:58 pm
I'm trying to implement user task protection by having my tasks run in ring 3. Before I can do that though I need to at least able to change segments. I try to do this by setting up my stack to use the new segments so that the task switcher pops them into place.
My GDT has the following entries because I haven't even bothered enabling ring 3 yet:
Well my goal is to have my tasks now run on entry 3 (CS) and entry 4 (DS) instead of 1 and 2 like the kernel. 0x18 and 0x20 are my selectors for code and {DS, ES, FS, GS} respectively. Now the problem is, I get a weird page fault when I try to run this code. My tasks are now trying access bogus address 0x76000008. Surely permissions on my pages are right since I haven't ventured into the realm of ring 3. What is messing up my paging?
My GDT has the following entries because I haven't even bothered enabling ring 3 yet:
Code: Select all
gp.limit = (sizeof(struct gdt_entry) * 5) - 1;
gp.base = &gdt;
gdt_set_gate(0, 0, 0, 0, 0);
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Ring 0 (kernel) CS and DS
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
gdt_set_gate(3, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Ring 3 (user processes) CS and DS
gdt_set_gate(4, 0, 0xFFFFFFFF, 0x92, 0xCF);