1 | /* |
---|
2 | Copyright (c) 2014, Hesham ALMatary |
---|
3 | All rights reserved. |
---|
4 | |
---|
5 | Redistribution and use in source and binary forms, with or without modification, |
---|
6 | are permitted provided that the following conditions are met: |
---|
7 | |
---|
8 | 1. Redistributions of source code must retain the above copyright notice, this |
---|
9 | list of conditions and the following disclaimer. |
---|
10 | |
---|
11 | 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
12 | this list of conditions and the following disclaimer in the documentation and/or |
---|
13 | other materials provided with the distribution. |
---|
14 | |
---|
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
---|
16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
---|
17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
---|
18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
---|
19 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
---|
22 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
25 | */ |
---|
26 | |
---|
27 | .align 4 |
---|
28 | .global setjmp |
---|
29 | .type setjmp,@function |
---|
30 | setjmp: |
---|
31 | |
---|
32 | l.sw 4(r3), r1 |
---|
33 | l.sw 8(r3), r2 |
---|
34 | /* Skip r3-r8 as they are not preserved across function calls */ |
---|
35 | l.sw 36(r3), r9 |
---|
36 | /* Skip r10 as it's preserved to be used by TLS */ |
---|
37 | /* Skip r11, setjmp always set it to 0 */ |
---|
38 | /* The following set if registers are preserved across function calls */ |
---|
39 | l.sw 52(r3), r14 |
---|
40 | l.sw 60(r3), r16 |
---|
41 | l.sw 68(r3), r18 |
---|
42 | l.sw 76(r3), r20 |
---|
43 | l.sw 84(r3), r22 |
---|
44 | l.sw 92(r3), r24 |
---|
45 | l.sw 100(r3), r26 |
---|
46 | l.sw 108(r3), r28 |
---|
47 | l.sw 116(r3), r30 |
---|
48 | /* Save Status Register */ |
---|
49 | l.mfspr r13, r0, 17 |
---|
50 | l.sw 124(r3), r13 |
---|
51 | /* Set result register to 0 and jump */ |
---|
52 | // Different cases for optional delay slot |
---|
53 | #if defined(__OR1K_NODELAY__) |
---|
54 | l.addi r11, r0, 0 |
---|
55 | l.jr r9 |
---|
56 | #elif defined(__OR1K_DELAY__) |
---|
57 | l.jr r9 |
---|
58 | l.addi r11, r0, 0 |
---|
59 | #else |
---|
60 | l.addi r11, r0, 0 |
---|
61 | l.jr r9 |
---|
62 | l.nop |
---|
63 | #endif |
---|
64 | |
---|
65 | .align 4 |
---|
66 | .global longjmp |
---|
67 | .type longjmp,@function |
---|
68 | longjmp: |
---|
69 | |
---|
70 | /* If the second argument to longjmp is zero, set return address to 1, |
---|
71 | otherwise set it to the value of the second argument */ |
---|
72 | l.addi r11, r0, 1 |
---|
73 | l.sfne r4, r0 |
---|
74 | l.bf 1f |
---|
75 | l.nop |
---|
76 | l.addi r11, r4, 0 |
---|
77 | |
---|
78 | /* Load status register */ |
---|
79 | 1: |
---|
80 | l.lwz r15, 124(r3) |
---|
81 | l.mtspr r0, r15, 17 |
---|
82 | |
---|
83 | l.lwz r1, 4(r3) |
---|
84 | l.lwz r2, 8(r3) |
---|
85 | /* Skip r3-r8 as they are not preserved across function calls */ |
---|
86 | l.lwz r9, 36(r3) |
---|
87 | /* Skip r11 as it's always set by longjmp */ |
---|
88 | l.lwz r14, 52(r3) |
---|
89 | l.lwz r16, 60(r3) |
---|
90 | l.lwz r18, 68(r3) |
---|
91 | l.lwz r20, 76(r3) |
---|
92 | l.lwz r22, 84(r3) |
---|
93 | l.lwz r24, 92(r3) |
---|
94 | l.lwz r26, 100(r3) |
---|
95 | l.lwz r28, 108(r3) |
---|
96 | |
---|
97 | // Different cases for optional delay slot |
---|
98 | #if defined(__OR1K_NODELAY__) |
---|
99 | l.lwz r30, 116(r3) |
---|
100 | l.jr r9 |
---|
101 | #elif defined(__OR1K_DELAY__) |
---|
102 | l.jr r9 |
---|
103 | l.lwz r30, 116(r3) |
---|
104 | #else |
---|
105 | l.lwz r30, 116(r3) |
---|
106 | l.jr r9 |
---|
107 | l.nop |
---|
108 | #endif |
---|