Privilege level 3

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
DennisCGc

Privilege level 3

Post by DennisCGc »

Hello.
I'm writing an OS (a small one), but I have a problem.
Many say it's easy to do that, but I think not.
My problem is I can't run a task in ring 3.
For example, when I set the SS to 43 (a privilege 3 descriptor) the OS gives a #GP fault :'(
The TSS is loaded before this, and with the good values, so I think that ain't the problem.
What could be the problem ?
My descriptors(maybe that will help):

GDT_ME dd 0,0

dd 0000ffffh ;ring 0 code segment 8
dd 00cf9a00h

dd 0000ffffh ;ring 0 data segment 16
dd 00cf9200h

   dw 103
   dw tss_begin
   dw 1000100100000000b
   dw 0


;define a ring 3 code segment
   dd 0x0000ffff
   dd 0x00cffa00
;data
   dd 0x0000ffff
   dd 0x00cff200
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Privilege level 3

Post by Pype.Clicker »

Only a DPL-0 segment will be a valid stack segment for DPL0 code. Which mean you cannot simply

Code: Select all

    mov ss,UDATA_SELECTOR
    jmp UCODE_SELECTOR:entrypoint
to enter a user-mode task... Even just 'jmp UCODE:point' is invalid because you can only jmp to code segment that have the same DPL as your CPL (DPL of the current code segment).

You should push things on the stack so that an IRET instruction would believe that the current execution comes from a call to INT nn that made a stack switch (see Holy Intel Manuals for the exact structure)

Code: Select all

    push USTACK_SELECTOR
    push user_stack_pointer
    push SOME_FLAGS
    push UCODE_SELECTOR
    push entry_point
    iret
or something alike ...
DennisCGc

Re:Privilege level 3

Post by DennisCGc »

Pype.Clicker wrote: Only a DPL-0 segment will be a valid stack segment for DPL0 code. Which mean you cannot simply

Code: Select all

    mov ss,UDATA_SELECTOR
    jmp UCODE_SELECTOR:entrypoint
to enter a user-mode task... Even just 'jmp UCODE:point' is invalid because you can only jmp to code segment that have the same DPL as your CPL (DPL of the current code segment).

You should push things on the stack so that an IRET instruction would believe that the current execution comes from a call to INT nn that made a stack switch (see Holy Intel Manuals for the exact structure)

Code: Select all

    push USTACK_SELECTOR
    push user_stack_pointer
    push SOME_FLAGS
    push UCODE_SELECTOR
    push entry_point
    iret
or something alike ...
Thanks! ;D
I shall try it ;)
Post Reply