参考:http://www.computer-engineering.org/index.html
读取键盘输入:
具体实现$JOS_DIR/kern/console.c
#define NO 0
#define SHIFT (1<<0)
#define CTL (1<<1)
#define ALT (1<<2)
#define CAPSLOCK (1<<3)
#define NUMLOCK (1<<4)
#define SCROLLLOCK (1<<5)
#define E0ESC (1<<6)
static uint8_t shiftcode[256] =
{
[0x1D] CTL,
[0x2A] SHIFT,
[0x36] SHIFT,
[0x38] ALT,
[0x9D] CTL,
[0xB8] ALT
};
这个数组定义表示的是shiftcode[0x1D]的值是CTL。
读取键盘输入:
kbRead:
WaitLoop: in al, 64h ; Read Status byte
and al, 10b ; Test IBF flag (Status<1>)
jz WaitLoop ; Wait for IBF = 1
in al, 60h ; Read input buffer
输出到键盘:
kbWrite:
WaitLoop: in al, 64h ; Read Status byte
and al, 01b ; Test OBF flag (Status<0>)
jnz WaitLoop ; Wait for OBF = 0
out 60h, cl ; Write data to output buffer
输出到键盘是初始化键盘和更改键盘的属性,这里在OS中没有用到。
键盘的和主机之间的通信使用的编码称为Scan Code Set,分为:
- Scan Code Set 1 - Original XT scan code set; supported by some modern keyboards
- Scan Code Set 2 - Default scan code set for all modern keyboards
- Scan Code Set 3 - Optional PS/2 scan code set--rarely used
具体实现$JOS_DIR/kern/console.c
#define NO 0
#define SHIFT (1<<0)
#define CTL (1<<1)
#define ALT (1<<2)
#define CAPSLOCK (1<<3)
#define NUMLOCK (1<<4)
#define SCROLLLOCK (1<<5)
#define E0ESC (1<<6)
static uint8_t shiftcode[256] =
{
[0x1D] CTL,
[0x2A] SHIFT,
[0x36] SHIFT,
[0x38] ALT,
[0x9D] CTL,
[0xB8] ALT
};
这个数组定义表示的是shiftcode[0x1D]的值是CTL。