OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 5:58 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Something wrong with KEYBOARD driver
PostPosted: Wed Apr 16, 2008 2:05 am 
Offline
Member
Member
User avatar

Joined: Fri Dec 07, 2007 9:57 am
Posts: 34
I have written a keyboard driver file, keyboard.c, that just do nothing but display the general_protection interrupt information.
i want it to handle a keybaord interrupt but it only handled the general_protection interrupt which is not my except. Now i have no ideal how to fix it well, and i really need your help. Thanks.

there is the code i wrote:

Scancode set 2 is what i wanna take.
I set the idt of IRQ1 in the file trap.c set_trap_gate(0x21,keyboard_interrupt)
And i do enable the IRQ1 in the function con_write(). outb_p(inb_p(0x21)&0xfd, 0x21);
And i do set the interrupt bit in main function init.c sti();


Code:
#include <keyboard.h>
#include <asm/io.h>


static unsigned char scancode;
static unsigned char brkflag;
static unsigned char mode;
static unsigned char e0;
static unsigned char key;
static unsigned char leds;


unsigned char key_map[] = {
/*0   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f*/
  0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 9 ,'`',/*00-0F*/
  0x0,0x0,0x0,0x0,0x0,'q','1',0x0,0x0,0x0,'z','s','a','w','2',0x0,/*10-1F*/
  0x0,'c','x','d','e','4','3',0x0,0x0,32, 'v','f','t','r','5',0x0,/*20-2F*/
  0x0,'n','b','k','g','y','6',0x0,0x0,0x0,'m','j','u','7','8',0x0,/*30-3F*/
  0x0,',','k','i','o','0','9',0x0,0x0,'.','/','l',';','p','-',0x0,/*40-4F*/
  0x0,0x0,'\'',0x0,'[','=',0x0,0x0,0x0,0x0,13,']',0x0,'\\',0x0,0x0,/*50-5F*/
  0x0,0x0,0x0,0x0,0x0,0x0, 8 ,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,/*60-6F*/
  '0','.','2','5','6','8',0x0,0x0,0x0,'+','3','1','*','9',0x0,0x0,/*70-7F*/
  0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};/*80-8F*/

unsigned char shift_map[] = {
/*0   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f*/
  0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 9 ,'~',/*00-0F*/
  0x0,0x0,0x0,0x0,0x0,'Q','!',0x0,0x0,0x0,'Z','S','A','W','@',0x0,/*10-1F*/
  0x0,'C','X','D','E','$','#',0x0,0x0,32, 'V','F','T','R','%',0x0,/*20-2F*/
  0x0,'N','B','K','G','Y','^',0x0,0x0,0x0,'M','J','U','&','*',0x0,/*30-3F*/
  0x0,'<','K','I','O',')','(',0x0,0x0,'>','?','L',':','p','_',0x0,/*40-4F*/
  0x0,0x0,'\"',0x0,'{','+',0x0,0x0,0x0,0x0,13,'}',0x0,'|',0x0,0x0,/*50-5F*/
  0x0,0x0,0x0,0x0,0x0,0x0, 8 ,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,/*60-6F*/
  0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,/*70-7F*/
  0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};/*80-8F*/

unsigned char alt_map[] = {
/*0   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f*/
  0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 9 ,'`',/*00-0F*/
  0x0,0x0,0x0,0x0,0x0,'q','1',0x0,0x0,0x0,'z','s','a','w','2',0x0,/*10-1F*/
  0x0,'c','x','d','e','4','3',0x0,0x0,32, 'v','f','t','r','5',0x0,/*20-2F*/
  0x0,'n','b','k','g','y','6',0x0,0x0,0x0,'m','j','u','7','8',0x0,/*30-3F*/
  0x0,',','k','i','o','0','9',0x0,0x0,'.','/','l',';','p','-',0x0,/*40-4F*/
  0x0,0x0,'\'',0x0,'[','=',0x0,0x0,0x0,0x0,13,']',0x0,'\\',0x0,0x0,/*50-5F*/
  0x0,0x0,0x0,0x0,0x0,0x0, 8 ,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,/*60-6F*/
  '0','.','2','5','6','8',0x0,0x0,0x0,'+','3','1','*','9',0x0,0x0,/*70-7F*/
  0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};/*80-8F*/



static void kb_wait(void);

static void non(void)
{
  /* just doing nothing */
}

static void fun(void)
{
  /* Not implement */
}

static void prt(void)
{
  unsigned char *map;
 
  if (mode & (RALT | LALT))
    map = alt_map;
  else if (mode & (RSHIFT | LSHIFT))
    map = shift_map;
  else
    map = key_map;
 
  key = *(map + scancode);
 
  if (mode & (LCTRL | RCTRL | CAPS_STATE))
    if (key >= 'a' && key <= '}')
      key -= 32;
  if (mode & (LCTRL | RCTRL))
      if (key >= 64 && key <= 64 + 32)
   key -= 64;
   
  printk("%c",key);
}

static void ctl(void)
{
  unsigned char temp;
  temp = LCTRL;

  if (e0 & E0)
    temp <<= 1;

  mode |= temp;
}

static void alt(void)
{
  unsigned char temp;

  if (e0 & E0)
    temp <<= 1;
 
  mode |= temp;
}

