5.1:外设-字符设备键盘

1:键盘中断

当按下键盘时会产生键盘中断,进入keyboard_interrupt:处理函数中

keyboard_interrupt:

        call key_table(,%eax,4)

在key_table里会找每个案件对应的处理函数,大部分都是do_self

key_table:
        .long none,do_self,do_self,do_self      /* 00-03 s0 esc 1 2 */
        .long do_self,do_self,do_self,do_self   /* 04-07 3 4 5 6 */

do_self里会通过key_map得到相应的ASCII码,然后放入读队列中

do_self:
        lea alt_map,%ebx
        lea key_map,%ebx
		call put_queue

最后调用tty的中断

call do_tty_interrupt

2:屏幕输出

唤醒等待队列

void do_tty_interrupt(int tty) 
      copy_to_cooked(tty_table+tty);
        	wake_up(&tty->secondary.proc_list);

唤醒tty读函数

int tty_read(unsigned channel, char * buf, int nr)
	sleep_if_empty(struct tty_queue * queue)
        while (!current->signal && EMPTY(*queue))
                interruptible_sleep_on(&queue->proc_list);

最后将队列中的数据放到用户空间就可以打印输出了

do {
        GETCH(tty->secondary,c);
        if (c==EOF_CHAR(tty) || c==10)
                tty->secondary.data--;
        if (c==EOF_CHAR(tty) && L_CANON(tty))
                return (b-buf);
        else {
                put_fs_byte(c,b++);
                if (!--nr)
                        break;
        }
} while (nr>0 && !EMPTY(tty->secondary));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值