makecontext.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* Modify saved context.
  2. Copyright (C) 2009 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Maciej W. Rozycki <macro@codesourcery.com>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library. If not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <sysdep.h>
  17. #include <sys/asm.h>
  18. #include <sys/fpregdef.h>
  19. #include <sys/regdef.h>
  20. #include "ucontext_i.h"
  21. /* int makecontext (ucontext_t *ucp, (void *func) (), int argc, ...) */
  22. .text
  23. LOCALSZ = 0
  24. ARGSZ = 0
  25. MASK = 0x00000000
  26. #ifdef __PIC__
  27. LOCALSZ = 1 /* save gp */
  28. #endif
  29. #if _MIPS_SIM != _ABIO32
  30. ARGSZ = 5 /* save a3-a7 */
  31. # ifdef __PIC__
  32. MASK = 0x10000000
  33. # endif
  34. #endif
  35. FRAMESZ = (((ARGSZ + LOCALSZ) * SZREG) + ALSZ) & ALMASK
  36. GPOFF = FRAMESZ - ((ARGSZ + 1) * SZREG)
  37. #if _MIPS_SIM != _ABIO32
  38. A3OFF = FRAMESZ - (5 * SZREG) /* callee-allocated */
  39. A4OFF = FRAMESZ - (4 * SZREG)
  40. A5OFF = FRAMESZ - (3 * SZREG)
  41. A6OFF = FRAMESZ - (2 * SZREG)
  42. A7OFF = FRAMESZ - (1 * SZREG)
  43. NARGREGS = 8
  44. #else
  45. A3OFF = FRAMESZ + (3 * SZREG) /* caller-allocated */
  46. NARGREGS = 4
  47. #endif
  48. NESTED (__makecontext, FRAMESZ, ra)
  49. .mask MASK, -(ARGSZ * SZREG)
  50. .fmask 0x00000000, 0
  51. 98:
  52. #ifdef __PIC__
  53. SETUP_GP
  54. #endif
  55. PTR_ADDIU sp, -FRAMESZ
  56. #ifdef __PIC__
  57. SETUP_GP64 (GPOFF, __makecontext)
  58. SAVE_GP (GPOFF)
  59. #endif
  60. /* Store args to be passed. */
  61. REG_S a3, A3OFF(sp)
  62. #if _MIPS_SIM != _ABIO32
  63. REG_S a4, A4OFF(sp)
  64. REG_S a5, A5OFF(sp)
  65. REG_S a6, A6OFF(sp)
  66. REG_S a7, A7OFF(sp)
  67. #endif
  68. /* Store a magic flag. */
  69. li v1, 1
  70. REG_S v1, (0 * SZREG + MCONTEXT_GREGS)(a0) /* zero */
  71. /* Set up the stack. */
  72. PTR_L t0, STACK_SP(a0)
  73. PTR_L t2, STACK_SIZE(a0)
  74. PTR_ADDIU t1, sp, A3OFF
  75. PTR_ADDU t0, t2
  76. and t0, ALMASK
  77. blez a2, 2f /* no arguments */
  78. /* Store register arguments. */
  79. PTR_ADDIU t2, a0, MCONTEXT_GREGS + 4 * SZREG
  80. move t3, zero
  81. 0:
  82. addiu t3, 1
  83. REG_L v1, (t1)
  84. PTR_ADDIU t1, SZREG
  85. REG_S v1, (t2)
  86. PTR_ADDIU t2, SZREG
  87. bgeu t3, a2, 2f /* all done */
  88. bltu t3, NARGREGS, 0b /* next */
  89. /* Make room for stack arguments. */
  90. PTR_SUBU t2, a2, t3
  91. PTR_SLL t2, 3
  92. PTR_SUBU t0, t2
  93. and t0, ALMASK
  94. /* Store stack arguments. */
  95. move t2, t0
  96. 1:
  97. addiu t3, 1
  98. REG_L v1, (t1)
  99. PTR_ADDIU t1, SZREG
  100. REG_S v1, (t2)
  101. PTR_ADDIU t2, SZREG
  102. bltu t3, a2, 1b /* next */
  103. 2:
  104. #if _MIPS_SIM == _ABIO32
  105. /* Make room for a0-a3 storage. */
  106. PTR_ADDIU t0, -(NARGSAVE * SZREG)
  107. #endif
  108. PTR_L v1, UCONTEXT_LINK(a0)
  109. #ifdef __PIC__
  110. PTR_ADDIU t9, 99f - 98b
  111. #else
  112. PTR_LA t9, 99f
  113. #endif
  114. REG_S t0, (29 * SZREG + MCONTEXT_GREGS)(a0) /* sp */
  115. REG_S v1, (16 * SZREG + MCONTEXT_GREGS)(a0) /* s0 */
  116. #ifdef __PIC__
  117. REG_S gp, (17 * SZREG + MCONTEXT_GREGS)(a0) /* s1 */
  118. #endif
  119. REG_S t9, (31 * SZREG + MCONTEXT_GREGS)(a0) /* ra */
  120. REG_S a1, MCONTEXT_PC(a0)
  121. #ifdef __PIC__
  122. RESTORE_GP64
  123. PTR_ADDIU sp, FRAMESZ
  124. #endif
  125. jr ra
  126. 99:
  127. #ifdef __PIC__
  128. move gp, s1
  129. #endif
  130. move a0, zero
  131. beqz s0, 0f
  132. /* setcontext (ucp) */
  133. move a0, s0
  134. #ifdef __PIC__
  135. PTR_LA t9, JUMPTARGET (__setcontext)
  136. jalr t9
  137. # if _MIPS_SIM == _ABIO32
  138. move gp, s1
  139. # endif
  140. #else
  141. jal JUMPTARGET (__setcontext)
  142. #endif
  143. move a0, v0
  144. 0:
  145. /* exit (a0) */
  146. #ifdef __PIC__
  147. PTR_LA t9, HIDDEN_JUMPTARGET (exit)
  148. jalr t9
  149. #else
  150. jal HIDDEN_JUMPTARGET (exit)
  151. #endif
  152. /* You don't exist, you won't feel anything. */
  153. 1:
  154. lb zero, (zero)
  155. b 1b
  156. PSEUDO_END (__makecontext)
  157. weak_alias (__makecontext, makecontext)