int.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of XNIX. */
  3. /*
  4. XNIX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) and later version.
  8. */
  9. /*
  10. XNIX is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. */
  15. /*
  16. You should have received a copy of the GNU General Public License
  17. along with XNIX. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _INT_H
  20. #define _INT_H
  21. #include <kernel/types.h>
  22. #include <kernel/errno.h>
  23. /* kernel/trap.S */
  24. void divide_error(void);
  25. void debug(void);
  26. void nmi(void);
  27. void int3(void);
  28. void overflow(void);
  29. void bound(void);
  30. void invalid_code(void);
  31. void device_not_avaliable(void);
  32. void double_fault(void);
  33. void fpu_segment_overrun(void);
  34. void invalid_tss(void);
  35. void segment_not_present(void);
  36. void stack_error(void);
  37. void general_protection(void);
  38. void page_fault(void);
  39. void reserved(void);
  40. void fpu_error(void);
  41. void alignment(void);
  42. void machine(void);
  43. void simd(void);
  44. void virtualization(void);
  45. void register_irq(int, void *, void *);
  46. void unregister_irq(int);
  47. void do_irq(__uint64_t *, __uint64_t);
  48. void do_timer(void);
  49. void do_keyboard(void);
  50. #define IRQ_SAVE_ALL() \
  51. "pushq %rax;\n\t" \
  52. "pushq %rcx;\n\t" \
  53. "pushq %rbx;\n\t" \
  54. "pushq %rdx;\n\t" \
  55. "pushq %rbp;\n\t" \
  56. "pushq %rsi;\n\t" \
  57. "pushq %rdi;\n\t" \
  58. "pushq %r8; \n\t" \
  59. "pushq %r9; \n\t" \
  60. "pushq %r10;\n\t" \
  61. "pushq %r11;\n\t" \
  62. "pushq %r12;\n\t" \
  63. "pushq %r13;\n\t" \
  64. "pushq %r14;\n\t" \
  65. "pushq %r15;\n\t" \
  66. "movq %ds, %rax;\n\t" \
  67. "pushq %rax; \n\t" \
  68. "movq %es, %rax;\n\t" \
  69. "pushq %rax; \n\t" \
  70. "movq %fs, %rax;\n\t" \
  71. "pushq %rax; \n\t" \
  72. "movq %gs, %rax;\n\t" \
  73. "pushq %rax;" \
  74. "movq $0x10, %rax;\n\t" \
  75. "movq %rax, %ds;\n\t" \
  76. "movq %rax, %es;\n\t" \
  77. "movq %rax, %fs;\n\t" \
  78. "movq %rax, %gs;\n\t"
  79. #define IRQ_NAMEN(nr) nr##_interrupt(void)
  80. #define IRQ_NAME(nr) IRQ_NAMEN(irq##nr)
  81. #define build_irq(nr) \
  82. void IRQ_NAME(nr); \
  83. __asm__ ( \
  84. ".globl irq"#nr"_interrupt\n\t;"\
  85. "irq"#nr"_interrupt: \n\t" \
  86. IRQ_SAVE_ALL() \
  87. /* arguments for do_irq */ \
  88. "movq %rsp, %rdi\n\t" \
  89. "movq $"#nr", %rsi\n\t" \
  90. "leaq ret_intr(%rip), %rax\n\t" \
  91. "pushq %rax\n\t" \
  92. "jmp do_irq\n\t" \
  93. );
  94. #define MAX_IRQ_NR 24
  95. struct irq_entry {
  96. void (*handler) (void);
  97. };
  98. extern struct irq_entry irq_table[MAX_IRQ_NR];
  99. #endif