diff options
author | Jason Molenda <jmolenda@apple.com> | 1999-08-31 01:14:27 +0000 |
---|---|---|
committer | Jason Molenda <jmolenda@apple.com> | 1999-08-31 01:14:27 +0000 |
commit | 104c1213b4821a4b8664e66db4643a951b461576 (patch) | |
tree | d77adb32fcf044a485e1d4e0bb58e9da0ce39671 /gdb/m32r-stub.c | |
parent | fd485a97b145f7b8abe7c5f5ec63edd8268a4182 (diff) | |
download | gdb-104c1213b4821a4b8664e66db4643a951b461576.zip gdb-104c1213b4821a4b8664e66db4643a951b461576.tar.gz gdb-104c1213b4821a4b8664e66db4643a951b461576.tar.bz2 |
import gdb-1999-08-30 snapshot
Diffstat (limited to 'gdb/m32r-stub.c')
-rw-r--r-- | gdb/m32r-stub.c | 136 |
1 files changed, 71 insertions, 65 deletions
diff --git a/gdb/m32r-stub.c b/gdb/m32r-stub.c index d4d8842..56ae5ef 100644 --- a/gdb/m32r-stub.c +++ b/gdb/m32r-stub.c @@ -179,7 +179,7 @@ extern void breakpoint(void); static int computeSignal(int); static void putpacket(unsigned char *); -static void getpacket(unsigned char *); +static unsigned char *getpacket(unsigned char *); static unsigned char *mem2hex(unsigned char *, unsigned char *, int, int); static unsigned char *hex2mem(unsigned char *, unsigned char *, int, int); @@ -204,7 +204,7 @@ static int strlen (const unsigned char *); void handle_exception(int exceptionVector) { - int sigval; + int sigval, stepping; int addr, length, i; unsigned char * ptr; unsigned char buf[16]; @@ -306,15 +306,16 @@ handle_exception(int exceptionVector) putpacket(remcomOutBuffer); + stepping = 0; + while (1==1) { remcomOutBuffer[0] = 0; - getpacket(remcomInBuffer); + ptr = getpacket(remcomInBuffer); binary = 0; - switch (remcomInBuffer[0]) { + switch (*ptr++) { default: /* Unknown code. Return an empty reply message. */ break; case 'R': - ptr = &remcomInBuffer[1]; if (hexToInt (&ptr, &addr)) registers[PC] = addr; strcpy(remcomOutBuffer, "OK"); @@ -327,7 +328,6 @@ handle_exception(int exceptionVector) case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */ { - ptr = &remcomInBuffer[1]; if (hexToInt(&ptr,&addr)) if (*(ptr++) == ',') if (hexToInt(&ptr,&length)) @@ -349,14 +349,11 @@ handle_exception(int exceptionVector) if (ptr) { strcpy(remcomOutBuffer,"E02"); - gdb_error("malformed write memory command: %s", - remcomInBuffer); } } break; case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */ - ptr = &remcomInBuffer[1]; if (hexToInt(&ptr,&addr)) if (*(ptr++) == ',') if (hexToInt(&ptr,&length)) @@ -372,8 +369,6 @@ handle_exception(int exceptionVector) if (ptr) { strcpy(remcomOutBuffer,"E01"); - gdb_error("malformed read memory command: %s", - remcomInBuffer); } break; case '?': @@ -392,7 +387,6 @@ handle_exception(int exceptionVector) { int regno; - ptr = &remcomInBuffer[1]; if (hexToInt (&ptr, ®no) && *ptr++ == '=') if (regno >= 0 && regno < NUMREGS) { @@ -435,17 +429,17 @@ handle_exception(int exceptionVector) break; } case 'G': /* set the value of the CPU registers - return OK */ - hex2mem(&remcomInBuffer[1], (unsigned char*) registers, NUMREGBYTES, 0); + hex2mem(&ptr, (unsigned char*) registers, NUMREGBYTES, 0); strcpy(remcomOutBuffer,"OK"); break; case 's': /* sAA..AA Step one instruction from AA..AA(optional) */ + stepping = 1; case 'c': /* cAA..AA Continue from address AA..AA(optional) */ /* try to read optional parameter, pc unchanged if no parm */ - ptr = &remcomInBuffer[1]; if (hexToInt(&ptr,&addr)) registers[ PC ] = addr; - if (remcomInBuffer[0] == 's') /* single-stepping */ + if (stepping) /* single-stepping */ { if (!prepare_to_step(0)) /* set up for single-step */ { @@ -505,7 +499,6 @@ handle_exception(int exceptionVector) break; #endif case 'q': - ptr = &remcomInBuffer[1]; if (*ptr++ == 'C' && *ptr++ == 'R' && *ptr++ == 'C' && @@ -581,65 +574,78 @@ hex(ch) /* scan for the sequence $<data>#<checksum> */ -static void -getpacket(buffer) - unsigned char * buffer; +unsigned char * +getpacket (buffer) + unsigned char *buffer; { unsigned char checksum; unsigned char xmitcsum; - int i; - int count; - unsigned char ch; + int count; + char ch; - do { - /* wait around for the start character, ignore all other characters */ - while ((ch = getDebugChar()) != '$'); - checksum = 0; - xmitcsum = -1; + while (1) + { + /* wait around for the start character, ignore all other characters */ + while ((ch = getDebugChar ()) != '$') + ; - count = 0; +retry: + checksum = 0; + xmitcsum = -1; + count = 0; - /* now, read until a # or end of buffer is found */ - while (count < BUFMAX) { - ch = getDebugChar(); - - if (ch == '#' && (count == 0 || buffer[count-1] != 0x7d)) - break; + /* now, read until a # or end of buffer is found */ + while (count < BUFMAX) + { + ch = getDebugChar (); + if (ch == '$') + goto retry; + if (ch == '#') + break; + checksum = checksum + ch; + buffer[count] = ch; + count = count + 1; + } + buffer[count] = 0; - checksum = checksum + ch; - buffer[count] = ch; - count = count + 1; - } - buffer[count] = 0; - - if (ch == '#') { - xmitcsum = hex(getDebugChar()) << 4; - xmitcsum += hex(getDebugChar()); - if (checksum != xmitcsum) { - if (remote_debug) { - unsigned char buf[16]; - - mem2hex((unsigned char *) &checksum, buf, 4, 0); - gdb_error("Bad checksum: my count = %s, ", buf); - mem2hex((unsigned char *) &xmitcsum, buf, 4, 0); - gdb_error("sent count = %s\n", buf); - gdb_error(" -- Bad buffer: \"%s\"\n", buffer); - } + if (ch == '#') + { + ch = getDebugChar (); + xmitcsum = hex (ch) << 4; + ch = getDebugChar (); + xmitcsum += hex (ch); + + if (checksum != xmitcsum) + { + if (remote_debug) + { + unsigned char buf[16]; + + mem2hex((unsigned char *) &checksum, buf, 4, 0); + gdb_error("Bad checksum: my count = %s, ", buf); + mem2hex((unsigned char *) &xmitcsum, buf, 4, 0); + gdb_error("sent count = %s\n", buf); + gdb_error(" -- Bad buffer: \"%s\"\n", buffer); + } + putDebugChar ('-'); /* failed checksum */ + } + else + { + putDebugChar ('+'); /* successful transfer */ + + /* if a sequence char is present, reply the sequence ID */ + if (buffer[2] == ':') + { + putDebugChar (buffer[0]); + putDebugChar (buffer[1]); + + return &buffer[3]; + } - putDebugChar('-'); /* failed checksum */ - } else { - putDebugChar('+'); /* successful transfer */ - /* if a sequence char is present, reply the sequence ID */ - if (buffer[2] == ':') { - putDebugChar( buffer[0] ); - putDebugChar( buffer[1] ); - /* remove sequence chars from buffer */ - count = strlen(buffer); - for (i=3; i <= count; i++) buffer[i-3] = buffer[i]; + return &buffer[0]; + } } - } } - } while (checksum != xmitcsum); } /* send the packet in buffer. */ |