1/* Copyright (c) 2020  C-SKY Microsystems All rights reserved.
2
3   This copyrighted material is made available to anyone wishing to use,
4   modify, copy, or redistribute it subject to the terms and conditions
5   of the FreeBSD License.   This program is distributed in the hope that
6   it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
7   including the implied warranties of MERCHANTABILITY or FITNESS FOR
8   A PARTICULAR PURPOSE.  A copy of this license is available at
9   http://www.opensource.org/licenses.
10*/
11
12#include <picolibc.h>
13
14	.section	.text
15	.align	3
16	.globl	setjmp
17	.type	setjmp,@function
18	.globl	longjmp
19	.type	longjmp,@function
20
21setjmp:
22
23#if defined(__CK801__)
24	stw	r4, (r0, 0)
25	stw    	r5, (r0, 4)
26	stw    	r6, (r0, 8)
27	stw    	r7, (r0, 12)
28	stw    	r8, (r0, 16)
29	stw    	r15, (r0, 20)
30	stw    	sp, (r0, 24)
31#elif defined(__CK802__)
32	stm	r4-r11, (r0)
33	stw    	r15, (r0, 32)
34	stw    	sp, (r0, 36)
35#else
36	stm    	r4-r11, (r0)
37	stw    	r15, (r0, 32)
38	stw    	r16, (r0, 36)
39	stw    	r17, (r0, 40)
40	stw    	r26, (r0, 44)
41	stw    	r27, (r0, 48)
42	stw    	r28, (r0, 52)
43	stw    	r29, (r0, 56)
44	stw    	r30, (r0, 60)
45	stw    	r31, (r0, 64)
46	stw    	sp, (r0, 68)
47#endif
48	movi   	r0, 0
49	rts
50
51longjmp:
52#if defined(__CK801__)
53	ldw	r4, (r0, 0)
54	ldw    	r5, (r0, 4)
55	ldw    	r6, (r0, 8)
56	ldw    	r7, (r0, 12)
57	ldw    	r8, (r0, 16)
58	ldw    	r15, (r0, 20)
59	ldw    	sp, (r0, 24)
60#elif defined(__CK802__)
61	ldm	r4-r11, (r0)
62	ldw    	r15, (r0, 32)
63	ldw    	sp, (r0, 36)
64#else
65	ldm   	r4-r11, (r0)
66	ldw    	r15, (r0, 32)
67	ldw    	r16, (r0, 36)
68	ldw    	r17, (r0, 40)
69	ldw    	r26, (r0, 44)
70	ldw    	r27, (r0, 48)
71	ldw    	r28, (r0, 52)
72	ldw    	r29, (r0, 56)
73	ldw    	r30, (r0, 60)
74	ldw    	r31, (r0, 64)
75	ldw    	sp, (r0, 68)
76#endif
77	mov    	r0, r1
78	cmpnei 	r1, 0
79	bt     	1f
80	movi   	r0, 1
811:	rts
82