interrupt.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef __KERNEL_INTERRUPT_H
  2. #define __KERNEL_INTERRUPT_H
  3. #include "stdint.h"
  4. #include "global.h"
  5. #define IDT_DESC_CNT 0x21 // 目前支持的中断数
  6. #define PIC_M_CTRL 0x20 // 主片的控制端口是 0x20
  7. #define PIC_M_DATA 0x21 // 主片的数据端口是 0x21
  8. #define PIC_S_CTRL 0xA0 // 从片的控制端口是 0xA0
  9. #define PIC_S_DATA 0xA1 // 从片的数据端口是 0xA1
  10. typedef void *intr_handler;
  11. /* 中断门描述符结构体 */
  12. // Example type_attributes values that people are likely to use (assuming DPL is 0):
  13. // 32-bit Interrupt Gate: 0x8E (p=1, dpl=0b00, type=0b1110 => type_attributes=0b1000_1110=0x8E)
  14. // 32-bit Trap Gate: 0x8F (p=1, dpl=0b00, type=0b1111 => type_attributes=1000_1111b=0x8F)
  15. // Task Gate: 0x85 (p=1, dpl=0b00, type=0b0101 => type_attributes=0b1000_0101=0x85)
  16. typedef struct
  17. {
  18. uint16_t offset_low; // 16位 偏移量的低 16 位 (0..15)
  19. uint16_t selector; // 选择器 acode segment selector in GDT or LDT
  20. uint8_t dcount; // 置 0
  21. uint8_t attribute; // 述符类型 (bit 7:0) gate type, dpl, and p fields
  22. uint16_t offset_high; // 16 位 偏移量的高 16 位 (16..31)
  23. } __attribute__((packed)) gate_desc;
  24. static void make_idt_desc(gate_desc *p_gdesc, uint8_t attr, intr_handler function);
  25. static void itd_desc_init(void);
  26. void itd_init(void);
  27. static gate_desc idt[IDT_DESC_CNT]; // 中断描述符表,本质上就是个中断门描述符数组
  28. extern intr_handler intr_entry_table[IDT_DESC_CNT]; // 声明引用定义在 kernel.S 中的中断处理函数入口数组
  29. #endif // __KERNEL_INTERRUPT_H