aboutsummaryrefslogtreecommitdiffstats
path: root/arch/cris
diff options
context:
space:
mode:
authorHarvey Harrison <harvey.harrison@gmail.com>2008-07-25 22:45:18 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-26 15:00:05 -0400
commit42a9a58361d3b65f4a7c2ad280cc1ec9b657e7d2 (patch)
tree7f539d4ec6ee6827c4d80a581b7cc49047e6143b /arch/cris
parent0ad122d901977890de554fdd3ff65474efc1a9bf (diff)
cris: use the common ascii hex helpers
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com> Cc: Mikael Starvik <starvik@axis.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/cris')
-rw-r--r--arch/cris/arch-v10/kernel/kgdb.c79
-rw-r--r--arch/cris/arch-v32/kernel/kgdb.c60
2 files changed, 37 insertions, 102 deletions
diff --git a/arch/cris/arch-v10/kernel/kgdb.c b/arch/cris/arch-v10/kernel/kgdb.c
index a3ca55150745..6fea45f2e40c 100644
--- a/arch/cris/arch-v10/kernel/kgdb.c
+++ b/arch/cris/arch-v10/kernel/kgdb.c
@@ -278,14 +278,6 @@ void putDebugChar (int val);
278 278
279void enableDebugIRQ (void); 279void enableDebugIRQ (void);
280 280
281/* Returns the character equivalent of a nibble, bit 7, 6, 5, and 4 of a byte,
282 represented by int x. */
283static char highhex (int x);
284
285/* Returns the character equivalent of a nibble, bit 3, 2, 1, and 0 of a byte,
286 represented by int x. */
287static char lowhex (int x);
288
289/* Returns the integer equivalent of a hexadecimal character. */ 281/* Returns the integer equivalent of a hexadecimal character. */
290static int hex (char ch); 282static int hex (char ch);
291 283
@@ -356,9 +348,6 @@ extern unsigned char executing_task;
356/* Run-length encoding maximum length. Send 64 at most. */ 348/* Run-length encoding maximum length. Send 64 at most. */
357#define RUNLENMAX 64 349#define RUNLENMAX 64
358 350
359/* Definition of all valid hexadecimal characters */
360static const char hexchars[] = "0123456789abcdef";
361
362/* The inbound/outbound buffers used in packet I/O */ 351/* The inbound/outbound buffers used in packet I/O */
363static char remcomInBuffer[BUFMAX]; 352static char remcomInBuffer[BUFMAX];
364static char remcomOutBuffer[BUFMAX]; 353static char remcomOutBuffer[BUFMAX];
@@ -499,8 +488,8 @@ gdb_cris_strtol (const char *s, char **endptr, int base)
499 char *sd; 488 char *sd;
500 int x = 0; 489 int x = 0;
501 490
502 for (s1 = (char*)s; (sd = gdb_cris_memchr(hexchars, *s1, base)) != NULL; ++s1) 491 for (s1 = (char*)s; (sd = gdb_cris_memchr(hex_asc, *s1, base)) != NULL; ++s1)
503 x = x * base + (sd - hexchars); 492 x = x * base + (sd - hex_asc);
504 493
505 if (endptr) 494 if (endptr)
506 { 495 {
@@ -670,22 +659,6 @@ read_register (char regno, unsigned int *valptr)
670} 659}
671 660
672/********************************** Packet I/O ******************************/ 661/********************************** Packet I/O ******************************/
673/* Returns the character equivalent of a nibble, bit 7, 6, 5, and 4 of a byte,
674 represented by int x. */
675static inline char
676highhex(int x)
677{
678 return hexchars[(x >> 4) & 0xf];
679}
680
681/* Returns the character equivalent of a nibble, bit 3, 2, 1, and 0 of a byte,
682 represented by int x. */
683static inline char
684lowhex(int x)
685{
686 return hexchars[x & 0xf];
687}
688
689/* Returns the integer equivalent of a hexadecimal character. */ 662/* Returns the integer equivalent of a hexadecimal character. */
690static int 663static int
691hex (char ch) 664hex (char ch)
@@ -721,8 +694,7 @@ mem2hex(char *buf, unsigned char *mem, int count)
721 /* Valid mem address. */ 694 /* Valid mem address. */
722 for (i = 0; i < count; i++) { 695 for (i = 0; i < count; i++) {
723 ch = *mem++; 696 ch = *mem++;
724 *buf++ = highhex (ch); 697 buf = pack_hex_byte(buf, ch);
725 *buf++ = lowhex (ch);
726 } 698 }
727 } 699 }
728 700
@@ -857,9 +829,9 @@ putpacket(char *buffer)
857 src++; 829 src++;
858 } 830 }
859 } 831 }
860 putDebugChar ('#'); 832 putDebugChar('#');
861 putDebugChar (highhex (checksum)); 833 putDebugChar(hex_asc_hi(checksum));
862 putDebugChar (lowhex (checksum)); 834 putDebugChar(hex_asc_lo(checksum));
863 } while(kgdb_started && (getDebugChar() != '+')); 835 } while(kgdb_started && (getDebugChar() != '+'));
864} 836}
865 837
@@ -895,9 +867,8 @@ stub_is_stopped(int sigval)
895 867
896 /* Send trap type (converted to signal) */ 868 /* Send trap type (converted to signal) */
897 869
898 *ptr++ = 'T'; 870 *ptr++ = 'T';
899 *ptr++ = highhex (sigval); 871 ptr = pack_hex_byte(ptr, sigval);
900 *ptr++ = lowhex (sigval);
901 872
902 /* Send register contents. We probably only need to send the 873 /* Send register contents. We probably only need to send the
903 * PC, frame pointer and stack pointer here. Other registers will be 874 * PC, frame pointer and stack pointer here. Other registers will be
@@ -910,9 +881,7 @@ stub_is_stopped(int sigval)
910 status = read_register (regno, &reg_cont); 881 status = read_register (regno, &reg_cont);
911 882
912 if (status == SUCCESS) { 883 if (status == SUCCESS) {
913 884 ptr = pack_hex_byte(ptr, regno);
914 *ptr++ = highhex (regno);
915 *ptr++ = lowhex (regno);
916 *ptr++ = ':'; 885 *ptr++ = ':';
917 886
918 ptr = mem2hex(ptr, (unsigned char *)&reg_cont, 887 ptr = mem2hex(ptr, (unsigned char *)&reg_cont,
@@ -937,8 +906,8 @@ stub_is_stopped(int sigval)
937 /* Store thread:r...; with the executing task TID. */ 906 /* Store thread:r...; with the executing task TID. */
938 gdb_cris_strcpy (&remcomOutBuffer[pos], "thread:"); 907 gdb_cris_strcpy (&remcomOutBuffer[pos], "thread:");
939 pos += gdb_cris_strlen ("thread:"); 908 pos += gdb_cris_strlen ("thread:");
940 remcomOutBuffer[pos++] = highhex (executing_task); 909 remcomOutBuffer[pos++] = hex_asc_hi(executing_task);
941 remcomOutBuffer[pos++] = lowhex (executing_task); 910 remcomOutBuffer[pos++] = hex_asc_lo(executing_task);
942 gdb_cris_strcpy (&remcomOutBuffer[pos], ";"); 911 gdb_cris_strcpy (&remcomOutBuffer[pos], ";");
943#endif 912#endif
944 913
@@ -1126,8 +1095,8 @@ handle_exception (int sigval)
1126 Success: SAA, where AA is the signal number. 1095 Success: SAA, where AA is the signal number.
1127 Failure: void. */ 1096 Failure: void. */
1128 remcomOutBuffer[0] = 'S'; 1097 remcomOutBuffer[0] = 'S';
1129 remcomOutBuffer[1] = highhex (sigval); 1098 remcomOutBuffer[1] = hex_asc_hi(sigval);
1130 remcomOutBuffer[2] = lowhex (sigval); 1099 remcomOutBuffer[2] = hex_asc_lo(sigval);
1131 remcomOutBuffer[3] = 0; 1100 remcomOutBuffer[3] = 0;
1132 break; 1101 break;
1133 1102
@@ -1224,23 +1193,23 @@ handle_exception (int sigval)
1224 case 'C': 1193 case 'C':
1225 /* Identify the remote current thread. */ 1194 /* Identify the remote current thread. */
1226 gdb_cris_strcpy (&remcomOutBuffer[0], "QC"); 1195 gdb_cris_strcpy (&remcomOutBuffer[0], "QC");
1227 remcomOutBuffer[2] = highhex (current_thread_c); 1196 remcomOutBuffer[2] = hex_asc_hi(current_thread_c);
1228 remcomOutBuffer[3] = lowhex (current_thread_c); 1197 remcomOutBuffer[3] = hex_asc_lo(current_thread_c);
1229 remcomOutBuffer[4] = '\0'; 1198 remcomOutBuffer[4] = '\0';
1230 break; 1199 break;
1231 case 'L': 1200 case 'L':
1232 gdb_cris_strcpy (&remcomOutBuffer[0], "QM"); 1201 gdb_cris_strcpy (&remcomOutBuffer[0], "QM");
1233 /* Reply with number of threads. */ 1202 /* Reply with number of threads. */
1234 if (os_is_started()) { 1203 if (os_is_started()) {
1235 remcomOutBuffer[2] = highhex (number_of_tasks); 1204 remcomOutBuffer[2] = hex_asc_hi(number_of_tasks);
1236 remcomOutBuffer[3] = lowhex (number_of_tasks); 1205 remcomOutBuffer[3] = hex_asc_lo(number_of_tasks);
1237 } 1206 }
1238 else { 1207 else {
1239 remcomOutBuffer[2] = highhex (0); 1208 remcomOutBuffer[2] = hex_asc_hi(0);
1240 remcomOutBuffer[3] = lowhex (1); 1209 remcomOutBuffer[3] = hex_asc_lo(1);
1241 } 1210 }
1242 /* Done with the reply. */ 1211 /* Done with the reply. */
1243 remcomOutBuffer[4] = lowhex (1); 1212 remcomOutBuffer[4] = hex_asc_lo(1);
1244 pos = 5; 1213 pos = 5;
1245 /* Expects the argument thread id. */ 1214 /* Expects the argument thread id. */
1246 for (; pos < (5 + HEXCHARS_IN_THREAD_ID); pos++) 1215 for (; pos < (5 + HEXCHARS_IN_THREAD_ID); pos++)
@@ -1251,16 +1220,16 @@ handle_exception (int sigval)
1251 for (thread_id = 0; thread_id < number_of_tasks; thread_id++) { 1220 for (thread_id = 0; thread_id < number_of_tasks; thread_id++) {
1252 nextpos = pos + HEXCHARS_IN_THREAD_ID - 1; 1221 nextpos = pos + HEXCHARS_IN_THREAD_ID - 1;
1253 for (; pos < nextpos; pos ++) 1222 for (; pos < nextpos; pos ++)
1254 remcomOutBuffer[pos] = lowhex (0); 1223 remcomOutBuffer[pos] = hex_asc_lo(0);
1255 remcomOutBuffer[pos++] = lowhex (thread_id); 1224 remcomOutBuffer[pos++] = hex_asc_lo(thread_id);
1256 } 1225 }
1257 } 1226 }
1258 else { 1227 else {
1259 /* Store the thread identifier of the boot task. */ 1228 /* Store the thread identifier of the boot task. */
1260 nextpos = pos + HEXCHARS_IN_THREAD_ID - 1; 1229 nextpos = pos + HEXCHARS_IN_THREAD_ID - 1;
1261 for (; pos < nextpos; pos ++) 1230 for (; pos < nextpos; pos ++)
1262 remcomOutBuffer[pos] = lowhex (0); 1231 remcomOutBuffer[pos] = hex_asc_lo(0);
1263 remcomOutBuffer[pos++] = lowhex (current_thread_c); 1232 remcomOutBuffer[pos++] = hex_asc_lo(current_thread_c);
1264 } 1233 }
1265 remcomOutBuffer[pos] = '\0'; 1234 remcomOutBuffer[pos] = '\0';
1266 break; 1235 break;
diff --git a/arch/cris/arch-v32/kernel/kgdb.c b/arch/cris/arch-v32/kernel/kgdb.c
index 4e2e2e271efb..8bd5a5bc0dc7 100644
--- a/arch/cris/arch-v32/kernel/kgdb.c
+++ b/arch/cris/arch-v32/kernel/kgdb.c
@@ -398,14 +398,6 @@ void putDebugChar(int val)
398} 398}
399#endif 399#endif
400 400
401/* Returns the character equivalent of a nibble, bit 7, 6, 5, and 4 of a byte,
402 represented by int x. */
403static char highhex(int x);
404
405/* Returns the character equivalent of a nibble, bit 3, 2, 1, and 0 of a byte,
406 represented by int x. */
407static char lowhex(int x);
408
409/* Returns the integer equivalent of a hexadecimal character. */ 401/* Returns the integer equivalent of a hexadecimal character. */
410static int hex(char ch); 402static int hex(char ch);
411 403
@@ -464,9 +456,6 @@ void breakpoint(void);
464/* Run-length encoding maximum length. Send 64 at most. */ 456/* Run-length encoding maximum length. Send 64 at most. */
465#define RUNLENMAX 64 457#define RUNLENMAX 64
466 458
467/* Definition of all valid hexadecimal characters */
468static const char hexchars[] = "0123456789abcdef";
469
470/* The inbound/outbound buffers used in packet I/O */ 459/* The inbound/outbound buffers used in packet I/O */
471static char input_buffer[BUFMAX]; 460static char input_buffer[BUFMAX];
472static char output_buffer[BUFMAX]; 461static char output_buffer[BUFMAX];
@@ -550,8 +539,8 @@ gdb_cris_strtol(const char *s, char **endptr, int base)
550 char *sd; 539 char *sd;
551 int x = 0; 540 int x = 0;
552 541
553 for (s1 = (char*)s; (sd = gdb_cris_memchr(hexchars, *s1, base)) != NULL; ++s1) 542 for (s1 = (char*)s; (sd = gdb_cris_memchr(hex_asc, *s1, base)) != NULL; ++s1)
554 x = x * base + (sd - hexchars); 543 x = x * base + (sd - hex_asc);
555 544
556 if (endptr) { 545 if (endptr) {
557 /* Unconverted suffix is stored in endptr unless endptr is NULL. */ 546 /* Unconverted suffix is stored in endptr unless endptr is NULL. */
@@ -655,22 +644,6 @@ read_register(char regno, unsigned int *valptr)
655} 644}
656 645
657/********************************** Packet I/O ******************************/ 646/********************************** Packet I/O ******************************/
658/* Returns the character equivalent of a nibble, bit 7, 6, 5, and 4 of a byte,
659 represented by int x. */
660static inline char
661highhex(int x)
662{
663 return hexchars[(x >> 4) & 0xf];
664}
665
666/* Returns the character equivalent of a nibble, bit 3, 2, 1, and 0 of a byte,
667 represented by int x. */
668static inline char
669lowhex(int x)
670{
671 return hexchars[x & 0xf];
672}
673
674/* Returns the integer equivalent of a hexadecimal character. */ 647/* Returns the integer equivalent of a hexadecimal character. */
675static int 648static int
676hex(char ch) 649hex(char ch)
@@ -704,8 +677,7 @@ mem2hex(char *buf, unsigned char *mem, int count)
704 /* Valid mem address. */ 677 /* Valid mem address. */
705 for (i = 0; i < count; i++) { 678 for (i = 0; i < count; i++) {
706 ch = *mem++; 679 ch = *mem++;
707 *buf++ = highhex (ch); 680 buf = pack_hex_byte(buf, ch);
708 *buf++ = lowhex (ch);
709 } 681 }
710 } 682 }
711 /* Terminate properly. */ 683 /* Terminate properly. */
@@ -723,8 +695,7 @@ mem2hex_nbo(char *buf, unsigned char *mem, int count)
723 mem += count - 1; 695 mem += count - 1;
724 for (i = 0; i < count; i++) { 696 for (i = 0; i < count; i++) {
725 ch = *mem--; 697 ch = *mem--;
726 *buf++ = highhex (ch); 698 buf = pack_hex_byte(buf, ch);
727 *buf++ = lowhex (ch);
728 } 699 }
729 700
730 /* Terminate properly. */ 701 /* Terminate properly. */
@@ -862,8 +833,8 @@ putpacket(char *buffer)
862 } 833 }
863 } 834 }
864 putDebugChar('#'); 835 putDebugChar('#');
865 putDebugChar(highhex (checksum)); 836 putDebugChar(hex_asc_hi(checksum));
866 putDebugChar(lowhex (checksum)); 837 putDebugChar(hex_asc_lo(checksum));
867 } while(kgdb_started && (getDebugChar() != '+')); 838 } while(kgdb_started && (getDebugChar() != '+'));
868} 839}
869 840
@@ -909,8 +880,7 @@ stub_is_stopped(int sigval)
909 /* Send trap type (converted to signal) */ 880 /* Send trap type (converted to signal) */
910 881
911 *ptr++ = 'T'; 882 *ptr++ = 'T';
912 *ptr++ = highhex(sigval); 883 ptr = pack_hex_byte(ptr, sigval);
913 *ptr++ = lowhex(sigval);
914 884
915 if (((reg.exs & 0xff00) >> 8) == 0xc) { 885 if (((reg.exs & 0xff00) >> 8) == 0xc) {
916 886
@@ -1018,30 +988,26 @@ stub_is_stopped(int sigval)
1018 } 988 }
1019 /* Only send PC, frame and stack pointer. */ 989 /* Only send PC, frame and stack pointer. */
1020 read_register(PC, &reg_cont); 990 read_register(PC, &reg_cont);
1021 *ptr++ = highhex(PC); 991 ptr = pack_hex_byte(PC);
1022 *ptr++ = lowhex(PC);
1023 *ptr++ = ':'; 992 *ptr++ = ':';
1024 ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[PC]); 993 ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[PC]);
1025 *ptr++ = ';'; 994 *ptr++ = ';';
1026 995
1027 read_register(R8, &reg_cont); 996 read_register(R8, &reg_cont);
1028 *ptr++ = highhex(R8); 997 ptr = pack_hex_byte(R8);
1029 *ptr++ = lowhex(R8);
1030 *ptr++ = ':'; 998 *ptr++ = ':';
1031 ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[R8]); 999 ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[R8]);
1032 *ptr++ = ';'; 1000 *ptr++ = ';';
1033 1001
1034 read_register(SP, &reg_cont); 1002 read_register(SP, &reg_cont);
1035 *ptr++ = highhex(SP); 1003 ptr = pack_hex_byte(SP);
1036 *ptr++ = lowhex(SP);
1037 *ptr++ = ':'; 1004 *ptr++ = ':';
1038 ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[SP]); 1005 ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[SP]);
1039 *ptr++ = ';'; 1006 *ptr++ = ';';
1040 1007
1041 /* Send ERP as well; this will save us an entire register fetch in some cases. */ 1008 /* Send ERP as well; this will save us an entire register fetch in some cases. */
1042 read_register(ERP, &reg_cont); 1009 read_register(ERP, &reg_cont);
1043 *ptr++ = highhex(ERP); 1010 ptr = pack_hex_byte(ERP);
1044 *ptr++ = lowhex(ERP);
1045 *ptr++ = ':'; 1011 *ptr++ = ':';
1046 ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[ERP]); 1012 ptr = mem2hex(ptr, (unsigned char *)&reg_cont, register_size[ERP]);
1047 *ptr++ = ';'; 1013 *ptr++ = ';';
@@ -1533,8 +1499,8 @@ handle_exception(int sigval)
1533 Success: SAA, where AA is the signal number. 1499 Success: SAA, where AA is the signal number.
1534 Failure: void. */ 1500 Failure: void. */
1535 output_buffer[0] = 'S'; 1501 output_buffer[0] = 'S';
1536 output_buffer[1] = highhex(sigval); 1502 output_buffer[1] = hex_asc_hi(sigval);
1537 output_buffer[2] = lowhex(sigval); 1503 output_buffer[2] = hex_asc_lo(sigval);
1538 output_buffer[3] = 0; 1504 output_buffer[3] = 0;
1539 break; 1505 break;
1540 1506