OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:34 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Switching from ring0 to ring3 cause GP
PostPosted: Fri Jun 17, 2022 1:13 pm 
Offline

Joined: Tue Apr 26, 2022 5:55 am
Posts: 1
Hi everyone.
I'm trying to set up the correct ring0 -> ring3 switching, but I'm getting a General Protection exception because of that. Moreover, the all next instructions from ring3 are executed successfully.
this is my GDT:

Code:
gdt64:
   dq 0
.csd0:
   dd 0
   db 0
   db 10011010b
   db 10100000b
   db 0x00
.dsd0:
   dd 0
   db 0
   db 10010010b
   db 10100000b
   db 0x00
.csd3:
   dd 0
   db 0
   db 11111010b
   db 10100000b
   db 0x00
.dsd3:
   dd 0
   db 0
   db 11110010b
   db 10100000b
   db 0x00
.tss:
   dw 0         ; limit
   dw 0         ; base
   db 0x00         ; base
   db 11101001b
   db 00000000b      ; limit (4 bits)
   db 0         ; base
   dd 0
   dd 0


When I'm in ring3 I check the CS register value (it contains 111b in the low bits), then I stop the execution (hlt, jmp ... hlt) and check the registers values
using qemu:

ES =0023 0000000000000000 00000fff 00a0f300 DPL=3 DS [-WA]
CS =0008 0000000000000000 00000000 00209a00 DPL=0 CS64 [-R-]
SS =0000 0000000000000000 00000000 00000000
DS =0023 0000000000000000 00000fff 00a0f300 DPL=3 DS [-WA]
FS =0023 0000000000000000 00000fff 00a0f300 DPL=3 DS [-WA]
GS =0023 0000000000000000 00000fff 00a0f300 DPL=3 DS [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =0028 0000000000150ad8 00000068 0000e900 DPL=3 TSS64-avl

It's strange to me, why CS register value is 0x08, because the CS value check every time passes.

Also, I refer to the AMD system programming manual (vol 2). But I don't know yet, how to check the GP error code in my interrupt handler.
If anyone knows what I missed?
I appreciate any help :)


Top
 Profile  
 
 Post subject: Re: Switching from ring0 to ring3 cause GP
PostPosted: Mon Jun 20, 2022 12:26 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
Hi,

Where is the code for switching to user mode? Did note that not only is CS referring to kernel code but SS appears to be the null descriptor. Nonetheless you didnt post the code that does the actual switch.

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: Switching from ring0 to ring3 cause GP
PostPosted: Wed Jun 29, 2022 2:37 am 
Offline
Member
Member

Joined: Wed Jun 29, 2022 2:17 am
Posts: 27
Hi
Where is the code for switching to user mode?
I think you may use the long call instruction to switching to user mode, it's wrong.

_________________
I'm a new man to develop operating system.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], MichaelPetch and 52 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group