Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mem write odd #730

Merged
merged 9 commits into from
Aug 1, 2018
15 changes: 14 additions & 1 deletion src/gdbserver/semihosting.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ static int mem_read(stlink_t *sl, uint32_t addr, void *data, uint16_t len)

static int mem_write(stlink_t *sl, uint32_t addr, void *data, uint16_t len)
{
// Note: this function can write more than it is asked to!
// If addr is not an even 32 bit boundary, or len is not a multiple of 4.
//
// If only 32 bit values can be written to the target,
// then this function should read the target memory at the
// start and end of the buffer where it will write more that
// the requested bytes. (perhaps reading the whole area is faster??).
//
// If 16 and 8 bit writes are available, then they could be used instead.

// Just return when the length is zero avoiding unneeded work.
if (len == 0) return 0;

int offset = addr % 4;
int write_len = len + offset;

Expand Down Expand Up @@ -341,7 +354,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
read_result = read(fd, buffer, buffer_len);
saved_errno = errno;

if (read_result == (uint32_t)-1) {
if (read_result == -1) {
*ret = buffer_len;
} else {
if (mem_write(sl, buffer_address, buffer, read_result) != 0 ) {
Expand Down