From 22fa5832042e6e79d8ecc8a26273c65664bb3b84 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 28 Oct 1998 19:41:06 +0000 Subject: Patch from Ian Lance Taylor : The RTEMS i386 stub in c/src/lib/libbsp/i386/shared/comm/i386-stub.c doesn't take advantage of some of the newer gdb remote features which permits shorter and fewer packets. Here is a patch which uses the 'T' response to report the registers which gdb generally needs, and implements the 'P' request to set only a single register. The general effect is to avoid sending all the register contents back and forth between gdb and the stub every time the stub stops. This also implements the 'D' request which handles the gdb detach command, so you can cleanly quit out of the debugger and leave the target board running. --- c/src/lib/libbsp/i386/shared/comm/i386-stub.c | 68 +++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/c/src/lib/libbsp/i386/shared/comm/i386-stub.c b/c/src/lib/libbsp/i386/shared/comm/i386-stub.c index d4fd60ad9b..8764d7b27a 100644 --- a/c/src/lib/libbsp/i386/shared/comm/i386-stub.c +++ b/c/src/lib/libbsp/i386/shared/comm/i386-stub.c @@ -124,8 +124,15 @@ void waitabit (); static const char hexchars[] = "0123456789abcdef"; +/* Number of registers. */ +#define NUMREGS 16 + +/* Number of bytes per register. */ +#define REGBYTES 4 + /* Number of bytes of registers. */ -#define NUMREGBYTES 64 +#define NUMREGBYTES (NUMREGS * REGBYTES) + enum regnames { EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, @@ -137,7 +144,7 @@ enum regnames /* * these should not be static cuz they can be used outside this module */ -int registers[NUMREGBYTES / 4]; +int registers[NUMREGS]; #define STACKSIZE 10000 int remcomStack[STACKSIZE / sizeof (int)]; @@ -741,7 +748,7 @@ void handle_exception (int exceptionVector) { int sigval; - int addr, length; + int addr, length, reg; char *ptr; int newPC; @@ -753,12 +760,33 @@ handle_exception (int exceptionVector) registers[PS], registers[PC]); - /* reply to host that an exception has occurred */ + /* Reply to host that an exception has occurred. Always return the + PC, SP, and FP, since gdb always wants them. */ + ptr = remcomOutBuffer; + *ptr++ = 'T'; sigval = computeSignal (exceptionVector); - remcomOutBuffer[0] = 'S'; - remcomOutBuffer[1] = hexchars[sigval >> 4]; - remcomOutBuffer[2] = hexchars[sigval % 16]; - remcomOutBuffer[3] = 0; + *ptr++ = hexchars[sigval >> 4]; + *ptr++ = hexchars[sigval % 16]; + + *ptr++ = hexchars[ESP]; + *ptr++ = ':'; + mem2hex ((char *) ®isters[ESP], ptr, REGBYTES, 0); + ptr += REGBYTES * 2; + *ptr++ = ';'; + + *ptr++ = hexchars[EBP]; + *ptr++ = ':'; + mem2hex ((char *) ®isters[EBP], ptr, REGBYTES, 0); + ptr += REGBYTES * 2; + *ptr++ = ';'; + + *ptr++ = hexchars[PC]; + *ptr++ = ':'; + mem2hex ((char *) ®isters[PC], ptr, REGBYTES, 0); + ptr += REGBYTES * 2; + *ptr++ = ';'; + + *ptr = '\0'; putpacket (remcomOutBuffer); @@ -786,6 +814,22 @@ handle_exception (int exceptionVector) strcpy (remcomOutBuffer, "OK"); break; + case 'P': /* Set specific register */ + ptr = &remcomInBuffer[1]; + if (hexToInt (&ptr, ®) + && *ptr++ == '=') + { + hex2mem (ptr, (char *) ®isters[reg], REGBYTES, 0); + strcpy (remcomOutBuffer, "OK"); + } + else + { + strcpy (remcomOutBuffer, "E01"); + debug_error ("malformed register set command; %s", + remcomInBuffer); + } + break; + /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ case 'm': /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */ @@ -864,6 +908,14 @@ handle_exception (int exceptionVector) break; + /* Detach. */ + case 'D': + putpacket (remcomOutBuffer); + registers[PS] &= 0xfffffeff; + _returnFromException (); /* this is a jump */ + + break; + /* kill the program */ case 'k': /* do nothing */ break; -- cgit v1.2.3