1/*
2 * Copyright (c) 2008 Jon Beniston <jon@beniston.com>
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25/* setjmp/longjmp for LatticeMico32. */
26#include <picolibc.h>
27
28
29	.section	.text
30	.align	4
31
32	.globl	setjmp
33	.type	setjmp,@function
34	.globl	longjmp
35	.type	longjmp,@function
36
37/* setjmp: save all callee saves into jmp_buf
38   r1 - Address of jmp_buf
39*/
40
41setjmp:
42        sw      (r1+0), r11
43        sw      (r1+4), r12
44        sw      (r1+8), r13
45        sw      (r1+12), r14
46        sw      (r1+16), r15
47        sw      (r1+20), r16
48        sw      (r1+24), r17
49        sw      (r1+28), r18
50        sw      (r1+32), r19
51        sw      (r1+36), r20
52        sw      (r1+40), r21
53        sw      (r1+44), r22
54        sw      (r1+48), r23
55        sw      (r1+52), r24
56        sw      (r1+56), r25
57        sw      (r1+60), gp
58        sw      (r1+64), fp
59        sw      (r1+68), sp
60        sw      (r1+72), ra
61        mvi     r1, 0
62        ret
63
64/* longjmp: restore all callee saves from jmp_buf
65   r1 - Address of jmb_buf
66   r2 - Value to return with
67*/
68
69        .global     longjmp
70        .type       longjmp,@function
71        .align      4
72
73longjmp:
74        lw      r11, (r1+0)
75        lw      r12, (r1+4)
76        lw      r13, (r1+8)
77        lw      r14, (r1+12)
78        lw      r15, (r1+16)
79        lw      r16, (r1+20)
80        lw      r17, (r1+24)
81        lw      r18, (r1+28)
82        lw      r19, (r1+32)
83        lw      r20, (r1+36)
84        lw      r21, (r1+40)
85        lw      r22, (r1+44)
86        lw      r23, (r1+48)
87        lw      r24, (r1+52)
88        lw      r25, (r1+56)
89        lw      gp, (r1+60)
90        lw      fp, (r1+64)
91        lw      sp, (r1+68)
92        lw      ra, (r1+72)
93        mv      r1, r2
94        ret
95
96
97