Skip to contentSkip to conversation

cris: kgdb: use native hex2bin

PATCH In review Andy Shevchenko 4 participants 7 messages Jun 4, 2013 – Sep 30, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Cc Geert Uytterhoeven <[email protected]>
---
 arch/cris/arch-v10/kernel/kgdb.c | 36 +++----------------------
 arch/cris/arch-v32/kernel/kgdb.c | 57 +++++++---------------------------------
 2 files changed, 14 insertions(+), 79 deletions(-)
arch/cris/arch-v10/kernel/kgdb.c +4 -32
index 22d846b..dbd4ba8 100644
@@ -413,18 +413,6 @@ gdb_cris_strtol (const char *s, char **endptr, int base)
 }
 
 /********************************** Packet I/O ******************************/
-/* 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
@@ -455,22 +443,6 @@ mem2hex(char *buf, unsigned char *mem, int count)
 	return (buf);
 }
 
-/* Convert the array, in hexadecimal representation, pointed to by buf into
-   binary representation. Put the result in mem, and return a pointer to
-   the character after the last byte written. */
-static unsigned char*
-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++);
-		*mem++ = ch;
-	}
-	return (mem);
-}
-
 /* Put the content of the array, in binary representation, pointed to by buf
    into memory pointed to by mem, and return a pointer to the character after
    the last byte written.
@@ -524,8 +496,8 @@ getpacket (char *buffer)
 		buffer[count] = '\0';
 		
 		if (ch == '#') {
-			xmitcsum = hex (getDebugChar ()) << 4;
-			xmitcsum += hex (getDebugChar ());
+			xmitcsum = hex_to_bin(getDebugChar()) << 4;
+			xmitcsum += hex_to_bin(getDebugChar());
 			if (checksum != xmitcsum) {
 				/* Wrong checksum */
 				putDebugChar ('-');
@@ -760,7 +732,7 @@ handle_exception (int sigval)
 				   Each byte of register data  is described by two hex digits.
 				   Success: OK
 				   Failure: void. */
-				hex2mem((char *)&cris_reg, &remcomInBuffer[1], sizeof(registers));
+				hex2bin((char *)&cris_reg, &remcomInBuffer[1], sizeof(registers));
 				gdb_cris_strcpy (remcomOutBuffer, "OK");
 				break;
 				
@@ -835,7 +807,7 @@ handle_exception (int sigval)
 					int length = gdb_cris_strtol(lenptr+1, &dataptr, 16);
 					if (*lenptr == ',' && *dataptr == ':') {
 						if (remcomInBuffer[0] == 'M') {
-							hex2mem(addr, dataptr + 1, length);
+							hex2bin(addr, dataptr + 1, length);
 						}
 						else /* X */ {
 							bin2mem(addr, dataptr + 1, length);
arch/cris/arch-v32/kernel/kgdb.c +10 -47

123 lines not on this page · raw message

Signature · 1 line
1.8.2.rc0.22.gb3600c3
#1 lore raw
Quoted 5 lines · Andy Shevchenko

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.

Cc Geert Uytterhoeven <[email protected]>

Forgot to mention this is v2.
Changes:
- rebased against today's linux-next
- v32 is also fixed
- fixed missed usage of hex() outside of hex2mem()

--
With Best Regards,
Andy Shevchenko

#2 lore raw
In reply to Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

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.

No one is interested in this?

Quoted 279 lines
Cc Geert Uytterhoeven <[email protected]>
---
 arch/cris/arch-v10/kernel/kgdb.c | 36 +++----------------------
 arch/cris/arch-v32/kernel/kgdb.c | 57 +++++++-----------------------
----------
 2 files changed, 14 insertions(+), 79 deletions(-)
arch/cris/arch renamed from arch/cris/arch-v10/kernel/kgdb.c +0 -1
-v10/kernel/kgdb.c

index 22d846b..dbd4ba8 100644

arch/cris/arch-v10/kernel/kgdb.c +0 -12
@@ -413,18 +413,6 @@ gdb_cris_strtol (const char *s, char **endptr, 
 int base)
 }
 
 /********************************** Packet I/O 
 ******************************/
-/* 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

arch/cris/arch-v10/kernel/kgdb.c +0 -1
@@ -455,22 +443,6 @@ mem2hex(char *buf, unsigned char *mem, int 
 count)
 	return (buf);
 }
 
-/* Convert the array, in hexadecimal representation, pointed to by 

buf into
- binary representation. Put the result in mem, and return a
pointer to

arch/cris/arch-v10/kernel/kgdb.c +0 -14
-   the character after the last byte written. */
-static unsigned char*
-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++);
-		*mem++ = ch;
-	}
-	return (mem);
-}
-
 /* Put the content of the array, in binary representation, pointed 

to by buf
into memory pointed to by mem, and return a pointer to the
character after
the last byte written.

arch/cris/arch-v10/kernel/kgdb.c +2 -2
@@ -524,8 +496,8 @@ getpacket (char *buffer)
 		buffer[count] = '\0';
 
 		if (ch == '#') {
-			xmitcsum = hex (getDebugChar ()) << 4;
-			xmitcsum += hex (getDebugChar ());
+			xmitcsum = hex_to_bin(getDebugChar()) << 4;
+			xmitcsum += hex_to_bin(getDebugChar());
 			if (checksum != xmitcsum) {
 				/* Wrong checksum */
 				putDebugChar ('-');
