cris: use the common ascii hex helpers
PATCH 3/9 cris: use the common ascii hex helpers
Signed-off-by Harvey Harrison <[email protected]>
--- arch/cris/arch-v10/kernel/kgdb.c | 103 +++++++++++--------------------------- arch/cris/arch-v32/kernel/kgdb.c | 91 +++++++++------------------------ 2 files changed, 54 insertions(+), 140 deletions(-)
arch/cris/arch-v10/kernel/kgdb.c +30 -73
@@ -278,17 +278,6 @@ void putDebugChar (int val);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. */ -static int hex (char ch); -/* Convert the memory, pointed to by mem into hexadecimal representation. Put the result in buf, and return a pointer to the last character in buf (null). */
@@ -356,9 +345,6 @@ extern unsigned char executing_task;/* Run-length encoding maximum length. Send 64 at most. */ #define RUNLENMAX 64 -/* Definition of all valid hexadecimal characters */ -static const char hexchars[] ="0123456789abcdef" ; -/* The inbound/outbound buffers used in packet I/O */ static char remcomInBuffer[BUFMAX ];static char remcomOutBuffer[BUFMAX ];
@@ -499,8 +485,8 @@ gdb_cris_strtol (const char *s, char **endptr, int base)char *sd;int x =0 ; -for (s1 = (char *)s; (sd =gdb_cris_memchr (hexchars, *s1, base)) !=NULL ; ++s1) - x = x * base + (sd - hexchars); +for (s1 = (char *)s; (sd =gdb_cris_memchr (hex_asc, *s1, base)) !=NULL ; ++s1) + x = x * base + (sd - hex_asc);if (endptr) {
@@ -670,35 +656,6 @@ read_register (char regno, unsigned int *valptr) }/********************************** 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. */ -static int -hex (char ch) -{ -if ((ch >='a' ) && (ch <='f' )) -return (ch -'a' +10 ); -if ((ch >='0' ) && (ch <='9' )) -return (ch -'0' ); -if ((ch >='A' ) && (ch <='F' )) -return (ch -'A' +10 ); -return (-1 ); -} -/* Convert the memory, pointed to by mem into hexadecimal representation. Put the result in buf, and return a pointer to the last character in buf (null). */
@@ -721,8 +678,8 @@ mem2hex(char *buf, unsigned char *mem, int count)/* Valid mem address. */ for (i =0 ; i < count; i++) { ch = *mem++; - *buf++ =highhex (ch); - *buf++ =lowhex (ch); + *buf++ =hex_asc_hi (ch); + *buf++ =hex_asc_lo (ch); } }
@@ -740,8 +697,8 @@ hex2mem (unsigned char *mem, char *buf, int count)int i;unsigned char ch;for (i =0 ; i < count; i++) { - ch =hex (*buf++) <<4 ; - ch = ch +hex (*buf++); + ch =hex_to_int (*buf++) <<4 ; + ch = ch +hex_to_int (*buf++); *mem++ = ch; }return (mem);
@@ -800,8 +757,8 @@ getpacket (char *buffer) buffer[count] ='\0' ;if (ch =='#' ) { - xmitcsum =hex (getDebugChar ()) <<4 ; - xmitcsum +=hex (getDebugChar ()); + xmitcsum =hex_to_int (getDebugChar ()) <<4 ; + xmitcsum +=hex_to_int (getDebugChar ());if (checksum != xmitcsum) {/* Wrong checksum */ putDebugChar ('-' );
@@ -857,9 +814,9 @@ putpacket(char *buffer) src++; } } -putDebugChar ('#' ); -putDebugChar (highhex (checksum)); -putDebugChar (lowhex (checksum)); +putDebugChar ('#' ); +putDebugChar (hex_asc_hi (checksum)); +putDebugChar (hex_asc_lo (checksum)); }while (kgdb_started && (getDebugChar () !='+' )); }
@@ -896,8 +853,8 @@ stub_is_stopped(int sigval)/* Send trap type (converted to signal) */ *ptr++ ='T' ; - *ptr++ =highhex (sigval); - *ptr++ =lowhex (sigval); + *ptr++ =hex_asc_hi (sigval); + *ptr++ =hex_asc_lo (sigval);/* Send register contents. We probably only need to send the * PC, frame pointer and stack pointer here. Other registers will be
@@ -911,8 +868,8 @@ stub_is_stopped(int sigval)if (status ==SUCCESS ) { - *ptr++ =highhex (regno); - *ptr++ =lowhex (regno); + *ptr++ =hex_asc_hi (regno); + *ptr++ =hex_asc_lo (regno); *ptr++ =':' ; ptr = mem2hex(ptr, (unsigned char *)®_cont,
@@ -937,8 +894,8 @@ stub_is_stopped(int sigval)/* Store thread:r...; with the executing task TID. */ gdb_cris_strcpy (&remcomOutBuffer[pos],"thread:" ); pos +=gdb_cris_strlen ("thread:" ); - remcomOutBuffer[pos++] =highhex (executing_task); - remcomOutBuffer[pos++] =lowhex (executing_task); + remcomOutBuffer[pos++] =hex_asc_hi (executing_task); + remcomOutBuffer[pos++] =hex_asc_lo (executing_task);gdb_cris_strcpy (&remcomOutBuffer[pos],";" );#endif
@@ -1126,8 +1083,8 @@ handle_exception (int sigval)Success: SAA, where AA is the signal number. Failure: void. */ remcomOutBuffer[0 ] ='S' ; - remcomOutBuffer[1 ] =highhex (sigval); - remcomOutBuffer[2 ] =lowhex (sigval); + remcomOutBuffer[1 ] =hex_asc_hi (sigval); + remcomOutBuffer[2 ] =hex_asc_lo (sigval); remcomOutBuffer[3 ] =0 ;break ;
@@ -1224,23 +1181,23 @@ handle_exception (int sigval)case 'C' :/* Identify the remote current thread. */ gdb_cris_strcpy (&remcomOutBuffer[0 ],"QC" ); - remcomOutBuffer[2 ] =highhex (current_thread_c); - remcomOutBuffer[3 ] =lowhex (current_thread_c); + remcomOutBuffer[2 ] =hex_asc_hi (current_thread_c); + remcomOutBuffer[3 ] =hex_asc_lo (current_thread_c); remcomOutBuffer[4 ] ='\0' ;break ;case 'L' :gdb_cris_strcpy (&remcomOutBuffer[0 ],"QM" );/* Reply with number of threads. */ if (os_is_started ()) { - remcomOutBuffer[2 ] =highhex (number_of_tasks); - remcomOutBuffer[3 ] =lowhex (number_of_tasks); + remcomOutBuffer[2 ] =hex_asc_hi (number_of_tasks); + remcomOutBuffer[3 ] =hex_asc_lo (number_of_tasks); }else { - remcomOutBuffer[2 ] =highhex (0 ); - remcomOutBuffer[3 ] =lowhex (1 ); + remcomOutBuffer[2 ] =hex_asc_hi (0 ); + remcomOutBuffer[3 ] =hex_asc_lo (1 ); }/* Done with the reply. */ - remcomOutBuffer[4 ] =lowhex (1 ); + remcomOutBuffer[4 ] =hex_asc_lo (1 ); pos =5 ;/* Expects the argument thread id. */ for (; pos < (5 +HEXCHARS_IN_THREAD_ID ); pos++)
@@ -1251,16 +1208,16 @@ handle_exception (int sigval)for (thread_id =0 ; thread_id < number_of_tasks; thread_id++) { nextpos = pos +HEXCHARS_IN_THREAD_ID -1 ;for (; pos < nextpos; pos ++) - remcomOutBuffer[pos] =lowhex (0 ); - remcomOutBuffer[pos++] =lowhex (thread_id); + remcomOutBuffer[pos] =hex_asc_lo (0 ); + remcomOutBuffer[pos++] =hex_asc_lo (thread_id); } }else {/* Store the thread identifier of the boot task. */ nextpos = pos +HEXCHARS_IN_THREAD_ID -1 ;for (; pos < nextpos; pos ++) - remcomOutBuffer[pos] =lowhex (0 ); - remcomOutBuffer[pos++] =lowhex (current_thread_c); + remcomOutBuffer[pos] =hex_asc_lo (0 ); + remcomOutBuffer[pos++] =hex_asc_lo (current_thread_c); } remcomOutBuffer[pos] ='\0' ;break ;
arch/cris/arch-v32/kernel/kgdb.c +24 -67
179 lines not on this page · raw message
Signature · 1 line
1.5.5.1.305.g7c84