Page 1 of 1

IDT problems

Posted: Sat Dec 04, 2004 5:17 pm
by jka913
Hi, I recently started working on the IDT and interrupts in my OS, but have been having some problems. I cannot seem to figure out why my code isn't working. Whenever I boot it it just restarts.

Here is the code:

Code: Select all

start:
 mov eax,isr49
 mov WORD [idt+0x49*8],ax??????;move low address
 mov WORD [idt+0x49*8+2],SELECTOR???;move selector
 mov WORD [idt+0x49*8+4],0x8E00
 shr eax,16?????????;move high address into ax
 mov WORD [idt+0x49*8+6],ax???;move high address
 lidt [idt_pointer]      ;load idt
 int 0x49
 jmp $

SELECTOR dw 0x10
idt:
 resb 0x50*8    ;descriptor = 8 bytes, ints 0-49
end_idt:
idt_pointer:
 dw end_idt - idt - 1
 dd idt 

isr49:
 pusha???;\
 push ds???; |
 push es???; |push registers
 push fs???; |
 push gs???;/

 mov ebx,0xB8000   ;0xB8000 = video memory
 mov al,0x44???   ;0x44 = 'D'
 mov BYTE [ebx],al ;print 'D'

 pop gs??????;\
 pop fs??????; |
 pop es??????; |pop registers
 pop ds??????; |
 popa??????;/
 iret
Thanks for any help,
jka913

Re:IDT problems

Posted: Sat Dec 04, 2004 8:12 pm
by Brendan
Hi,
jka913 wrote: Hi, I recently started working on the IDT and interrupts in my OS, but have been having some problems. I cannot seem to figure out why my code isn't working. Whenever I boot it it just restarts.

Here is the code:
This all looks correct, assuming that it's been cut & pasted to save space ("SELECTOR" may need to be defined before use, the IDT would be in the .bss section and the idt_pointer would be in the .data section).

Can you run it through Bochs and see what the CPU was doing when it crashes?


Cheers,

Brendan

Re:IDT problems

Posted: Sun Dec 05, 2004 12:06 pm
by ASHLEY4
One thing i see, that may not be has it should, is your using HEX number for DEC numbers.
eg:

Code: Select all

resb 0x50*8    ;descriptor = 8 bytes, ints 0-49; this is 0-79
0x50*8 this 80 *8

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.

Re:IDT problems

Posted: Sun Dec 05, 2004 8:41 pm
by Brendan
Hi,
ASHLEY4 wrote: One thing i see, that may not be has it should, is your using HEX number for DEC numbers.
eg:

Code: Select all

resb 0x50*8    ;descriptor = 8 bytes, ints 0-49; this is 0-79
0x50*8 this 80 *8
I think it's only an incorrect comment - (IMHO) it should be:

Code: Select all

resb 0x50*8    ;descriptor = 8 bytes, ints 0x00-0x4F; this is 0-79
In any case it shouldn't effect interrupt number 0x49...


Cheers,

Brendan

Re:IDT problems

Posted: Sun Dec 05, 2004 8:55 pm
by jka913
I found the problem, the tutorial I was using used 0x10 for the selector and I had no idea what this was, so I just used that. Apparently it is supposed to be 0x8, it now works. ;D

Re:IDT problems

Posted: Sun Dec 05, 2004 10:11 pm
by Curufir
No. Don't just use it because it works.

The reason it works is because in this particular case 0x10 is probably a data selector and 0x8 is a code selector. The actual value 0x8/0x10 is immaterial, it's just an offset to a selector in the GDT. The reboot is likely due to an unhandled exception leading to a triple fault because you are trying to load CS with a non-executable selector.

Work the whole problem solving process, don't just hack away until things work, try to understand why they failed in the first place. Otherwise things rapidly turn into some kind of voodoo.

Hopefully you already figured the problem before you made the change, but your last comment was unclear. Whether you did or not it's still good advice IMHO.

Apologies for preaching, especially if my analysis was wrong.