GDT problem

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
pini

GDT problem

Post by pini »

here's my gdt code :
[pre]gdt:
db 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
db 0xFF,0xFF,0x0,0x0,0x0,0x9A,0xCF,0x0
db 0xFF,0xFF,0x0,0x0,0x0,0x92,0xCF,0x0
gdtend:

gdtptr:
dw 0
dd 0

mov ax,gdtend
mov bx,gdt
sub ax,bx
mov [gtdptr],ax
mov ax,ds
movzx ecx,ax
shl ecx,4
mov ebx,gdt
add ecx,ebx
mov [gdtptr+2],ecx
lgdt [gdtptr]
mov eax,cr0
or eax,0x1
mov cr0,eax
jmp next
next:
mov ax,0x10
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
mov esp,0x8000
jmp dword 0x8:KERNEL_ADDRESS[/pre]
And I get a sequence of messages like this with bochs :
[pre]selector->index*8+7 = 5583
gdtr.limit=40
fetch_raw_descriptor: GDT: index > limit[/pre]
and bochs pushes 16 bytes on the stack until ESP reaches the bottom of the memory.

What is the problem ?
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:GDT problem

Post by df »

Code: Select all


mov ax,(gdtend - gdt) -1
mov word [gdt],ax

movzx eax,ds
shl eax,4
mov ebx,gdt
add eax,ebx
mov dword [gdt+2],eax

lgdt [gdt]

mov eax,cr0
or al,1
mov cr0,eax

jmp next
next:

mov ax,0x10
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
mov esp,0x8000
jmp dword 0x8:KERNEL_ADDRESS

gdt:
db 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
db 0xFF,0xFF,0x0,0x0,0x0,0x9A,0xCF,0x0
db 0xFF,0xFF,0x0,0x0,0x0,0x92,0xCF,0x0
gdtend:

untested. might have bugs.
-- Stu --
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:GDT problem

Post by Pype.Clicker »

- you should CLI before you call this code.
- i suggest the "jmp next" become a jmp 0x08:next and that the code that do segments initialization is in [bits 32]
Post Reply