2 * MIPS internal definitions and helpers
4 * This work is licensed under the terms of the GNU GPL, version 2 or later.
5 * See the COPYING file in the top-level directory.
8 #ifndef MIPS_INTERNAL_H
9 #define MIPS_INTERNAL_H
11 #include "exec/memattrs.h"
14 * MMU types, the first four entries have the same layout as the
19 MMU_TYPE_R4000
= 1, /* Standard TLB */
20 MMU_TYPE_BAT
= 2, /* Block Address Translation */
21 MMU_TYPE_FMT
= 3, /* Fixed Mapping */
22 MMU_TYPE_DVF
= 4, /* Dual VTLB and FTLB */
36 int32_t CP0_Config4_rw_bitmask
;
38 int32_t CP0_Config5_rw_bitmask
;
40 int32_t CP0_Config6_rw_bitmask
;
42 int32_t CP0_Config7_rw_bitmask
;
43 target_ulong CP0_LLAddr_rw_bitmask
;
47 int32_t CP0_Status_rw_bitmask
;
48 int32_t CP0_TCStatus_rw_bitmask
;
51 int32_t CP1_fcr31_rw_bitmask
;
56 int32_t CP0_SRSConf0_rw_bitmask
;
58 int32_t CP0_SRSConf1_rw_bitmask
;
60 int32_t CP0_SRSConf2_rw_bitmask
;
62 int32_t CP0_SRSConf3_rw_bitmask
;
64 int32_t CP0_SRSConf4_rw_bitmask
;
66 int32_t CP0_PageGrain_rw_bitmask
;
67 int32_t CP0_PageGrain
;
68 target_ulong CP0_EBaseWG_rw_bitmask
;
70 enum mips_mmu_types mmu_type
;
74 extern const char regnames
[32][4];
75 extern const char fregnames
[32][4];
77 extern const struct mips_def_t mips_defs
[];
78 extern const int mips_defs_number
;
80 void mips_cpu_do_interrupt(CPUState
*cpu
);
81 bool mips_cpu_exec_interrupt(CPUState
*cpu
, int int_req
);
82 hwaddr
mips_cpu_get_phys_page_debug(CPUState
*cpu
, vaddr addr
);
83 int mips_cpu_gdb_read_register(CPUState
*cpu
, GByteArray
*buf
, int reg
);
84 int mips_cpu_gdb_write_register(CPUState
*cpu
, uint8_t *buf
, int reg
);
85 void mips_cpu_do_unaligned_access(CPUState
*cpu
, vaddr addr
,
86 MMUAccessType access_type
,
87 int mmu_idx
, uintptr_t retaddr
);
89 #if !defined(CONFIG_USER_ONLY)
91 typedef struct r4k_tlb_t r4k_tlb_t
;
108 unsigned int EHINV
:1;
112 struct CPUMIPSTLBContext
{
115 int (*map_address
)(struct CPUMIPSState
*env
, hwaddr
*physical
, int *prot
,
116 target_ulong address
, MMUAccessType access_type
);
117 void (*helper_tlbwi
)(struct CPUMIPSState
*env
);
118 void (*helper_tlbwr
)(struct CPUMIPSState
*env
);
119 void (*helper_tlbp
)(struct CPUMIPSState
*env
);
120 void (*helper_tlbr
)(struct CPUMIPSState
*env
);
121 void (*helper_tlbinv
)(struct CPUMIPSState
*env
);
122 void (*helper_tlbinvf
)(struct CPUMIPSState
*env
);
125 r4k_tlb_t tlb
[MIPS_TLB_MAX
];
130 int no_mmu_map_address(CPUMIPSState
*env
, hwaddr
*physical
, int *prot
,
131 target_ulong address
, MMUAccessType access_type
);
132 int fixed_mmu_map_address(CPUMIPSState
*env
, hwaddr
*physical
, int *prot
,
133 target_ulong address
, MMUAccessType access_type
);
134 int r4k_map_address(CPUMIPSState
*env
, hwaddr
*physical
, int *prot
,
135 target_ulong address
, MMUAccessType access_type
);
136 void r4k_helper_tlbwi(CPUMIPSState
*env
);
137 void r4k_helper_tlbwr(CPUMIPSState
*env
);
138 void r4k_helper_tlbp(CPUMIPSState
*env
);
139 void r4k_helper_tlbr(CPUMIPSState
*env
);
140 void r4k_helper_tlbinv(CPUMIPSState
*env
);
141 void r4k_helper_tlbinvf(CPUMIPSState
*env
);
142 void r4k_invalidate_tlb(CPUMIPSState
*env
, int idx
, int use_extra
);
143 uint32_t cpu_mips_get_random(CPUMIPSState
*env
);
145 void mips_cpu_do_transaction_failed(CPUState
*cs
, hwaddr physaddr
,
146 vaddr addr
, unsigned size
,
147 MMUAccessType access_type
,
148 int mmu_idx
, MemTxAttrs attrs
,
149 MemTxResult response
, uintptr_t retaddr
);
150 hwaddr
cpu_mips_translate_address(CPUMIPSState
*env
, target_ulong address
,
151 MMUAccessType access_type
);
154 #define cpu_signal_handler cpu_mips_signal_handler
156 #ifndef CONFIG_USER_ONLY
157 extern const VMStateDescription vmstate_mips_cpu
;
160 static inline bool cpu_mips_hw_interrupts_enabled(CPUMIPSState
*env
)
162 return (env
->CP0_Status
& (1 << CP0St_IE
)) &&
163 !(env
->CP0_Status
& (1 << CP0St_EXL
)) &&
164 !(env
->CP0_Status
& (1 << CP0St_ERL
)) &&
165 !(env
->hflags
& MIPS_HFLAG_DM
) &&
167 * Note that the TCStatus IXMT field is initialized to zero,
168 * and only MT capable cores can set it to one. So we don't
169 * need to check for MT capabilities here.
171 !(env
->active_tc
.CP0_TCStatus
& (1 << CP0TCSt_IXMT
));
174 /* Check if there is pending and not masked out interrupt */
175 static inline bool cpu_mips_hw_interrupts_pending(CPUMIPSState
*env
)
181 pending
= env
->CP0_Cause
& CP0Ca_IP_mask
;
182 status
= env
->CP0_Status
& CP0Ca_IP_mask
;
184 if (env
->CP0_Config3
& (1 << CP0C3_VEIC
)) {
186 * A MIPS configured with a vectorizing external interrupt controller
187 * will feed a vector into the Cause pending lines. The core treats
188 * the status lines as a vector level, not as individual masks.
190 r
= pending
> status
;
193 * A MIPS configured with compatibility or VInt (Vectored Interrupts)
194 * treats the pending lines as individual interrupt lines, the status
195 * lines are individual masks.
197 r
= (pending
& status
) != 0;
202 void mips_tcg_init(void);
204 void msa_reset(CPUMIPSState
*env
);
207 uint32_t cpu_mips_get_count(CPUMIPSState
*env
);
208 void cpu_mips_store_count(CPUMIPSState
*env
, uint32_t value
);
209 void cpu_mips_store_compare(CPUMIPSState
*env
, uint32_t value
);
210 void cpu_mips_start_count(CPUMIPSState
*env
);
211 void cpu_mips_stop_count(CPUMIPSState
*env
);
214 void mmu_init(CPUMIPSState
*env
, const mips_def_t
*def
);
215 bool mips_cpu_tlb_fill(CPUState
*cs
, vaddr address
, int size
,
216 MMUAccessType access_type
, int mmu_idx
,
217 bool probe
, uintptr_t retaddr
);
220 void update_pagemask(CPUMIPSState
*env
, target_ulong arg1
, int32_t *pagemask
);
222 static inline void mips_env_set_pc(CPUMIPSState
*env
, target_ulong value
)
224 env
->active_tc
.PC
= value
& ~(target_ulong
)1;
226 env
->hflags
|= MIPS_HFLAG_M16
;
228 env
->hflags
&= ~(MIPS_HFLAG_M16
);
232 static inline void restore_pamask(CPUMIPSState
*env
)
234 if (env
->hflags
& MIPS_HFLAG_ELPA
) {
235 env
->PAMask
= (1ULL << env
->PABITS
) - 1;
237 env
->PAMask
= PAMASK_BASE
;
241 static inline int mips_vpe_active(CPUMIPSState
*env
)
245 /* Check that the VPE is enabled. */
246 if (!(env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_EVP
))) {
249 /* Check that the VPE is activated. */
250 if (!(env
->CP0_VPEConf0
& (1 << CP0VPEC0_VPA
))) {
255 * Now verify that there are active thread contexts in the VPE.
257 * This assumes the CPU model will internally reschedule threads
258 * if the active one goes to sleep. If there are no threads available
259 * the active one will be in a sleeping state, and we can turn off
262 if (!(env
->active_tc
.CP0_TCStatus
& (1 << CP0TCSt_A
))) {
263 /* TC is not activated. */
266 if (env
->active_tc
.CP0_TCHalt
& 1) {
267 /* TC is in halt state. */
274 static inline int mips_vp_active(CPUMIPSState
*env
)
276 CPUState
*other_cs
= first_cpu
;
278 /* Check if the VP disabled other VPs (which means the VP is enabled) */
279 if ((env
->CP0_VPControl
>> CP0VPCtl_DIS
) & 1) {
283 /* Check if the virtual processor is disabled due to a DVP */
284 CPU_FOREACH(other_cs
) {
285 MIPSCPU
*other_cpu
= MIPS_CPU(other_cs
);
286 if ((&other_cpu
->env
!= env
) &&
287 ((other_cpu
->env
.CP0_VPControl
>> CP0VPCtl_DIS
) & 1)) {
294 static inline void compute_hflags(CPUMIPSState
*env
)
296 env
->hflags
&= ~(MIPS_HFLAG_COP1X
| MIPS_HFLAG_64
| MIPS_HFLAG_CP0
|
297 MIPS_HFLAG_F64
| MIPS_HFLAG_FPU
| MIPS_HFLAG_KSU
|
298 MIPS_HFLAG_AWRAP
| MIPS_HFLAG_DSP
| MIPS_HFLAG_DSP_R2
|
299 MIPS_HFLAG_DSP_R3
| MIPS_HFLAG_SBRI
| MIPS_HFLAG_MSA
|
300 MIPS_HFLAG_FRE
| MIPS_HFLAG_ELPA
| MIPS_HFLAG_ERL
);
301 if (env
->CP0_Status
& (1 << CP0St_ERL
)) {
302 env
->hflags
|= MIPS_HFLAG_ERL
;
304 if (!(env
->CP0_Status
& (1 << CP0St_EXL
)) &&
305 !(env
->CP0_Status
& (1 << CP0St_ERL
)) &&
306 !(env
->hflags
& MIPS_HFLAG_DM
)) {
307 env
->hflags
|= (env
->CP0_Status
>> CP0St_KSU
) &
310 #if defined(TARGET_MIPS64)
311 if ((env
->insn_flags
& ISA_MIPS3
) &&
312 (((env
->hflags
& MIPS_HFLAG_KSU
) != MIPS_HFLAG_UM
) ||
313 (env
->CP0_Status
& (1 << CP0St_PX
)) ||
314 (env
->CP0_Status
& (1 << CP0St_UX
)))) {
315 env
->hflags
|= MIPS_HFLAG_64
;
318 if (!(env
->insn_flags
& ISA_MIPS3
)) {
319 env
->hflags
|= MIPS_HFLAG_AWRAP
;
320 } else if (((env
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
321 !(env
->CP0_Status
& (1 << CP0St_UX
))) {
322 env
->hflags
|= MIPS_HFLAG_AWRAP
;
323 } else if (env
->insn_flags
& ISA_MIPS_R6
) {
324 /* Address wrapping for Supervisor and Kernel is specified in R6 */
325 if ((((env
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_SM
) &&
326 !(env
->CP0_Status
& (1 << CP0St_SX
))) ||
327 (((env
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_KM
) &&
328 !(env
->CP0_Status
& (1 << CP0St_KX
)))) {
329 env
->hflags
|= MIPS_HFLAG_AWRAP
;
333 if (((env
->CP0_Status
& (1 << CP0St_CU0
)) &&
334 !(env
->insn_flags
& ISA_MIPS_R6
)) ||
335 !(env
->hflags
& MIPS_HFLAG_KSU
)) {
336 env
->hflags
|= MIPS_HFLAG_CP0
;
338 if (env
->CP0_Status
& (1 << CP0St_CU1
)) {
339 env
->hflags
|= MIPS_HFLAG_FPU
;
341 if (env
->CP0_Status
& (1 << CP0St_FR
)) {
342 env
->hflags
|= MIPS_HFLAG_F64
;
344 if (((env
->hflags
& MIPS_HFLAG_KSU
) != MIPS_HFLAG_KM
) &&
345 (env
->CP0_Config5
& (1 << CP0C5_SBRI
))) {
346 env
->hflags
|= MIPS_HFLAG_SBRI
;
348 if (env
->insn_flags
& ASE_DSP_R3
) {
350 * Our cpu supports DSP R3 ASE, so enable
351 * access to DSP R3 resources.
353 if (env
->CP0_Status
& (1 << CP0St_MX
)) {
354 env
->hflags
|= MIPS_HFLAG_DSP
| MIPS_HFLAG_DSP_R2
|
357 } else if (env
->insn_flags
& ASE_DSP_R2
) {
359 * Our cpu supports DSP R2 ASE, so enable
360 * access to DSP R2 resources.
362 if (env
->CP0_Status
& (1 << CP0St_MX
)) {
363 env
->hflags
|= MIPS_HFLAG_DSP
| MIPS_HFLAG_DSP_R2
;
366 } else if (env
->insn_flags
& ASE_DSP
) {
368 * Our cpu supports DSP ASE, so enable
369 * access to DSP resources.
371 if (env
->CP0_Status
& (1 << CP0St_MX
)) {
372 env
->hflags
|= MIPS_HFLAG_DSP
;
376 if (env
->insn_flags
& ISA_MIPS_R2
) {
377 if (env
->active_fpu
.fcr0
& (1 << FCR0_F64
)) {
378 env
->hflags
|= MIPS_HFLAG_COP1X
;
380 } else if (env
->insn_flags
& ISA_MIPS_R1
) {
381 if (env
->hflags
& MIPS_HFLAG_64
) {
382 env
->hflags
|= MIPS_HFLAG_COP1X
;
384 } else if (env
->insn_flags
& ISA_MIPS4
) {
386 * All supported MIPS IV CPUs use the XX (CU3) to enable
387 * and disable the MIPS IV extensions to the MIPS III ISA.
388 * Some other MIPS IV CPUs ignore the bit, so the check here
389 * would be too restrictive for them.
391 if (env
->CP0_Status
& (1U << CP0St_CU3
)) {
392 env
->hflags
|= MIPS_HFLAG_COP1X
;
395 if (ase_msa_available(env
)) {
396 if (env
->CP0_Config5
& (1 << CP0C5_MSAEn
)) {
397 env
->hflags
|= MIPS_HFLAG_MSA
;
400 if (env
->active_fpu
.fcr0
& (1 << FCR0_FREP
)) {
401 if (env
->CP0_Config5
& (1 << CP0C5_FRE
)) {
402 env
->hflags
|= MIPS_HFLAG_FRE
;
405 if (env
->CP0_Config3
& (1 << CP0C3_LPA
)) {
406 if (env
->CP0_PageGrain
& (1 << CP0PG_ELPA
)) {
407 env
->hflags
|= MIPS_HFLAG_ELPA
;
412 void cpu_mips_tlb_flush(CPUMIPSState
*env
);
413 void sync_c0_status(CPUMIPSState
*env
, CPUMIPSState
*cpu
, int tc
);
414 void cpu_mips_store_status(CPUMIPSState
*env
, target_ulong val
);
415 void cpu_mips_store_cause(CPUMIPSState
*env
, target_ulong val
);
417 const char *mips_exception_name(int32_t exception
);
419 void QEMU_NORETURN
do_raise_exception_err(CPUMIPSState
*env
, uint32_t exception
,
420 int error_code
, uintptr_t pc
);
422 static inline void QEMU_NORETURN
do_raise_exception(CPUMIPSState
*env
,
426 do_raise_exception_err(env
, exception
, 0, pc
);