Page 1 of 3

Keyboard interrupt

Posted: Sat Feb 21, 2004 9:40 am
by ich_will
Hi @all.

What have I to do, to enable the keyboard interrupt in pmode.
Currently I do this:

1. create and load an IDT Table
2. register my keyboard-handler-function and enable the irq
3. wait for the keyboard to accept commands
4. restart the controller, and enable it
5. set the scanning rate
6. enable interrupts

at point 6 is the problem, with bochs this works fine, with my AMD 5x86 (133Mhz) too but with my AMD Duron(1,00GHz) the interrupt handler for Triple Faults is called (prints out a message).

the code for the steps (2) 3 - 5:

Code: Select all

void init_keyboard()
{
   putstr("Initialize the Keyboard..................");

   enable_irq(1, keyboardInt, INT_GATE|BITS_32|PRESENT|RING_2);

   SendData(0xFF);      //Restart keyboard
   SendData(0xF4);      //Enables keyboard and Scanning
   SetRate(KDefault);   //Sets default scanning rate

   enable(); // if i don't call this function, i don't get the message

   putstr(".DONE\n");

   for(;;);    // this is to be sure nothing else create the triple fault
}

void SendData(unsigned char data) //Sends a command or data to keyboard
{
   WaitForReady();      //MicroDelay((unsigned long) 10);
   outportb(0x60, data);
}

void WaitForReady(void)   //determines if the keyboard is ready to accept a command
{
    volatile long i = MAX_TRYES_FOR_READY;
    while(i-- && (inportb(0x64) & 0x02));
}

inline static unsigned char inportb(int port)
{
   register unsigned char r;
   
      asm volatile
   ( 
      "inb %%dx, %%al\n\t" 
      : "=a" (r) 
      : "d" (port)
   );

      return (r);
}

inline static void outportb(int port, unsigned char data)
{
   asm volatile
   (
      "outb %%al, %%dx\n\t" 
      :
      : "a" (data), "d" (port)
   );
}

inline static void enable()
{
   asm volatile 
   (
      "sti"
      :
      :
   );
}

Re:Keyboard interrupt

Posted: Sun Feb 22, 2004 6:03 am
by ich_will
HELLO???? ??? HELP

Do I have to call another function before enabler interrupts??

Re:Keyboard interrupt

Posted: Mon Feb 23, 2004 4:38 am
by Pype.Clicker
ich_will wrote: HELLO???? ??? HELP

Do I have to call another function before enabler interrupts??
hey! give us the time ... it's the week-end for everyone ;)

i'm unsure about it, but it sounds like there's something different on your AMD duron that cause you troubles. It could be the fact that its BIOS does not enable A20, or that it has a more strrict emulation of the 8042 chip ... whatever ...

btw, i don't see your handler here ...

Does the "done" text appear before you get a tripple fault ? does it wait until you press a key to crash or does it just crash as soon as you reenable interrupts ?

What about clock interrupt ? did you mask it, do you have a valid handler for it ? ...

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 8:23 am
by ich_will
It could be the fact that its BIOS does not enable A20
I enable A 20 in my Bootloader.
Does the "done" text appear before you get a tripple fault ?
No.
does it wait until you press a key to crash or does it just crash as soon as you reenable interrupts ?
It crashes just when I reenable interrupts.
What about clock interrupt ? did you mask it, do you have a valid handler for it ? ...
No, but what has the clock interrupt to do with this??

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 8:39 am
by Solar
Simple. Clock interrupt predates keyboard interrupt. You enable interrupts, the next clock interrupt occurs, the CPU tries to get the applicable but non-existing interrupt handler from the IDT... tripple fault.

Or am I mistaken, Pype?

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 9:07 am
by srg
Solar wrote: Simple. Clock interrupt predates keyboard interrupt. You enable interrupts, the next clock interrupt occurs, the CPU tries to get the applicable but non-existing interrupt handler from the IDT... tripple fault.

Or am I mistaken, Pype?
Also, as the 1GHz Duron is vastly faster than BOCHS or a 5x86 133, then things will happen in a different order (I mean compaired to when the clock interrupt strikes).

If you don't want to make a handler for the clock interrupt, then I'd suggest you make sure it's masked in the PIC, or just make a dummy stub handler for that interrupt.

srg

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 9:28 am
by ich_will
So I have to do something like this: ???

Code: Select all

void clock_handler()
{
  int value;

  outportb(0x70,0x0E);   // Tell the chip what to read

  value = inportb(0x71); // read it
  
  putint(value);
}

void init_clock()
{
  disable();
  putstr("Initialize the Clock.....................");
  
  enable_irq(8, clock_handler, INT_GATE|BITS_32|PRESENT|RING_2);

  outportb(0x70,0x0B); // Tell the chip what to write
  outportb(0x71,0x53); // 01010011
   
   putstr("...DONE\n");
   
   enable();
}

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 9:31 am
by Solar
Just mask it out...?

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 9:36 am
by ich_will
OK, like this:

current_mask = 0xffff; //disables all interrupts

outportb(PICMI, current_mask & 0xFF);
outportb(PICSI, (current_mask >> 8) & 0xFF);

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 9:37 am
by Candy
ich_will wrote: current_mask = 0xffff; //disables all interrupts
How is masking all interrupts going to help you get the keyboard interrupt working?

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 9:44 am
by ich_will
this is stands in my init_pic funtion, the mask is for the function enable_irq. If I disable all interrupts first the clock interrupt is masked out, or.

P.S: the smile in the code above is "8 )" not a smily.

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 10:51 am
by Pype.Clicker
starting with the keyboard interrupt alone make things easier to debug as *you* can decide when the interrupt arise (which is not the case with the Clock). So trying to unmask *only* the keyboard and see what happens may be a more accurate test ...

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 11:45 am
by ich_will
Whats the problem with disabling all interrupts???

Code: Select all

current_mask = 0xffff; //disables all interrupts

outportb(PICMI, current_mask & 0xFF);
outportb(PICSI, (current_mask >> 8 ) & 0xFF);
UNMASK all interrupts or does solar mean something else with:
Just mask it out...?

Do you mean I should enable interrupts without try to set up the keyboard irq?? (That works)

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 12:11 pm
by Candy
ich_will wrote: Whats the problem with disabling all interrupts???
If you disable all interrupts you won't get the keyboard interrupts either, so your code won't do that. I had the impression you wanted your keyboard interrupt to work.
UNMASK all interrupts or does solar mean something else with:
Just mask it out...?
Just mask it out means mask out the interrupts you don't want. Not the ones you do want.

Re:Keyboard interrupt

Posted: Wed Feb 25, 2004 12:32 pm
by ich_will
OK, the enable_irq function mask the given irq.

enable_irq(unsigned short x, void (*handler)(), unsigned char flags)

I think the problem has nothing to do with the mask. The clock interrupt is unmask with this:

current_mask = 0xffff; //disables all interrupts

outportb(PICMI, current_mask & 0xFF);
outportb(PICSI, (current_mask >> 8 ) & 0xFF);

or not?