armv7a: fix interpretation of MMU table
[openocd.git] / src / target / armv7a.c
index 57b8799f0c8f301e7b0cc3ecadd16aa89379b7b0..170cfcc28db2dbee92f7361b6efb0135486a8908 100644 (file)
@@ -232,27 +232,26 @@ int armv7a_mmu_translate_va(struct target *target,  uint32_t va, uint32_t *val)
        }
 
 
-       if ((first_lvl_descriptor & 0x3) == 2) {
+       if ((first_lvl_descriptor & 0x40002) == 2) {
                /* section descriptor */
                *val = (first_lvl_descriptor & 0xfff00000) | (va & 0x000fffff);
                return ERROR_OK;
+       } else if ((first_lvl_descriptor & 0x40002) == 0x40002) {
+               /* supersection descriptor */
+               if (first_lvl_descriptor & 0x00f001e0) {
+                       LOG_ERROR("Physical address does not fit into 32 bits");
+                       return ERROR_TARGET_TRANSLATION_FAULT;
+               }
+               *val = (first_lvl_descriptor & 0xff000000) | (va & 0x00ffffff);
+               return ERROR_OK;
        }
 
-       if ((first_lvl_descriptor & 0x3) == 1) {
-               /* coarse page table */
-               retval = armv7a->armv7a_mmu.read_physical_memory(target,
-                               (first_lvl_descriptor & 0xfffffc00) | ((va & 0x000ff000) >> 10),
-                               4, 1, (uint8_t *)&second_lvl_descriptor);
-               if (retval != ERROR_OK)
-                       return retval;
-       } else if ((first_lvl_descriptor & 0x3) == 3)   {
-               /* fine page table */
-               retval = armv7a->armv7a_mmu.read_physical_memory(target,
-                               (first_lvl_descriptor & 0xfffff000) | ((va & 0x000ffc00) >> 8),
-                               4, 1, (uint8_t *)&second_lvl_descriptor);
-               if (retval != ERROR_OK)
-                       return retval;
-       }
+       /* page table */
+       retval = armv7a->armv7a_mmu.read_physical_memory(target,
+                       (first_lvl_descriptor & 0xfffffc00) | ((va & 0x000ff000) >> 10),
+                       4, 1, (uint8_t *)&second_lvl_descriptor);
+       if (retval != ERROR_OK)
+               return retval;
 
        second_lvl_descriptor = target_buffer_get_u32(target, (uint8_t *)
                        &second_lvl_descriptor);
@@ -267,23 +266,12 @@ int armv7a_mmu_translate_va(struct target *target,  uint32_t va, uint32_t *val)
        if ((second_lvl_descriptor & 0x3) == 1) {
                /* large page descriptor */
                *val = (second_lvl_descriptor & 0xffff0000) | (va & 0x0000ffff);
-               return ERROR_OK;
-       }
-
-       if ((second_lvl_descriptor & 0x3) == 2) {
+       } else {
                /* small page descriptor */
                *val = (second_lvl_descriptor & 0xfffff000) | (va & 0x00000fff);
-               return ERROR_OK;
        }
 
-       if ((second_lvl_descriptor & 0x3) == 3) {
-               *val = (second_lvl_descriptor & 0xfffffc00) | (va & 0x000003ff);
-               return ERROR_OK;
-       }
-
-       /* should not happen */
-       LOG_ERROR("Address translation failure");
-       return ERROR_TARGET_TRANSLATION_FAULT;
+       return ERROR_OK;
 
 done:
        return retval;
@@ -564,21 +552,17 @@ COMMAND_HANDLER(handle_cache_l2x)
 {
        struct target *target = get_current_target(CMD_CTX);
        uint32_t base, way;
-       switch (CMD_ARGC) {
-               case 0:
-                       return ERROR_COMMAND_SYNTAX_ERROR;
-                       break;
-               case 2:
-                       /* command_print(CMD_CTX, "%s %s", CMD_ARGV[0], CMD_ARGV[1]); */
-                       COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], base);
-                       COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], way);
-
-                       /* AP address is in bits 31:24 of DP_SELECT */
-                       armv7a_l2x_cache_init(target, base, way);
-                       break;
-               default:
-                       return ERROR_COMMAND_SYNTAX_ERROR;
-       }
+
+       if (CMD_ARGC != 2)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       /* command_print(CMD_CTX, "%s %s", CMD_ARGV[0], CMD_ARGV[1]); */
+       COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], base);
+       COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], way);
+
+       /* AP address is in bits 31:24 of DP_SELECT */
+       armv7a_l2x_cache_init(target, base, way);
+
        return ERROR_OK;
 }
 

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)