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
Privilege level 3
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Privilege level 3
Only a DPL-0 segment will be a valid stack segment for DPL0 code. Which mean you cannot simply
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)
or something alike ...
Code: Select all
mov ss,UDATA_SELECTOR
jmp UCODE_SELECTOR:entrypoint
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
Re:Privilege level 3
Thanks! ;DPype.Clicker wrote: Only a DPL-0 segment will be a valid stack segment for DPL0 code. Which mean you cannot simplyto 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).Code: Select all
mov ss,UDATA_SELECTOR jmp UCODE_SELECTOR:entrypoint
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)
or something alike ...Code: Select all
push USTACK_SELECTOR push user_stack_pointer push SOME_FLAGS push UCODE_SELECTOR push entry_point iret
I shall try it