Page 1 of 1

TSS exception immediately after switching to usermode

Posted: Wed Jan 19, 2011 8:32 am
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?

Re: TSS exception immediately after switching to usermode

Posted: Wed Jan 19, 2011 8:51 am
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.