arm_adi_v5: fix access to 64-bit MEM-AP
[openocd.git] / src / target / arm_adi_v5.c
index c421fe6a3935069ebcd6562034efed1e2f49e30a..2bb11b25ec2f26b9c3807fab1982af74e3cf7f37 100644 (file)
@@ -946,25 +946,30 @@ int dap_get_debugbase(struct adiv5_ap *ap,
        int retval;
        uint32_t baseptr_upper, baseptr_lower;
 
-       baseptr_upper = 0;
-
-       if (is_64bit_ap(ap)) {
-               /* Read higher order 32-bits of base address */
-               retval = dap_queue_ap_read(ap, MEM_AP_REG_BASE64, &baseptr_upper);
+       if (ap->cfg_reg == MEM_AP_REG_CFG_INVALID) {
+               retval = dap_queue_ap_read(ap, MEM_AP_REG_CFG, &ap->cfg_reg);
                if (retval != ERROR_OK)
                        return retval;
        }
-
        retval = dap_queue_ap_read(ap, MEM_AP_REG_BASE, &baseptr_lower);
        if (retval != ERROR_OK)
                return retval;
        retval = dap_queue_ap_read(ap, AP_REG_IDR, apid);
        if (retval != ERROR_OK)
                return retval;
+       /* MEM_AP_REG_BASE64 is defined as 'RES0'; can be read and then ignored on 32 bits AP */
+       if (ap->cfg_reg == MEM_AP_REG_CFG_INVALID || is_64bit_ap(ap)) {
+               retval = dap_queue_ap_read(ap, MEM_AP_REG_BASE64, &baseptr_upper);
+               if (retval != ERROR_OK)
+                       return retval;
+       }
+
        retval = dap_run(dap);
        if (retval != ERROR_OK)
                return retval;
 
+       if (!is_64bit_ap(ap))
+               baseptr_upper = 0;
        *dbgbase = (((target_addr_t)baseptr_upper) << 32) | baseptr_lower;
 
        return ERROR_OK;
@@ -1310,8 +1315,8 @@ static int dap_rom_display(struct command_invocation *cmd,
                        command_print(cmd, "\t%sROMTABLE[0x%x] = 0x%" PRIx32 "",
                                        tabs, entry_offset, romentry);
                        if (romentry & 0x01) {
-                               /* Recurse */
-                               retval = dap_rom_display(cmd, ap, base_addr + (romentry & 0xFFFFF000), depth + 1);
+                               /* Recurse. "romentry" is signed */
+                               retval = dap_rom_display(cmd, ap, base_addr + (int32_t)(romentry & 0xFFFFF000), depth + 1);
                                if (retval != ERROR_OK)
                                        return retval;
                        } else if (romentry != 0) {
@@ -1768,20 +1773,26 @@ COMMAND_HANDLER(dap_baseaddr_command)
        ap = dap_ap(dap, apsel);
        retval = dap_queue_ap_read(ap, MEM_AP_REG_BASE, &baseaddr_lower);
 
-       if (is_64bit_ap(ap) && retval == ERROR_OK)
+       if (retval == ERROR_OK && ap->cfg_reg == MEM_AP_REG_CFG_INVALID)
+               retval = dap_queue_ap_read(ap, MEM_AP_REG_CFG, &ap->cfg_reg);
+
+       if (retval == ERROR_OK && (ap->cfg_reg == MEM_AP_REG_CFG_INVALID || is_64bit_ap(ap))) {
+               /* MEM_AP_REG_BASE64 is defined as 'RES0'; can be read and then ignored on 32 bits AP */
                retval = dap_queue_ap_read(ap, MEM_AP_REG_BASE64, &baseaddr_upper);
+       }
+
+       if (retval == ERROR_OK)
+               retval = dap_run(dap);
        if (retval != ERROR_OK)
                return retval;
-       retval = dap_run(dap);
-       if (retval != ERROR_OK)
-               return retval;
+
        if (is_64bit_ap(ap)) {
                baseaddr = (((target_addr_t)baseaddr_upper) << 32) | baseaddr_lower;
                command_print(CMD, "0x%016" PRIx64, baseaddr);
        } else
                command_print(CMD, "0x%08" PRIx32, baseaddr_lower);
 
-       return retval;
+       return ERROR_OK;
 }
 
 COMMAND_HANDLER(dap_memaccess_command)

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)