IDT problems

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
jka913

IDT problems

Post 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
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:IDT problems

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
ASHLEY4

Re:IDT problems

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:IDT problems

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
jka913

Re:IDT problems

Post 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
Curufir

Re:IDT problems

Post 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.
Post Reply