1 /*
2 Copyright (C) 1991 DJ Delorie
3 All rights reserved.
4 
5 Redistribution, modification, and use in source and binary forms is permitted
6 provided that the above copyright notice and following paragraph are
7 duplicated in all such forms.
8 
9 This file is distributed WITHOUT ANY WARRANTY; without even the implied
10 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 #include <sys/cdefs.h>
14 
15 _BEGIN_STD_C
16 
17 #if defined(__or1k__) || defined(__or1knd__)
18 /*
19  * r1, r2, r9, r14, r16 .. r30, SR.
20  */
21 #define _JBLEN 13
22 #define _JBTYPE unsigned long
23 #endif
24 
25 #if defined(__arm__) || defined(__thumb__)
26 /*
27  * All callee preserved registers:
28  *  core registers:
29  *   r4 - r10, fp, sp, lr
30  *  VFP registers (architectural support dependent):
31  *   d8 - d15
32  */
33 #define _JBLEN 20
34 #define _JBTYPE long long
35 #endif
36 
37 #if defined(__aarch64__)
38 #define _JBLEN 22
39 #define _JBTYPE long long
40 #endif
41 
42 #if defined(__AVR__)
43 #define _JBLEN 24
44 #endif
45 
46 #ifdef __sparc__
47 /*
48  * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext).
49  * All else recovered by under/over(flow) handling.
50  */
51 #define	_JBLEN	13
52 #endif
53 
54 #ifdef __BFIN__
55 #define _JBLEN  40
56 #endif
57 
58 #ifdef __epiphany__
59 /* All callee preserved registers: r4-r10,fp, sp, lr,r15, r32-r39  */
60 #define _JBTYPE long long
61 #define _JBLEN 10
62 #endif
63 
64 /* necv70 was 9 as well. */
65 
66 #if defined(__m68k__) || defined(__mc68000__)
67 /*
68  * onsstack,sigmask,sp,pc,psl,d2-d7,a2-a6,
69  * fp2-fp7	for 68881.
70  * All else recovered by under/over(flow) handling.
71  */
72 #define	_JBLEN	34
73 #endif
74 
75 #if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__)
76 /*
77  * D, X, Y are not saved.
78  * Only take into account the pseudo soft registers (max 32).
79  */
80 #define _JBLEN  32
81 #endif
82 
83 #ifdef __nds32__
84 /* 17 words for GPRs,
85    1 word for $fpcfg.freg and 30 words for FPUs
86    Reserved 2 words for aligement-adjustment. When storeing double-precision
87    floating-point register into memory, the address has to be
88    double-word-aligned.
89    Check libc/machine/nds32/setjmp.S for more information.  */
90 #if __NDS32_EXT_FPU_SP__ || __NDS32_EXT_FPU_DP__
91 #define	_JBLEN 50
92 #else
93 #define _JBLEN 18
94 #endif
95 #endif
96 
97 #if defined(__Z8001__) || defined(__Z8002__)
98 /* 16 regs + pc */
99 #define _JBLEN 20
100 #endif
101 
102 #ifdef _AM29K
103 /*
104  * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext).
105  * All else recovered by under/over(flow) handling.
106  */
107 #define	_JBLEN	9
108 #endif
109 
110 #ifdef __i386__
111 # if defined(__iamcu__)
112 /* Intel MCU jmp_buf only covers callee-saved registers. */
113 #  define _JBLEN	6
114 # else
115 #  define _JBLEN	9
116 # endif
117 #endif
118 
119 #ifdef __x86_64__
120 #  define _JBTYPE long long
121 #  define _JBLEN  8
122 #endif
123 
124 #ifdef __i960__
125 #define _JBLEN 35
126 #endif
127 
128 #ifdef __M32R__
129 /* Only 8 words are currently needed.  10 gives us some slop if we need
130    to expand.  */
131 #define _JBLEN 10
132 #endif
133 
134 #ifdef __mips__
135 # if defined(__mips64)
136 #  define _JBTYPE long long
137 # endif
138 # ifdef __mips_soft_float
139 #  define _JBLEN 11
140 # else
141 #  define _JBLEN 23
142 # endif
143 #endif
144 
145 #ifdef __m88000__
146 #define _JBLEN 21
147 #endif
148 
149 #ifdef __H8300__
150 #define _JBLEN 5
151 #define _JBTYPE int
152 #endif
153 
154 #ifdef __H8300H__
155 /* same as H8/300 but registers are twice as big */
156 #define _JBLEN 5
157 #define _JBTYPE long
158 #endif
159 
160 #if defined (__H8300S__) || defined (__H8300SX__)
161 /* same as H8/300 but registers are twice as big */
162 #define _JBLEN 5
163 #define _JBTYPE long
164 #endif
165 
166 #ifdef __H8500__
167 #define _JBLEN 4
168 #endif
169 
170 #ifdef  __sh__
171 #if __SH5__
172 #define _JBLEN 50
173 #define _JBTYPE long long
174 #else
175 #define _JBLEN 20
176 #endif /* __SH5__ */
177 #endif
178 
179 #ifdef  __v800
180 #define _JBLEN 28
181 #endif
182 
183 #ifdef __PPC__
184 #ifdef __powerpc64__
185 #ifdef __ALTIVEC__
186 #define _JBLEN 70
187 #else
188 #define _JBLEN 43
189 #endif
190 #else
191 #ifdef __ALTIVEC__
192 #define _JBLEN 64
193 #else
194 #define _JBLEN 32
195 #endif
196 #endif
197 #define _JBTYPE double
198 #endif
199 
200 #ifdef __MICROBLAZE__
201 #define _JBLEN  20
202 #define _JBTYPE unsigned int
203 #endif
204 
205 #ifdef __hppa__
206 /* %r30, %r2-%r18, %r27, pad, %fr12-%fr15.
207    Note space exists for the FP registers, but they are not
208    saved.  */
209 #define _JBLEN 28
210 #endif
211 
212 #if defined(__mn10300__) || defined(__mn10200__)
213 #ifdef __AM33_2__
214 #define _JBLEN 26
215 #else
216 /* A guess */
217 #define _JBLEN 10
218 #endif
219 #endif
220 
221 #ifdef __v850
222 /* I think our setjmp is saving 15 regs at the moment.  Gives us one word
223    slop if we need to expand.  */
224 #define _JBLEN 16
225 #endif
226 
227 #if defined(_C4x)
228 #define _JBLEN 10
229 #endif
230 #if defined(_C3x)
231 #define _JBLEN 9
232 #endif
233 
234 #ifdef __TMS320C6X__
235 #define _JBLEN 13
236 #endif
237 
238 #ifdef __TIC80__
239 #define _JBLEN 13
240 #endif
241 
242 #ifdef __D10V__
243 #define _JBLEN 8
244 #endif
245 
246 #ifdef __D30V__
247 #define _JBLEN ((64 /* GPR */ + (2*2) /* ACs */ + 18 /* CRs */) / 2)
248 #define _JBTYPE double
249 #endif
250 
251 #ifdef __frv__
252 #define _JBLEN (68/2)  /* room for 68 32-bit regs */
253 #define _JBTYPE double
254 #endif
255 
256 #ifdef __moxie__
257 #define _JBLEN 10
258 #endif
259 
260 #ifdef __CRX__
261 #define _JBLEN 9
262 #endif
263 
264 #if (defined(__CR16__) || defined(__CR16C__) ||defined(__CR16CP__))
265 /* r6, r7, r8, r9, r10, r11, r12 (r12L, r12H),
266  * r13 (r13L, r13H), ra(raL, raH), sp(spL, spH) */
267 #define _JBLEN 14
268 #define _JBTYPE unsigned short
269 #endif
270 
271 #ifdef __fr30__
272 #define _JBLEN 10
273 #endif
274 
275 #ifdef  __FT32__
276 #define _JBLEN 27
277 #endif
278 
279 #ifdef __iq2000__
280 #define _JBLEN 32
281 #endif
282 
283 #ifdef __mcore__
284 #define _JBLEN 16
285 #endif
286 
287 #ifdef __arc__
288 #define _JBLEN 25 /* r13-r30,blink,lp_count,lp_start,lp_end,mlo,mhi,status32 */
289 #define _JBTYPE unsigned long
290 #endif
291 
292 #ifdef __ARC64__
293 /* r14-r27,sp,ilink,r30,blink  */
294 #define _JBLEN 18
295 #ifdef __ARC64_ARCH64__
296 #define _JBTYPE long long
297 #else  /* __ARC64_ARCH32__ */
298 #define _JBTYPE long
299 #endif
300 #endif /* __ARC64__ */
301 
302 #ifdef __MMIX__
303 /* Using a layout compatible with GCC's built-in.  */
304 #define _JBLEN 5
305 #define _JBTYPE unsigned long
306 #endif
307 
308 #ifdef __mt__
309 #define _JBLEN 16
310 #endif
311 
312 #ifdef __SPU__
313 #define _JBLEN 50
314 #define _JBTYPE __vector signed int
315 #endif
316 
317 #ifdef __xstormy16__
318 /* 4 GPRs plus SP plus PC. */
319 #define _JBLEN 8
320 #endif
321 
322 #ifdef __XTENSA__
323 #if __XTENSA_WINDOWED_ABI__
324 
325 /* The jmp_buf structure for Xtensa windowed ABI holds the following
326    (where "proc" is the procedure that calls setjmp): 4-12 registers
327    from the window of proc, the 4 words from the save area at proc's $sp
328    (in case a subsequent alloca in proc moves $sp), and the return
329    address within proc. Everything else is saved on the stack in the
330    normal save areas. The jmp_buf structure is:
331 
332    struct jmp_buf {
333       int regs[12];
334       int save[4];
335       void *return_address;
336    }
337 
338    See the setjmp code for details.  */
339 
340 /* sizeof(struct jmp_buf) */
341 #define _JBLEN 17
342 
343 #else /* __XTENSA_CALL0_ABI__ */
344 
345 /* a0, a1, a12, a13, a14, a15 */
346 #define _JBLEN 6
347 
348 #endif /* __XTENSA_CALL0_ABI__ */
349 #endif /* __XTENSA__ */
350 
351 #ifdef __mep__
352 /* 16 GPRs, pc, hi, lo */
353 #define _JBLEN 19
354 #endif
355 
356 #ifdef __CRIS__
357 #define _JBLEN 18
358 #endif
359 
360 #ifdef __ia64
361 #define _JBLEN 64
362 #endif
363 
364 #ifdef __lm32__
365 #define _JBLEN 19
366 #endif
367 
368 #ifdef __m32c__
369 #if defined(__r8c_cpu__) || defined(__m16c_cpu__)
370 #define _JBLEN (22/2)
371 #else
372 #define _JBLEN (34/2)
373 #endif
374 #define _JBTYPE unsigned short
375 #endif /* __m32c__ */
376 
377 #ifdef __MSP430__
378 #define _JBLEN 9
379 
380 #ifdef __MSP430X_LARGE__
381 #define _JBTYPE unsigned long
382 #else
383 #define _JBTYPE unsigned short
384 #endif
385 #endif
386 
387 #ifdef __RL78__
388 /* Three banks of registers, SP, CS, ES, PC */
389 #define _JBLEN (8*3+8)
390 #define _JBTYPE unsigned char
391 #endif
392 
393 /*
394  * There are two versions of setjmp()/longjmp():
395  *   1) Compiler (gcc) built-in versions.
396  *   2) Function-call versions.
397  *
398  * The built-in versions are used most of the time.  When used, gcc replaces
399  * calls to setjmp()/longjmp() with inline assembly code.  The built-in
400  * versions save/restore a variable number of registers.
401 
402  * _JBLEN is set to 40 to be ultra-safe with the built-in versions.
403  * It only needs to be 12 for the function-call versions
404  * but this data structure is used by both versions.
405  */
406 #ifdef __NIOS2__
407 #define _JBLEN 40
408 #define _JBTYPE unsigned long
409 #endif
410 
411 #ifdef __PRU__
412 #define _JBLEN 48
413 #define _JBTYPE unsigned int
414 #endif
415 
416 #ifdef __RX__
417 #define _JBLEN 0x44
418 #endif
419 
420 #ifdef __VISIUM__
421 /* All call-saved GP registers: r11-r19,r21,r22,r23.  */
422 #define _JBLEN 12
423 #endif
424 
425 #ifdef __riscv
426 /* _JBTYPE using long long to make sure the alignment is align to 8 byte,
427    otherwise in rv32imafd, store/restore FPR may mis-align.  */
428 #define _JBTYPE long long
429 #ifdef __riscv_32e
430 #define _JBLEN ((4*sizeof(long))/sizeof(long))
431 #else
432 #define _JBLEN ((14*sizeof(long) + 12*sizeof(double))/sizeof(long))
433 #endif
434 #endif
435 
436 #ifdef __CSKYABIV2__
437 #define _JBTYPE unsigned long
438 #if defined(__CK801__)
439 #define _JBLEN 7
440 #elif defined(__CK802__)
441 #define _JBLEN 10
442 #else
443 #define _JBLEN 18
444 #endif
445 #endif
446 
447 #ifdef _JBLEN
448 #ifdef _JBTYPE
449 typedef	_JBTYPE jmp_buf[_JBLEN];
450 #else
451 typedef	int jmp_buf[_JBLEN];
452 #endif
453 #endif
454 
455 _END_STD_C
456 
457 #if (defined(__CYGWIN__) || defined(__rtems__)) && __POSIX_VISIBLE
458 #include <signal.h>
459 
460 _BEGIN_STD_C
461 
462 /* POSIX sigsetjmp/siglongjmp macros */
463 #ifdef _JBTYPE
464 typedef _JBTYPE sigjmp_buf[_JBLEN+1+((sizeof (_JBTYPE) + sizeof (sigset_t) - 1)
465 				     /sizeof (_JBTYPE))];
466 #else
467 typedef int sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (int))];
468 #endif
469 
470 #define _SAVEMASK	_JBLEN
471 #define _SIGMASK	(_JBLEN+1)
472 
473 
474 #ifdef _POSIX_THREADS
475 #define __SIGMASK_FUNC pthread_sigmask
476 #else
477 #define __SIGMASK_FUNC sigprocmask
478 #endif
479 
480 
481 #if defined(__GNUC__)
482 
483 #define sigsetjmp(env, savemask) \
484             __extension__ \
485             ({ \
486               sigjmp_buf *_sjbuf = &(env); \
487               ((*_sjbuf)[_SAVEMASK] = savemask,\
488               __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *)((*_sjbuf) + _SIGMASK)),\
489               setjmp (*_sjbuf)); \
490             })
491 
492 #define siglongjmp(env, val) \
493             __extension__ \
494             ({ \
495               sigjmp_buf *_sjbuf = &(env); \
496               ((((*_sjbuf)[_SAVEMASK]) ? \
497                __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *)((*_sjbuf) + _SIGMASK), 0)\
498                : 0), \
499                longjmp (*_sjbuf, val)); \
500             })
501 
502 #else /* !__GNUC__ */
503 
504 #define sigsetjmp(env, savemask) ((env)[_SAVEMASK] = savemask,\
505                __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *) ((env) + _SIGMASK)),\
506                setjmp (env))
507 
508 #define siglongjmp(env, val) ((((env)[_SAVEMASK])?\
509                __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *) ((env) + _SIGMASK), 0):0),\
510                longjmp (env, val))
511 
512 #endif
513 
514 /* POSIX _setjmp/_longjmp, maintained for XSI compatibility.  These
515    are equivalent to sigsetjmp/siglongjmp when not saving the signal mask.
516    New applications should use sigsetjmp/siglongjmp instead. */
517 #define _setjmp(env)		sigsetjmp ((env), 0)
518 #define _longjmp(env, val)	siglongjmp ((env), (val))
519 
520 _END_STD_C
521 
522 #endif /* (__CYGWIN__ or __rtems__) and __POSIX_VISIBLE */
523