X-Git-Url: https://git.kernelconcepts.de/?a=blobdiff_plain;f=common%2Fkgdb.c;h=d357463695f3c0cc85dd2b88ce2504a7312dd97a;hb=aac081a37e419c0d627d4ca257689dae543403ac;hp=862f3684e2afbbda0cde825d8aaaacfe97d8833a;hpb=156feb90d200f186cdfd856d7f6f1878bb1bec1e;p=karo-tx-uboot.git diff --git a/common/kgdb.c b/common/kgdb.c index 862f3684e2..d357463695 100644 --- a/common/kgdb.c +++ b/common/kgdb.c @@ -1,4 +1,4 @@ -/* taken from arch/ppc/kernel/ppc-stub.c */ +/* taken from arch/powerpc/kernel/ppc-stub.c */ /**************************************************************************** @@ -103,7 +103,7 @@ static char remcomOutBuffer[BUFMAX]; static char remcomRegBuffer[BUFMAX]; static int initialized = 0; -static int kgdb_active = 0, first_entry = 1; +static int kgdb_active; static struct pt_regs entry_regs; static long error_jmp_buf[BUFMAX/2]; static int longjmp_on_fault = 0; @@ -132,11 +132,20 @@ hex(unsigned char ch) static unsigned char * mem2hex(char *mem, char *buf, int count) { + char *tmp; unsigned char ch; + /* + * We use the upper half of buf as an intermediate buffer for the + * raw memory copy. Hex conversion will work against this one. + */ + tmp = buf + count; longjmp_on_fault = 1; + + memcpy(tmp, mem, count); + while (count-- > 0) { - ch = *mem++; + ch = *tmp++; *buf++ = hexchars[ch >> 4]; *buf++ = hexchars[ch & 0xf]; } @@ -151,21 +160,33 @@ mem2hex(char *mem, char *buf, int count) static char * hex2mem(char *buf, char *mem, int count) { - int i, hexValue; - unsigned char ch; - char *mem_start = mem; + int hexValue; + char *tmp_raw, *tmp_hex; + + /* + * We use the upper half of buf as an intermediate buffer for the + * raw memory that is converted from hex. + */ + tmp_raw = buf + count * 2; + tmp_hex = tmp_raw - 1; longjmp_on_fault = 1; - for (i=0; i= buf) { + tmp_raw--; + hexValue = hex(*tmp_hex--); + if (hexValue < 0) kgdb_error(KGDBERR_NOTHEXDIG); - ch = hexValue << 4; - if ((hexValue = hex(*buf++)) < 0) + *tmp_raw = hexValue; + hexValue = hex(*tmp_hex--); + if (hexValue < 0) kgdb_error(KGDBERR_NOTHEXDIG); - ch |= hexValue; - *mem++ = ch; + *tmp_raw |= hexValue << 4; + } - kgdb_flush_cache_range((void *)mem_start, (void *)(mem - 1)); + + memcpy(mem, tmp_raw, count); + + kgdb_flush_cache_range((void *)mem, (void *)(mem+count)); longjmp_on_fault = 0; return buf; @@ -327,16 +348,7 @@ handle_exception (struct pt_regs *regs) kgdb_enter(regs, &kd); - if (first_entry) { - /* - * the first time we enter kgdb, we save the processor - * state so that we can return to the monitor if the - * remote end quits gdb (or at least, tells us to quit - * with the 'k' packet) - */ - entry_regs = *regs; - first_entry = 0; - } + entry_regs = *regs; ptr = remcomOutBuffer; @@ -438,7 +450,6 @@ handle_exception (struct pt_regs *regs) case 'k': /* kill the program, actually return to monitor */ kd.extype = KGDBEXIT_KILL; *regs = entry_regs; - first_entry = 1; goto doexit; case 'C': /* CSS continue with signal SS */ @@ -563,7 +574,7 @@ breakpoint(void) } int -do_kgdb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +do_kgdb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { printf("Entering KGDB mode via exception handler...\n\n"); kgdb_breakpoint(argc - 1, argv + 1);