2003-10-24 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / sh-stub.c
index 56f89157219cd203ed0d2c50d46c1785f41716d6..bdd9e501b861b4ffc2c2dbe7176bf8ced4e614c9 100644 (file)
@@ -1,4 +1,4 @@
-/* sh-stub.c -- debugging stub for the Hitachi-SH.
+/* sh-stub.c -- debugging stub for the Renesas-SH.
 
  NOTE!! This code has to be compiled with optimization, otherwise the 
  function inlining which generates the exception handlers won't work.
 
  NOTE!! This code has to be compiled with optimization, otherwise the 
  function inlining which generates the exception handlers won't work.
 #include <string.h>
 #include <setjmp.h>
 
 #include <string.h>
 #include <setjmp.h>
 
-/* Hitachi SH architecture instruction encoding masks */
+/* Renesas SH architecture instruction encoding masks */
 
 #define COND_BR_MASK   0xff00
 #define UCOND_DBR_MASK 0xe000
 
 #define COND_BR_MASK   0xff00
 #define UCOND_DBR_MASK 0xe000
 #define UCOND_DISP     0x0fff
 #define UCOND_REG      0x0f00
 
 #define UCOND_DISP     0x0fff
 #define UCOND_REG      0x0f00
 
-/* Hitachi SH instruction opcodes */
+/* Renesas SH instruction opcodes */
 
 #define BF_INSTR       0x8b00
 #define BT_INSTR       0x8900
 
 #define BF_INSTR       0x8b00
 #define BT_INSTR       0x8900
 #define TRAPA_INSTR    0xc300
 #define SSTEP_INSTR    0xc3ff
 
 #define TRAPA_INSTR    0xc300
 #define SSTEP_INSTR    0xc3ff
 
-/* Hitachi SH processor register masks */
+/* Renesas SH processor register masks */
 
 #define T_BIT_MASK     0x0001
 
 
 #define T_BIT_MASK     0x0001
 
@@ -199,7 +199,7 @@ static int hex (char);
 static char *mem2hex (char *, char *, int);
 static char *hex2mem (char *, char *, int);
 static int hexToInt (char **, int *);
 static char *mem2hex (char *, char *, int);
 static char *hex2mem (char *, char *, int);
 static int hexToInt (char **, int *);
-static void getpacket (char *);
+static unsigned char *getpacket (void);
 static void putpacket (char *);
 static void handle_buserror (void);
 static int computeSignal (int exceptionVector);
 static void putpacket (char *);
 static void handle_buserror (void);
 static int computeSignal (int exceptionVector);
@@ -277,8 +277,8 @@ int registers[NUMREGBYTES / 4];
 stepData instrBuffer;
 char stepped;
 static const char hexchars[] = "0123456789abcdef";
 stepData instrBuffer;
 char stepped;
 static const char hexchars[] = "0123456789abcdef";
