hosted/firmware/jtag: Fix unhandled exception introduced with da15cc3cb7.

Write in endianess independant way.
This commit is contained in:
Uwe Bonnes 2022-01-22 14:46:47 +01:00 committed by Piotr Esden-Tempski
parent d594b42976
commit b1ed55a18f
2 changed files with 12 additions and 15 deletions

View File

@ -1,7 +1,7 @@
/*
* This file is part of the Black Magic Debug project.
*
* Copyright(C) 2020 - 2021 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de)
* Copyright(C) 2020 - 2022 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -126,26 +126,21 @@ static void jtagtap_tdi_tdo_seq(
chunk = 64;
}
ticks -= chunk;
uint8_t di[8];
memset(di, 0, 8);
uint64_t di = 0;
int bytes = (chunk + 7) >> 3;
int i = 0;
if (DI) {
memcpy(&di, DI, bytes);
int remainder = chunk & 7;
DI += bytes;
DI += bytes;
if (remainder) {
uint8_t rem = *DI;
rem &= (1 << remainder) - 1;
*di = rem;
for (; i < bytes; i++) {
di |= *DI << (i * 8);
DI++;
}
};
}
/* PRIx64 differs with system. Use it explicit in the format string*/
s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,
"!J%c%02x%" PRIx64 "%c",
(!ticks && final_tms) ?
REMOTE_TDITDO_TMS : REMOTE_TDITDO_NOTMS,
chunk, *(uint64_t*)di, REMOTE_EOM);
chunk, di, REMOTE_EOM);
platform_buffer_write(construct,s);
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
@ -156,8 +151,10 @@ static void jtagtap_tdi_tdo_seq(
}
if (DO) {
uint64_t res = remotehston(-1, (char *)&construct[1]);
memcpy(DO, &res, bytes);
DO += bytes;
for (i = bytes; i > 0; i--) {
*DO++ = res & 0xff;
res >>= 8;
}
}
}
}