make_ppc32_sysv_elf_gas.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. .type make_fcontext,@function
  78. make_fcontext:
  79. # save return address into R6
  80. mflr %r6
  81. # first arg of make_fcontext() == top address of context-function
  82. # shift address in R3 to lower 16 byte boundary
  83. clrrwi %r3, %r3, 4
  84. # reserve space for context-data on context-stack
  85. # including 64 byte of linkage + parameter area (R1 % 16 == 0)
  86. subi %r3, %r3, 336
  87. # third arg of make_fcontext() == address of context-function
  88. stw %r5, 240(%r3)
  89. # set back-chain to zero
  90. li %r0, 0
  91. stw %r0, 244(%r3)
  92. mffs %f0 # load FPSCR
  93. stfd %f0, 144(%r3) # save FPSCR
  94. # compute address of returned transfer_t
  95. addi %r0, %r3, 252
  96. mr %r4, %r0
  97. stw %r4, 228(%r3)
  98. # load LR
  99. mflr %r0
  100. # jump to label 1
  101. bl 1f
  102. 1:
  103. # load LR into R4
  104. mflr %r4
  105. # compute abs address of label finish
  106. addi %r4, %r4, finish - 1b
  107. # restore LR
  108. mtlr %r0
  109. # save address of finish as return-address for context-function
  110. # will be entered after context-function returns
  111. stw %r4, 236(%r3)
  112. # restore return address from R6
  113. mtlr %r6
  114. blr # return pointer to context-data
  115. finish:
  116. # save return address into R0
  117. mflr %r0
  118. # save return address on stack, set up stack frame
  119. stw %r0, 4(%r1)
  120. # allocate stack space, R1 % 16 == 0
  121. stwu %r1, -16(%r1)
  122. # exit code is zero
  123. li %r3, 0
  124. # exit application
  125. bl _exit@plt
  126. .size make_fcontext, .-make_fcontext
  127. /* Mark that we don't need executable stack. */
  128. .section .note.GNU-stack,"",%progbits