Problem running an application in ring 3
Posted: Thu Aug 20, 2015 9:26 pm
Hi there,
I've been trying to run an application on my OS, it loads and runs fine in Ring 0, but when I switch it to Ring 3 it goes wrong. I think my problem may be with my TSS, I am finding lots of conflicting information about how to set that up. I have this:
this defines the flags of the TSS based on http://wiki.osdev.org/GDT_Tutorial#Some ... _life_easy, the base is the location of the TSS and the size is the size of the TSS
It seems to be working, in that I'm not getting any fault 10s, and it successful switches to ring 3, back to ring 0 for a syscall, however this is where things mess up.
the values in the registers are all wrong. mostly 0xffffffff and it page faults trying to access 0xffffffff.
So my other theory is I'm doing something wrong with the stack. When I page fault I print out from ESP to the kstack top i get:
e <- 14, page fault
5 <- error code (page not accessible)
ffffffff <- eip ???
1b <- cs
10296 <- eflags
f0201fc0 <- user esp
23 <- userss
i've been going in circles a couple of days on this, and i don't really have an idea what's going wrong and what information is relevant.
I've been trying to run an application on my OS, it loads and runs fine in Ring 0, but when I switch it to Ring 3 it goes wrong. I think my problem may be with my TSS, I am finding lots of conflicting information about how to set that up. I have this:
Code: Select all
#define GDT_TSS SEG_GRAN(1) | SEG_PRES(1) | SEG_PRIV(0) | SEG_SIZE(1) | SEG_CODE_EXA
It seems to be working, in that I'm not getting any fault 10s, and it successful switches to ring 3, back to ring 0 for a syscall, however this is where things mess up.
the values in the registers are all wrong. mostly 0xffffffff and it page faults trying to access 0xffffffff.
So my other theory is I'm doing something wrong with the stack. When I page fault I print out from ESP to the kstack top i get:
e <- 14, page fault
5 <- error code (page not accessible)
ffffffff <- eip ???
1b <- cs
10296 <- eflags
f0201fc0 <- user esp
23 <- userss
i've been going in circles a couple of days on this, and i don't really have an idea what's going wrong and what information is relevant.