Optimize read a bit.

Remove some unnecessary scans.
This commit is contained in:
Tim Newsome 2016-09-07 11:40:55 -07:00
parent c68b13ed67
commit 526bbc5284
1 changed files with 39 additions and 31 deletions

View File

@ -595,7 +595,9 @@ static int cache_check(struct target *target)
return ERROR_OK; return ERROR_OK;
} }
/** Write cache to the target, and optionally run the program. */ /** Write cache to the target, and optionally run the program.
* Then read the value at address into the cache, assuming address < 128. */
#define CACHE_NO_READ 128
static int cache_write(struct target *target, unsigned int address, bool run) static int cache_write(struct target *target, unsigned int address, bool run)
{ {
LOG_DEBUG("enter"); LOG_DEBUG("enter");
@ -633,17 +635,19 @@ static int cache_write(struct target *target, unsigned int address, bool run)
} }
} }
// Throw away the results of the first read, since it'll contain the result if (run || address < CACHE_NO_READ) {
// of the read that happened just before debugint was set. // Throw away the results of the first read, since it'll contain the
// result of the read that happened just before debugint was set.
add_dbus_scan(target, &field[scan], out + 8*scan, NULL, DBUS_OP_READ, add_dbus_scan(target, &field[scan], out + 8*scan, NULL, DBUS_OP_READ,
address, DMCONTROL_HALTNOT); address, DMCONTROL_HALTNOT);
scan++; scan++;
// This scan contains the results of the read the caller requested, as well // This scan contains the results of the read the caller requested, as
// as an interrupt bit worth looking at. // well as an interrupt bit worth looking at.
add_dbus_scan(target, &field[scan], out + 8*scan, in + 8*scan, DBUS_OP_READ, add_dbus_scan(target, &field[scan], out + 8*scan, in + 8*scan,
address, DMCONTROL_HALTNOT); DBUS_OP_READ, address, DMCONTROL_HALTNOT);
scan++; scan++;
}
int retval = jtag_execute_queue(); int retval = jtag_execute_queue();
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
@ -697,6 +701,7 @@ static int cache_write(struct target *target, unsigned int address, bool run)
} else { } else {
cache_clean(target); cache_clean(target);
if (run || address < CACHE_NO_READ) {
int interrupt = buf_get_u32(in + 8*(scan-1), DBUS_DATA_START + 33, 1); int interrupt = buf_get_u32(in + 8*(scan-1), DBUS_DATA_START + 33, 1);
if (interrupt) { if (interrupt) {
increase_interrupt_high_delay(target); increase_interrupt_high_delay(target);
@ -708,7 +713,8 @@ static int cache_write(struct target *target, unsigned int address, bool run)
} }
} else { } else {
// We read a useful value in that last scan. // We read a useful value in that last scan.
unsigned int read_addr = buf_get_u32(in + 8*(scan-1), DBUS_ADDRESS_START, info->addrbits); unsigned int read_addr = buf_get_u32(in + 8*(scan-1),
DBUS_ADDRESS_START, info->addrbits);
if (read_addr != address) { if (read_addr != address) {
LOG_INFO("Got data from 0x%x but expected it from 0x%x", LOG_INFO("Got data from 0x%x but expected it from 0x%x",
read_addr, address); read_addr, address);
@ -718,6 +724,7 @@ static int cache_write(struct target *target, unsigned int address, bool run)
info->dram_cache[read_addr].valid = true; info->dram_cache[read_addr].valid = true;
} }
} }
}
LOG_DEBUG("exit"); LOG_DEBUG("exit");
@ -747,7 +754,8 @@ uint64_t cache_get(struct target *target, slot_t slot)
/* Write instruction that jumps from the specified word in Debug RAM to resume /* Write instruction that jumps from the specified word in Debug RAM to resume
* in Debug ROM. */ * in Debug ROM. */
static void dram_write_jump(struct target *target, unsigned int index, bool set_interrupt) static void dram_write_jump(struct target *target, unsigned int index,
bool set_interrupt)
{ {
dram_write32(target, index, dram_write32(target, index,
jal(0, (uint32_t) (DEBUG_ROM_RESUME - (DEBUG_RAM_START + 4*index))), jal(0, (uint32_t) (DEBUG_ROM_RESUME - (DEBUG_RAM_START + 4*index))),
@ -1614,7 +1622,7 @@ static int riscv_read_memory(struct target *target, uint32_t address,
return ERROR_FAIL; return ERROR_FAIL;
} }
cache_set_jump(target, 3); cache_set_jump(target, 3);
cache_write(target, 4, false); cache_write(target, CACHE_NO_READ, false);
riscv_info_t *info = (riscv_info_t *) target->arch_info; riscv_info_t *info = (riscv_info_t *) target->arch_info;
const int max_batch_size = 256; const int max_batch_size = 256;