acn.s 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Code to support tracing from assembly code
  2. .text
  3. # Usage:
  4. # call acn
  5. # .asciz "message\n"
  6. .globl acn
  7. .globl _acn
  8. acn:
  9. _acn: # return address at 128
  10. push %rax # 120
  11. push %rbx # 112
  12. push %rcx # 104
  13. push %rdx # 96
  14. push %rbp # 88
  15. push %rsp # 80
  16. push %rsi # 72
  17. push %rdi # 64
  18. push %r8 # 56
  19. push %r9 # 48
  20. push %r10 # 40
  21. push %r11 # 32
  22. push %r12 # 24
  23. push %r13 # 16
  24. push %r14 # 8
  25. push %r15 # 0
  26. # For calling C I want to put arguments in
  27. # Linux: rdi, rsi, rdx, rcx, r8, r9
  28. # Windows: rcx, rdx, r8, r9, stack, stack
  29. .ifdef __WIN64__
  30. mov 128(%rsp), %rcx
  31. mov 120(%rsp), %rdx
  32. mov 112(%rsp), %r8
  33. mov 104(%rsp), %r9
  34. .else
  35. .ifdef __CYGWIN__
  36. mov 128(%rsp), %rcx
  37. mov 120(%rsp), %rdx
  38. mov 112(%rsp), %r8
  39. mov 104(%rsp), %r9
  40. .else
  41. mov 128(%rsp), %rdi
  42. mov 120(%rsp), %rsi
  43. mov 112(%rsp), %rdx
  44. mov 104(%rsp), %rcx
  45. .endif
  46. .endif
  47. # There must be space for 4 registers above the stack pointer, and
  48. # the stack should be aligned at a multiple of 16 just before any CALL.
  49. # Or possibly a multiple of 32, which is what I impose here.
  50. mov %rsp, %rax
  51. sub $64, %rsp
  52. shr $5, %rsp
  53. shl $5, %rsp
  54. mov %rax, 40(%rsp)
  55. call _acn1 # This function must return the real return address!
  56. mov 40(%rsp), %rsp
  57. mov %rax, 128(%rsp)
  58. pop %r15
  59. pop %r14
  60. pop %r13
  61. pop %r12
  62. pop %r11
  63. pop %r10
  64. pop %r9
  65. pop %r8
  66. pop %rdi
  67. pop %rsi
  68. pop %rsp
  69. pop %rbp
  70. pop %rdx
  71. pop %rcx
  72. pop %rbx
  73. pop %rax
  74. ret
  75. # end of acn.s