Page 1 of 1

IRQ mouse driver

Posted: Tue Apr 04, 2017 7:05 am
by obiwac
I am making an os in c and nasm, and I want to do irqs so that I can get a mouse driver to work. I found this: http://www.osdever.net/bkerndev/Docs/irqs.htm, but when I try to compile the c code part of it, I get:

Code: Select all

interrupts/irq.c:4:1: error: parameter ‘irq_routines’ is initialized
 void* irq_routines[16] = {
and here is the whole code:

Code: Select all

#include "irq.h"

void* irq_routines[16] = {
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0
	
};

void irq_add_handler(int irq, void (*handler) (struct registers* r)) {
	irq_routines[irq] = handler;
	
}

void irq_remove_handler(int irq) {
	irq_routines[irq] = 0;
	
}

void irq_remap(void) {
	outportb(0x20, 0x11);
	outportb(0xA0, 0x11);
	
	outportb(0x21, 0x20);
	outportb(0xA1, 0x28);
	outportb(0x21, 0x04);
	outportb(0xA1, 0x02);
	outportb(0x21, 0x01);
	outportb(0xA1, 0x01);
	outportb(0x21, 0x0);
	outportb(0xA1, 0x0);
	
}

void irq_init(void) {
	irq_remap();
	
	set_idt_gate(32, (unsigned) irq0);
	set_idt_gate(33, (unsigned) irq1);
	set_idt_gate(34, (unsigned) irq2);
	set_idt_gate(35, (unsigned) irq3);
	set_idt_gate(36, (unsigned) irq4);
	set_idt_gate(37, (unsigned) irq5);
	set_idt_gate(38, (unsigned) irq6);
	set_idt_gate(39, (unsigned) irq7);
	set_idt_gate(40, (unsigned) irq8);
	set_idt_gate(41, (unsigned) irq9);
	set_idt_gate(42, (unsigned) irq10);
	set_idt_gate(43, (unsigned) irq11);
	set_idt_gate(44, (unsigned) irq12);
	set_idt_gate(45, (unsigned) irq13);
	set_idt_gate(46, (unsigned) irq14);
	set_idt_gate(47, (unsigned) irq15);
	
}

void irq_handler(struct registers* r) {
	void (*handler) (struct registers* r);
	handler = irq_routines[r->num - 32];
	
	if (handler) {
		handler(r);
		
	} if (r->num >= 40) {
		outportb(0xA0, 0x20);
		
	}
	
	outportb(0x20, 0x20);
	
}
Sorry if this is not the right place to ask, but as you all develop oses as oppose to, for example, the people on stackoverflow or something, then I would assume that you would have encountered this problem once if not, multiple times.

Thanks in advance, all replies will be appreciated!! :D

Re: IRQ mouse driver

Posted: Tue Apr 04, 2017 7:25 am
by onlyonemac
From the error message, it sounds like your compiler doesn't like the initialisation of the array "irq_routines". There are three likely reasons for this (I'm not 100% sure because it's been a while since I did much with C and I don't normally initialise arrays like that):
  • You're trying to initialise an array with pointers with a list of integers. Try replacing the "0"s with "NULL"s.
  • You've declared a size for the array *and* provided an initialiser list. Try removing the "[16]" from the definition of the array.
  • Your compiler doesn't let you initialise an array of pointers
These are just guesses. There are often subtle differences like this between compilers, or between different versions of the same compiler, or between different configurations of the compiler. It's possible that the person who wrote the tutorial was using a different compiler which didn't have a problem with this.

Also make sure you've entered or copied-and-pasted the code correctly.

Re: IRQ mouse driver

Posted: Tue Apr 04, 2017 7:45 am
by LtG
You didn't include your irq.h in your post, the issue might also be there.. Maybe you missed a semicolon (;), a parentheses, etc.. Quite possibly simple syntax error. Also you didn't mention which compiler you use..

Re: IRQ mouse driver

Posted: Tue Apr 04, 2017 7:47 am
by Octocontrabass
In general, error messages from your compiler aren't going to be specific to OS development, so you can get some useful information about them from Google.

For this error in particular, you've probably made a mistake in irq.h that looks like an unfinished function declaration to the compiler. (Did you forget a semicolon somewhere?)

Re: IRQ mouse driver

Posted: Tue Apr 04, 2017 2:08 pm
by obiwac
Thank you so much to all who replied! It was the classical forgot to put semicolon error in the header file.