6 #if !defined(TARGET_SPARC64)
7 #define TARGET_LONG_BITS 32
8 #define TARGET_FPREGS 32
9 #define TARGET_PAGE_BITS 12 /* 4k */
11 #define TARGET_LONG_BITS 64
12 #define TARGET_FPREGS 64
13 #define TARGET_PAGE_BITS 13 /* 8k */
16 #define TARGET_PHYS_ADDR_BITS 64
18 #define CPUState struct CPUSPARCState
22 #include "softfloat.h"
24 #define TARGET_HAS_ICE 1
26 #if !defined(TARGET_SPARC64)
27 #define ELF_MACHINE EM_SPARC
29 #define ELF_MACHINE EM_SPARCV9
32 /*#define EXCP_INTERRUPT 0x100*/
34 /* trap definitions */
35 #ifndef TARGET_SPARC64
36 #define TT_TFAULT 0x01
37 #define TT_ILL_INSN 0x02
38 #define TT_PRIV_INSN 0x03
39 #define TT_NFPU_INSN 0x04
40 #define TT_WIN_OVF 0x05
41 #define TT_WIN_UNF 0x06
42 #define TT_UNALIGNED 0x07
43 #define TT_FP_EXCP 0x08
44 #define TT_DFAULT 0x09
46 #define TT_EXTINT 0x10
47 #define TT_CODE_ACCESS 0x21
48 #define TT_UNIMP_FLUSH 0x25
49 #define TT_DATA_ACCESS 0x29
50 #define TT_DIV_ZERO 0x2a
51 #define TT_NCP_INSN 0x24
54 #define TT_TFAULT 0x08
55 #define TT_CODE_ACCESS 0x0a
56 #define TT_ILL_INSN 0x10
57 #define TT_UNIMP_FLUSH TT_ILL_INSN
58 #define TT_PRIV_INSN 0x11
59 #define TT_NFPU_INSN 0x20
60 #define TT_FP_EXCP 0x21
62 #define TT_CLRWIN 0x24
63 #define TT_DIV_ZERO 0x28
64 #define TT_DFAULT 0x30
65 #define TT_DATA_ACCESS 0x32
66 #define TT_UNALIGNED 0x34
67 #define TT_PRIV_ACT 0x37
68 #define TT_EXTINT 0x40
75 #define TT_WOTHER 0x10
79 #define PSR_NEG_SHIFT 23
80 #define PSR_NEG (1 << PSR_NEG_SHIFT)
81 #define PSR_ZERO_SHIFT 22
82 #define PSR_ZERO (1 << PSR_ZERO_SHIFT)
83 #define PSR_OVF_SHIFT 21
84 #define PSR_OVF (1 << PSR_OVF_SHIFT)
85 #define PSR_CARRY_SHIFT 20
86 #define PSR_CARRY (1 << PSR_CARRY_SHIFT)
87 #define PSR_ICC (PSR_NEG|PSR_ZERO|PSR_OVF|PSR_CARRY)
88 #define PSR_EF (1<<12)
95 #define CC_SRC (env->cc_src)
96 #define CC_SRC2 (env->cc_src2)
97 #define CC_DST (env->cc_dst)
98 #define CC_OP (env->cc_op)
101 CC_OP_DYNAMIC
, /* must use dynamic code to get cc_op */
102 CC_OP_FLAGS
, /* all cc are back in status register */
103 CC_OP_DIV
, /* modify N, Z and V, C = 0*/
104 CC_OP_ADD
, /* modify all flags, CC_DST = res, CC_SRC = src1 */
105 CC_OP_ADDX
, /* modify all flags, CC_DST = res, CC_SRC = src1 */
106 CC_OP_TADD
, /* modify all flags, CC_DST = res, CC_SRC = src1 */
107 CC_OP_TADDTV
, /* modify all flags except V, CC_DST = res, CC_SRC = src1 */
108 CC_OP_SUB
, /* modify all flags, CC_DST = res, CC_SRC = src1 */
109 CC_OP_SUBX
, /* modify all flags, CC_DST = res, CC_SRC = src1 */
110 CC_OP_TSUB
, /* modify all flags, CC_DST = res, CC_SRC = src1 */
111 CC_OP_TSUBTV
, /* modify all flags except V, CC_DST = res, CC_SRC = src1 */
112 CC_OP_LOGIC
, /* modify N and Z, C = V = 0, CC_DST = res */
116 /* Trap base register */
117 #define TBR_BASE_MASK 0xfffff000
119 #if defined(TARGET_SPARC64)
120 #define PS_IG (1<<11)
121 #define PS_MG (1<<10)
122 #define PS_RMO (1<<7)
123 #define PS_RED (1<<5)
124 #define PS_PEF (1<<4)
126 #define PS_PRIV (1<<2)
130 #define FPRS_FEF (1<<2)
132 #define HS_PRIV (1<<2)
136 #define FSR_RD1 (1ULL << 31)
137 #define FSR_RD0 (1ULL << 30)
138 #define FSR_RD_MASK (FSR_RD1 | FSR_RD0)
139 #define FSR_RD_NEAREST 0
140 #define FSR_RD_ZERO FSR_RD0
141 #define FSR_RD_POS FSR_RD1
142 #define FSR_RD_NEG (FSR_RD1 | FSR_RD0)
144 #define FSR_NVM (1ULL << 27)
145 #define FSR_OFM (1ULL << 26)
146 #define FSR_UFM (1ULL << 25)
147 #define FSR_DZM (1ULL << 24)
148 #define FSR_NXM (1ULL << 23)
149 #define FSR_TEM_MASK (FSR_NVM | FSR_OFM | FSR_UFM | FSR_DZM | FSR_NXM)
151 #define FSR_NVA (1ULL << 9)
152 #define FSR_OFA (1ULL << 8)
153 #define FSR_UFA (1ULL << 7)
154 #define FSR_DZA (1ULL << 6)
155 #define FSR_NXA (1ULL << 5)
156 #define FSR_AEXC_MASK (FSR_NVA | FSR_OFA | FSR_UFA | FSR_DZA | FSR_NXA)
158 #define FSR_NVC (1ULL << 4)
159 #define FSR_OFC (1ULL << 3)
160 #define FSR_UFC (1ULL << 2)
161 #define FSR_DZC (1ULL << 1)
162 #define FSR_NXC (1ULL << 0)
163 #define FSR_CEXC_MASK (FSR_NVC | FSR_OFC | FSR_UFC | FSR_DZC | FSR_NXC)
165 #define FSR_FTT2 (1ULL << 16)
166 #define FSR_FTT1 (1ULL << 15)
167 #define FSR_FTT0 (1ULL << 14)
168 //gcc warns about constant overflow for ~FSR_FTT_MASK
169 //#define FSR_FTT_MASK (FSR_FTT2 | FSR_FTT1 | FSR_FTT0)
170 #ifdef TARGET_SPARC64
171 #define FSR_FTT_NMASK 0xfffffffffffe3fffULL
172 #define FSR_FTT_CEXC_NMASK 0xfffffffffffe3fe0ULL
173 #define FSR_LDFSR_OLDMASK 0x0000003f000fc000ULL
174 #define FSR_LDXFSR_MASK 0x0000003fcfc00fffULL
175 #define FSR_LDXFSR_OLDMASK 0x00000000000fc000ULL
177 #define FSR_FTT_NMASK 0xfffe3fffULL
178 #define FSR_FTT_CEXC_NMASK 0xfffe3fe0ULL
179 #define FSR_LDFSR_OLDMASK 0x000fc000ULL
181 #define FSR_LDFSR_MASK 0xcfc00fffULL
182 #define FSR_FTT_IEEE_EXCP (1ULL << 14)
183 #define FSR_FTT_UNIMPFPOP (3ULL << 14)
184 #define FSR_FTT_SEQ_ERROR (4ULL << 14)
185 #define FSR_FTT_INVAL_FPR (6ULL << 14)
187 #define FSR_FCC1_SHIFT 11
188 #define FSR_FCC1 (1ULL << FSR_FCC1_SHIFT)
189 #define FSR_FCC0_SHIFT 10
190 #define FSR_FCC0 (1ULL << FSR_FCC0_SHIFT)
194 #define MMU_NF (1<<1)
196 #define PTE_ENTRYTYPE_MASK 3
197 #define PTE_ACCESS_MASK 0x1c
198 #define PTE_ACCESS_SHIFT 2
199 #define PTE_PPN_SHIFT 7
200 #define PTE_ADDR_MASK 0xffffff00
202 #define PG_ACCESSED_BIT 5
203 #define PG_MODIFIED_BIT 6
204 #define PG_CACHE_BIT 7
206 #define PG_ACCESSED_MASK (1 << PG_ACCESSED_BIT)
207 #define PG_MODIFIED_MASK (1 << PG_MODIFIED_BIT)
208 #define PG_CACHE_MASK (1 << PG_CACHE_BIT)
210 /* 3 <= NWINDOWS <= 32. */
211 #define MIN_NWINDOWS 3
212 #define MAX_NWINDOWS 32
214 #if !defined(TARGET_SPARC64)
215 #define NB_MMU_MODES 2
217 #define NB_MMU_MODES 3
218 typedef struct trap_state
{
226 typedef struct sparc_def_t
{
228 target_ulong iu_version
;
229 uint32_t fpu_version
;
230 uint32_t mmu_version
;
232 uint32_t mmu_ctpr_mask
;
233 uint32_t mmu_cxr_mask
;
234 uint32_t mmu_sfsr_mask
;
235 uint32_t mmu_trcr_mask
;
236 uint32_t mxcc_version
;
242 #define CPU_FEATURE_FLOAT (1 << 0)
243 #define CPU_FEATURE_FLOAT128 (1 << 1)
244 #define CPU_FEATURE_SWAP (1 << 2)
245 #define CPU_FEATURE_MUL (1 << 3)
246 #define CPU_FEATURE_DIV (1 << 4)
247 #define CPU_FEATURE_FLUSH (1 << 5)
248 #define CPU_FEATURE_FSQRT (1 << 6)
249 #define CPU_FEATURE_FMUL (1 << 7)
250 #define CPU_FEATURE_VIS1 (1 << 8)
251 #define CPU_FEATURE_VIS2 (1 << 9)
252 #define CPU_FEATURE_FSMULD (1 << 10)
253 #define CPU_FEATURE_HYPV (1 << 11)
254 #define CPU_FEATURE_CMT (1 << 12)
255 #define CPU_FEATURE_GL (1 << 13)
256 #ifndef TARGET_SPARC64
257 #define CPU_DEFAULT_FEATURES (CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | \
258 CPU_FEATURE_MUL | CPU_FEATURE_DIV | \
259 CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT | \
260 CPU_FEATURE_FMUL | CPU_FEATURE_FSMULD)
262 #define CPU_DEFAULT_FEATURES (CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP | \
263 CPU_FEATURE_MUL | CPU_FEATURE_DIV | \
264 CPU_FEATURE_FLUSH | CPU_FEATURE_FSQRT | \
265 CPU_FEATURE_FMUL | CPU_FEATURE_VIS1 | \
266 CPU_FEATURE_VIS2 | CPU_FEATURE_FSMULD)
268 mmu_us_12
, // Ultrasparc < III (64 entry TLB)
269 mmu_us_3
, // Ultrasparc III (512 entry TLB)
270 mmu_us_4
, // Ultrasparc IV (several TLBs, 32 and 256MB pages)
275 typedef struct CPUSPARCState
{
276 target_ulong gregs
[8]; /* general registers */
277 target_ulong
*regwptr
; /* pointer to current register window */
278 target_ulong pc
; /* program counter */
279 target_ulong npc
; /* next program counter */
280 target_ulong y
; /* multiply/divide register */
282 /* emulator internal flags handling */
283 target_ulong cc_src
, cc_src2
;
287 target_ulong t0
, t1
; /* temporaries live across basic blocks */
288 target_ulong cond
; /* conditional branch result (XXX: save it in a
289 temporary register when possible) */
291 uint32_t psr
; /* processor state register */
292 target_ulong fsr
; /* FPU state register */
293 float32 fpr
[TARGET_FPREGS
]; /* floating point registers */
294 uint32_t cwp
; /* index of current register window (extracted
296 uint32_t wim
; /* window invalid mask */
297 target_ulong tbr
; /* trap base register */
298 int psrs
; /* supervisor mode (extracted from PSR) */
299 int psrps
; /* previous supervisor mode */
300 int psret
; /* enable traps */
301 uint32_t psrpil
; /* interrupt blocking level */
302 uint32_t pil_in
; /* incoming interrupt level bitmap */
303 int psref
; /* enable fpu */
304 target_ulong version
;
307 /* NOTE: we allow 8 more registers to handle wrapping */
308 target_ulong regbase
[MAX_NWINDOWS
* 16 + 8];
313 #if defined(TARGET_SPARC64)
317 uint64_t immuregs
[16];
318 uint64_t dmmuregs
[16];
319 uint64_t itlb_tag
[64];
320 uint64_t itlb_tte
[64];
321 uint64_t dtlb_tag
[64];
322 uint64_t dtlb_tte
[64];
323 uint32_t mmu_version
;
325 uint32_t mmuregs
[32];
326 uint64_t mxccdata
[4];
327 uint64_t mxccregs
[8];
328 uint64_t mmubpregs
[4];
331 /* temporary float registers */
334 float_status fp_status
;
335 #if defined(TARGET_SPARC64)
337 #define MAXTL_MASK (MAXTL_MAX - 1)
339 trap_state ts
[MAXTL_MAX
];
340 uint32_t xcc
; /* Extended integer condition codes */
345 uint32_t cansave
, canrestore
, otherwin
, wstate
, cleanwin
;
346 uint64_t agregs
[8]; /* alternate general registers */
347 uint64_t bgregs
[8]; /* backup for normal global registers */
348 uint64_t igregs
[8]; /* interrupt general registers */
349 uint64_t mgregs
[8]; /* mmu general registers */
351 uint64_t tick_cmpr
, stick_cmpr
;
354 uint32_t gl
; // UA2005
355 /* UA 2005 hyperprivileged registers */
356 uint64_t hpstate
, htstate
[MAXTL_MAX
], hintp
, htba
, hver
, hstick_cmpr
, ssr
;
357 void *hstick
; // UA 2005
359 #define SOFTINT_TIMER 1
360 #define SOFTINT_STIMER (1 << 16)
366 CPUSPARCState
*cpu_sparc_init(const char *cpu_model
);
367 void cpu_sparc_set_id(CPUSPARCState
*env
, unsigned int cpu
);
368 void sparc_cpu_list (FILE *f
, int (*cpu_fprintf
)(FILE *f
, const char *fmt
,
371 void cpu_unlock(void);
372 int cpu_sparc_handle_mmu_fault(CPUSPARCState
*env1
, target_ulong address
, int rw
,
373 int mmu_idx
, int is_softmmu
);
374 target_ulong
mmu_probe(CPUSPARCState
*env
, target_ulong address
, int mmulev
);
375 void dump_mmu(CPUSPARCState
*env
);
378 void gen_intermediate_code_init(CPUSPARCState
*env
);
381 int cpu_sparc_exec(CPUSPARCState
*s
);
383 #define GET_PSR(env) (env->version | (env->psr & PSR_ICC) | \
384 (env->psref? PSR_EF : 0) | \
385 (env->psrpil << 8) | \
386 (env->psrs? PSR_S : 0) | \
387 (env->psrps? PSR_PS : 0) | \
388 (env->psret? PSR_ET : 0) | env->cwp)
390 #ifndef NO_CPU_IO_DEFS
391 static inline void memcpy32(target_ulong
*dst
, const target_ulong
*src
)
403 static inline void cpu_set_cwp(CPUSPARCState
*env1
, int new_cwp
)
405 /* put the modified wrap registers at their proper location */
406 if (env1
->cwp
== env1
->nwindows
- 1)
407 memcpy32(env1
->regbase
, env1
->regbase
+ env1
->nwindows
* 16);
409 /* put the wrap registers at their temporary location */
410 if (new_cwp
== env1
->nwindows
- 1)
411 memcpy32(env1
->regbase
+ env1
->nwindows
* 16, env1
->regbase
);
412 env1
->regwptr
= env1
->regbase
+ (new_cwp
* 16);
415 static inline int cpu_cwp_inc(CPUSPARCState
*env1
, int cwp
)
417 if (unlikely(cwp
>= env1
->nwindows
))
418 cwp
-= env1
->nwindows
;
422 static inline int cpu_cwp_dec(CPUSPARCState
*env1
, int cwp
)
424 if (unlikely(cwp
< 0))
425 cwp
+= env1
->nwindows
;
430 #define PUT_PSR(env, val) do { int _tmp = val; \
431 env->psr = _tmp & PSR_ICC; \
432 env->psref = (_tmp & PSR_EF)? 1 : 0; \
433 env->psrpil = (_tmp & PSR_PIL) >> 8; \
434 env->psrs = (_tmp & PSR_S)? 1 : 0; \
435 env->psrps = (_tmp & PSR_PS)? 1 : 0; \
436 env->psret = (_tmp & PSR_ET)? 1 : 0; \
437 cpu_set_cwp(env, _tmp & PSR_CWP); \
438 CC_OP = CC_OP_FLAGS; \
441 #ifdef TARGET_SPARC64
442 #define GET_CCR(env) (((env->xcc >> 20) << 4) | ((env->psr & PSR_ICC) >> 20))
443 #define PUT_CCR(env, val) do { int _tmp = val; \
444 env->xcc = (_tmp >> 4) << 20; \
445 env->psr = (_tmp & 0xf) << 20; \
446 CC_OP = CC_OP_FLAGS; \
448 #define GET_CWP64(env) (env->nwindows - 1 - (env)->cwp)
450 #ifndef NO_CPU_IO_DEFS
451 static inline void PUT_CWP64(CPUSPARCState
*env1
, int cwp
)
453 if (unlikely(cwp
>= env1
->nwindows
|| cwp
< 0))
455 cpu_set_cwp(env1
, env1
->nwindows
- 1 - cwp
);
461 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
462 int is_asi
, int size
);
463 int cpu_sparc_signal_handler(int host_signum
, void *pinfo
, void *puc
);
465 #define cpu_init cpu_sparc_init
466 #define cpu_exec cpu_sparc_exec
467 #define cpu_gen_code cpu_sparc_gen_code
468 #define cpu_signal_handler cpu_sparc_signal_handler
469 #define cpu_list sparc_cpu_list
471 #define CPU_SAVE_VERSION 5
473 /* MMU modes definitions */
474 #define MMU_MODE0_SUFFIX _user
475 #define MMU_MODE1_SUFFIX _kernel
476 #ifdef TARGET_SPARC64
477 #define MMU_MODE2_SUFFIX _hypv
479 #define MMU_USER_IDX 0
480 #define MMU_KERNEL_IDX 1
481 #define MMU_HYPV_IDX 2
483 static inline int cpu_mmu_index(CPUState
*env1
)
485 #if defined(CONFIG_USER_ONLY)
487 #elif !defined(TARGET_SPARC64)
492 else if ((env1
->hpstate
& HS_PRIV
) == 0)
493 return MMU_KERNEL_IDX
;
499 static inline int cpu_fpu_enabled(CPUState
*env1
)
501 #if defined(CONFIG_USER_ONLY)
503 #elif !defined(TARGET_SPARC64)
506 return ((env1
->pstate
& PS_PEF
) != 0) && ((env1
->fprs
& FPRS_FEF
) != 0);
510 #if defined(CONFIG_USER_ONLY)
511 static inline void cpu_clone_regs(CPUState
*env
, target_ulong newsp
)
514 env
->regwptr
[22] = newsp
;
516 /* FIXME: Do we also need to clear CF? */
518 printf ("HELPME: %s:%d\n", __FILE__
, __LINE__
);
523 #include "exec-all.h"
525 /* sum4m.c, sun4u.c */
526 void cpu_check_irqs(CPUSPARCState
*env
);
528 #ifdef TARGET_SPARC64
530 void cpu_tick_set_count(void *opaque
, uint64_t count
);
531 uint64_t cpu_tick_get_count(void *opaque
);
532 void cpu_tick_set_limit(void *opaque
, uint64_t limit
);
535 static inline void cpu_pc_from_tb(CPUState
*env
, TranslationBlock
*tb
)
538 env
->npc
= tb
->cs_base
;
541 static inline void cpu_get_tb_cpu_state(CPUState
*env
, target_ulong
*pc
,
542 target_ulong
*cs_base
, int *flags
)
546 #ifdef TARGET_SPARC64
547 // AM . Combined FPU enable bits . PRIV . DMMU enabled . IMMU enabled
548 *flags
= ((env
->pstate
& PS_AM
) << 2)
549 | (((env
->pstate
& PS_PEF
) >> 1) | ((env
->fprs
& FPRS_FEF
) << 2))
550 | (env
->pstate
& PS_PRIV
) | ((env
->lsu
& (DMMU_E
| IMMU_E
)) >> 2);
552 // FPU enable . Supervisor
553 *flags
= (env
->psref
<< 4) | env
->psrs
;