[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH for-7.1 v6 20/51] target/nios2: Create EXCP_SEMIHOST for semi-hos
From: |
Richard Henderson |
Subject: |
[PATCH for-7.1 v6 20/51] target/nios2: Create EXCP_SEMIHOST for semi-hosting |
Date: |
Wed, 16 Mar 2022 22:05:07 -0700 |
Decode 'break 1' during translation, rather than doing
it again during exception processing.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/nios2/cpu.h | 1 +
target/nios2/helper.c | 14 ++++++--------
target/nios2/translate.c | 17 ++++++++++++++++-
3 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h
index 555972fe6b..d003af5afc 100644
--- a/target/nios2/cpu.h
+++ b/target/nios2/cpu.h
@@ -156,6 +156,7 @@ FIELD(CR_TLBMISC, EE, 24, 1)
/* Exceptions */
#define EXCP_BREAK 0x1000
+#define EXCP_SEMIHOST 0x1001
#define EXCP_RESET 0
#define EXCP_PRESET 1
#define EXCP_IRQ 2
diff --git a/target/nios2/helper.c b/target/nios2/helper.c
index 52a49f7ead..eeff032379 100644
--- a/target/nios2/helper.c
+++ b/target/nios2/helper.c
@@ -172,14 +172,6 @@ void nios2_cpu_do_interrupt(CPUState *cs)
case EXCP_BREAK:
qemu_log_mask(CPU_LOG_INT, "BREAK exception at pc=%x\n", env->pc);
- /* The semihosting instruction is "break 1". */
- if (semihosting_enabled() &&
- cpu_ldl_code(env, env->pc) == 0x003da07a) {
- qemu_log_mask(CPU_LOG_INT, "Entering semihosting\n");
- env->pc += 4;
- do_nios2_semihosting(env);
- break;
- }
if ((env->ctrl[CR_STATUS] & CR_STATUS_EH) == 0) {
env->ctrl[CR_BSTATUS] = env->ctrl[CR_STATUS];
@@ -196,6 +188,12 @@ void nios2_cpu_do_interrupt(CPUState *cs)
env->pc = cpu->exception_addr;
break;
+ case EXCP_SEMIHOST:
+ qemu_log_mask(CPU_LOG_INT, "BREAK semihosting at pc=%x\n", env->pc);
+ env->pc += 4;
+ do_nios2_semihosting(env);
+ break;
+
default:
cpu_abort(cs, "unhandled exception type=%d\n",
cs->exception_index);
diff --git a/target/nios2/translate.c b/target/nios2/translate.c
index 459e30b338..cfad110186 100644
--- a/target/nios2/translate.c
+++ b/target/nios2/translate.c
@@ -33,6 +33,7 @@
#include "exec/translator.h"
#include "qemu/qemu-print.h"
#include "exec/gen-icount.h"
+#include "semihosting/semihost.h"
/* is_jmp field values */
#define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */
@@ -686,6 +687,20 @@ static void trap(DisasContext *dc, uint32_t code, uint32_t
flags)
t_gen_helper_raise_exception(dc, EXCP_TRAP);
}
+static void gen_break(DisasContext *dc, uint32_t code, uint32_t flags)
+{
+#ifndef CONFIG_USER_ONLY
+ /* The semihosting instruction is "break 1". */
+ R_TYPE(instr, code);
+ if (semihosting_enabled() && instr.imm5 == 1) {
+ t_gen_helper_raise_exception(dc, EXCP_SEMIHOST);
+ return;
+ }
+#endif
+
+ t_gen_helper_raise_exception(dc, EXCP_BREAK);
+}
+
static const Nios2Instruction r_type_instructions[] = {
INSTRUCTION_ILLEGAL(),
INSTRUCTION(eret), /* eret */
@@ -739,7 +754,7 @@ static const Nios2Instruction r_type_instructions[] = {
INSTRUCTION(add), /* add */
INSTRUCTION_ILLEGAL(),
INSTRUCTION_ILLEGAL(),
- INSTRUCTION_FLG(gen_excp, EXCP_BREAK), /* break */
+ INSTRUCTION(gen_break), /* break */
INSTRUCTION_ILLEGAL(),
INSTRUCTION(nop), /* nop */
INSTRUCTION_ILLEGAL(),
--
2.25.1
- [PATCH for-7.1 v6 11/51] target/nios2: Split control registers away from general registers, (continued)
- [PATCH for-7.1 v6 11/51] target/nios2: Split control registers away from general registers, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 12/51] target/nios2: Clean up nios2_cpu_dump_state, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 13/51] target/nios2: Use hw/registerfields.h for CR_STATUS fields, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 14/51] target/nios2: Use hw/registerfields.h for CR_EXCEPTION fields, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 15/51] target/nios2: Use hw/registerfields.h for CR_TLBADDR fields, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 16/51] target/nios2: Use hw/registerfields.h for CR_TLBACC fields, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 17/51] target/nios2: Rename CR_TLBMISC_WR to CR_TLBMISC_WE, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 18/51] target/nios2: Use hw/registerfields.h for CR_TLBMISC fields, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 20/51] target/nios2: Create EXCP_SEMIHOST for semi-hosting,
Richard Henderson <=
- [PATCH for-7.1 v6 19/51] target/nios2: Move R_FOO and CR_BAR into enumerations, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 22/51] target/nios2: Hoist CPU_LOG_INT logging, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 21/51] target/nios2: Clean up nios2_cpu_do_interrupt, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 23/51] target/nios2: Handle EXCP_UNALIGN and EXCP_UALIGND, Richard Henderson, 2022/03/17
- [PATCH for-7.1 v6 25/51] target/nios2: Clean up handling of tlbmisc in do_exception, Richard Henderson, 2022/03/17