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 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/>.
19 #if !defined(__TRICORE_CPU_H__)
20 #define __TRICORE_CPU_H__
22 #include "tricore-defs.h"
24 #include "qemu-common.h"
25 #include "exec/cpu-defs.h"
26 #include "fpu/softfloat.h"
28 #define ELF_MACHINE EM_TRICORE
30 #define CPUArchState struct CPUTriCoreState
32 struct CPUTriCoreState
;
34 struct tricore_boot_info
;
36 #define NB_MMU_MODES 3
38 typedef struct tricore_def_t tricore_def_t
;
40 typedef struct CPUTriCoreState CPUTriCoreState
;
41 struct CPUTriCoreState
{
47 /* Frequently accessed PSW_USB bits are stored separately for efficiency.
48 This contains all the other bits. Use psw_{read,write} to access
52 /* PSW flag cache for faster execution
55 uint32_t PSW_USB_V
; /* Only if bit 31 set, then flag is set */
56 uint32_t PSW_USB_SV
; /* Only if bit 31 set, then flag is set */
57 uint32_t PSW_USB_AV
; /* Only if bit 31 set, then flag is set. */
58 uint32_t PSW_USB_SAV
; /* Only if bit 31 set, then flag is set. */
71 /* Mem Protection Register */
154 /* Memory Management Registers */
172 /* Debug Registers */
188 /* Floating Point Registers */
193 uint32_t hflags
; /* CPU State */
197 /* Internal CPU feature flags. */
200 const tricore_def_t
*cpu_model
;
202 struct QEMUTimer
*timer
; /* Internal timer */
205 #define MASK_PCXI_PCPN 0xff000000
206 #define MASK_PCXI_PIE 0x00800000
207 #define MASK_PCXI_UL 0x00400000
208 #define MASK_PCXI_PCXS 0x000f0000
209 #define MASK_PCXI_PCXO 0x0000ffff
211 #define MASK_PSW_USB 0xff000000
212 #define MASK_USB_C 0x80000000
213 #define MASK_USB_V 0x40000000
214 #define MASK_USB_SV 0x20000000
215 #define MASK_USB_AV 0x10000000
216 #define MASK_USB_SAV 0x08000000
217 #define MASK_PSW_PRS 0x00003000
218 #define MASK_PSW_IO 0x00000c00
219 #define MASK_PSW_IS 0x00000200
220 #define MASK_PSW_GW 0x00000100
221 #define MASK_PSW_CDE 0x00000080
222 #define MASK_PSW_CDC 0x0000007f
224 #define MASK_SYSCON_PRO_TEN 0x2
225 #define MASK_SYSCON_FCD_SF 0x1
227 #define MASK_CPUID_MOD 0xffff0000
228 #define MASK_CPUID_MOD_32B 0x0000ff00
229 #define MASK_CPUID_REV 0x000000ff
231 #define MASK_ICR_PIPN 0x00ff0000
232 #define MASK_ICR_IE 0x00000100
233 #define MASK_ICR_CCPN 0x000000ff
235 #define MASK_FCX_FCXS 0x000f0000
236 #define MASK_FCX_FCXO 0x0000ffff
238 #define MASK_LCX_LCXS 0x000f0000
239 #define MASK_LCX_LCX0 0x0000ffff
241 #define TRICORE_HFLAG_KUU 0x3
242 #define TRICORE_HFLAG_UM0 0x00002 /* user mode-0 flag */
243 #define TRICORE_HFLAG_UM1 0x00001 /* user mode-1 flag */
244 #define TRICORE_HFLAG_SM 0x00000 /* kernel mode flag */
246 enum tricore_features
{
252 static inline int tricore_feature(CPUTriCoreState
*env
, int feature
)
254 return (env
->features
& (1ULL << feature
)) != 0;
257 /* TriCore Traps Classes*/
333 uint32_t psw_read(CPUTriCoreState
*env
);
334 void psw_write(CPUTriCoreState
*env
, uint32_t val
);
337 #define MMU_USER_IDX 2
339 void tricore_cpu_list(FILE *f
, fprintf_function cpu_fprintf
);
341 #define cpu_exec cpu_tricore_exec
342 #define cpu_signal_handler cpu_tricore_signal_handler
343 #define cpu_list tricore_cpu_list
345 static inline int cpu_mmu_index(CPUTriCoreState
*env
)
352 #include "exec/cpu-all.h"
355 /* 1 bit to define user level / supervisor access */
358 /* 1 bit to indicate direction */
360 /* Type of instruction that generated the access */
361 ACCESS_CODE
= 0x10, /* Code fetch access */
362 ACCESS_INT
= 0x20, /* Integer load/store access */
363 ACCESS_FLOAT
= 0x30, /* floating point load/store access */
366 void cpu_state_reset(CPUTriCoreState
*s
);
367 int cpu_tricore_exec(CPUTriCoreState
*s
);
368 void tricore_tcg_init(void);
369 int cpu_tricore_signal_handler(int host_signum
, void *pinfo
, void *puc
);
371 static inline void cpu_get_tb_cpu_state(CPUTriCoreState
*env
, target_ulong
*pc
,
372 target_ulong
*cs_base
, int *flags
)
379 TriCoreCPU
*cpu_tricore_init(const char *cpu_model
);
381 static inline CPUTriCoreState
*cpu_init(const char *cpu_model
)
383 TriCoreCPU
*cpu
= cpu_tricore_init(cpu_model
);
393 int cpu_tricore_handle_mmu_fault(CPUState
*cpu
, target_ulong address
,
394 int rw
, int mmu_idx
);
395 #define cpu_handle_mmu_fault cpu_tricore_handle_mmu_fault
397 #include "exec/exec-all.h"
399 static inline void cpu_pc_from_tb(CPUTriCoreState
*env
, TranslationBlock
*tb
)
404 #endif /*__TRICORE_CPU_H__ */