int.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 *, void *);
  47. void unregister_irq(int);
  48. /* kernel/timer.S */
  49. void do_irq(__uint64_t *, __uint64_t);
  50. void do_timer(void);
  51. void do_keyboard(void);
  52. /* kernel/timer.S */
  53. extern __uint64_t jiffies;
  54. #define IRQ_SAVE_ALL() \
  55. "pushq %rax;\n\t" \
  56. "pushq %rcx;\n\t" \
  57. "pushq %rbx;\n\t" \
  58. "pushq %rdx;\n\t" \
  59. "pushq %rbp;\n\t" \
  60. "pushq %rsi;\n\t" \
  61. "pushq %rdi;\n\t" \
  62. "pushq %r8; \n\t" \
  63. "pushq %r9; \n\t" \
  64. "pushq %r10;\n\t" \
  65. "pushq %r11;\n\t" \
  66. "pushq %r12;\n\t" \
  67. "pushq %r13;\n\t" \
  68. "pushq %r14;\n\t" \
  69. "pushq %r15;\n\t" \
  70. "movq %ds, %rax;\n\t" \
  71. "pushq %rax; \n\t" \
  72. "movq %es, %rax;\n\t" \
  73. "pushq %rax; \n\t" \
  74. "movq %fs, %rax;\n\t" \
  75. "pushq %rax; \n\t" \
  76. "movq %gs, %rax;\n\t" \
  77. "pushq %rax;" \
  78. "movq $0x10, %rax;\n\t" \
  79. "movq %rax, %ds;\n\t" \
  80. "movq %rax, %es;\n\t" \
  81. "movq %rax, %fs;\n\t" \
  82. "movq %rax, %gs;\n\t"
  83. #define IRQ_NAMEN(nr) nr##_interrupt(void)
  84. #define IRQ_NAME(nr) IRQ_NAMEN(irq##nr)
  85. #define build_irq(nr) \
  86. void IRQ_NAME(nr); \
  87. __asm__ ( \
  88. ".globl irq"#nr"_interrupt\n\t;"\
  89. "irq"#nr"_interrupt: \n\t" \
  90. "cli\n\t" \
  91. IRQ_SAVE_ALL() \
  92. /* arguments for do_irq */ \
  93. "movq %rsp, %rdi\n\t" \
  94. "movq $"#nr", %rsi\n\t" \
  95. "leaq ret_intr(%rip), %rax\n\t" \
  96. "pushq %rax\n\t" \
  97. "jmp do_irq\n\t" \
  98. );
  99. #define MAX_IRQ_NR 0x60
  100. struct irq_entry {
  101. void (*handler) (void);
  102. };
  103. extern struct irq_entry irq_table[MAX_IRQ_NR];
  104. #endif
  105. /* offsets value in stack */
  106. #define GS 0
  107. #define FS 8
  108. #define ES 16
  109. #define DS 24
  110. #define R15 32
  111. #define R14 40
  112. #define R13 48
  113. #define R12 56
  114. #define R11 64
  115. #define R10 72
  116. #define R9 80
  117. #define R8 88
  118. #define RDI 96
  119. #define RSI 104
  120. #define RBP 112
  121. #define RBX 120
  122. #define RDX 128
  123. #define RCX 136
  124. #define RAX 144
  125. #define HANDLER 152
  126. #define ERRCODE 160
  127. #define RIP 168
  128. #define RFLAGS 176
  129. /* maybe, maybe, well... */
  130. #define RSP 184
  131. #define SS 192
  132. #endif