TSS exception immediately after 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
User avatar
samuelagm
Posts: 7
Joined: Thu Jun 17, 2010 6:33 pm
Location: Nigeria

TSS exception immediately after switching to usermode

Post by samuelagm »

Guys, i get this tss exception when i switch to user mode, even though i've not loaded a tss yet, below is my usermode switch code, and when iret is executed is starts executing from address _1:, so any function below _1: in my asm file, is executed this something i should worry about?, or is there a fix

_to_usermode:
cli
mov ax, 0x23
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax

mov eax, esp
push 0x23
push eax
pushf
push 0x1B
push _1
iret
_ 1:

_pgbit: > This function is executed, when iret in the function above is executed
mov eax,cr0


Something just flashed in my head just now; would moving the _to_usermode function to the end of my asm file where there is no function or instruction afterward solve the problem?
And there shall be nothing impossible to those who believe
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: TSS exception immediately after switching to usermode

Post by Combuster »

Of course the processor has to execute something, and it does whatever it finds at _1 because you told it to - that means that whatever code you want to run in userland should go there.

As for the TSS exception, there are a bunch of reasons why you'd get that. A list of potential causes is listed in the processor manuals (you need 3A, find the exception reference), although the most likely cause is that one hasn't been set up - you need a TSS before going to userland or you won't be coming back.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply