@@ -114,7 +114,7 @@ static void esp32_mark_register_dirty(struct reg *reg_list, int regidx)
114
114
reg_list [regidx ].dirty = 1 ;
115
115
}
116
116
117
- static int esp32_fetch_all_regs (struct target * target )
117
+ static int esp32_fetch_all_regs (struct target * target , uint8_t cpu_mask )
118
118
{
119
119
int i , j ;
120
120
int cpenable ;
@@ -139,6 +139,9 @@ static int esp32_fetch_all_regs(struct target *target)
139
139
// Read registers from both cores
140
140
for (size_t c = 0 ; c < ESP32_CPU_COUNT ; c ++ )
141
141
{
142
+ if ((cpu_mask & (1 << c )) == 0 ) {
143
+ continue ;
144
+ }
142
145
//Start out with A0-A63; we can reach those immediately. Grab them per 16 registers.
143
146
for (j = 0 ; j < 64 ; j += 16 ) {
144
147
//Grab the 16 registers we can see
@@ -160,7 +163,10 @@ static int esp32_fetch_all_regs(struct target *target)
160
163
161
164
162
165
res = jtag_execute_queue ();
163
- if (res != ERROR_OK ) return res ;
166
+ if (res != ERROR_OK ) {
167
+ LOG_ERROR ("Failed to read ARs (%d)!\n" , res );
168
+ return res ;
169
+ }
164
170
165
171
esp32_checkdsr (esp32 -> esp32_targets [c ]);
166
172
cpenable = intfromchars (regvals [c ][XT_REG_IDX_CPENABLE ]);
@@ -169,7 +175,7 @@ static int esp32_fetch_all_regs(struct target *target)
169
175
//We're now free to use any of A0-A15 as scratch registers
170
176
//Grab the SFRs and user registers first. We use A3 as a scratch register.
171
177
for (i = 0 ; i < XT_NUM_REGS ; i ++ ) {
172
- if (regReadable (esp32_regs [i ].flags , cpenable ) && (esp32_regs [i ].type == XT_REG_SPECIAL || esp32_regs [i ].type == XT_REG_USER )) {
178
+ if (regReadable (esp32_regs [i ].flags , cpenable ) && (esp32_regs [i ].type == XT_REG_SPECIAL || esp32_regs [i ].type == XT_REG_USER || esp32_regs [ i ]. type == XT_REG_FR )) {
173
179
if (esp32_regs [i ].type == XT_REG_USER ) {
174
180
esp108_queue_exec_ins (esp32 -> esp32_targets [c ], XT_INS_RUR (esp32_regs [i ].reg_num , XT_REG_A3 ));
175
181
}
@@ -187,12 +193,15 @@ static int esp32_fetch_all_regs(struct target *target)
187
193
188
194
//Ok, send the whole mess to the CPU.
189
195
res = jtag_execute_queue ();
190
- if (res != ERROR_OK ) return res ;
196
+ if (res != ERROR_OK ) {
197
+ LOG_ERROR ("Failed to fetch AR regs!\n" );
198
+ return res ;
199
+ }
191
200
192
201
esp32_checkdsr (esp32 -> esp32_targets [c ]);
193
202
//DSR checking: follows order in which registers are requested.
194
203
for (i = 0 ; i < XT_NUM_REGS ; i ++ ) {
195
- if (regReadable (esp32_regs [i ].flags , cpenable ) && (esp32_regs [i ].type == XT_REG_SPECIAL || esp32_regs [i ].type == XT_REG_USER )) {
204
+ if (regReadable (esp32_regs [i ].flags , cpenable ) && (esp32_regs [i ].type == XT_REG_SPECIAL || esp32_regs [i ].type == XT_REG_USER || esp32_regs [ i ]. type == XT_REG_FR )) {
196
205
if (intfromchars (dsrs [c ][i ])& OCDDSR_EXECEXCEPTION ) {
197
206
LOG_ERROR ("Exception reading %s!\n" , esp32_regs [i ].name );
198
207
return ERROR_FAIL ;
@@ -233,7 +242,6 @@ static int esp32_fetch_all_regs(struct target *target)
233
242
struct reg * cpu_reg_list = esp32 -> core_caches [c ]-> reg_list ;
234
243
esp32_mark_register_dirty (cpu_reg_list , XT_REG_IDX_A3 );
235
244
}
236
- esp32_checkdsr (esp32 -> esp32_targets [0 ]);
237
245
return ERROR_OK ;
238
246
}
239
247
@@ -306,7 +314,7 @@ static int esp32_write_dirty_registers(struct target *target, struct reg *reg_li
306
314
regval = esp108_reg_get (& reg_list [realadr ]);
307
315
LOG_DEBUG ("%s: Writing back reg %s value %08X, num =%i" , target -> cmd_name , esp32_regs [realadr ].name , regval , esp32_regs [realadr ].reg_num );
308
316
esp108_queue_nexus_reg_write (target , NARADR_DDR , regval );
309
- esp108_queue_exec_ins (target , XT_INS_RSR (XT_SR_DDR , esp32_regs [XT_REG_IDX_AR0 + i + j ].reg_num ));
317
+ esp108_queue_exec_ins (target , XT_INS_RSR (XT_SR_DDR , esp32_regs [XT_REG_IDX_AR0 + i ].reg_num ));
310
318
reg_list [realadr ].dirty = 0 ;
311
319
}
312
320
}
@@ -962,7 +970,6 @@ static int xtensa_step(struct target *target,
962
970
static const uint32_t icount_val = -2 ; /* ICOUNT value to load for 1 step */
963
971
uint32_t icountlvl ;
964
972
uint32_t oldps , newps , oldpc ;
965
- int tries = 10 ;
966
973
967
974
LOG_DEBUG ("%s: %s(current=%d, address=0x%04x, handle_breakpoints=%i)" , target -> cmd_name , __func__ , current , address , handle_breakpoints );
968
975
@@ -1011,7 +1018,6 @@ static int xtensa_step(struct target *target,
1011
1018
1012
1019
1013
1020
do {
1014
- // We have equival amount of BP for each cpu
1015
1021
{
1016
1022
struct reg * cpu_reg_list = esp32 -> core_caches [esp32 -> active_cpu ]-> reg_list ;
1017
1023
esp108_reg_set (& cpu_reg_list [XT_REG_IDX_ICOUNTLEVEL ], icountlvl );
@@ -1047,22 +1053,23 @@ static int xtensa_step(struct target *target,
1047
1053
if (!(intfromchars (dsr )& OCDDSR_STOPPED )) {
1048
1054
LOG_ERROR ("%s: %s: Timed out waiting for target to finish stepping. dsr=0x%08x" , target -> cmd_name , __func__ , intfromchars (dsr ));
1049
1055
return ERROR_TARGET_TIMEOUT ;
1050
- } else
1051
- {
1052
- target -> state = TARGET_HALTED ;
1053
- esp32_fetch_all_regs (target );
1054
1056
}
1055
- } while ( esp108_reg_get ( & reg_list [ XT_REG_IDX_PC ]) == oldpc && -- tries );
1056
- LOG_DEBUG ( "Stepped from %X to %X" , oldpc , esp108_reg_get ( & reg_list [ XT_REG_IDX_PC ]) );
1057
+ esp32_fetch_all_regs ( target , 1 << esp32 -> active_cpu );
1058
+ } while ( 0 );
1057
1059
1058
- if (!tries ) {
1060
+ uint32_t cur_pc = esp108_reg_get (& reg_list [XT_REG_IDX_PC ]);
1061
+ if (oldpc == cur_pc ) {
1059
1062
LOG_WARNING ("%s: %s: Stepping doesn't seem to change PC! dsr=0x%08x" , target -> cmd_name , __func__ , intfromchars (dsr ));
1060
1063
}
1061
-
1064
+ else {
1065
+ LOG_DEBUG ("Stepped from %X to %X" , oldpc , cur_pc );
1066
+ }
1062
1067
// This operation required to clear state
1063
1068
for (size_t cp = 0 ; cp < ESP32_CPU_COUNT ; cp ++ )
1064
1069
{
1065
- if (cp != esp32 -> active_cpu ) xtensa_read_dsr (esp32 -> esp32_targets [cp ]);
1070
+ if (cp != esp32 -> active_cpu ) {
1071
+ xtensa_read_dsr (esp32 -> esp32_targets [cp ]);
1072
+ }
1066
1073
}
1067
1074
1068
1075
if (cause & DEBUGCAUSE_DB ) {
@@ -1359,7 +1366,7 @@ static int xtensa_poll(struct target *target)
1359
1366
}
1360
1367
1361
1368
unsigned int dsr0 = intfromchars (dsr [0 ]);
1362
- unsigned int dsr1 = intfromchars (dsr [0 ]);
1369
+ unsigned int dsr1 = intfromchars (dsr [1 ]);
1363
1370
unsigned int common_reason = dsr0 | dsr1 ; // We should know if even one of CPU was stopped
1364
1371
1365
1372
unsigned int common_pwrstath = pwrstath [0 ] | pwrstath [1 ];
@@ -1369,7 +1376,7 @@ static int xtensa_poll(struct target *target)
1369
1376
LOG_DEBUG ("Stopped: CPU0: %d CPU1: %d" , (dsr0 & OCDDSR_STOPPED ) ? 1 : 0 , (dsr1 & OCDDSR_STOPPED ) ? 1 : 0 );
1370
1377
xtensa_halt (target );
1371
1378
target -> state = TARGET_HALTED ;
1372
- esp32_fetch_all_regs (target );
1379
+ esp32_fetch_all_regs (target , 0x3 );
1373
1380
//Examine why the target was halted
1374
1381
target -> debug_reason = DBG_REASON_DBGRQ ;
1375
1382
for (size_t i = 0 ; i < ESP32_CPU_COUNT ; i ++ )
0 commit comments