Page 1 of 2
howto transfer control from ring 0 to ring 3
Posted: Sun Dec 16, 2007 11:33 pm
by orange
Hi all....
Im playing in 64bit longmode
Can i directly transfer control from ring 0 to ring 3
i use far jmp to ring 3 GDT but the code raise exception.
Code: Select all
jmp gdt_code_ring3:ring3_code
ring3_code:
can u help to resolve my problem???
thanks...
Posted: Mon Dec 17, 2007 1:49 am
by Combuster
http://www.catb.org/~esr/faqs/smart-questions.html
in other words:
- you should've searched for an answer - specifically the intel manuals
- you provide far too few details to make a sensible diagnosis
- you use sms shortcuts.
Re: howto transfer control from ring 0 to ring 3
Posted: Mon Dec 17, 2007 2:43 am
by AJ
orange wrote:
Can i directly transfer control from ring 0 to ring 3
Yes and No. If you mean 'can I do it with a far jump', the answer is no. You do it in the same way as you currently do your task switches (I assume if you have got to playing with ring 3, you
do have a scheduler by now?).
Cheers,
Adam
Posted: Mon Dec 17, 2007 7:05 am
by Mikae
Also, you can use 'far ret' instruction to jump from r0 to r3. You have to push desired address (CS:RIP) on stack and execute 'far ret'.
Posted: Mon Dec 17, 2007 7:23 pm
by orange
for now i not use task to switching and i have change my code from "far jump" to "far ret". because i thing ring 0 can do anything, including jump to ring 3 directly.
i have do this for my code now
push code_selector_ring3
push offset_ring3
and then do retf
i just want to test syscall/sysret from ring3 to ring 0
thanks for help... next time i will attach my code.
or can u give me sample longmode with syscall/sysret...
Cheers.
Orange
Posted: Mon Dec 17, 2007 7:36 pm
by crazygray1
Caps your I's!!!
Sorry OCD
Posted: Mon Dec 17, 2007 9:16 pm
by piranha
Caps your I's!!!
Sorry OCD
I have OCD too!
-JL
Posted: Mon Dec 17, 2007 9:30 pm
by orange
Posted: Mon Dec 17, 2007 10:14 pm
by Brynet-Inc
Are you serious?
http://www.google.com/search?hl=en&q=OCD
Still, crazygray1.. you're considerably irritating as well, so please stay on topic.

Posted: Mon Dec 17, 2007 10:37 pm
by orange
Posted: Thu Dec 20, 2007 7:56 pm
by orange
Hi guys...
this my code, whats wrong with this code.
i just want to jump to ring 3, but i get an error.
Code: Select all
ORG 0x7C00
USE16
cli
lgdt [cs:GDTR]
mov eax,cr0
or al,1
mov cr0,eax
jmp 8:PM_Start
GDTR: dw 5*8-1
dd GDT
GDT: dw 0x0000,0x0000,0x0000,0x0000 ; (0) NUll Selector
dw 0xFFFF,0x0000,0x9A00,0x00CF ; (8) Code Segment 32bit ring 0
dw 0xFFFF,0x0000,0x9200,0x00CF ; (16) Data Segment 32bit ring 0
dw 0xFFFF,0x0000,0xFA00,0x00CF ; (24) Code Segment 32bit ring 3
dw 0xFFFF,0x0000,0xF200,0x00CF ; (32) Data Segment 32bit ring 3
USE32
PM_Start:
mov ax,16
mov ds,ax
mov es,ax
mov ss,ax
mov fs,ax
mov gs,ax
mov eax,'P M '
mov [0xB8000],eax
push dword 32 ; SS
push dword Stack_Top ; ESP
push dword 0 ; EFLAGS
push dword 24 ; CS
push dword PM_Ring3 ; EIP
iret ; Jmp to ring 3
PM_Ring3:
mov ax,32
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov eax,'R 3 '
mov [0B8000h],eax
jmp PM_Ring3
db 512 dup (0)
Stack_Top:
Thanks...
Posted: Fri Dec 21, 2007 3:08 am
by AJ
You need the RPL of the segment to be 3. That means, or the value 24 with 3. I must say, I prefer these things to be shown in hex, especially when setting / clearing bits. This means it becomes 0x18 | 0x03.
If you test it in Bochs first, it will tell you what the error is which makes debugging a lot easier!
Cheers,
Adam
Posted: Fri Dec 21, 2007 4:21 am
by orange
AJ wrote:You need the RPL of the segment to be 3. That means, or the value 24 with 3. I must say, I prefer these things to be shown in hex, especially when setting / clearing bits. This means it becomes 0x18 | 0x03.
Thank's Adam
but how to make RPL of the segment tobe 3????
If you test it in Bochs first, it will tell you what the error is which makes debugging a lot easier!
I test in vmware, because i can't use bochs. How to load img file without floppy in bochs??.
In vmware i just setting floppy use floppy image..
Cheers....
Orange
Posted: Fri Dec 21, 2007 4:25 am
by AJ
orange wrote:
but how to make RPL of the segment tobe 3????
You OR 24 (0x18) with three which gives you 27 (0x1B) - set this as your CS instead of 24.
Cheers,
Adam
Posted: Fri Dec 21, 2007 4:46 am
by orange
I change my code like this...
first i change CS 24 tobe 27, but i still get an error

. Then i try to change SS 32 tobe 35,,,, and thanks GOD, that ist works.
Code: Select all
push dword 35 ; SS
push dword Stack_Top ; ESP
push dword 0 ; RFLAGS
push dword 27 ; CS
push dword PM_Ring3 ; EIP
iret ; Jmp to ring 3
Thank's Adam....
Cheers...
Orange