1.1 数据结构与函数

2009-05-13 08:07:38来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折


中断向量表有多个vector,0-31为CPU用,32~32+15对应IRQ0~IRQ15一个vector对应一个source,数据类型是struct intsrc
代码:

/*
* An interrupt source. The upper-layer code uses the PIC methods to
* control a given source. The lower-layer PIC drivers can store additional
* private data in a given interrupt source such as an interrupt pin number
* or an I/O APIC pointer.
*/
struct intsrc {
  struct pic *is_pic;
  struct ithd *is_ithread;
  u_long *is_count;
  u_long *is_straycount;
  u_int is_index;
};
其实在vector后面的是中断控制器,如8259A,I/O APIC等,事实上,对中断源的控制实际上就是对中断控制器的操作,因此,在struct intsrc中有成员struct pic *is_pic,
即中断控制器的操作函数表,通过这个表,可以为不同的中断控制器定义不同的操作,达到demultiplex的作用。这里pic是programmable interrupt controller的意思。
代码:
/*
* Methods that a PIC provides to mask/unmask a given interrupt source,
* "turn on" the interrupt on the CPU side by setting up an IDT entry, and
* return the vector associated with this source.
*/
struct pic {
  void (*pic_enable_source)(struct intsrc *);
  void (*pic_disable_source)(struct intsrc *);
  void (*pic_eoi_source)(struct intsrc *);
  void (*pic_enable_intr)(struct intsrc *);
  int (*pic_vector)(struct intsrc *);
  int (*pic_source_pending)(struct intsrc *);
  void (*pic_suspend)(struct intsrc *);
  void (*pic_resume)(struct intsrc *);
};
系统中所有的中断源组成一个数组,由于当采用I/O APIC作为中断控制器时,可以有191个中断号(IRQ),因此该数组大小定义为191。
代码:
static struct intsrc *interrupt_sources[NUM_IO_INTS];
/* With I/O APIC's we can have up to 191 interrupts. */
#define NUM_IO_INTS 191
所谓登记中断源,就是将实际的中断控制器的对应struct intsrc数据结构添加到该数组中去。同时,系统为每个登记的中断源创建一个中断线程,中断处理程序就在该线程的上下文中运行,该线程的入口函数为ithread_loop(),struct intsrc结构成员is_ithread指向描述中断线程的数据结构struct ithd,而struct ithd结构成员it_td指向真正的线程结构struct thread,从而将中断与系统的调度单元线程联系起来。
代码:
/*
* Describe an interrupt thread. There is one of these per interrupt vector.
* Note that this actually describes an interrupt source. There may or may
* not be an actual kernel thread attached to a given source.
*/
struct ithd {
  struct mtx it_lock;
  struct thread *it_td; /* Interrupt process. */
  LIST_ENTRY(ithd) it_list; /* All interrupt threads. */
  TAILQ_HEAD(, intrhand) it_handlers; /* Interrupt handlers. */
  struct ithd *it_interrupted; /* Who we interrupted. */
  void (*it_disable)(uintptr_t); /* Enable interrupt source. */

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:新fvwm配置文件

下一篇:1.2 8259A的登记过程