Triple-fault when switching to usermode

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.
Post Reply
Najimac
Posts: 6
Joined: Fri Oct 30, 2015 3:28 am
Location: /earth/

Triple-fault when switching to usermode

Post by Najimac »

Hello, I am following James Malloy's, Everything went fine until I got to the usermode chapter.
Note: I fixed every bug I found listed in the wiki page about his tutorial's bugs.
I think it faults when tss_flush is called.
Here is the definition of tss_flush

Code: Select all

tss_flush:
   mov ax, 0x2B      ; Load the index of our TSS structure - The index is
                     ; 0x28, as it is the 5th selector and each is 8 bytes
                     ; long, but we set the bottom two bits (making 0x2B)
                     ; so that it has an RPL of 3, not zero.
   ltr ax            ; Load 0x2B into the task state register.
   ret 

User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Triple-fault when switching to usermode

Post by BrightLight »

You think it faults? Set a breakpoint right before "ltr ax" and check if your GDT/TSS contains what it should.
Do you have exception handling? Are your page tables accessible by user mode? What's in your GDT? What's in your TSS?
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Najimac
Posts: 6
Joined: Fri Oct 30, 2015 3:28 am
Location: /earth/

Re: Triple-fault when switching to usermode

Post by Najimac »

I think I fixed it, I probably was writing the wrong thing into the gdt. (I don't think I put every sample of code I saw.)
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Triple-fault when switching to usermode

Post by BrightLight »

You still think? :lol:
Does it work or not? I don't think there's thinking in that; it's just a fact you can see: it works or not.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: Triple-fault when switching to usermode

Post by mariuszp »

I don't recommend following JamesM's tutorial, it's very buggy and does horrible things that you should never do, such as trying to "move" a stack and search for vlaues on it that need to be modified, disabling paging to copy a page table, etc. The wiki has a full list. I can't remember exactly what it was, but I recall there being a problem with the usermode switch too.
Post Reply