Analysis of segment descriptor -- Jos

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.