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