cpu: Define ArchCPU
[qemu/ar7.git] / target / tricore / cpu.h
blob8d660df34a2809b8752001f8d09b1ea265210ce4
1 /*
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/>.
20 #ifndef TRICORE_CPU_H
21 #define TRICORE_CPU_H
23 #include "qemu-common.h"
24 #include "cpu-qom.h"
25 #include "exec/cpu-defs.h"
26 #include "tricore-defs.h"
28 struct tricore_boot_info;
30 typedef struct tricore_def_t tricore_def_t;
32 typedef struct CPUTriCoreState CPUTriCoreState;
33 struct CPUTriCoreState {
34 /* GPR Register */
35 uint32_t gpr_a[16];
36 uint32_t gpr_d[16];
37 /* CSFR Register */
38 uint32_t PCXI;
39 /* Frequently accessed PSW_USB bits are stored separately for efficiency.
40 This contains all the other bits. Use psw_{read,write} to access
41 the whole PSW. */
42 uint32_t PSW;
44 /* PSW flag cache for faster execution
46 uint32_t PSW_USB_C;
47 uint32_t PSW_USB_V; /* Only if bit 31 set, then flag is set */
48 uint32_t PSW_USB_SV; /* Only if bit 31 set, then flag is set */
49 uint32_t PSW_USB_AV; /* Only if bit 31 set, then flag is set. */
50 uint32_t PSW_USB_SAV; /* Only if bit 31 set, then flag is set. */
52 uint32_t PC;
53 uint32_t SYSCON;
54 uint32_t CPU_ID;
55 uint32_t CORE_ID;
56 uint32_t BIV;
57 uint32_t BTV;
58 uint32_t ISP;
59 uint32_t ICR;
60 uint32_t FCX;
61 uint32_t LCX;
62 uint32_t COMPAT;
64 /* Mem Protection Register */
65 uint32_t DPR0_0L;
66 uint32_t DPR0_0U;
67 uint32_t DPR0_1L;
68 uint32_t DPR0_1U;
69 uint32_t DPR0_2L;
70 uint32_t DPR0_2U;
71 uint32_t DPR0_3L;
72 uint32_t DPR0_3U;
74 uint32_t DPR1_0L;
75 uint32_t DPR1_0U;
76 uint32_t DPR1_1L;
77 uint32_t DPR1_1U;
78 uint32_t DPR1_2L;
79 uint32_t DPR1_2U;
80 uint32_t DPR1_3L;
81 uint32_t DPR1_3U;
83 uint32_t DPR2_0L;
84 uint32_t DPR2_0U;
85 uint32_t DPR2_1L;
86 uint32_t DPR2_1U;
87 uint32_t DPR2_2L;
88 uint32_t DPR2_2U;
89 uint32_t DPR2_3L;
90 uint32_t DPR2_3U;
92 uint32_t DPR3_0L;
93 uint32_t DPR3_0U;
94 uint32_t DPR3_1L;
95 uint32_t DPR3_1U;
96 uint32_t DPR3_2L;
97 uint32_t DPR3_2U;
98 uint32_t DPR3_3L;
99 uint32_t DPR3_3U;
101 uint32_t CPR0_0L;
102 uint32_t CPR0_0U;
103 uint32_t CPR0_1L;
104 uint32_t CPR0_1U;
105 uint32_t CPR0_2L;
106 uint32_t CPR0_2U;
107 uint32_t CPR0_3L;
108 uint32_t CPR0_3U;
110 uint32_t CPR1_0L;
111 uint32_t CPR1_0U;
112 uint32_t CPR1_1L;
113 uint32_t CPR1_1U;
114 uint32_t CPR1_2L;
115 uint32_t CPR1_2U;
116 uint32_t CPR1_3L;
117 uint32_t CPR1_3U;
119 uint32_t CPR2_0L;
120 uint32_t CPR2_0U;
121 uint32_t CPR2_1L;
122 uint32_t CPR2_1U;
123 uint32_t CPR2_2L;
124 uint32_t CPR2_2U;
125 uint32_t CPR2_3L;
126 uint32_t CPR2_3U;
128 uint32_t CPR3_0L;
129 uint32_t CPR3_0U;
130 uint32_t CPR3_1L;
131 uint32_t CPR3_1U;
132 uint32_t CPR3_2L;
133 uint32_t CPR3_2U;
134 uint32_t CPR3_3L;
135 uint32_t CPR3_3U;
137 uint32_t DPM0;
138 uint32_t DPM1;
139 uint32_t DPM2;
140 uint32_t DPM3;
142 uint32_t CPM0;
143 uint32_t CPM1;
144 uint32_t CPM2;
145 uint32_t CPM3;
147 /* Memory Management Registers */
148 uint32_t MMU_CON;
149 uint32_t MMU_ASI;
150 uint32_t MMU_TVA;
151 uint32_t MMU_TPA;
152 uint32_t MMU_TPX;
153 uint32_t MMU_TFA;
154 /* {1.3.1 only */
155 uint32_t BMACON;
156 uint32_t SMACON;
157 uint32_t DIEAR;
158 uint32_t DIETR;
159 uint32_t CCDIER;
160 uint32_t MIECON;
161 uint32_t PIEAR;
162 uint32_t PIETR;
163 uint32_t CCPIER;
164 /*} */
165 /* Debug Registers */
166 uint32_t DBGSR;
167 uint32_t EXEVT;
168 uint32_t CREVT;
169 uint32_t SWEVT;
170 uint32_t TR0EVT;
171 uint32_t TR1EVT;
172 uint32_t DMS;
173 uint32_t DCX;
174 uint32_t DBGTCR;
175 uint32_t CCTRL;
176 uint32_t CCNT;
177 uint32_t ICNT;
178 uint32_t M1CNT;
179 uint32_t M2CNT;
180 uint32_t M3CNT;
181 /* Floating Point Registers */
182 float_status fp_status;
183 /* QEMU */
184 int error_code;
185 uint32_t hflags; /* CPU State */
187 CPU_COMMON
189 /* Internal CPU feature flags. */
190 uint64_t features;
192 const tricore_def_t *cpu_model;
193 void *irq[8];
194 struct QEMUTimer *timer; /* Internal timer */
198 * TriCoreCPU:
199 * @env: #CPUTriCoreState
201 * A TriCore CPU.
203 struct TriCoreCPU {
204 /*< private >*/
205 CPUState parent_obj;
206 /*< public >*/
208 CPUTriCoreState env;
211 static inline TriCoreCPU *tricore_env_get_cpu(CPUTriCoreState *env)
213 return TRICORE_CPU(container_of(env, TriCoreCPU, env));
216 #define ENV_GET_CPU(e) CPU(tricore_env_get_cpu(e))
218 #define ENV_OFFSET offsetof(TriCoreCPU, env)
220 hwaddr tricore_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
221 void tricore_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
224 #define MASK_PCXI_PCPN 0xff000000
225 #define MASK_PCXI_PIE_1_3 0x00800000
226 #define MASK_PCXI_PIE_1_6 0x00200000
227 #define MASK_PCXI_UL 0x00400000
228 #define MASK_PCXI_PCXS 0x000f0000
229 #define MASK_PCXI_PCXO 0x0000ffff
231 #define MASK_PSW_USB 0xff000000
232 #define MASK_USB_C 0x80000000
233 #define MASK_USB_V 0x40000000
234 #define MASK_USB_SV 0x20000000
235 #define MASK_USB_AV 0x10000000
236 #define MASK_USB_SAV 0x08000000
237 #define MASK_PSW_PRS 0x00003000
238 #define MASK_PSW_IO 0x00000c00
239 #define MASK_PSW_IS 0x00000200
240 #define MASK_PSW_GW 0x00000100
241 #define MASK_PSW_CDE 0x00000080
242 #define MASK_PSW_CDC 0x0000007f
243 #define MASK_PSW_FPU_RM 0x3000000
245 #define MASK_SYSCON_PRO_TEN 0x2
246 #define MASK_SYSCON_FCD_SF 0x1
248 #define MASK_CPUID_MOD 0xffff0000
249 #define MASK_CPUID_MOD_32B 0x0000ff00
250 #define MASK_CPUID_REV 0x000000ff
252 #define MASK_ICR_PIPN 0x00ff0000
253 #define MASK_ICR_IE_1_3 0x00000100
254 #define MASK_ICR_IE_1_6 0x00008000
255 #define MASK_ICR_CCPN 0x000000ff
257 #define MASK_FCX_FCXS 0x000f0000
258 #define MASK_FCX_FCXO 0x0000ffff
260 #define MASK_LCX_LCXS 0x000f0000
261 #define MASK_LCX_LCX0 0x0000ffff
263 #define MASK_DBGSR_DE 0x1
264 #define MASK_DBGSR_HALT 0x6
265 #define MASK_DBGSR_SUSP 0x10
266 #define MASK_DBGSR_PREVSUSP 0x20
267 #define MASK_DBGSR_PEVT 0x40
268 #define MASK_DBGSR_EVTSRC 0x1f00
270 #define TRICORE_HFLAG_KUU 0x3
271 #define TRICORE_HFLAG_UM0 0x00002 /* user mode-0 flag */
272 #define TRICORE_HFLAG_UM1 0x00001 /* user mode-1 flag */
273 #define TRICORE_HFLAG_SM 0x00000 /* kernel mode flag */
275 enum tricore_features {
276 TRICORE_FEATURE_13,
277 TRICORE_FEATURE_131,
278 TRICORE_FEATURE_16,
279 TRICORE_FEATURE_161,
282 static inline int tricore_feature(CPUTriCoreState *env, int feature)
284 return (env->features & (1ULL << feature)) != 0;
287 /* TriCore Traps Classes*/
288 enum {
289 TRAPC_NONE = -1,
290 TRAPC_MMU = 0,
291 TRAPC_PROT = 1,
292 TRAPC_INSN_ERR = 2,
293 TRAPC_CTX_MNG = 3,
294 TRAPC_SYSBUS = 4,
295 TRAPC_ASSERT = 5,
296 TRAPC_SYSCALL = 6,
297 TRAPC_NMI = 7,
298 TRAPC_IRQ = 8
301 /* Class 0 TIN */
302 enum {
303 TIN0_VAF = 0,
304 TIN0_VAP = 1,
307 /* Class 1 TIN */
308 enum {
309 TIN1_PRIV = 1,
310 TIN1_MPR = 2,
311 TIN1_MPW = 3,
312 TIN1_MPX = 4,
313 TIN1_MPP = 5,
314 TIN1_MPN = 6,
315 TIN1_GRWP = 7,
318 /* Class 2 TIN */
319 enum {
320 TIN2_IOPC = 1,
321 TIN2_UOPC = 2,
322 TIN2_OPD = 3,
323 TIN2_ALN = 4,
324 TIN2_MEM = 5,
327 /* Class 3 TIN */
328 enum {
329 TIN3_FCD = 1,
330 TIN3_CDO = 2,
331 TIN3_CDU = 3,
332 TIN3_FCU = 4,
333 TIN3_CSU = 5,
334 TIN3_CTYP = 6,
335 TIN3_NEST = 7,
338 /* Class 4 TIN */
339 enum {
340 TIN4_PSE = 1,
341 TIN4_DSE = 2,
342 TIN4_DAE = 3,
343 TIN4_CAE = 4,
344 TIN4_PIE = 5,
345 TIN4_DIE = 6,
348 /* Class 5 TIN */
349 enum {
350 TIN5_OVF = 1,
351 TIN5_SOVF = 1,
354 /* Class 6 TIN
356 * Is always TIN6_SYS
359 /* Class 7 TIN */
360 enum {
361 TIN7_NMI = 0,
364 uint32_t psw_read(CPUTriCoreState *env);
365 void psw_write(CPUTriCoreState *env, uint32_t val);
367 void fpu_set_state(CPUTriCoreState *env);
369 #define MMU_USER_IDX 2
371 void tricore_cpu_list(void);
373 #define cpu_signal_handler cpu_tricore_signal_handler
374 #define cpu_list tricore_cpu_list
376 static inline int cpu_mmu_index(CPUTriCoreState *env, bool ifetch)
378 return 0;
381 typedef CPUTriCoreState CPUArchState;
382 typedef TriCoreCPU ArchCPU;
384 #include "exec/cpu-all.h"
386 enum {
387 /* 1 bit to define user level / supervisor access */
388 ACCESS_USER = 0x00,
389 ACCESS_SUPER = 0x01,
390 /* 1 bit to indicate direction */
391 ACCESS_STORE = 0x02,
392 /* Type of instruction that generated the access */
393 ACCESS_CODE = 0x10, /* Code fetch access */
394 ACCESS_INT = 0x20, /* Integer load/store access */
395 ACCESS_FLOAT = 0x30, /* floating point load/store access */
398 void cpu_state_reset(CPUTriCoreState *s);
399 void tricore_tcg_init(void);
400 int cpu_tricore_signal_handler(int host_signum, void *pinfo, void *puc);
402 static inline void cpu_get_tb_cpu_state(CPUTriCoreState *env, target_ulong *pc,
403 target_ulong *cs_base, uint32_t *flags)
405 *pc = env->PC;
406 *cs_base = 0;
407 *flags = 0;
410 #define TRICORE_CPU_TYPE_SUFFIX "-" TYPE_TRICORE_CPU
411 #define TRICORE_CPU_TYPE_NAME(model) model TRICORE_CPU_TYPE_SUFFIX
412 #define CPU_RESOLVING_TYPE TYPE_TRICORE_CPU
414 /* helpers.c */
415 bool tricore_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
416 MMUAccessType access_type, int mmu_idx,
417 bool probe, uintptr_t retaddr);
419 #endif /* TRICORE_CPU_H */