GDT and IDT problems
Posted: Fri Oct 15, 2004 3:44 am
Hello,
I'm currently switching from a three-staged OS to a two-staged one. I made this piece of code yesterday and I'm having some troubles with it.
Now everytime I try to add a new segment descriptor (a video segment, a call gate, ...) in the init file, I get an error. The error occurs when I move the address of the newly created video descriptor in gs for example. Why? Isn't possible to add a new segment descriptor to an existing GDT?
Also, what is the problem with the IDT, everytime I try 'int 0' I get an error.
Thank you in advance.
Boot file:
Init file:
I'm currently switching from a three-staged OS to a two-staged one. I made this piece of code yesterday and I'm having some troubles with it.
Now everytime I try to add a new segment descriptor (a video segment, a call gate, ...) in the init file, I get an error. The error occurs when I move the address of the newly created video descriptor in gs for example. Why? Isn't possible to add a new segment descriptor to an existing GDT?
Also, what is the problem with the IDT, everytime I try 'int 0' I get an error.
Thank you in advance.
Boot file:
Code: Select all
[bits 16]
[org 0x7c00]
jmp boot
GDTR:
GDTsize dw GDTEND-GDT-1
GDTbase dd 0x500
GDT:
NULLSEL EQU $-GDT
dd 0
dd 0
CODESEL EQU $-GDT
dw 0xFFFF
dw 0
db 0
db 0x9A
db 0xCF
db 0
DATASEL EQU $-GDT
dw 0xFFFF
dw 0
db 0
db 0x92
db 0xCF
db 0
GDTEND:
boot:
mov ax,cs
mov ds,ax
mov es,ax
mov fs,ax
mov ax,0x200
mov ss,ax
mov sp,0x1000
read:
mov ax,900h
mov es,ax
xor bx,bx
mov ah,2
mov al,3
xor ch,ch
mov cl,2
xor dx,dx
int 13h
jc read
mov dx,0x3F2
mov al,0x0C
out dx,al
xor ax,ax
mov ds,ax
mov es,ax
mov si,GDT
mov di,[GDTbase]
mov cx,[GDTsize]
cld
rep movsb
cli
mov eax,cr0
or al,1
mov cr0,eax
lgdt [GDTR]
jmp CODESEL:FLUSH
[bits 32]
FLUSH:
mov eax,DATASEL
mov ds,eax
mov es,eax
mov fs,eax
mov gs,eax
mov ss,eax
mov esp,0xffff
jmp dword 8h:9000h
TIMES 510-($-$$) db 0
DW 0xAA55
Init file:
Code: Select all
[bits 32]
[org 9000h]
mov ebx,Int01Handler
mov [entry00],bx
shr ebx,16
mov [entry00+6],bx
mov si,GDT
mov di,[GDTbase]
mov cx,[GDTsize]
cld
rep movsb
mov si,IDT
mov di,[IDTbase]
mov cx,[IDTsize]
cld
rep movsb
lidt [IDTR]
lgdt [GDTR]
mov eax,DATASEL
mov ds,eax
mov es,eax
mov fs,eax
mov eax,VIDEOSEL ;<+++ NOT WORKING
mov gs,eax
mov eax,DATASEL
mov ss,eax
mov esp,0xffff
;mov ecx,4 ;<+++ these were working before I changed the GDT
;mov edi,0b8000h
;mov esi,string
;rep movsw
int 0
jmp $
Int01Handler:
jmp $
iret
string db 't e s t ',0
GDTR:
GDTsize dw GDTEND-GDT-1
GDTbase dd 0x500
GDT:
NULLSEL EQU $-GDT
dd 0
dd 0
CODESEL EQU $-GDT
dw 0xFFFF
dw 0
db 0
db 0x9A
db 0xCF
db 0
DATASEL EQU $-GDT
dw 0xFFFF
dw 0
db 0
db 0x92
db 0xCF
db 0
VIDEOSEL EQU $-GDT ;
db 9fh
db 0fh
db 0
db 80h
db 0bh
db 10010010b
db 0
db 0
GDTEND:
IDTR:
IDTsize dw IDTEND-IDT-1
IDTbase dd 0x600
IDT:
entry00:
dw 0
dw 8h
db 0
db 10001110b
dw 0
IDTEND: