Keyboard interrupt

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.
ich_will

Keyboard interrupt

Post 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"
      :
      :
   );
}
ich_will

Re:Keyboard interrupt

Post by ich_will »

HELLO???? ??? HELP

Do I have to call another function before enabler interrupts??
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:Keyboard interrupt

Post 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 ? ...
ich_will

Re:Keyboard interrupt

Post 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??
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Keyboard interrupt

Post 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?
Every good solution is obvious once you've found it.
srg

Re:Keyboard interrupt

Post 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
ich_will

Re:Keyboard interrupt

Post 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();
}
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Keyboard interrupt

Post by Solar »

Just mask it out...?
Every good solution is obvious once you've found it.
ich_will

Re:Keyboard interrupt

Post by ich_will »

OK, like this:

current_mask = 0xffff; //disables all interrupts

outportb(PICMI, current_mask & 0xFF);
outportb(PICSI, (current_mask >> 8) & 0xFF);
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Keyboard interrupt

Post 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?
ich_will

Re:Keyboard interrupt

Post 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.
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:Keyboard interrupt

Post 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 ...
ich_will

Re:Keyboard interrupt

Post 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)
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Keyboard interrupt

Post 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.
ich_will

Re:Keyboard interrupt

Post 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?
Post Reply