diff options
| author | Evgeniy Naydanov <109669442+en-sc@users.noreply.github.com> | 2025-10-09 13:08:18 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-09 13:08:18 +0300 |
| commit | eb01c632a4bb1c07d2bddb008d6987c809f1c496 (patch) | |
| tree | 4097c926ae8d24b7ae9cb909901a36f0c1ccca8e | |
| parent | 608ba433d7701c87fc7372888fa03fc9217637e4 (diff) | |
| parent | 9d4c94e51fdaba3290a16825e48f393b9650a321 (diff) | |
| download | riscv-openocd-riscv.zip riscv-openocd-riscv.tar.gz riscv-openocd-riscv.tar.bz2 | |
Fix bug in scratch_reserve
| -rw-r--r-- | src/target/riscv/riscv-013.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 4fd041f..f2fb22f 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1203,12 +1203,13 @@ static int scratch_reserve(struct target *target, if (info->dataaccess == 1) { /* Sign extend dataaddr. */ scratch->hart_address = info->dataaddr; - if (info->dataaddr & (1<<11)) - scratch->hart_address |= 0xfffffffffffff000ULL; + if (info->dataaddr & BIT(DM_HARTINFO_DATAADDR_LENGTH - 1)) + scratch->hart_address |= + GENMASK_ULL(riscv_xlen(target) - 1, DM_HARTINFO_DATAADDR_LENGTH); /* Align. */ - scratch->hart_address = (scratch->hart_address + alignment - 1) & ~(alignment - 1); + scratch->hart_address = ALIGN_UP(scratch->hart_address, alignment); - if ((size_bytes + scratch->hart_address - info->dataaddr + 3) / 4 >= + if (DIV_ROUND_UP(size_bytes + scratch->hart_address - info->dataaddr, 4) <= info->datasize) { scratch->memory_space = SPACE_DM_DATA; scratch->debug_address = (scratch->hart_address - info->dataaddr) / 4; @@ -1222,10 +1223,9 @@ static int scratch_reserve(struct target *target, /* Allow for ebreak at the end of the program. */ unsigned int program_size = (program->instruction_count + 1) * 4; - scratch->hart_address = (info->progbuf_address + program_size + alignment - 1) & - ~(alignment - 1); + scratch->hart_address = ALIGN_UP(info->progbuf_address + program_size, alignment); if ((info->progbuf_writable == YNM_YES) && - ((size_bytes + scratch->hart_address - info->progbuf_address + 3) / 4 >= + (DIV_ROUND_UP(size_bytes + scratch->hart_address - info->progbuf_address, 4) <= info->progbufsize)) { scratch->memory_space = SPACE_DMI_PROGBUF; scratch->debug_address = (scratch->hart_address - info->progbuf_address) / 4; @@ -1235,8 +1235,7 @@ static int scratch_reserve(struct target *target, /* Option 3: User-configured memory area as scratch RAM */ if (target_alloc_working_area(target, size_bytes + alignment - 1, &scratch->area) == ERROR_OK) { - scratch->hart_address = (scratch->area->address + alignment - 1) & - ~(alignment - 1); + scratch->hart_address = ALIGN_UP(scratch->area->address, alignment); scratch->memory_space = SPACE_DMI_RAM; scratch->debug_address = scratch->hart_address; return ERROR_OK; |
