int.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 _KINT_H
  20. #define _KINT_H
  21. #ifndef __ASM__
  22. #include <kernel/types.h>
  23. #include <kernel/errno.h>
  24. /* kernel/trap.S */
  25. void divide_error(void);
  26. void debug(void);
  27. void nmi(void);
  28. void int3(void);
  29. void overflow(void);
  30. void bound(void);
  31. void invalid_code(void);
  32. void device_not_avaliable(void);
  33. void double_fault(void);
  34. void fpu_segment_overrun(void);
  35. void invalid_tss(void);
  36. void segment_not_present(void);
  37. void stack_error(void);
  38. void general_protection(void);
  39. void page_fault(void);
  40. void reserved(void);
  41. void fpu_error(void);
  42. void alignment(void);
  43. void machine(void);
  44. void simd(void);
  45. void virtualization(void);
  46. void register_irq(int, void *, const void *);
  47. void unregister_irq(int);
  48. /* kernel/timer.S */
  49. void do_irq(const __uint64_t *, __uint64_t);
  50. void do_timer(void);
  51. void do_keyboard(void);
  52. void trace_irq(void);
  53. /* kernel/timer.S */
  54. extern __uint64_t jiffies;
  55. #define IRQ_SAVE_ALL() \
  56. "pushq %rax;\n\t" \
  57. "pushq %rcx;\n\t" \
  58. "pushq %rbx;\n\t" \
  59. "pushq %rdx;\n\t" \
  60. "pushq %rbp;\n\t" \
  61. "pushq %rsi;\n\t" \
  62. "pushq %rdi;\n\t" \
  63. "pushq %r8; \n\t" \
  64. "pushq %r9; \n\t" \
  65. "pushq %r10;\n\t" \
  66. "pushq %r11;\n\t" \
  67. "pushq %r12;\n\t" \
  68. "pushq %r13;\n\t" \
  69. "pushq %r14;\n\t" \
  70. "pushq %r15;\n\t" \
  71. "movq %ds, %rax;\n\t" \
  72. "pushq %rax; \n\t" \
  73. "movq %es, %rax;\n\t" \
  74. "pushq %rax; \n\t" \
  75. "movq %fs, %rax;\n\t" \
  76. "pushq %rax; \n\t" \
  77. "movq %gs, %rax;\n\t" \
  78. "pushq %rax;" \
  79. "movq $0x10, %rax;\n\t" \
  80. "movq %rax, %ds;\n\t" \
  81. "movq %rax, %es;\n\t" \
  82. "movq %rax, %fs;\n\t" \
  83. "movq %rax, %gs;\n\t"
  84. #define IRQ_NAMEN(nr) nr##_interrupt(void)
  85. #define IRQ_NAME(nr) IRQ_NAMEN(irq##nr)
  86. #define build_irq(nr) \
  87. void IRQ_NAME(nr); \
  88. __asm__ ( \
  89. ".globl irq"#nr"_interrupt\n\t;"\
  90. "irq"#nr"_interrupt: \n\t" \
  91. "cli\n\t" \
  92. IRQ_SAVE_ALL() \
  93. /* arguments for do_irq */ \
  94. "movq %rsp, %rdi\n\t" \
  95. "movq $"#nr", %rsi\n\t" \
  96. "leaq ret_intr(%rip), %rax\n\t" \
  97. "pushq %rax\n\t" \
  98. "jmp do_irq\n\t" \
  99. );
  100. #define MAX_IRQ_NR 0x60
  101. struct irq_entry {
  102. void (*handler) (void);
  103. };
  104. extern struct irq_entry irq_table[MAX_IRQ_NR];
  105. #endif
  106. /* offsets value in stack */
  107. #define off_gs 0
  108. #define off_fs 1
  109. #define off_es 2
  110. #define off_ds 3
  111. #define off_r15 4
  112. #define off_r14 5
  113. #define off_r13 6
  114. #define off_r12 7
  115. #define off_r11 8
  116. #define off_r10 9
  117. #define off_r9 10
  118. #define off_r8 11
  119. #define off_rdi 12
  120. #define off_rsi 13
  121. #define off_rbp 14
  122. #define off_rbx 15
  123. #define off_rdx 16
  124. #define off_rcx 17
  125. #define off_rax 18
  126. #define off_handler 19
  127. #define off_errcode 20
  128. #define off_rip 21
  129. #define off_rflags 22
  130. #define off_rsp 23
  131. #define off_ss 24
  132. #define GS 0
  133. #define FS 8
  134. #define ES 16
  135. #define DS 24
  136. #define R15 32
  137. #define R14 40
  138. #define R13 48
  139. #define R12 56
  140. #define R11 64
  141. #define R10 72
  142. #define R9 80
  143. #define R8 88
  144. #define RDI 96
  145. #define RSI 104
  146. #define RBP 112
  147. #define RBX 120
  148. #define RDX 128
  149. #define RCX 136
  150. #define RAX 144
  151. #define HANDLER 152
  152. #define ERRCODE 160
  153. #define RIP 168
  154. #define RFLAGS 176
  155. /* maybe, maybe, well... */
  156. #define RSP 184
  157. #define SS 192
  158. #endif