Page 1 of 1

need explanation on this (tss's prvil field)

Posted: Mon Aug 03, 2020 4:15 am
by ITchimp
I am creating a tss segment so I can switch to user mode...
This is the privilege level description I got from osdev's article

Privl: Privilege, 2 bits. Contains the ring level, 0 = highest (kernel), 3 = lowest (user applications).

I still don't understand what I should set it to...

since tss should store the stack pointer and stack segment value for kernel... it should be set to 0.

but james molloy set the access byte to 0xE9, which implies that the privilege level is set to 3 ...

is he wrong or I intepret it wrong?

Re: need explanation on this (tss's prvil field)

Posted: Mon Aug 03, 2020 7:32 am
by iansjack
The Intel manual seems to be pretty clear on this:
Any program or procedure with access to a TSS descriptor (that is, whose CPL is numerically equal to or less than the DPL of the TSS descriptor) can dispatch the task with a call or a jump.

In most systems, the DPLs of TSS descriptors are set to values less than 3, so that only privileged software can perform task switching. However, in multitasking applications, DPLs for some TSS descriptors may be set to 3 to allow task switching at the application (or user) privilege level.
So the answer is (as it so often is) - "It depends....".

Re: need explanation on this (tss's prvil field)

Posted: Mon Aug 03, 2020 7:48 pm
by ITchimp
my question is: switching to user level from kernel level, dpl is something between...

linux kernel book (bovet mentioned dpl should be set to 0)

james molloy sets it to 3 ....

I am confused...

Re: need explanation on this (tss's prvil field)

Posted: Tue Aug 04, 2020 3:17 am
by iansjack
The setting in the descriptor is just telling you whether a user process can access the TSS or not; the kernel always can. I can't see any reason why you would want to make it accessible to a user process (and I can think of plenty of reasons not to).