2014-09-01 15:59:46 +04:00
|
|
|
/*
|
|
|
|
* 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-01-26 21:17:26 +03:00
|
|
|
#include "qemu/osdep.h"
|
2022-02-07 11:27:56 +03:00
|
|
|
#include "qemu/log.h"
|
2023-05-26 09:19:44 +03:00
|
|
|
#include "hw/registerfields.h"
|
2014-09-01 15:59:46 +04:00
|
|
|
#include "cpu.h"
|
2016-03-15 15:18:37 +03:00
|
|
|
#include "exec/exec-all.h"
|
2019-08-08 19:30:35 +03:00
|
|
|
#include "fpu/softfloat-helpers.h"
|
2019-04-17 22:17:57 +03:00
|
|
|
#include "qemu/qemu-print.h"
|
2014-09-01 15:59:46 +04:00
|
|
|
|
2014-09-01 15:59:48 +04:00
|
|
|
enum {
|
|
|
|
TLBRET_DIRTY = -4,
|
|
|
|
TLBRET_INVALID = -3,
|
|
|
|
TLBRET_NOMATCH = -2,
|
|
|
|
TLBRET_BADADDR = -1,
|
|
|
|
TLBRET_MATCH = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static int get_physical_address(CPUTriCoreState *env, hwaddr *physical,
|
|
|
|
int *prot, target_ulong address,
|
2021-01-28 01:42:54 +03:00
|
|
|
MMUAccessType access_type, int mmu_idx)
|
2014-09-01 15:59:48 +04:00
|
|
|
{
|
|
|
|
int ret = TLBRET_MATCH;
|
|
|
|
|
|
|
|
*physical = address & 0xFFFFFFFF;
|
|
|
|
*prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2020-05-29 10:21:47 +03:00
|
|
|
|
|
|
|
hwaddr tricore_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
|
|
|
|
{
|
|
|
|
TriCoreCPU *cpu = TRICORE_CPU(cs);
|
|
|
|
hwaddr phys_addr;
|
|
|
|
int prot;
|
|
|
|
int mmu_idx = cpu_mmu_index(&cpu->env, false);
|
|
|
|
|
2021-01-28 01:42:53 +03:00
|
|
|
if (get_physical_address(&cpu->env, &phys_addr, &prot, addr,
|
|
|
|
MMU_DATA_LOAD, mmu_idx)) {
|
2020-05-29 10:21:47 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return phys_addr;
|
|
|
|
}
|
2014-09-01 15:59:48 +04:00
|
|
|
|
2023-07-14 14:23:51 +03:00
|
|
|
/* TODO: Add exception support */
|
2014-09-01 15:59:48 +04:00
|
|
|
static void raise_mmu_exception(CPUTriCoreState *env, target_ulong address,
|
|
|
|
int rw, int tlb_error)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-03 03:27:29 +03:00
|
|
|
bool tricore_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
|
|
|
|
MMUAccessType rw, int mmu_idx,
|
|
|
|
bool probe, uintptr_t retaddr)
|
2014-09-01 15:59:46 +04:00
|
|
|
{
|
2014-09-01 15:59:48 +04:00
|
|
|
TriCoreCPU *cpu = TRICORE_CPU(cs);
|
|
|
|
CPUTriCoreState *env = &cpu->env;
|
|
|
|
hwaddr physical;
|
|
|
|
int prot;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
rw &= 1;
|
|
|
|
ret = get_physical_address(env, &physical, &prot,
|
2021-01-28 01:42:54 +03:00
|
|
|
address, rw, mmu_idx);
|
2019-04-03 03:27:29 +03:00
|
|
|
|
|
|
|
qemu_log_mask(CPU_LOG_MMU, "%s address=" TARGET_FMT_lx " ret %d physical "
|
2023-01-11 00:29:47 +03:00
|
|
|
HWADDR_FMT_plx " prot %d\n",
|
2019-04-03 03:27:29 +03:00
|
|
|
__func__, (target_ulong)address, ret, physical, prot);
|
2014-09-01 15:59:48 +04:00
|
|
|
|
|
|
|
if (ret == TLBRET_MATCH) {
|
|
|
|
tlb_set_page(cs, address & TARGET_PAGE_MASK,
|
|
|
|
physical & TARGET_PAGE_MASK, prot | PAGE_EXEC,
|
|
|
|
mmu_idx, TARGET_PAGE_SIZE);
|
2019-04-03 03:27:29 +03:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
assert(ret < 0);
|
|
|
|
if (probe) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-01 15:59:48 +04:00
|
|
|
raise_mmu_exception(env, address, rw, ret);
|
2019-04-03 03:27:29 +03:00
|
|
|
cpu_loop_exit_restore(cs, retaddr);
|
2014-09-01 15:59:48 +04:00
|
|
|
}
|
2019-04-03 03:27:29 +03:00
|
|
|
}
|
2014-09-01 15:59:48 +04:00
|
|
|
|
2014-09-01 15:59:46 +04:00
|
|
|
static void tricore_cpu_list_entry(gpointer data, gpointer user_data)
|
|
|
|
{
|
|
|
|
ObjectClass *oc = data;
|
|
|
|
const char *typename;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
typename = object_class_get_name(oc);
|
|
|
|
name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_TRICORE_CPU));
|
2019-04-17 22:17:57 +03:00
|
|
|
qemu_printf(" %s\n", name);
|
2014-09-01 15:59:46 +04:00
|
|
|
g_free(name);
|
|
|
|
}
|
|
|
|
|
2019-04-17 22:17:57 +03:00
|
|
|
void tricore_cpu_list(void)
|
2014-09-01 15:59:46 +04:00
|
|
|
{
|
|
|
|
GSList *list;
|
|
|
|
|
2018-03-03 10:33:10 +03:00
|
|
|
list = object_class_get_list_sorted(TYPE_TRICORE_CPU, false);
|
2019-04-17 22:17:57 +03:00
|
|
|
qemu_printf("Available CPUs:\n");
|
|
|
|
g_slist_foreach(list, tricore_cpu_list_entry, NULL);
|
2014-09-01 15:59:46 +04:00
|
|
|
g_slist_free(list);
|
|
|
|
}
|
|
|
|
|
2016-03-11 18:03:11 +03:00
|
|
|
void fpu_set_state(CPUTriCoreState *env)
|
|
|
|
{
|
2023-08-28 14:26:43 +03:00
|
|
|
switch (extract32(env->PSW, 24, 2)) {
|
|
|
|
case 0:
|
|
|
|
set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
set_float_rounding_mode(float_round_up, &env->fp_status);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
set_float_rounding_mode(float_round_down, &env->fp_status);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
set_float_rounding_mode(float_round_to_zero, &env->fp_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-11 18:03:11 +03:00
|
|
|
set_flush_inputs_to_zero(1, &env->fp_status);
|
|
|
|
set_flush_to_zero(1, &env->fp_status);
|
2023-08-28 14:26:46 +03:00
|
|
|
set_float_detect_tininess(float_tininess_before_rounding, &env->fp_status);
|
2016-03-11 18:03:11 +03:00
|
|
|
set_default_nan_mode(1, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
2014-09-01 15:59:46 +04:00
|
|
|
uint32_t psw_read(CPUTriCoreState *env)
|
|
|
|
{
|
|
|
|
/* clear all USB bits */
|
2023-08-28 14:26:43 +03:00
|
|
|
env->PSW &= 0x7ffffff;
|
2014-09-01 15:59:46 +04:00
|
|
|
/* now set them from the cache */
|
|
|
|
env->PSW |= ((env->PSW_USB_C != 0) << 31);
|
|
|
|
env->PSW |= ((env->PSW_USB_V & (1 << 31)) >> 1);
|
|
|
|
env->PSW |= ((env->PSW_USB_SV & (1 << 31)) >> 2);
|
|
|
|
env->PSW |= ((env->PSW_USB_AV & (1 << 31)) >> 3);
|
|
|
|
env->PSW |= ((env->PSW_USB_SAV & (1 << 31)) >> 4);
|
|
|
|
|
|
|
|
return env->PSW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void psw_write(CPUTriCoreState *env, uint32_t val)
|
|
|
|
{
|
|
|
|
env->PSW_USB_C = (val & MASK_USB_C);
|
2016-02-17 00:27:32 +03:00
|
|
|
env->PSW_USB_V = (val & MASK_USB_V) << 1;
|
|
|
|
env->PSW_USB_SV = (val & MASK_USB_SV) << 2;
|
|
|
|
env->PSW_USB_AV = (val & MASK_USB_AV) << 3;
|
|
|
|
env->PSW_USB_SAV = (val & MASK_USB_SAV) << 4;
|
2014-09-01 15:59:46 +04:00
|
|
|
env->PSW = val;
|
2016-03-11 18:03:11 +03:00
|
|
|
|
|
|
|
fpu_set_state(env);
|
2014-09-01 15:59:46 +04:00
|
|
|
}
|
2023-05-26 09:19:44 +03:00
|
|
|
|
|
|
|
#define FIELD_GETTER_WITH_FEATURE(NAME, REG, FIELD, FEATURE) \
|
|
|
|
uint32_t NAME(CPUTriCoreState *env) \
|
|
|
|
{ \
|
2023-07-21 09:06:05 +03:00
|
|
|
if (tricore_has_feature(env, TRICORE_FEATURE_##FEATURE)) { \
|
2023-05-26 09:19:44 +03:00
|
|
|
return FIELD_EX32(env->REG, REG, FIELD ## _ ## FEATURE); \
|
|
|
|
} \
|
|
|
|
return FIELD_EX32(env->REG, REG, FIELD ## _13); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FIELD_GETTER(NAME, REG, FIELD) \
|
|
|
|
uint32_t NAME(CPUTriCoreState *env) \
|
|
|
|
{ \
|
|
|
|
return FIELD_EX32(env->REG, REG, FIELD); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FIELD_SETTER_WITH_FEATURE(NAME, REG, FIELD, FEATURE) \
|
|
|
|
void NAME(CPUTriCoreState *env, uint32_t val) \
|
|
|
|
{ \
|
2023-07-21 09:06:05 +03:00
|
|
|
if (tricore_has_feature(env, TRICORE_FEATURE_##FEATURE)) { \
|
2023-05-26 09:19:44 +03:00
|
|
|
env->REG = FIELD_DP32(env->REG, REG, FIELD ## _ ## FEATURE, val); \
|
|
|
|
} \
|
|
|
|
env->REG = FIELD_DP32(env->REG, REG, FIELD ## _13, val); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FIELD_SETTER(NAME, REG, FIELD) \
|
|
|
|
void NAME(CPUTriCoreState *env, uint32_t val) \
|
|
|
|
{ \
|
|
|
|
env->REG = FIELD_DP32(env->REG, REG, FIELD, val); \
|
|
|
|
}
|
|
|
|
|
|
|
|
FIELD_GETTER_WITH_FEATURE(pcxi_get_pcpn, PCXI, PCPN, 161)
|
|
|
|
FIELD_SETTER_WITH_FEATURE(pcxi_set_pcpn, PCXI, PCPN, 161)
|
|
|
|
FIELD_GETTER_WITH_FEATURE(pcxi_get_pie, PCXI, PIE, 161)
|
|
|
|
FIELD_SETTER_WITH_FEATURE(pcxi_set_pie, PCXI, PIE, 161)
|
|
|
|
FIELD_GETTER_WITH_FEATURE(pcxi_get_ul, PCXI, UL, 161)
|
|
|
|
FIELD_SETTER_WITH_FEATURE(pcxi_set_ul, PCXI, UL, 161)
|
|
|
|
FIELD_GETTER(pcxi_get_pcxs, PCXI, PCXS)
|
|
|
|
FIELD_GETTER(pcxi_get_pcxo, PCXI, PCXO)
|
|
|
|
|
|
|
|
FIELD_GETTER_WITH_FEATURE(icr_get_ie, ICR, IE, 161)
|
|
|
|
FIELD_SETTER_WITH_FEATURE(icr_set_ie, ICR, IE, 161)
|
|
|
|
FIELD_GETTER(icr_get_ccpn, ICR, CCPN)
|
|
|
|
FIELD_SETTER(icr_set_ccpn, ICR, CCPN)
|