Page 2 of 2

Re:Loadin up the GDT whilst in protected mode.

Posted: Wed Jan 08, 2003 1:10 pm
by Guest
hi
i took curufir advice oand added this statement to my code:

dw gdt_end - gdt - 1

now it links fine without ne errors
so my gdt loadin funcion is:

[BITS 32]

segment .text

[global _loadGDT]


gdtr
   dw gdt_end - gdt - 1
   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

; Begin Load GDT
_loadGDT:

   ;push ebp
   ;mov ebp, esp
   lgdt [gdtr]      ; Load GDT
   ;pop ebp         ; Restore Caller's stack frame
   ret
; End Load GDT

so is dat all i need to do 2 load the GDT or do i need to do nething else?
so wot do i do next after setting up the gdt?

thnx

Re:Loadin up the GDT whilst in protected mode.

Posted: Wed Jan 08, 2003 1:33 pm
by df

Code: Select all

gdtr
   dw gdt_end - gdt - 1
   dd gdt
gdt:
remember when you build your gdt,

Code: Select all

movzx eax,ds
shl eax,4
add eax,gdt

mov dword [gdtr + 2], eax
its a flat offset! you must calculate your datasegment it lives in from segment to 32bit address

also remember the GDT trick, the first selector is a null selector, so you can use it to hold your size/pointer!