/*
* linux/kernel/keyboard.S
*
* (C) 1991 Linus Torvalds
*/
/*
* Thanks to Alfred Leung for US keyboard patches
* Wolfgang Thiel for German keyboard patches
* Marc Corsini for the French keyboard
*/
#include <linux/config.h> // 内核配置头文件
.text
.globl _keyboard_interrupt
/*
* these are for the keyboard read functions
*/
/* 键盘缓冲区长度 */
size = 1024 /* must be a power of two ! And MUST be the same
as in tty_io.c !!!! */
/* 缓冲队列结构中的偏移量 */
head = 4 // 缓冲区头指针偏移量
tail = 8 // 缓冲区尾指针偏移量
proc_list = 12 // 等待该缓冲区进程偏移量
buf = 16 // 缓冲区偏移量
/*
* 定义变量mode,表示特殊键按下的状态
* cap,alt,ctrl,shift
*/
mode: .byte 0 /* caps, alt, ctrl and shift mode */
/*
* 数字锁定键,大小写转换键,滚动锁定键scroll-lock
* 定义变量leds
*/
leds: .byte 2 /* num-lock, caps, scroll-lock mode (nom-lock on) */
/*
* 0xe0或者是0xe1指示气候跟随的是一个或者是两个字符扫描码
*/
e0: .byte 0
/*
* con_int is the real interrupt routine that reads the
* keyboard scan-code and converts it into the appropriate
* ascii character(s).
*/
_keyboard_interrupt: // 键盘中断处理程序入口点
/* 保存寄存器 */
pushl %eax
pushl %ebx
pushl %ecx
pushl %edx
push %ds
push %es
//
// ds,es设置为内核数据段
movl $0x10,%eax
mov %ax,%ds
mov %ax,%es
//
xorl %al,%al /* %eax is scan code, al = 0 */
inb $0x60,%al // 现在al寄存器就是中断之后读取的键盘扫描码
/
cmpb $0xe0,%al // 如果扫描码是0xe0
je set_e0 // 跳转到set_e0
/
cmpb $0xe1,%al // 如果是0xe1
je set_e1
/
call key_table(,%eax,4) // 调用键处理程序key_table + %eax * 4
movb $0,e0 // 复位e0标志
// 下面的代码是使硬件复位处理。首先是禁止键盘的工作,然后开启
// 键盘工作
e0_e1: inb $0x61,%al
jmp 1f // 时间延迟
1: jmp 1f
1: orb $0x80,%al
jmp 1f
1: jmp 1f
1: outb %al,$0x61
jmp 1f
1: jmp 1f
1: andb $0x7F,%al
outb %al,$0x61
///
movb $0x20,%al // 发送中断结束信号
outb %al,$0x20
pushl $0 // 将控制台号tty = 0压入栈
call _do_tty_interrupt // 调用_do_tty_interrupt
addl $4,%esp // 丢弃入栈参数,并返回
///
// 恢复上下文
pop %es
pop %ds
popl %edx
popl %ecx
popl %ebx
popl %eax
///
iret // 中断返回
set_e0: movb $1,e0
jmp e0_e1
set_e1: movb $2,e0
jmp e0_e1
/*
* This routine fills the buffer with max 8 bytes, taken from
* %ebx:%eax. (%edx is high). The bytes are written in the
* order %al,%ah,%eal,%eah,%bl,%bh ... until %eax is zero.
*/
/* 下面的子程序将ebx:eax中最多8个