]>
git.proxmox.com Git - qemu.git/blob - target-sparc/win_helper.c
2 * Helpers for CWP and PSTATE handling
4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 //#define DEBUG_PSTATE
26 #define DPRINTF_PSTATE(fmt, ...) \
27 do { printf("PSTATE: " fmt , ## __VA_ARGS__); } while (0)
29 #define DPRINTF_PSTATE(fmt, ...) do {} while (0)
32 static inline void memcpy32(target_ulong
*dst
, const target_ulong
*src
)
44 void cpu_set_cwp(CPUState
*env
, int new_cwp
)
46 /* put the modified wrap registers at their proper location */
47 if (env
->cwp
== env
->nwindows
- 1) {
48 memcpy32(env
->regbase
, env
->regbase
+ env
->nwindows
* 16);
52 /* put the wrap registers at their temporary location */
53 if (new_cwp
== env
->nwindows
- 1) {
54 memcpy32(env
->regbase
+ env
->nwindows
* 16, env
->regbase
);
56 env
->regwptr
= env
->regbase
+ (new_cwp
* 16);
59 target_ulong
cpu_get_psr(CPUState
*env
)
61 helper_compute_psr(env
);
63 #if !defined(TARGET_SPARC64)
64 return env
->version
| (env
->psr
& PSR_ICC
) |
65 (env
->psref
? PSR_EF
: 0) |
67 (env
->psrs
? PSR_S
: 0) |
68 (env
->psrps
? PSR_PS
: 0) |
69 (env
->psret
? PSR_ET
: 0) | env
->cwp
;
71 return env
->psr
& PSR_ICC
;
75 void cpu_put_psr(CPUState
*env
, target_ulong val
)
77 env
->psr
= val
& PSR_ICC
;
78 #if !defined(TARGET_SPARC64)
79 env
->psref
= (val
& PSR_EF
) ? 1 : 0;
80 env
->psrpil
= (val
& PSR_PIL
) >> 8;
82 #if ((!defined(TARGET_SPARC64)) && !defined(CONFIG_USER_ONLY))
85 #if !defined(TARGET_SPARC64)
86 env
->psrs
= (val
& PSR_S
) ? 1 : 0;
87 env
->psrps
= (val
& PSR_PS
) ? 1 : 0;
88 env
->psret
= (val
& PSR_ET
) ? 1 : 0;
89 cpu_set_cwp(env
, val
& PSR_CWP
);
91 env
->cc_op
= CC_OP_FLAGS
;
94 int cpu_cwp_inc(CPUState
*env
, int cwp
)
96 if (unlikely(cwp
>= env
->nwindows
)) {
102 int cpu_cwp_dec(CPUState
*env
, int cwp
)
104 if (unlikely(cwp
< 0)) {
105 cwp
+= env
->nwindows
;
110 #ifndef TARGET_SPARC64
111 void helper_rett(CPUState
*env
)
115 if (env
->psret
== 1) {
116 helper_raise_exception(env
, TT_ILL_INSN
);
120 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1) ;
121 if (env
->wim
& (1 << cwp
)) {
122 helper_raise_exception(env
, TT_WIN_UNF
);
124 cpu_set_cwp(env
, cwp
);
125 env
->psrs
= env
->psrps
;
128 /* XXX: use another pointer for %iN registers to avoid slow wrapping
130 void helper_save(CPUState
*env
)
134 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
135 if (env
->wim
& (1 << cwp
)) {
136 helper_raise_exception(env
, TT_WIN_OVF
);
138 cpu_set_cwp(env
, cwp
);
141 void helper_restore(CPUState
*env
)
145 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
146 if (env
->wim
& (1 << cwp
)) {
147 helper_raise_exception(env
, TT_WIN_UNF
);
149 cpu_set_cwp(env
, cwp
);
152 void helper_wrpsr(CPUState
*env
, target_ulong new_psr
)
154 if ((new_psr
& PSR_CWP
) >= env
->nwindows
) {
155 helper_raise_exception(env
, TT_ILL_INSN
);
157 cpu_put_psr(env
, new_psr
);
161 target_ulong
helper_rdpsr(CPUState
*env
)
163 return cpu_get_psr(env
);
167 /* XXX: use another pointer for %iN registers to avoid slow wrapping
169 void helper_save(CPUState
*env
)
173 cwp
= cpu_cwp_dec(env
, env
->cwp
- 1);
174 if (env
->cansave
== 0) {
175 helper_raise_exception(env
, TT_SPILL
| (env
->otherwin
!= 0 ?
177 ((env
->wstate
& 0x38) >> 1)) :
178 ((env
->wstate
& 0x7) << 2)));
180 if (env
->cleanwin
- env
->canrestore
== 0) {
181 /* XXX Clean windows without trap */
182 helper_raise_exception(env
, TT_CLRWIN
);
186 cpu_set_cwp(env
, cwp
);
191 void helper_restore(CPUState
*env
)
195 cwp
= cpu_cwp_inc(env
, env
->cwp
+ 1);
196 if (env
->canrestore
== 0) {
197 helper_raise_exception(env
, TT_FILL
| (env
->otherwin
!= 0 ?
199 ((env
->wstate
& 0x38) >> 1)) :
200 ((env
->wstate
& 0x7) << 2)));
204 cpu_set_cwp(env
, cwp
);
208 void helper_flushw(CPUState
*env
)
210 if (env
->cansave
!= env
->nwindows
- 2) {
211 helper_raise_exception(env
, TT_SPILL
| (env
->otherwin
!= 0 ?
213 ((env
->wstate
& 0x38) >> 1)) :
214 ((env
->wstate
& 0x7) << 2)));
218 void helper_saved(CPUState
*env
)
221 if (env
->otherwin
== 0) {
228 void helper_restored(CPUState
*env
)
231 if (env
->cleanwin
< env
->nwindows
- 1) {
234 if (env
->otherwin
== 0) {
241 target_ulong
cpu_get_ccr(CPUState
*env
)
245 psr
= cpu_get_psr(env
);
247 return ((env
->xcc
>> 20) << 4) | ((psr
& PSR_ICC
) >> 20);
250 void cpu_put_ccr(CPUState
*env
, target_ulong val
)
252 env
->xcc
= (val
>> 4) << 20;
253 env
->psr
= (val
& 0xf) << 20;
257 target_ulong
cpu_get_cwp64(CPUState
*env
)
259 return env
->nwindows
- 1 - env
->cwp
;
262 void cpu_put_cwp64(CPUState
*env
, int cwp
)
264 if (unlikely(cwp
>= env
->nwindows
|| cwp
< 0)) {
265 cwp
%= env
->nwindows
;
267 cpu_set_cwp(env
, env
->nwindows
- 1 - cwp
);
270 target_ulong
helper_rdccr(CPUState
*env
)
272 return cpu_get_ccr(env
);
275 void helper_wrccr(CPUState
*env
, target_ulong new_ccr
)
277 cpu_put_ccr(env
, new_ccr
);
280 /* CWP handling is reversed in V9, but we still use the V8 register
282 target_ulong
helper_rdcwp(CPUState
*env
)
284 return cpu_get_cwp64(env
);
287 void helper_wrcwp(CPUState
*env
, target_ulong new_cwp
)
289 cpu_put_cwp64(env
, new_cwp
);
292 static inline uint64_t *get_gregset(CPUState
*env
, uint32_t pstate
)
296 DPRINTF_PSTATE("ERROR in get_gregset: active pstate bits=%x%s%s%s\n",
298 (pstate
& PS_IG
) ? " IG" : "",
299 (pstate
& PS_MG
) ? " MG" : "",
300 (pstate
& PS_AG
) ? " AG" : "");
301 /* pass through to normal set of global registers */
313 void cpu_change_pstate(CPUState
*env
, uint32_t new_pstate
)
315 uint32_t pstate_regs
, new_pstate_regs
;
318 if (env
->def
->features
& CPU_FEATURE_GL
) {
319 /* PS_AG is not implemented in this case */
320 new_pstate
&= ~PS_AG
;
323 pstate_regs
= env
->pstate
& 0xc01;
324 new_pstate_regs
= new_pstate
& 0xc01;
326 if (new_pstate_regs
!= pstate_regs
) {
327 DPRINTF_PSTATE("change_pstate: switching regs old=%x new=%x\n",
328 pstate_regs
, new_pstate_regs
);
329 /* Switch global register bank */
330 src
= get_gregset(env
, new_pstate_regs
);
331 dst
= get_gregset(env
, pstate_regs
);
332 memcpy32(dst
, env
->gregs
);
333 memcpy32(env
->gregs
, src
);
335 DPRINTF_PSTATE("change_pstate: regs new=%x (unchanged)\n",
338 env
->pstate
= new_pstate
;
341 void helper_wrpstate(CPUState
*env
, target_ulong new_state
)
343 cpu_change_pstate(env
, new_state
& 0xf3f);
345 #if !defined(CONFIG_USER_ONLY)
346 if (cpu_interrupts_enabled(env
)) {
352 void helper_wrpil(CPUState
*env
, target_ulong new_pil
)
354 #if !defined(CONFIG_USER_ONLY)
355 DPRINTF_PSTATE("helper_wrpil old=%x new=%x\n",
356 env
->psrpil
, (uint32_t)new_pil
);
358 env
->psrpil
= new_pil
;
360 if (cpu_interrupts_enabled(env
)) {
366 void helper_done(CPUState
*env
)
368 trap_state
*tsptr
= cpu_tsptr(env
);
370 env
->pc
= tsptr
->tnpc
;
371 env
->npc
= tsptr
->tnpc
+ 4;
372 cpu_put_ccr(env
, tsptr
->tstate
>> 32);
373 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
374 cpu_change_pstate(env
, (tsptr
->tstate
>> 8) & 0xf3f);
375 cpu_put_cwp64(env
, tsptr
->tstate
& 0xff);
378 DPRINTF_PSTATE("... helper_done tl=%d\n", env
->tl
);
380 #if !defined(CONFIG_USER_ONLY)
381 if (cpu_interrupts_enabled(env
)) {
387 void helper_retry(CPUState
*env
)
389 trap_state
*tsptr
= cpu_tsptr(env
);
391 env
->pc
= tsptr
->tpc
;
392 env
->npc
= tsptr
->tnpc
;
393 cpu_put_ccr(env
, tsptr
->tstate
>> 32);
394 env
->asi
= (tsptr
->tstate
>> 24) & 0xff;
395 cpu_change_pstate(env
, (tsptr
->tstate
>> 8) & 0xf3f);
396 cpu_put_cwp64(env
, tsptr
->tstate
& 0xff);
399 DPRINTF_PSTATE("... helper_retry tl=%d\n", env
->tl
);
401 #if !defined(CONFIG_USER_ONLY)
402 if (cpu_interrupts_enabled(env
)) {