2000-03-22 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / m32r-stub.c
index d4d8842377655944ba771914d6dbb55e3b717552..9fdf4969e5a4eb7bbda499084fca308c977e01d9 100644 (file)
@@ -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(void);
 
 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();
     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, &regno) && *ptr++ == '=')
            if (regno >= 0 && regno < NUMREGS)
              {
@@ -431,21 +425,21 @@ handle_exception(int exceptionVector)
                strcpy (remcomOutBuffer, "OK");
                break;
              }
-         strcpy (remcomOutBuffer, "P01");
+         strcpy (remcomOutBuffer, "E01");
          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 ()
 {
+  unsigned char *buffer = &remcomInBuffer[0];
   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.  */
This page took 0.025683 seconds and 4 git commands to generate.