make_ppc64_sysv_macho_gas.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
  13. * ------------------------------------------------- *
  14. * | TOC | R14 | R15 | R16 | *
  15. * ------------------------------------------------- *
  16. * ------------------------------------------------- *
  17. * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
  18. * ------------------------------------------------- *
  19. * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
  20. * ------------------------------------------------- *
  21. * | R17 | R18 | R19 | R20 | *
  22. * ------------------------------------------------- *
  23. * ------------------------------------------------- *
  24. * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
  25. * ------------------------------------------------- *
  26. * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
  27. * ------------------------------------------------- *
  28. * | R21 | R22 | R23 | R24 | *
  29. * ------------------------------------------------- *
  30. * ------------------------------------------------- *
  31. * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
  32. * ------------------------------------------------- *
  33. * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
  34. * ------------------------------------------------- *
  35. * | R25 | R26 | R27 | R28 | *
  36. * ------------------------------------------------- *
  37. * ------------------------------------------------- *
  38. * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
  39. * ------------------------------------------------- *
  40. * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
  41. * ------------------------------------------------- *
  42. * | R29 | R30 | R31 | hidden | *
  43. * ------------------------------------------------- *
  44. * ------------------------------------------------- *
  45. * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
  46. * ------------------------------------------------- *
  47. * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
  48. * ------------------------------------------------- *
  49. * | CR | LR | PC | back-chain| *
  50. * ------------------------------------------------- *
  51. * ------------------------------------------------- *
  52. * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
  53. * ------------------------------------------------- *
  54. * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
  55. * ------------------------------------------------- *
  56. * | cr saved | lr saved | compiler | linker | *
  57. * ------------------------------------------------- *
  58. * ------------------------------------------------- *
  59. * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
  60. * ------------------------------------------------- *
  61. * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
  62. * ------------------------------------------------- *
  63. * | TOC saved | FCTX | DATA | | *
  64. * ------------------------------------------------- *
  65. * *
  66. .text
  67. .globl _make_fcontext
  68. _make_fcontext:
  69. ; save return address into R6
  70. mflr r6
  71. ; first arg of make_fcontext() == top address of context-function
  72. ; shift address in R3 to lower 16 byte boundary
  73. clrrwi r3, r3, 4
  74. ; reserve space for context-data on context-stack
  75. ; including 64 byte of linkage + parameter area (R1 16 == 0)
  76. subi r3, r3, 248
  77. ; third arg of make_fcontext() == address of context-function
  78. stw r5, 176(r3)
  79. ; set back-chain to zero
  80. li %r0, 0
  81. std %r0, 184(%r3)
  82. ; compute address of returned transfer_t
  83. addi %r0, %r3, 232
  84. mr %r4, %r0
  85. std %r4, 152(%r3)
  86. ; load LR
  87. mflr r0
  88. ; jump to label 1
  89. bl l1
  90. l1:
  91. ; load LR into R4
  92. mflr r4
  93. ; compute abs address of label finish
  94. addi r4, r4, lo16((finish - .) + 4)
  95. ; restore LR
  96. mtlr r0
  97. ; save address of finish as return-address for context-function
  98. ; will be entered after context-function returns
  99. std r4, 168(r3)
  100. ; restore return address from R6
  101. mtlr r6
  102. blr ; return pointer to context-data
  103. finish:
  104. ; save return address into R0
  105. mflr r0
  106. ; save return address on stack, set up stack frame
  107. stw r0, 8(r1)
  108. ; allocate stack space, R1 16 == 0
  109. stwu r1, -32(r1)
  110. ; set return value to zero
  111. li r3, 0
  112. ; exit application
  113. bl __exit
  114. nop