On Fri, Jul 1, 2011 at 7:32 AM, Øyvind Harboe <[email protected]> wrote:
> You need to translate words to the host endianness if the
> host is to interpret the words.
>
> However, if you are just copying memory, then you can read
> words and write them back, without worrying about endianness.
Yes, that's it. And target_read_memory() just gets to the host data
bytes from the target, but thay are kept on the host in _target_
endianess. That's OK if we just want to temporarily store this data on
the host, like we do for example with breakpoint->orig_instr. But
before any comparison of this data with some macros defined on the
host, we must transform it to the _host_ endianess via
target_buffer_get_u32() function.
In mips_m4k.c code we currently have :
/* check that user program has not modified breakpoint instruction */
if ((retval = target_read_memory(target,
breakpoint->address, 4, 1,
(uint8_t*)¤t_instr)) != ERROR_OK)
{
return retval;
}
if (current_instr == MIPS32_SDBBP)
{
if ((retval = target_write_memory(target,
breakpoint->address, 4, 1,
breakpoint->orig_instr)) !=
ERROR_OK)
{
return retval;
}
}
i.e. we have comparison of current_instr which we obtained from target
via target_read_memory() and is kept in the host in _target_ endianess
with MIPS32_SDBBP macro which is defined on the host and thus kept in
the _host_ endianess.
Now, if target and host have same endianenss, this can pass unnoticed.
But if the endianess between host and the target differ, this check
will never pass, although there is really soft-break instruction in
the target.
Because this check never pass, original instruction is never wrote
back to the target and it keeps hitting breakpoint over and over.
If we take a look at arm7_9_common.c, we can see that it is properly
done this way :
/* check that user program as not modified breakpoint instruction */
if ((retval = target_read_memory(target,
breakpoint->address, 4, 1,
(uint8_t*)¤t_instr)) != ERROR_OK)
{
return retval;
}
current_instr = target_buffer_get_u32(target,
(uint8_t *)¤t_instr);
if (current_instr == arm7_9->arm_bkpt)
if ((retval = target_write_memory(target,
breakpoint->address, 4,
1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
i.e. current_instr is transformed to _host_ endianess prior to
comparison via target_buffer_get_u32() function.
Finally, the patch for MIPS should consist of only adding this missing line.
BR,
Drasko
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development