[Pdbg] [PATCH 13/14] gdbserver: use read-modify-write for put_mem that is not 8-byte aligned
Nicholas Piggin
npiggin at gmail.com
Tue Mar 29 20:05:31 AEDT 2022
Excerpts from Joel Stanley's message of March 16, 2022 9:46 am:
> On Mon, 14 Mar 2022 at 04:18, Nicholas Piggin <npiggin at gmail.com> wrote:
>>
>> Not all targets have memory access that can support arbitrary byte
>> writes. Use RMW for put_mem commands that are not 8-byte aligned.
>
> Do we know which targets can/can't support unaligned byte writes?
sbefifo chip ops at least can only do 8 byte aligned / sized writes.
>> @@ -318,17 +318,27 @@ static void put_mem(uint64_t *stack, void *priv)
>> err = 2;
>> goto out;
>> }
>> - } else {
>> - stack[2] = __builtin_bswap64(stack[2]) >> 32;
>> }
>>
>> - PR_INFO("put_mem 0x%016" PRIx64 " = 0x%016" PRIx64 "\n", addr, stack[2]);
>> + if (len == 4 && littleendian) {
>> + insn = (uint32_t *)data;
>> + *insn = bswap_32(*insn);
>> + }
>>
>> - if (mem_write(adu_target, addr, data, len, 0, false)) {
>> + start_addr = addr & ~(align - 1);
>> + end_addr = (addr + len + (align - 1)) & ~(align - 1);
>
> Would some ALIGN_UP / ALIGN_DOWN macros make sense here?
Yeah that could improve things.
>
>> + if (addr != start_addr || (addr + len) != end_addr) {
>> + buf = malloc(end_addr - start_addr);
>> + mem_read(adu_target, start_addr, buf, end_addr - start_addr, 0, false);
>> + memcpy(buf + (addr - start_addr), data, len);
>> + } else {
>> + buf = data;
>> + }
>> +
>> + if (mem_write(adu_target, start_addr, buf, end_addr - start_addr, 0, false)) {
>> PR_ERROR("Unable to write memory\n");
>> err = 3;
>> }
>
> Needs to free buf if it was malloc'd.
Good catch.
Thanks,
Nick
More information about the Pdbg
mailing list