ontop.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 ontop_fcontext
  27. .type ontop_fcontext,@function
  28. .align 16
  29. ontop_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. /* preserve ontop-function in R8 */
  47. movq %rdx, %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. /* keep return-address on stack */
  55. /* indirect jump to context */
  56. jmp *%r8
  57. .size ontop_fcontext,.-ontop_fcontext
  58. /* Mark that we don't need executable stack. */
  59. .section .note.GNU-stack,"",%progbits