idt.h 1010 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef IDT_H
  2. #define IDT_H
  3. #include "type.h"
  4. /* Segment selectors */
  5. #define KERNEL_CS 0x08
  6. /* How every interrupt gate (handler) is defined */
  7. typedef struct {
  8. u16 low_offset; /* Lower 16 bits of handler function address */
  9. u16 sel; /* Kernel segment selector */
  10. u8 always0;
  11. /* First byte
  12. * Bit 7: "Interrupt is present"
  13. * Bits 6-5: Privilege level of caller (0=kernel..3=user)
  14. * Bit 4: Set to 0 for interrupt gates
  15. * Bits 3-0: bits 1110 = decimal 14 = "32 bit interrupt gate" */
  16. u8 flags;
  17. u16 high_offset; /* Higher 16 bits of handler function address */
  18. } __attribute__((packed)) idt_gate_t ;
  19. /* A pointer to the array of interrupt handlers.
  20. * Assembly instruction 'lidt' will read it */
  21. typedef struct {
  22. u16 limit;
  23. u32 base;
  24. } __attribute__((packed)) idt_register_t;
  25. #define IDT_ENTRIES 256
  26. idt_gate_t idt[IDT_ENTRIES];
  27. idt_register_t idt_reg;
  28. /* Functions implemented in idt.c */
  29. void set_idt_gate(int n, u32 handler);
  30. void set_idt();
  31. #endif