Skip to contentSkip to conversation

hvf: arm: sign extend when SSE=1

PATCH Applied Joelle van Dyne 2 participants 2 messages Feb 24, 2025 – Feb 25, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hvf: arm: sign extend when SSE=1

According to the ARM manual, when SSE=1 the data item must be sign extended.

---
 target/arm/hvf/hvf.c | 4 ++++
 1 file changed, 4 insertions(+)
target/arm/hvf/hvf.c +4 -0
index 0afd96018e..43cf250eef 100644
@@ -1971,6 +1971,7 @@ int hvf_vcpu_exec(CPUState *cpu)
         bool isv = syndrome & ARM_EL_ISV;
         bool iswrite = (syndrome >> 6) & 1;
         bool s1ptw = (syndrome >> 7) & 1;
+        bool sse = (syndrome >> 21) & 1;
         uint32_t sas = (syndrome >> 22) & 3;
         uint32_t len = 1 << sas;
         uint32_t srt = (syndrome >> 16) & 0x1f;
@@ -1998,6 +1999,9 @@ int hvf_vcpu_exec(CPUState *cpu)
             address_space_read(&address_space_memory,
                                hvf_exit->exception.physical_address,
                                MEMTXATTRS_UNSPECIFIED, &val, len);
+            if (sse && len != sizeof(uint64_t)) {
+                val = sextract64(val, 0, len * 8);
+            }
             hvf_set_reg(cpu, srt, val);
         }
 
Signature · 1 line
2.41.0
#1 lore raw
Quoted 22 lines · Joelle van Dyne

According to the ARM manual, when SSE=1 the data item must be sign extended.

---
 target/arm/hvf/hvf.c | 4 ++++
 1 file changed, 4 insertions(+)
target/arm/hvf/hvf.c +1 -0
index 0afd96018e..43cf250eef 100644
@@ -1971,6 +1971,7 @@ int hvf_vcpu_exec(CPUState *cpu)
         bool isv = syndrome & ARM_EL_ISV;
         bool iswrite = (syndrome >> 6) & 1;
         bool s1ptw = (syndrome >> 7) & 1;
+        bool sse = (syndrome >> 21) & 1;
         uint32_t sas = (syndrome >> 22) & 3;
         uint32_t len = 1 << sas;
         uint32_t srt = (syndrome >> 16) & 0x1f;

target/arm/hvf/hvf.c int hvf_vcpu_exec(CPUState *cpu) · line 2004

Quoted 6 lines
target/arm/hvf/hvf.c +3 -0
@@ -1998,6 +1999,9 @@ int hvf_vcpu_exec(CPUState *cpu)
             address_space_read(&address_space_memory,
                                hvf_exit->exception.physical_address,
                                MEMTXATTRS_UNSPECIFIED, &val, len);
+            if (sse && len != sizeof(uint64_t)) {
+                val = sextract64(val, 0, len * 8);
+            }

sse is only set for byte, halfword or word loads, so if it is set then len won't be 8. Plus sextract64(val, 0, 64) is valid (returning the input value). So we don't need to check len here.

target/arm/hvf/hvf.c int hvf_vcpu_exec(CPUState *cpu) · line 2006

Quoted 2 lines
target/arm/hvf/hvf.c +0 -0
             hvf_set_reg(cpu, srt, val);
         }

I've applied this to target-arm.next, with the check on "len" removed from the if() condition.

thanks
-- PMM