OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 7:06 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: IRQ mouse driver
PostPosted: Tue Apr 04, 2017 7:05 am 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2017 12:15 pm
Posts: 149
Location: Belgium
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:
interrupts/irq.c:4:1: error: parameter ‘irq_routines’ is initialized
void* irq_routines[16] = {


and here is the whole code:
Code:
#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

_________________
AQUA OS: https://obiwac.wordpress.com/aqua-os/


Top
 Profile  
 
 Post subject: Re: IRQ mouse driver
PostPosted: Tue Apr 04, 2017 7:25 am 
Offline
Member
Member

Joined: Sat Mar 01, 2014 2:59 pm
Posts: 1146
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.

_________________
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing


Top
 Profile  
 
 Post subject: Re: IRQ mouse driver
PostPosted: Tue Apr 04, 2017 7:45 am 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 384
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..


Top
 Profile  
 
 Post subject: Re: IRQ mouse driver
PostPosted: Tue Apr 04, 2017 7:47 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5137
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?)


Top
 Profile  
 
 Post subject: Re: IRQ mouse driver
PostPosted: Tue Apr 04, 2017 2:08 pm 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2017 12:15 pm
Posts: 149
Location: Belgium
Thank you so much to all who replied! It was the classical forgot to put semicolon error in the header file.

_________________
AQUA OS: https://obiwac.wordpress.com/aqua-os/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], SemrushBot [Bot] and 142 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group