Question about segmentation in x80-86

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
asientador
Posts: 1
Joined: Thu Jul 06, 2023 1:13 am

Question about segmentation in x80-86

Post by asientador »

I'm actually reading “Understanding the Linux Kernel” by Daniel P Bovet as an introduction to Linux Kernel Development.

As far as I've read, the book focuses on the x80-86 architecture, so segmentation is treated as its part of this architecture.

I'ts said that the Segment Descriptor relative address inside the GDT or LDT is obtained by multiplying the 13-bit index field of the Segment Selector by 8.

The example that's shown is: “if the GDT is at 0×00020000 (the value stored in the gdtr register) and the index specified by the Segment Selector is 2, the address of the corresponding Segment Descriptor is 0×00020000 + (2 × 8), or 0×00020010.”

If the value of the GDT entry is 0×00020000, how can I get the Segment Selector from that?.

As I understand, 8byte Segment Descriptors are the ones stored in the GDT or LDT.

Other thing that I don't quite understand is the size of the logical address. As I've read, they are composed of a Segment Selector or Segment Number (16 bits) and the 32 bits offset. Is this total address 48 bits in size? Or just 16 bits of Segment Number and 16 bits of Offset.

Thanks in advance for your help, devs.

Asientador.
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Freenode IRC: klange

Re: Question about segmentation in x80-86

Post by klange »

Two things:

"x80-86" is not a thing. The x in x86 is a placeholder for the prefixes for 8086, 80186, 80268, 80386, and so on.

When transcribing an address in hexadecimal, the x is a literal x from hexadecimal, not a mathematical multiplication sign, so it should not be written with ×.
User avatar
JAAman
Member
Member
Posts: 877
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Question about segmentation in x80-86

Post by JAAman »

asientador wrote: I'ts said that the Segment Descriptor relative address inside the GDT or LDT is obtained by multiplying the 13-bit index field of the Segment Selector by 8.

The example that's shown is: “if the GDT is at 0×00020000 (the value stored in the gdtr register) and the index specified by the Segment Selector is 2, the address of the corresponding Segment Descriptor is 0×00020000 + (2 × 8), or 0×00020010.”

If the value of the GDT entry is 0×00020000, how can I get the Segment Selector from that?.
you cannot ever get the segment selector from the GDT entry, you obtain the GDT entry from the segment selector

the segment selector is the 16-bit value loaded into a segment register. This segment selector contains several pieces of information, one of which is the index in the GDT (or LDT) it refers to (and since each descriptor is 8 bytes long, multiplying the index by 8 gives the offset)
Other thing that I don't quite understand is the size of the logical address. As I've read, they are composed of a Segment Selector or Segment Number (16 bits) and the 32 bits offset. Is this total address 48 bits in size? Or just 16 bits of Segment Number and 16 bits of Offset.
this is a 16-bit segment selector (this selector identifies the permissions ring, whether it is a global or local segment (is it in the GDT or LDT), and which index in the descriptor table), which is combined with a 32-bit offset (actually, the offset can be either 16-bit or 32-bit, depending on the size indicator in the segment descriptor)

this means you have 7 different types of pointers:
16:16R -- These pointers are used when the GDT is suppressed (simulated RMode or emulated via VMode)
16-bit -- local 16-bit pointer pointing within the bounds of a currently selected a16 segment
32-bit -- local 32-bit pointer pointing within the bounds of a currently selected a32 segment
64-bit -- local 64-bit pointer pointing within the bounds of a currently selected a64 segment
16:16 (32-bits total) -- FAR pointer specifying an a16 segment and 16-bit offset within that segment
16:32 (48-bits total) -- FAR pointer specifying an a32 segment and 32-bit offset within that segment <- this is the one your documentation is referring to
16:64 (80-bits total) -- FAR pointer specifying an a64 segment and 64-bit offset within that segment
Post Reply