/* convert the hex array pointed to by buf into binary to be placed in mem * return a pointer to the character AFTER the last byte fetched from buf. */ static char * hex2mem(char *buf, char *mem, int count) { int hexValue; char *tmp_raw, *tmp_hex; /* * We use the upper half of buf as an intermediate buffer for the * raw memory that is converted from hex. */ tmp_raw = buf + count * 2; tmp_hex = tmp_raw - 1; longjmp_on_fault = 1; while (tmp_hex >= buf) { tmp_raw--; hexValue = hex(*tmp_hex--); if (hexValue < 0) kgdb_error(KGDBERR_NOTHEXDIG); *tmp_raw = hexValue; hexValue = hex(*tmp_hex--); if (hexValue < 0) kgdb_error(KGDBERR_NOTHEXDIG); *tmp_raw |= hexValue << 4; } memcpy(mem, tmp_raw, count); kgdb_flush_cache_range((void *)mem, (void *)(mem+count)); longjmp_on_fault = 0; return buf; }
/* convert the hex array pointed to by buf into binary to be placed in mem * return a pointer to the character AFTER the last byte fetched from buf. */ static char * hex2mem(char *buf, char *mem, int count) { int i, hexValue; unsigned char ch; char *mem_start = mem; longjmp_on_fault = 1; for (i=0; i<count; i++) { if ((hexValue = hex(*buf++)) < 0) kgdb_error(KGDBERR_NOTHEXDIG); ch = hexValue << 4; if ((hexValue = hex(*buf++)) < 0) kgdb_error(KGDBERR_NOTHEXDIG); ch |= hexValue; *mem++ = ch; } kgdb_flush_cache_range((void *)mem_start, (void *)(mem - 1)); longjmp_on_fault = 0; return buf; }