libunwind.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /* Support functions for the unwinder.
  2. Copyright (C) 2003-2022 Free Software Foundation, Inc.
  3. Contributed by Paul Brook
  4. This file is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 3, or (at your option) any
  7. later version.
  8. This file is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* An executable stack is *not* required for these functions. */
  20. #if defined(__ELF__) && defined(__linux__)
  21. .section .note.GNU-stack,"",%progbits
  22. .previous
  23. #endif
  24. #ifdef __ARM_EABI__
  25. /* Some attributes that are common to all routines in this file. */
  26. /* Tag_ABI_align_needed: This code does not require 8-byte
  27. alignment from the caller. */
  28. /* .eabi_attribute 24, 0 -- default setting. */
  29. /* Tag_ABI_align_preserved: This code preserves 8-byte
  30. alignment in any callee. */
  31. .eabi_attribute 25, 1
  32. #endif /* __ARM_EABI__ */
  33. #ifndef __symbian__
  34. #include "lib1funcs.S"
  35. .macro UNPREFIX name
  36. .global SYM (\name)
  37. EQUIV SYM (\name), SYM (__\name)
  38. .endm
  39. #if (__ARM_ARCH == 4)
  40. /* Some coprocessors require armv5t. We know this code will never be run on
  41. other cpus. Tell gas to allow armv5t, but only mark the objects as armv4.
  42. */
  43. .arch armv5t
  44. #ifdef __ARM_ARCH_4T__
  45. .object_arch armv4t
  46. #else
  47. .object_arch armv4
  48. #endif
  49. #endif
  50. #if !__ARM_ARCH_ISA_ARM && __ARM_ARCH_ISA_THUMB == 1
  51. /* r0 points to a 16-word block. Upload these values to the actual core
  52. state. */
  53. FUNC_START restore_core_regs
  54. movs r1, r0
  55. adds r1, r1, #52
  56. ldmia r1!, {r3, r4, r5}
  57. subs r3, r3, #4
  58. mov ip, r3
  59. str r5, [r3]
  60. mov lr, r4
  61. /* Restore r8-r11. */
  62. movs r1, r0
  63. adds r1, r1, #32
  64. ldmia r1!, {r2, r3, r4, r5}
  65. mov r8, r2
  66. mov r9, r3
  67. mov sl, r4
  68. mov fp, r5
  69. movs r1, r0
  70. adds r1, r1, #8
  71. ldmia r1!, {r2, r3, r4, r5, r6, r7}
  72. ldr r1, [r0, #4]
  73. ldr r0, [r0]
  74. mov sp, ip
  75. pop {pc}
  76. FUNC_END restore_core_regs
  77. UNPREFIX restore_core_regs
  78. /* ARMV6M does not have coprocessors, so these should never be used. */
  79. FUNC_START gnu_Unwind_Restore_VFP
  80. RET
  81. /* Store VFR regsters d0-d15 to the address in r0. */
  82. FUNC_START gnu_Unwind_Save_VFP
  83. RET
  84. /* Load VFP registers d0-d15 from the address in r0.
  85. Use this to load from FSTMD format. */
  86. FUNC_START gnu_Unwind_Restore_VFP_D
  87. RET
  88. /* Store VFP registers d0-d15 to the address in r0.
  89. Use this to store in FLDMD format. */
  90. FUNC_START gnu_Unwind_Save_VFP_D
  91. RET
  92. /* Load VFP registers d16-d31 from the address in r0.
  93. Use this to load from FSTMD (=VSTM) format. Needs VFPv3. */
  94. FUNC_START gnu_Unwind_Restore_VFP_D_16_to_31
  95. RET
  96. /* Store VFP registers d16-d31 to the address in r0.
  97. Use this to store in FLDMD (=VLDM) format. Needs VFPv3. */
  98. FUNC_START gnu_Unwind_Save_VFP_D_16_to_31
  99. RET
  100. FUNC_START gnu_Unwind_Restore_WMMXD
  101. RET
  102. FUNC_START gnu_Unwind_Save_WMMXD
  103. RET
  104. FUNC_START gnu_Unwind_Restore_WMMXC
  105. RET
  106. FUNC_START gnu_Unwind_Save_WMMXC
  107. RET
  108. .macro UNWIND_WRAPPER name nargs
  109. FUNC_START \name
  110. /* Create a phase2_vrs structure. */
  111. /* Save r0 in the PC slot so we can use it as a scratch register. */
  112. push {r0}
  113. add r0, sp, #4
  114. push {r0, lr} /* Push original SP and LR. */
  115. /* Make space for r8-r12. */
  116. sub sp, sp, #20
  117. /* Save low registers. */
  118. push {r0, r1, r2, r3, r4, r5, r6, r7}
  119. /* Save high registers. */
  120. add r0, sp, #32
  121. mov r1, r8
  122. mov r2, r9
  123. mov r3, sl
  124. mov r4, fp
  125. mov r5, ip
  126. stmia r0!, {r1, r2, r3, r4, r5}
  127. /* Restore original low register values. */
  128. add r0, sp, #4
  129. ldmia r0!, {r1, r2, r3, r4, r5}
  130. /* Restore orginial r0. */
  131. ldr r0, [sp, #60]
  132. str r0, [sp]
  133. /* Demand-save flags, plus an extra word for alignment. */
  134. movs r3, #0
  135. push {r2, r3}
  136. /* Point r1 at the block. Pass r[0..nargs) unchanged. */
  137. add r\nargs, sp, #4
  138. bl SYM (__gnu\name)
  139. ldr r3, [sp, #64]
  140. add sp, sp, #72
  141. bx r3
  142. FUNC_END \name
  143. UNPREFIX \name
  144. .endm
  145. #else /* __ARM_ARCH_ISA_ARM || __ARM_ARCH_ISA_THUMB != 1 */
  146. /* r0 points to a 16-word block. Upload these values to the actual core
  147. state. */
  148. ARM_FUNC_START restore_core_regs
  149. /* We must use sp as the base register when restoring sp. Push the
  150. last 3 registers onto the top of the current stack to achieve
  151. this. */
  152. add r1, r0, #52
  153. ldmia r1, {r3, r4, r5} /* {sp, lr, pc}. */
  154. #if defined(__thumb2__)
  155. /* Thumb-2 doesn't allow sp in a load-multiple instruction, so push
  156. the target address onto the target stack. This is safe as
  157. we're always returning to somewhere further up the call stack. */
  158. mov ip, r3
  159. mov lr, r4
  160. str r5, [ip, #-4]!
  161. #elif defined(__INTERWORKING__)
  162. /* Restore pc into ip. */
  163. mov r2, r5
  164. stmfd sp!, {r2, r3, r4}
  165. #else
  166. stmfd sp!, {r3, r4, r5}
  167. #endif
  168. /* Don't bother restoring ip. */
  169. ldmia r0, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, sl, fp}
  170. #if defined(__thumb2__)
  171. /* Pop the return address off the target stack. */
  172. mov sp, ip
  173. pop {pc}
  174. #elif defined(__INTERWORKING__)
  175. /* Pop the three registers we pushed earlier. */
  176. ldmfd sp, {ip, sp, lr}
  177. bx ip
  178. #else
  179. ldmfd sp, {sp, lr, pc}
  180. #endif
  181. FUNC_END restore_core_regs
  182. UNPREFIX restore_core_regs
  183. /* Load VFP registers d0-d15 from the address in r0.
  184. Use this to load from FSTMX format. */
  185. ARM_FUNC_START gnu_Unwind_Restore_VFP
  186. /* Use the generic coprocessor form so that gas doesn't complain
  187. on soft-float targets. */
  188. ldc p11,cr0,[r0],{0x21} /* fldmiax r0, {d0-d15} */
  189. RET
  190. /* Store VFP registers d0-d15 to the address in r0.
  191. Use this to store in FSTMX format. */
  192. ARM_FUNC_START gnu_Unwind_Save_VFP
  193. /* Use the generic coprocessor form so that gas doesn't complain
  194. on soft-float targets. */
  195. stc p11,cr0,[r0],{0x21} /* fstmiax r0, {d0-d15} */
  196. RET
  197. /* Load VFP registers d0-d15 from the address in r0.
  198. Use this to load from FSTMD format. */
  199. ARM_FUNC_START gnu_Unwind_Restore_VFP_D
  200. ldc p11,cr0,[r0],{0x20} /* fldmiad r0, {d0-d15} */
  201. RET
  202. /* Store VFP registers d0-d15 to the address in r0.
  203. Use this to store in FLDMD format. */
  204. ARM_FUNC_START gnu_Unwind_Save_VFP_D
  205. stc p11,cr0,[r0],{0x20} /* fstmiad r0, {d0-d15} */
  206. RET
  207. /* Load VFP registers d16-d31 from the address in r0.
  208. Use this to load from FSTMD (=VSTM) format. Needs VFPv3. */
  209. ARM_FUNC_START gnu_Unwind_Restore_VFP_D_16_to_31
  210. ldcl p11,cr0,[r0],{0x20} /* vldm r0, {d16-d31} */
  211. RET
  212. /* Store VFP registers d16-d31 to the address in r0.
  213. Use this to store in FLDMD (=VLDM) format. Needs VFPv3. */
  214. ARM_FUNC_START gnu_Unwind_Save_VFP_D_16_to_31
  215. stcl p11,cr0,[r0],{0x20} /* vstm r0, {d16-d31} */
  216. RET
  217. ARM_FUNC_START gnu_Unwind_Restore_WMMXD
  218. /* Use the generic coprocessor form so that gas doesn't complain
  219. on non-iWMMXt targets. */
  220. ldcl p1, cr0, [r0], #8 /* wldrd wr0, [r0], #8 */
  221. ldcl p1, cr1, [r0], #8 /* wldrd wr1, [r0], #8 */
  222. ldcl p1, cr2, [r0], #8 /* wldrd wr2, [r0], #8 */
  223. ldcl p1, cr3, [r0], #8 /* wldrd wr3, [r0], #8 */
  224. ldcl p1, cr4, [r0], #8 /* wldrd wr4, [r0], #8 */
  225. ldcl p1, cr5, [r0], #8 /* wldrd wr5, [r0], #8 */
  226. ldcl p1, cr6, [r0], #8 /* wldrd wr6, [r0], #8 */
  227. ldcl p1, cr7, [r0], #8 /* wldrd wr7, [r0], #8 */
  228. ldcl p1, cr8, [r0], #8 /* wldrd wr8, [r0], #8 */
  229. ldcl p1, cr9, [r0], #8 /* wldrd wr9, [r0], #8 */
  230. ldcl p1, cr10, [r0], #8 /* wldrd wr10, [r0], #8 */
  231. ldcl p1, cr11, [r0], #8 /* wldrd wr11, [r0], #8 */
  232. ldcl p1, cr12, [r0], #8 /* wldrd wr12, [r0], #8 */
  233. ldcl p1, cr13, [r0], #8 /* wldrd wr13, [r0], #8 */
  234. ldcl p1, cr14, [r0], #8 /* wldrd wr14, [r0], #8 */
  235. ldcl p1, cr15, [r0], #8 /* wldrd wr15, [r0], #8 */
  236. RET
  237. ARM_FUNC_START gnu_Unwind_Save_WMMXD
  238. /* Use the generic coprocessor form so that gas doesn't complain
  239. on non-iWMMXt targets. */
  240. stcl p1, cr0, [r0], #8 /* wstrd wr0, [r0], #8 */
  241. stcl p1, cr1, [r0], #8 /* wstrd wr1, [r0], #8 */
  242. stcl p1, cr2, [r0], #8 /* wstrd wr2, [r0], #8 */
  243. stcl p1, cr3, [r0], #8 /* wstrd wr3, [r0], #8 */
  244. stcl p1, cr4, [r0], #8 /* wstrd wr4, [r0], #8 */
  245. stcl p1, cr5, [r0], #8 /* wstrd wr5, [r0], #8 */
  246. stcl p1, cr6, [r0], #8 /* wstrd wr6, [r0], #8 */
  247. stcl p1, cr7, [r0], #8 /* wstrd wr7, [r0], #8 */
  248. stcl p1, cr8, [r0], #8 /* wstrd wr8, [r0], #8 */
  249. stcl p1, cr9, [r0], #8 /* wstrd wr9, [r0], #8 */
  250. stcl p1, cr10, [r0], #8 /* wstrd wr10, [r0], #8 */
  251. stcl p1, cr11, [r0], #8 /* wstrd wr11, [r0], #8 */
  252. stcl p1, cr12, [r0], #8 /* wstrd wr12, [r0], #8 */
  253. stcl p1, cr13, [r0], #8 /* wstrd wr13, [r0], #8 */
  254. stcl p1, cr14, [r0], #8 /* wstrd wr14, [r0], #8 */
  255. stcl p1, cr15, [r0], #8 /* wstrd wr15, [r0], #8 */
  256. RET
  257. ARM_FUNC_START gnu_Unwind_Restore_WMMXC
  258. /* Use the generic coprocessor form so that gas doesn't complain
  259. on non-iWMMXt targets. */
  260. ldc2 p1, cr8, [r0], #4 /* wldrw wcgr0, [r0], #4 */
  261. ldc2 p1, cr9, [r0], #4 /* wldrw wcgr1, [r0], #4 */
  262. ldc2 p1, cr10, [r0], #4 /* wldrw wcgr2, [r0], #4 */
  263. ldc2 p1, cr11, [r0], #4 /* wldrw wcgr3, [r0], #4 */
  264. RET
  265. ARM_FUNC_START gnu_Unwind_Save_WMMXC
  266. /* Use the generic coprocessor form so that gas doesn't complain
  267. on non-iWMMXt targets. */
  268. stc2 p1, cr8, [r0], #4 /* wstrw wcgr0, [r0], #4 */
  269. stc2 p1, cr9, [r0], #4 /* wstrw wcgr1, [r0], #4 */
  270. stc2 p1, cr10, [r0], #4 /* wstrw wcgr2, [r0], #4 */
  271. stc2 p1, cr11, [r0], #4 /* wstrw wcgr3, [r0], #4 */
  272. RET
  273. /* Wrappers to save core registers, then call the real routine. */
  274. .macro UNWIND_WRAPPER name nargs
  275. ARM_FUNC_START \name
  276. /* Create a phase2_vrs structure. */
  277. /* Split reg push in two to ensure the correct value for sp. */
  278. #if defined(__thumb2__)
  279. mov ip, sp
  280. push {lr} /* PC is ignored. */
  281. push {ip, lr} /* Push original SP and LR. */
  282. #else
  283. stmfd sp!, {sp, lr, pc}
  284. #endif
  285. stmfd sp!, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, sl, fp, ip}
  286. /* Demand-save flags, plus an extra word for alignment. */
  287. mov r3, #0
  288. stmfd sp!, {r2, r3}
  289. /* Point r1 at the block. Pass r[0..nargs) unchanged. */
  290. add r\nargs, sp, #4
  291. #if defined(__thumb__) && !defined(__thumb2__)
  292. /* Switch back to thumb mode to avoid interworking hassle. */
  293. adr ip, .L1_\name
  294. orr ip, ip, #1
  295. bx ip
  296. .thumb
  297. .L1_\name:
  298. bl SYM (__gnu\name) __PLT__
  299. ldr r3, [sp, #64]
  300. add sp, #72
  301. bx r3
  302. #else
  303. bl SYM (__gnu\name) __PLT__
  304. ldr lr, [sp, #64]
  305. add sp, sp, #72
  306. RET
  307. #endif
  308. FUNC_END \name
  309. UNPREFIX \name
  310. .endm
  311. #endif /* __ARM_ARCH_ISA_ARM || __ARM_ARCH_ISA_THUMB != 1 */
  312. UNWIND_WRAPPER _Unwind_RaiseException 1
  313. UNWIND_WRAPPER _Unwind_Resume 1
  314. UNWIND_WRAPPER _Unwind_Resume_or_Rethrow 1
  315. UNWIND_WRAPPER _Unwind_ForcedUnwind 3
  316. UNWIND_WRAPPER _Unwind_Backtrace 2
  317. #endif /* ndef __symbian__ */