Skip to contentSkip to conversation

target-arm: ESR IL bit fixes

PATCH In review Peter Maydell 2 participants 7 messages May 17, 2016

lore
Share & tools
lore
#0 lore raw

cover target-arm: ESR IL bit fixes

These patches fix some problems with setting the IL bit in ESR syndrome register values:
* we were not setting IL for insn abort, watchpoint or swstep (which should all always have IL==1)
* we were trying to set the IL bit in arm_cpu_do_interrupt_aarch64() if doing a 32->64 bit exception entry, which was wrong in several ways; instead we should just rely on exception.syndrome already having the correct IL bit value

The patches are intended to apply on top of target-arm.next:
https://git.linaro.org/people/peter.maydell/qemu-arm.git target-arm.next
(which has Edgar's patch which gets us correct IL bit values for data abort exceptions).

Peter Maydell (2):
target-arm: Set IL bit in syndromes for insn abort, watchpoint, swstep
target-arm: Don't try to set ESR IL bit in

    arm_cpu_do_interrupt_aarch64()
 target-arm/helper.c    | 3 ---
 target-arm/internals.h | 6 +++---
 2 files changed, 3 insertions(+), 6 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 target-arm: Set IL bit in syndromes for insn abort, watchpoint, swstep

For some exception syndrome types, the IL bit should always be set. This includes the instruction abort, watchpoint and software step syndrome types; add the missing ARM_EL_IL bit to the syndrome values returned by syn_insn_abort(), syn_swstep() and syn_watchpoint().

---
 target-arm/internals.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target-arm/internals.h +3 -3
index 54a0fb1..7768a24 100644
@@ -382,7 +382,7 @@ static inline uint32_t syn_fp_access_trap(int cv, int cond, bool is_16bit)
 static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int fsc)
 {
     return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
-        | (ea << 9) | (s1ptw << 7) | fsc;
+        | ARM_EL_IL | (ea << 9) | (s1ptw << 7) | fsc;
 }
 
 static inline uint32_t syn_data_abort_no_iss(int same_el,
@@ -411,13 +411,13 @@ static inline uint32_t syn_data_abort_with_iss(int same_el,
 static inline uint32_t syn_swstep(int same_el, int isv, int ex)
 {
     return (EC_SOFTWARESTEP << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
-        | (isv << 24) | (ex << 6) | 0x22;
+        | ARM_EL_IL | (isv << 24) | (ex << 6) | 0x22;
 }
 
 static inline uint32_t syn_watchpoint(int same_el, int cm, int wnr)
 {
     return (EC_WATCHPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
-        | (cm << 8) | (wnr << 6) | 0x22;
+        | ARM_EL_IL | (cm << 8) | (wnr << 6) | 0x22;
 }
 
 static inline uint32_t syn_breakpoint(int same_el)
Signature · 1 line
1.9.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] target-arm: Set IL bit in syndromes for insn abort, watchpoint, swstep

Quoted 4 lines · Peter Maydell

For some exception syndrome types, the IL bit should always be set. This includes the instruction abort, watchpoint and software step syndrome types; add the missing ARM_EL_IL bit to the syndrome values returned by syn_insn_abort(), syn_swstep() and syn_watchpoint().

Hi,

Maybe we should have a reference in a comment to the table in the pseudo code for AArch64.ExceptionClass?
It makes it a little easier to understand some of these settings...

Either way:

Cheers,
Edgar

Quoted 38 lines
---
 target-arm/internals.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target-arm/internals.h +3 -3
index 54a0fb1..7768a24 100644
@@ -382,7 +382,7 @@ static inline uint32_t syn_fp_access_trap(int cv, int cond, bool is_16bit)
 static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int fsc)
 {
     return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
-        | (ea << 9) | (s1ptw << 7) | fsc;
+        | ARM_EL_IL | (ea << 9) | (s1ptw << 7) | fsc;
 }
 
 static inline uint32_t syn_data_abort_no_iss(int same_el,
@@ -411,13 +411,13 @@ static inline uint32_t syn_data_abort_with_iss(int same_el,
 static inline uint32_t syn_swstep(int same_el, int isv, int ex)
 {
     return (EC_SOFTWARESTEP << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
-        | (isv << 24) | (ex << 6) | 0x22;
+        | ARM_EL_IL | (isv << 24) | (ex << 6) | 0x22;
 }
 
 static inline uint32_t syn_watchpoint(int same_el, int cm, int wnr)
 {
     return (EC_WATCHPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
-        | (cm << 8) | (wnr << 6) | 0x22;
+        | ARM_EL_IL | (cm << 8) | (wnr << 6) | 0x22;
 }
 
 static inline uint32_t syn_breakpoint(int same_el)
Signature · 1 line
1.9.1
#3 lore raw

Re: [Qemu-arm] [PATCH 1/2] target-arm: Set IL bit in syndromes for insn abort, watchpoint, swstep

Quoted 9 lines · Edgar E. Iglesias
Quoted 4 lines · Peter Maydell

For some exception syndrome types, the IL bit should always be set. This includes the instruction abort, watchpoint and software step syndrome types; add the missing ARM_EL_IL bit to the syndrome values returned by syn_insn_abort(), syn_swstep() and syn_watchpoint().

Maybe we should have a reference in a comment to the table in the pseudo code for AArch64.ExceptionClass?
It makes it a little easier to understand some of these settings...

I just used the text parts of the ARM ARM as reference for this one, not the pseudocode (specifically, D7.2.27, the ESR_ELx register description, has the definition of the IL bit and says which exceptions have IL set). I think for pretty much any feature in the emulation you need to look it up in the ARM ARM to understand what it's doing, and we could end up with cross-references every other line...

thanks
-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] target-arm: Set IL bit in syndromes for insn abort, watchpoint, swstep

Quoted 7 lines · Peter Maydell
Quoted 5 lines · Edgar E. Iglesias
Quoted 4 lines · Peter Maydell

For some exception syndrome types, the IL bit should always be set. This includes the instruction abort, watchpoint and software step syndrome types; add the missing ARM_EL_IL bit to the syndrome values returned by syn_insn_abort(), syn_swstep() and syn_watchpoint().

Quoted 6 lines
Quoted 3 lines

Maybe we should have a reference in a comment to the table in the pseudo code for AArch64.ExceptionClass?
It makes it a little easier to understand some of these settings...

I just used the text parts of the ARM ARM as reference for this one, not the pseudocode (specifically, D7.2.27, the ESR_ELx register description,

Aha, I hadn't seen that text. I always end up in D1.10.4 where the IL description is quite brief.

Quoted 4 lines

has the definition of the IL bit and says which exceptions have IL set). I think for pretty much any feature in the emulation you need to look it up in the ARM ARM to understand what it's doing, and we could end up with cross-references every other line...

Yeah, fair enough.

Cheers,
Edgar

#5 lore raw

PATCH 2/2 target-arm: Don't try to set ESR IL bit in arm_cpu_do_interrupt_aarch64()

In reply to Peter Maydell

Remove some incorrect code from arm_cpu_do_interrupt_aarch64() which attempts to set the IL bit in the syndrome register based on the value of env->thumb. This is wrong in several ways:
* IL doesn't indicate Thumb-vs-ARM, it indicates instruction length (which may be 16 or 32 for Thumb and is always 32 for ARM)
* not every syndrome format uses IL like this -- for some IL is always set, and for some it is always clear
* the code is changing esr_el[new_el] even for interrupt entry, which is not supposed to modify ESR_ELx at all

Delete the code, and instead rely on the syndrome value in env->exception.syndrome having already been set up with the correct value of IL.

---
 target-arm/helper.c | 3 ---
 1 file changed, 3 deletions(-)
target-arm/helper.c +0 -3
index d652c01..df65e68 100644
@@ -6349,9 +6349,6 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)
         env->elr_el[new_el] = env->pc;
     } else {
         env->banked_spsr[aarch64_banked_spsr_index(new_el)] = cpsr_read(env);
-        if (!env->thumb) {
-            env->cp15.esr_el[new_el] |= 1 << 25;
-        }
         env->elr_el[new_el] = env->regs[15];
 
         aarch64_sync_32_to_64(env);
Signature · 1 line
1.9.1
Reviewed-by Tested-by on v1 2/2
#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-arm: Don't try to set ESR IL bit in arm_cpu_do_interrupt_aarch64()

Quoted 10 lines · Peter Maydell

Remove some incorrect code from arm_cpu_do_interrupt_aarch64() which attempts to set the IL bit in the syndrome register based on the value of env->thumb. This is wrong in several ways:
* IL doesn't indicate Thumb-vs-ARM, it indicates instruction length (which may be 16 or 32 for Thumb and is always 32 for ARM)
* not every syndrome format uses IL like this -- for some IL is always set, and for some it is always clear
* the code is changing esr_el[new_el] even for interrupt entry, which is not supposed to modify ESR_ELx at all

Quoted 3 lines

Delete the code, and instead rely on the syndrome value in env->exception.syndrome having already been set up with the correct value of IL.

Quoted 23 lines
---
 target-arm/helper.c | 3 ---
 1 file changed, 3 deletions(-)
target-arm/helper.c +0 -3
index d652c01..df65e68 100644
@@ -6349,9 +6349,6 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)
         env->elr_el[new_el] = env->pc;
     } else {
         env->banked_spsr[aarch64_banked_spsr_index(new_el)] = cpsr_read(env);
-        if (!env->thumb) {
-            env->cp15.esr_el[new_el] |= 1 << 25;
-        }
         env->elr_el[new_el] = env->regs[15];
 
         aarch64_sync_32_to_64(env);
Signature · 1 line
1.9.1