Xv6 with picoc & Linkage editor  v1.0
The project delineate mutual cohesion between c library, linkage editor ( linker), interpreter and operating system by porting the same on xv6 kernel
kbd.c
00001 #include "types.h"
00002 #include "x86.h"
00003 #include "defs.h"
00004 #include "kbd.h"
00005 
00006 int
00007 kbdgetc(void)
00008 {
00009   static uint shift;
00010   static uchar *charcode[4] = {
00011     normalmap, shiftmap, ctlmap, ctlmap
00012   };
00013   uint st, data, c;
00014 
00015   st = inb(KBSTATP);
00016   if((st & KBS_DIB) == 0)
00017     return -1;
00018   data = inb(KBDATAP);
00019 
00020   if(data == 0xE0){
00021     shift |= E0ESC;
00022     return 0;
00023   } else if(data & 0x80){
00024     // Key released
00025     data = (shift & E0ESC ? data : data & 0x7F);
00026     shift &= ~(shiftcode[data] | E0ESC);
00027     return 0;
00028   } else if(shift & E0ESC){
00029     // Last character was an E0 escape; or with 0x80
00030     data |= 0x80;
00031     shift &= ~E0ESC;
00032   }
00033 
00034   shift |= shiftcode[data];
00035   shift ^= togglecode[data];
00036   c = charcode[shift & (CTL | SHIFT)][data];
00037   if(shift & CAPSLOCK){
00038     if('a' <= c && c <= 'z')
00039       c += 'A' - 'a';
00040     else if('A' <= c && c <= 'Z')
00041       c += 'a' - 'A';
00042   }
00043   return c;
00044 }
00045 
00046 void
00047 kbdintr(void)
00048 {
00049   consoleintr(kbdgetc);
00050 }
 All Data Structures