Getting to Ring 3 x86-64
Posted: Tue Sep 24, 2024 7:05 am
So I am currently working on my hobby-os kernel written in Rust. I previously set up multitaksing (which itself needs to be improved but that is a topic for another post), now I want to test creating usermode processes and so far, have compelted the following steps.
- Set up a GDT with userspace entries and a TSS
- Mapped the new user "program" (a function with a loop) and it's stack to userspace.
- Set up Multitaksing & Interrupt Handling for Ring 0
What I am wondering is what steps are necessary when switching to Ring 3. My kernel tripple faults if I attempt to switch to the newly created usermode process' cpu context (iretq frame with usermode CS, SS, newly mapped stack and function entry).
I followed the following book quite closely when it comes to the implementation details. https://github.com/dreamportdev/Osdev-Notes.
This is my github repository, feel free to check out the userspace branch, which is my current attempt at "fixing the issue". I added a loop in the TaskScheduler::switch_process function so that it does not tripple fault while testing, but the issue still presists if I remove the loop. https://github.com/chickensoftware/os/tree/userspace
Thanks in advance
- Set up a GDT with userspace entries and a TSS
- Mapped the new user "program" (a function with a loop) and it's stack to userspace.
- Set up Multitaksing & Interrupt Handling for Ring 0
What I am wondering is what steps are necessary when switching to Ring 3. My kernel tripple faults if I attempt to switch to the newly created usermode process' cpu context (iretq frame with usermode CS, SS, newly mapped stack and function entry).
I followed the following book quite closely when it comes to the implementation details. https://github.com/dreamportdev/Osdev-Notes.
This is my github repository, feel free to check out the userspace branch, which is my current attempt at "fixing the issue". I added a loop in the TaskScheduler::switch_process function so that it does not tripple fault while testing, but the issue still presists if I remove the loop. https://github.com/chickensoftware/os/tree/userspace
Thanks in advance