OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 27, 2024 4:45 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Question about segmentation in x80-86
PostPosted: Thu Jul 06, 2023 1:46 am 
Offline

Joined: Thu Jul 06, 2023 1:13 am
Posts: 1
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.


Top
 Profile  
 
 Post subject: Re: Question about segmentation in x80-86
PostPosted: Thu Jul 20, 2023 7:41 pm 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
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 ×.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: Question about segmentation in x80-86
PostPosted: Thu Jul 20, 2023 9:03 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 27, 2004 11:00 pm
Posts: 874
Location: WA
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)
Quote:
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

_________________
## ---- ----- ------ Intel Manuals
OSdev wiki


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group