Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Protected mode
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Segment addressing === {{details|X86 memory segmentation}} [[File:080810-protected-286-segments.PNG|thumb|right|upright=1.4|Virtual segments of 80286]] ==== Real mode ==== In real mode each logical address points directly into a physical memory location, every logical address consists of two 16-bit parts: The segment part of the logical address contains the base address of a segment with a granularity of 16 bytes, i.e. a segment may start at physical address 0, 16, 32, ..., 2<sup>20</sup> β 16. The offset part of the logical address contains an offset inside the segment, i.e. the physical address can be calculated as physical_address = segment_part Γ 16 + offset, if the address [[A20 line|line A20]] is enabled, or (segment_part Γ 16 + offset) mod 2<sup>20</sup>, if A20 is off.{{Clarify|date=August 2011}} Every segment has a size of 2<sup>16</sup> bytes. ==== Protected mode ==== In protected mode, the {{Mono|segment_part}} is replaced by a 16-bit ''selector'', in which the 13 upper bits (bit 3 to bit 15) contain the index of an ''entry'' inside a ''descriptor table''. The next bit (bit 2) specifies whether the operation is used with the GDT or the LDT. The lowest two bits (bit 1 and bit 0) of the selector are combined to define the privilege of the request, where the values of 0 and 3 represent the highest and the lowest privilege, respectively. This means that the byte offset of descriptors in the descriptor table is the same as the 16-bit selector, provided the lower three bits are zeroed. The descriptor table entry defines the real ''linear'' address of the segment, a limit value for the segment size, and some attribute bits (flags). ==== 286 ==== The segment address inside the descriptor table entry has a length of 24 bits so every byte of the physical memory can be defined as bound of the segment. The limit value inside the descriptor table entry has a length of 16 bits so segment length can be between 1 byte and 2<sup>16</sup> byte. The calculated linear address equals the physical memory address. ==== 386 ==== The segment address inside the descriptor table entry is expanded to 32 bits so every byte of the physical memory can be defined as bound of the segment. The limit value inside the descriptor table entry is expanded to 20 bits and completed with a granularity flag (G-bit, for short): * If G-bit is zero limit has a granularity of 1 byte, i.e. segment size may be 1, 2, ..., 2<sup>20</sup> bytes. * If G-bit is one limit has a granularity of 2<sup>12</sup> bytes, i.e. segment size may be 1 Γ 2<sup>12</sup>, 2 Γ 2<sup>12</sup>, ..., 2<sup>20</sup> Γ 2<sup>12</sup> bytes. If paging is off, the calculated linear address equals the physical memory address. If paging is on, the calculated linear address is used as input of paging. The 386 processor also uses 32 bit values for the address offset. For maintaining compatibility with 286 protected mode a new default flag (D-bit, for short) was added. If the D-bit of a code segment is off (0) all commands inside this segment will be interpreted as 16-bit commands by default; if it is on (1), they will be interpreted as 32-bit commands. ==== Structure of segment descriptor entry ==== <div> {| class="infobox" style="text-align:center" |- |style="text-align:center" |''80286 Segment descriptor'' |- | {| |style="width:15px;text-align:center"|<sup>3</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>0</sub> |- |colspan="16" style="background:silver;text-align:center"|Base[0..15] |colspan="16" style="background:silver;text-align:center"|Limit[0..15] |- |style="width:15px;text-align:center"|<sup>6</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>6</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>6</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>6</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>2</sub> |- |colspan="16" style="background:silver;text-align:center"|''Unused'' |colspan="1" style="background:silver;text-align:center"|P |colspan="2" style="background:silver;text-align:center"|DPL |colspan="1" style="background:silver;text-align:center"|S |colspan="1" style="background:silver;text-align:center"|X |colspan="1" style="background:silver;text-align:center"|C |colspan="1" style="background:silver;text-align:center"|R |colspan="1" style="background:silver;text-align:center"|A |colspan="8" style="background:silver;text-align:center"|Base[16..23] |} |} {| class="infobox" style="text-align:center" |- |style="text-align:center" |''80386 Segment descriptor'' |- | {| style="text-align:center" |style="width:15px;text-align:center"|<sup>3</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>2</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>1</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>0</sup><sub>0</sub> |- |colspan="16" style="background:silver;text-align:center"|Base[0..15] |colspan="16" style="background:silver;text-align:center"|Limit[0..15] |- |style="width:15px;text-align:center"|<sup>6</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>6</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>6</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>6</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>5</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>2</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>1</sub> |style="width:15px;text-align:center"|<sup>4</sup><sub>0</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>9</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>8</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>7</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>6</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>5</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>4</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>3</sub> |style="width:15px;text-align:center"|<sup>3</sup><sub>2</sub> |- |colspan="8" style="background:silver;text-align:center"|Base[24..31] |colspan="1" style="background:silver;text-align:center"|G |colspan="1" style="background:silver;text-align:center"|D |colspan="1" style="background:silver;text-align:center"|0 |colspan="1" style="background:silver;text-align:center"|''U'' |colspan="4" style="background:silver;text-align:center"|Limit[16..19] |colspan="1" style="background:silver;text-align:center"|P |colspan="2" style="background:silver;text-align:center"|DPL |colspan="1" style="background:silver;text-align:center"|S |colspan="1" style="background:silver;text-align:center"|X |colspan="1" style="background:silver;text-align:center"|C |colspan="1" style="background:silver;text-align:center"|R |colspan="1" style="background:silver;text-align:center"|A |colspan="8" style="background:silver;text-align:center"|Base[16..23] |} |} Where: *''A'' is the ''Accessed'' bit; *''R'' is the ''Readable'' bit; *''C'' (Bit 42) depends on ''X'':<ref name="OSDev GDT">{{cite web|url=https://wiki.osdev.org/Global_Descriptor_Table#Structure|title=Global Descriptor table - OSDev Wiki}}</ref> **if ''X'' = 1 then ''C'' is the ''Conforming'' bit, and determines which privilege levels can far-jump to this segment (without changing privilege level): ***if ''C'' = 0 then only code with the same privilege level as ''DPL'' may jump here; ***if ''C'' = 1 then code with the same or a lower privilege level relative to ''DPL'' may jump here. **if ''X'' = 0 then ''C'' is the ''direction'' bit: ***if ''C'' = 0 then the segment grows ''up''; ***if ''C'' = 1 then the segment grows ''down''. *''X'' is the ''Executable'' bit:<ref name="OSDev GDT"/> **if ''X'' = 1 then the segment is a code segment; **if ''X'' = 0 then the segment is a data segment. *''S'' is the ''Segment type'' bit, which should generally be cleared for system segments;<ref name="OSDev GDT"></ref> *''DPL'' is the ''Descriptor Privilege Level''; *''P'' is the ''Present'' bit; *''D'' is the ''Default operand size''; *''G'' is the ''Granularity'' bit; *Bit 52 of the 80386 descriptor is not used by the hardware. </div>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Protected mode
(section)
Add topic