Commit 26824972 authored by Harvey Harrison's avatar Harvey Harrison Committed by Linus Torvalds

mn10300: use the common ascii hex helpers

Signed-off-by: default avatarHarvey Harrison <harvey.harrison@gmail.com>
Acked-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 19caeed6
...@@ -163,8 +163,6 @@ static char input_buffer[BUFMAX]; ...@@ -163,8 +163,6 @@ static char input_buffer[BUFMAX];
static char output_buffer[BUFMAX]; static char output_buffer[BUFMAX];
static char trans_buffer[BUFMAX]; static char trans_buffer[BUFMAX];
static const char hexchars[] = "0123456789abcdef";
struct gdbstub_bkpt { struct gdbstub_bkpt {
u8 *addr; /* address of breakpoint */ u8 *addr; /* address of breakpoint */
u8 len; /* size of breakpoint */ u8 len; /* size of breakpoint */
...@@ -363,8 +361,8 @@ static int putpacket(char *buffer) ...@@ -363,8 +361,8 @@ static int putpacket(char *buffer)
} }
gdbstub_io_tx_char('#'); gdbstub_io_tx_char('#');
gdbstub_io_tx_char(hexchars[checksum >> 4]); gdbstub_io_tx_char(hex_asc_hi(checksum));
gdbstub_io_tx_char(hexchars[checksum & 0xf]); gdbstub_io_tx_char(hex_asc_lo(checksum));
} while (gdbstub_io_rx_char(&ch, 0), } while (gdbstub_io_rx_char(&ch, 0),
ch == '-' && (gdbstub_io("### GDB Rx NAK\n"), 0), ch == '-' && (gdbstub_io("### GDB Rx NAK\n"), 0),
...@@ -822,8 +820,7 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault) ...@@ -822,8 +820,7 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault)
if ((u32) mem & 1 && count >= 1) { if ((u32) mem & 1 && count >= 1) {
if (gdbstub_read_byte(mem, ch) != 0) if (gdbstub_read_byte(mem, ch) != 0)
return 0; return 0;
*buf++ = hexchars[ch[0] >> 4]; buf = pack_hex_byte(buf, ch[0]);
*buf++ = hexchars[ch[0] & 0xf];
mem++; mem++;
count--; count--;
} }
...@@ -831,10 +828,8 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault) ...@@ -831,10 +828,8 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault)
if ((u32) mem & 3 && count >= 2) { if ((u32) mem & 3 && count >= 2) {
if (gdbstub_read_word(mem, ch) != 0) if (gdbstub_read_word(mem, ch) != 0)
return 0; return 0;
*buf++ = hexchars[ch[0] >> 4]; buf = pack_hex_byte(buf, ch[0]);
*buf++ = hexchars[ch[0] & 0xf]; buf = pack_hex_byte(buf, ch[1]);
*buf++ = hexchars[ch[1] >> 4];
*buf++ = hexchars[ch[1] & 0xf];
mem += 2; mem += 2;
count -= 2; count -= 2;
} }
...@@ -842,14 +837,10 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault) ...@@ -842,14 +837,10 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault)
while (count >= 4) { while (count >= 4) {
if (gdbstub_read_dword(mem, ch) != 0) if (gdbstub_read_dword(mem, ch) != 0)
return 0; return 0;
*buf++ = hexchars[ch[0] >> 4]; buf = pack_hex_byte(buf, ch[0]);
*buf++ = hexchars[ch[0] & 0xf]; buf = pack_hex_byte(buf, ch[1]);
*buf++ = hexchars[ch[1] >> 4]; buf = pack_hex_byte(buf, ch[2]);
*buf++ = hexchars[ch[1] & 0xf]; buf = pack_hex_byte(buf, ch[3]);
*buf++ = hexchars[ch[2] >> 4];
*buf++ = hexchars[ch[2] & 0xf];
*buf++ = hexchars[ch[3] >> 4];
*buf++ = hexchars[ch[3] & 0xf];
mem += 4; mem += 4;
count -= 4; count -= 4;
} }
...@@ -857,10 +848,8 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault) ...@@ -857,10 +848,8 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault)
if (count >= 2) { if (count >= 2) {
if (gdbstub_read_word(mem, ch) != 0) if (gdbstub_read_word(mem, ch) != 0)
return 0; return 0;
*buf++ = hexchars[ch[0] >> 4]; buf = pack_hex_byte(buf, ch[0]);
*buf++ = hexchars[ch[0] & 0xf]; buf = pack_hex_byte(buf, ch[1]);
*buf++ = hexchars[ch[1] >> 4];
*buf++ = hexchars[ch[1] & 0xf];
mem += 2; mem += 2;
count -= 2; count -= 2;
} }
...@@ -868,8 +857,7 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault) ...@@ -868,8 +857,7 @@ unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault)
if (count >= 1) { if (count >= 1) {
if (gdbstub_read_byte(mem, ch) != 0) if (gdbstub_read_byte(mem, ch) != 0)
return 0; return 0;
*buf++ = hexchars[ch[0] >> 4]; buf = pack_hex_byte(buf, ch[0]);
*buf++ = hexchars[ch[0] & 0xf];
} }
*buf = 0; *buf = 0;
...@@ -1304,14 +1292,14 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep) ...@@ -1304,14 +1292,14 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
*ptr++ = 'O'; *ptr++ = 'O';
ptr = mem2hex(title, ptr, sizeof(title) - 1, 0); ptr = mem2hex(title, ptr, sizeof(title) - 1, 0);
hx = hexchars[(excep & 0xf000) >> 12]; hx = hex_asc_hi(excep >> 8);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
hx = hexchars[(excep & 0x0f00) >> 8]; hx = hex_asc_lo(excep >> 8);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
hx = hexchars[(excep & 0x00f0) >> 4]; hx = hex_asc_hi(excep);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
hx = hexchars[(excep & 0x000f)]; hx = hex_asc_lo(excep);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
ptr = mem2hex(crlf, ptr, sizeof(crlf) - 1, 0); ptr = mem2hex(crlf, ptr, sizeof(crlf) - 1, 0);
*ptr = 0; *ptr = 0;
...@@ -1322,22 +1310,22 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep) ...@@ -1322,22 +1310,22 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
*ptr++ = 'O'; *ptr++ = 'O';
ptr = mem2hex(tbcberr, ptr, sizeof(tbcberr) - 1, 0); ptr = mem2hex(tbcberr, ptr, sizeof(tbcberr) - 1, 0);
hx = hexchars[(bcberr & 0xf0000000) >> 28]; hx = hex_asc_hi(bcberr >> 24);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
hx = hexchars[(bcberr & 0x0f000000) >> 24]; hx = hex_asc_lo(bcberr >> 24);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
hx = hexchars[(bcberr & 0x00f00000) >> 20]; hx = hex_asc_hi(bcberr >> 16);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
hx = hexchars[(bcberr & 0x000f0000) >> 16]; hx = hex_asc_lo(bcberr >> 16);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
hx = hexchars[(bcberr & 0x0000f000) >> 12]; hx = hex_asc_hi(bcberr >> 8);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
hx = hexchars[(bcberr & 0x00000f00) >> 8]; hx = hex_asc_lo(bcberr >> 8);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
hx = hexchars[(bcberr & 0x000000f0) >> 4]; hx = hex_asc_hi(bcberr);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
hx = hexchars[(bcberr & 0x0000000f)]; hx = hex_asc_lo(bcberr);
*ptr++ = hexchars[hx >> 4]; *ptr++ = hexchars[hx & 0xf]; ptr = pack_hex_byte(ptr, hx);
ptr = mem2hex(crlf, ptr, sizeof(crlf) - 1, 0); ptr = mem2hex(crlf, ptr, sizeof(crlf) - 1, 0);
*ptr = 0; *ptr = 0;
...@@ -1353,14 +1341,12 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep) ...@@ -1353,14 +1341,12 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
* Send trap type (converted to signal) * Send trap type (converted to signal)
*/ */
*ptr++ = 'T'; *ptr++ = 'T';
*ptr++ = hexchars[sigval >> 4]; ptr = pack_hex_byte(ptr, sigval);
*ptr++ = hexchars[sigval & 0xf];
/* /*
* Send Error PC * Send Error PC
*/ */
*ptr++ = hexchars[GDB_REGID_PC >> 4]; ptr = pack_hex_byte(ptr, GDB_REGID_PC);
*ptr++ = hexchars[GDB_REGID_PC & 0xf];
*ptr++ = ':'; *ptr++ = ':';
ptr = mem2hex(&regs->pc, ptr, 4, 0); ptr = mem2hex(&regs->pc, ptr, 4, 0);
*ptr++ = ';'; *ptr++ = ';';
...@@ -1368,8 +1354,7 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep) ...@@ -1368,8 +1354,7 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
/* /*
* Send frame pointer * Send frame pointer
*/ */
*ptr++ = hexchars[GDB_REGID_FP >> 4]; ptr = pack_hex_byte(ptr, GDB_REGID_FP);
*ptr++ = hexchars[GDB_REGID_FP & 0xf];
*ptr++ = ':'; *ptr++ = ':';
ptr = mem2hex(&regs->a3, ptr, 4, 0); ptr = mem2hex(&regs->a3, ptr, 4, 0);
*ptr++ = ';'; *ptr++ = ';';
...@@ -1378,8 +1363,7 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep) ...@@ -1378,8 +1363,7 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
* Send stack pointer * Send stack pointer
*/ */
ssp = (unsigned long) (regs + 1); ssp = (unsigned long) (regs + 1);
*ptr++ = hexchars[GDB_REGID_SP >> 4]; ptr = pack_hex_byte(ptr, GDB_REGID_SP);
*ptr++ = hexchars[GDB_REGID_SP & 0xf];
*ptr++ = ':'; *ptr++ = ':';
ptr = mem2hex(&ssp, ptr, 4, 0); ptr = mem2hex(&ssp, ptr, 4, 0);
*ptr++ = ';'; *ptr++ = ';';
...@@ -1399,8 +1383,8 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep) ...@@ -1399,8 +1383,8 @@ static int gdbstub(struct pt_regs *regs, enum exception_code excep)
/* request repeat of last signal number */ /* request repeat of last signal number */
case '?': case '?':
output_buffer[0] = 'S'; output_buffer[0] = 'S';
output_buffer[1] = hexchars[sigval >> 4]; output_buffer[1] = hex_asc_hi(sigval);
output_buffer[2] = hexchars[sigval & 0xf]; output_buffer[2] = hex_asc_lo(sigval);
output_buffer[3] = 0; output_buffer[3] = 0;
break; break;
...@@ -1838,8 +1822,8 @@ void gdbstub_exit(int status) ...@@ -1838,8 +1822,8 @@ void gdbstub_exit(int status)
gdbstub_busy = 1; gdbstub_busy = 1;
output_buffer[0] = 'W'; output_buffer[0] = 'W';
output_buffer[1] = hexchars[(status >> 4) & 0x0F]; output_buffer[1] = hex_asc_hi(status);
output_buffer[2] = hexchars[status & 0x0F]; output_buffer[2] = hex_asc_lo(status);
output_buffer[3] = 0; output_buffer[3] = 0;
gdbstub_io_tx_char('$'); gdbstub_io_tx_char('$');
...@@ -1853,8 +1837,8 @@ void gdbstub_exit(int status) ...@@ -1853,8 +1837,8 @@ void gdbstub_exit(int status)
} }
gdbstub_io_tx_char('#'); gdbstub_io_tx_char('#');
gdbstub_io_tx_char(hexchars[checksum >> 4]); gdbstub_io_tx_char(hex_asc_hi(checksum));
gdbstub_io_tx_char(hexchars[checksum & 0xf]); gdbstub_io_tx_char(hex_asc_lo(checksum));
/* make sure the output is flushed, or else RedBoot might clobber it */ /* make sure the output is flushed, or else RedBoot might clobber it */
gdbstub_io_tx_flush(); gdbstub_io_tx_flush();
......
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