Skip to contentSkip to conversation

Buggy wfi support for ARM user

Qemu-devel Laurent Desnogues 3 participants 5 messages Jun 8, 2008

lore
Share & tools
lore
#0 lore raw

The wfi instruction for user mode ARM results in:

qemu: unhandled CPU exception 0x10001 - aborting

I propose that for user mode this instruction be considered as a NOP. Any thoughts?

Laurent

#1 lore raw
Quoted 6 lines · Laurent Desnogues

The wfi instruction for user mode ARM results in:

qemu: unhandled CPU exception 0x10001 - aborting

I propose that for user mode this instruction be considered as a NOP. Any thoughts?

Allowing usermode to issue WFI sounds like a bug.

Paul

#2 lore raw
Quoted 4 lines
Quoted 2 lines

I propose that for user mode this instruction be considered as a NOP. Any thoughts?

Allowing usermode to issue WFI sounds like a bug.

Here is a proposal that makes WFI no-ops for user mode emulation. Comments welcome, especially as I am not used to send patches :)

Laurent

config-host.mak +1 -1
diff -ru -x .svn trunk/config-host.mak edit/config-host.mak
@@ -27,7 +27,7 @@
 CONFIG_VNC_TLS_CFLAGS= 
 CONFIG_VNC_TLS_LIBS=-lgnutls  
 VERSION=0.9.1
-SRC_PATH=/home/ldesnogu/work/Emu/qemu/trunk
+SRC_PATH=/home/ldesnogu/work/Emu/qemu/edit
 TARGET_DIRS=arm-linux-user
 CONFIG_SDL=yes
 SDL_LIBS=-L/usr/lib64 -lSDL -lpthread
target-arm/helpers.h +2 -0
diff -ru -x .svn trunk/target-arm/helpers.h edit/target-arm/helpers.h
@@ -122,7 +122,9 @@
 
 DEF_HELPER_1_3(sel_flags, uint32_t, (uint32_t, uint32_t, uint32_t))
 DEF_HELPER_0_1(exception, void, (uint32_t))
+#ifndef CONFIG_USER_ONLY
 DEF_HELPER_0_0(wfi, void, (void))
+#endif
 
 DEF_HELPER_0_2(cpsr_write, void, (uint32_t, uint32_t))
 DEF_HELPER_1_0(cpsr_read, uint32_t, (void))
target-arm/op_helper.c +2 -0
diff -ru -x .svn trunk/target-arm/op_helper.c edit/target-arm/op_helper.c
@@ -247,12 +247,14 @@
     return res;
 }
 
+#ifndef CONFIG_USER_ONLY
 void HELPER(wfi)(void)
 {
     env->exception_index = EXCP_HLT;
     env->halted = 1;
     cpu_loop_exit();
 }
