diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2015-10-01 07:42:29 -0400 |
---|---|---|
committer | Jesper Nilsson <jespern@axis.com> | 2015-11-02 14:03:04 -0500 |
commit | 4d0d39758d3e10a31e7f146d56760a92396feb85 (patch) | |
tree | ff92670f49e587f3896cda79c4767d5df9cc6fea /arch/cris/arch-v32 | |
parent | 6a13feb9c82803e2b815eca72fa7a9f5561d7861 (diff) |
cris: kgdb: use native hex2bin
There are kernel native helpers to convert hex ascii to the binary format:
hex_to_bin() and hex2bin(). Thus, no need to reimplement them customly.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Jesper Nilsson <jespern@axis.com>
Diffstat (limited to 'arch/cris/arch-v32')
-rw-r--r-- | arch/cris/arch-v32/kernel/kgdb.c | 96 |
1 files changed, 38 insertions, 58 deletions
diff --git a/arch/cris/arch-v32/kernel/kgdb.c b/arch/cris/arch-v32/kernel/kgdb.c index b06813aeb120..e0fdea706eca 100644 --- a/arch/cris/arch-v32/kernel/kgdb.c +++ b/arch/cris/arch-v32/kernel/kgdb.c | |||
@@ -384,19 +384,11 @@ int getDebugChar(void); | |||
384 | /* Serial port, writes one character. ETRAX 100 specific. from debugport.c */ | 384 | /* Serial port, writes one character. ETRAX 100 specific. from debugport.c */ |
385 | void putDebugChar(int val); | 385 | void putDebugChar(int val); |
386 | 386 | ||
387 | /* Returns the integer equivalent of a hexadecimal character. */ | ||
388 | static int hex(char ch); | ||
389 | |||
390 | /* Convert the memory, pointed to by mem into hexadecimal representation. | 387 | /* Convert the memory, pointed to by mem into hexadecimal representation. |
391 | Put the result in buf, and return a pointer to the last character | 388 | Put the result in buf, and return a pointer to the last character |
392 | in buf (null). */ | 389 | in buf (null). */ |
393 | static char *mem2hex(char *buf, unsigned char *mem, int count); | 390 | static char *mem2hex(char *buf, unsigned char *mem, int count); |
394 | 391 | ||
395 | /* Convert the array, in hexadecimal representation, pointed to by buf into | ||
396 | binary representation. Put the result in mem, and return a pointer to | ||
397 | the character after the last byte written. */ | ||
398 | static unsigned char *hex2mem(unsigned char *mem, char *buf, int count); | ||
399 | |||
400 | /* Put the content of the array, in binary representation, pointed to by buf | 392 | /* Put the content of the array, in binary representation, pointed to by buf |
401 | into memory pointed to by mem, and return a pointer to | 393 | into memory pointed to by mem, and return a pointer to |
402 | the character after the last byte written. */ | 394 | the character after the last byte written. */ |
@@ -449,7 +441,7 @@ static char output_buffer[BUFMAX]; | |||
449 | /* Error and warning messages. */ | 441 | /* Error and warning messages. */ |
450 | enum error_type | 442 | enum error_type |
451 | { | 443 | { |
452 | SUCCESS, E01, E02, E03, E04, E05, E06, | 444 | SUCCESS, E01, E02, E03, E04, E05, E06, E07, E08 |
453 | }; | 445 | }; |
454 | 446 | ||
455 | static char *error_message[] = | 447 | static char *error_message[] = |
@@ -461,6 +453,8 @@ static char *error_message[] = | |||
461 | "E04 The command is not supported - [s,C,S,!,R,d,r] - internal error.", | 453 | "E04 The command is not supported - [s,C,S,!,R,d,r] - internal error.", |
462 | "E05 Change register content - P - the register is not implemented..", | 454 | "E05 Change register content - P - the register is not implemented..", |
463 | "E06 Change memory content - M - internal error.", | 455 | "E06 Change memory content - M - internal error.", |
456 | "E07 Change register content - P - the register is not stored on the stack", | ||
457 | "E08 Invalid parameter" | ||
464 | }; | 458 | }; |
465 | 459 | ||
466 | /********************************** Breakpoint *******************************/ | 460 | /********************************** Breakpoint *******************************/ |
@@ -539,7 +533,7 @@ gdb_cris_strtol(const char *s, char **endptr, int base) | |||
539 | /********************************* Register image ****************************/ | 533 | /********************************* Register image ****************************/ |
540 | 534 | ||
541 | /* Write a value to a specified register in the register image of the current | 535 | /* Write a value to a specified register in the register image of the current |
542 | thread. Returns status code SUCCESS, E02 or E05. */ | 536 | thread. Returns status code SUCCESS, E02, E05 or E08. */ |
543 | static int | 537 | static int |
544 | write_register(int regno, char *val) | 538 | write_register(int regno, char *val) |
545 | { | 539 | { |
@@ -547,8 +541,9 @@ write_register(int regno, char *val) | |||
547 | 541 | ||
548 | if (regno >= R0 && regno <= ACR) { | 542 | if (regno >= R0 && regno <= ACR) { |
549 | /* Consecutive 32-bit registers. */ | 543 | /* Consecutive 32-bit registers. */ |
550 | hex2mem((unsigned char *)®.r0 + (regno - R0) * sizeof(unsigned int), | 544 | if (hex2bin((unsigned char *)®.r0 + (regno - R0) * sizeof(unsigned int), |
551 | val, sizeof(unsigned int)); | 545 | val, sizeof(unsigned int))) |
546 | status = E08; | ||
552 | 547 | ||
553 | } else if (regno == BZ || regno == VR || regno == WZ || regno == DZ) { | 548 | } else if (regno == BZ || regno == VR || regno == WZ || regno == DZ) { |
554 | /* Read-only registers. */ | 549 | /* Read-only registers. */ |
@@ -557,16 +552,19 @@ write_register(int regno, char *val) | |||
557 | } else if (regno == PID) { | 552 | } else if (regno == PID) { |
558 | /* 32-bit register. (Even though we already checked SRS and WZ, we cannot | 553 | /* 32-bit register. (Even though we already checked SRS and WZ, we cannot |
559 | combine this with the EXS - SPC write since SRS and WZ have different size.) */ | 554 | combine this with the EXS - SPC write since SRS and WZ have different size.) */ |
560 | hex2mem((unsigned char *)®.pid, val, sizeof(unsigned int)); | 555 | if (hex2bin((unsigned char *)®.pid, val, sizeof(unsigned int))) |
556 | status = E08; | ||
561 | 557 | ||
562 | } else if (regno == SRS) { | 558 | } else if (regno == SRS) { |
563 | /* 8-bit register. */ | 559 | /* 8-bit register. */ |
564 | hex2mem((unsigned char *)®.srs, val, sizeof(unsigned char)); | 560 | if (hex2bin((unsigned char *)®.srs, val, sizeof(unsigned char))) |
561 | status = E08; | ||
565 | 562 | ||
566 | } else if (regno >= EXS && regno <= SPC) { | 563 | } else if (regno >= EXS && regno <= SPC) { |
567 | /* Consecutive 32-bit registers. */ | 564 | /* Consecutive 32-bit registers. */ |
568 | hex2mem((unsigned char *)®.exs + (regno - EXS) * sizeof(unsigned int), | 565 | if (hex2bin((unsigned char *)®.exs + (regno - EXS) * sizeof(unsigned int), |
569 | val, sizeof(unsigned int)); | 566 | val, sizeof(unsigned int))) |
567 | status = E08; | ||
570 | 568 | ||
571 | } else if (regno == PC) { | 569 | } else if (regno == PC) { |
572 | /* Pseudo-register. Treat as read-only. */ | 570 | /* Pseudo-register. Treat as read-only. */ |
@@ -574,7 +572,9 @@ write_register(int regno, char *val) | |||
574 | 572 | ||
575 | } else if (regno >= S0 && regno <= S15) { | 573 | } else if (regno >= S0 && regno <= S15) { |
576 | /* 32-bit registers. */ | 574 | /* 32-bit registers. */ |
577 | hex2mem((unsigned char *)&sreg.s0_0 + (reg.srs * 16 * sizeof(unsigned int)) + (regno - S0) * sizeof(unsigned int), val, sizeof(unsigned int)); | 575 | if (hex2bin((unsigned char *)&sreg.s0_0 + (reg.srs * 16 * sizeof(unsigned int)) + (regno - S0) * sizeof(unsigned int), |
576 | val, sizeof(unsigned int))) | ||
577 | status = E08; | ||
578 | } else { | 578 | } else { |
579 | /* Non-existing register. */ | 579 | /* Non-existing register. */ |
580 | status = E05; | 580 | status = E05; |
@@ -630,19 +630,6 @@ read_register(char regno, unsigned int *valptr) | |||
630 | } | 630 | } |
631 | 631 | ||
632 | /********************************** Packet I/O ******************************/ | 632 | /********************************** Packet I/O ******************************/ |
633 | /* Returns the integer equivalent of a hexadecimal character. */ | ||
634 | static int | ||
635 | hex(char ch) | ||
636 | { | ||
637 | if ((ch >= 'a') && (ch <= 'f')) | ||
638 | return (ch - 'a' + 10); | ||
639 | if ((ch >= '0') && (ch <= '9')) | ||
640 | return (ch - '0'); | ||
641 | if ((ch >= 'A') && (ch <= 'F')) | ||
642 | return (ch - 'A' + 10); | ||
643 | return -1; | ||
644 | } | ||
645 | |||
646 | /* Convert the memory, pointed to by mem into hexadecimal representation. | 633 | /* Convert the memory, pointed to by mem into hexadecimal representation. |
647 | Put the result in buf, and return a pointer to the last character | 634 | Put the result in buf, and return a pointer to the last character |
648 | in buf (null). */ | 635 | in buf (null). */ |
@@ -689,22 +676,6 @@ mem2hex_nbo(char *buf, unsigned char *mem, int count) | |||
689 | return buf; | 676 | return buf; |
690 | } | 677 | } |
691 | 678 | ||
692 | /* Convert the array, in hexadecimal representation, pointed to by buf into | ||
693 | binary representation. Put the result in mem, and return a pointer to | ||
694 | the character after the last byte written. */ | ||
695 | static unsigned char* | ||
696 | hex2mem(unsigned char *mem, char *buf, int count) | ||
697 | { | ||
698 | int i; | ||
699 | unsigned char ch; | ||
700 | for (i = 0; i < count; i++) { | ||
701 | ch = hex (*buf++) << 4; | ||
702 | ch = ch + hex (*buf++); | ||
703 | *mem++ = ch; | ||
704 | } | ||
705 | return mem; | ||
706 | } | ||
707 | |||
708 | /* Put the content of the array, in binary representation, pointed to by buf | 679 | /* Put the content of the array, in binary representation, pointed to by buf |
709 | into memory pointed to by mem, and return a pointer to the character after | 680 | into memory pointed to by mem, and return a pointer to the character after |
710 | the last byte written. | 681 | the last byte written. |
@@ -763,8 +734,8 @@ getpacket(char *buffer) | |||
763 | buffer[count] = 0; | 734 | buffer[count] = 0; |
764 | 735 | ||
765 | if (ch == '#') { | 736 | if (ch == '#') { |
766 | xmitcsum = hex(getDebugChar()) << 4; | 737 | xmitcsum = hex_to_bin(getDebugChar()) << 4; |
767 | xmitcsum += hex(getDebugChar()); | 738 | xmitcsum += hex_to_bin(getDebugChar()); |
768 | if (checksum != xmitcsum) { | 739 | if (checksum != xmitcsum) { |
769 | /* Wrong checksum */ | 740 | /* Wrong checksum */ |
770 | putDebugChar('-'); | 741 | putDebugChar('-'); |
@@ -1304,14 +1275,17 @@ handle_exception(int sigval) | |||
1304 | /* Write registers. GXX..XX | 1275 | /* Write registers. GXX..XX |
1305 | Each byte of register data is described by two hex digits. | 1276 | Each byte of register data is described by two hex digits. |
1306 | Success: OK | 1277 | Success: OK |
1307 | Failure: void. */ | 1278 | Failure: E08. */ |
1308 | /* General and special registers. */ | 1279 | /* General and special registers. */ |
1309 | hex2mem((char *)®, &input_buffer[1], sizeof(registers)); | 1280 | if (hex2bin((char *)®, &input_buffer[1], sizeof(registers))) |
1281 | gdb_cris_strcpy(output_buffer, error_message[E08]); | ||
1310 | /* Support registers. */ | 1282 | /* Support registers. */ |
1311 | hex2mem((char *)&sreg + (reg.srs * 16 * sizeof(unsigned int)), | 1283 | else if (hex2bin((char *)&sreg + (reg.srs * 16 * sizeof(unsigned int)), |
1312 | &input_buffer[1] + sizeof(registers), | 1284 | &input_buffer[1] + sizeof(registers), |
1313 | 16 * sizeof(unsigned int)); | 1285 | 16 * sizeof(unsigned int))) |
1314 | gdb_cris_strcpy(output_buffer, "OK"); | 1286 | gdb_cris_strcpy(output_buffer, error_message[E08]); |
1287 | else | ||
1288 | gdb_cris_strcpy(output_buffer, "OK"); | ||
1315 | break; | 1289 | break; |
1316 | 1290 | ||
1317 | case 'P': | 1291 | case 'P': |
@@ -1338,6 +1312,10 @@ handle_exception(int sigval) | |||
1338 | /* Do not support non-existing registers. */ | 1312 | /* Do not support non-existing registers. */ |
1339 | gdb_cris_strcpy(output_buffer, error_message[E05]); | 1313 | gdb_cris_strcpy(output_buffer, error_message[E05]); |
1340 | break; | 1314 | break; |
1315 | case E08: | ||
1316 | /* Invalid parameter. */ | ||
1317 | gdb_cris_strcpy(output_buffer, error_message[E08]); | ||
1318 | break; | ||
1341 | default: | 1319 | default: |
1342 | /* Valid register number. */ | 1320 | /* Valid register number. */ |
1343 | gdb_cris_strcpy(output_buffer, "OK"); | 1321 | gdb_cris_strcpy(output_buffer, "OK"); |
@@ -1380,7 +1358,7 @@ handle_exception(int sigval) | |||
1380 | AA..AA is the start address, LLLL is the number of bytes, and | 1358 | AA..AA is the start address, LLLL is the number of bytes, and |
1381 | XX..XX is the hexadecimal data. | 1359 | XX..XX is the hexadecimal data. |
1382 | Success: OK | 1360 | Success: OK |
1383 | Failure: void. */ | 1361 | Failure: E08. */ |
1384 | { | 1362 | { |
1385 | char *lenptr; | 1363 | char *lenptr; |
1386 | char *dataptr; | 1364 | char *dataptr; |
@@ -1389,13 +1367,15 @@ handle_exception(int sigval) | |||
1389 | int len = gdb_cris_strtol(lenptr+1, &dataptr, 16); | 1367 | int len = gdb_cris_strtol(lenptr+1, &dataptr, 16); |
1390 | if (*lenptr == ',' && *dataptr == ':') { | 1368 | if (*lenptr == ',' && *dataptr == ':') { |
1391 | if (input_buffer[0] == 'M') { | 1369 | if (input_buffer[0] == 'M') { |
1392 | hex2mem(addr, dataptr + 1, len); | 1370 | if (hex2bin(addr, dataptr + 1, len)) |
1371 | gdb_cris_strcpy(output_buffer, error_message[E08]); | ||
1372 | else | ||
1373 | gdb_cris_strcpy(output_buffer, "OK"); | ||
1393 | } else /* X */ { | 1374 | } else /* X */ { |
1394 | bin2mem(addr, dataptr + 1, len); | 1375 | bin2mem(addr, dataptr + 1, len); |
1376 | gdb_cris_strcpy(output_buffer, "OK"); | ||
1395 | } | 1377 | } |
1396 | gdb_cris_strcpy(output_buffer, "OK"); | 1378 | } else { |
1397 | } | ||
1398 | else { | ||
1399 | gdb_cris_strcpy(output_buffer, error_message[E06]); | 1379 | gdb_cris_strcpy(output_buffer, error_message[E06]); |
1400 | } | 1380 | } |
1401 | } | 1381 | } |