Skip to contentSkip to conversation

ARM: BKPT instructions should raise prefetch aborts with IFSR type 00010

Qemu-devel Applied Alex Zuepke 3 participants 6 messages Mar 25, 2011 – Jun 3, 2011

lore
Share & tools
lore
#0 lore raw

Hi,

while digging through some problems with BKPT exceptions on ARM, I discovered that QEMU does not update IFSR on prefetch aborts. This should be done since ARMv6 according to ARM docs. Please include.

Best Regards,
Alex

Signature · 2 lines
Alexander Zuepke                                [email protected]
SYSGO AG ~ Am Pfaffenstein 14 ~ 55270 Klein-Winternheim ~ Germany

target-arm: BKPT instructions should raise prefetch aborts with IFSR type 00010 diff against qemu 0.14.0

target-arm/translate.c +2 -0
@@ -6389,6 +6389,7 @@
                 goto illegal_op;
             }
             /* bkpt */
+            env->cp15.c5_insn = 2;
             gen_exception_insn(s, 4, EXCP_BKPT);
             break;
         case 0x8: /* signed multiply */
@@ -8930,6 +8931,7 @@
             break;
 
         case 0xe: /* bkpt */
+            env->cp15.c5_insn = 2;
             gen_exception_insn(s, 2, EXCP_BKPT);
             break;
 
#1 lore raw
Quoted 3 lines · Alex Zuepke

while digging through some problems with BKPT exceptions on ARM, I discovered that QEMU does not update IFSR on prefetch aborts. This should be done since ARMv6 according to ARM docs. Please include.

This patch is the wrong approach to fixing this bug -- the updating of the IFSR needs to be done when the exception is taken, not when we translate the breakpoint instruction.

I'll put this on my todo list. If you happen to have a convenient test case demonstrating the problem, that would make a fix happen faster ;-)

-- PMM

#2 lore raw

Hi Peter,

Quoted 8 lines · Peter Maydell
Quoted 3 lines · Alex Zuepke

while digging through some problems with BKPT exceptions on ARM, I discovered that QEMU does not update IFSR on prefetch aborts. This should be done since ARMv6 according to ARM docs. Please include.

This patch is the wrong approach to fixing this bug -- the updating of the IFSR needs to be done when the exception is taken, not when we translate the breakpoint instruction.

target-arm/helper.c +2 -0
@@ -808,6 +808,8 @@ void do_interrupt(CPUARMState *env)
                 return;
             }
         }
+        /* indicate debug exception in IFSR */
+        env->cp15.c5_insn = 2;
         /* Fall through to prefetch abort.  */
     case EXCP_PREFETCH_ABORT:
         new_mode = ARM_CPU_MODE_ABT;

Something like this? This neither looks good ...

Quoted 3 lines

I'll put this on my todo list. If you happen to have a convenient test case demonstrating the problem, that would make a fix happen faster ;-)

Testcase is attached.

$ gunzip tc.elf.gz
$ qemu-system-arm.orig -nographic --cpu cortex-a8 -kernel tc.elf
testcase: IFSR undefined on QEMU
got prefetch abort, IFSR is 12345678
test: failed
HALT
Killed
$ qemu-system-arm.fixed -nographic --cpu cortex-a8 -kernel tc.elf
testcase: IFSR undefined on QEMU
got prefetch abort, IFSR is 00000002
test: OK
HALT
Killed

Best Regards,
Alex

Signature · 2 lines
Alexander Zuepke                                [email protected]
SYSGO AG ~ Am Pfaffenstein 14 ~ 55270 Klein-Winternheim ~ Germany
#3 lore raw
In reply to Peter Maydell

Hi,

Quoted 9 lines · Peter Maydell
Quoted 3 lines · Alex Zuepke

while digging through some problems with BKPT exceptions on ARM, I discovered that QEMU does not update IFSR on prefetch aborts. This should be done since ARMv6 according to ARM docs. Please include.

This patch is the wrong approach to fixing this bug -- the updating of the IFSR needs to be done when the exception is taken, not when we translate the breakpoint instruction.

Quoted 5 lines

I'll put this on my todo list. If you happen to have a convenient test case demonstrating the problem, that would make a fix happen faster ;-)

-- PMM

I tried to fix it, new patch attached.
But I'm not sure if it is required for semihosting as well.

On ARMv7-M bkpt works differently, and debug registers aren't implemented yet, so I didn't touch it.

Best Regards,
Alex

Signature · 2 lines
Alexander Zuepke                                [email protected]
SYSGO AG ~ Am Pfaffenstein 14 ~ 55270 Klein-Winternheim ~ Germany

target-arm: BKPT instructions should raise prefetch aborts with IFSR type 00010 diff against qemu 0.14.1

target-arm/helper.c +1 -0
@@ -847,6 +849,7 @@ void do_interrupt(CPUARMState *env)
                 return;
             }
         }
+        env->cp15.c5_insn = 2;
         /* Fall through to prefetch abort.  */
     case EXCP_PREFETCH_ABORT:
         new_mode = ARM_CPU_MODE_ABT;
Reviewed-by
#4 lore raw
Quoted 7 lines · Alex Zuepke
Quoted 4 lines · Peter Maydell
Quoted 3 lines · Alex Zuepke

while digging through some problems with BKPT exceptions on ARM, I discovered that QEMU does not update IFSR on prefetch aborts. This should be done since ARMv6 according to ARM docs. Please include.

I tried to fix it, new patch attached.

Thanks. I've looked at it and given it a quick test; I'm happy with this version.

Quoted 1 line

But I'm not sure if it is required for semihosting as well.

I think the value of IFSR is not defined after a semihosting request (different implementations might use an actual SVC handler or might intercept the SVC before it becomes an actual CPU SVC exception). For QEMU we handle the semihosting request and return immediately rather than actually delivering a CPU exception, so I think it makes sense not to set IFSR in that case.

-- PMM

#5 lore raw
In reply to Alex Zuepke
Quoted 16 lines · Alex Zuepke

Hi,

Quoted 13 lines · Peter Maydell
Quoted 3 lines · Alex Zuepke

while digging through some problems with BKPT exceptions on ARM, I discovered that QEMU does not update IFSR on prefetch aborts. This should be done since ARMv6 according to ARM docs. Please include.

This patch is the wrong approach to fixing this bug -- the updating of the IFSR needs to be done when the exception is taken, not when we translate the breakpoint instruction.

I'll put this on my todo list. If you happen to have a convenient test case demonstrating the problem, that would make a fix happen faster ;-)

Quoted 8 lines
Quoted 1 line

-- PMM

I tried to fix it, new patch attached.
But I'm not sure if it is required for semihosting as well.

On ARMv7-M bkpt works differently, and debug registers aren't implemented yet, so I didn't touch it.

Thanks, applied. In the future, could you please send the patch inline, or at least attach a patch that can be applied with git am?

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net