36 8259A 控制编程

参考

https://blog.51cto.com/13475106/category6.html及狄泰软件相关课程

一般来说,X86系统中使用2个8259A级联作为中断代理
操作系统-中断代理-8295A
从上图可以得知,只有一个8259A(主)能连接到CPU,剩下的(从)只能级联,只能连接到主8259A的中断引脚上。

8259A的设置与控制

1.初始化命令字
2.用于确定是否需要级联,设置起始中断向量等
操作系统-中断代理-8295A
ICW1:初始化8259A连接方式和中断触发方式
操作系统-中断代理-8295A
ICW2:设置起始中断向量
操作系统-中断代理-8295A
ICW3:指定主从8259A的级联引脚
操作系统-中断代理-8295A
ICW4:初始化8259A数据连接方式和中断触发方式
操作系统-中断代理-8295A
简单代码演示

Init8259A:
    ; 初始化主片
    ; 1) 先写 ICW1
    mov al, 0x11;00010001二进制                ; IC4 = 1, ICW4-write required
    out MASTER_ICW1_PORT, al;对应0x20端口

    call delay

    ; 2) 接着写 ICW2
    mov al, 0x20;00100000低三位为0                  ; interrupt vector = 0x20
    out MASTER_ICW2_PORT, al

    call delay

    ; 3) 接着写 ICW3               
    mov al, 0x04;00000100                   ; ICW3[2] = 1, for slave connection
    out MASTER_ICW3_PORT, al

    call delay

    ; 4) 接着写 ICW4
    mov al, 0x01;00000001                   ; ICW4[0] = 1, for Intel Architecture
    out MASTER_ICW4_PORT, al

    call delay

    ; 初始化从片
    ; 1) 先写 ICW1
    mov al, 0x11;00010001                   ; IC4 = 1, ICW4-write required
    out SLAVE_ICW1_PORT, al

    call delay

    ; 2) 接着写 ICW2
    mov al, 0x28;相差8位主从0x20开始需要8位所以从机从0x28开始                    ; interrupt vector = 0x28
    out SLAVE_ICW2_PORT, al

    call delay

    ; 3) 接着写 ICW3               
    mov al, 0x02                    ; ICW3[1] = 1, connect to master IR2
    out SLAVE_ICW3_PORT, al

    call delay

    ; 4) 接着写 ICW4
    mov al, 0x01                    ; for Intel Architecture
    out SLAVE_ICW4_PORT, al     

    call delay

    ret

8259A的设置与控制

1.操作命令字
2.用于设置中断优先级方式,中断结束模式
操作系统-中断代理-8295A
OCW1:屏蔽连接在8259A上的中断源
OCW1命令字最终写入IMR寄存器-IMR寄存器为初级中断屏蔽寄存器,如果标志寄存器中的IF为0,则屏蔽所有外部中断
OCW2:设置中断结束方式和优先级模式
操作系统-中断代理-8295A
OCW3:设置特殊屏蔽方式及查询方式
操作系统-中断代理-8295A
代码演示

;--------------------------
; write_EOI:
;--------------------------
write_master_EOI:
    mov al, 00100000B               ; OCW2 select, EOI
    out MASTER_OCW2_PORT, al
    ret

write_slave_EOI:
    mov al,  00100000B
    out SLAVE_OCW2_PORT, al
    ret

;----------------------------
; read_isr:
;----------------------------
read_master_isr:
    mov al, 00001011B           ; OCW3 select, read ISR
    out MASTER_OCW3_PORT, al
    jmp $+2
    in al, MASTER_OCW3_PORT
    ret

read_slave_isr:
    mov al, 00001011B
    out SLAVE_OCW3_PORT, al
    jmp $+2
    in al, SLAVE_OCW3_PORT
    ret

;-----------------------------
; read_irr:
;-----------------------------
read_master_irr:
    mov al, 00001010B           ; OCW3 select, read IRR 
    out MASTER_OCW3_PORT, al
    jmp $+2
    in al, MASTER_OCW3_PORT
    ret

read_slave_irr:
    mov al, 00001010B
    out SLAVE_OCW3_PORT, al
    jmp $+2
    in al, SLAVE_OCW3_PORT
    ret

;-----------------------------
; read_imr:
;-----------------------------
read_master_imr:
    in al, MASTER_IMR_PORT
    ret

read_slave_imr:
    in al, SLAVE_IMR_PORT
    ret

;------------------------------
; send_smm_command
;------------------------------
send_smm_command:
    mov al, 01101000B           ; SMM=ESMM=1, OCW3 select
    out MASTER_OCW3_PORT, al    
    ret

小结

1.英特尔架构的中断系统由中断管理和中断处理构成
2.处理器负责响应中断以及执行中断服务程序
3.8259A负责管理中断和裁决中断-ICW控制字用于初始化配置,OCW控制字用于中断结束及优先级设置

  

  

原文地址:https://www.cnblogs.com/lh03061238/p/14521750.html