Skip to content

Commit

Permalink
[ merge ] Andreas Seltenreich <uwi7@rz.uni-karlsruhe.de> patches
Browse files Browse the repository at this point in the history
  • Loading branch information
texane committed Nov 25, 2012
1 parent 7942914 commit 08872f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
35 changes: 29 additions & 6 deletions gdbserver/gdb-server.c
Expand Up @@ -1076,20 +1076,43 @@ int serve(stlink_t *sl, int port) {
stm32_addr_t start = strtoul(s_start, NULL, 16);
unsigned count = strtoul(s_count, NULL, 16);

for(unsigned int i = 0; i < count; i ++) {
if(start % 4) {
unsigned align_count = 4 - start % 4;
if (align_count > count) align_count = count;
for(unsigned int i = 0; i < align_count; i ++) {
char hex[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
uint8_t byte = strtoul(hex, NULL, 16);
sl->q_buf[i] = byte;
}
stlink_write_mem8(sl, start, align_count);
start += align_count;
count -= align_count;
hexdata += 2*align_count;
}

if((count % 4) == 0 && (start % 4) == 0) {
stlink_write_mem32(sl, start, count);
} else {
stlink_write_mem8(sl, start, count);
if(count - count % 4) {
unsigned aligned_count = count - count % 4;

for(unsigned int i = 0; i < aligned_count; i ++) {
char hex[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
uint8_t byte = strtoul(hex, NULL, 16);
sl->q_buf[i] = byte;
}
stlink_write_mem32(sl, start, aligned_count);
count -= aligned_count;
start += aligned_count;
hexdata += 2*aligned_count;
}

if(count) {
for(unsigned int i = 0; i < count; i ++) {
char hex[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
uint8_t byte = strtoul(hex, NULL, 16);
sl->q_buf[i] = byte;
}
stlink_write_mem8(sl, start, count);
}
reply = strdup("OK");

break;
}

Expand Down
6 changes: 3 additions & 3 deletions src/stlink-common.c
Expand Up @@ -543,7 +543,7 @@ void stlink_write_mem32(stlink_t *sl, uint32_t addr, uint16_t len) {
DLOG("*** stlink_write_mem32 %u bytes to %#x\n", len, addr);
if (len % 4 != 0) {
fprintf(stderr, "Error: Data length doesn't have a 32 bit alignment: +%d byte.\n", len % 4);
return;
abort();
}
sl->backend->write_mem32(sl, addr, len);
}
Expand All @@ -553,7 +553,7 @@ void stlink_read_mem32(stlink_t *sl, uint32_t addr, uint16_t len) {
if (len % 4 != 0) { // !!! never ever: fw gives just wrong values
fprintf(stderr, "Error: Data length doesn't have a 32 bit alignment: +%d byte.\n",
len % 4);
return;
abort();
}
sl->backend->read_mem32(sl, addr, len);
}
Expand All @@ -563,7 +563,7 @@ void stlink_write_mem8(stlink_t *sl, uint32_t addr, uint16_t len) {
if (len > 0x40 ) { // !!! never ever: Writing more then 0x40 bytes gives unexpected behaviour
fprintf(stderr, "Error: Data length > 64: +%d byte.\n",
len);
return;
abort();
}
sl->backend->write_mem8(sl, addr, len);
}
Expand Down

0 comments on commit 08872f8

Please sign in to comment.