what happens internally

anchitjindal07's Avatar, Join Date: Jul 2009
Go4Expert Member
Friends please tell me what happens internally when we press any key on keyboard
i know that it saves the value of certai registers and taKES ON INTERRUPT handler. upto this point its ok. what happen after that???????
What is interrupt handler instructed to do???????????

Thanks
0
Seema786's Avatar
Banned
anyone know what he/she is telling ?
0
anchitjindal07's Avatar, Join Date: Jul 2009
Go4Expert Member
yaar i am asking u how the operatring system knows which key has been pressed and what to do when a particular key is pressed
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Which OS?
0
anchitjindal07's Avatar, Join Date: Jul 2009
Go4Expert Member
Any oerating system. Ok take your own example (of OS) and please explain
0
indiansword's Avatar, Join Date: Oct 2008
Security Expert
Input > Process > Output. THere is a RUBBER NOTCH beneath ur keyboard key. When u push the key the NOTCH is pushed and the circuit on the keyboard is completed, which send a msg to CPU [PROCESSOR] and the key is recorded, and output on application along with monitor .
0
anchitjindal07's Avatar, Join Date: Jul 2009
Go4Expert Member
Thankyou friend for ur reply but I am asking in terms of interrupt. Would you please explain
0
_eb75_'s Avatar, Join Date: Jun 2012
Go4Expert Member
Quote:
Originally Posted by anchitjindal07 View Post
Friends please tell me what happens internally when we press any key on keyboard
i know that it saves the value of certai registers and taKES ON INTERRUPT handler. upto this point its ok. what happen after that???????
What is interrupt handler instructed to do???????????

Thanks
I like questions with the word internally.
To my mind it would be good to give an answer with a full exact code, to be at a concrete level. Unfortunately this is impossible, because we have too much code. Is it really? This question is easy because it don't specify any kernel by name. So, I can use my own! I did write it 1994 when Intel 386, protected mode, was new. It is small and simple enough (some 1000-1500 c-code whole thing). I tested it also taking a connection to a server by the serial line modem (telnet port at server).

Code:
char  KBDSub() 
{ static short code;
  static short xl, xh;
  static char scan[]={  /* Scan code conversion table for most usual codes */
  0,033,'1','2','3','4','5','6','7','8','9','0','+','x','\b','\t',
  'q','w','e','r','t','y','u','i','o','p','?',012,015,015,
  'a','s','d','f','g','h','j','k','l','&','?',0,
  '\\',',','z','x','c','v','b','n','m',',','.','-','/',0,' ',' ',' ',' '};

   code = inportb(0x060)   ;
   xh = xl = inportb(0x061);    /* Read scan code*/
   xl = xl | 0x080         ;
    outportb( 0x61 , xl)    ;
   outportb( 0x061, xh)    ;
   if(code >=0 && code <=0x040 ) return(scan[ code]);
   else return( 0);
}

void  KBDIntHandler() 
{       outportb(PIC1_CMND,PIC_EOI);
              Send(0,KBD_BOX,KBDSub()); // send message to mailbox- hopefully keyboard task is waiting!
}
************************************************** ********

Outside the question presented:

Yes, saving on entry must be done:

Code:
#define Save()      asm volatile ("pusha"); 
#define Restore() asm ("popa;leave;iret;");
Where this saving/restoring is?

Interrupt call gate.

Code:
void InterruptHandler() 
{
  short store;
 Save();
 enter_int_gate(store);
      KBDIntHandler();
 leave_int_gate(store);
 Restore();
}
Code:
(#define  leave_int_gate(STORE)  asm("movw %0,%%bx;movw %%bx,%%ds;"\
                                     :\
                    :"m"(STORE));)

A KBD task:


Code:
void main(void) {
 while(TRUE) {
................
  kbd_char = receive(KBD_BOX,TIMEOUT);
 ................
 }
}

and so on................................I used mainly c and some inline assembly, only floppy disk (see history of computers) boot sector was written using assembly...........