[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 14/64] target/nios2: Stop generating code if gen_check_supervi
From: |
Richard Henderson |
Subject: |
[PATCH v7 14/64] target/nios2: Stop generating code if gen_check_supervisor fails |
Date: |
Thu, 21 Apr 2022 08:16:45 -0700 |
Whether the cpu is in user-mode or not is something that we
know at translation-time. We do not need to generate code
after having raised an exception.
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/nios2/translate.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/target/nios2/translate.c b/target/nios2/translate.c
index eb97e13feb..d61e349207 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -169,12 +169,14 @@ static void gen_excp(DisasContext *dc, uint32_t code,
uint32_t flags)
t_gen_helper_raise_exception(dc, flags);
}
-static void gen_check_supervisor(DisasContext *dc)
+static bool gen_check_supervisor(DisasContext *dc)
{
if (dc->base.tb->flags & CR_STATUS_U) {
/* CPU in user mode, privileged instruction called, stop. */
t_gen_helper_raise_exception(dc, EXCP_SUPERI);
+ return false;
}
+ return true;
}
/*
@@ -384,7 +386,9 @@ static const Nios2Instruction i_type_instructions[] = {
*/
static void eret(DisasContext *dc, uint32_t code, uint32_t flags)
{
- gen_check_supervisor(dc);
+ if (!gen_check_supervisor(dc)) {
+ return;
+ }
tcg_gen_mov_tl(cpu_R[CR_STATUS], cpu_R[CR_ESTATUS]);
tcg_gen_mov_tl(cpu_R[R_PC], cpu_R[R_EA]);
@@ -447,7 +451,9 @@ static void rdctl(DisasContext *dc, uint32_t code, uint32_t
flags)
{
R_TYPE(instr, code);
- gen_check_supervisor(dc);
+ if (!gen_check_supervisor(dc)) {
+ return;
+ }
if (unlikely(instr.c == R_ZERO)) {
return;
@@ -474,9 +480,13 @@ static void rdctl(DisasContext *dc, uint32_t code,
uint32_t flags)
/* ctlN <- rA */
static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
{
- gen_check_supervisor(dc);
+ if (!gen_check_supervisor(dc)) {
+ return;
+ }
-#ifndef CONFIG_USER_ONLY
+#ifdef CONFIG_USER_ONLY
+ g_assert_not_reached();
+#else
R_TYPE(instr, code);
TCGv v = load_gpr(dc, instr.a);
--
2.34.1
- [PATCH v7 01/64] linux-user/nios2: Hoist pc advance to the top of EXCP_TRAP, (continued)
- [PATCH v7 01/64] linux-user/nios2: Hoist pc advance to the top of EXCP_TRAP, Richard Henderson, 2022/04/21
- [PATCH v7 05/64] linux-user/nios2: Handle special qemu syscall return values, Richard Henderson, 2022/04/21
- [PATCH v7 06/64] linux-user/nios2: Remove do_sigreturn, Richard Henderson, 2022/04/21
- [PATCH v7 07/64] linux-user/nios2: Use QEMU_ESIGRETURN from do_rt_sigreturn, Richard Henderson, 2022/04/21
- [PATCH v7 09/64] target/nios2: Remove user-only nios2_cpu_do_interrupt, Richard Henderson, 2022/04/21
- [PATCH v7 08/64] tests/tcg/nios2: Re-enable linux-user tests, Richard Henderson, 2022/04/21
- [PATCH v7 10/64] target/nios2: Remove nios2_cpu_record_sigsegv, Richard Henderson, 2022/04/21
- [PATCH v7 11/64] target/nios2: Build helper.c for system only, Richard Henderson, 2022/04/21
- [PATCH v7 12/64] linux-user/nios2: Use force_sig_fault for EXCP_DEBUG, Richard Henderson, 2022/04/21
- [PATCH v7 13/64] target/nios2: Check supervisor on eret, Richard Henderson, 2022/04/21
- [PATCH v7 14/64] target/nios2: Stop generating code if gen_check_supervisor fails,
Richard Henderson <=
- [PATCH v7 15/64] target/nios2: Add NUM_GP_REGS and NUM_CP_REGS, Richard Henderson, 2022/04/21
- [PATCH v7 16/64] target/nios2: Split PC out of env->regs[], Richard Henderson, 2022/04/21
- [PATCH v7 17/64] target/nios2: Split out helper for eret instruction, Richard Henderson, 2022/04/21
- [PATCH v7 18/64] target/nios2: Fix BRET instruction, Richard Henderson, 2022/04/21
- [PATCH v7 19/64] target/nios2: Do not create TCGv for control registers, Richard Henderson, 2022/04/21
- [PATCH v7 20/64] linux-user/nios2: Only initialize SP and PC in target_cpu_copy_regs, Richard Henderson, 2022/04/21
- [PATCH v7 23/64] target/nios2: Clean up nios2_cpu_dump_state, Richard Henderson, 2022/04/21
- [PATCH v7 22/64] target/nios2: Split control registers away from general registers, Richard Henderson, 2022/04/21
- [PATCH v7 24/64] target/nios2: Use hw/registerfields.h for CR_STATUS fields, Richard Henderson, 2022/04/21
- [PATCH v7 25/64] target/nios2: Use hw/registerfields.h for CR_EXCEPTION fields, Richard Henderson, 2022/04/21