GDT Help

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
beyondsociety

GDT Help

Post by beyondsociety »

Im at the point where I want to implement the gdt trick for addressing 4GB of memory without enabling paging. How do I set this up?

0xA0000000 + base = 0x100000
base = 0x100000 - 0xA0000000
base = -9FF00000 = 60100000

Do I have to add this base to the gdt segments: code, data? Or do I need to add the base to the gdt pointer that gets loaded by lgdt? For instance:

Code: Select all

gdt_ptr: gdt_end - gdt_start - 1 ; Limit
gdt ;base
Adek336

Re:GDT Help

Post by Adek336 »

Only GDT.base.

Look:
JMP CS:0xA000_0000

CS.base = 0x6010_0000

CS.base + offset = 0x6010_0000 + 0xA000_0000 = 0x1_0010_0000.

When you put 1_0010_0000 into a longword you get 10_0000. So what you have to do, is to get this overflow. By setting the GDT.base to 6010_0000. Not GDTR. Do you understand how this trick works?

Btw, you don?t access 4Gb with this technique, all it is useful for is to allow a kernel linked at 0xa000_0000 init paging.

Cheers,
Adrian.
beyondsociety

Re:GDT Help

Post by beyondsociety »

Do you understand how this trick works?
Could you explain it more throughly.
Adek336

Re:GDT Help

Post by Adek336 »

JMP CS:0xA000_0000
the CPU puts the logical adress into a longword:

A000_0000

adds the cs.base:

A000_0000
6010_0000 +

and the value is

0010_0000 because the 33 bit is not saved in a longword.

So it is an overflow, where the 33 bit is ignored.

Cheers,
Adrian.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:GDT Help

Post by Pype.Clicker »

there's a nice previous thread which discuss the whole trick. Hope it'll help ;)
Post Reply