2 * TriCore emulation for qemu: main CPU struct.
4 * Copyright (c) 2012-2014 Bastian Koppelmann C-Lab/University Paderborn
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.1 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/>.
24 #include "hw/registerfields.h"
25 #include "exec/cpu-defs.h"
26 #include "qemu/cpu-float.h"
27 #include "tricore-defs.h"
29 typedef struct CPUArchState
{
33 /* Frequently accessed PSW_USB bits are stored separately for efficiency.
34 This contains all the other bits. Use psw_{read,write} to access
37 /* PSW flag cache for faster execution */
39 uint32_t PSW_USB_V
; /* Only if bit 31 set, then flag is set */
40 uint32_t PSW_USB_SV
; /* Only if bit 31 set, then flag is set */
41 uint32_t PSW_USB_AV
; /* Only if bit 31 set, then flag is set. */
42 uint32_t PSW_USB_SAV
; /* Only if bit 31 set, then flag is set. */
44 #define R(ADDR, NAME, FEATURE) uint32_t NAME;
45 #define A(ADDR, NAME, FEATURE) uint32_t NAME;
46 #define E(ADDR, NAME, FEATURE) uint32_t NAME;
52 /* Floating Point Registers */
53 float_status fp_status
;
55 /* Internal CPU feature flags. */
61 * @env: #CPUTriCoreState
71 struct TriCoreCPUClass
{
72 CPUClass parent_class
;
74 DeviceRealize parent_realize
;
75 ResettablePhases parent_phases
;
78 hwaddr
tricore_cpu_get_phys_page_debug(CPUState
*cpu
, vaddr addr
);
79 void tricore_cpu_dump_state(CPUState
*cpu
, FILE *f
, int flags
);
81 FIELD(PCXI
, PCPN_13
, 24, 8)
82 FIELD(PCXI
, PCPN_161
, 22, 8)
83 FIELD(PCXI
, PIE_13
, 23, 1)
84 FIELD(PCXI
, PIE_161
, 21, 1)
85 FIELD(PCXI
, UL_13
, 22, 1)
86 FIELD(PCXI
, UL_161
, 20, 1)
87 FIELD(PCXI
, PCXS
, 16, 4)
88 FIELD(PCXI
, PCXO
, 0, 16)
89 uint32_t pcxi_get_ul(CPUTriCoreState
*env
);
90 uint32_t pcxi_get_pie(CPUTriCoreState
*env
);
91 uint32_t pcxi_get_pcpn(CPUTriCoreState
*env
);
92 uint32_t pcxi_get_pcxs(CPUTriCoreState
*env
);
93 uint32_t pcxi_get_pcxo(CPUTriCoreState
*env
);
94 void pcxi_set_ul(CPUTriCoreState
*env
, uint32_t val
);
95 void pcxi_set_pie(CPUTriCoreState
*env
, uint32_t val
);
96 void pcxi_set_pcpn(CPUTriCoreState
*env
, uint32_t val
);
98 FIELD(ICR
, IE_161
, 15, 1)
99 FIELD(ICR
, IE_13
, 8, 1)
100 FIELD(ICR
, PIPN
, 16, 8)
101 FIELD(ICR
, CCPN
, 0, 8)
103 uint32_t icr_get_ie(CPUTriCoreState
*env
);
104 uint32_t icr_get_ccpn(CPUTriCoreState
*env
);
106 void icr_set_ccpn(CPUTriCoreState
*env
, uint32_t val
);
107 void icr_set_ie(CPUTriCoreState
*env
, uint32_t val
);
109 #define MASK_PSW_USB 0xff000000
110 #define MASK_USB_C 0x80000000
111 #define MASK_USB_V 0x40000000
112 #define MASK_USB_SV 0x20000000
113 #define MASK_USB_AV 0x10000000
114 #define MASK_USB_SAV 0x08000000
115 #define MASK_PSW_PRS 0x00003000
116 #define MASK_PSW_IO 0x00000c00
117 #define MASK_PSW_IS 0x00000200
118 #define MASK_PSW_GW 0x00000100
119 #define MASK_PSW_CDE 0x00000080
120 #define MASK_PSW_CDC 0x0000007f
121 #define MASK_PSW_FPU_RM 0x3000000
123 #define MASK_SYSCON_PRO_TEN 0x2
124 #define MASK_SYSCON_FCD_SF 0x1
126 #define MASK_CPUID_MOD 0xffff0000
127 #define MASK_CPUID_MOD_32B 0x0000ff00
128 #define MASK_CPUID_REV 0x000000ff
131 #define MASK_FCX_FCXS 0x000f0000
132 #define MASK_FCX_FCXO 0x0000ffff
134 #define MASK_LCX_LCXS 0x000f0000
135 #define MASK_LCX_LCX0 0x0000ffff
137 #define MASK_DBGSR_DE 0x1
138 #define MASK_DBGSR_HALT 0x6
139 #define MASK_DBGSR_SUSP 0x10
140 #define MASK_DBGSR_PREVSUSP 0x20
141 #define MASK_DBGSR_PEVT 0x40
142 #define MASK_DBGSR_EVTSRC 0x1f00
144 enum tricore_priv_levels
{
145 TRICORE_PRIV_UM0
= 0x0, /* user mode-0 flag */
146 TRICORE_PRIV_UM1
= 0x1, /* user mode-1 flag */
147 TRICORE_PRIV_SM
= 0x2, /* kernel mode flag */
150 enum tricore_features
{
158 static inline int tricore_has_feature(CPUTriCoreState
*env
, int feature
)
160 return (env
->features
& (1ULL << feature
)) != 0;
163 /* TriCore Traps Classes*/
240 uint32_t psw_read(CPUTriCoreState
*env
);
241 void psw_write(CPUTriCoreState
*env
, uint32_t val
);
242 int tricore_cpu_gdb_read_register(CPUState
*cs
, GByteArray
*mem_buf
, int n
);
243 int tricore_cpu_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
);
245 void fpu_set_state(CPUTriCoreState
*env
);
247 #define MMU_USER_IDX 2
249 #include "exec/cpu-all.h"
251 FIELD(TB_FLAGS
, PRIV
, 0, 2)
253 void cpu_state_reset(CPUTriCoreState
*s
);
254 void tricore_tcg_init(void);
256 static inline void cpu_get_tb_cpu_state(CPUTriCoreState
*env
, vaddr
*pc
,
257 uint64_t *cs_base
, uint32_t *flags
)
259 uint32_t new_flags
= 0;
263 new_flags
|= FIELD_DP32(new_flags
, TB_FLAGS
, PRIV
,
264 extract32(env
->PSW
, 10, 2));
268 #define CPU_RESOLVING_TYPE TYPE_TRICORE_CPU
271 bool tricore_cpu_tlb_fill(CPUState
*cs
, vaddr address
, int size
,
272 MMUAccessType access_type
, int mmu_idx
,
273 bool probe
, uintptr_t retaddr
);
275 #endif /* TRICORE_CPU_H */