This is an automated email from Gerrit.

"Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8271

-- gerrit

commit 71a390a195f6cbf742e79c2afd6c797a39fc23b8
Author: Antonio Borneo <borneo.anto...@gmail.com>
Date:   Tue May 14 11:03:45 2024 +0200

    target: aarch64: access reg ELR_EL2 only in EL2 and EL3
    
    The register ELR_EL2 is accessible and it's content is relevant
    only when the target is in EL2 or EL3.
    Virtualization SW in EL1 can also access it, but this either
    triggers a trap to EL2 or returns ELR_EL1. Debugger should not mix
    the real ELR_EL2 with the virtual register.
    
    Without this patch, an error:
            Error: Opcode 0xd53c4020, DSCR.ERR=1, DSCR.EL=1
    is triggered by GDB register window or through GDB command
            x/p $ELR_EL2
    or through OpenOCD command
            reg ELR_EL2
    
    Detect the EL and return error if the register cannot be accessed.
    
    Change-Id: Idf02b42a7339df83260c1e44ceabbb05fbf392b9
    Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com>

diff --git a/src/target/armv8.c b/src/target/armv8.c
index e8c189c1c8..a537d610ca 100644
--- a/src/target/armv8.c
+++ b/src/target/armv8.c
@@ -319,6 +319,11 @@ static int armv8_read_reg(struct armv8_common *armv8, int 
regnum, uint64_t *regv
                                ARMV8_MRS(SYSTEM_ELR_EL1, 0), &value_64);
                break;
        case ARMV8_ELR_EL2:
+               if (curel < SYSTEM_CUREL_EL2) {
+                       LOG_DEBUG("ELR_EL2 not accessible in EL%u", curel);
+                       retval = ERROR_FAIL;
+                       break;
+               }
                retval = dpm->instr_read_data_r0_64(dpm,
                                ARMV8_MRS(SYSTEM_ELR_EL2, 0), &value_64);
                break;
@@ -454,6 +459,11 @@ static int armv8_write_reg(struct armv8_common *armv8, int 
regnum, uint64_t valu
                                ARMV8_MSR_GP(SYSTEM_ELR_EL1, 0), value_64);
                break;
        case ARMV8_ELR_EL2:
+               if (curel < SYSTEM_CUREL_EL2) {
+                       LOG_DEBUG("ELR_EL2 not accessible in EL%u", curel);
+                       retval = ERROR_FAIL;
+                       break;
+               }
                retval = dpm->instr_write_data_r0_64(dpm,
                                ARMV8_MSR_GP(SYSTEM_ELR_EL2, 0), value_64);
                break;

-- 

Reply via email to