forked from quic/qemu
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
target/mips: Implement Loongson CSR instructions
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 <[email protected]> Message-Id: <[email protected]> [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é <[email protected]>
- Loading branch information
Showing
14 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Loongson CSR instructions | ||
# | ||
# Copyright (C) 2023 Jiaxun Yang <[email protected]> | ||
# | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
# | ||
|
||
&r rs rt rd sa | ||
|
||
@rs_rd ...... rs:5 ..... rd:5 ..... ...... &r rt=0 sa=0 | ||
|
||
CPUCFG 110010 ..... 01000 ..... 00100 011000 @rs_rd | ||
|
||
RDCSR 110010 ..... 00000 ..... 00100 011000 @rs_rd | ||
WRCSR 110010 ..... 00001 ..... 00100 011000 @rs_rd | ||
DRDCSR 110010 ..... 00010 ..... 00100 011000 @rs_rd | ||
DWRCSR 110010 ..... 00011 ..... 00100 011000 @rs_rd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Loongson CSR instructions translation routines | ||
* | ||
* Copyright (c) 2023 Jiaxun Yang <[email protected]> | ||
* | ||
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Loongson CSR instructions translation routines | ||
* | ||
* Copyright (c) 2023 Jiaxun Yang <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#include "qemu/osdep.h" | ||
#include "qemu/main-loop.h" | ||
#include "cpu.h" | ||
#include "internal.h" | ||
#include "qemu/host-utils.h" | ||
#include "exec/helper-proto.h" | ||
#include "exec/exec-all.h" | ||
#include "exec/cpu_ldst.h" | ||
|
||
#define GET_MEMTXATTRS(cas) \ | ||
((MemTxAttrs){.requester_id = env_cpu(cas)->cpu_index}) | ||
|
||
uint64_t helper_lcsr_rdcsr(CPUMIPSState *env, target_ulong r_addr) | ||
{ | ||
return address_space_ldl(&env->iocsr.as, r_addr, | ||
GET_MEMTXATTRS(env), NULL); | ||
} | ||
|
||
uint64_t helper_lcsr_drdcsr(CPUMIPSState *env, target_ulong r_addr) | ||
{ | ||
return address_space_ldq(&env->iocsr.as, r_addr, | ||
GET_MEMTXATTRS(env), NULL); | ||
} | ||
|
||
void helper_lcsr_wrcsr(CPUMIPSState *env, target_ulong w_addr, | ||
target_ulong val) | ||
{ | ||
address_space_stl(&env->iocsr.as, w_addr, | ||
val, GET_MEMTXATTRS(env), NULL); | ||
} | ||
|
||
void helper_lcsr_dwrcsr(CPUMIPSState *env, target_ulong w_addr, | ||
target_ulong val) | ||
{ | ||
address_space_stq(&env->iocsr.as, w_addr, | ||
val, GET_MEMTXATTRS(env), NULL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters