interrupt.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * interrupt.h
  3. *
  4. * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _INTERRUPT_H_
  20. #define _INTERRUPT_H_
  21. #include <common.h>
  22. #include <sdk/cpu.h>
  23. #include <sdk/list.h>
  24. #define IDT_NUM_INTERRUPTS 256
  25. #define ISR_STUB_SIZE 64
  26. #define HAS_ERROR_CODE(x) (((x) == 8) || ((x) >= 10 && (x) <= 14))
  27. #define IDT_GATE_KERNEL 0x8E
  28. #define IDT_GATE_USER 0xEE
  29. #define CONTEXT_SWITCH_MAGIC 0xDEADBEEF
  30. #pragma pack(push, 1)
  31. typedef struct
  32. {
  33. word_t offset;
  34. word_t selector;
  35. byte_t zero;
  36. byte_t type;
  37. word_t offset_high;
  38. } idt_entry_t;
  39. #pragma pack(pop)
  40. typedef void (*isr_proc_t)(registers_t *regs, byte_t interrupt_num);
  41. typedef struct
  42. {
  43. isr_proc_t procedure;
  44. bool_t interrupts;
  45. } interrupt_handler_t;
  46. void interrupt_init(void);
  47. dword_t set_int_handler(byte_t interrupt_num, isr_proc_t proc, bool_t interrupts, bool_t usermode);
  48. dword_t remove_int_handler(byte_t interrupt_num);
  49. #endif