Commit 42a9a583 authored by Harvey Harrison's avatar Harvey Harrison Committed by Linus Torvalds

cris: use the common ascii hex helpers

Signed-off-by: default avatarHarvey Harrison <harvey.harrison@gmail.com>
Cc: Mikael Starvik <starvik@axis.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0ad122d9
...@@ -278,14 +278,6 @@ void putDebugChar (int val); ...@@ -278,14 +278,6 @@ void putDebugChar (int val);
void enableDebugIRQ (void); void enableDebugIRQ (void);
/* Returns the character equivalent of a nibble, bit 7, 6, 5, and 4 of a byte,
represented by int x. */
static char highhex (int x);
/* Returns the character equivalent of a nibble, bit 3, 2, 1, and 0 of a byte,
represented by int x. */
static char lowhex (int x);
/* Returns the integer equivalent of a hexadecimal character. */ /* Returns the integer equivalent of a hexadecimal character. */
static int hex (char ch); static int hex (char ch);
...@@ -356,9 +348,6 @@ extern unsigned char executing_task; ...@@ -356,9 +348,6 @@ extern unsigned char executing_task;
/* Run-length encoding maximum length. Send 64 at most. */ /* Run-length encoding maximum length. Send 64 at most. */
#define RUNLENMAX 64 #define RUNLENMAX 64
/* Definition of all valid hexadecimal characters */
static const char hexchars[] = "0123456789abcdef";
/* The inbound/outbound buffers used in packet I/O */ /* The inbound/outbound buffers used in packet I/O */
static char remcomInBuffer[BUFMAX]; static char remcomInBuffer[BUFMAX];
static char remcomOutBuffer[BUFMAX]; static char remcomOutBuffer[BUFMAX];
...@@ -499,8 +488,8 @@ gdb_cris_strtol (const char *s, char **endptr, int base) ...@@ -499,8 +488,8 @@ gdb_cris_strtol (const char *s, char **endptr, int base)
char *sd; char *sd;
int x = 0; int x = 0;
for (s1 = (char*)s; (sd = gdb_cris_memchr(hexchars, *s1, base)) != NULL; ++s1) for (s1 = (char*)s; (sd = gdb_cris_memchr(hex_asc, *s1, base)) != NULL; ++s1)
x = x * base + (sd - hexchars); x = x * base + (sd - hex_asc);
if (endptr) if (endptr)
{ {
...@@ -670,22 +659,6 @@ read_register (char regno, unsigned int *valptr) ...@@ -670,22 +659,6 @@ read_register (char regno, unsigned int *valptr)
} }
/********************************** Packet I/O ******************************/ /********************************** Packet I/O ******************************/
/* Returns the character equivalent of a nibble, bit 7, 6, 5, and 4 of a byte,
represented by int x. */
static inline char
highhex(int x)
{
return hexchars[(x >> 4) & 0xf];
}
/* Returns the character equivalent of a nibble, bit 3, 2, 1, and 0 of a byte,
represented by int x. */
static inline char
lowhex(int x)
{
return hexchars[x & 0xf];
}
/* Returns the integer equivalent of a hexadecimal character. */ /* Returns the integer equivalent of a hexadecimal character. */
static int static int
hex (char ch) hex (char ch)
...@@ -721,8 +694,7 @@ mem2hex(char *buf, unsigned char *mem, int count) ...@@ -721,8 +694,7 @@ mem2hex(char *buf, unsigned char *mem, int count)
/* Valid mem address. */ /* Valid mem address. */
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
ch = *mem++; ch = *mem++;
*buf++ = highhex (ch); buf = pack_hex_byte(buf, ch);
*buf++ = lowhex (ch);
} }
} }
...@@ -857,9 +829,9 @@ putpacket(char *buffer) ...@@ -857,9 +829,9 @@ putpacket(char *buffer)
src++; src++;
} }
} }
putDebugChar ('#'); putDebugChar('#');
putDebugChar (highhex (checksum)); putDebugChar(hex_asc_hi(checksum));
putDebugChar (lowhex (checksum)); putDebugChar(hex_asc_lo(checksum));
} while(kgdb_started && (getDebugChar() != '+')); } while(kgdb_started && (getDebugChar() != '+'));
} }
...@@ -895,9 +867,8 @@ stub_is_stopped(int sigval) ...@@ -895,9 +867,8 @@ stub_is_stopped(int sigval)
/* Send trap type (converted to signal) */ /* Send trap type (converted to signal) */
*ptr++ = 'T'; *ptr++ = 'T';
*ptr++ = highhex (sigval); ptr = pack_hex_byte(ptr, sigval);
*ptr++ = lowhex (sigval);
/* Send register contents. We probably only need to send the /* Send register contents. We probably only need to send the
* PC, frame pointer and stack pointer here. Other registers will be * PC, frame pointer and stack pointer here. Other registers will be
...@@ -910,9 +881,7 @@ stub_is_stopped(int sigval) ...@@ -910,9 +881,7 @@ stub_is_stopped(int sigval)
status = read_register (regno, &reg_cont); status = read_register (regno, &reg_cont);
if (status == SUCCESS) { if (status == SUCCESS) {
ptr = pack_hex_byte(ptr, regno);
*ptr++ = highhex (regno);
*ptr++ = lowhex (regno);
*ptr++ = ':'; *ptr++ = ':';
ptr = mem2hex(ptr, (unsigned char *)&reg_cont, ptr = mem2hex(ptr, (unsigned char *)&reg_cont,
...@@ -937,8 +906,8 @@ stub_is_stopped(int sigval) ...@@ -937,8 +906,8 @@ stub_is_stopped(int sigval)
/* Store thread:r...; with the executing task TID. */ /* Store thread:r...; with the executing task TID. */
gdb_cris_strcpy (&remcomOutBuffer[pos], "thread:"); gdb_cris_strcpy (&remcomOutBuffer[pos], "thread:");
pos += gdb_cris_strlen ("thread:"); pos += gdb_cris_strlen ("thread:");
remcomOutBuffer[pos++] = highhex (executing_task); remcomOutBuffer[pos++] = hex_asc_hi(executing_task);
remcomOutBuffer[pos++] = lowhex (executing_task); remcomOutBuffer[pos++] = hex_asc_lo(executing_task);
gdb_cris_strcpy (&remcomOutBuffer[pos], ";"); gdb_cris_strcpy (&remcomOutBuffer[pos], ";");
#endif #endif
...@@ -1126,8 +1095,8 @@ handle_exception (int sigval) ...@@ -1126,8 +1095,8 @@ handle_exception (int sigval)
Success: SAA, where AA is the signal number. Success: SAA, where AA is the signal number.
Failure: void. */ Failure: void. */
remcomOutBuffer[0] = 'S'; remcomOutBuffer[0] = 'S';
remcomOutBuffer[1] = highhex (sigval); remcomOutBuffer[1] = hex_asc_hi(sigval);
remcomOutBuffer[2] = lowhex (sigval); remcomOutBuffer[2] = hex_asc_lo(sigval);
remcomOutBuffer[3] = 0; remcomOutBuffer[3] = 0;
break; break;
...@@ -1224,23 +1193,23 @@ handle_exception (int sigval) ...@@ -1224,23 +1193,23 @@ handle_exception (int sigval)
case 'C': case 'C':
/* Identify the remote current thread. */ /* Identify the remote current thread. */
gdb_cris_strcpy (&remcomOutBuffer[0], "QC"); gdb_cris_strcpy (&remcomOutBuffer[0], "QC");
remcomOutBuffer[2] = highhex (current_thread_c); remcomOutBuffer[2] = hex_asc_hi(current_thread_c);
remcomOutBuffer[3] = lowhex (current_thread_c); remcomOutBuffer[3] = hex_asc_lo(current_thread_c);
remcomOutBuffer[4] = '\0'; remcomOutBuffer[4] = '\0';
break; break;
case 'L': case 'L':
gdb_cris_strcpy (&remcomOutBuffer[0], "QM"); gdb_cris_strcpy (&remcomOutBuffer[0], "QM");
/* Reply with number of threads. */ /* Reply with number of threads. */
if (os_is_started()) { if (os_is_started()) {
remcomOutBuffer[2] = highhex (number_of_tasks); remcomOutBuffer[2] = hex_asc_hi(number_of_tasks);
remcomOutBuffer[3] = lowhex (number_of_tasks); remcomOutBuffer[3] = hex_asc_lo(number_of_tasks);
} }
else { else {
remcomOutBuffer[2] = highhex (0); remcomOutBuffer[2] = hex_asc_hi(0);
remcomOutBuffer[3] = lowhex (1); remcomOutBuffer[3] = hex_asc_lo(1);
} }
/* Done with the reply. */ /* Done with the reply. */
remcomOutBuffer[4] = lowhex (1); remcomOutBuffer[4] = hex_asc_lo(1);
pos = 5; pos = 5;
/* Expects the argument thread id. */ /* Expects the argument thread id. */
for (; pos < (5 + HEXCHARS_IN_THREAD_ID); pos++) for (; pos < (5 + HEXCHARS_IN_THREAD_ID); pos++)
...@@ -1251,16 +1220,16 @@ handle_exception (int sigval) ...@@ -1251,16 +1220,16 @@ handle_exception (int sigval)
for (thread_id = 0; thread_id < number_of_tasks; thread_id++) { for (thread_id = 0; thread_id < number_of_tasks; thread_id++) {
nextpos = pos + HEXCHARS_IN_THREAD_ID - 1; nextpos = pos + HEXCHARS_IN_THREAD_ID - 1;
for (; pos < nextpos; pos ++) for (; pos < nextpos; pos ++)
remcomOutBuffer[pos] = lowhex (0); remcomOutBuffer[pos] = hex_asc_lo(0);
remcomOutBuffer[pos++] = lowhex (thread_id); remcomOutBuffer[pos++] = hex_asc_lo(thread_id);
} }
} }
else { else {
/* Store the thread identifier of the boot task. */ /* Store the thread identifier of the boot task. */
nextpos = pos + HEXCHARS_IN_THREAD_ID - 1; nextpos = pos + HEXCHARS_IN_THREAD_ID - 1;
for (; pos < nextpos; pos ++) for (; pos < nextpos; pos ++)
remcomOutBuffer[pos] = lowhex (0); remcomOutBuffer[pos] = hex_asc_lo(0);
remcomOutBuffer[pos++] = lowhex (current_thread_c); remcomOutBuffer[pos++] = hex_asc_lo(current_thread_c);
} }
remcomOutBuffer[pos] = '\0'; remcomOutBuffer[pos] = '\0';
break; break;
......
...@@ -398,14 +398,6 @@ void putDebugChar(int val) ...@@ -398,14 +398,6 @@ void putDebugChar(int val)
} }
#endif #endif
/* Returns the character equivalent of a nibble, bit 7, 6, 5, and 4 of a byte,
represented by int x. */
static char highhex(int x);
/* Returns the character equivalent of a nibble, bit 3, 2, 1, and 0 of a byte,
represented by int x. */
static char lowhex(int x);
/* Returns the integer equivalent of a hexadecimal character. */ /* Returns the integer equivalent of a hexadecimal character. */
static int hex(char ch); static int hex(char ch);
...@@ -464,9 +456,6 @@ void breakpoint(void); ...@@ -464,9 +456,6 @@ void breakpoint(void);
/* Run-length encoding maximum length. Send 64 at most. */ /* Run-length encoding maximum length. Send 64 at most. */
#define RUNLENMAX 64 #define RUNLENMAX 64
/* Definition of all valid hexadecimal characters */
static const char hexchars[] = "0123456789abcdef";
/* The inbound/outbound buffers used in packet I/O */ /* The inbound/outbound buffers used in packet I/O */
static char input_buffer[BUFMAX]; static char input_buffer[BUFMAX];
static char output_buffer[BUFMAX]; static char output_buffer[BUFMAX];
...@@ -550,8 +539,8 @@ gdb_cris_strtol(const char *s, char **endptr, int base) ...@@ -550,8 +539,8 @@ gdb_cris_strtol(const char *s, char **endptr, int base)
char *sd; char *sd;
int x = 0; int x = 0;
for (s1 = (char*)s; (sd = gdb_cris_memchr(hexchars, *s1, base)) != NULL; ++s1) for (s1 = (char*)s; (sd = gdb_cris_memchr(hex_asc, *s1, base)) != NULL; ++s1)
x = x * base + (sd - hexchars); x = x * base + (sd - hex_asc);
if (endptr) { if (endptr) {
/* Unconverted suffix is stored in endptr unless endptr is NULL. */ /* Unconverted suffix is stored in endptr unless endptr is NULL. */
...@@ -655,22 +644,6 @@ read_register(char regno, unsigned int *valptr) ...@@ -655,22 +644,6 @@ read_register(char regno, unsigned int *valptr)
} }
/********************************** Packet I/O ******************************/ /********************************** Packet I/O ******************************/
/* Returns the character equivalent of a nibble, bit 7, 6, 5, and 4 of a byte,
represented by int x. */
static inline char
highhex(int x)
{
return hexchars[(x >> 4) & 0xf];
}
/* Returns the character equivalent of a nibble, bit 3, 2, 1, and 0 of a byte,
represented by int x. */
static inline char
lowhex(int x)
{
return hexchars[x & 0xf];
}
/* Returns the integer equivalent of a hexadecimal character. */ /* Returns the integer equivalent of a hexadecimal character. */
static int static int
hex(char ch) hex(char ch)
...@@ -704,8 +677,7 @@ mem2hex(char *buf, unsigned char *mem, int count) ...@@ -704,8 +677,7 @@ mem2hex(char *buf, unsigned char *mem, int count)
/* Valid mem address. */ /* Valid mem address. */
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
ch = *mem++; ch = *mem++;
*buf++ = highhex (ch); buf = pack_hex_byte(buf, ch);
*buf++ = lowhex (ch);
} }
} }
/* Terminate properly. */ /* Terminate properly. */
...@@ -723,8 +695,7 @@ mem2hex_nbo(char *buf, unsigned char *mem, int count) ...@@ -723,8 +695,7 @@ mem2hex_nbo(char *buf, unsigned char *mem, int count)
mem += count - 1; mem += count - 1;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
ch = *mem--; ch = *mem--;
*buf++ = highhex (ch); buf = pack_hex_byte(buf, ch);
*buf++ = lowhex (ch);
} }
/* Terminate properly. */ /* Terminate properly. */
...@@ -862,8 +833,8 @@ putpacket(char *buffer) ...@@ -862,8 +833,8 @@ putpacket(char *buffer)
} }
} }
putDebugChar('#'); putDebugChar('#');
putDebugChar(highhex (checksum)); putDebugChar(hex_asc_hi(checksum));
putDebugChar(lowhex (checksum)); putDebugChar(hex_asc_lo(checksum));
} while(kgdb_started && (getDebugChar() != '+')); } while(kgdb_started && (getDebugChar() != '+'));
} }
...@@ -909,8 +880,7 @@ stub_is_stopped(int sigval) ...@@ -909,8 +880,7 @@ stub_is_stopped(int sigval)
/* Send trap type (converted to signal) */ /* Send trap type (converted to signal) */
*ptr++ = 'T'; *ptr++ = 'T';
*ptr++ = highhex(sigval); ptr = pack_hex_byte(ptr, sigval);
*ptr++ = lowhex(sigval);
if (((reg.exs & 0xff00) >> 8) == 0xc) { if (((reg.exs & 0xff00) >> 8) == 0xc) {
...@@ -1018,30 +988,26 @@ stub_is_stopped(int sigval) ...@@ -1018,30 +988,26 @@ stub_is_stopped(int sigval)
} }
/* Only send PC, frame and stack pointer. */ /* Only send PC, frame and stack pointer. */
read_register(PC, &reg_cont); read_register(PC, &reg_cont);
*ptr++ = highhex(PC); ptr = pack_hex_byte(PC);
*ptr++ = lowhex(PC);
*ptr++ = ':'; *ptr++ = ':';
ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[PC]); ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[PC]);
*ptr++ = ';'; *ptr++ = ';';
read_register(R8, &reg_cont); read_register(R8, &reg_cont);
*ptr++ = highhex(R8); ptr = pack_hex_byte(R8);
*ptr++ = lowhex(R8);
*ptr++ = ':'; *ptr++ = ':';
ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[R8]); ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[R8]);
*ptr++ = ';'; *ptr++ = ';';
read_register(SP, &reg_cont); read_register(SP, &reg_cont);
*ptr++ = highhex(SP); ptr = pack_hex_byte(SP);
*ptr++ = lowhex(SP);
*ptr++ = ':'; *ptr++ = ':';
ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[SP]); ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[SP]);
*ptr++ = ';'; *ptr++ = ';';
/* Send ERP as well; this will save us an entire register fetch in some cases. */ /* Send ERP as well; this will save us an entire register fetch in some cases. */
read_register(ERP, &reg_cont); read_register(ERP, &reg_cont);
*ptr++ = highhex(ERP); ptr = pack_hex_byte(ERP);
*ptr++ = lowhex(ERP);
*ptr++ = ':'; *ptr++ = ':';
ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[ERP]); ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[ERP]);
*ptr++ = ';'; *ptr++ = ';';
...@@ -1533,8 +1499,8 @@ handle_exception(int sigval) ...@@ -1533,8 +1499,8 @@ handle_exception(int sigval)
Success: SAA, where AA is the signal number. Success: SAA, where AA is the signal number.
Failure: void. */ Failure: void. */
output_buffer[0] = 'S'; output_buffer[0] = 'S';
output_buffer[1] = highhex(sigval); output_buffer[1] = hex_asc_hi(sigval);
output_buffer[2] = lowhex(sigval); output_buffer[2] = hex_asc_lo(sigval);
output_buffer[3] = 0; output_buffer[3] = 0;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment