Linux中断机制,linux中断


PC/AT 微机级联式8259控制系统

The 8259 was introduced as part of Intel's MCS 85 family in 1976. The 8259A was included in the original PC introduced in 1981 and maintained by the PC/XT when introduced in 1983. A second 8259A was added with the introduction of the PC/AT. The 8259 has coexisted with the Intel APIC Architecture since its introduction in Symmetric Multi-Processor PCs. Modern PCs have begun to phase out the 8259A in favor of the Intel APIC Architecture. However, while not anymore a separate chip, the 8259A interface is still provided by the Southbridge chipset on modern x86 motherboards.

The main signal pins on an 8259 are as follows: eight interrupt input request lines named IRQ0 through IRQ7, an interrupt request output line named INTR, interrupt acknowledgment line named INTA, D0 through D7 for communicating the interrupt level or vector offset. Other connections include CAS0 through CAS2 for cascading between 8259s.

Up to eight slave 8259s may be cascaded to a master 8259 to provide up to 64 IRQs. 8259s are cascaded by connecting the INT line of one slave 8259 to the IRQ line of one master 8259.

There are three registers, an Interrupt Mask Register (IMR), an Interrupt Request Register (IRR), and an In-Service Register (ISR). The IRR maintains a mask of the current interrupts that are pending acknowledgement, the ISR maintains a mask of the interrupts that are pending an EOI, and the IMR maintains a mask of interrupts that should not be sent an acknowledgement.

End Of Interrupt (EOI) operations support specific EOI, non-specific EOI, and auto-EOI. A specific EOI specifies the IRQ level it is acknowledging in the ISR. A non-specific EOI resets the IRQ level in the ISR. Auto-EOI resets the IRQ level in the ISR immediately after the interrupt is acknowledged.

Edge and level interrupt trigger modes are supported by the 8259A. Fixed priority and rotating priority modes are supported.

The 8259 may be configured to work with an 8080/8085 or an 8086/8088. On the 8086/8088, the interrupt controller will provide an interrupt number on the data bus when an interrupt occurs. The interrupt cycle of the 8080/8085 will issue three bytes on the data bus (corresponding to a CALL instruction in the 8080/8085 instruction set).

The 8259A provides additional functionality compared to the 8259 (in particular buffered mode and level-triggered mode) and is upward compatible with it.

来自 <http://en.wikipedia.org/wiki/Intel_8259>

clip_image001

中断信号通常分为两类: 硬件中断和软件中断, int 0x0 ~ int 0x1F 属于软件中断(异常)[故障 + 陷阱], 在Linux 中, 将0x20 ~ 0x2F 对应于8259A中断控制芯片发出的硬件请求信号 IRQ 0x0 ~ IRQ 0xF, 并把程序发出的系统调用中断设置为 int 0x80

clip_image002

clip_image003

在Linux中, 内核首先使用一个哑中断向量(中断描述符)对中断描述符表所有的256个描述符进行了默认设置, 这个哑中断向量指向一个默认的"无中断" 处理过程.

clip_image004

硬件异常(int 0x0 ~ int 0x01f)处理在文件 traps.c

系统调用中断int 0x80 则在 sched.c 中进行了初始化.


linux下的中断机制

提高计算机的运行效率,准确的说是CPU的效率。举个例子,比如程序要进行格式化磁盘,那么这个操作要十分钟,那么如果没有中断机制,那么CPU要一直在那里等待操作的完成,之后再执行后面的任务。在等的时候任何请求的不响应。如果有中断,那么就可以让磁盘先去格式化,CPU就执行其他任务,当格式化完成时,以中断的方式打断CPU,通知CPU格式化操作完成。

 

linux驱动自动检测中断号有什作用???

我以arm为例子,硬件发中断信号之后,arm cpu会跳到0x18地址执行irq中断,这个是硬件机制。是硬性规定。

我们在要在0x18处放一个跳转代码,跳转到这段跳转代码后我们通过软件进行一些处理之后会跳转到asm_do_irq中执行irq_desc->irq_handler,在这个handler里面会我们执行一个irq_desc->action->handler,这个hander就是在写驱动的时候通过request_irq把驱动的中断处理程序挂在irq_desc结构的irqaction list中的。

这个是linux的中断机制。非一两句能说清楚。
 

相关内容