[section .sfunc] [bits 32] ; 放上与中断相关的函数 ; Delay: %rep 5 nop %endrep ret Init8259A: push ax ; master ; ICW1 mov al, 00010001B out MASTER_ICW1_PORT, al call Delay ; ICW2 mov al, 0x20 out MASTER_ICW2_PORT, al call Delay ; ICW3 mov al, 00000100B out MASTER_ICW3_PORT, al call Delay ; ICW4 mov al, 00010001B out MASTER_ICW4_PORT, al call Delay ; slave ; ICW1 mov al, 00010001B out SLAVE_ICW1_PORT, al call Delay ; ICW2 mov al, 0x28 out SLAVE_ICW2_PORT, al call Delay ; ICW3 mov al, 00000010B out SLAVE_ICW3_PORT, al call Delay ; ICW4 mov al, 00000001B out SLAVE_ICW4_PORT, al call Delay pop ax ret ; al --> IMR register value ; dx --> 8259A port WriteIMR: out dx, al call Delay ret ; dx --> 8259A ; return: ; ax --> IMR register value ReadIMR: in ax, dx call Delay ret
; ; dx --> 8259A port WriteEOI: push ax mov al, 0x20 out dx, al call Delay pop ax ret [section .gfunc] [bits 32] ; 全局函数给C语言调用的,需要将函数地址传入到交换区 ; parameter ===> Task* pt RunTask: push ebp mov ebp, esp mov esp, [ebp + 8] lldt word [esp + 200] ltr word [esp + 202] pop gs pop fs pop es pop ds popad add esp, 4 iret ;初始化 8259A ; InitInterrupt: push ebp mov ebp, esp push ax push dx call Init8259A sti mov ax, 0xFF mov dx, MASTER_IMR_PORT call WriteIMR mov ax, 0xFF mov dx, SLAVE_IMR_PORT call WriteIMR pop dx pop ax leave ret
; ;打开时钟中断开关 EnableTimer: push ebp mov ebp, esp push ax push dx mov dx, MASTER_IMR_PORT call ReadIMR and ax, 0xFE call WriteIMR pop dx pop ax leave ret ; void SendEOI(uint port); ; port ==> 8259A port SendEOI: push ebp mov ebp, esp mov edx, [ebp + 8] mov al, 0x20 out dx, al call Delay leave ret