yet it causes a gpf when i divide by 0 even though i have a divide by zero handler installed
here is my code
Code: Select all
void init_idt(void){
word *idt;word *idtptr;dword *idtptr2;
dword intptr;
byte x=1;
__asm("cli");
idt=0x00000500; /*idt starts here*/
intptr=&int0h;
*idt=intptr & 0x0000FFFF;
idt++;idt++;
*idt=0x10;
idt++;idt++;
*idt=0x8E00;
idt++;idt++;
*idt=intptr & 0xFFFF0000 >> 16;
idt++;idt++;
while (x>=16){
intptr=&int0h;
*idt=intptr & 0x0000FFFF;
idt++;idt++;
*idt=0x10;
idt++;idt++;
*idt=0x8E00;
idt++;idt++;
*idt=intptr & 0xFFFF0000 >> 16;
idt++;idt++;
x++;
}
idt=0x00000500+0x21*6;
intptr=&int21h;
*idt=intptr & 0x0000FFFF;
idt++;idt++;
*idt=0x10;
idt++;idt++;
*idt=0x8E00;
idt++;idt++;
*idt=intptr & 0xFFFF0000 >> 16;
idt++;idt++;
loidt();
}
/*asm*/
_loidt:
lidt [idt_pointer]
ret
idt_pointer:
dw 03CAh - 0500h - 1
dd 0500h
/*end asm*/
#define ireturn __asm("iret")
byte key;
void int0h(void){
printf("Exception: Divide by zero error");cury++;
printf("Currently no way to recover; computer halted");
__asm("hlt");
__asm("iret");
}
void int20h(void){ /*irq0; bios tick*/
printc(0,0,'!');
ireturn;
}
void int21h(void){ /*irq1; keyboard*/
byte t;
strt:
t=inb(0x64) & 0x0001;
if (t>0){
key=inb(0x60);
}else{
goto strt;}
printc(0,1,'!');
ireturn;
}
/*EDIT:*/
void init_pics(int pic1, int pic2)
{
/* send ICW1 */
outb(PIC1, ICW1);
outb(PIC2, ICW1);
/* send ICW2 */
outb(PIC1 + 1, pic1); /* remap */
outb(PIC2 + 1, pic2); /* pics */
/* send ICW3 */
outb(PIC1 + 1, 4); /* IRQ2 -> connection to slave */
outb(PIC2 + 1, 2);
/* send ICW4 */
outb(PIC1 + 1, ICW4);
outb(PIC2 + 1, ICW4);
/* disable all IRQs */
outb(PIC1 + 1, 0xFF);
}
void main(void)
{ byte t=0,i=0;
curx=0;cury=0;
printf("hello from JuleOS!");
printf(" testing");
init_idt();
init_pics(0x20,0x28);
__asm("sti");
for(;;){
if (key!=0){printc(0,0,key); key=0;}
}
}
sorry for lack of comments and not that good of code readability