Skip to content

Commit bfc5c76

Browse files
committed
armv7a: cache ttbcr and ttb0/1 on debug state entry
Instead of re-reading ttbcr and ttb0/1 whenever a virt2phys translation is done, cache the values once when entering debug state. Use the cached values in armv7a_mmu_translate_va(). Change-Id: I1bc5349ad2f19b2dd75bdd48468a2c1f1e028699 Signed-off-by: Matthias Welwarsky <matthias@welwarsky.de> Reviewed-on: http://openocd.zylin.com/3112 Tested-by: jenkins
1 parent f18ca51 commit bfc5c76

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

src/target/armv7a.c

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ static int armv7a_read_ttbcr(struct target *target)
129129
struct armv7a_common *armv7a = target_to_armv7a(target);
130130
struct arm_dpm *dpm = armv7a->arm.dpm;
131131
uint32_t ttbcr, ttbcr_n;
132-
int retval = dpm->prepare(dpm);
132+
int ttbidx;
133+
int retval;
134+
135+
retval = dpm->prepare(dpm);
133136
if (retval != ERROR_OK)
134137
goto done;
138+
135139
/* MRC p15,0,<Rt>,c2,c0,2 ; Read CP15 Translation Table Base Control Register*/
136140
retval = dpm->instr_read_data_r0(dpm,
137141
ARMV4_5_MRC(15, 0, 0, 2, 0, 2),
@@ -145,6 +149,15 @@ static int armv7a_read_ttbcr(struct target *target)
145149
armv7a->armv7a_mmu.ttbcr = ttbcr;
146150
armv7a->armv7a_mmu.cached = 1;
147151

152+
for (ttbidx = 0; ttbidx < 2; ttbidx++) {
153+
/* MRC p15,0,<Rt>,c2,c0,ttbidx */
154+
retval = dpm->instr_read_data_r0(dpm,
155+
ARMV4_5_MRC(15, 0, 0, 2, 0, ttbidx),
156+
&armv7a->armv7a_mmu.ttbr[ttbidx]);
157+
if (retval != ERROR_OK)
158+
goto done;
159+
}
160+
148161
/*
149162
* ARM Architecture Reference Manual (ARMv7-A and ARMv7-Redition),
150163
* document # ARM DDI 0406C
@@ -182,42 +195,21 @@ int armv7a_mmu_translate_va(struct target *target, uint32_t va, uint32_t *val)
182195
uint32_t second_lvl_descriptor = 0x0;
183196
int retval;
184197
struct armv7a_common *armv7a = target_to_armv7a(target);
185-
struct arm_dpm *dpm = armv7a->arm.dpm;
186198
uint32_t ttbidx = 0; /* default to ttbr0 */
187199
uint32_t ttb_mask;
188200
uint32_t va_mask;
189-
uint32_t ttbcr;
190201
uint32_t ttb;
191202

192-
retval = dpm->prepare(dpm);
193-
if (retval != ERROR_OK)
194-
goto done;
195-
196-
/* MRC p15,0,<Rt>,c2,c0,2 ; Read CP15 Translation Table Base Control Register*/
197-
retval = dpm->instr_read_data_r0(dpm,
198-
ARMV4_5_MRC(15, 0, 0, 2, 0, 2),
199-
&ttbcr);
200-
if (retval != ERROR_OK)
201-
goto done;
202-
203-
/* if ttbcr has changed or was not read before, re-read the information */
204-
if ((armv7a->armv7a_mmu.cached == 0) ||
205-
(armv7a->armv7a_mmu.ttbcr != ttbcr)) {
206-
armv7a_read_ttbcr(target);
207-
}
203+
if (target->state != TARGET_HALTED)
204+
LOG_INFO("target not halted, using cached values for translation table!");
208205

209206
/* if va is above the range handled by ttbr0, select ttbr1 */
210207
if (va > armv7a->armv7a_mmu.ttbr_range[0]) {
211208
/* select ttb 1 */
212209
ttbidx = 1;
213210
}
214-
/* MRC p15,0,<Rt>,c2,c0,ttbidx */
215-
retval = dpm->instr_read_data_r0(dpm,
216-
ARMV4_5_MRC(15, 0, 0, 2, 0, ttbidx),
217-
&ttb);
218-
if (retval != ERROR_OK)
219-
return retval;
220211

212+
ttb = armv7a->armv7a_mmu.ttbr[ttbidx];
221213
ttb_mask = armv7a->armv7a_mmu.ttbr_mask[ttbidx];
222214
va_mask = 0xfff00000 & armv7a->armv7a_mmu.ttbr_range[ttbidx];
223215

@@ -279,9 +271,6 @@ int armv7a_mmu_translate_va(struct target *target, uint32_t va, uint32_t *val)
279271
}
280272

281273
return ERROR_OK;
282-
283-
done:
284-
return retval;
285274
}
286275

287276
/* V7 method VA TO PA */
@@ -740,6 +729,8 @@ int armv7a_arch_state(struct target *target)
740729

741730
arm_arch_state(target);
742731

732+
armv7a_read_ttbcr(target);
733+
743734
if (armv7a->is_armv7r) {
744735
LOG_USER("D-Cache: %s, I-Cache: %s",
745736
state[armv7a->armv7a_mmu.armv7a_cache.d_u_cache_enabled],

src/target/armv7a.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct armv7a_mmu_common {
8787
/* following field mmu working way */
8888
int32_t cached; /* 0: not initialized, 1: initialized */
8989
uint32_t ttbcr; /* cache for ttbcr register */
90+
uint32_t ttbr[2];
9091
uint32_t ttbr_mask[2];
9192
uint32_t ttbr_range[2];
9293

0 commit comments

Comments
 (0)