InterruptEntry.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <Kernel/Arch/x86/DescriptorTable.h>
  7. #include <Kernel/Arch/x86/TrapFrame.h>
  8. // clang-format off
  9. asm(
  10. ".globl interrupt_common_asm_entry\n"
  11. "interrupt_common_asm_entry: \n"
  12. " pusha\n"
  13. " pushl %ds\n"
  14. " pushl %es\n"
  15. " pushl %fs\n"
  16. " pushl %gs\n"
  17. " pushl %ss\n"
  18. " mov $" __STRINGIFY(GDT_SELECTOR_DATA0) ", %ax\n"
  19. " mov %ax, %ds\n"
  20. " mov %ax, %es\n"
  21. " mov $" __STRINGIFY(GDT_SELECTOR_PROC) ", %ax\n"
  22. " mov %ax, %fs\n"
  23. " pushl %esp \n" // set TrapFrame::regs
  24. " subl $" __STRINGIFY(TRAP_FRAME_SIZE - 4) ", %esp \n"
  25. " movl %esp, %ebx \n" // save pointer to TrapFrame
  26. " pushl %ebx \n"
  27. " cld\n"
  28. " call enter_trap \n"
  29. " movl %ebx, 0(%esp) \n" // push pointer to TrapFrame
  30. " call handle_interrupt\n"
  31. " movl %ebx, 0(%esp) \n" // push pointer to TrapFrame
  32. ".globl common_trap_exit \n"
  33. "common_trap_exit: \n"
  34. // another thread may have handled this trap at this point, so don't
  35. // make assumptions about the stack other than there's a TrapFrame
  36. // and a pointer to it.
  37. " call exit_trap \n"
  38. " addl $" __STRINGIFY(TRAP_FRAME_SIZE + 4) ", %esp\n" // pop TrapFrame and pointer to it
  39. ".globl interrupt_common_asm_exit \n"
  40. "interrupt_common_asm_exit: \n"
  41. " addl $4, %esp\n" // pop %ss
  42. " popl %gs\n"
  43. " popl %fs\n"
  44. " popl %es\n"
  45. " popl %ds\n"
  46. " popa\n"
  47. " addl $0x4, %esp\n" // skip exception_code, isr_number
  48. " iret\n"
  49. );
  50. // clang-format on