IDT and GDT

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
f2

IDT and GDT

Post by f2 »

What are these? What do they do? When are they set up? How are they set up?
K.J.

Re:IDT and GDT

Post by K.J. »

IDT: Interrupt Descriptor Table
(from the Intel 386 Reference Manual)
The interrupt descriptor table (IDT) associates each interrupt or exception identifier with a descriptor for the instructions that service the associated event.


GDT: Global Descriptor Table
(from the Intel 386 Reference Manula)
A descriptor table is simply a memory array of 8-byte entries that contain descriptors... A descriptor table is variable in length and may contain up to 8192 (2^(13)) descriptors. The first entry of the GDT (INDEX=0) is not used by the processor, however.

Descriptor:
(from the Intel 386 Reference Manual)
The segment descriptor provides the processor with the data it needs to map a logical address into a linear address. Descriptors are created by compilers, linkers, loaders, or the operating system, not by applications programmers.

The location of the GDT is specified with the lgdt assembly instruction. The location of the IDT is specified with the lidt assembly instruction.

The Intel 386 Reference Manual can be downloaded here:
http://www.execpc.com/~geezer/os/386intel.zip

Hope that helps you,
K.J.
f2

Re:IDT and GDT

Post by f2 »

How do us programmers write this IDT? And where is the source code placed? How is it organized?

>> The segment descriptor provides the processor with the data it needs to map a logical address into a linear address. <<

And what are linear addresses? Logical addresses? How are they different/alike?

Thanks!
K.J.

Re:IDT and GDT

Post by K.J. »

Download Chris Geise's OSD example kernels(written in C and ASM) for an example of setting up and using an IDT and a GDT:
http://www.execpc.com/~geezer/osd/code/osd.zip

K.J.
f2

Re:IDT and GDT

Post by f2 »

And what are linear addresses? Logical addresses? How are they different/alike?

And, should the link be http://www.execpc.com/geezer/osd/code/osd.zip because the '~' is screwing up the link, I think. Thanks!
K.J.

Re:IDT and GDT

Post by K.J. »

The links should be:
http://www.execpc.com/~geezer/os/386intel.zip
and
http://www.execpc.com/~geezer/osd/code/osd.zip

As for the differences/similarities or linear and lagical adresses, I don't know for sure, they seem to have "double" meaning.

K.J.
f2

Re:IDT and GDT

Post by f2 »

So why would you need to map a logical to linear if they're the same? I'm pretty confused about what these really are. Addressing?
DTShadowWolf

Re:IDT and GDT

Post by DTShadowWolf »

Logical Addresses are used in pmode with Virtual Memory by applications during run-time. It's supposed to be easier to use, ala Paging & what-not.

Linear Addresses occur from a flat memory layout ( generally before the GDT & IDT are setup along with virtual memory ), it can exist in PMode, but Logical Addresses w/ Paging are easier as Linear Addresses use Segmentation.

That's what I gather, maybe I'm off?
f2

Re:IDT and GDT

Post by f2 »

So this GDT just converts these addressings? Do we program this GDT, or is it just...there?
The_Legend

Re:IDT and GDT

Post by The_Legend »

Well basically you set it up and exec the LGDT instruction
to load it. But another question: Do you think it gets
permantly changed? (Gates or whatever, or do you stick
with interrupt gates which only affect the IDT?)
f2

Re:IDT and GDT

Post by f2 »

Is LGDT a NASM instruction? I don't recall it, but I'll go look it up. Thanks!
K.J.

Re:IDT and GDT

Post by K.J. »

[tt]lgdt[/tt] loads a gdt and [tt]lidt[/tt] loads an idt. They both work in NASM and are a standard x86 assembly instuction.

K.J.
f2

Re:IDT and GDT

Post by f2 »

Where does it load the GDT and IDT? Into memory? How is this of use to us?
Chris Giese

Re:IDT and GDT

Post by Chris Giese »

Descriptors define memory usage in protected mode. They
provide address translation, which means the code can be
linked to run at one address, but can be loaded into memory
at a different address. They also provide protection. Both
of these are very useful for multitasking.

The GDT is a table of descriptors. The LGDT instruction
tells the CPU where the GDT is, and how big it is.

The interrupt descriptor table (IDT) tells the CPU where
to jump when an interrupt occurs. The LIDT instruction
tells the CPU where the IDT is, and how big it is.

You get to write the GDT and IDT. They can be stored
anywhere in memory.

"Normal" addresses are relative to the segment base. A
linear address is relative to 0. I'm not sure, but Intel's
docs may have a different meaning for "linear". I also
don't know what a "logical" address is. Most of the
online lecture notes for OS design classes use the
terms "virtual address" and "physical address".

Here is some code and a .GIF that might help explain the GDT:
http://www.execpc.com/~geezer/osd/pmode/pmode.gif
http://www.execpc.com/~geezer/osd/pmode/quick.zip
jedld

Re:IDT and GDT

Post by jedld »

After setting up the GDT and entering
protected mode, is there any way
to change the contents and size of the GDT?,
I tried to add an entry to the GDT and then
when I assigned its corresponding selector
to the SS register,it reboots. How do you
change the GDT after entering pmode?
Post Reply