Page 1 of 1

GDT Type

Posted: Mon Dec 10, 2007 4:38 pm
by matias_beretta
Can you tell me what GDT type should I use? I only want to have 1 segment to access the whole memory.

Data:
------
* Read-Only
* Read-Only, accessed
* Read/Write
* Read/Write, accessed
* Read-Only, expand-down
* Read-Only, expand-down, accessed
* Read/Write, expand-down
* Read/Write, expand-down, accessed

Code:
-------
* Execute-Only
* Execute-Only, accessed
* Execute/Read
* Execute/Read, accessed
* Execute-Only, conforming
* Execute-Only, conforming, accessed
* Execute/Read-Only, conforming
* Execute/Read-Only, conforming, accessed

Thanks

Posted: Mon Dec 10, 2007 5:07 pm
by Combuster
You will always need more than one (i.e. both code and data segments).

Reply

Posted: Mon Dec 10, 2007 5:08 pm
by matias_beretta
Ok, but, what type should i use for eachone?

Posted: Mon Dec 10, 2007 5:16 pm
by Combuster
Do you want to be able to write to memory?
Do you want to have the segment go from 0 to 4G or from 4G to 0
Do you want to have the segment tagged as used or unused
Do you want to read from CS-relative addresses
Are you aware of the difference between conforming and non-conforming segments?
Did you know that all the information you need to answer these questions for yourself is in the intel manuals?

Reply

Posted: Mon Dec 10, 2007 5:58 pm
by matias_beretta
Do you want to be able to write to memory?
Yes
Do you want to have the segment go from 0 to 4G or from 4G to 0
What's the difference?
Do you want to have the segment tagged as used or unused
What is used or unused?
Do you want to read from CS-relative addresses
Yes
Are you aware of the difference between conforming and non-conforming segments?
As far as i know and understand, comforming is when you jump to another segment with another protection level and you still use the protection of the other segment.
Did you know that all the information you need to answer these questions for yourself is in the intel manuals?
Yes, I have those manuals. Things related to GDT (page 73...)

Sorry if you cant understand my definition of comforming and non-comforming, i am from argentina and i'm still studing english.

Re: Reply

Posted: Tue Dec 11, 2007 1:55 am
by Combuster
matias_beretta wrote:Do you want to be able to write to memory?
Yes
Do you want to have the segment go from 0 to 4G or from 4G to 0
What's the difference?
Do you want to have the segment tagged as used or unused
What is used or unused?
Do you want to read from CS-relative addresses
Yes
Are you aware of the difference between conforming and non-conforming segments?
As far as i know and understand, comforming is when you jump to another segment with another protection level and you still use the protection of the other segment.
It seems to me that you know everything needed to make an educated choice about what GDT type you want to use. :roll:

Posted: Tue Dec 11, 2007 9:31 am
by Craze Frog
Here's my GDT ("tutorial standard"):

Code: Select all

align 8
; null descriptor
gdt:    dw 0
        dw 0
        db 0
        db 0
        db 0
        db 0
; kernel code
KERNEL_CODE_SEL    =  $-gdt   ; Segment selector
gdt2:   dw 0xFFFF               ; limit 0xFFFFF
        dw 0                    ;
        db 0                    ;
        db 0x9A                 ; present, ring 0, code, readable
        db 0xCF                 ; page-granular, 32-bit
        db 0                    ;
; kernel data
KERNEL_DATA_SEL    =  $-gdt     ; Segment selector
gdt3:   dw 0xFFFF               ; limit 0xFFFFF
        dw 0                    ; base 0
        db 0
        db 0x92                 ; present, ring 0, data, writable
        db 0xCF                 ; page-granular, 32-bit
        db 0
; user code
USER_CODE_SEL      =  $-gdt+3   ; Segment selector
gdt4:   dw 0xFFFF
        dw 0
        db 0
        db 0xFA                 ; present, ring 3, code, readable
        db 0xCF
        db 0
; user data
USER_DATA_SEL      =  $-gdt+3
gdt5:   dw 0xFFFF
        dw 0
        db 0
        db 0xF2                 ; present, ring 3, data, writable
        db 0xCF
        db 0
gdt_end:

Reply

Posted: Wed Dec 12, 2007 7:17 am
by matias_beretta
Thanks Craze Frog, but i shouldn't the user code and data segments go into the LDT?

Posted: Wed Dec 12, 2007 7:21 am
by JamesM
On a single-TSS system it doesn't need to. I don't even have an LDT!

Posted: Wed Dec 12, 2007 11:36 am
by Dandee Yuyo
Eh Matias! Saludos desde Argentina! :D

You don't need an LDT, even with multiple TSSs. I do task-switching via TSSs and a task gate, and I only use the GDT. Moreover I wouldn't recommend to "abuse" of segmentation since it is not supported in 64-bit long mode (in case you want to make your OS 64 bits in the future).