Page 1 of 1

GDT problem

Posted: Sun Jan 19, 2003 5:53 am
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 ?

Re:GDT problem

Posted: Sun Jan 19, 2003 6:06 am
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.

Re:GDT problem

Posted: Mon Jan 20, 2003 12:57 am
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]