trap.S 1.9 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. .globl __stack_chk_fail
  20. __stack_chk_fail:
  21. movq schkfail_msg(%rip), %rdi
  22. scf_die:
  23. hlt
  24. jmp scf_die
  25. .globl divide_error
  26. divide_error:
  27. pushq %rax
  28. leaq do_divide_error(%rip), %rax
  29. no_error_code:
  30. /* and save other registers seriously now */
  31. pushq %rcx
  32. pushq %rdx
  33. pushq %rbp
  34. pushq %rsi
  35. pushq %rdi
  36. pushq %r8
  37. pushq %r9
  38. pushq %r10
  39. pushq %r11
  40. pushq %r12
  41. pushq %r13
  42. pushq %r14
  43. pushq %r15
  44. /* segments also */
  45. movq %ds, %rcx
  46. pushq %rcx
  47. movq %es, %rcx
  48. pushq %rcx
  49. movq %fs, %rcx
  50. pushq %rcx
  51. movq %gs, %rcx
  52. pushq %rcx
  53. /* that fake error code */
  54. pushq $0
  55. /* KERNEL_DS */
  56. movq $0x10, %rcx
  57. movq %ds, %rcx
  58. movq %es, %rcx
  59. movq %fs, %rcx
  60. movq %gs, %rcx
  61. /* call that interrupt handler */
  62. callq *%rax
  63. restore_all:
  64. /* now we restore and return */
  65. /* ignore that "error code" */
  66. addq $8, %rsp
  67. popq %rax
  68. movq %gs, %rax
  69. popq %rax
  70. movq %fs, %rax
  71. popq %rax
  72. movq %es, %rax
  73. popq %rax
  74. movq %ds, %rax
  75. popq %r15
  76. popq %r14
  77. popq %r13
  78. popq %r12
  79. popq %r11
  80. popq %r10
  81. popq %r9
  82. popq %r8
  83. popq %rdi
  84. popq %rsi
  85. popq %rbp
  86. popq %rdx
  87. popq %rcx
  88. popq %rax
  89. /* then say goodbye to */
  90. .section .rodata
  91. schkfail_msg:
  92. .asciz "kernel panic: stack check fail. \n"