Page 1 of 1

Triple-fault when switching to usermode

Posted: Mon Feb 15, 2016 5:34 am
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 


Re: Triple-fault when switching to usermode

Posted: Mon Feb 15, 2016 7:55 am
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?

Re: Triple-fault when switching to usermode

Posted: Mon Feb 15, 2016 7:58 am
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.)

Re: Triple-fault when switching to usermode

Posted: Mon Feb 15, 2016 8:06 am
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.

Re: Triple-fault when switching to usermode

Posted: Thu Feb 18, 2016 9:08 am
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.