Problem with unmasking irq'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
petrusss

Problem with unmasking irq's

Post by petrusss »

Hi!
I'm having problems with my OS, I'm trying to fix hardware interrupts but I can't make it work... :|
Software interrupts work perfectly.
When I try to unmask the keyboard, I get a General Protection Fault.

This is my unmasking code:

Code: Select all

void unmaskIRQ(unsigned char irq) {
   if(irq==ALL) {
      outb(MASTERDATA,0x00);
      outb(SLAVEDATA,0x00);
   }
   else {
      irq = irq & (1<<irq);

      if(irq < 8)
         outb(MASTERDATA, irq&0xFF);
      else
         outb(SLAVEDATA, irq>>8);
   }
}
petrusss

Re:Problem with unmasking irq's

Post by petrusss »

And here's the main code:

Code: Select all

extern void kbdHandler_stub();
extern void print_version_stub();

void kbdHandler();
void print_version();

void kstart() {
   INTS(false);
   remapPIC(0x20,0x28);
   maskIRQ(ALL);

   LoadExceptions();

   AddInt(KEYBOARD, kbdHandler_stub, 0);
   AddInt(21, print_version_stub, 0);


   loadIDTR();


   unmaskIRQ(KEYBOARD);
   INTS(true);


   kclearScreen();
   kprintf("Welcome!");

   asm("int $1");

   return;
}

void print_version() {
   kprintf("\n======================\n");
   kprintf("PeOS version 0.0000001\n");
   kprintf("======================\n");

}


void kbdHandler() {
   kprintf("Key pressed!");
   // char scancode = inb(0x60);


    //sendEOI();
   //outb(0x21, EOI);
}
I've tried to put the call to unmaskIRQ elsewhere in the code, but I still get GPF.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Problem with unmasking irq's

Post by Pype.Clicker »

petrusss wrote: This is my unmasking code:

Code: Select all

void unmaskIRQ(unsigned char irq) {
   if(irq==ALL) {
      outb(MASTERDATA,0x00);
      outb(SLAVEDATA,0x00);
   }
   else {
      irq = irq & (1<<irq);

      if(irq < 8)
         outb(MASTERDATA, irq&0xFF);
      else
         outb(SLAVEDATA, irq>>8);
   }
}
There are things that looks weird in the "irq = irq & (1<<irq)" command. I would rather have expected something like

Code: Select all

   irqmask = inb(MASTERDATA); 
   irqmask &= (1<<irq);
   outb(MASTERDATA,irqmask);
so that only the bit from "irq" number is toggled, and other are left unchanged.
There are chances that your code also enable IRQ0, which has no handler so far and thus will trigger GPF every 1/18.2 sec.
petrusss

Re:Problem with unmasking irq's

Post by petrusss »

Thanks, I don't get GPF now :)
But I still don't get keypresses :|
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Problem with unmasking irq's

Post by Pype.Clicker »

where do "kstart()" returns to ? if it's a 'cli; hlt" loop, you're unlikely to get any keypress at all ...

Did you sent an end-of-interrupt signal to the PIC in your handler?
Did you read the byte from the keyboard controller ?

both these stuff are mandatory to get more IRQ1 ?

And what's that "int $1" stuff ??
petrusss

Re:Problem with unmasking irq's

Post by petrusss »

Hahah!
Of course... :]
When I press a key, I start getting alot of GPF's =|
I'll experiment a bit.
petrusss

Re:Problem with unmasking irq's

Post by petrusss »

OK, I can't make it not crash. :|
I get some GPF's (~100), and then it crashes.
This is what I get from bochs:

00083325742i[CPU ] read_virtual_checks(): write beyond limit
00083325790p[CPU ] >>PANIC<< fetch_raw_descriptor: LDTR.valid=0

A keypress starts that GPF loop =|
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Problem with unmasking irq's

Post by Pype.Clicker »

it is likely that you have something wrong in your ISR stub, which makes a bad segment selector being popped, which triggers a GPF, etc.
Post Reply