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.
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 ...
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
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.