Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Ok I've been beating on this for a while now and I have no idea whats going wrong. I'm trying to make the switch from kernel space to user land and I keep getting a triple fault. I have my gdt set up and the TSS but when I run the function to jump to user space it dies. Here is the code in question:
Help me out. Am I missing something? Is there some small pre switch step I missed? Also, if I try to run a function from the kernel after the user mode switch, will that cause a triple fault? It may sound like a stupid question but from what I have been reading, I'm not sure.
Try running your OS in Bochs with the debugger enabled. It will tell you exactly what is wrong with your descriptors, and you can even step through this code line-by-line.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Run the OS in bochs so you can see what's really going on.
Make the user task a simple jmp $ so you are not using the ss selector or other memory outside the cs selector. This will narrow it down a little between jumping to user space and accessing stack memory from user space.
The Bochs log will also tell you if it's a descriptor error or a page fault.
* Side note - You should probably have some basic exception handlers before jumping to user space. Even if it's just to dump the register values to screen and halt the CPU.
Well I believe I solved the initial issue and am now in user mode. But now when I try to run system calls, specifically "int 0x80", I get an invalid opcode fault. I have no idea where to begin with this. I have interrupt 128 in my idt and its set for ring 3.
SlayterDev wrote:Well I believe I solved the initial issue and am now in user mode. But now when I try to run system calls, specifically "int 0x80", I get an invalid opcode fault. I have no idea where to begin with this. I have interrupt 128 in my idt and its set for ring 3.
You would probably get a General Protection Fault if your IDT was wrong, so you probably are ending up at the wrong address. You should be able to get the address of the invalid opcode from the exception handler. Make sure it is running the code that you think it's running.
Or run it in Bochs and step through it, line-by-line. (Or SimNOW, if you just don't want to use Bochs for some reason.)
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott