2014-09-01 15:59:46 +04:00
|
|
|
/*
|
|
|
|
* TriCore emulation for qemu: main CPU struct.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012-2014 Bastian Koppelmann C-Lab/University Paderborn
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2019-01-23 17:08:55 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2014-09-01 15:59:46 +04:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-06-29 12:05:55 +03:00
|
|
|
|
|
|
|
#ifndef TRICORE_CPU_H
|
|
|
|
#define TRICORE_CPU_H
|
2014-09-01 15:59:46 +04:00
|
|
|
|
2016-03-15 15:49:25 +03:00
|
|
|
#include "cpu-qom.h"
|
2023-05-26 09:19:44 +03:00
|
|
|
#include "hw/registerfields.h"
|
2014-09-01 15:59:46 +04:00
|
|
|
#include "exec/cpu-defs.h"
|
2022-03-23 18:57:39 +03:00
|
|
|
#include "qemu/cpu-float.h"
|
2019-03-22 21:51:19 +03:00
|
|
|
#include "tricore-defs.h"
|
2014-09-01 15:59:46 +04:00
|
|
|
|
2022-02-07 15:35:58 +03:00
|
|
|
typedef struct CPUArchState {
|
2014-09-01 15:59:46 +04:00
|
|
|
/* GPR Register */
|
|
|
|
uint32_t gpr_a[16];
|
|
|
|
uint32_t gpr_d[16];
|
|
|
|
/* Frequently accessed PSW_USB bits are stored separately for efficiency.
|
|
|
|
This contains all the other bits. Use psw_{read,write} to access
|
|
|
|
the whole PSW. */
|
|
|
|
uint32_t PSW;
|
2023-09-13 13:53:25 +03:00
|
|
|
/* PSW flag cache for faster execution */
|
2014-09-01 15:59:46 +04:00
|
|
|
uint32_t PSW_USB_C;
|
|
|
|
uint32_t PSW_USB_V; /* Only if bit 31 set, then flag is set */
|
|
|
|
uint32_t PSW_USB_SV; /* Only if bit 31 set, then flag is set */
|
|
|
|
uint32_t PSW_USB_AV; /* Only if bit 31 set, then flag is set. */
|
|
|
|
uint32_t PSW_USB_SAV; /* Only if bit 31 set, then flag is set. */
|
|
|
|
|
2023-09-13 13:53:25 +03:00
|
|
|
#define R(ADDR, NAME, FEATURE) uint32_t NAME;
|
|
|
|
#define A(ADDR, NAME, FEATURE) uint32_t NAME;
|
|
|
|
#define E(ADDR, NAME, FEATURE) uint32_t NAME;
|
|
|
|
#include "csfr.h.inc"
|
|
|
|
#undef R
|
|
|
|
#undef A
|
|
|
|
#undef E
|
2014-09-01 15:59:46 +04:00
|
|
|
|
|
|
|
/* Floating Point Registers */
|
2016-03-11 18:03:11 +03:00
|
|
|
float_status fp_status;
|
2014-09-01 15:59:46 +04:00
|
|
|
|
|
|
|
/* Internal CPU feature flags. */
|
|
|
|
uint64_t features;
|
2022-02-07 15:35:58 +03:00
|
|
|
} CPUTriCoreState;
|
2014-09-01 15:59:46 +04:00
|
|
|
|
2016-03-15 15:49:25 +03:00
|
|
|
/**
|
|
|
|
* TriCoreCPU:
|
|
|
|
* @env: #CPUTriCoreState
|
|
|
|
*
|
|
|
|
* A TriCore CPU.
|
|
|
|
*/
|
2022-02-14 19:15:16 +03:00
|
|
|
struct ArchCPU {
|
2016-03-15 15:49:25 +03:00
|
|
|
CPUState parent_obj;
|
|
|
|
|
|
|
|
CPUTriCoreState env;
|
|
|
|
};
|
|
|
|
|
2023-10-13 12:35:04 +03:00
|
|
|
struct TriCoreCPUClass {
|
|
|
|
CPUClass parent_class;
|
|
|
|
|
|
|
|
DeviceRealize parent_realize;
|
|
|
|
ResettablePhases parent_phases;
|
|
|
|
};
|
2016-03-15 15:49:25 +03:00
|
|
|
|
|
|
|
hwaddr tricore_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
|
2019-04-17 22:18:02 +03:00
|
|
|
void tricore_cpu_dump_state(CPUState *cpu, FILE *f, int flags);
|
2016-03-15 15:49:25 +03:00
|
|
|
|
2023-05-26 09:19:44 +03:00
|
|
|
FIELD(PCXI, PCPN_13, 24, 8)
|
|
|
|
FIELD(PCXI, PCPN_161, 22, 8)
|
|
|
|
FIELD(PCXI, PIE_13, 23, 1)
|
|
|
|
FIELD(PCXI, PIE_161, 21, 1)
|
|
|
|
FIELD(PCXI, UL_13, 22, 1)
|
|
|
|
FIELD(PCXI, UL_161, 20, 1)
|
|
|
|
FIELD(PCXI, PCXS, 16, 4)
|
|
|
|
FIELD(PCXI, PCXO, 0, 16)
|
|
|
|
uint32_t pcxi_get_ul(CPUTriCoreState *env);
|
|
|
|
uint32_t pcxi_get_pie(CPUTriCoreState *env);
|
|
|
|
uint32_t pcxi_get_pcpn(CPUTriCoreState *env);
|
|
|
|
uint32_t pcxi_get_pcxs(CPUTriCoreState *env);
|
|
|
|
uint32_t pcxi_get_pcxo(CPUTriCoreState *env);
|
|
|
|
void pcxi_set_ul(CPUTriCoreState *env, uint32_t val);
|
|
|
|
void pcxi_set_pie(CPUTriCoreState *env, uint32_t val);
|
|
|
|
void pcxi_set_pcpn(CPUTriCoreState *env, uint32_t val);
|
|
|
|
|
|
|
|
FIELD(ICR, IE_161, 15, 1)
|
|
|
|
FIELD(ICR, IE_13, 8, 1)
|
|
|
|
FIELD(ICR, PIPN, 16, 8)
|
|
|
|
FIELD(ICR, CCPN, 0, 8)
|
|
|
|
|
|
|
|
uint32_t icr_get_ie(CPUTriCoreState *env);
|
|
|
|
uint32_t icr_get_ccpn(CPUTriCoreState *env);
|
|
|
|
|
|
|
|
void icr_set_ccpn(CPUTriCoreState *env, uint32_t val);
|
|
|
|
void icr_set_ie(CPUTriCoreState *env, uint32_t val);
|
2014-09-01 15:59:46 +04:00
|
|
|
|
|
|
|
#define MASK_PSW_USB 0xff000000
|
|
|
|
#define MASK_USB_C 0x80000000
|
|
|
|
#define MASK_USB_V 0x40000000
|
|
|
|
#define MASK_USB_SV 0x20000000
|
|
|
|
#define MASK_USB_AV 0x10000000
|
|
|
|
#define MASK_USB_SAV 0x08000000
|
|
|
|
#define MASK_PSW_PRS 0x00003000
|
|
|
|
#define MASK_PSW_IO 0x00000c00
|
|
|
|
#define MASK_PSW_IS 0x00000200
|
|
|
|
#define MASK_PSW_GW 0x00000100
|
|
|
|
#define MASK_PSW_CDE 0x00000080
|
|
|
|
#define MASK_PSW_CDC 0x0000007f
|
2016-03-11 18:03:11 +03:00
|
|
|
#define MASK_PSW_FPU_RM 0x3000000
|
2014-09-01 15:59:46 +04:00
|
|
|
|
|
|
|
#define MASK_SYSCON_PRO_TEN 0x2
|
|
|
|
#define MASK_SYSCON_FCD_SF 0x1
|
|
|
|
|
|
|
|
#define MASK_CPUID_MOD 0xffff0000
|
|
|
|
#define MASK_CPUID_MOD_32B 0x0000ff00
|
|
|
|
#define MASK_CPUID_REV 0x000000ff
|
|
|
|
|
|
|
|
|
|
|
|
#define MASK_FCX_FCXS 0x000f0000
|
|
|
|
#define MASK_FCX_FCXO 0x0000ffff
|
|
|
|
|
|
|
|
#define MASK_LCX_LCXS 0x000f0000
|
|
|
|
#define MASK_LCX_LCX0 0x0000ffff
|
|
|
|
|
2015-02-25 15:29:24 +03:00
|
|
|
#define MASK_DBGSR_DE 0x1
|
|
|
|
#define MASK_DBGSR_HALT 0x6
|
|
|
|
#define MASK_DBGSR_SUSP 0x10
|
|
|
|
#define MASK_DBGSR_PREVSUSP 0x20
|
|
|
|
#define MASK_DBGSR_PEVT 0x40
|
|
|
|
#define MASK_DBGSR_EVTSRC 0x1f00
|
|
|
|
|
2023-06-21 17:22:59 +03:00
|
|
|
enum tricore_priv_levels {
|
|
|
|
TRICORE_PRIV_UM0 = 0x0, /* user mode-0 flag */
|
|
|
|
TRICORE_PRIV_UM1 = 0x1, /* user mode-1 flag */
|
|
|
|
TRICORE_PRIV_SM = 0x2, /* kernel mode flag */
|
|
|
|
};
|
2014-09-01 15:59:46 +04:00
|
|
|
|
|
|
|
enum tricore_features {
|
|
|
|
TRICORE_FEATURE_13,
|
|
|
|
TRICORE_FEATURE_131,
|
|
|
|
TRICORE_FEATURE_16,
|
2015-05-06 21:18:41 +03:00
|
|
|
TRICORE_FEATURE_161,
|
2023-06-14 13:00:32 +03:00
|
|
|
TRICORE_FEATURE_162,
|
2014-09-01 15:59:46 +04:00
|
|
|
};
|
|
|
|
|
2023-07-21 09:06:05 +03:00
|
|
|
static inline int tricore_has_feature(CPUTriCoreState *env, int feature)
|
2014-09-01 15:59:46 +04:00
|
|
|
{
|
|
|
|
return (env->features & (1ULL << feature)) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TriCore Traps Classes*/
|
|
|
|
enum {
|
|
|
|
TRAPC_NONE = -1,
|
|
|
|
TRAPC_MMU = 0,
|
|
|
|
TRAPC_PROT = 1,
|
|
|
|
TRAPC_INSN_ERR = 2,
|
|
|
|
TRAPC_CTX_MNG = 3,
|
|
|
|
TRAPC_SYSBUS = 4,
|
|
|
|
TRAPC_ASSERT = 5,
|
|
|
|
TRAPC_SYSCALL = 6,
|
|
|
|
TRAPC_NMI = 7,
|
2016-02-19 16:43:43 +03:00
|
|
|
TRAPC_IRQ = 8
|
2014-09-01 15:59:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Class 0 TIN */
|
|
|
|
enum {
|
|
|
|
TIN0_VAF = 0,
|
|
|
|
TIN0_VAP = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Class 1 TIN */
|
|
|
|
enum {
|
|
|
|
TIN1_PRIV = 1,
|
|
|
|
TIN1_MPR = 2,
|
|
|
|
TIN1_MPW = 3,
|
|
|
|
TIN1_MPX = 4,
|
|
|
|
TIN1_MPP = 5,
|
|
|
|
TIN1_MPN = 6,
|
|
|
|
TIN1_GRWP = 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Class 2 TIN */
|
|
|
|
enum {
|
|
|
|
TIN2_IOPC = 1,
|
|
|
|
TIN2_UOPC = 2,
|
|
|
|
TIN2_OPD = 3,
|
|
|
|
TIN2_ALN = 4,
|
|
|
|
TIN2_MEM = 5,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Class 3 TIN */
|
|
|
|
enum {
|
|
|
|
TIN3_FCD = 1,
|
|
|
|
TIN3_CDO = 2,
|
|
|
|
TIN3_CDU = 3,
|
|
|
|
TIN3_FCU = 4,
|
|
|
|
TIN3_CSU = 5,
|
|
|
|
TIN3_CTYP = 6,
|
|
|
|
TIN3_NEST = 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Class 4 TIN */
|
|
|
|
enum {
|
|
|
|
TIN4_PSE = 1,
|
|
|
|
TIN4_DSE = 2,
|
|
|
|
TIN4_DAE = 3,
|
|
|
|
TIN4_CAE = 4,
|
|
|
|
TIN4_PIE = 5,
|
|
|
|
TIN4_DIE = 6,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Class 5 TIN */
|
|
|
|
enum {
|
|
|
|
TIN5_OVF = 1,
|
|
|
|
TIN5_SOVF = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Class 6 TIN
|
|
|
|
*
|
|
|
|
* Is always TIN6_SYS
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Class 7 TIN */
|
|
|
|
enum {
|
|
|
|
TIN7_NMI = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t psw_read(CPUTriCoreState *env);
|
|
|
|
void psw_write(CPUTriCoreState *env, uint32_t val);
|
2020-05-29 10:21:48 +03:00
|
|
|
int tricore_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n);
|
|
|
|
int tricore_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n);
|
2014-09-01 15:59:46 +04:00
|
|
|
|
2016-03-11 18:03:11 +03:00
|
|
|
void fpu_set_state(CPUTriCoreState *env);
|
|
|
|
|
2014-09-01 15:59:46 +04:00
|
|
|
#define MMU_USER_IDX 2
|
|
|
|
|
|
|
|
#include "exec/cpu-all.h"
|
|
|
|
|
2023-06-21 17:22:59 +03:00
|
|
|
FIELD(TB_FLAGS, PRIV, 0, 2)
|
|
|
|
|
2014-09-01 15:59:46 +04:00
|
|
|
void cpu_state_reset(CPUTriCoreState *s);
|
|
|
|
void tricore_tcg_init(void);
|
|
|
|
|
2023-06-21 16:56:24 +03:00
|
|
|
static inline void cpu_get_tb_cpu_state(CPUTriCoreState *env, vaddr *pc,
|
|
|
|
uint64_t *cs_base, uint32_t *flags)
|
2014-09-01 15:59:46 +04:00
|
|
|
{
|
2023-06-21 17:22:59 +03:00
|
|
|
uint32_t new_flags = 0;
|
2014-09-01 15:59:46 +04:00
|
|
|
*pc = env->PC;
|
|
|
|
*cs_base = 0;
|
2023-06-21 17:22:59 +03:00
|
|
|
|
|
|
|
new_flags |= FIELD_DP32(new_flags, TB_FLAGS, PRIV,
|
|
|
|
extract32(env->PSW, 10, 2));
|
|
|
|
*flags = new_flags;
|
2014-09-01 15:59:46 +04:00
|
|
|
}
|
|
|
|
|
2018-02-07 13:40:25 +03:00
|
|
|
#define CPU_RESOLVING_TYPE TYPE_TRICORE_CPU
|
2014-09-01 15:59:46 +04:00
|
|
|
|
|
|
|
/* helpers.c */
|
2019-04-03 03:27:29 +03:00
|
|
|
bool tricore_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
|
|
|
|
MMUAccessType access_type, int mmu_idx,
|
|
|
|
bool probe, uintptr_t retaddr);
|
2014-09-01 15:59:46 +04:00
|
|
|
|
2016-06-29 12:05:55 +03:00
|
|
|
#endif /* TRICORE_CPU_H */
|