setjmp.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. _BEGIN_STD_C
  2. #if defined(__or1k__) || defined(__or1knd__)
  3. #define _JBLEN 31 /* 32 GPRs - r0 */
  4. #define _JBTYPE unsigned long
  5. #endif
  6. #if defined(__arm__) || defined(__thumb__)
  7. /*
  8. * All callee preserved registers:
  9. * v1 - v7, fp, ip, sp, lr, f4, f5, f6, f7
  10. */
  11. #define _JBLEN 23
  12. #endif
  13. #if defined(__aarch64__)
  14. #define _JBLEN 22
  15. #define _JBTYPE long long
  16. #endif
  17. #if defined(__AVR__)
  18. #define _JBLEN 24
  19. #endif
  20. #ifdef __sparc__
  21. /*
  22. * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext).
  23. * All else recovered by under/over(flow) handling.
  24. */
  25. #define _JBLEN 13
  26. #endif
  27. #ifdef __BFIN__
  28. #define _JBLEN 40
  29. #endif
  30. #ifdef __epiphany__
  31. /* All callee preserved registers: r4-r10,fp, sp, lr,r15, r32-r39 */
  32. #define _JBTYPE long long
  33. #define _JBLEN 10
  34. #endif
  35. /* necv70 was 9 as well. */
  36. #if defined(__m68k__) || defined(__mc68000__)
  37. /*
  38. * onsstack,sigmask,sp,pc,psl,d2-d7,a2-a6,
  39. * fp2-fp7 for 68881.
  40. * All else recovered by under/over(flow) handling.
  41. */
  42. #define _JBLEN 34
  43. #endif
  44. #if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__)
  45. /*
  46. * D, X, Y are not saved.
  47. * Only take into account the pseudo soft registers (max 32).
  48. */
  49. #define _JBLEN 32
  50. #endif
  51. #ifdef __nds32__
  52. /* 17 words for GPRs,
  53. 1 word for $fpcfg.freg and 30 words for FPUs
  54. Reserved 2 words for aligement-adjustment. When storeing double-precision
  55. floating-point register into memory, the address has to be
  56. double-word-aligned.
  57. Check libc/machine/nds32/setjmp.S for more information. */
  58. #if __NDS32_EXT_FPU_SP__ || __NDS32_EXT_FPU_DP__
  59. #define _JBLEN 50
  60. #else
  61. #define _JBLEN 18
  62. #endif
  63. #endif
  64. #if defined(__Z8001__) || defined(__Z8002__)
  65. /* 16 regs + pc */
  66. #define _JBLEN 20
  67. #endif
  68. #ifdef _AM29K
  69. /*
  70. * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext).
  71. * All else recovered by under/over(flow) handling.
  72. */
  73. #define _JBLEN 9
  74. #endif
  75. #ifdef __i386__
  76. # if defined(__CYGWIN__) && !defined (_JBLEN)
  77. # define _JBLEN (13 * 4)
  78. # elif defined(__unix__) || defined(__rtems__)
  79. # define _JBLEN 9
  80. # else
  81. # include "setjmp-dj.h"
  82. # endif
  83. #endif
  84. #ifdef __x86_64__
  85. # ifdef __CYGWIN__
  86. # define _JBTYPE long
  87. # define _JBLEN 32
  88. # else
  89. # define _JBTYPE long long
  90. # define _JBLEN 8
  91. # endif
  92. #endif
  93. #ifdef __i960__
  94. #define _JBLEN 35
  95. #endif
  96. #ifdef __M32R__
  97. /* Only 8 words are currently needed. 10 gives us some slop if we need
  98. to expand. */
  99. #define _JBLEN 10
  100. #endif
  101. #ifdef __mips__
  102. # if defined(__mips64)
  103. # define _JBTYPE long long
  104. # endif
  105. # ifdef __mips_soft_float
  106. # define _JBLEN 11
  107. # else
  108. # define _JBLEN 23
  109. # endif
  110. #endif
  111. #ifdef __m88000__
  112. #define _JBLEN 21
  113. #endif
  114. #ifdef __H8300__
  115. #define _JBLEN 5
  116. #define _JBTYPE int
  117. #endif
  118. #ifdef __H8300H__
  119. /* same as H8/300 but registers are twice as big */
  120. #define _JBLEN 5
  121. #define _JBTYPE long
  122. #endif
  123. #if defined (__H8300S__) || defined (__H8300SX__)
  124. /* same as H8/300 but registers are twice as big */
  125. #define _JBLEN 5
  126. #define _JBTYPE long
  127. #endif
  128. #ifdef __H8500__
  129. #define _JBLEN 4
  130. #endif
  131. #ifdef __sh__
  132. #if __SH5__
  133. #define _JBLEN 50
  134. #define _JBTYPE long long
  135. #else
  136. #define _JBLEN 20
  137. #endif /* __SH5__ */
  138. #endif
  139. #ifdef __v800
  140. #define _JBLEN 28
  141. #endif
  142. #ifdef __PPC__
  143. #ifdef __ALTIVEC__
  144. #define _JBLEN 64
  145. #else
  146. #define _JBLEN 32
  147. #endif
  148. #define _JBTYPE double
  149. #endif
  150. #ifdef __MICROBLAZE__
  151. #define _JBLEN 20
  152. #define _JBTYPE unsigned int
  153. #endif
  154. #ifdef __hppa__
  155. /* %r30, %r2-%r18, %r27, pad, %fr12-%fr15.
  156. Note space exists for the FP registers, but they are not
  157. saved. */
  158. #define _JBLEN 28
  159. #endif
  160. #if defined(__mn10300__) || defined(__mn10200__)
  161. #ifdef __AM33_2__
  162. #define _JBLEN 26
  163. #else
  164. /* A guess */
  165. #define _JBLEN 10
  166. #endif
  167. #endif
  168. #ifdef __v850
  169. /* I think our setjmp is saving 15 regs at the moment. Gives us one word
  170. slop if we need to expand. */
  171. #define _JBLEN 16
  172. #endif
  173. #if defined(_C4x)
  174. #define _JBLEN 10
  175. #endif
  176. #if defined(_C3x)
  177. #define _JBLEN 9
  178. #endif
  179. #ifdef __TMS320C6X__
  180. #define _JBLEN 13
  181. #endif
  182. #ifdef __TIC80__
  183. #define _JBLEN 13
  184. #endif
  185. #ifdef __D10V__
  186. #define _JBLEN 8
  187. #endif
  188. #ifdef __D30V__
  189. #define _JBLEN ((64 /* GPR */ + (2*2) /* ACs */ + 18 /* CRs */) / 2)
  190. #define _JBTYPE double
  191. #endif
  192. #ifdef __frv__
  193. #define _JBLEN (68/2) /* room for 68 32-bit regs */
  194. #define _JBTYPE double
  195. #endif
  196. #ifdef __moxie__
  197. #define _JBLEN 16
  198. #endif
  199. #ifdef __CRX__
  200. #define _JBLEN 9
  201. #endif
  202. #if (defined(__CR16__) || defined(__CR16C__) ||defined(__CR16CP__))
  203. /* r6, r7, r8, r9, r10, r11, r12 (r12L, r12H),
  204. * r13 (r13L, r13H), ra(raL, raH), sp(spL, spH) */
  205. #define _JBLEN 14
  206. #define _JBTYPE unsigned short
  207. #endif
  208. #ifdef __fr30__
  209. #define _JBLEN 10
  210. #endif
  211. #ifdef __iq2000__
  212. #define _JBLEN 32
  213. #endif
  214. #ifdef __mcore__
  215. #define _JBLEN 16
  216. #endif
  217. #ifdef __MMIX__
  218. /* Using a layout compatible with GCC's built-in. */
  219. #define _JBLEN 5
  220. #define _JBTYPE unsigned long
  221. #endif
  222. #ifdef __mt__
  223. #define _JBLEN 16
  224. #endif
  225. #ifdef __SPU__
  226. #define _JBLEN 50
  227. #define _JBTYPE __vector signed int
  228. #endif
  229. #ifdef __xstormy16__
  230. /* 4 GPRs plus SP plus PC. */
  231. #define _JBLEN 8
  232. #endif
  233. #ifdef __XTENSA__
  234. #if __XTENSA_WINDOWED_ABI__
  235. /* The jmp_buf structure for Xtensa windowed ABI holds the following
  236. (where "proc" is the procedure that calls setjmp): 4-12 registers
  237. from the window of proc, the 4 words from the save area at proc's $sp
  238. (in case a subsequent alloca in proc moves $sp), and the return
  239. address within proc. Everything else is saved on the stack in the
  240. normal save areas. The jmp_buf structure is:
  241. struct jmp_buf {
  242. int regs[12];
  243. int save[4];
  244. void *return_address;
  245. }
  246. See the setjmp code for details. */
  247. #define _JBLEN 17 /* 12 + 4 + 1 */
  248. #else /* __XTENSA_CALL0_ABI__ */
  249. #define _JBLEN 6 /* a0, a1, a12, a13, a14, a15 */
  250. #endif /* __XTENSA_CALL0_ABI__ */
  251. #endif /* __XTENSA__ */
  252. #ifdef __mep__
  253. /* 16 GPRs, pc, hi, lo */
  254. #define _JBLEN 19
  255. #endif
  256. #ifdef __CRIS__
  257. #define _JBLEN 18
  258. #endif
  259. #ifdef __lm32__
  260. #define _JBLEN 19
  261. #endif
  262. #ifdef __m32c__
  263. #if defined(__r8c_cpu__) || defined(__m16c_cpu__)
  264. #define _JBLEN (22/2)
  265. #else
  266. #define _JBLEN (34/2)
  267. #endif
  268. #define _JBTYPE unsigned short
  269. #endif /* __m32c__ */
  270. #ifdef __MSP430__
  271. #define _JBLEN 9
  272. #ifdef __MSP430X_LARGE__
  273. #define _JBTYPE unsigned long
  274. #else
  275. #define _JBTYPE unsigned short
  276. #endif
  277. #endif
  278. #ifdef __RL78__
  279. /* Three banks of registers, SP, CS, ES, PC */
  280. #define _JBLEN (8*3+8)
  281. #define _JBTYPE unsigned char
  282. #endif
  283. /*
  284. * There are two versions of setjmp()/longjmp():
  285. * 1) Compiler (gcc) built-in versions.
  286. * 2) Function-call versions.
  287. *
  288. * The built-in versions are used most of the time. When used, gcc replaces
  289. * calls to setjmp()/longjmp() with inline assembly code. The built-in
  290. * versions save/restore a variable number of registers.
  291. * _JBLEN is set to 40 to be ultra-safe with the built-in versions.
  292. * It only needs to be 12 for the function-call versions
  293. * but this data structure is used by both versions.
  294. */
  295. #ifdef __NIOS2__
  296. #define _JBLEN 40
  297. #define _JBTYPE unsigned long
  298. #endif
  299. #ifdef __RX__
  300. #define _JBLEN 0x44
  301. #endif
  302. #ifdef _JBLEN
  303. #ifdef _JBTYPE
  304. typedef _JBTYPE jmp_buf[_JBLEN];
  305. #else
  306. typedef int jmp_buf[_JBLEN];
  307. #endif
  308. #endif
  309. _END_STD_C
  310. #if defined(__CYGWIN__) || defined(__rtems__)
  311. #include <signal.h>
  312. #ifdef __cplusplus
  313. extern "C" {
  314. #endif
  315. /* POSIX sigsetjmp/siglongjmp macros */
  316. #ifdef _JBTYPE
  317. typedef _JBTYPE sigjmp_buf[_JBLEN+1+((sizeof (_JBTYPE) + sizeof (sigset_t) - 1)
  318. /sizeof (_JBTYPE))];
  319. #else
  320. typedef int sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (int))];
  321. #endif
  322. #define _SAVEMASK _JBLEN
  323. #define _SIGMASK (_JBLEN+1)
  324. #ifdef __CYGWIN__
  325. # define _CYGWIN_WORKING_SIGSETJMP
  326. #endif
  327. #ifdef _POSIX_THREADS
  328. #define __SIGMASK_FUNC pthread_sigmask
  329. #else
  330. #define __SIGMASK_FUNC sigprocmask
  331. #endif
  332. #if defined(__GNUC__)
  333. #define sigsetjmp(env, savemask) \
  334. __extension__ \
  335. ({ \
  336. sigjmp_buf *_sjbuf = &(env); \
  337. ((*_sjbuf)[_SAVEMASK] = savemask,\
  338. __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *)((*_sjbuf) + _SIGMASK)),\
  339. setjmp (*_sjbuf)); \
  340. })
  341. #define siglongjmp(env, val) \
  342. __extension__ \
  343. ({ \
  344. sigjmp_buf *_sjbuf = &(env); \
  345. ((((*_sjbuf)[_SAVEMASK]) ? \
  346. __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *)((*_sjbuf) + _SIGMASK), 0)\
  347. : 0), \
  348. longjmp (*_sjbuf, val)); \
  349. })
  350. #else /* !__GNUC__ */
  351. #define sigsetjmp(env, savemask) ((env)[_SAVEMASK] = savemask,\
  352. __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *) ((env) + _SIGMASK)),\
  353. setjmp (env))
  354. #define siglongjmp(env, val) ((((env)[_SAVEMASK])?\
  355. __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *) ((env) + _SIGMASK), 0):0),\
  356. longjmp (env, val))
  357. #endif
  358. /* POSIX _setjmp/_longjmp, maintained for XSI compatibility. These
  359. are equivalent to sigsetjmp/siglongjmp when not saving the signal mask.
  360. New applications should use sigsetjmp/siglongjmp instead. */
  361. #ifdef __CYGWIN__
  362. extern void _longjmp(jmp_buf, int);
  363. extern int _setjmp(jmp_buf);
  364. #else
  365. #define _setjmp(env) sigsetjmp ((env), 0)
  366. #define _longjmp(env, val) siglongjmp ((env), (val))
  367. #endif
  368. #ifdef __cplusplus
  369. }
  370. #endif
  371. #endif /* __CYGWIN__ or __rtems__ */