GDT & IDT under paging...

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.
Post Reply
Silverhawk

GDT & IDT under paging...

Post by Silverhawk »

Hello,

I wonder what the utility of GDT,LDT & IDT when paging is enabled ?
I belived that paging disbled segmentation ?

thanks !
mystran

Re:GDT & IDT under paging...

Post by mystran »

Paging does not disable segmentation. You actually can't do that at all, and if people talk about about disabling segmentation they simply mean that they have one kernel CS of 4GB, one kernel data of 4GB and the same segments for user code, all starting from 0. This way all your segments can reference all the memory, with same offset pointing to same address in all segments.

The only difference between kernel and user segments is that when you are executing kernel code, you need a code-segment with "ring 0" priviledges, and need a data segment with the same ring. For user-level you want "ring 3" code segment and a data segment that can be accessed from "ring 3" code.

You don't necessarily need LDT at all, but you need GDT to define these 4 segments, plus at least one Task State Segment per processor (if you do software task-swithing) or per process (if you want to use the hardware mechanism).

IDT you use to describe your interrupt handlers, which you will want to do no matter what kind of memory model you want to implement.

Paging works after any segmentation has been applied. If you have all segments 4GB and starting from 0, then your logical address is directly the linear address, which is then looked for from the page directory to find a physical address.

If you had a segment starting from 0x20000 and you referenced memory at 0x00200 then your linear address would be 0x20200 (as long as the logical address is smaller than the segment limit). If you disabled paging, then linear address == physical address..

So basicly:

Code: Select all

 linear_address = apply_segmentation(logical_address)
and

Code: Select all

 physical_address = apply_paging(linear_address)
so that when both are in use

Code: Select all

 physical_address = apply_paging(apply_segmentation(logical_address))
This conversion is done by hardware. Segmentation you can only "disable" by defining such segments that it has no effect, while paging you can disable/enable with a control bit.

IDT is more or less different thing, and while you reference the segments in GDT to select the code segment that the interrupt handler should use (so you can tell if it runs with the priviledged or unpriviledged version of your code segment, when you have this "disabled", flat scheme), you need IDT to tell the processor where the handlers for different interrupts are.

So whether you use segmentation or not, you still need to define some segments with GDT, and you still need IDT to describe your interrupts. LDT is only useful if you use hardware task-switching and want task-specific segments, or if you need more segments than you can fit into GDT.

What this all means, is that you still need to understand the segments even if they are useless for you. Btw, the intel manuals describe the model where segments are used just for protection; it is common enough. The information is essentially the same as here, but with more detail.
Silverhawk

Re:GDT & IDT under paging...

Post by Silverhawk »

Thanks mystran !

I really enjoy your answer : it is very accurate !
This is bit more clear in my mind now.
I'm going to disgest it for a while... ;)

You've really helped me !!!
Post Reply