Page 1 of 1

what is really the use of GDT??

Posted: Sat Aug 23, 2008 2:35 pm
by weezo
hello every one,
this is my first post here coz i am new here,
in short in all tutorials i read i found setting up GDT then i never hear about it again through the tutorial,my questions are:
what if i want to write segmented-memory model operating system does that mean laoding the executable into segment selector(in GDT) and jump to it???
were i can found tutorials about segmented-model operating systems that dont use paging??
thnx alot for interest :shock:

Re: what is really the use of GDT??

Posted: Sat Aug 23, 2008 2:52 pm
by mathematician
If you want to know how a segmented memory model works the easiest way is to read up on MS-DOS programming. From what I can gether most teach yourself books om assembly language programming still use MS-DOS programs for their examples. The difference between segmented memory in real and protected mode is not really that great, and principally involves the processor in looking up a segment address in the GDT, instead of reading it straight out of the segment register.

But why do you want to use a segmented memory model? Thanks to AMD it is no longer possible to do that if you are running in in 64 bit mode, even if you want to.

Re: what is really the use of GDT??

Posted: Sun Aug 24, 2008 12:40 pm
by Combuster
MS-Dos (real mode) segmentation is not the same as protected mode segmentation (which is the one that relies on GDT and LDT). In real mode, the processor "invents" GDT entries by taking the segment selector and multiplying it by 16 for using that as the segment's offset. Hardly much of the capabilities that the processor provides.

In protected mode, you'll have to provide a GDT (and if you want to use segmentation to its fullest, you probably want a LDT as well). Each selector now points to an entry in the GDT or LDT, which in turn determines the segment's offset and size, access permissions and a few more things.

The problems with protected mode segmentation is that you need a compiler that is aware of that. However, most compilers (i.e. all common ones) assume a flat memory model based on paging and no segmentation, or assume real-mode segmentation (all 16 bit compilers), making it a hell to write programs for your OS in a language other than assembly :(

Since paging is the norm, you'll find that everything around isn't meant for segmented models. Hence getting a segmentation based OS working takes some creativeness in respect to memory management, which you will figure can cause some classical problems. Expect an absense in tutorials for segmented memory models for the same reason, so you will really doing all the research on your own.
And as mathematician mentioned, segmentation was dropped in long mode (which you need for 64-bit code)

So, now you know what you're up to you can decide whether you actually want the added challenge, or prefer to take the beaten path. Irrespective of what you decide, we can help with other problems you might get.

Re: what is really the use of GDT??

Posted: Mon Aug 25, 2008 3:37 am
by weezo
thanx all for replies

Re: what is really the use of GDT??

Posted: Mon Aug 25, 2008 4:03 am
by mathematician
If you want a compiler which will do a segmented memory model in protected mode, I have a feeling Watcom's C compiler might do it.

Re: what is really the use of GDT??

Posted: Wed Aug 27, 2008 9:36 am
by DLBuunk
OS/2 made use of the Pmode segmented memory model, and Watcom C compiler can compile/link for OS/2. So mathematican is correct, you could try Watcom C.