+#endif
 
 void HELPER(exception)(uint32_t excp)
 {
target-arm/translate.c +12 -0
diff -ru -x .svn trunk/target-arm/translate.c edit/target-arm/translate.c
@@ -69,7 +69,10 @@
 
 /* These instructions trap after executing, so defer them until after the
    conditional executions state has been updated.  */
+/* for user mode hosted emulation wfi is treated as a no-op */
+#ifndef CONFIG_USER_ONLY
 #define DISAS_WFI 4
+#endif
 #define DISAS_SWI 5
 
 /* XXX: move that elsewhere */
@@ -2619,8 +2622,12 @@
     if ((insn & 0x0fff0fff) == 0x0e070f90
         || (insn & 0x0fff0fff) == 0x0e070f58) {
         /* Wait for interrupt.  */
+        /* for user mode hosted emulation wfi is treated as a no-op */
+        /* FIXME:  for ARMv7 this should always be a no-op */
+#ifndef CONFIG_USER_ONLY
         gen_set_pc_im(s->pc);
         s->is_jmp = DISAS_WFI;
+#endif
         return 0;
     }
     rd = (insn >> 12) & 0xf;
@@ -3499,8 +3506,11 @@
 {
     switch (val) {
     case 3: /* wfi */
+        /* for user mode hosted emulation wfi is treated as a no-op */
+#ifndef CONFIG_USER_ONLY
         gen_set_pc_im(s->pc);
         s->is_jmp = DISAS_WFI;
+#endif
         break;
     case 2: /* wfe */
     case 4: /* sev */
@@ -8712,9 +8722,11 @@
         case DISAS_TB_JUMP:
             /* nothing more to generate */
             break;
+#ifndef CONFIG_USER_ONLY
         case DISAS_WFI:
             gen_helper_wfi();
             break;
+#endif
         case DISAS_SWI:
             gen_exception(EXCP_SWI);
             break;
#3 lore raw
Quoted 7 lines · Laurent Desnogues
Quoted 4 lines
Quoted 2 lines

I propose that for user mode this instruction be considered as a NOP. Any thoughts?

Allowing usermode to issue WFI sounds like a bug.

Here is a proposal that makes WFI no-ops for user mode emulation. Comments welcome, especially as I am not used to send patches :)

Generally, the config-host.mak part should be suppressed in patches.

I don't know about this WFI case or even much of ARM at all, but if enabling WFI is controversial, maybe it could be implemented as a CPU feature so that it is disabled by default.

#4 lore raw
Quoted 10 lines · Blue Swirl
Quoted 7 lines · Laurent Desnogues
Quoted 4 lines
Quoted 2 lines

I propose that for user mode this instruction be considered as a NOP. Any thoughts?

Allowing usermode to issue WFI sounds like a bug.

Here is a proposal that makes WFI no-ops for user mode emulation. Comments welcome, especially as I am not used to send patches :)

Generally, the config-host.mak part should be suppressed in patches.

Sorry about that, I used make clean instead of distclean.

Quoted 3 lines

I don't know about this WFI case or even much of ARM at all, but if enabling WFI is controversial, maybe it could be implemented as a CPU feature so that it is disabled by default.

It's not controversial I think. It's just that it's architected to be executable by user processes. However it only makes sense if a process can receive interruptions which is not really the case for qemu user mode emulation. This instruction is used to reduce power in idle loops.

Laurent

Only in trunk: build.log

target-arm/helpers.h +2 -0
diff -ru -x .svn trunk/target-arm/helpers.h edit/target-arm/helpers.h
@@ -122,7 +122,9 @@
 
 DEF_HELPER_1_3(sel_flags, uint32_t, (uint32_t, uint32_t, uint32_t))
 DEF_HELPER_0_1(exception, void, (uint32_t))
+#ifndef CONFIG_USER_ONLY
 DEF_HELPER_0_0(wfi, void, (void))
+#endif
 
 DEF_HELPER_0_2(cpsr_write, void, (uint32_t, uint32_t))
 DEF_HELPER_1_0(cpsr_read, uint32_t, (void))
target-arm/op_helper.c +2 -0
diff -ru -x .svn trunk/target-arm/op_helper.c edit/target-arm/op_helper.c
@@ -247,12 +247,14 @@
     return res;
 }
 
+#ifndef CONFIG_USER_ONLY
 void HELPER(wfi)(void)
 {
     env->exception_index = EXCP_HLT;
     env->halted = 1;
     cpu_loop_exit();
 }
+#endif
 
 void HELPER(exception)(uint32_t excp)
 {
target-arm/translate.c +12 -0
diff -ru -x .svn trunk/target-arm/translate.c edit/target-arm/translate.c
@@ -69,7 +69,10 @@
 
 /* These instructions trap after executing, so defer them until after the
    conditional executions state has been updated.  */
+/* for user mode hosted emulation wfi is treated as a no-op */
+#ifndef CONFIG_USER_ONLY
 #define DISAS_WFI 4
+#endif
 #define DISAS_SWI 5
 
 /* XXX: move that elsewhere */
@@ -2619,8 +2622,12 @@
     if ((insn & 0x0fff0fff) == 0x0e070f90
         || (insn & 0x0fff0fff) == 0x0e070f58) {
         /* Wait for interrupt.  */
+        /* for user mode hosted emulation wfi is treated as a no-op */
+        /* FIXME:  for ARMv7 this should always be a no-op */
+#ifndef CONFIG_USER_ONLY
         gen_set_pc_im(s->pc);
         s->is_jmp = DISAS_WFI;
+#endif
         return 0;
     }
     rd = (insn >> 12) & 0xf;
@@ -3499,8 +3506,11 @@
 {
     switch (val) {
     case 3: /* wfi */
+        /* for user mode hosted emulation wfi is treated as a no-op */
+#ifndef CONFIG_USER_ONLY
         gen_set_pc_im(s->pc);
         s->is_jmp = DISAS_WFI;
+#endif
         break;
     case 2: /* wfe */
     case 4: /* sev */
@@ -8712,9 +8722,11 @@
         case DISAS_TB_JUMP:
             /* nothing more to generate */
             break;
+#ifndef CONFIG_USER_ONLY
         case DISAS_WFI:
             gen_helper_wfi();
             break;
+#endif
         case DISAS_SWI:
             gen_exception(EXCP_SWI);
             break;