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/asmmacro.h> |
---|
29 | |
---|
30 | /* Store the register window onto the 8-byte aligned area starting |
---|
31 | * at %reg. It might be %sp, it might not, we don't care. |
---|
32 | */ |
---|
33 | #define RW_STORE(reg) \ |
---|
34 | std %l0, [%reg + RW_L0]; \ |
---|
35 | std %l2, [%reg + RW_L2]; \ |
---|
36 | std %l4, [%reg + RW_L4]; \ |
---|
37 | std %l6, [%reg + RW_L6]; \ |
---|
38 | std %i0, [%reg + RW_I0]; \ |
---|
39 | std %i2, [%reg + RW_I2]; \ |
---|
40 | std %i4, [%reg + RW_I4]; \ |
---|
41 | std %i6, [%reg + RW_I6]; |
---|
42 | |
---|
43 | /* Load a register window from the area beginning at %reg. */ |
---|
44 | #define RW_LOAD(reg) \ |
---|
45 | ldd [%reg + RW_L0], %l0; \ |
---|
46 | ldd [%reg + RW_L2], %l2; \ |
---|
47 | ldd [%reg + RW_L4], %l4; \ |
---|
48 | ldd [%reg + RW_L6], %l6; \ |
---|
49 | ldd [%reg + RW_I0], %i0; \ |
---|
50 | ldd [%reg + RW_I2], %i2; \ |
---|
51 | ldd [%reg + RW_I4], %i4; \ |
---|
52 | ldd [%reg + RW_I6], %i6; |
---|
53 | |
---|
54 | /* Loading and storing struct pt_reg trap frames. */ |
---|
55 | #define PT_LOAD_INS(base_reg) \ |
---|
56 | ldd [%base_reg + SF_REGS_SZ + PT_I0], %i0; \ |
---|
57 | ldd [%base_reg + SF_REGS_SZ + PT_I2], %i2; \ |
---|
58 | ldd [%base_reg + SF_REGS_SZ + PT_I4], %i4; \ |
---|
59 | ldd [%base_reg + SF_REGS_SZ + PT_I6], %i6; |
---|
60 | |
---|
61 | #define PT_LOAD_GLOBALS(base_reg) \ |
---|
62 | ld [%base_reg + SF_REGS_SZ + PT_G1], %g1; \ |
---|
63 | ldd [%base_reg + SF_REGS_SZ + PT_G2], %g2; \ |
---|
64 | ldd [%base_reg + SF_REGS_SZ + PT_G4], %g4; \ |
---|
65 | ldd [%base_reg + SF_REGS_SZ + PT_G6], %g6; |
---|
66 | |
---|
67 | #define PT_LOAD_GLOBALS_23(base_reg) \ |
---|
68 | ldd [%base_reg + SF_REGS_SZ + PT_G2], %g2; |
---|
69 | |
---|
70 | #define PT_LOAD_YREG(base_reg, scratch) \ |
---|
71 | ld [%base_reg + SF_REGS_SZ + PT_Y], %scratch; \ |
---|
72 | wr %scratch, 0x0, %y; |
---|
73 | |
---|
74 | #define PT_LOAD_PRIV(base_reg, pt_psr, pt_pc, pt_npc) \ |
---|
75 | ld [%base_reg + SF_REGS_SZ + PT_PSR], %pt_psr; \ |
---|
76 | ld [%base_reg + SF_REGS_SZ + PT_PC], %pt_pc; \ |
---|
77 | ld [%base_reg + SF_REGS_SZ + PT_NPC], %pt_npc; |
---|
78 | |
---|
79 | #define PT_LOAD_ALL(base_reg, pt_psr, pt_pc, pt_npc, scratch) \ |
---|
80 | PT_LOAD_YREG(base_reg, scratch) \ |
---|
81 | PT_LOAD_INS(base_reg) \ |
---|
82 | PT_LOAD_GLOBALS(base_reg) \ |
---|
83 | PT_LOAD_PRIV(base_reg, pt_psr, pt_pc, pt_npc) |
---|
84 | |
---|
85 | #define PT_LOAD_ALL_FAST(base_reg, pt_psr, pt_pc, pt_npc, scratch) \ |
---|
86 | PT_LOAD_YREG(base_reg, scratch) \ |
---|
87 | PT_LOAD_GLOBALS(base_reg) |
---|
88 | |
---|
89 | #define PT_STORE_INS(base_reg) \ |
---|
90 | std %i0, [%base_reg + SF_REGS_SZ + PT_I0]; \ |
---|
91 | std %i2, [%base_reg + SF_REGS_SZ + PT_I2]; \ |
---|
92 | std %i4, [%base_reg + SF_REGS_SZ + PT_I4]; \ |
---|
93 | std %i6, [%base_reg + SF_REGS_SZ + PT_I6]; |
---|
94 | |
---|
95 | #define PT_STORE_GLOBALS(base_reg) \ |
---|
96 | st %g1, [%base_reg + SF_REGS_SZ + PT_G1]; \ |
---|
97 | std %g2, [%base_reg + SF_REGS_SZ + PT_G2]; \ |
---|
98 | std %g4, [%base_reg + SF_REGS_SZ + PT_G4]; \ |
---|
99 | std %g6, [%base_reg + SF_REGS_SZ + PT_G6]; |
---|
100 | |
---|
101 | #define PT_STORE_GLOBALS_23(base_reg) \ |
---|
102 | std %g2, [%base_reg + SF_REGS_SZ + PT_G2]; |
---|
103 | |
---|
104 | #define PT_STORE_YREG(base_reg, scratch) \ |
---|
105 | rd %y, %scratch; \ |
---|
106 | st %scratch, [%base_reg + SF_REGS_SZ + PT_Y]; |
---|
107 | |
---|
108 | #define PT_STORE_PRIV(base_reg, pt_psr, pt_pc, pt_npc) \ |
---|
109 | st %pt_psr, [%base_reg + SF_REGS_SZ + PT_PSR]; \ |
---|
110 | st %pt_pc, [%base_reg + SF_REGS_SZ + PT_PC]; \ |
---|
111 | st %pt_npc, [%base_reg + SF_REGS_SZ + PT_NPC]; |
---|
112 | |
---|
113 | #define PT_STORE_ALL(base_reg, reg_psr, reg_pc, reg_npc, g_scratch) \ |
---|
114 | PT_STORE_PRIV(base_reg, reg_psr, reg_pc, reg_npc) \ |
---|
115 | PT_STORE_GLOBALS(base_reg) \ |
---|
116 | PT_STORE_YREG(base_reg, g_scratch) \ |
---|
117 | PT_STORE_INS(base_reg) |
---|
118 | |
---|
119 | #define PT_STORE_ALL_FAST(base_reg, reg_psr, reg_pc, reg_npc, g_scratch) \ |
---|
120 | PT_STORE_GLOBALS(base_reg) \ |
---|
121 | PT_STORE_YREG(base_reg, g_scratch) |
---|
122 | |
---|
123 | /* Store the fpu register window*/ |
---|
124 | #define FW_STORE(reg) \ |
---|
125 | std %f0, [reg + FW_F0]; \ |
---|
126 | std %f2, [reg + FW_F2]; \ |
---|
127 | std %f4, [reg + FW_F4]; \ |
---|
128 | std %f6, [reg + FW_F6]; \ |
---|
129 | std %f8, [reg + FW_F8]; \ |
---|
130 | std %f10, [reg + FW_F10]; \ |
---|
131 | std %f12, [reg + FW_F12]; \ |
---|
132 | std %f14, [reg + FW_F14]; \ |
---|
133 | std %f16, [reg + FW_F16]; \ |
---|
134 | std %f18, [reg + FW_F18]; \ |
---|
135 | std %f20, [reg + FW_F20]; \ |
---|
136 | std %f22, [reg + FW_F22]; \ |
---|
137 | std %f24, [reg + FW_F24]; \ |
---|
138 | std %f26, [reg + FW_F26]; \ |
---|
139 | std %f28, [reg + FW_F28]; \ |
---|
140 | std %f30, [reg + FW_F30]; \ |
---|
141 | st %fsr, [reg + FW_FSR]; |
---|
142 | |
---|
143 | /* Load a fpu register window from the area beginning at reg. */ |
---|
144 | #define FW_LOAD(reg) \ |
---|
145 | ldd [reg + FW_F0], %f0; \ |
---|
146 | ldd [reg + FW_F2], %f2; \ |
---|
147 | ldd [reg + FW_F4], %f4; \ |
---|
148 | ldd [reg + FW_F6], %f6; \ |
---|
149 | ldd [reg + FW_F8], %f8; \ |
---|
150 | ldd [reg + FW_F10], %f10; \ |
---|
151 | ldd [reg + FW_F12], %f12; \ |
---|
152 | ldd [reg + FW_F14], %f14; \ |
---|
153 | ldd [reg + FW_F16], %f16; \ |
---|
154 | ldd [reg + FW_F18], %f18; \ |
---|
155 | ldd [reg + FW_F20], %f20; \ |
---|
156 | ldd [reg + FW_F22], %f22; \ |
---|
157 | ldd [reg + FW_F24], %f24; \ |
---|
158 | ldd [reg + FW_F26], %f26; \ |
---|
159 | ldd [reg + FW_F28], %f28; \ |
---|
160 | ldd [reg + FW_F30], %f30; \ |
---|
161 | ld [reg + FW_FSR], %fsr; |
---|
162 | |
---|
163 | #define SET_WIM_CWPMIN2(psr_reg,tmp1,tmp2,tmp3,tmp4) \ |
---|
164 | sethi %hi(_nwindows_min2), %##tmp1; \ |
---|
165 | and %##psr_reg, SPARC_PSR_WIN_MASK, %##tmp3; \ |
---|
166 | mov 1, %##tmp2; \ |
---|
167 | ld [ %##tmp1 + %lo(_nwindows_min2)], %##tmp1; \ |
---|
168 | sll %##tmp2, %##tmp3, %##tmp3; \ |
---|
169 | sll %##tmp3, 2, %##tmp4; \ |
---|
170 | srl %##tmp3, %##tmp1, %##tmp1; \ |
---|
171 | or %##tmp4, %##tmp1, %##tmp3; \ |
---|
172 | wr %##tmp3, 0x0, %wim; \ |
---|
173 | nop; nop; nop; |
---|
174 | |
---|
175 | #define SET_WIM_CWPMIN1(psr_reg,tmp1,tmp2,tmp3,tmp4) \ |
---|
176 | sethi %hi(_nwindows_min1), %##tmp1; \ |
---|
177 | and %##psr_reg, SPARC_PSR_WIN_MASK, %##tmp3; \ |
---|
178 | mov 1, %##tmp2; \ |
---|
179 | ld [ %##tmp1 + %lo(_nwindows_min1)], %##tmp1; \ |
---|
180 | sll %##tmp2, %##tmp3, %##tmp3; \ |
---|
181 | sll %##tmp3, 1, %##tmp4; \ |
---|
182 | srl %##tmp3, %##tmp1, %##tmp1; \ |
---|
183 | or %##tmp4, %##tmp1, %##tmp3; \ |
---|
184 | wr %##tmp3, 0x0, %wim; \ |
---|
185 | nop; nop; nop; |
---|