03afdc28b3
Loongson introduced CSR instructions since 3A4000, which looks similar to IOCSR and CPUCFG instructions we seen in LoongArch. Unfortunately we don't have much document about those instructions, bit fields of CPUCFG instructions and IOCSR registers can be found at 3A4000's user manual, while instruction encodings can be found at arch/mips/include/asm/mach-loongson64/loongson_regs.h from Linux Kernel. Our predefined CPUCFG bits are differ from actual 3A4000, since we can't emulate all CPUCFG features present in 3A4000 for now, we just enable bits for what we have in TCG. Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> Message-Id: <20230521214832.20145-2-jiaxun.yang@flygoat.com> [JY: Fixed typo in ase_lcsr_available(), retrict GEN_FALSE_TRANS] [PMD: Fix meson's mips_softmmu_ss -> mips_system_ss, restrict AddressSpace/MemoryRegion to SysEmu] Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
76 lines
1.7 KiB
C
76 lines
1.7 KiB
C
/*
|
|
* Loongson CSR instructions translation routines
|
|
*
|
|
* Copyright (c) 2023 Jiaxun Yang <jiaxun.yang@flygoat.com>
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "cpu.h"
|
|
#include "tcg/tcg-op.h"
|
|
#include "tcg/tcg-op-gvec.h"
|
|
#include "exec/helper-gen.h"
|
|
#include "translate.h"
|
|
|
|
/* Include the auto-generated decoder. */
|
|
#include "decode-lcsr.c.inc"
|
|
|
|
static bool trans_CPUCFG(DisasContext *ctx, arg_CPUCFG *a)
|
|
{
|
|
TCGv dest = tcg_temp_new();
|
|
TCGv src1 = tcg_temp_new();
|
|
|
|
gen_load_gpr(src1, a->rs);
|
|
gen_helper_lcsr_cpucfg(dest, cpu_env, src1);
|
|
gen_store_gpr(dest, a->rd);
|
|
|
|
return true;
|
|
}
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
static bool gen_rdcsr(DisasContext *ctx, arg_r *a,
|
|
void (*func)(TCGv, TCGv_ptr, TCGv))
|
|
{
|
|
TCGv dest = tcg_temp_new();
|
|
TCGv src1 = tcg_temp_new();
|
|
|
|
check_cp0_enabled(ctx);
|
|
gen_load_gpr(src1, a->rs);
|
|
func(dest, cpu_env, src1);
|
|
gen_store_gpr(dest, a->rd);
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool gen_wrcsr(DisasContext *ctx, arg_r *a,
|
|
void (*func)(TCGv_ptr, TCGv, TCGv))
|
|
{
|
|
TCGv val = tcg_temp_new();
|
|
TCGv addr = tcg_temp_new();
|
|
|
|
check_cp0_enabled(ctx);
|
|
gen_load_gpr(addr, a->rs);
|
|
gen_load_gpr(val, a->rd);
|
|
func(cpu_env, addr, val);
|
|
|
|
return true;
|
|
}
|
|
|
|
TRANS(RDCSR, gen_rdcsr, gen_helper_lcsr_rdcsr)
|
|
TRANS(DRDCSR, gen_rdcsr, gen_helper_lcsr_drdcsr)
|
|
TRANS(WRCSR, gen_wrcsr, gen_helper_lcsr_wrcsr)
|
|
TRANS(DWRCSR, gen_wrcsr, gen_helper_lcsr_dwrcsr)
|
|
#else
|
|
#define GEN_FALSE_TRANS(name) \
|
|
static bool trans_##name(DisasContext *ctx, arg_##name * a) \
|
|
{ \
|
|
return false; \
|
|
}
|
|
|
|
GEN_FALSE_TRANS(RDCSR)
|
|
GEN_FALSE_TRANS(DRDCSR)
|
|
GEN_FALSE_TRANS(WRCSR)
|
|
GEN_FALSE_TRANS(DWRCSR)
|
|
#endif
|