irq.h 3.4 KB

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