1 /** 2 * @file irq.h 3 * @author longjin 4 * @brief 中断处理程序 5 * @version 0.1 6 * @date 2022-01-28 7 * 8 * @copyright Copyright (c) 2022 9 * 10 */ 11 12 #pragma once 13 #include <common/glib.h> 14 15 #include <process/ptrace.h> 16 #pragma GCC push_options 17 #pragma GCC optimize ("O0") 18 19 #define IRQ_NUM 24 20 #define SMP_IRQ_NUM 10 21 #define LOCAL_APIC_IRQ_NUM 50 22 23 extern void (*interrupt_table[24])(void); 24 extern void do_IRQ(struct pt_regs *regs, ul number); 25 26 27 extern void (*SMP_interrupt_table[SMP_IRQ_NUM])(void); 28 29 extern void (*syscall_intr_table[1])(void); 30 extern void (*local_apic_interrupt_table[LOCAL_APIC_IRQ_NUM])(void); 31 32 /* ========= 中断向量分配表 ========== 33 34 0~255 IDT 35 36 0 ~ 31 trap fault abort for system 37 0 devide error 38 1 debug 39 2 NMI 40 3 breakpoint 41 4 overflow 42 5 bound range 43 6 undefined opcode 44 7 device not available 45 8 double fault 46 9 coprocessor segment overrun 47 10 invalid TSS 48 11 segment not present 49 12 stack segment fault 50 13 general protection 51 14 page fault 52 15 53 16 x87 FPU error 54 17 alignment check 55 18 machine check 56 19 SIMD exception 57 20 virtualization exception 58 21 ~ 31 Do not use 59 60 32 ~ 55 I/O APIC 61 32 8259A 62 33 keyboard 63 34 HPET timer 0,8254 counter 0 64 35 serial port A 65 36 serial port B 66 37 parallel port 67 38 floppy 68 39 parallel port 69 40 RTC,HPET timer 1 70 41 Generic 71 42 Generic 72 43 HPET timer 2 73 44 HPET timer 3 / mouse 74 45 FERR# 75 46 SATA primary 76 47 SATA secondary 77 48 PIRQA 78 49 PIRQB 79 50 PIRQC 80 51 PIRQD 81 52 PIRQE 82 53 PIRQF 83 54 PIRQG 84 55 PIRQH 85 86 87 0x80 system call 88 0x81 system interrupt 系统中断 89 90 [150,200) Local APIC 91 150 CMCI 92 151 Timer 93 152 Thermal Monitor 94 153 Performance Counter 95 154 LINT0 96 155 LINT1 97 156 Error 98 157 xhci_controller_0 99 158 xhci_controller_1 100 159 xhci_controller_2 101 160 xhci_controller_3 102 103 200 ~ 255 MP IPI 104 105 */ 106 107 typedef struct hardware_intr_type 108 { 109 // 使能中断操作接口 110 void (*enable)(ul irq_num); 111 // 禁止中断操作接口 112 void (*disable)(ul irq_num); 113 114 // 安装中断操作接口 115 ul (*install)(ul irq_num, void *arg); 116 // 卸载中断操作接口 117 void (*uninstall)(ul irq_num); 118 // 应答中断操作接口 119 void (*ack)(ul irq_num); 120 } hardware_intr_controller; 121 122 // 中断描述结构体 123 typedef struct 124 { 125 hardware_intr_controller *controller; 126 // 中断名 127 char *irq_name; 128 // 中断处理函数的参数 129 ul parameter; 130 // 中断处理函数 131 void (*handler)(ul irq_num, ul parameter, struct pt_regs *regs); 132 133 // 自定义的标志位 134 ul flags; 135 } irq_desc_t; 136 137 138 // 这几个表一定要放在这里,否则在HPET初始化后收到中断,会产生page fault 139 irq_desc_t interrupt_desc[IRQ_NUM] = {0}; 140 irq_desc_t local_apic_interrupt_desc[LOCAL_APIC_IRQ_NUM] = {0}; 141 irq_desc_t SMP_IPI_desc[SMP_IRQ_NUM] = {0}; 142 143 144 /** 145 * @brief 中断注册函数 146 * 147 * @param irq_num 中断向量号 148 * @param arg 传递给中断安装接口的参数 149 * @param handler 中断处理函数 150 * @param paramater 中断处理函数的参数 151 * @param controller 中断控制器结构 152 * @param irq_name 中断名 153 * @return int 154 */ 155 int irq_register(ul irq_num, void *arg, void (*handler)(ul irq_num, ul parameter, struct pt_regs *regs), ul paramater, hardware_intr_controller *controller, char *irq_name); 156 157 /** 158 * @brief 中断注销函数 159 * 160 * @param irq_num 中断向量号 161 * @return int 162 */ 163 int irq_unregister(ul irq_num); 164 165 /** 166 * @brief 初始化中断模块 167 */ 168 void irq_init(); 169 #pragma GCC pop_options