1#include <picolibc.h>
2
3 ##############################################################################
4 # setjmp.S -- CR16 setjmp routine                                            #
5 #                                                                            #
6/* Copyright (c) 2004 National Semiconductor Corporation                      */
7 #                                                                            #
8 # The authors hereby grant permission to use, copy, modify, distribute,      #
9 # and license this software and its documentation for any purpose, provided  #
10 # that existing copyright notices are retained in all copies and that this   #
11 # notice is included verbatim in any distributions. No written agreement,    #
12 # license, or royalty fee is required for any of the authorized uses.        #
13 # Modifications to this software may be copyrighted by their authors         #
14 # and need not follow the licensing terms described here, provided that      #
15 # the new terms are clearly indicated on the first page of each file where   #
16 # they apply.                                                                #
17 #                                                                            #
18 # C library -- setjmp, longjmp                                               #
19 # longjmp(a,v)                                                               #
20 # will generate a "return(v)"                                                #
21 # from the last call to                                                      #
22 # setjmp(a)                                                                  #
23 # by restoring r7-ra, sp,                                                    #
24 # and pc from 'a'                                                            #
25 # and doing a return. (Makes sure that longjmp never returns 0).             #
26 ##############################################################################
27
28	.text
29	.file	"setjmp.s"
30        .align 4
31
32        .globl _setjmp
33        .align 4
34_setjmp:
35        #r3, r2: .blkw
36	storw r7, 0(r3,r2)
37	addd $2, (r3,r2)
38	storw r8, 0(r3,r2)
39	addd $2, (r3,r2)
40	storw r9, 0(r3,r2)
41	addd $2, (r3,r2)
42	storw r10, 0(r3,r2)
43	addd $2, (r3,r2)
44	storw r11, 0(r3,r2)
45	addd $2, (r3,r2)
46
47	stord (r12), 0(r3,r2)
48	addd $4, (r3,r2)
49	stord (r13), 0(r3,r2)
50	addd $4, (r3,r2)
51
52	stord (ra), 0(r3,r2)
53	addd $4, (r3,r2)
54	stord (sp), 0(r3,r2)
55
56        movd  $0,(r1,r0)
57        jump  (ra)
58
59        .globl _longjmp
60_longjmp:
61        #r3, r2: .blkw # pointer save area
62        #r5, r4: .blkw # ret vlaue
63
64	loadw 0(r3,r2), r7
65	addd $2, (r3,r2)
66	loadw 0(r3,r2), r8
67	addd $2, (r3,r2)
68	loadw 0(r3,r2), r9
69	addd $2, (r3,r2)
70	loadw 0(r3,r2), r10
71	addd $2, (r3,r2)
72	loadw 0(r3,r2), r11
73	addd $2, (r3,r2)
74
75	loadd 0(r3,r2), (r12)
76	addd $4, (r3,r2)
77	loadd 0(r3,r2), (r13)
78	addd $4, (r3,r2)
79
80	loadd 0(r3,r2), (ra)
81	addd $4, (r3,r2)
82	loadd 0(r3,r2), (sp)
83
84#ifdef __INT32__
85        movd (r5,r4), (r1,r0)
86        cmpd $0, (r5,r4)
87        bne end1
88        movd $1, (r1,r0)
89#else
90        movw r4, r0
91        cmpw $0, r4
92        bne end1
93        movw $1, r0
94#endif
95end1:
96        jump (ra)
97        .align 4
98
99
100