GDT Type

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
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

GDT Type

Post 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
Matías Beretta
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

You will always need more than one (i.e. both code and data segments).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

Reply

Post by matias_beretta »

Ok, but, what type should i use for eachone?
Matías Beretta
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

Reply

Post 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.
Matías Beretta
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Reply

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post 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:
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

Reply

Post by matias_beretta »

Thanks Craze Frog, but i shouldn't the user code and data segments go into the LDT?
Matías Beretta
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

On a single-TSS system it doesn't need to. I don't even have an LDT!
User avatar
Dandee Yuyo
Member
Member
Posts: 47
Joined: Fri Nov 09, 2007 6:46 pm
Location: Argentina

Post 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).
NaN - Not a Nerd
Working on: Physical Memory Management with a 5-lod mipmap XD
Post Reply