InterruptEntry.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Gunnar Beutner <gbeutner@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <Kernel/Arch/x86/DescriptorTable.h>
  8. #include <Kernel/Arch/x86/TrapFrame.h>
  9. // clang-format off
  10. asm(
  11. ".globl interrupt_common_asm_entry\n"
  12. "interrupt_common_asm_entry: \n"
  13. // save all the other registers
  14. " pushq %r15\n"
  15. " pushq %r14\n"
  16. " pushq %r13\n"
  17. " pushq %r12\n"
  18. " pushq %r11\n"
  19. " pushq %r10\n"
  20. " pushq %r9\n"
  21. " pushq %r8\n"
  22. " pushq %rax\n"
  23. " pushq %rcx\n"
  24. " pushq %rdx\n"
  25. " pushq %rbx\n"
  26. " pushq %rsp\n"
  27. " pushq %rbp\n"
  28. " pushq %rsi\n"
  29. " pushq %rdi\n"
  30. " pushq %rsp \n" /* set TrapFrame::regs */
  31. " subq $" __STRINGIFY(TRAP_FRAME_SIZE - 8) ", %rsp \n"
  32. " movq %rsp, %rdi \n"
  33. " cld\n"
  34. " call enter_trap \n"
  35. " movq %rsp, %rdi \n"
  36. " call handle_interrupt \n"
  37. ".globl common_trap_exit \n"
  38. "common_trap_exit: \n"
  39. // another thread may have handled this trap at this point, so don't
  40. // make assumptions about the stack other than there's a TrapFrame.
  41. " movq %rsp, %rdi \n"
  42. " call exit_trap \n"
  43. " addq $" __STRINGIFY(TRAP_FRAME_SIZE) ", %rsp\n" // pop TrapFrame
  44. ".globl interrupt_common_asm_exit \n"
  45. "interrupt_common_asm_exit: \n"
  46. " popq %rdi\n"
  47. " popq %rsi\n"
  48. " popq %rbp\n"
  49. " addq $8, %rsp\n" // skip restoring rsp
  50. " popq %rbx\n"
  51. " popq %rdx\n"
  52. " popq %rcx\n"
  53. " popq %rax\n"
  54. " popq %r8\n"
  55. " popq %r9\n"
  56. " popq %r10\n"
  57. " popq %r11\n"
  58. " popq %r12\n"
  59. " popq %r13\n"
  60. " popq %r14\n"
  61. " popq %r15\n"
  62. " addq $0x8, %rsp\n" // skip exception_code, isr_number
  63. " iretq\n"
  64. );
  65. // clang-format on