armv7a: cache ttbcr and ttb0/1 on debug state entry
[openocd.git] / src / target / armv7a.c
index db72afd2128dced727c0789226d038c75b93a0a3..183fde1bf6fcdb1706f022473a8dd7a0ca51bbf2 100644 (file)
@@ -129,9 +129,13 @@ static int armv7a_read_ttbcr(struct target *target)
        struct armv7a_common *armv7a = target_to_armv7a(target);
        struct arm_dpm *dpm = armv7a->arm.dpm;
        uint32_t ttbcr, ttbcr_n;
-       int retval = dpm->prepare(dpm);
+       int ttbidx;
+       int retval;
+
+       retval = dpm->prepare(dpm);
        if (retval != ERROR_OK)
                goto done;
+
        /*  MRC p15,0,<Rt>,c2,c0,2 ; Read CP15 Translation Table Base Control Register*/
        retval = dpm->instr_read_data_r0(dpm,
                        ARMV4_5_MRC(15, 0, 0, 2, 0, 2),
@@ -145,6 +149,15 @@ static int armv7a_read_ttbcr(struct target *target)
        armv7a->armv7a_mmu.ttbcr = ttbcr;
        armv7a->armv7a_mmu.cached = 1;
 
+       for (ttbidx = 0; ttbidx < 2; ttbidx++) {
+               /*  MRC p15,0,<Rt>,c2,c0,ttbidx */
+               retval = dpm->instr_read_data_r0(dpm,
+                               ARMV4_5_MRC(15, 0, 0, 2, 0, ttbidx),
+                               &armv7a->armv7a_mmu.ttbr[ttbidx]);
+               if (retval != ERROR_OK)
+                       goto done;
+       }
+
        /*
         * ARM Architecture Reference Manual (ARMv7-A and ARMv7-Redition),
         * document # ARM DDI 0406C
@@ -182,42 +195,21 @@ int armv7a_mmu_translate_va(struct target *target,  uint32_t va, uint32_t *val)
        uint32_t second_lvl_descriptor = 0x0;
        int retval;
        struct armv7a_common *armv7a = target_to_armv7a(target);
-       struct arm_dpm *dpm = armv7a->arm.dpm;
        uint32_t ttbidx = 0;    /*  default to ttbr0 */
        uint32_t ttb_mask;
        uint32_t va_mask;
-       uint32_t ttbcr;
        uint32_t ttb;
 
-       retval = dpm->prepare(dpm);
-       if (retval != ERROR_OK)
-               goto done;
-
-       /*  MRC p15,0,<Rt>,c2,c0,2 ; Read CP15 Translation Table Base Control Register*/
-       retval = dpm->instr_read_data_r0(dpm,
-                       ARMV4_5_MRC(15, 0, 0, 2, 0, 2),
-                       &ttbcr);
-       if (retval != ERROR_OK)
-               goto done;
-
-       /* if ttbcr has changed or was not read before, re-read the information */
-       if ((armv7a->armv7a_mmu.cached == 0) ||
-               (armv7a->armv7a_mmu.ttbcr != ttbcr)) {
-               armv7a_read_ttbcr(target);
-       }
+       if (target->state != TARGET_HALTED)
+               LOG_INFO("target not halted, using cached values for translation table!");
 
        /* if va is above the range handled by ttbr0, select ttbr1 */
        if (va > armv7a->armv7a_mmu.ttbr_range[0]) {
                /*  select ttb 1 */
                ttbidx = 1;
        }
-       /*  MRC p15,0,<Rt>,c2,c0,ttbidx */
-       retval = dpm->instr_read_data_r0(dpm,
-                       ARMV4_5_MRC(15, 0, 0, 2, 0, ttbidx),
-                       &ttb);
-       if (retval != ERROR_OK)
-               return retval;
 
+       ttb = armv7a->armv7a_mmu.ttbr[ttbidx];
        ttb_mask = armv7a->armv7a_mmu.ttbr_mask[ttbidx];
        va_mask = 0xfff00000 & armv7a->armv7a_mmu.ttbr_range[ttbidx];
 
@@ -279,9 +271,6 @@ int armv7a_mmu_translate_va(struct target *target,  uint32_t va, uint32_t *val)
        }
 
        return ERROR_OK;
-
-done:
-       return retval;
 }
 
 /*  V7 method VA TO PA  */
@@ -740,6 +729,8 @@ int armv7a_arch_state(struct target *target)
 
        arm_arch_state(target);
 
+       armv7a_read_ttbcr(target);
+
        if (armv7a->is_armv7r) {
                LOG_USER("D-Cache: %s, I-Cache: %s",
                        state[armv7a->armv7a_mmu.armv7a_cache.d_u_cache_enabled],

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)