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.
Hi everyone ,
I want to know how can i switch to user mode.
I have the task state segment (TSS) but i don't know how to switch to user mode.
I have followed the tutorial that provided in the wiki about setting up the user mode but it didn't run because i am using MSVC 2005 inline assembly not gcc or other compilers like it.
Now i have a question:
How can i switch to user mode?
----------------------------------------------
Thanks in advance
Last edited by melgmry0101b on Sun Jul 24, 2011 12:49 pm, edited 1 time in total.
How did reading the manuals, tutorials, and existing forum posts not answer your question?
"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 ]
_asm {
cli
mov ax, 0x23 ; user mode data selector is 0x20 (GDT entry 3). Also sets RPL to 3
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
push 0x23 ; SS, notice it uses same selector as above
push esp ; ESP
pushfd ; EFLAGS
pop eax
or eax, 0x200 ; enable IF in EFLAGS
push eax
push 0x1b ; CS, user mode code selector is 0x18. With RPL 3 this is 0x1b
lea eax, [a] ; EIP first
push eax
iretd
a:
add esp, 4 ;fix stack
}
And Bochs Debugger gave me this error:
[CPU0] check_cs <0x0023> : not a valid code segment !
Can anyone help me?
----------------------------------
Thanks in advance.
Last edited by quok on Sun Jul 24, 2011 2:00 pm, edited 1 time in total.
Reason:Stripped colors from post. Read the forum rules! NO COLORS!
This code is the code that provided with the tutorial of user mode but it is in AT&T syntax and Microsoft Visual C++ is using Intel syntax and i didn't use AT&T before so that can anyone help me by converting it to Intel syntax?
------------------------------------------------
Thanks in advance.
The address parameter is the address of where you want the code to start executing after you have entered usermode. I just find it more robust than using the jump forward.