setjmp.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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. # elif defined(__iamcu__)
  81. /* Intel MCU jmp_buf only covers callee-saved registers. */
  82. # define _JBLEN 6
  83. # else
  84. # include "setjmp-dj.h"
  85. # endif
  86. #endif
  87. #ifdef __x86_64__
  88. # ifdef __CYGWIN__
  89. # define _JBTYPE long
  90. # define _JBLEN 32
  91. # else
  92. # define _JBTYPE long long
  93. # define _JBLEN 8
  94. # endif
  95. #endif
  96. #ifdef __i960__
  97. #define _JBLEN 35
  98. #endif
  99. #ifdef __M32R__
  100. /* Only 8 words are currently needed. 10 gives us some slop if we need
  101. to expand. */
  102. #define _JBLEN 10
  103. #endif
  104. #ifdef __mips__
  105. # if defined(__mips64)
  106. # define _JBTYPE long long
  107. # endif
  108. # ifdef __mips_soft_float
  109. # define _JBLEN 11
  110. # else
  111. # define _JBLEN 23
  112. # endif
  113. #endif
  114. #ifdef __m88000__
  115. #define _JBLEN 21
  116. #endif
  117. #ifdef __H8300__
  118. #define _JBLEN 5
  119. #define _JBTYPE int
  120. #endif
  121. #ifdef __H8300H__
  122. /* same as H8/300 but registers are twice as big */
  123. #define _JBLEN 5
  124. #define _JBTYPE long
  125. #endif
  126. #if defined (__H8300S__) || defined (__H8300SX__)
  127. /* same as H8/300 but registers are twice as big */
  128. #define _JBLEN 5
  129. #define _JBTYPE long
  130. #endif
  131. #ifdef __H8500__
  132. #define _JBLEN 4
  133. #endif
  134. #ifdef __sh__
  135. #if __SH5__
  136. #define _JBLEN 50
  137. #define _JBTYPE long long
  138. #else
  139. #define _JBLEN 20
  140. #endif /* __SH5__ */
  141. #endif
  142. #ifdef __v800
  143. #define _JBLEN 28
  144. #endif
  145. #ifdef __PPC__
  146. #ifdef __ALTIVEC__
  147. #define _JBLEN 64
  148. #else
  149. #define _JBLEN 32
  150. #endif
  151. #define _JBTYPE double
  152. #endif
  153. #ifdef __MICROBLAZE__
  154. #define _JBLEN 20
  155. #define _JBTYPE unsigned int
  156. #endif
  157. #ifdef __hppa__
  158. /* %r30, %r2-%r18, %r27, pad, %fr12-%fr15.
  159. Note space exists for the FP registers, but they are not
  160. saved. */
  161. #define _JBLEN 28
  162. #endif
  163. #if defined(__mn10300__) || defined(__mn10200__)
  164. #ifdef __AM33_2__
  165. #define _JBLEN 26
  166. #else
  167. /* A guess */
  168. #define _JBLEN 10
  169. #endif
  170. #endif
  171. #ifdef __v850
  172. /* I think our setjmp is saving 15 regs at the moment. Gives us one word
  173. slop if we need to expand. */
  174. #define _JBLEN 16
  175. #endif
  176. #if defined(_C4x)
  177. #define _JBLEN 10
  178. #endif
  179. #if defined(_C3x)
  180. #define _JBLEN 9
  181. #endif
  182. #ifdef __TMS320C6X__
  183. #define _JBLEN 13
  184. #endif
  185. #ifdef __TIC80__
  186. #define _JBLEN 13
  187. #endif
  188. #ifdef __D10V__
  189. #define _JBLEN 8
  190. #endif
  191. #ifdef __D30V__
  192. #define _JBLEN ((64 /* GPR */ + (2*2) /* ACs */ + 18 /* CRs */) / 2)
  193. #define _JBTYPE double
  194. #endif
  195. #ifdef __frv__
  196. #define _JBLEN (68/2) /* room for 68 32-bit regs */
  197. #define _JBTYPE double
  198. #endif
  199. #ifdef __moxie__
  200. #define _JBLEN 16
  201. #endif
  202. #ifdef __CRX__
  203. #define _JBLEN 9
  204. #endif
  205. #if (defined(__CR16__) || defined(__CR16C__) ||defined(__CR16CP__))
  206. /* r6, r7, r8, r9, r10, r11, r12 (r12L, r12H),
  207. * r13 (r13L, r13H), ra(raL, raH), sp(spL, spH) */
  208. #define _JBLEN 14
  209. #define _JBTYPE unsigned short
  210. #endif
  211. #ifdef __fr30__
  212. #define _JBLEN 10
  213. #endif
  214. #ifdef __FT32__
  215. #define _JBLEN 27
  216. #endif
  217. #ifdef __iq2000__
  218. #define _JBLEN 32
  219. #endif
  220. #ifdef __mcore__
  221. #define _JBLEN 16
  222. #endif
  223. #ifdef __arc__
  224. #define _JBLEN 25 /* r13-r30,blink,lp_count,lp_start,lp_end,mlo,mhi,status32 */
  225. #endif
  226. #ifdef __MMIX__
  227. /* Using a layout compatible with GCC's built-in. */
  228. #define _JBLEN 5
  229. #define _JBTYPE unsigned long
  230. #endif
  231. #ifdef __mt__
  232. #define _JBLEN 16
  233. #endif
  234. #ifdef __SPU__
  235. #define _JBLEN 50
  236. #define _JBTYPE __vector signed int
  237. #endif
  238. #ifdef __xstormy16__
  239. /* 4 GPRs plus SP plus PC. */
  240. #define _JBLEN 8
  241. #endif
  242. #ifdef __mep__
  243. /* 16 GPRs, pc, hi, lo */
  244. #define _JBLEN 19
  245. #endif
  246. #ifdef __CRIS__
  247. #define _JBLEN 18
  248. #endif
  249. #ifdef __ia64
  250. #define _JBLEN 64
  251. #endif
  252. #ifdef __lm32__
  253. #define _JBLEN 19
  254. #endif
  255. #ifdef __m32c__
  256. #if defined(__r8c_cpu__) || defined(__m16c_cpu__)
  257. #define _JBLEN (22/2)
  258. #else
  259. #define _JBLEN (34/2)
  260. #endif
  261. #define _JBTYPE unsigned short
  262. #endif /* __m32c__ */
  263. #ifdef __MSP430__
  264. #define _JBLEN 9
  265. #ifdef __MSP430X_LARGE__
  266. #define _JBTYPE unsigned long
  267. #else
  268. #define _JBTYPE unsigned short
  269. #endif
  270. #endif
  271. #ifdef __RL78__
  272. /* Three banks of registers, SP, CS, ES, PC */
  273. #define _JBLEN (8*3+8)
  274. #define _JBTYPE unsigned char
  275. #endif
  276. /*
  277. * There are two versions of setjmp()/longjmp():
  278. * 1) Compiler (gcc) built-in versions.
  279. * 2) Function-call versions.
  280. *
  281. * The built-in versions are used most of the time. When used, gcc replaces
  282. * calls to setjmp()/longjmp() with inline assembly code. The built-in
  283. * versions save/restore a variable number of registers.
  284. * _JBLEN is set to 40 to be ultra-safe with the built-in versions.
  285. * It only needs to be 12 for the function-call versions
  286. * but this data structure is used by both versions.
  287. */
  288. #ifdef __NIOS2__
  289. #define _JBLEN 40
  290. #define _JBTYPE unsigned long
  291. #endif
  292. #ifdef __RX__
  293. #define _JBLEN 0x44
  294. #endif
  295. #ifdef __VISIUM__
  296. /* All call-saved GP registers: r11-r19,r21,r22,r23. */
  297. #define _JBLEN 12
  298. #endif
  299. #ifdef __riscv
  300. /* _JBTYPE using long long to make sure the alignment is align to 8 byte,
  301. otherwise in rv32imafd, store/restore FPR may mis-align. */
  302. #define _JBTYPE long long
  303. #ifdef __riscv_32e
  304. #define _JBLEN ((4*sizeof(long))/sizeof(long))
  305. #else
  306. #define _JBLEN ((14*sizeof(long) + 12*sizeof(double))/sizeof(long))
  307. #endif
  308. #endif
  309. #ifdef _JBLEN
  310. #ifdef _JBTYPE
  311. typedef _JBTYPE jmp_buf[_JBLEN];
  312. #else
  313. typedef int jmp_buf[_JBLEN];
  314. #endif
  315. #endif
  316. _END_STD_C
  317. #if (defined(__CYGWIN__) || defined(__rtems__)) && __POSIX_VISIBLE
  318. #include <signal.h>
  319. #ifdef __cplusplus
  320. extern "C" {
  321. #endif
  322. /* POSIX sigsetjmp/siglongjmp macros */
  323. #ifdef _JBTYPE
  324. typedef _JBTYPE sigjmp_buf[_JBLEN+1+((sizeof (_JBTYPE) + sizeof (sigset_t) - 1)
  325. /sizeof (_JBTYPE))];
  326. #else
  327. typedef int sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (int))];
  328. #endif
  329. #define _SAVEMASK _JBLEN
  330. #define _SIGMASK (_JBLEN+1)
  331. #ifdef __CYGWIN__
  332. # define _CYGWIN_WORKING_SIGSETJMP
  333. #endif
  334. #ifdef _POSIX_THREADS
  335. #define __SIGMASK_FUNC pthread_sigmask
  336. #else
  337. #define __SIGMASK_FUNC sigprocmask
  338. #endif
  339. #ifdef __CYGWIN__
  340. /* Per POSIX, siglongjmp has to be implemented as function. Cygwin
  341. provides functions for both, siglongjmp and sigsetjmp since 2.2.0. */
  342. extern void siglongjmp (sigjmp_buf, int) __attribute__ ((__noreturn__));
  343. extern int sigsetjmp (sigjmp_buf, int);
  344. #endif
  345. #if defined(__GNUC__)
  346. #define sigsetjmp(env, savemask) \
  347. __extension__ \
  348. ({ \
  349. sigjmp_buf *_sjbuf = &(env); \
  350. ((*_sjbuf)[_SAVEMASK] = savemask,\
  351. __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *)((*_sjbuf) + _SIGMASK)),\
  352. setjmp (*_sjbuf)); \
  353. })
  354. #define siglongjmp(env, val) \
  355. __extension__ \
  356. ({ \
  357. sigjmp_buf *_sjbuf = &(env); \
  358. ((((*_sjbuf)[_SAVEMASK]) ? \
  359. __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *)((*_sjbuf) + _SIGMASK), 0)\
  360. : 0), \
  361. longjmp (*_sjbuf, val)); \
  362. })
  363. #else /* !__GNUC__ */
  364. #define sigsetjmp(env, savemask) ((env)[_SAVEMASK] = savemask,\
  365. __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *) ((env) + _SIGMASK)),\
  366. setjmp (env))
  367. #define siglongjmp(env, val) ((((env)[_SAVEMASK])?\
  368. __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *) ((env) + _SIGMASK), 0):0),\
  369. longjmp (env, val))
  370. #endif
  371. /* POSIX _setjmp/_longjmp, maintained for XSI compatibility. These
  372. are equivalent to sigsetjmp/siglongjmp when not saving the signal mask.
  373. New applications should use sigsetjmp/siglongjmp instead. */
  374. #ifdef __CYGWIN__
  375. extern void _longjmp (jmp_buf, int) __attribute__ ((__noreturn__));
  376. extern int _setjmp (jmp_buf);
  377. #else
  378. #define _setjmp(env) sigsetjmp ((env), 0)
  379. #define _longjmp(env, val) siglongjmp ((env), (val))
  380. #endif
  381. #ifdef __cplusplus
  382. }
  383. #endif
  384. #endif /* (__CYGWIN__ or __rtems__) and __POSIX_VISIBLE */