Help with IDT's and PIC's

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
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Help with IDT's and PIC's

Post by earlz »

I my idt i am having problems, it does not crash after enabling ints but it dont cause any interrupts such as irq 0(mapped to 0x20) or irq1(remapped to 0x21)
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
Last edited by earlz on Sat Sep 10, 2005 11:00 pm, edited 1 time in total.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Help with IDT's and PIC's

Post by xenos »

It seems to me the problem is caused by increasing the idt pointer twice between writing new data into the IDT:

Code: Select all

	idt++;idt++;
But since you declared idt as a pointer of type word

Code: Select all

word *idt;
each increment already moves to the next word location.
Post Reply