-char remcomInBuffer[BUFMAX];
-char remcomOutBuffer[BUFMAX];
+static char remcomInBuffer[BUFMAX];
+static char remcomOutBuffer[BUFMAX];
 
 char highhex(int  x)
 {
 
 char highhex(int  x)
 {
@@ -382,28 +382,32 @@ hexToInt (char **ptr, int *intValue)
 
 /* scan for the sequence $<data>#<checksum>     */
 
 
 /* scan for the sequence $<data>#<checksum>     */
 
-static
-void
-getpacket (char *buffer)
+char *
+getpacket (void)
 {
 {
+  unsigned char *buffer = &remcomInBuffer[0];
   unsigned char checksum;
   unsigned char xmitcsum;
   unsigned char checksum;
   unsigned char xmitcsum;
-  int i;
   int count;
   char ch;
   int count;
   char ch;
-  do
+
+  while (1)
     {
       /* wait around for the start character, ignore all other characters */
     {
       /* wait around for the start character, ignore all other characters */
-      while ((ch = getDebugChar ()) != '$');
+      while ((ch = getDebugChar ()) != '$')
+       ;
+
+retry:
       checksum = 0;
       xmitcsum = -1;
       checksum = 0;
       xmitcsum = -1;
-
       count = 0;
 
       /* now, read until a # or end of buffer is found */
       while (count < BUFMAX)
        {
          ch = getDebugChar ();
       count = 0;
 
       /* 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;
          if (ch == '#')
            break;
          checksum = checksum + ch;
@@ -414,39 +418,42 @@ getpacket (char *buffer)
 
       if (ch == '#')
        {
 
       if (ch == '#')
        {
-         xmitcsum = hex (getDebugChar ()) << 4;
-         xmitcsum += hex (getDebugChar ());
+         ch = getDebugChar ();
+         xmitcsum = hex (ch) << 4;
+         ch = getDebugChar ();
+         xmitcsum += hex (ch);
+
          if (checksum != xmitcsum)
          if (checksum != xmitcsum)
-           putDebugChar ('-'); /* failed checksum */
+           {
+             putDebugChar ('-');       /* failed checksum */
+           }
          else
            {
              putDebugChar ('+');       /* successful transfer */
          else
            {
              putDebugChar ('+');       /* successful transfer */
+
              /* if a sequence char is present, reply the sequence ID */
              if (buffer[2] == ':')
                {
                  putDebugChar (buffer[0]);
                  putDebugChar (buffer[1]);
              /* 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[3];
                }
                }
+
+             return &buffer[0];
            }
        }
     }
            }
        }
     }
-  while (checksum != xmitcsum);
-
 }
 
 
 }
 
 
-/* send the packet in buffer.  The host get's one chance to read it.
-   This routine does not wait for a positive acknowledge.  */
+/* send the packet in buffer. */
 
 static void
 
 static void
-putpacket (register char *buffer)
+putpacket (char *buffer)
 {
 {
-  register  int checksum;
-  register  int count;
+  int checksum;
+  int count;
 
   /*  $<packet info>#<checksum>. */
   do
 
   /*  $<packet info>#<checksum>. */
   do
@@ -493,7 +500,6 @@ putpacket (register char *buffer)
       putDebugChar (lowhex(checksum));
     }
   while  (getDebugChar() != '+');
       putDebugChar (lowhex(checksum));
     }
   while  (getDebugChar() != '+');
-
 }
 
 
 }
 
 
@@ -649,7 +655,7 @@ When in the monitor mode we talk a human on the serial line rather than gdb.
 void
 gdb_handle_exception (int exceptionVector)
 {
 void
 gdb_handle_exception (int exceptionVector)
 {
-  int sigval;
+  int sigval, stepping;
   int addr, length;
   char *ptr;
 
   int addr, length;
   char *ptr;
 
@@ -678,12 +684,14 @@ gdb_handle_exception (int exceptionVector)
    */
   undoSStep ();
 
    */
   undoSStep ();
 
+  stepping = 0;
+
   while (1)
     {
       remcomOutBuffer[0] = 0;
   while (1)
     {
       remcomOutBuffer[0] = 0;
-      getpacket (remcomInBuffer);
+      ptr = getpacket ();
 
 
-      switch (remcomInBuffer[0])
+      switch (*ptr++)
        {
        case '?':
          remcomOutBuffer[0] = 'S';
        {
        case '?':
          remcomOutBuffer[0] = 'S';
@@ -698,7 +706,7 @@ gdb_handle_exception (int exceptionVector)
          mem2hex ((char *) registers, remcomOutBuffer, NUMREGBYTES);
          break;
        case 'G':               /* set the value of the CPU registers - return OK */
          mem2hex ((char *) registers, remcomOutBuffer, NUMREGBYTES);
          break;
        case 'G':               /* set the value of the CPU registers - return OK */
-         hex2mem (&remcomInBuffer[1], (char *) registers, NUMREGBYTES);
+         hex2mem (ptr, (char *) registers, NUMREGBYTES);
          strcpy (remcomOutBuffer, "OK");
          break;
 
          strcpy (remcomOutBuffer, "OK");
          break;
 
@@ -708,7 +716,6 @@ gdb_handle_exception (int exceptionVector)
            {
              dofault = 0;
              /* TRY, TO READ %x,%x.  IF SUCCEED, SET PTR = 0 */
            {
              dofault = 0;
              /* TRY, TO READ %x,%x.  IF SUCCEED, SET PTR = 0 */
-             ptr = &remcomInBuffer[1];
              if (hexToInt (&ptr, &addr))
                if (*(ptr++) == ',')
                  if (hexToInt (&ptr, &length))
              if (hexToInt (&ptr, &addr))
                if (*(ptr++) == ',')
                  if (hexToInt (&ptr, &length))
@@ -733,7 +740,6 @@ gdb_handle_exception (int exceptionVector)
              dofault = 0;
 
              /* TRY, TO READ '%x,%x:'.  IF SUCCEED, SET PTR = 0 */
              dofault = 0;
 
              /* TRY, TO READ '%x,%x:'.  IF SUCCEED, SET PTR = 0 */
-             ptr = &remcomInBuffer[1];
              if (hexToInt (&ptr, &addr))
                if (*(ptr++) == ',')
                  if (hexToInt (&ptr, &length))
              if (hexToInt (&ptr, &addr))
                if (*(ptr++) == ',')
                  if (hexToInt (&ptr, &length))
@@ -755,15 +761,15 @@ gdb_handle_exception (int exceptionVector)
 
          /* cAA..AA    Continue at address AA..AA(optional) */
          /* sAA..AA   Step one instruction from AA..AA(optional) */
 
          /* cAA..AA    Continue at address AA..AA(optional) */
          /* sAA..AA   Step one instruction from AA..AA(optional) */
-       case 'c':
        case 's':
        case 's':
+         stepping = 1;
+       case 'c':
          {
            /* tRY, to read optional parameter, pc unchanged if no parm */
          {
            /* tRY, to read optional parameter, pc unchanged if no parm */
-           ptr = &remcomInBuffer[1];
            if (hexToInt (&ptr, &addr))
              registers[PC] = addr;
 
            if (hexToInt (&ptr, &addr))
              registers[PC] = addr;
 
-           if (remcomInBuffer[0] == 's')
+           if (stepping)
              doSStep ();
          }
          return;
              doSStep ();
          }
          return;
@@ -796,7 +802,7 @@ void handle_exception(int exceptionVector)
 }
 
 void
 }
 
 void
-gdb_mode()
+gdb_mode (void)
 {
   ingdbmode = GDBCOOKIE;
   breakpoint();
 {
   ingdbmode = GDBCOOKIE;
   breakpoint();
@@ -818,7 +824,7 @@ breakpoint (void)
 
 /* Note:
 
 
 /* Note:
 
-   The Hitachi SH family uses two exception architectures:
+   The Renesas SH family uses two exception architectures:
 
    SH1 & SH2:
 
 
    SH1 & SH2:
 
@@ -1318,7 +1324,7 @@ static __inline__ void code_for_catch_exception(int n)
 
 
 static  void
 
 
 static  void
-exceptions()
+exceptions (void)
 {
   code_for_catch_exception (CPU_BUS_ERROR_VEC);
   code_for_catch_exception (DMA_BUS_ERROR_VEC);
 {
   code_for_catch_exception (CPU_BUS_ERROR_VEC);
   code_for_catch_exception (DMA_BUS_ERROR_VEC);
@@ -1486,12 +1492,12 @@ exceptions()
 void handleError (char theSSR);
 
 void
 void handleError (char theSSR);
 
 void
-nop ()
+nop (void)
 {
 
 }
 void 
 {
 
 }
 void 
-init_serial()
+init_serial (void)
 {
   int i;
 
 {
   int i;
 
@@ -1550,7 +1556,7 @@ getDebugChar (void)
 }
 
 int 
 }
 
 int 
-putDebugCharReady()
+putDebugCharReady (void)
 {
   return (SSR1 & SCI_TDRE);
 }
 {
   return (SSR1 & SCI_TDRE);
 }
This page took 0.0269 seconds and 4 git commands to generate.