Global Descriptor Table: Difference between revisions

Replaced most of my box drawn diagrams with wiki tables.
[unchecked revision][unchecked revision]
(Replaced most of my box drawn diagrams with wiki tables.)
Line 7:
The '''GDT''' is pointed to by the value in the '''GDTR''' register. This is loaded using the '''LGDT''' assembly instruction, whose argument is a pointer to a '''GDT Descriptor''' structure:
 
{| class="wikitable" style="border-width: 3px; width: 720px"
<pre>
|+style="text-align: left;"|'''GDT DescriptorDESCRIPTOR (GDTR):'''
|-
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|style="padding: 2px; width: 461px; text-align: left ; border-left: 1px ; border-right: none;" |79 (64-bit Mode / 48 (32-bit Mode)
┃79 (64-bit Mode) / 48 (32-bit Mode) 16│15 0┃
|style="padding: 2px; width: 10px; text-align: right; border-left: none; border-right: 1px ;" |16
┠───────────────────────────────────────────────────────────────┼───────────────────────────────┨
|style="padding: 2px; width: 221px; text-align: left ; border-left: 1px ; border-right: none;" |15
┃Offset │Size ┃
|style="padding: 2px; width: 11px; text-align: right; border-left: none; border-right: 1px ;" |0
┃63 (64-bit Mode) / 31 (32-bit Mode) 0│15 0┃
|-
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|style="padding: 2px; width: 461px; text-align: left ; border-left: 1px ; border-right: none;" |'''Offset'''<br>63 (64-bit Mode) / 31 (32-bit Mode)
</pre>
|style="padding: 2px; width: 10px; text-align: right; border-left: none; border-right: 1px ;" |<br>0
|style="padding: 2px; width: 221px; text-align: left ; border-left: 1px ; border-right: none;" |'''Size'''<br>15
|style="padding: 2px; width: 11px; text-align: right; border-left: none; border-right: 1px ;" |<br>0
|}
 
* '''Size:''' The size of the table in bytes subtracted by 1. This subtraction occurs because the maximum value of '''Size''' is 65535, while the '''GDT''' can be up to 65536 bytes in length (8192 entries). Further, no '''GDT''' can have a size of 0 bytes.
Line 49 ⟶ 53:
== Segment Descriptor ==
 
Each entry in the table is contains '''Segment Descriptor''' entries which are 8 bytes long. Each entry has a complex structure:
{| class="wikitable" style="border-width: 3px; width: 640px;"
 
|+style="text-align: left;"|'''SEGMENT DESCRIPTOR:'''
<pre>
|-
SEGMENT DESCRIPTOR:
|style="padding: 2px; width: 136px; text-align: left ; border-left: 1px ; border-right: none;"|63
┏━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━┯━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━┓
|style="padding: 2px; width: 15px; text-align: right; border-left: none; border-right: 1px ;"|56
┃63 56│55 52│51 48│47 40│39 32┃
|style="padding: 2px; width: 56px; text-align: left ; border-left: 1px ; border-right: none;"|55
┠───────────────────────┼───────────┼───────────┼───────────────────────┼───────────────────────┨
|style="padding: 2px; width: 15px; text-align: right; border-left: none; border-right: 1px ;"|52
┃Base │Flags │Limit │Access Byte │Base ┃
|style="padding: 2px; width: 56px; text-align: left ; border-left: 1px ; border-right: none;"|51
┃31 24│4 0│19 16│7 0│23 16┃
|style="padding: 2px; width: 15px; text-align: right; border-left: none; border-right: 1px ;"|48
┗━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━┛
|style="padding: 2px; width: 136px; text-align: left ; border-left: 1px ; border-right: none;"|47
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|style="padding: 2px; width: 15px; text-align: right; border-left: none; border-right: 1px ;"|40
┃31 16│15 0┃
|style="padding: 2px; width: 136px; text-align: left ; border-left: 1px ; border-right: none;"|39
┠───────────────────────────────────────────────┼───────────────────────────────────────────────┨
|style="padding: 2px; width: 16px; text-align: right; border-left: none; border-right: 1px ;"|32
┃Base │Limit ┃
|-
┃15 0│15 0┃
|style="padding: 2px; width: 136px; text-align: left ; border-left: 1px ; border-right: none;"|'''Base'''<br>31
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|style="padding: 2px; width: 15px; text-align: right; border-left: none; border-right: 1px ;"|<br>24
</pre>
|style="padding: 2px; width: 56px; text-align: left ; border-left: 1px ; border-right: none;"|'''Flags'''<br>4
|style="padding: 2px; width: 15px; text-align: right; border-left: none; border-right: 1px ;"|<br>0
|style="padding: 2px; width: 56px; text-align: left ; border-left: 1px ; border-right: none;"|'''Limit'''<br>19
|style="padding: 2px; width: 15px; text-align: right; border-left: none; border-right: 1px ;"|<br>16
|style="padding: 2px; width: 136px; text-align: left ; border-left: 1px ; border-right: none;"|'''Access Byte'''<br>7
|style="padding: 2px; width: 15px; text-align: right; border-left: none; border-right: 1px ;"|<br>0
|style="padding: 2px; width: 136px; text-align: left ; border-left: 1px ; border-right: none;"|'''Base'''<br>23
|style="padding: 2px; width: 16px; text-align: right; border-left: none; border-right: 1px ;"|<br>16
|}
{| class="wikitable" style="border-width: 3px; width: 640px;"
|-
|style="padding: 2px; width: 296px; border-right: none;" |31
|style="padding: 2px; width: 15px; text-align: right; border-left: none;" |16
|style="padding: 2px; width: 296px; border-right: none;" |15
|style="padding: 2px; width: 16px; text-align: right; border-left: none;" |0
|-
|style="padding: 2px; width: 296px; border-right: none;" |'''Base'''<br>15
|style="padding: 2px; width: 15px; text-align: right; border-left: none;" |<br>0
|style="padding: 2px; width: 296px; border-right: none;" |'''Limit'''<br>15
|style="padding: 2px; width: 16px; text-align: right; border-left: none;" |<br>0
|}
 
* '''Base:''' A 32-bit value containing the linear address where the segment begins.
Line 74 ⟶ 99:
For more information, see '''Section 3.4.5: Segment Descriptors''' and '''Figure 3-8: Segment Descriptor''' of the Intel Software Developer Manual, Volume 3-A.
 
{| class="wikitable" style="border-width: 3px; width: 640px;"
=== Access Byte ===
|+style="text-align: left;"|'''ACCESS BYTE:'''
 
|-
The '''Access Byte''' is laid out as follows:
|style="padding: 2px; width: 75px; text-align: center; border-left: 1px ; border-right: 1px ;"|7
 
|style="padding: 2px; width: 76px; text-align: center; border-left: 1px ; border-right: none;"|6
<pre>
|style="padding: 2px; width: 75px; text-align: center; border-left: none; border-right: 1px ;"|5
ACCESS BYTE:
|style="padding: 2px; width: 75px; text-align: center; border-left: 1px ; border-right: 1px ;"|4
┏━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┓
|style="padding: 2px; width: 75px; text-align: center; border-left: 1px ; border-right: 1px ;"|3
┃ 7 │ 6 5 │ 4 │ 3 │ 2 │ 1 │ 0 ┃
|style="padding: 2px; width: 75px; text-align: center; border-left: 1px ; border-right: 1px ;"|2
┠─────────┼───────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┨
|style="padding: 2px; width: 75px; text-align: center; border-left: 1px ; border-right: 1px ;"|1
┃Pr │Privl │S │Ex │DC │RW │Ac ┃
|style="padding: 2px; width: 76px; text-align: center; border-left: 1px ; border-right: 1px ;"|0
┗━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━┛
|-
</pre>
|style="padding: 2px; width: 75px; text-align: left ; border-left: 1px ; border-right: 1px ;"|'''Pr'''
|style="padding: 2px; width: 76px; text-align: left ; border-left: 1px ; border-right: none;"|'''Privl'''
|style="padding: 2px; width: 75px; text-align: left ; border-left: none; border-right: 1px ;"|
|style="padding: 2px; width: 75px; text-align: left ; border-left: 1px ; border-right: 1px ;"|'''S'''
|style="padding: 2px; width: 75px; text-align: left ; border-left: 1px ; border-right: 1px ;"|'''Ex'''
|style="padding: 2px; width: 75px; text-align: left ; border-left: 1px ; border-right: 1px ;"|'''DC'''
|style="padding: 2px; width: 75px; text-align: left ; border-left: 1px ; border-right: 1px ;"|'''RW'''
|style="padding: 2px; width: 76px; text-align: left ; border-left: 1px ; border-right: 1px ;"|'''Ac'''
|}
 
* '''Pr:''' Present bit. Allows an entry to refer to a valid segment. Must be set ('''1''') for any valid segment.
Line 101 ⟶ 135:
* '''Ac:''' Accessed bit. Best left clear ('''0'''), the CPU will set it when the segment is accessed.
 
{| class="wikitable" style="border-width: 3px; width: 320px;"
=== Flags ===
|+style="text-align: left;"|'''FLAGS:'''
 
|-
The '''Flags''' are laid out as follows:
|style="padding: 2px; width: 75px; text-align: center; border-left: 1px ; border-right: 1px ;"|3
 
|style="padding: 2px; width: 75px; text-align: center; border-left: 1px ; border-right: 1px ;"|2
<pre>
|style="padding: 2px; width: 75px; text-align: center; border-left: 1px ; border-right: 1px ;"|1
FLAGS:
|style="padding: 2px; width: 76px; text-align: center; border-left: 1px ; border-right: 1px ;"|0
┏━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┓
|-
┃ 3 │ 2 │ 1 │ 0 ┃
|style="padding: 2px; width: 75px; text-align: left ; border-left: 1px ; border-right: 1px ;"|'''Gr'''
┠─────────┼─────────┼─────────┼─────────┨
|style="padding: 2px; width: 75px; text-align: left ; border-left: 1px ; border-right: 1px ;"|'''Sz'''
┃Gr │Sz │L │Reserved ┃
|style="padding: 2px; width: 75px; text-align: left ; border-left: 1px ; border-right: 1px ;"|'''L'''
┗━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━┛
|style="padding: 2px; width: 76px; text-align: left ; border-left: 1px ; border-right: 1px ;"|Reserved
</pre>
|}
 
* '''Gr:''' Granularity flag, indicates the size the '''Limit''' value is scaled by. If clear ('''0'''), the '''Limit''' is in 1 Byte blocks (byte granularity). If set ('''1'''), the '''Limit''' is in 4 KiB blocks (page granularity).
53

edits