Skip to contentSkip to conversation

target-lm32: stop VM on illegal or unknown instruction

RFC PATCH New Michael Walle 1 participant 1 message Sep 25, 2013

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 target-lm32: stop VM on illegal or unknown instruction

Instead of translating the instruction to a no-op, pause the VM and display a message to the user.

As a side effect, this also works for instructions where the operands are only known at runtime.

I have some doubt about the implementation of the "ill" helper. Esp. if it is allowed to call qemu_system_vmstop_request()?

Maybe someone has a better idea. Richard Henderson proposed to raise EXCP_DEBUG, but that may lead to a segmentation fault within the gdbstub if it has not been initialized. Eg. running qemu without the '-s' commandline switch.

---
 target-lm32/helper.h    |    1 +
 target-lm32/op_helper.c |   17 +++++++++
 target-lm32/translate.c |   91 +++++++++++++++++++++++++++++++----------------
 3 files changed, 79 insertions(+), 30 deletions(-)
target-lm32/helper.h +1 -0
index ad44fdf..f4442e0 100644
@@ -13,5 +13,6 @@ DEF_HELPER_1(rcsr_im, i32, env)
 DEF_HELPER_1(rcsr_ip, i32, env)
 DEF_HELPER_1(rcsr_jtx, i32, env)
 DEF_HELPER_1(rcsr_jrx, i32, env)
+DEF_HELPER_1(ill, void, env)
 
 #include "exec/def-helper.h"
target-lm32/op_helper.c +17 -0
index 71f21d1..7189cb5 100644
@@ -8,6 +8,10 @@
 
 #include "exec/softmmu_exec.h"
 
+#ifndef CONFIG_USER_ONLY
+#include "sysemu/sysemu.h"
+#endif
+
 #if !defined(CONFIG_USER_ONLY)
 #define MMUSUFFIX _mmu
 #define SHIFT 0
@@ -39,6 +43,19 @@ void HELPER(hlt)(CPULM32State *env)
     cpu_loop_exit(env);
 }
 
+void HELPER(ill)(CPULM32State *env)
+{
+#ifndef CONFIG_USER_ONLY
+    CPUState *cs = CPU(lm32_env_get_cpu(env));
+    fprintf(stderr, "VM paused due to illegal instruction. "
+            "Connect a debugger or switch to the monitor console "
+            "to find out more.\n");
+    qemu_system_vmstop_request(RUN_STATE_PAUSED);
+    cs->halted = 1;
+    raise_exception(env, EXCP_HALTED);
+#endif
+}
+
 void HELPER(wcsr_bp)(CPULM32State *env, uint32_t bp, uint32_t idx)
 {
     uint32_t addr = bp & ~1;
target-lm32/translate.c +61 -30

192 lines not on this page · raw message

Signature · 1 line
1.7.10.4