@@ -760,7 +732,7 @@ handle_exception (int sigval)
 				   Each byte of register data  is 

described by two hex digits.

arch/cris/arch-v10/kernel/kgdb.c +0 -1
 				   Success: OK
 				   Failure: void. */
-				hex2mem((char *)&cris_reg, 

&remcomInBuffer[1], sizeof(registers));

arch/cris/arch-v10/kernel/kgdb.c +1 -0
+				hex2bin((char *)&cris_reg, 

&remcomInBuffer[1], sizeof(registers));
gdb_cris_strcpy (remcomOutBuffer,
"OK");

arch/cris/arch-v10/kernel/kgdb.c +0 -1
 				break;
@@ -835,7 +807,7 @@ handle_exception (int sigval)
 					int length = 
 gdb_cris_strtol(lenptr+1, &dataptr, 16);
 					if (*lenptr == ',' && 
 *dataptr == ':') {
 						if 
 (remcomInBuffer[0] == 'M') {
-							hex2mem(addr

, dataptr + 1, length);

arch/cris/arch-v10/kernel/kgdb.c +1 -0
+							hex2bin(addr

, dataptr + 1, length);

arch/cris/arch-v10/kernel/kgdb.c +0 -0
 						}
 						else /* X */ {
 							bin2mem(addr

, dataptr + 1, length);

arch/cris/arch renamed from arch/cris/arch-v32/kernel/kgdb.c +0 -1
-v32/kernel/kgdb.c

index b06813a..590c11b 100644

arch/cris/arch-v32/kernel/kgdb.c +0 -0
@@ -384,19 +384,11 @@ int getDebugChar(void);
 /* Serial port, writes one character. ETRAX 100 specific. from 

debugport.c */
void putDebugChar(int val);

arch/cris/arch-v32/kernel/kgdb.c +0 -3
-/* 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). */
static char *mem2hex(char *buf, unsigned char *mem, int count);

-/* Convert the array, in hexadecimal representation, pointed to by buf into
- binary representation. Put the result in mem, and return a
pointer to

arch/cris/arch-v32/kernel/kgdb.c +0 -2
-   the character after the last byte written. */
-static unsigned char *hex2mem(unsigned char *mem, char *buf, int 

count);
-
/* Put the content of the array, in binary representation, pointed
to by buf
into memory pointed to by mem, and return a pointer to the character after the last byte written. */

arch/cris/arch-v32/kernel/kgdb.c +1 -1
@@ -547,7 +539,7 @@ write_register(int regno, char *val)
 
         if (regno >= R0 && regno <= ACR) {
 		/* Consecutive 32-bit registers. */
-		hex2mem((unsigned char *)&reg.r0 + (regno - R0) * 
 sizeof(unsigned int),
+		hex2bin((unsigned char *)&reg.r0 + (regno - R0) * 
 sizeof(unsigned int),
 			val, sizeof(unsigned int));

} else if (regno == BZ || regno == VR || regno == WZ ||
regno == DZ) {

arch/cris/arch-v32/kernel/kgdb.c +0 -0
@@ -557,15 +549,15 @@ write_register(int regno, char *val)
 	} else if (regno == PID) {
 		/* 32-bit register. (Even though we already checked 

SRS and WZ, we cannot
combine this with the EXS - SPC write since SRS
and WZ have different size.) */

arch/cris/arch-v32/kernel/kgdb.c +0 -1
-		hex2mem((unsigned char *)&reg.pid, val, 

sizeof(unsigned int));

arch/cris/arch-v32/kernel/kgdb.c +1 -0
+		hex2bin((unsigned char *)&reg.pid, val, 

sizeof(unsigned int));

arch/cris/arch-v32/kernel/kgdb.c +0 -1
 	} else if (regno == SRS) {
 		/* 8-bit register. */
-		hex2mem((unsigned char *)&reg.srs, val, 

sizeof(unsigned char));

arch/cris/arch-v32/kernel/kgdb.c +1 -0
+		hex2bin((unsigned char *)&reg.srs, val, 

sizeof(unsigned char));

arch/cris/arch-v32/kernel/kgdb.c +0 -1
 	} else if (regno >= EXS && regno <= SPC) {
 		/* Consecutive 32-bit registers. */
-		hex2mem((unsigned char *)&reg.exs + (regno - EXS) * 

sizeof(unsigned int),

arch/cris/arch-v32/kernel/kgdb.c +1 -0
+		hex2bin((unsigned char *)&reg.exs + (regno - EXS) * 

sizeof(unsigned int),

arch/cris/arch-v32/kernel/kgdb.c +1 -1
 			 val, sizeof(unsigned int));
 
        } else if (regno == PC) {
@@ -574,7 +566,7 @@ write_register(int regno, char *val)
 
        } else if (regno >= S0 && regno <= S15) {
                /* 32-bit registers. */
-               hex2mem((unsigned char *)&sreg.s0_0 + (reg.srs * 16 * 
 sizeof(unsigned int)) + (regno - S0) * sizeof(unsigned int), val, 
 sizeof(unsigned int));
+               hex2bin((unsigned char *)&sreg.s0_0 + (reg.srs * 16 * 
 sizeof(unsigned int)) + (regno - S0) * sizeof(unsigned int), val, 

sizeof(unsigned int));

arch/cris/arch-v32/kernel/kgdb.c +0 -13
 	} else {
 		/* Non-existing register. */
 		status = E05;
@@ -630,19 +622,6 @@ read_register(char regno, unsigned int *valptr)
 }
 
 /********************************** Packet I/O 
 ******************************/
-/* 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). */

arch/cris/arch-v32/kernel/kgdb.c +0 -1
@@ -689,22 +668,6 @@ mem2hex_nbo(char *buf, unsigned char *mem, int 
 count)
 	return buf;
 }
 
-/* Convert the array, in hexadecimal representation, pointed to by 

buf into
- binary representation. Put the result in mem, and return a
pointer to

arch/cris/arch-v32/kernel/kgdb.c +0 -14
-   the character after the last byte written. */
-static unsigned char*
-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++);
-		*mem++ = ch;
-	}
-	return mem;
-}
-
 /* Put the content of the array, in binary representation, pointed 

to by buf
into memory pointed to by mem, and return a pointer to the
character after
the last byte written.

arch/cris/arch-v32/kernel/kgdb.c +4 -4
@@ -763,8 +726,8 @@ getpacket(char *buffer)
 		buffer[count] = 0;
 
 		if (ch == '#') {
-			xmitcsum = hex(getDebugChar()) << 4;
-			xmitcsum += hex(getDebugChar());
+			xmitcsum = hex_to_bin(getDebugChar()) << 4;
+			xmitcsum += hex_to_bin(getDebugChar());
 			if (checksum != xmitcsum) {
 				/* Wrong checksum */
 				putDebugChar('-');
