Page 1 of 1

Is this code working properly to listen to IRQ ?

Posted: Fri May 30, 2014 4:12 pm
by Toggy
Hello,

I tried to the a PS2/Mouse driver, but I have some troubles with my IRQ I think, it is a bit strange because my keyboard work perfectly.
I wanted to know if this code was good or if I have not understand the IRQ concept.

Here I register listener:

Code: Select all

#include "io.h"
#include "idt.h"
#include "driver/mouse.h"

void _asm_default_int(void);
void _asm_irq_0(void);
void _asm_irq_1(void);
void _asm_irq_12(void);

/*
 * 'init_idt_desc' initialise un descripteur de segment situe en idt.
 * 'desc' est l'adresse lineaire du descripteur a initialiser.
 * L'argument 'type' doit avoir pour valeur INTGATE, TRAPGATE
 * ou TASKGATE.
 */
void init_idt_desc(u16 select, u32 offset, u16 type, struct idtdesc *desc)
{
	desc->offset0_15 = (offset & 0xffff);
	desc->select = select;
	desc->type = type;
	desc->offset16_31 = (offset & 0xffff0000) >> 16;
	return;
}

/*
 * Cette fonction initialise la IDT apres que le kernel soit charge 
 * en memoire. 
 */
void init_idt(void)
{
	int i;
	
	/* Initialisation des descripteurs systeme par defaut */
	for (i = 0; i < IDTSIZE; i++) 
		init_idt_desc(0x08, (u32) _asm_default_int, INTGATE, &kidt[i]);// default handler

	init_idt_desc(0x08, (u32) _asm_irq_0, INTGATE, &kidt[32]);	/* horloge */
	init_idt_desc(0x08, (u32) _asm_irq_1, INTGATE, &kidt[33]);	/* clavier */

	/* Initialisation de la structure pour IDTR */
	kidtr.limite = IDTSIZE * 8;
	kidtr.base = IDTBASE;

	/* Recopie de la IDT a son adresse */
	memcpy((char *) kidtr.base, (char *) kidt, kidtr.limite);

	/* Chargement du registre IDTR */
	asm("lidtl (kidtr)");
}
Here is my ASM code:

Code: Select all

extern isr_default_int, isr_clock_int, isr_kbd_int
global _asm_default_int, _asm_irq_0, _asm_irq_1
_asm_default_int:
	call isr_default_int
	mov al,0x20
	out 0x20,al
	iret

_asm_irq_0:
	call isr_clock_int
	mov al,0x20
	out 0x20,al
	iret

_asm_irq_1:
	call isr_kbd_int
	mov al,0x20
	out 0x20,al
        iret
This code is not really mine, I used a tutorial on a french website and I think the IRQ is not properly working, isn't it ?
My isr_default_int looks like not call, even if I had properly set up my mouse.

Thanks in advance

Re: Is this code working properly to listen to IRQ ?

Posted: Fri May 30, 2014 5:59 pm
by sortie
I'm sorry, I would look closer at this, but it's late. However, I can see at a glance that your interrupt handlers don't preserve the registers of whatever was interrupted. If that code was based on a tutorial, that tutorial is likely trash and you should discard it.

For reference, I am working on a tutorial and it's not finished yet, but it does show how I recommend doing interrupt handling (and other things) at the moment: https://gitorious.org/sortie/myos/

See also the http://wiki.osdev.org/System_V_ABI for information on the calling convention (assuming a gcc targeting ELF, such as a http://wiki.osdev.org/GCC_Cross-Compiler that we use as standard practice around here).

If this short and quick reply doesn't resolve your issues, I'll gladly take a closer look tomorrow. You should avoid non-English comments in your code when asking for help on an English forum, such comments are of little use to many of us and would potentially reduce the amount of help you can get.

Re: Is this code working properly to listen to IRQ ?

Posted: Fri May 30, 2014 6:28 pm
by Toggy
Ok thank you for your answer.
I think I have not understand something in the IRQ I will continue to work on this.
Thank you.

Re: Is this code working properly to listen to IRQ ?

Posted: Sat May 31, 2014 2:12 am
by Toggy
Well, I had put my mouse listener on the wrong entry, it was at "kidt[100]" because my IRQ vector for the 8-12 "port" is initialize at 0x70.
My mouse seems to not work actually, but it is probably an error in my mouse init because when I tried on Virtual Box instead of QEMU it tells me that the OS do not support mouse.
Is VirtualBox indicate the good error ? I means is it because I did an error when I initialize the mouse ?