1 | /* |
---|
2 | * Copyright (c) 2011 Aeroflex Gaisler |
---|
3 | * |
---|
4 | * BSD license: |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
7 | * of this software and associated documentation files (the "Software"), to deal |
---|
8 | * in the Software without restriction, including without limitation the rights |
---|
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
10 | * copies of the Software, and to permit persons to whom the Software is |
---|
11 | * furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
---|
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
22 | * THE SOFTWARE. |
---|
23 | */ |
---|
24 | |
---|
25 | |
---|
26 | #include <asm-leon/leon.h> |
---|
27 | #include <asm-leon/leonstack.h> |
---|
28 | #include <asm-leon/irq.h> |
---|
29 | #include <asm-leon/irq.h> |
---|
30 | #include <asm-leon/time.h> |
---|
31 | #include <asm-leon/contextswitch.h> |
---|
32 | |
---|
33 | /* This asm code relies on the following offsets (setjmp.h): |
---|
34 | #define THREAD_JB_SP 0 |
---|
35 | #define THREAD_JB_PC 1 |
---|
36 | #define THREAD_JB_PSR 8 |
---|
37 | #define THREAD_JB_WIM 9 */ |
---|
38 | |
---|
39 | int |
---|
40 | _do_thread_setjmp (threadctx_t env, unsigned int savesigs) |
---|
41 | { |
---|
42 | |
---|
43 | #ifndef _FLAT |
---|
44 | /* first restore should trap */ |
---|
45 | env[THREAD_JB_WIM] = 1 << ((env[THREAD_JB_PSR] & SPARC_PSR_WIN_MASK) + 1); |
---|
46 | env[THREAD_JB_WIM] |= env[THREAD_JB_WIM] >> SPARC_NUM_REGWIN; |
---|
47 | #else |
---|
48 | env[THREAD_JB_WIM] = 0; |
---|
49 | #endif |
---|
50 | |
---|
51 | #ifndef _SOFT_FLOAT |
---|
52 | env[THREAD_JB_FPUCTX] = fpustate_current; |
---|
53 | #endif |
---|
54 | return 0; |
---|
55 | } |
---|
56 | |
---|
57 | void |
---|
58 | thread_longjmp (threadctx_t env, int val) |
---|
59 | { |
---|
60 | |
---|
61 | if (!val) |
---|
62 | val = 1; |
---|
63 | |
---|
64 | #ifndef _SOFT_FLOAT |
---|
65 | fpustate_current = env[THREAD_JB_FPUCTX]; |
---|
66 | #endif |
---|
67 | |
---|
68 | _switch_to (env, val); |
---|
69 | |
---|
70 | /* __asm__ __volatile__( \ */ |
---|
71 | /* " mov %8,%%i0 /\* propagate on restore *\/ \n\t"\ */ |
---|
72 | /* " mov %0,%%i1 /\* propagate on restore *\/ \n\t"\ */ |
---|
73 | /* " restore \n\t"\ */ |
---|
74 | /* " mov %%o0,%%g6 \n\t"\ */ |
---|
75 | /* " mov %%o1,%%g3 /\* former %%i1 (val) *\/ \n\t"\ */ |
---|
76 | /* " \n\t"\ */ |
---|
77 | /* " !ta 0x03 /\* flush registers *\/ \n\t"\ */ |
---|
78 | /* " save %%sp, %7, %%sp \n\t"\ */ |
---|
79 | /* " save %%sp, %7, %%sp \n\t"\ */ |
---|
80 | /* " save %%sp, %7, %%sp \n\t"\ */ |
---|
81 | /* " save %%sp, %7, %%sp \n\t"\ */ |
---|
82 | /* " save %%sp, %7, %%sp \n\t"\ */ |
---|
83 | /* " save %%sp, %7, %%sp \n\t"\ */ |
---|
84 | /* " save %%sp, %7, %%sp \n\t"\ */ |
---|
85 | /* " \n\t"\ */ |
---|
86 | /* " ldd [%%g6+%5], %%g4 /\* load psr,wim *\/ \n\t"\ */ |
---|
87 | /* " wr %%g4, 0x20, %%psr \n\t"\ */ |
---|
88 | /* " nop \n\t"\ */ |
---|
89 | /* " nop \n\t"\ */ |
---|
90 | /* " nop \n\t"\ */ |
---|
91 | /* " ldd [%%g6 +%1], %%sp /\* load sp, pc to jump to *\/ \n\t"\ */ |
---|
92 | /* " wr %%g5, 0x0, %%wim \n\t"\ */ |
---|
93 | /* " \n\t"\ */ |
---|
94 | /* " ldd [%%sp], %%l0 /\* restore window *\/ \n\t"\ */ |
---|
95 | /* " ldd [%%sp+8], %%l2 \n\t"\ */ |
---|
96 | /* " ldd [%%sp+16], %%l4 \n\t"\ */ |
---|
97 | /* " ldd [%%sp+24], %%l6 \n\t"\ */ |
---|
98 | /* " \n\t"\ */ |
---|
99 | /* " ldd [%%sp+32], %%i0 \n\t"\ */ |
---|
100 | /* " ldd [%%sp+40], %%i2 \n\t"\ */ |
---|
101 | /* " ldd [%%sp+48], %%i4 \n\t"\ */ |
---|
102 | /* " ldd [%%sp+56], %%i6 \n\t"\ */ |
---|
103 | /* " wr %%g4, 0x00, %%psr \n\t"\ */ |
---|
104 | /* " nop \n\t"\ */ |
---|
105 | /* " nop \n\t"\ */ |
---|
106 | /* " nop \n\t"\ */ |
---|
107 | /* " \n\t"\ */ |
---|
108 | /* " jmp %%o7 + 8 /\* success *\/ \n\t"\ */ |
---|
109 | /* " mov %%g3, %%o0 /\* return %%g3 *\/ \n\t"\ */ |
---|
110 | /* : : /\* %0 *\/ "r" (val), \ */ |
---|
111 | /* /\* %1 *\/ "i" (sizeof(int) * THREAD_JB_SP), \ */ |
---|
112 | /* /\* %2 *\/ "i" (sizeof(int) * THREAD_JB_I7), \ */ |
---|
113 | /* /\* %3 *\/ "i" (sizeof(int) * THREAD_JB_FP), \ */ |
---|
114 | /* /\* %4 *\/ "i" (sizeof(int) * THREAD_JB_PC), \ */ |
---|
115 | /* /\* %5 *\/ "i" (sizeof(int) * THREAD_JB_PSR), \ */ |
---|
116 | /* /\* %6 *\/ "i" (sizeof(int) * THREAD_JB_WIM), \ */ |
---|
117 | /* /\* %7 *\/ "i" (-SF_REGS_SZ), \ */ |
---|
118 | /* /\* %8 *\/ "r" (env) ); */ |
---|
119 | |
---|
120 | /* never come here */ |
---|
121 | } |
---|