Analysis of segment descriptor
In/Kern/env. C, you can see the definition of gdt (Global Descriptor Table), which separates the data segment and code segment of the user space from the code segment of the kernel data segment.
Gd _ ** is defined in/INC/memlayout. h.
We will find that gd_kt gd_kd here... their low 3bits are all 0. Why? The definition of segment descriptor
CPL: current privilege level current privileged level
So... privileged?
OK. Here, the Gobal descriptor section is clear.
According to the following definition, we can know that gdt has six descriptors, one seg_null, the kernel data segment, the kernel code segment, the user data segment, the user code segment, and the task segment separator.
How to initialize segement descriptor? Here, Jos uses macro-defined seg ()
The definition of struct segdesc is as follows:
(In other words, Jos uses struct field-based methods, while Linux 0.11 uses two long variables to record this information)
Check the initialized macro seg.
Note that the last two three initialization data values are 1. Here, the length of the specified segment is 32 bits, and the segment is in the minimum unit of 4 K.
There is such code in the initialization of struct segdesc: The final initialization parameter 0 specifies DPL, that is, 0 privileged level (highest)
Sta_x sta_r indicates the type of the segment. Here are various types about the type: these are all applications.
After the above introduction, we can realize that
The kernel code segment is marked as executable and readable.
The kernel data segment is marked as readable and writable.
User code segments are marked as executable and readable
User Data Segment marked as readable and writable
The base address of each segment starts from 0x0, the kernel segment privilege level is 0, and the user segment privilege level is 3
2014 on the way to miaoyin Temple
Analysis of segment descriptor -- Jos