irq.h 3.2 KB

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