jump.S 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright Oliver Kowalke 2009.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /****************************************************************************************
  8. * *
  9. * ---------------------------------------------------------------------------------- *
  10. * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
  11. * ---------------------------------------------------------------------------------- *
  12. * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
  13. * ---------------------------------------------------------------------------------- *
  14. * | R12 | R13 | R14 | R15 | *
  15. * ---------------------------------------------------------------------------------- *
  16. * ---------------------------------------------------------------------------------- *
  17. * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
  18. * ---------------------------------------------------------------------------------- *
  19. * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
  20. * ---------------------------------------------------------------------------------- *
  21. * | RBX | RBP | RIP | EXIT | *
  22. * ---------------------------------------------------------------------------------- *
  23. * *
  24. ****************************************************************************************/
  25. .text
  26. .globl jump_fcontext
  27. .type jump_fcontext,@function
  28. .align 16
  29. jump_fcontext:
  30. pushq %rbp /* save RBP */
  31. pushq %rbx /* save RBX */
  32. pushq %r15 /* save R15 */
  33. pushq %r14 /* save R14 */
  34. pushq %r13 /* save R13 */
  35. pushq %r12 /* save R12 */
  36. /* store RSP (pointing to context-data) in RAX */
  37. movq %rsp, %rax
  38. /* restore RSP (pointing to context-data) from RDI */
  39. movq %rdi, %rsp
  40. popq %r12 /* restrore R12 */
  41. popq %r13 /* restrore R13 */
  42. popq %r14 /* restrore R14 */
  43. popq %r15 /* restrore R15 */
  44. popq %rbx /* restrore RBX */
  45. popq %rbp /* restrore RBP */
  46. /* restore return-address */
  47. popq %r8
  48. /* return transfer_t from jump */
  49. /* RAX == fctx, RDX == data */
  50. movq %rsi, %rdx
  51. /* pass transfer_t as first arg in context function */
  52. /* RDI == fctx, RSI == data */
  53. movq %rax, %rdi
  54. /* indirect jump to context */
  55. jmp *%r8
  56. .size jump_fcontext,.-jump_fcontext
  57. /* Mark that we don't need executable stack. */
  58. .section .note.GNU-stack,"",%progbits