Page 1 of 1

Help me out of this problem

Posted: Sun Aug 31, 2003 11:06 am
by The_Pro
hello all,
i'm developing out a protected-mode os. I've jumped into the pmode and now i've started writing interrupts. I heard that interrupts 0h-1fh are exceptions and 20h-2fh are for hardware interrupts. I've written a procedure to install the interrupts. The idt structure is:

idt:

%rep 0x1f
   dw   0
   dw   08h
   db   0
   db   8eh
   dw   0
%endrep

idt_end:

idt_descriptor:
size   dw   idt_end - idt - 1
   dd   idt

------------------------------------


   I've written a simple interrupt handler for the divide by 0 exception. But, when i write a code as:

   mov   ax, 20h
   mov   bl, 0h
   div   bl
i get the error message as 3rd (13) exception with no resolution. The interrupt handler is below:

int_0:
   pusha
   push   ss
   push   gs
   push   ds
   push   fs

   pop   fs
   pop   ds
   pop   gs
   pop   ss
   popa
   iretd

   The gdt structure for the code segment is :

code_descriptor:

   dw   0xFFFF
   dw   0
   db   0
   db   0x9A
   db   0xCF
   db   0



   Please help me out of this problem.

Thanks in advance.

Re:Help me out of this problem

Posted: Sun Aug 31, 2003 12:06 pm
by Therx
I presume you've loaded handler addresses into the IDT structure before the lidt instruction.

Re:Help me out of this problem

Posted: Sun Aug 31, 2003 1:00 pm
by Pype.Clicker
I guess i'm just repeating what Pete said, but the code you showed just creates an IDT which makes every handler to be located at 0x08:0x0000 ... you need to have something like "setup_handler" function which would install function X as handler for interrupt Y.

for instance:

Code: Select all

;; expects eax=handler and edx=interrupt number.
;; no register modified
setup_idt_handler:
    mov [idt+edx*8],ax
    rol eax,16
    mov [idt+6+edx*8],ax
    rol eax,16
    ret

setup_idt:
    ...
    mov eax,int_0
    xor edx,edx
    call setup_idt_handler;
    ...
    lidt[...]
btw, as your so-called "int_0 handler" does nothing but returning, your code will be halting on "div" instruction, continuously calling the DIV_BY_0 exception and returning to the faulty instruction :-/