Fix: Take into account progbuf writability. (#424)

When allocating scratch memory within RISC-V target
(scratch_reserve()), take into account whether progbuf
is writable or not, as determined by examine_progbuf().
busy
Jan Matyas 2019-11-20 21:00:00 +01:00 committed by Tim Newsome
parent e944de422e
commit 739d16d503
1 changed files with 6 additions and 2 deletions

View File

@ -1073,6 +1073,7 @@ static int scratch_reserve(struct target *target,
riscv013_info_t *info = get_info(target); riscv013_info_t *info = get_info(target);
/* Option 1: See if data# registers can be used as the scratch memory */
if (info->dataaccess == 1) { if (info->dataaccess == 1) {
/* Sign extend dataaddr. */ /* Sign extend dataaddr. */
scratch->hart_address = info->dataaddr; scratch->hart_address = info->dataaddr;
@ -1089,6 +1090,7 @@ static int scratch_reserve(struct target *target,
} }
} }
/* Option 2: See if progbuf can be used as the scratch memory */
if (examine_progbuf(target) != ERROR_OK) if (examine_progbuf(target) != ERROR_OK)
return ERROR_FAIL; return ERROR_FAIL;
@ -1096,13 +1098,15 @@ static int scratch_reserve(struct target *target,
unsigned program_size = (program->instruction_count + 1) * 4; unsigned program_size = (program->instruction_count + 1) * 4;
scratch->hart_address = (info->progbuf_address + program_size + alignment - 1) & scratch->hart_address = (info->progbuf_address + program_size + alignment - 1) &
~(alignment - 1); ~(alignment - 1);
if ((size_bytes + scratch->hart_address - info->progbuf_address + 3) / 4 >= if ((info->progbuf_writable == YNM_YES) &&
info->progbufsize) { ((size_bytes + scratch->hart_address - info->progbuf_address + 3) / 4 >=
info->progbufsize)) {
scratch->memory_space = SPACE_DMI_PROGBUF; scratch->memory_space = SPACE_DMI_PROGBUF;
scratch->debug_address = (scratch->hart_address - info->progbuf_address) / 4; scratch->debug_address = (scratch->hart_address - info->progbuf_address) / 4;
return ERROR_OK; return ERROR_OK;
} }
/* Option 3: User-configured memory area as scratch RAM */
if (target_alloc_working_area(target, size_bytes + alignment - 1, if (target_alloc_working_area(target, size_bytes + alignment - 1,
&scratch->area) == ERROR_OK) { &scratch->area) == ERROR_OK) {
scratch->hart_address = (scratch->area->address + alignment - 1) & scratch->hart_address = (scratch->area->address + alignment - 1) &