make_ppc32_sysv_macho_gas.S 5.3 KB

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