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"
13 #include "tcg/tcg-internal.h"
17 * MMU types, the first four entries have the same layout as the
22 MMU_TYPE_R4000
= 1, /* Standard TLB */
23 MMU_TYPE_BAT
= 2, /* Block Address Translation */
24 MMU_TYPE_FMT
= 3, /* Fixed Mapping */
25 MMU_TYPE_DVF
= 4, /* Dual VTLB and FTLB */
39 int32_t CP0_Config4_rw_bitmask
;
41 int32_t CP0_Config5_rw_bitmask
;
43 int32_t CP0_Config6_rw_bitmask
;
45 int32_t CP0_Config7_rw_bitmask
;
46 target_ulong CP0_LLAddr_rw_bitmask
;
50 int32_t CP0_Status_rw_bitmask
;
51 int32_t CP0_TCStatus_rw_bitmask
;
54 int32_t CP1_fcr31_rw_bitmask
;
59 int32_t CP0_SRSConf0_rw_bitmask
;
61 int32_t CP0_SRSConf1_rw_bitmask
;
63 int32_t CP0_SRSConf2_rw_bitmask
;
65 int32_t CP0_SRSConf3_rw_bitmask
;
67 int32_t CP0_SRSConf4_rw_bitmask
;
69 int32_t CP0_PageGrain_rw_bitmask
;
70 int32_t CP0_PageGrain
;
71 target_ulong CP0_EBaseWG_rw_bitmask
;
73 enum mips_mmu_types mmu_type
;
77 extern const char regnames
[32][4];
78 extern const char fregnames
[32][4];
80 extern const struct mips_def_t mips_defs
[];
81 extern const int mips_defs_number
;
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 #define USEG_LIMIT ((target_ulong)(int32_t)0x7FFFFFFFUL)
90 #define KSEG0_BASE ((target_ulong)(int32_t)0x80000000UL)
91 #define KSEG1_BASE ((target_ulong)(int32_t)0xA0000000UL)
92 #define KSEG2_BASE ((target_ulong)(int32_t)0xC0000000UL)
93 #define KSEG3_BASE ((target_ulong)(int32_t)0xE0000000UL)
95 #define KVM_KSEG0_BASE ((target_ulong)(int32_t)0x40000000UL)
96 #define KVM_KSEG2_BASE ((target_ulong)(int32_t)0x60000000UL)
98 #if !defined(CONFIG_USER_ONLY)
110 int get_physical_address(CPUMIPSState
*env
, hwaddr
*physical
,
111 int *prot
, target_ulong real_address
,
112 MMUAccessType access_type
, int mmu_idx
);
113 hwaddr
mips_cpu_get_phys_page_debug(CPUState
*cpu
, vaddr addr
);
115 typedef struct r4k_tlb_t r4k_tlb_t
;
132 unsigned int EHINV
:1;
136 struct CPUMIPSTLBContext
{
139 int (*map_address
)(struct CPUMIPSState
*env
, hwaddr
*physical
, int *prot
,
140 target_ulong address
, MMUAccessType access_type
);
141 void (*helper_tlbwi
)(struct CPUMIPSState
*env
);
142 void (*helper_tlbwr
)(struct CPUMIPSState
*env
);
143 void (*helper_tlbp
)(struct CPUMIPSState
*env
);
144 void (*helper_tlbr
)(struct CPUMIPSState
*env
);
145 void (*helper_tlbinv
)(struct CPUMIPSState
*env
);
146 void (*helper_tlbinvf
)(struct CPUMIPSState
*env
);
149 r4k_tlb_t tlb
[MIPS_TLB_MAX
];
154 void mips_cpu_do_transaction_failed(CPUState
*cs
, hwaddr physaddr
,
155 vaddr addr
, unsigned size
,
156 MMUAccessType access_type
,
157 int mmu_idx
, MemTxAttrs attrs
,
158 MemTxResult response
, uintptr_t retaddr
);
160 void sync_c0_status(CPUMIPSState
*env
, CPUMIPSState
*cpu
, int tc
);
161 void cpu_mips_store_status(CPUMIPSState
*env
, target_ulong val
);
162 void cpu_mips_store_cause(CPUMIPSState
*env
, target_ulong val
);
164 extern const VMStateDescription vmstate_mips_cpu
;
166 #endif /* !CONFIG_USER_ONLY */
168 #define cpu_signal_handler cpu_mips_signal_handler
170 static inline bool cpu_mips_hw_interrupts_enabled(CPUMIPSState
*env
)
172 return (env
->CP0_Status
& (1 << CP0St_IE
)) &&
173 !(env
->CP0_Status
& (1 << CP0St_EXL
)) &&
174 !(env
->CP0_Status
& (1 << CP0St_ERL
)) &&
175 !(env
->hflags
& MIPS_HFLAG_DM
) &&
177 * Note that the TCStatus IXMT field is initialized to zero,
178 * and only MT capable cores can set it to one. So we don't
179 * need to check for MT capabilities here.
181 !(env
->active_tc
.CP0_TCStatus
& (1 << CP0TCSt_IXMT
));
184 /* Check if there is pending and not masked out interrupt */
185 static inline bool cpu_mips_hw_interrupts_pending(CPUMIPSState
*env
)
191 pending
= env
->CP0_Cause
& CP0Ca_IP_mask
;
192 status
= env
->CP0_Status
& CP0Ca_IP_mask
;
194 if (env
->CP0_Config3
& (1 << CP0C3_VEIC
)) {
196 * A MIPS configured with a vectorizing external interrupt controller
197 * will feed a vector into the Cause pending lines. The core treats
198 * the status lines as a vector level, not as individual masks.
200 r
= pending
> status
;
203 * A MIPS configured with compatibility or VInt (Vectored Interrupts)
204 * treats the pending lines as individual interrupt lines, the status
205 * lines are individual masks.
207 r
= (pending
& status
) != 0;
212 void mips_tcg_init(void);
214 void msa_reset(CPUMIPSState
*env
);
217 uint32_t cpu_mips_get_count(CPUMIPSState
*env
);
218 void cpu_mips_store_count(CPUMIPSState
*env
, uint32_t value
);
219 void cpu_mips_store_compare(CPUMIPSState
*env
, uint32_t value
);
220 void cpu_mips_start_count(CPUMIPSState
*env
);
221 void cpu_mips_stop_count(CPUMIPSState
*env
);
223 static inline void mips_env_set_pc(CPUMIPSState
*env
, target_ulong value
)
225 env
->active_tc
.PC
= value
& ~(target_ulong
)1;
227 env
->hflags
|= MIPS_HFLAG_M16
;
229 env
->hflags
&= ~(MIPS_HFLAG_M16
);
233 static inline void restore_pamask(CPUMIPSState
*env
)
235 if (env
->hflags
& MIPS_HFLAG_ELPA
) {
236 env
->PAMask
= (1ULL << env
->PABITS
) - 1;
238 env
->PAMask
= PAMASK_BASE
;
242 static inline int mips_vpe_active(CPUMIPSState
*env
)
246 /* Check that the VPE is enabled. */
247 if (!(env
->mvp
->CP0_MVPControl
& (1 << CP0MVPCo_EVP
))) {
250 /* Check that the VPE is activated. */
251 if (!(env
->CP0_VPEConf0
& (1 << CP0VPEC0_VPA
))) {
256 * Now verify that there are active thread contexts in the VPE.
258 * This assumes the CPU model will internally reschedule threads
259 * if the active one goes to sleep. If there are no threads available
260 * the active one will be in a sleeping state, and we can turn off
263 if (!(env
->active_tc
.CP0_TCStatus
& (1 << CP0TCSt_A
))) {
264 /* TC is not activated. */
267 if (env
->active_tc
.CP0_TCHalt
& 1) {
268 /* TC is in halt state. */
275 static inline int mips_vp_active(CPUMIPSState
*env
)
277 CPUState
*other_cs
= first_cpu
;
279 /* Check if the VP disabled other VPs (which means the VP is enabled) */
280 if ((env
->CP0_VPControl
>> CP0VPCtl_DIS
) & 1) {
284 /* Check if the virtual processor is disabled due to a DVP */
285 CPU_FOREACH(other_cs
) {
286 MIPSCPU
*other_cpu
= MIPS_CPU(other_cs
);
287 if ((&other_cpu
->env
!= env
) &&
288 ((other_cpu
->env
.CP0_VPControl
>> CP0VPCtl_DIS
) & 1)) {
295 static inline void compute_hflags(CPUMIPSState
*env
)
297 env
->hflags
&= ~(MIPS_HFLAG_COP1X
| MIPS_HFLAG_64
| MIPS_HFLAG_CP0
|
298 MIPS_HFLAG_F64
| MIPS_HFLAG_FPU
| MIPS_HFLAG_KSU
|
299 MIPS_HFLAG_AWRAP
| MIPS_HFLAG_DSP
| MIPS_HFLAG_DSP_R2
|
300 MIPS_HFLAG_DSP_R3
| MIPS_HFLAG_SBRI
| MIPS_HFLAG_MSA
|
301 MIPS_HFLAG_FRE
| MIPS_HFLAG_ELPA
| MIPS_HFLAG_ERL
);
302 if (env
->CP0_Status
& (1 << CP0St_ERL
)) {
303 env
->hflags
|= MIPS_HFLAG_ERL
;
305 if (!(env
->CP0_Status
& (1 << CP0St_EXL
)) &&
306 !(env
->CP0_Status
& (1 << CP0St_ERL
)) &&
307 !(env
->hflags
& MIPS_HFLAG_DM
)) {
308 env
->hflags
|= (env
->CP0_Status
>> CP0St_KSU
) &
311 #if defined(TARGET_MIPS64)
312 if ((env
->insn_flags
& ISA_MIPS3
) &&
313 (((env
->hflags
& MIPS_HFLAG_KSU
) != MIPS_HFLAG_UM
) ||
314 (env
->CP0_Status
& (1 << CP0St_PX
)) ||
315 (env
->CP0_Status
& (1 << CP0St_UX
)))) {
316 env
->hflags
|= MIPS_HFLAG_64
;
319 if (!(env
->insn_flags
& ISA_MIPS3
)) {
320 env
->hflags
|= MIPS_HFLAG_AWRAP
;
321 } else if (((env
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_UM
) &&
322 !(env
->CP0_Status
& (1 << CP0St_UX
))) {
323 env
->hflags
|= MIPS_HFLAG_AWRAP
;
324 } else if (env
->insn_flags
& ISA_MIPS_R6
) {
325 /* Address wrapping for Supervisor and Kernel is specified in R6 */
326 if ((((env
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_SM
) &&
327 !(env
->CP0_Status
& (1 << CP0St_SX
))) ||
328 (((env
->hflags
& MIPS_HFLAG_KSU
) == MIPS_HFLAG_KM
) &&
329 !(env
->CP0_Status
& (1 << CP0St_KX
)))) {
330 env
->hflags
|= MIPS_HFLAG_AWRAP
;
334 if (((env
->CP0_Status
& (1 << CP0St_CU0
)) &&
335 !(env
->insn_flags
& ISA_MIPS_R6
)) ||
336 !(env
->hflags
& MIPS_HFLAG_KSU
)) {
337 env
->hflags
|= MIPS_HFLAG_CP0
;
339 if (env
->CP0_Status
& (1 << CP0St_CU1
)) {
340 env
->hflags
|= MIPS_HFLAG_FPU
;
342 if (env
->CP0_Status
& (1 << CP0St_FR
)) {
343 env
->hflags
|= MIPS_HFLAG_F64
;
345 if (((env
->hflags
& MIPS_HFLAG_KSU
) != MIPS_HFLAG_KM
) &&
346 (env
->CP0_Config5
& (1 << CP0C5_SBRI
))) {
347 env
->hflags
|= MIPS_HFLAG_SBRI
;
349 if (env
->insn_flags
& ASE_DSP_R3
) {
351 * Our cpu supports DSP R3 ASE, so enable
352 * access to DSP R3 resources.
354 if (env
->CP0_Status
& (1 << CP0St_MX
)) {
355 env
->hflags
|= MIPS_HFLAG_DSP
| MIPS_HFLAG_DSP_R2
|
358 } else if (env
->insn_flags
& ASE_DSP_R2
) {
360 * Our cpu supports DSP R2 ASE, so enable
361 * access to DSP R2 resources.
363 if (env
->CP0_Status
& (1 << CP0St_MX
)) {
364 env
->hflags
|= MIPS_HFLAG_DSP
| MIPS_HFLAG_DSP_R2
;
367 } else if (env
->insn_flags
& ASE_DSP
) {
369 * Our cpu supports DSP ASE, so enable
370 * access to DSP resources.
372 if (env
->CP0_Status
& (1 << CP0St_MX
)) {
373 env
->hflags
|= MIPS_HFLAG_DSP
;
377 if (env
->insn_flags
& ISA_MIPS_R2
) {
378 if (env
->active_fpu
.fcr0
& (1 << FCR0_F64
)) {
379 env
->hflags
|= MIPS_HFLAG_COP1X
;
381 } else if (env
->insn_flags
& ISA_MIPS_R1
) {
382 if (env
->hflags
& MIPS_HFLAG_64
) {
383 env
->hflags
|= MIPS_HFLAG_COP1X
;
385 } else if (env
->insn_flags
& ISA_MIPS4
) {
387 * All supported MIPS IV CPUs use the XX (CU3) to enable
388 * and disable the MIPS IV extensions to the MIPS III ISA.
389 * Some other MIPS IV CPUs ignore the bit, so the check here
390 * would be too restrictive for them.
392 if (env
->CP0_Status
& (1U << CP0St_CU3
)) {
393 env
->hflags
|= MIPS_HFLAG_COP1X
;
396 if (ase_msa_available(env
)) {
397 if (env
->CP0_Config5
& (1 << CP0C5_MSAEn
)) {
398 env
->hflags
|= MIPS_HFLAG_MSA
;
401 if (env
->active_fpu
.fcr0
& (1 << FCR0_FREP
)) {
402 if (env
->CP0_Config5
& (1 << CP0C5_FRE
)) {
403 env
->hflags
|= MIPS_HFLAG_FRE
;
406 if (env
->CP0_Config3
& (1 << CP0C3_LPA
)) {
407 if (env
->CP0_PageGrain
& (1 << CP0PG_ELPA
)) {
408 env
->hflags
|= MIPS_HFLAG_ELPA
;