static void sft(void)
{
  if (scancode == 0x12)
    mode |= LSHIFT;
  else if (scancode == 0x59)
    mode |= RSHIFT;
}

static void cur(void)
{
  /*Not implement*/
}

static void set_leds(void)
{
  kb_wait();
  outb(0xed, 0x60);   /* set leds command */
  kb_wait();
  outb(leds, 0x60);   /* send param */
}

static void sroll(void)
{
  leds ^= SCROLL_LOCK;
  set_leds();
}

static void num_lock(void)
{
  leds ^= NUM_LOCK;
  set_leds();
}

static void cap(void)
{
  leds ^= CAPS_LOCK;
     set_leds();
}

static void kb_wait(void)
{
  while (inb(0x64) & 0x02)
    ;
}



void keyboard_interrupt(void)
{
  unsigned char a;

  void (*kfun_table[])(void) = {
    /*0   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f*/
    non,fun,non,fun,fun,fun,fun,fun,non,fun,fun,fun,fun,prt,prt,non,/*00-0F*/
    non,alt,alt,non,ctl,prt,prt,non,non,non,prt,prt,prt,prt,prt,non,/*10-1F*/
    non,prt,prt,prt,prt,prt,prt,non,non,prt,prt,prt,prt,prt,prt,prt,/*20-2F*/
    non,prt,prt,prt,prt,prt,prt,non,non,non,prt,prt,prt,prt,prt,prt,/*30-3F*/
    non,prt,prt,prt,prt,prt,prt,non,non,prt,prt,prt,prt,prt,prt,prt,/*40-4F*/
    non,non,prt,non,prt,prt,non,non,cap,sft,prt,prt,non,prt,non,non,/*50-5F*/
    non,non,non,non,non,non,prt,non,non,cur,non,cur,cur,non,non,non,/*60-6F*/
    cur,cur,cur,cur,cur,cur,cur,cur,cur,cur,cur,cur,cur,cur,cur,cur,/*70-7F*/
    non,non,non,fun,non,non,non,non,non,non,non,non,non,non,non,non /*80-8F*/
  };

  scancode = inb(0x60);

  if (brkflag && scancode == 0x11) {
    if (e0 & E0) {
      mode &= ~RALT;
      e0   &= ~E0;
    }else
      mode &= ~LALT;
    brkflag = 0;
  }else if (brkflag && scancode == 0x14) {
    if (e0 & E0) {
      mode &= ~RCTRL;
      e0   &= ~E0;
    }else
      mode &= ~LCTRL;
    brkflag = 0;
  }else if (brkflag) {
    e0 = 0;
    brkflag = 0;
  }else if (scancode == 0xe0)
    e0 |= E0;
  else if (scancode == 0xe1)
    e0 |= E1;
  else if (scancode == 0xF0)       /* set brkflag  */
    brkflag = 1;
  else
    (*kfun_table[scancode])();

  a = inb(0x61);      /* disable KB   *
  outb(a|0x80, 0x61);      /* enable  KB   */
  outb(a&0x7f, 0x61);      /* E O I        */
       
   
               
     
 
printk("%c",key);
 

}




and the macro values of mode, leds, e0 are defined at keyboard.h

Code:
#ifndef KEYBOARD_H
#define KEYBOADR_H

/* macro of mode */
#define LSHIFT      0x01
#define RSHIFT      0x02
#define LCTRL       0x04
#define RCTRL       0x08
#define LALT        0x10
#define RALT        0x20
#define CAPS_STATE  0x40
#define CAPS        0x80

/* macro of leds */
#define SCROLL_LOCK 0x01
#define NUM_LOCK    0x02
#define CAPS_LOCK   0x04


/* macro of eo */
#define E0          0x01
#define E1          0x02



void keyboard_interrupt(void);         
           


#endif  /*keyboard.h*/




Thanks a lot for you reading here.


Last edited by negcit.K on Thu Apr 17, 2008 2:56 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 6:36 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
[wiki]Category:FAQ[/wiki] - I suggest you try that first.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 7:10 am 
Offline
Member
Member
User avatar

Joined: Wed Apr 09, 2008 5:44 pm
Posts: 42
Location: Mars
before to be able to manage a keyboard from PM, you sould reprogramm the PIC to point to the vector you want for keybord.

in PM, the 16 first interrupts are for internal errors managment.

i'm pretty sure that each time you hit a key, it generate the error n°9 coprossessor segment overun (IRQ 9).

Code:
if you want to know more about it, please seek documentations and yeahhh!
remapirq:
        mov     al,11h
        out     20h,al
        out     0a0h,al
        mov     al,32       
        out     21h,al
        mov     al,40
        out     0a1h,al
        mov     al,4
        out     21h,al
        mov     al,2
        out     0a1h,al
        mov     al,1
        out     21h,al
        out     0a1h,al
        mov     al,0fbh
        out     21h,al
        mov     al,0ffh
        out     0a1h,al
        ret

_________________
welcome in my dream.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 17, 2008 2:08 am 
Offline
Member
Member
User avatar

Joined: Fri Dec 07, 2007 9:57 am
Posts: 34
Combuster wrote:
...

Which part do you want me to search?


Quote:
before to be able to manage a keyboard from PM, you sould reprogramm the PIC to point to the vector you want for keybord.

I dit it


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], Google [Bot], SemrushBot [Bot] and 73 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