[mkc2008] Kernel Entry and Kernel Exit - Segmentation

Jan Bierbaum s3306700 at mail.inf.tu-dresden.de
Sat Apr 4 01:36:58 CEST 2009


Hello!


I have some serious problems understanding segmentation. Reading the
Intel manual's part about that topic was not too great a help.


Segmentation does translate logical addresses to linear addresses with
the help of segment descriptors. Those descriptors specify base address
and size of a segment. Logical addresses consist of a segment selector
(referring to a segment descriptor) and an offset into that segment.
(slide 5).

Since it's possible to have a segment cover the complete 4 GB address
space (slide 9) the offset needs to be 32 bit long. When we add the
segment selector that would necessarily produce a logical address longer
then 32 bit.

All addresses specified by software are logical addresses because
segmentation is a mandatory feature. Here is my problem:
Addresses/Pointers in 32 bit code are 32 bit, not more. So how is the
segment selector specified? And the other way around - what segment
selector is used when none is explicitly specified?

To run any program we need at least a code segment and a stack/data
segment (slide 9). So is the segment choosing done implicitly - code
segment for fetching instructions, stack segment for stack operations,
data segment for operant fetching? Nevertheless there must be a way to
explicitly specify a segment selector to use. Otherwise the extra data
segments would not make any sense.


Another issue are the different privilege levels: current privilege
level (CPL), requested privilege level (RPL), descriptor privilege level
 (DPL).

CPL refers to the privilege level the CPU currently runs on. So this is
used e.g. for checking the access right on page tables and instructions.
DPLs are attached to various descriptors and function as a kind of guard
- the descriptor or better the resource it "describes" may only be used
if CPL <= DPL. RPLs are found inside segment selectors and can demote,
but not promote, the CPL for access to the segment the selector
references. Correct?


Sorry for the lengthy post and thanks in advance for some explanations.


CU, Jan.



More information about the mkc2008 mailing list