@@ -1306,9 +1269,9 @@ handle_exception(int sigval)
 				   Success: OK
 				   Failure: void. */
 				/* General and special registers. */
-				hex2mem((char *)&reg, 
 &input_buffer[1], sizeof(registers));
+				hex2bin((char *)&reg, 
 &input_buffer[1], sizeof(registers));
 				/* Support registers. */
-				hex2mem((char *)&sreg + (reg.srs * 
 16 * sizeof(unsigned int)),
+				hex2bin((char *)&sreg + (reg.srs * 

16 * sizeof(unsigned int)),
&input_buffer[1] +
sizeof(registers),

arch/cris/arch-v32/kernel/kgdb.c +0 -0
 					16 * sizeof(unsigned int));
 				gdb_cris_strcpy(output_buffer, 

"OK");

arch/cris/arch-v32/kernel/kgdb.c +0 -1
@@ -1389,7 +1352,7 @@ handle_exception(int sigval)
 					int len = 
 gdb_cris_strtol(lenptr+1, &dataptr, 16);
 					if (*lenptr == ',' && 
 *dataptr == ':') {
 						if (input_buffer[0] 
 == 'M') {
-							hex2mem(addr

, dataptr + 1, len);

arch/cris/arch-v32/kernel/kgdb.c +1 -0
+							hex2bin(addr

, dataptr + 1, len);

arch/cris/arch-v32/kernel/kgdb.c +0 -0
 						} else /* X */ {
 							bin2mem(addr

, dataptr + 1, len);
}

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#3 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

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.

No one is interested in this?

Hm, dunno why, but obviously I've missed these patches, and I can't find them on my main mailaccount either.

Anyways, I found them on a secondary account, and have added them to the CRIS linux-next tree.

Thanks!

/^JN - Jesper Nilsson

Signature · 1 line
               Jesper Nilsson -- [email protected]
#4 lore raw
Quoted 9 lines · Jesper Nilsson
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

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.

Quoted 7 lines
Quoted 1 line

No one is interested in this?

Hm, dunno why, but obviously I've missed these patches, and I can't find them on my main mailaccount either.

Anyways, I found them on a secondary account, and have added them to the CRIS linux-next tree.

Just noticed that it was along time ago and currently it might produce compile warnings or errors since now hex2bin is prefixed by __must_check.

Would you like me to send v2?

Quoted 4 lines

Thanks!

/^JN - Jesper Nilsson

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#5 lore raw
Quoted 15 lines · Andy Shevchenko
Quoted 14 lines · Jesper Nilsson
Quoted 9 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

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.

No one is interested in this?

Hm, dunno why, but obviously I've missed these patches, and I can't find them on my main mailaccount either.

Quoted 8 lines
Quoted 2 lines

Anyways, I found them on a secondary account, and have added them to the CRIS linux-next tree.

Just noticed that it was along time ago and currently it might produce compile warnings or errors since now hex2bin is prefixed by __must_check.

Would you like me to send v2?

Unless you've tweaked them more since you sent them, it shouldn't be necessary, the patches applied cleanly. Those (most) files in CRIS are not touched very often... :-)

Quoted 1 line

Andy Shevchenko <[email protected]>

/^JN - Jesper Nilsson
--
Jesper Nilsson -- jesper_at_jni.nu

#6 lore raw
Quoted 23 lines · Jesper Nilsson
Quoted 22 lines · Andy Shevchenko
Quoted 9 lines · Jesper Nilsson
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

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.

Quoted 7 lines
Quoted 1 line

No one is interested in this?

Hm, dunno why, but obviously I've missed these patches, and I can't find them on my main mailaccount either.

Anyways, I found them on a secondary account, and have added them to the CRIS linux-next tree.

Just noticed that it was along time ago and currently it might produce compile warnings or errors since now hex2bin is prefixed by __must_check.

Quoted 5 lines
Quoted 1 line

Would you like me to send v2?

Unless you've tweaked them more since you sent them, it shouldn't be necessary, the patches applied cleanly. Those (most) files in CRIS are not touched very often... :-)

... and now I saw your v2, I'll take that instead since you already fixed the __must_check problems.

Thanks a lot!

Quoted 1 line
Quoted 1 line

Andy Shevchenko <[email protected]>

/^JN - Jesper Nilsson

Signature · 1 line
               Jesper Nilsson -- [email protected]