1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
25 #include "armv4_5_mmu.h"
28 uint32_t armv4mmu_translate_va(target_t
*target
, armv4_5_mmu_common_t
*armv4_5_mmu
, uint32_t va
, int *type
, uint32_t *cb
, int *domain
, uint32_t *ap
);
30 char* armv4_5_mmu_page_type_names
[] =
32 "section", "large page", "small page", "tiny page"
35 uint32_t armv4_5_mmu_translate_va(target_t
*target
, armv4_5_mmu_common_t
*armv4_5_mmu
, uint32_t va
, int *type
, uint32_t *cb
, int *domain
, uint32_t *ap
)
37 uint32_t first_lvl_descriptor
= 0x0;
38 uint32_t second_lvl_descriptor
= 0x0;
39 uint32_t ttb
= armv4_5_mmu
->get_ttb(target
);
41 armv4_5_mmu_read_physical(target
, armv4_5_mmu
,
42 (ttb
& 0xffffc000) | ((va
& 0xfff00000) >> 18),
43 4, 1, (uint8_t*)&first_lvl_descriptor
);
44 first_lvl_descriptor
= target_buffer_get_u32(target
, (uint8_t*)&first_lvl_descriptor
);
46 LOG_DEBUG("1st lvl desc: %8.8" PRIx32
"", first_lvl_descriptor
);
48 if ((first_lvl_descriptor
& 0x3) == 0)
51 LOG_ERROR("Address translation failure");
52 return ERROR_TARGET_TRANSLATION_FAULT
;
55 if (!armv4_5_mmu
->has_tiny_pages
&& ((first_lvl_descriptor
& 0x3) == 3))
58 LOG_ERROR("Address translation failure");
59 return ERROR_TARGET_TRANSLATION_FAULT
;
62 /* domain is always specified in bits 8-5 */
63 *domain
= (first_lvl_descriptor
& 0x1e0) >> 5;
65 if ((first_lvl_descriptor
& 0x3) == 2)
67 /* section descriptor */
68 *type
= ARMV4_5_SECTION
;
69 *cb
= (first_lvl_descriptor
& 0xc) >> 2;
70 *ap
= (first_lvl_descriptor
& 0xc00) >> 10;
71 return (first_lvl_descriptor
& 0xfff00000) | (va
& 0x000fffff);
74 if ((first_lvl_descriptor
& 0x3) == 1)
76 /* coarse page table */
77 armv4_5_mmu_read_physical(target
, armv4_5_mmu
,
78 (first_lvl_descriptor
& 0xfffffc00) | ((va
& 0x000ff000) >> 10),
79 4, 1, (uint8_t*)&second_lvl_descriptor
);
81 else if ((first_lvl_descriptor
& 0x3) == 3)
84 armv4_5_mmu_read_physical(target
, armv4_5_mmu
,
85 (first_lvl_descriptor
& 0xfffff000) | ((va
& 0x000ffc00) >> 8),
86 4, 1, (uint8_t*)&second_lvl_descriptor
);
89 second_lvl_descriptor
= target_buffer_get_u32(target
, (uint8_t*)&second_lvl_descriptor
);
91 LOG_DEBUG("2nd lvl desc: %8.8" PRIx32
"", second_lvl_descriptor
);
93 if ((second_lvl_descriptor
& 0x3) == 0)
96 LOG_ERROR("Address translation failure");
97 return ERROR_TARGET_TRANSLATION_FAULT
;
100 /* cacheable/bufferable is always specified in bits 3-2 */
101 *cb
= (second_lvl_descriptor
& 0xc) >> 2;
103 if ((second_lvl_descriptor
& 0x3) == 1)
105 /* large page descriptor */
106 *type
= ARMV4_5_LARGE_PAGE
;
107 *ap
= (second_lvl_descriptor
& 0xff0) >> 4;
108 return (second_lvl_descriptor
& 0xffff0000) | (va
& 0x0000ffff);
111 if ((second_lvl_descriptor
& 0x3) == 2)
113 /* small page descriptor */
114 *type
= ARMV4_5_SMALL_PAGE
;
115 *ap
= (second_lvl_descriptor
& 0xff0) >> 4;
116 return (second_lvl_descriptor
& 0xfffff000) | (va
& 0x00000fff);
119 if ((second_lvl_descriptor
& 0x3) == 3)
121 /* tiny page descriptor */
122 *type
= ARMV4_5_TINY_PAGE
;
123 *ap
= (second_lvl_descriptor
& 0x30) >> 4;
124 return (second_lvl_descriptor
& 0xfffffc00) | (va
& 0x000003ff);
127 /* should not happen */
129 LOG_ERROR("Address translation failure");
130 return ERROR_TARGET_TRANSLATION_FAULT
;
133 int armv4_5_mmu_read_physical(target_t
*target
, armv4_5_mmu_common_t
*armv4_5_mmu
, uint32_t address
, uint32_t size
, uint32_t count
, uint8_t *buffer
)
137 if (target
->state
!= TARGET_HALTED
)
138 return ERROR_TARGET_NOT_HALTED
;
140 /* disable MMU and data (or unified) cache */
141 armv4_5_mmu
->disable_mmu_caches(target
, 1, 1, 0);
143 retval
= armv4_5_mmu
->read_memory(target
, address
, size
, count
, buffer
);
145 /* reenable MMU / cache */
146 armv4_5_mmu
->enable_mmu_caches(target
, armv4_5_mmu
->mmu_enabled
,
147 armv4_5_mmu
->armv4_5_cache
.d_u_cache_enabled
,
148 armv4_5_mmu
->armv4_5_cache
.i_cache_enabled
);
153 int armv4_5_mmu_write_physical(target_t
*target
, armv4_5_mmu_common_t
*armv4_5_mmu
, uint32_t address
, uint32_t size
, uint32_t count
, uint8_t *buffer
)
157 if (target
->state
!= TARGET_HALTED
)
158 return ERROR_TARGET_NOT_HALTED
;
160 /* disable MMU and data (or unified) cache */
161 armv4_5_mmu
->disable_mmu_caches(target
, 1, 1, 0);
163 retval
= armv4_5_mmu
->write_memory(target
, address
, size
, count
, buffer
);
165 /* reenable MMU / cache */
166 armv4_5_mmu
->enable_mmu_caches(target
, armv4_5_mmu
->mmu_enabled
,
167 armv4_5_mmu
->armv4_5_cache
.d_u_cache_enabled
,
168 armv4_5_mmu
->armv4_5_cache
.i_cache_enabled
);
173 int armv4_5_mmu_handle_md_phys_command(command_context_t
*cmd_ctx
, char *cmd
, char **args
, int argc
, target_t
*target
, armv4_5_mmu_common_t
*armv4_5_mmu
)
177 uint32_t address
= 0;
187 if (target
->state
!= TARGET_HALTED
)
189 command_print(cmd_ctx
, "target must be stopped for \"%s\" command", cmd
);
197 count
= strtoul(args
[1], NULL
, 0);
199 address
= strtoul(args
[0], NULL
, 0);
216 buffer
= calloc(count
, size
);
217 if ((retval
= armv4_5_mmu_read_physical(target
, armv4_5_mmu
, address
, size
, count
, buffer
)) != ERROR_OK
)
221 case ERROR_TARGET_UNALIGNED_ACCESS
:
222 command_print(cmd_ctx
, "error: address not aligned");
224 case ERROR_TARGET_NOT_HALTED
:
225 command_print(cmd_ctx
, "error: target must be halted for memory accesses");
227 case ERROR_TARGET_DATA_ABORT
:
228 command_print(cmd_ctx
, "error: access caused data abort, system possibly corrupted");
231 command_print(cmd_ctx
, "error: unknown error");
237 for (i
= 0; i
< count
; i
++)
240 output_len
+= snprintf(output
+ output_len
, 128 - output_len
, "0x%8.8" PRIx32
": ", address
+ (i
*size
));
245 output_len
+= snprintf(output
+ output_len
, 128 - output_len
, "%8.8" PRIx32
" ", target_buffer_get_u32(target
, &buffer
[i
*4]));
248 output_len
+= snprintf(output
+ output_len
, 128 - output_len
, "%4.4x ", target_buffer_get_u16(target
, &buffer
[i
*2]));
251 output_len
+= snprintf(output
+ output_len
, 128 - output_len
, "%2.2x ", buffer
[i
*1]);
255 if ((i
% 8 == 7) || (i
== count
- 1))
257 command_print(cmd_ctx
, "%s", output
);
267 int armv4_5_mmu_handle_mw_phys_command(command_context_t
*cmd_ctx
, char *cmd
, char **args
, int argc
, target_t
*target
, armv4_5_mmu_common_t
*armv4_5_mmu
)
269 uint32_t address
= 0;
272 uint8_t value_buf
[4];
274 if (target
->state
!= TARGET_HALTED
)
276 command_print(cmd_ctx
, "target must be stopped for \"%s\" command", cmd
);
283 address
= strtoul(args
[0], NULL
, 0);
284 value
= strtoul(args
[1], NULL
, 0);
289 target_buffer_set_u32(target
, value_buf
, value
);
290 retval
= armv4_5_mmu_write_physical(target
, armv4_5_mmu
, address
, 4, 1, value_buf
);
293 target_buffer_set_u16(target
, value_buf
, value
);
294 retval
= armv4_5_mmu_write_physical(target
, armv4_5_mmu
, address
, 2, 1, value_buf
);
297 value_buf
[0] = value
;
298 retval
= armv4_5_mmu_write_physical(target
, armv4_5_mmu
, address
, 1, 1, value_buf
);
306 case ERROR_TARGET_UNALIGNED_ACCESS
:
307 command_print(cmd_ctx
, "error: address not aligned");
309 case ERROR_TARGET_DATA_ABORT
:
310 command_print(cmd_ctx
, "error: access caused data abort, system possibly corrupted");
312 case ERROR_TARGET_NOT_HALTED
:
313 command_print(cmd_ctx
, "error: target must be halted for memory accesses");
318 command_print(cmd_ctx
, "error: unknown error");
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)