In the previous section, the segment register has attribute characteristics , This section will cover the of segment descriptors and segment selectors

The previous section talked about the segment register 96 position , Only 16 Bits are visible ( The rest 80 Bit buffer to CPU Inside ), This is visible 16 Bit is segment selector

Which this 16 Bit Division 3 part

0~1 position : by RPL Called request privilege level ,2 Just one bit 4 Kinds of permissions   0  ,1,2,3  The larger the number , The smaller the permission, the vice versa

The first 2 position :TL    When TL=0 Go when you need it GDT( Unload segment descriptors from the global descriptor table )  TL=1 go LDT( Local descriptor table , this Windows Not used )

3~15:    Index Index this value as a subscript GDT Corresponding table entry found in table (32 Bit system GDT Each item in the table 8 Bytes , One segment descriptor per bit )

            Load this segment descriptor .

Index Specify what we load GDT Table item , That is, specify the loaded segment descriptor , Many people may have noticed 0~1 Request privilege level of bit RPL,

Index Although as an index, it allows us to locate the corresponding segment descriptor , And load it , However, this segment descriptor may not be loaded successfully , Each segment descriptor has an attribute , It can specify what permissions you must have before I can be loaded by you , If you don't have such permission , I'm sorry , We don't fit

( We can understand that , This is the girl on a blind date , Some require men to have a room and a car , Some require the rich second generation , Of course, some do not have any requirements )

A man on a blind date can be regarded as a segment selector , On a blind date ( It is equivalent to finding this segment descriptor and ), Then put your own conditions (RPL Request privilege level ) Compare with the girls' requirements , If the requirements are not met , Bye, loading segment descriptor failed , If you meet the requirements, you can try .

Segment descriptor has 64 Position in GDT The structure in the table is as follows

P position : Segment descriptor medium high 4 In bytes 15 position P Bit is the most important 1 position , If P=0 It represents this segment descriptor. Don't look at it. It's invalid. It's an invalid descriptor

          P=1 Indicates that this segment descriptor is valid ( If P=0 All other operations are meaningless )

G position : Is granularity G=0 representative 20 Bit Limit The unit is BYTE,G=1 representative 20 Bit Limit The unit is 4KB One page

        G=0 or 1 Can only determine the size of access , It does not determine the size of the segment , Only decide Limit Scope of ( and Limit Determines the size of the segment you can access )

D/B position : I'll explain later. It's complicated

DPL: High in segment descriptor 4 Byte 13-14 position , Represents the segment descriptor privilege level , Only the selector that wants to load this segment descriptor has a request privilege level higher than

        Or equal to DPL To load this segment ( That is, you have met the conditions required by the woman )RPL( Permission greater than )>=DPL Just one of the conditions , Next post

        Section permission check will give you a comprehensive description , Plus practical test

S position : S=0 Represents that this descriptor is a system segment descriptor ,S=1 Represents that this segment descriptor is a code segment descriptor or a data segment descriptor

      GDT There are two types of descriptors in. One is system segment descriptor , Another segment descriptor or code segment

 

When S=1 Refer to the figure below when using

S=1 And TYPE field <8 Represents that this segment descriptor is a data segment

A Have you ever visited this paragraph , Visited A=1, Not visited A=0

W position :W=1 Represents that this paragraph is readable and writable ,W=0 Represents that this segment is read-only

E position : Extension direction E=0 Represents upward expansion ,E=1 Represents downward expansion

Expand up : The access scope of a paragraph we talked about earlier is Base reach Base+Limit  therefore 0x3B         
FS The segment of can only access the data of one page ,DS,CS,ES Can access the whole 4GB, Expanding upward means that the accessible range of this segment is  Base reach Base+Limit

Extend down : representative 4GB Space except Base reach Base+Limit The space between cannot be accessed , All other spaces are accessible , It is equivalent to the negation of upward expansion

S=1 And TYPE field >=8 Represents that this segment descriptor is a code segment

A Have you ever visited this paragraph , Visited A=1, Not visited A=0

R position :R=0 Represents that this code segment is executable ,R=1 Represents that this segment can be readable

C position :C=0 Is a non-conforming snippet   ( This will be discussed in detail in the following post )

          C=1 Is a consistent snippet

 

Segment descriptor D:B You should discuss it in several situations ( To be divided into these cases, they must be downward compatible )

1: For data segments, whether up-down or down compatible  

      D/B=1 The upper limit of the segment is 4GB

      D/B=0 The upper limit of the segment is 64KB           8086 Segment register is used in mode *16+ Offset address (16 position )= addressing 1MB

2: Impact on code snippets                   If the snippet is selected to be loaded into cs Yes      

      D/B=1 Using 32 Bit addressing mode

      D/B=0 actually is 16 Bit addressing mode            Friends who have learned hard coding should know hard coding 67 You can change the default addressing mode   Will not change D/B position

 3: yes SS Impact of segment                    If the segment descriptor is loaded into ss In the segment register

     D/B=1                                 Implicit stack access instruction (PUSH  POP 
CALL) use 32 Bit stack pointer ESP

     D/B=0                                 Implicit stack access   (PUSH  POP  CALL) use 16 Bit stack pointer SP

If it is a data segment descriptor or code segment description

Segment descriptor medium high 4 Byte 24-31 position : As Base of 24-31 position    high 4 Byte 0-7 position : As Base of 16-23 position

Low in segment descriptor 4 Byte 16-31 position :   As Base Low 16 position   

Low in segment descriptor 4 In bytes 0-15 position : As Limit Low 15 position     Segment descriptor high 4 In bytes 16-19 Bit as Limit of 16-19 position

G Bit is important if G=0, be Limit Yes 20-31 All bits are filled 0 Unit is BYTE

If G=1 Limit of 20-31 All bits are filled 0, Unit is 4KB( A small page   4096 byte ) 

Atttibute Is the upper four bytes of the segment descriptor 8-23 position , This property bit controls some properties of the segment

If in the segment descriptor P=1  S=0, Is the system segment descriptor , At this time, according to TYPE The values of are divided into the following system segment descriptors

 

This post will focus on the parsing of segment descriptors , As the name suggests, segment descriptors describe segments ( For example, the data segment can be written , extend , The Writeability of a code segment, and so on ), System descriptors and data snippets are different ( I'll talk about it later ), The data segment and code segment will be similar , The next article is the permission check of the segment , The protection mode must revolve around the segment , page , Segment mechanism and page mechanism for memory protection , You need to know what the paragraph page does , And how to protect , You can understand the segment page and understand the protection mode

 

 

Technology