1/*
2Copyright (c) 1990 The Regents of the University of California.
3All rights reserved.
4
5Redistribution and use in source and binary forms are permitted
6provided that the above copyright notice and this paragraph are
7duplicated in all such forms and that any documentation,
8and/or other materials related to such
9distribution and use acknowledge that the software was developed
10by the University of California, Berkeley.  The name of the
11University may not be used to endorse or promote products derived
12from this software without specific prior written permission.
13THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17#include <picolibc.h>
18
19	.global	_setjmp
20	.global	_longjmp
21
22#ifdef __Z8001__
23	segm
24
25#ifdef __STD_CALL__
26
27_setjmp:
28	ldl	rr6,rr14(#4)	! get argument
29	ldl	rr2,@rr14	! fetch pc
30	ldl	@rr6,rr2	! save it
31	ldl	rr6(#16),rr8
32	ldl	rr6(#4),rr10
33	ldl	rr6(#8),rr12	! remember frame pointer
34	ldl	rr6(#12),rr14	! remember stack pointer
35	ldk	r7,#0
36	ret	t
37
38_longjmp:
39	ldl	rr4,rr14(#4)	! get first argument
40	ld	r7,rr14(#8)	! get return value
41	ldl	rr8,rr4(#16)
42	ldl	rr10,rr4(#4)
43	ldl	rr12,rr4(#8)	! restore old frame pointer
44	ldl	rr14,rr4(#12)	! restore old stack pointer
45	ldl	rr4,@rr4	! return address
46	inc	r15,#4
47	jp	@rr4
48
49#else /* above __STD_CALL_, below not */
50
51_setjmp:
52	ldl	rr2,@rr14	! fetch pc
53	ldl	@rr6,rr2	! save it
54	ldl	rr6(16),rr8
55	ldl	rr6(4),rr10
56	ldl	rr6(8),rr12	! and the other special regs
57	ldl	rr6(12),rr14
58	ldk	r2,#0
59	ret	t
60
61_longjmp:
62	ld	r2,r5		! get return value
63	ldl	rr4,rr6(0)
64	ldl	rr8,rr6(16)
65	ldl	rr10,rr6(4)
66	ldl	rr12,rr6(8)
67	ldl	rr14,rr6(12)
68	inc	r15,#4
69	jp	@rr4
70
71#endif  /* not __STD_CALL__ */
72#else /* above Z8001, below Z8002 */
73	unseg
74
75#ifdef __STD_CALL__
76
77_setjmp:
78	ld	r7,r15(#2)	! get argument
79	ld	r2,@r15		! fetch pc
80	ld	@r7,r2		! save it
81	ldl	r7(#14),rr8
82	ldl	r7(#2),rr10
83	ldl	r7(#6),rr12	! remember frame pointer
84	ldl	r7(#10),rr14	! remember stack pointer
85	ldk	r7,#0
86	ret	t
87
88_longjmp:
89	ld	r4,r15(#2)	! get first argument (jmp_buf)
90	ld	r7,r15(#4)	! get return value
91	ldl	rr8,r4(#14)
92	ldl	rr10,r4(#2)
93	ldl	rr12,r4(#6)	! restore old frame pointer
94	ldl	rr14,r4(#10)	! restore old stack pointer
95	ld	r4,@r4		! return address
96	inc	r15,#2
97	jp	@r4
98
99#else /* above __STD_CALL_, below not */
100
101_setjmp:
102	ld	r2,@r15	! fetch pc
103	ld	@r7,r2	! save it
104	ldl	r7(4),rr10
105	ldl	r7(8),rr12	! and the other special regs
106	ldl	r7(12),rr14
107	ldk	r2,#0
108	ret	t
109
110_longjmp:
111	ld	r2,r6		! get return value
112	ld	r4,@r7
113	ldl	rr10,r7(4)
114	ldl	rr12,r7(8)
115	ldl	rr14,r7(12)
116	inc	r15,#2
117	jp	@r4
118
119#endif  /* not __STD_CALL__ */
120#endif  /* Z8002 version */
121