Just a quick question, for educational and self debugging purposes, I was wondering if it was possible to read entries from the Global Descriptor Table, for example:

GDT          db          00,00
GDTaddr   db          00,00,00,00

sgdt GDT
sub dword ptr[GDTaddr],18     ;2nd Entry
mov edi,dword ptr[GDTaddr]
mov esi,offset entry
mov ecx,8h                               ;entry is 8 bytes long
loopr:
lodsb
stosb
loop loopr

Program keeps stopin, i would assume ad lodsb, so I was wonderin if the address of the GDT was not readable.

What you're trying to do is not useful to an application so why are you tinkering around in there? Most programmers who work in assembly can go their entire lives without working with system instructions. Are you planning on designing your own operating system or modifying an existing one?

For example:
Instruction Description Useful to App.? Protected from App?
SGDT Store GDT register No No
LGDT Load GDT register No Yes

Yeah, I know it is not important to an application, and mainly for building an OS. But i aint buildin an operating system, I'm not even using that code i stuck up in my last post in my program, this was only for trying to find out if I could access, or read, entries from the GDT, so i could follow and debug my program for my own learning. Or are we not allowed to get information from that?

As I posted you can read it only, but I really don't see what good it will do you for debugging.
By the way its only 6 bytes. segment and selector.

Well, its not so much debugging, really just more, following the process of my application.

Ok, so i know that I can access the address of the GDT, but is it possible to access the entries with in it?

For example, if i wanted to find the Virtual Address of the stack segment, and the ss register was equal to 0x0023, this then means that to find that address we must find the entry with in the GDT,
0x23 meaning entry: 2 of the GDT? right? So when i try to access this, or at least I think I am, the program terminates. Is this reason because I do not have access to this?

ya ya, I've had those downloaded for a long time, I use those alot, but I doesn't seem to inform, or at least I cannot find, whether or not reading entries from the GDT is allowed. Which is why i came here. This will clear things up for me because if reading entries from the GDT are not allowed, this explains why my program is screwin up, otherwise, I've made the fault some where when I typed in the numbers. Thanks for the help though.

*PROTECTED MODE STUFF*
If you are running as an application program,
then you application is most likely running in another ring
of the processor and most likely will not be able to
execute privileged instructions like SGDT and LGDT.
Applications programs address space is limited by the LDT,
and does not correspond to GDT entries.
A segment selector used in segment registers in protected
mode acts as an index into a table of segment descriptors.
Segment descriptors contain the size,attributes,and beginning
linear address of segments.
The beginning linear address of a descriptor table
is stored in GDTr and LDTr registers, the processor
multiplies a selector by 8 to index into these entries.
Hope this helps.

great, yeah, so if I'm not able to access SGDT, and if i still used it, what would be the meaning of the value that it returned, becuase i got one. Also, does this mean the GDT is located in a different 4GB RAM area? but the LDT is located in the same Ram as the program? or at least the descriptor tables point to segments that are in the same RAM as my application, right. Basically I'm trying to find these segmented areas in the Applications RAM, wondering if its possible.

As to the meaning of the value returned by SGDT it will be
a 48-bit BASE Address/Limit value.
I do not know much about protected mode,
I just play around in DOS.

You cannot access the GDT from within an application. The operating system aqnd hardware, between the two of them, conspire to ensure that an application can only access the memory allocated to it. They do that to prevent an application from trashing another applications code and data, or, even worse, the operating system's code and data.

A GDT entry contains a segment address (usually set to zero in modern operating systems), a 32 or 48 bit offset address (depending upon whether it is a 32 bit or 64 bit processor), and various flags all mixed up togetrher. The flage determine such things as:

Can you read from the segment?
Can you write to the segment?
Does the segment contain code or data?
Is the segment present in memory (rather than swapped out to disk)
The segment's privilege level

And so on.

Edited 7 Years Ago by mathematician: n/a

Well assuming that you are running a protected mode operating system such as Windows or Linux, you can be absolutely certain that it is loaded. Your computer would collapse on the floor otherwise.

This article has been dead for over six months. Start a new discussion instead.