Page 1 of 1

GDT misconfigured

Posted: Tue Aug 30, 2016 9:51 am
by leosa99
Hi !
I got a problem setting a 'test' GDT.
I want a short code segment starting from 0x1000 to 0x2000 but i can't figure out how to set up this code segment.
I know that the problem comes from my code segment cause if i set my code segment to start from 0x0 and end like my data segment, it works. So the problem is my code segment ...

Thanks in advance !

Here's my GDT :

Code: Select all

GDT_NULL:
dd 0
dd 0

; The problem is here ...
; CS 0x1000 to 0x2000
; 0x1000 = 1000 0000 00000 (bin)
GDT_CS:
dw 0001 0000 0000 0000b ; Limit (low 2 bytes)
db 0000 0000b ; Base (low 3 bytes)
db 0001 0000b ; Base again
db 0000 0000b ; Base again
db 1001 1000b ; Access
db 0000 0100b ; Limit (high 4 bits) & Flags
db 0000 0000b ; Base (high byte)

GDT_DS:
dw 1111111111111111b
db 00000000b
db 00000000b
db 00000000b
db 10010010b ; Access
db 11110100b ; Limit & Flags
db 00000000b

END_GDT:

GDT_PTR:
dw END_GDT - GDT_NULL - 1
dd GDT_NULL

Re: GDT misconfigured

Posted: Tue Aug 30, 2016 5:48 pm
by Octocontrabass
leosa99 wrote:

Code: Select all

db 0000 0100b ; Limit (high 4 bits) & Flags

db 11110100b ; Limit & Flags
It looks like you're putting the flags and the high four bits of the limit in the wrong order.

Why are you using segmentation anyway? It's rendered completely* obsolete by paging. All sane operating systems set up the GDT for a flat memory model (base=0, limit=4GB on all segments) and then use paging for memory management.

*Well, mostly. It does have a few uses, like thread-local data, but you don't need to worry about that now.

Re: GDT misconfigured

Posted: Wed Aug 31, 2016 3:09 am
by leosa99
Yeah i see the mistake, thanks !