irq.h 3.2 KB

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