883f2c591f
The 'hwaddr' type is defined in "exec/hwaddr.h" as:
hwaddr is the type of a physical address
(its size can be different from 'target_ulong').
All definitions use the 'HWADDR_' prefix, except TARGET_FMT_plx:
$ fgrep define include/exec/hwaddr.h
#define HWADDR_H
#define HWADDR_BITS 64
#define HWADDR_MAX UINT64_MAX
#define TARGET_FMT_plx "%016" PRIx64
^^^^^^
#define HWADDR_PRId PRId64
#define HWADDR_PRIi PRIi64
#define HWADDR_PRIo PRIo64
#define HWADDR_PRIu PRIu64
#define HWADDR_PRIx PRIx64
#define HWADDR_PRIX PRIX64
Since hwaddr's size can be *different* from target_ulong, it is
very confusing to read one of its format using the 'TARGET_FMT_'
prefix, normally used for the target_long / target_ulong types:
$ fgrep TARGET_FMT_ include/exec/cpu-defs.h
#define TARGET_FMT_lx "%08x"
#define TARGET_FMT_ld "%d"
#define TARGET_FMT_lu "%u"
#define TARGET_FMT_lx "%016" PRIx64
#define TARGET_FMT_ld "%" PRId64
#define TARGET_FMT_lu "%" PRIu64
Apparently this format was missed during commit a8170e5e97
("Rename target_phys_addr_t to hwaddr"), so complete it by
doing a bulk-rename with:
$ sed -i -e s/TARGET_FMT_plx/HWADDR_FMT_plx/g $(git grep -l TARGET_FMT_plx)
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20230110212947.34557-1-philmd@linaro.org>
[thuth: Fix some warnings from checkpatch.pl along the way]
Signed-off-by: Thomas Huth <thuth@redhat.com>
155 lines
4.5 KiB
C
155 lines
4.5 KiB
C
/*
|
|
* 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
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* 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/>.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/log.h"
|
|
#include "cpu.h"
|
|
#include "exec/exec-all.h"
|
|
#include "fpu/softfloat-helpers.h"
|
|
#include "qemu/qemu-print.h"
|
|
|
|
enum {
|
|
TLBRET_DIRTY = -4,
|
|
TLBRET_INVALID = -3,
|
|
TLBRET_NOMATCH = -2,
|
|
TLBRET_BADADDR = -1,
|
|
TLBRET_MATCH = 0
|
|
};
|
|
|
|
#if defined(CONFIG_SOFTMMU)
|
|
static int get_physical_address(CPUTriCoreState *env, hwaddr *physical,
|
|
int *prot, target_ulong address,
|
|
MMUAccessType access_type, int mmu_idx)
|
|
{
|
|
int ret = TLBRET_MATCH;
|
|
|
|
*physical = address & 0xFFFFFFFF;
|
|
*prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
|
|
|
return ret;
|
|
}
|
|
|
|
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);
|
|
|
|
if (get_physical_address(&cpu->env, &phys_addr, &prot, addr,
|
|
MMU_DATA_LOAD, mmu_idx)) {
|
|
return -1;
|
|
}
|
|
return phys_addr;
|
|
}
|
|
#endif
|
|
|
|
/* TODO: Add exeption support*/
|
|
static void raise_mmu_exception(CPUTriCoreState *env, target_ulong address,
|
|
int rw, int tlb_error)
|
|
{
|
|
}
|
|
|
|
bool tricore_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
|
|
MMUAccessType rw, int mmu_idx,
|
|
bool probe, uintptr_t retaddr)
|
|
{
|
|
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,
|
|
address, rw, mmu_idx);
|
|
|
|
qemu_log_mask(CPU_LOG_MMU, "%s address=" TARGET_FMT_lx " ret %d physical "
|
|
HWADDR_FMT_plx " prot %d\n",
|
|
__func__, (target_ulong)address, ret, physical, prot);
|
|
|
|
if (ret == TLBRET_MATCH) {
|
|
tlb_set_page(cs, address & TARGET_PAGE_MASK,
|
|
physical & TARGET_PAGE_MASK, prot | PAGE_EXEC,
|
|
mmu_idx, TARGET_PAGE_SIZE);
|
|
return true;
|
|
} else {
|
|
assert(ret < 0);
|
|
if (probe) {
|
|
return false;
|
|
}
|
|
raise_mmu_exception(env, address, rw, ret);
|
|
cpu_loop_exit_restore(cs, retaddr);
|
|
}
|
|
}
|
|
|
|
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));
|
|
qemu_printf(" %s\n", name);
|
|
g_free(name);
|
|
}
|
|
|
|
void tricore_cpu_list(void)
|
|
{
|
|
GSList *list;
|
|
|
|
list = object_class_get_list_sorted(TYPE_TRICORE_CPU, false);
|
|
qemu_printf("Available CPUs:\n");
|
|
g_slist_foreach(list, tricore_cpu_list_entry, NULL);
|
|
g_slist_free(list);
|
|
}
|
|
|
|
void fpu_set_state(CPUTriCoreState *env)
|
|
{
|
|
set_float_rounding_mode(env->PSW & MASK_PSW_FPU_RM, &env->fp_status);
|
|
set_flush_inputs_to_zero(1, &env->fp_status);
|
|
set_flush_to_zero(1, &env->fp_status);
|
|
set_default_nan_mode(1, &env->fp_status);
|
|
}
|
|
|
|
uint32_t psw_read(CPUTriCoreState *env)
|
|
{
|
|
/* clear all USB bits */
|
|
env->PSW &= 0x6ffffff;
|
|
/* 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);
|
|
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;
|
|
env->PSW = val;
|
|
|
|
fpu_set_state(env);
|
|
}
|