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 200 kick cpu 功能(使得某个核心立即运行进程调度) 106 107 */ 108 109 typedef struct hardware_intr_type 110 { 111 // 使能中断操作接口 112 void (*enable)(ul irq_num); 113 // 禁止中断操作接口 114 void (*disable)(ul irq_num); 115 116 // 安装中断操作接口 117 ul (*install)(ul irq_num, void *arg); 118 // 卸载中断操作接口 119 void (*uninstall)(ul irq_num); 120 // 应答中断操作接口 121 void (*ack)(ul irq_num); 122 } hardware_intr_controller; 123 124 // 中断描述结构体 125 typedef struct 126 { 127 hardware_intr_controller *controller; 128 // 中断名 129 char *irq_name; 130 // 中断处理函数的参数 131 ul parameter; 132 // 中断处理函数 133 void (*handler)(ul irq_num, ul parameter, struct pt_regs *regs); 134 135 // 自定义的标志位 136 ul flags; 137 } irq_desc_t; 138 139 140 // 这几个表一定要放在这里,否则在HPET初始化后收到中断,会产生page fault 141 irq_desc_t interrupt_desc[IRQ_NUM] = {0}; 142 irq_desc_t local_apic_interrupt_desc[LOCAL_APIC_IRQ_NUM] = {0}; 143 irq_desc_t SMP_IPI_desc[SMP_IRQ_NUM] = {0}; 144 145 146 /** 147 * @brief 中断注册函数 148 * 149 * @param irq_num 中断向量号 150 * @param arg 传递给中断安装接口的参数 151 * @param handler 中断处理函数 152 * @param paramater 中断处理函数的参数 153 * @param controller 中断控制器结构 154 * @param irq_name 中断名 155 * @return int 156 */ 157 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); 158 159 /** 160 * @brief 中断注销函数 161 * 162 * @param irq_num 中断向量号 163 * @return int 164 */ 165 int irq_unregister(ul irq_num); 166 167 /** 168 * @brief 初始化中断模块 169 */ 170 void irq_init(); 171 #pragma GCC pop_options