Loadin up the GDT whilst in protected mode.

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

Re:Loadin up the GDT whilst in protected mode.

Post 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
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:Loadin up the GDT whilst in protected mode.

Post 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!
-- Stu --
Post Reply