RSS
热门关键字:  linux  安装  服务  系统  网络
当前位置 :| 主页>文档库>

Linux源代码阅读笔记--硬件中断

来源: 作者: 时间:2007-04-12 点击:

Linux硬件中断

Linux 中断和其他操作系统的中断处理一样,要求有硬件和软件的支持。Linux的好处就是可以看到核心处理中断的一举一动,以下对linux的中断机制做详细的分析。

首先对linux中能处理的中断分类:

1.物理硬件设备产生的中断,这些设备与主板上的i8259A中断控制器相连,具体的连接可以找本《计算机组成原理》看看。linux中可以处理的有16个中断号,但这并不意味linux只能处理16个外设中断请求,实际上许多外设是可以共享中断号,这个要求操作系统的软件支持,在后面可以看到linux是如果处理。

2.异常,异常是无法预测的意外。如被0除、缺页:

set_trap_gate(0,&divide_error);
  set_trap_gate(1,&debug);
  set_intr_gate(2,&nmi);
  set_system_gate(3,&int3); /* int3-5 can be called from all */
  set_system_gate(4,&overflow);
  set_system_gate(5,&bounds);
  set_trap_gate(6,&invalid_op);
  set_trap_gate(7,&device_not_available);
  set_trap_gate(8,&double_fault);
  set_trap_gate(9,&coprocessor_segment_overrun);
  set_trap_gate(10,&invalid_TSS);
  set_trap_gate(11,&segment_not_present);
  set_trap_gate(12,&stack_segment);
  set_trap_gate(13,&general_protection);
  set_trap_gate(14,&page_fault);
  set_trap_gate(15,&spurious_interrupt_bug);
  set_trap_gate(16,&coprocessor_error);
  set_trap_gate(17,&alignment_check);
  set_trap_gate(18,&machine_check);
  set_trap_gate(19,&simd_coprocessor_error);
   
  set_system_gate(SYSCALL_VECTOR,&system_call);
   
  /*
   * default LDT is a single-entry callgate to lcall7 for iBCS
   * and a callgate to lcall27 for Solaris/x86 binaries
   */
  set_call_gate(&default_ldt[0],lcall7);
  set_call_gate(&default_ldt[4],lcall27);
  

以上摘自i386\kernel\Traps.c-> trap_init()函数片断,trap_init()函数又被操作系统的初始化工作start_kernel()函数调用,从列表中可以看出linux所处理的异常。从上面的注释中可以看到异常3-5,就是中断指令int3,int4,int5可以被所有的进程调用,这三个实际上是调试程序所用到的,所以当然能被你的程序调用。而其他的异常只能被处于特权级0的进程调用,也就是说这些异常只能被内核所处理,道理非常明显,但是实现起来就不是那么直接了。

最新评论共有 1 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
栏目列表