GDT Questions...

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
jrfritz

GDT Questions...

Post by jrfritz »

I'll just post some GDT questions here as they come up:

Can I make a CodeSel that can be read/write/exec?

Can I make a Stack Sel? If yes...how?
jrfritz

Re:GDT Questions...

Post by jrfritz »

Ok..I can make a stack sel...bit 010/011...

Could someone show me a example of a stack sel that is read/write? ( bit 011 )?

Also...

Can I make a CodeSel that can be read/write/exec?
beyondsociety

Re:GDT Questions...

Post by beyondsociety »

[attachment deleted by admin]
jrfritz

Re:GDT Questions...

Post by jrfritz »

Also...if I made a stack selector...how would I push values into there?
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 Questions...

Post by Pype.Clicker »

a code selector can *never* be written. If you need to write to a code chunk, use a data segment that maps the same memory region (though is discourage such ancient technique :-)

a stack segment is simply a data segment, though the "EXPAND DOWN" bit may sometimes be useful for stacks only: it will define the valid addresses ranging from limit to 0xffffffff instead of the usual [0..limit-1], which means you can easily protect from stack overflow
Guest

Re:GDT Questions...

Post by Guest »

hi,
i no dis is a lil off topic, but can neone give me links to some good online GDT, tutorials or docs that explain the GDT thoroughly and easily.
links would be most appreciated.
thnx
jrfritz

Re:GDT Questions...

Post by jrfritz »

My GDT:

gdtr
dw gdt_end
dd gdt
gdt
nullsel equ $-gdt
gdt0
dd 0
dd 0
codesel equ $-gdt
dw 0ffffh
dw 0
db 0
db 09ah
db 0cfh
db 0h
datasel equ $-gdt
dw 0ffffh
dw 0h
db 0h
db 092h
db 0cfh
db 0

gdt_end

And some Links:

http://osdev.neopages.net/tutorials/descripters.php
http://www.csee.umbc.edu/~plusquel/310/slides/micro_arch2.pdf
Curufir

Re:GDT Questions...

Post by Curufir »

Code: Select all

    dw gdt_end
I thought I'd already explained why this is wrong in another thread. This part of the gdt register is the size of the gdt.

Ok, let's make it simpler by describing a scenario. Let's say you load your gdt to a base above 64k linear. Now the maximum value you can stick into that word is 0xFFFF. Do you see why it cannot possibly be the memory location of the end of the gdt?

In your GDT the correct value is:

Code: Select all

gdt_end - gdt - 1
Why -1? Because the gdt_end label refers to the instruction following it. Ie 1 more than the actual length of your gdt.

I dunno who came up with the idea that this part of the GDTR is a memory reference but they need shooting, or pointing at the intel manuals :).
jrfritz

Re:GDT Questions...

Post by jrfritz »

Do I remove the gdt_end or how do I edit it to make it correct? code please?
jrfritz

Re:GDT Questions...

Post by jrfritz »

Ok...I had that in my code before...I must have gotton confused...
Post Reply