Keyboard

void con_init(void) // 键盘也是console的一部分 { set_trap_gate(0x21, &keyboard_interrupt); }
// kernel/chr_drv/keyboard.S .globl _keyboard_interrupt _keyboard_interrupt: inb $0x60,%al // 从端口0x60读扫描码 call key_table(,%eax,4) ... push $0 call _do_tty_interrupt key_table: .long none,do_self,do_self,do_self // 扫描码00-03 .long do_self, ...,func,scroll,cursor key_map: .byte 0,27 .ascii "1234567890-=" .byte 127,9 .ascii "qwertyuiop[]" .byte 13,0 .ascii "asdfghjkl;'" .byte '`,0 .ascii "\\zxcvbnm,./" .byte 0,'*,0,32 /* 36-39 */ .fill 16,1,0 .byte '-,0,0,0,'+ .byte 0,0,0,0,0,0,0 .byte '< .fill 10,1,0 do_self: lea alt_map,%ebx testb $0x20,mode // alt键是否同时按下 jne 1f lea shift_map,%ebx testb $0x03,mode jne 1f lea key_map,%ebx 1: movb (%ebx,%eax),%al // 扫描码索引,ascii码-> al orb %al,%al je none // 没有对应的ascii码 testb $0x4c,mode // 是否大写锁定 je 2f cmpb $'a,%al jb 2f cmpb $'},%al ja 2f subb $32,%al 2: testb $0x0c,mode // 处理其他模式 je 3f cmpb $64,%al jb 3f cmpb $64+32,%al jae 3f subb $64,%al 3: testb $0x10,mode je 4f orb $0x80,%al 4: andl $0xff,%eax xorl %ebx,%ebx call put_queue none: ret put_queue: pushl %ecx pushl %edx movl table_list,%edx # read-queue for console movl head(%edx),%ecx 1: movb %al,buf(%edx,%ecx)
回显:
void do_tty_interrupt(int tty) // 上面传入的是0 { copy_to_cooked(tty_table+tty); } void copy_to_cooked(struct tty_struct *tty) { GETCH(tty->read_q,c); if(L_ECHO(tty)) { // 回显 PUTCH(c,tty->write_q); tty->write(tty); } PUTCH(c,tty->secondary); ... wake_up(&tty->secondary.proc_list); }
 
notion image
notion image