gdb/stubs/sparc-stub.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /****************************************************************************

  2.                 THIS SOFTWARE IS NOT COPYRIGHTED

  3.    HP offers the following for use in the public domain.  HP makes no
  4.    warranty with regard to the software or it's performance and the
  5.    user accepts the software "AS IS" with all faults.

  6.    HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
  7.    TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  8.    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

  9. ****************************************************************************/

  10. /****************************************************************************
  11. *  Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $
  12. *
  13. *  Module name: remcom.c $
  14. *  Revision: 1.34 $
  15. *  Date: 91/03/09 12:29:49 $
  16. *  Contributor:     Lake Stevens Instrument Division$
  17. *
  18. *  Description:     low level support for gdb debugger. $
  19. *
  20. *  Considerations:  only works on target hardware $
  21. *
  22. *  Written by:      Glenn Engel $
  23. *  ModuleState:     Experimental $
  24. *
  25. *  NOTES:           See Below $
  26. *
  27. *  Modified for SPARC by Stu Grossman, Cygnus Support.
  28. *
  29. *  This code has been extensively tested on the Fujitsu SPARClite demo board.
  30. *
  31. *  To enable debugger support, two things need to happen.  One, a
  32. *  call to set_debug_traps() is necessary in order to allow any breakpoints
  33. *  or error conditions to be properly intercepted and reported to gdb.
  34. Two, a breakpoint needs to be generated to begin communication.  This
  35. *  is most easily accomplished by a call to breakpoint().  Breakpoint()
  36. *  simulates a breakpoint by executing a trap #1.
  37. *
  38. *************
  39. *
  40. *    The following gdb commands are supported:
  41. *
  42. * command          function                               Return value
  43. *
  44. *    g             return the value of the CPU registers  hex data or ENN
  45. *    G             set the value of the CPU registers     OK or ENN
  46. *
  47. *    mAA..AA,LLLL  Read LLLL bytes at address AA..AA      hex data or ENN
  48. *    MAA..AA,LLLL: Write LLLL bytes at address AA.AA      OK or ENN
  49. *
  50. *    c             Resume at current address              SNN   ( signal NN)
  51. *    cAA..AA       Continue at address AA..AA             SNN
  52. *
  53. *    s             Step one instruction                   SNN
  54. *    sAA..AA       Step one instruction from AA..AA       SNN
  55. *
  56. *    k             kill
  57. *
  58. *    ?             What was the last sigval ?             SNN   (signal NN)
  59. *
  60. * All commands and responses are sent with a packet which includes a
  61. * checksum.  A packet consists of
  62. *
  63. * $<packet info>#<checksum>.
  64. *
  65. * where
  66. * <packet info> :: <characters representing the command or response>
  67. * <checksum>    :: < two hex digits computed as modulo 256 sum of <packetinfo>>
  68. *
  69. * When a packet is received, it is first acknowledged with either '+' or '-'.
  70. * '+' indicates a successful transfer.  '-' indicates a failed transfer.
  71. *
  72. * Example:
  73. *
  74. * Host:                  Reply:
  75. * $m0,10#2a               +$00010203040506070809101112131415#42
  76. *
  77. ****************************************************************************/

  78. #include <string.h>
  79. #include <signal.h>

  80. /************************************************************************
  81. *
  82. * external low-level support routines
  83. */

  84. extern void putDebugChar();        /* write a single character      */
  85. extern int getDebugChar();        /* read and return a single char */

  86. /************************************************************************/
  87. /* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/
  88. /* at least NUMREGBYTES*2 are needed for register packets */
  89. #define BUFMAX 2048

  90. static int initialized = 0;        /* !0 means we've been initialized */

  91. static void set_mem_fault_trap();

  92. static const char hexchars[]="0123456789abcdef";

  93. #define NUMREGS 72

  94. /* Number of bytes of registers.  */
  95. #define NUMREGBYTES (NUMREGS * 4)
  96. enum regnames {G0, G1, G2, G3, G4, G5, G6, G7,
  97.                  O0, O1, O2, O3, O4, O5, SP, O7,
  98.                  L0, L1, L2, L3, L4, L5, L6, L7,
  99.                  I0, I1, I2, I3, I4, I5, FP, I7,

  100.                  F0, F1, F2, F3, F4, F5, F6, F7,
  101.                  F8, F9, F10, F11, F12, F13, F14, F15,
  102.                  F16, F17, F18, F19, F20, F21, F22, F23,
  103.                  F24, F25, F26, F27, F28, F29, F30, F31,
  104.                  Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR };

  105. /***************************  ASSEMBLY CODE MACROS *************************/
  106. /*                                                                            */

  107. extern void trap_low();

  108. asm("
  109.         .reserve trapstack, 1000 * 4, \"bss\", 8

  110.         .data
  111.         .align        4

  112. in_trap_handler:
  113.         .word        0

  114.         .text
  115.         .align 4

  116. ! This function is called when any SPARC trap (except window overflow or
  117. ! underflow) occurs.  It makes sure that the invalid register window is still
  118. ! available before jumping into C code.  It will also restore the world if you
  119. ! return from handle_exception.

  120.         .globl _trap_low
  121. _trap_low:
  122.         mov        %psr, %l0
  123.         mov        %wim, %l3

  124.         srl        %l3, %l0, %l4                ! wim >> cwp
  125.         cmp        %l4, 1
  126.         bne        window_fine                ! Branch if not in the invalid window
  127.         nop

  128. ! Handle window overflow

  129.         mov        %g1, %l4                ! Save g1, we use it to hold the wim
  130.         srl        %l3, 1, %g1                ! Rotate wim right
  131.         tst        %g1
  132.         bg        good_wim                ! Branch if new wim is non-zero
  133.         nop

  134. ! At this point, we need to bring a 1 into the high order bit of the wim.
  135. ! Since we don't want to make any assumptions about the number of register
  136. ! windows, we figure it out dynamically so as to setup the wim correctly.

  137.         not        %g1                        ! Fill g1 with ones
  138.         mov        %g1, %wim                ! Fill the wim with ones
  139.         nop
  140.         nop
  141.         nop
  142.         mov        %wim, %g1                ! Read back the wim
  143.         inc        %g1                        ! Now g1 has 1 just to left of wim
  144.         srl        %g1, 1, %g1                ! Now put 1 at top of wim
  145.         mov        %g0, %wim                ! Clear wim so that subsequent save
  146.         nop                                !  won't trap
  147.         nop
  148.         nop

  149. good_wim:
  150.         save        %g0, %g0, %g0                ! Slip into next window
  151.         mov        %g1, %wim                ! Install the new wim

  152.         std        %l0, [%sp + 0 * 4]        ! save L & I registers
  153.         std        %l2, [%sp + 2 * 4]
  154.         std        %l4, [%sp + 4 * 4]
  155.         std        %l6, [%sp + 6 * 4]

  156.         std        %i0, [%sp + 8 * 4]
  157.         std        %i2, [%sp + 10 * 4]
  158.         std        %i4, [%sp + 12 * 4]
  159.         std        %i6, [%sp + 14 * 4]

  160.         restore                                ! Go back to trap window.
  161.         mov        %l4, %g1                ! Restore %g1

  162. window_fine:
  163.         sethi        %hi(in_trap_handler), %l4
  164.         ld        [%lo(in_trap_handler) + %l4], %l5
  165.         tst        %l5
  166.         bg        recursive_trap
  167.         inc        %l5

  168.         set        trapstack+1000*4, %sp        ! Switch to trap stack

  169. recursive_trap:
  170.         st        %l5, [%lo(in_trap_handler) + %l4]
  171.         sub        %sp,(16+1+6+1+72)*4,%sp        ! Make room for input & locals
  172.                                          ! + hidden arg + arg spill
  173.                                         ! + doubleword alignment
  174.                                         ! + registers[72] local var

  175.         std        %g0, [%sp + (24 + 0) * 4] ! registers[Gx]
  176.         std        %g2, [%sp + (24 + 2) * 4]
  177.         std        %g4, [%sp + (24 + 4) * 4]
  178.         std        %g6, [%sp + (24 + 6) * 4]

  179.         std        %i0, [%sp + (24 + 8) * 4] ! registers[Ox]
  180.         std        %i2, [%sp + (24 + 10) * 4]
  181.         std        %i4, [%sp + (24 + 12) * 4]
  182.         std        %i6, [%sp + (24 + 14) * 4]
  183.                                         ! F0->F31 not implemented
  184.         mov        %y, %l4
  185.         mov        %tbr, %l5
  186.         st        %l4, [%sp + (24 + 64) * 4] ! Y
  187.         st        %l0, [%sp + (24 + 65) * 4] ! PSR
  188.         st        %l3, [%sp + (24 + 66) * 4] ! WIM
  189.         st        %l5, [%sp + (24 + 67) * 4] ! TBR
  190.         st        %l1, [%sp + (24 + 68) * 4] ! PC
  191.         st        %l2, [%sp + (24 + 69) * 4] ! NPC

  192.                                         ! CPSR and FPSR not impl

  193.         or        %l0, 0xf20, %l4
  194.         mov        %l4, %psr                ! Turn on traps, disable interrupts

  195.         call        _handle_exception
  196.         add        %sp, 24 * 4, %o0        ! Pass address of registers

  197. ! Reload all of the registers that aren't on the stack

  198.         ld        [%sp + (24 + 1) * 4], %g1 ! registers[Gx]
  199.         ldd        [%sp + (24 + 2) * 4], %g2
  200.         ldd        [%sp + (24 + 4) * 4], %g4
  201.         ldd        [%sp + (24 + 6) * 4], %g6

  202.         ldd        [%sp + (24 + 8) * 4], %i0 ! registers[Ox]
  203.         ldd        [%sp + (24 + 10) * 4], %i2
  204.         ldd        [%sp + (24 + 12) * 4], %i4
  205.         ldd        [%sp + (24 + 14) * 4], %i6

  206.         ldd        [%sp + (24 + 64) * 4], %l0 ! Y & PSR
  207.         ldd        [%sp + (24 + 68) * 4], %l2 ! PC & NPC

  208.         restore                                ! Ensure that previous window is valid
  209.         save        %g0, %g0, %g0                !  by causing a window_underflow trap

  210.         mov        %l0, %y
  211.         mov        %l1, %psr                ! Make sure that traps are disabled
  212.                                         ! for rett

  213.         sethi        %hi(in_trap_handler), %l4
  214.         ld        [%lo(in_trap_handler) + %l4], %l5
  215.         dec        %l5
  216.         st        %l5, [%lo(in_trap_handler) + %l4]

  217.         jmpl        %l2, %g0                ! Restore old PC
  218.         rett        %l3                        ! Restore old nPC
  219. ");

  220. /* Convert ch from a hex digit to an int */

  221. static int
  222. hex (unsigned char ch)
  223. {
  224.   if (ch >= 'a' && ch <= 'f')
  225.     return ch-'a'+10;
  226.   if (ch >= '0' && ch <= '9')
  227.     return ch-'0';
  228.   if (ch >= 'A' && ch <= 'F')
  229.     return ch-'A'+10;
  230.   return -1;
  231. }

  232. static char remcomInBuffer[BUFMAX];
  233. static char remcomOutBuffer[BUFMAX];

  234. /* scan for the sequence $<data>#<checksum>     */

  235. unsigned char *
  236. getpacket (void)
  237. {
  238.   unsigned char *buffer = &remcomInBuffer[0];
  239.   unsigned char checksum;
  240.   unsigned char xmitcsum;
  241.   int count;
  242.   char ch;

  243.   while (1)
  244.     {
  245.       /* wait around for the start character, ignore all other characters */
  246.       while ((ch = getDebugChar ()) != '$')
  247.         ;

  248. retry:
  249.       checksum = 0;
  250.       xmitcsum = -1;
  251.       count = 0;

  252.       /* now, read until a # or end of buffer is found */
  253.       while (count < BUFMAX - 1)
  254.         {
  255.           ch = getDebugChar ();
  256.           if (ch == '$')
  257.             goto retry;
  258.           if (ch == '#')
  259.             break;
  260.           checksum = checksum + ch;
  261.           buffer[count] = ch;
  262.           count = count + 1;
  263.         }
  264.       buffer[count] = 0;

  265.       if (ch == '#')
  266.         {
  267.           ch = getDebugChar ();
  268.           xmitcsum = hex (ch) << 4;
  269.           ch = getDebugChar ();
  270.           xmitcsum += hex (ch);

  271.           if (checksum != xmitcsum)
  272.             {
  273.               putDebugChar ('-');        /* failed checksum */
  274.             }
  275.           else
  276.             {
  277.               putDebugChar ('+');        /* successful transfer */

  278.               /* if a sequence char is present, reply the sequence ID */
  279.               if (buffer[2] == ':')
  280.                 {
  281.                   putDebugChar (buffer[0]);
  282.                   putDebugChar (buffer[1]);

  283.                   return &buffer[3];
  284.                 }

  285.               return &buffer[0];
  286.             }
  287.         }
  288.     }
  289. }

  290. /* send the packet in buffer.  */

  291. static void
  292. putpacket (unsigned char *buffer)
  293. {
  294.   unsigned char checksum;
  295.   int count;
  296.   unsigned char ch;

  297.   /*  $<packet info>#<checksum>. */
  298.   do
  299.     {
  300.       putDebugChar('$');
  301.       checksum = 0;
  302.       count = 0;

  303.       while (ch = buffer[count])
  304.         {
  305.           putDebugChar(ch);
  306.           checksum += ch;
  307.           count += 1;
  308.         }

  309.       putDebugChar('#');
  310.       putDebugChar(hexchars[checksum >> 4]);
  311.       putDebugChar(hexchars[checksum & 0xf]);

  312.     }
  313.   while (getDebugChar() != '+');
  314. }

  315. /* Indicate to caller of mem2hex or hex2mem that there has been an
  316.    error.  */
  317. static volatile int mem_err = 0;

  318. /* Convert the memory pointed to by mem into hex, placing result in buf.
  319. * Return a pointer to the last char put in buf (null), in case of mem fault,
  320. * return 0.
  321. * If MAY_FAULT is non-zero, then we will handle memory faults by returning
  322. * a 0, else treat a fault like any other fault in the stub.
  323. */

  324. static unsigned char *
  325. mem2hex (unsigned char *mem, unsigned char *buf, int count, int may_fault)
  326. {
  327.   unsigned char ch;

  328.   set_mem_fault_trap(may_fault);

  329.   while (count-- > 0)
  330.     {
  331.       ch = *mem++;
  332.       if (mem_err)
  333.         return 0;
  334.       *buf++ = hexchars[ch >> 4];
  335.       *buf++ = hexchars[ch & 0xf];
  336.     }

  337.   *buf = 0;

  338.   set_mem_fault_trap(0);

  339.   return buf;
  340. }

  341. /* convert the hex array pointed to by buf into binary to be placed in mem
  342. * return a pointer to the character AFTER the last byte written */

  343. static char *
  344. hex2mem (unsigned char *buf, unsigned char *mem, int count, int may_fault)
  345. {
  346.   int i;
  347.   unsigned char ch;

  348.   set_mem_fault_trap(may_fault);

  349.   for (i=0; i<count; i++)
  350.     {
  351.       ch = hex(*buf++) << 4;
  352.       ch |= hex(*buf++);
  353.       *mem++ = ch;
  354.       if (mem_err)
  355.         return 0;
  356.     }

  357.   set_mem_fault_trap(0);

  358.   return mem;
  359. }

  360. /* This table contains the mapping between SPARC hardware trap types, and
  361.    signals, which are primarily what GDB understands.  It also indicates
  362.    which hardware traps we need to commandeer when initializing the stub. */

  363. static struct hard_trap_info
  364. {
  365.   unsigned char tt;                /* Trap type code for SPARClite */
  366.   unsigned char signo;                /* Signal that we map this trap into */
  367. } hard_trap_info[] = {
  368.   {1, SIGSEGV},                        /* instruction access error */
  369.   {2, SIGILL},                        /* privileged instruction */
  370.   {3, SIGILL},                        /* illegal instruction */
  371.   {4, SIGEMT},                        /* fp disabled */
  372.   {36, SIGEMT},                        /* cp disabled */
  373.   {7, SIGBUS},                        /* mem address not aligned */
  374.   {9, SIGSEGV},                        /* data access exception */
  375.   {10, SIGEMT},                        /* tag overflow */
  376.   {128+1, SIGTRAP},                /* ta 1 - normal breakpoint instruction */
  377.   {0, 0}                        /* Must be last */
  378. };

  379. /* Set up exception handlers for tracing and breakpoints */

  380. void
  381. set_debug_traps (void)
  382. {
  383.   struct hard_trap_info *ht;

  384.   for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
  385.     exceptionHandler(ht->tt, trap_low);

  386.   initialized = 1;
  387. }

  388. asm ("
  389. ! Trap handler for memory errors.  This just sets mem_err to be non-zero.  It
  390. ! assumes that %l1 is non-zero.  This should be safe, as it is doubtful that
  391. ! 0 would ever contain code that could mem fault.  This routine will skip
  392. ! past the faulting instruction after setting mem_err.

  393.         .text
  394.         .align 4

  395. _fltr_set_mem_err:
  396.         sethi %hi(_mem_err), %l0
  397.         st %l1, [%l0 + %lo(_mem_err)]
  398.         jmpl %l2, %g0
  399.         rett %l2+4
  400. ");

  401. static void
  402. set_mem_fault_trap (int enable)
  403. {
  404.   extern void fltr_set_mem_err();
  405.   mem_err = 0;

  406.   if (enable)
  407.     exceptionHandler(9, fltr_set_mem_err);
  408.   else
  409.     exceptionHandler(9, trap_low);
  410. }

  411. /* Convert the SPARC hardware trap type code to a unix signal number. */

  412. static int
  413. computeSignal (int tt)
  414. {
  415.   struct hard_trap_info *ht;

  416.   for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
  417.     if (ht->tt == tt)
  418.       return ht->signo;

  419.   return SIGHUP;                /* default for things we don't know about */
  420. }

  421. /*
  422. * While we find nice hex chars, build an int.
  423. * Return number of chars processed.
  424. */

  425. static int
  426. hexToInt(char **ptr, int *intValue)
  427. {
  428.   int numChars = 0;
  429.   int hexValue;

  430.   *intValue = 0;

  431.   while (**ptr)
  432.     {
  433.       hexValue = hex(**ptr);
  434.       if (hexValue < 0)
  435.         break;

  436.       *intValue = (*intValue << 4) | hexValue;
  437.       numChars ++;

  438.       (*ptr)++;
  439.     }

  440.   return (numChars);
  441. }

  442. /*
  443. * This function does all command procesing for interfacing to gdb.  It
  444. * returns 1 if you should skip the instruction at the trap address, 0
  445. * otherwise.
  446. */

  447. extern void breakinst();

  448. static void
  449. handle_exception (unsigned long *registers)
  450. {
  451.   int tt;                        /* Trap type */
  452.   int sigval;
  453.   int addr;
  454.   int length;
  455.   char *ptr;
  456.   unsigned long *sp;

  457. /* First, we must force all of the windows to be spilled out */

  458.   asm("        save %sp, -64, %sp
  459.         save %sp, -64, %sp
  460.         save %sp, -64, %sp
  461.         save %sp, -64, %sp
  462.         save %sp, -64, %sp
  463.         save %sp, -64, %sp
  464.         save %sp, -64, %sp
  465.         save %sp, -64, %sp
  466.         restore
  467.         restore
  468.         restore
  469.         restore
  470.         restore
  471.         restore
  472.         restore
  473.         restore
  474. ");

  475.   if (registers[PC] == (unsigned long)breakinst)
  476.     {
  477.       registers[PC] = registers[NPC];
  478.       registers[NPC] += 4;
  479.     }

  480.   sp = (unsigned long *)registers[SP];

  481.   tt = (registers[TBR] >> 4) & 0xff;

  482.   /* reply to host that an exception has occurred */
  483.   sigval = computeSignal(tt);
  484.   ptr = remcomOutBuffer;

  485.   *ptr++ = 'T';
  486.   *ptr++ = hexchars[sigval >> 4];
  487.   *ptr++ = hexchars[sigval & 0xf];

  488.   *ptr++ = hexchars[PC >> 4];
  489.   *ptr++ = hexchars[PC & 0xf];
  490.   *ptr++ = ':';
  491.   ptr = mem2hex((char *)&registers[PC], ptr, 4, 0);
  492.   *ptr++ = ';';

  493.   *ptr++ = hexchars[FP >> 4];
  494.   *ptr++ = hexchars[FP & 0xf];
  495.   *ptr++ = ':';
  496.   ptr = mem2hex(sp + 8 + 6, ptr, 4, 0); /* FP */
  497.   *ptr++ = ';';

  498.   *ptr++ = hexchars[SP >> 4];
  499.   *ptr++ = hexchars[SP & 0xf];
  500.   *ptr++ = ':';
  501.   ptr = mem2hex((char *)&sp, ptr, 4, 0);
  502.   *ptr++ = ';';

  503.   *ptr++ = hexchars[NPC >> 4];
  504.   *ptr++ = hexchars[NPC & 0xf];
  505.   *ptr++ = ':';
  506.   ptr = mem2hex((char *)&registers[NPC], ptr, 4, 0);
  507.   *ptr++ = ';';

  508.   *ptr++ = hexchars[O7 >> 4];
  509.   *ptr++ = hexchars[O7 & 0xf];
  510.   *ptr++ = ':';
  511.   ptr = mem2hex((char *)&registers[O7], ptr, 4, 0);
  512.   *ptr++ = ';';

  513.   *ptr++ = 0;

  514.   putpacket(remcomOutBuffer);

  515.   while (1)
  516.     {
  517.       remcomOutBuffer[0] = 0;

  518.       ptr = getpacket();
  519.       switch (*ptr++)
  520.         {
  521.         case '?':
  522.           remcomOutBuffer[0] = 'S';
  523.           remcomOutBuffer[1] = hexchars[sigval >> 4];
  524.           remcomOutBuffer[2] = hexchars[sigval & 0xf];
  525.           remcomOutBuffer[3] = 0;
  526.           break;

  527.         case 'd':                /* toggle debug flag */
  528.           break;

  529.         case 'g':                /* return the value of the CPU registers */
  530.           {
  531.             ptr = remcomOutBuffer;
  532.             ptr = mem2hex((char *)registers, ptr, 16 * 4, 0); /* G & O regs */
  533.             ptr = mem2hex(sp + 0, ptr, 16 * 4, 0); /* L & I regs */
  534.             memset(ptr, '0', 32 * 8); /* Floating point */
  535.             mem2hex((char *)&registers[Y],
  536.                     ptr + 32 * 4 * 2,
  537.                     8 * 4,
  538.                     0);                /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */
  539.           }
  540.           break;

  541.         case 'G':           /* set the value of the CPU registers - return OK */
  542.           {
  543.             unsigned long *newsp, psr;

  544.             psr = registers[PSR];

  545.             hex2mem(ptr, (char *)registers, 16 * 4, 0); /* G & O regs */
  546.             hex2mem(ptr + 16 * 4 * 2, sp + 0, 16 * 4, 0); /* L & I regs */
  547.             hex2mem(ptr + 64 * 4 * 2, (char *)&registers[Y],
  548.                     8 * 4, 0);        /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */

  549.             /* See if the stack pointer has moved.  If so, then copy the saved
  550.                locals and ins to the new location.  This keeps the window
  551.                overflow and underflow routines happy.  */

  552.             newsp = (unsigned long *)registers[SP];
  553.             if (sp != newsp)
  554.               sp = memcpy(newsp, sp, 16 * 4);

  555.             /* Don't allow CWP to be modified. */

  556.             if (psr != registers[PSR])
  557.               registers[PSR] = (psr & 0x1f) | (registers[PSR] & ~0x1f);

  558.             strcpy(remcomOutBuffer,"OK");
  559.           }
  560.           break;

  561.         case 'm':          /* mAA..AA,LLLL  Read LLLL bytes at address AA..AA */
  562.           /* Try to read %x,%x.  */

  563.           if (hexToInt(&ptr, &addr)
  564.               && *ptr++ == ','
  565.               && hexToInt(&ptr, &length))
  566.             {
  567.               if (mem2hex((char *)addr, remcomOutBuffer, length, 1))
  568.                 break;

  569.               strcpy (remcomOutBuffer, "E03");
  570.             }
  571.           else
  572.             strcpy(remcomOutBuffer,"E01");
  573.           break;

  574.         case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
  575.           /* Try to read '%x,%x:'.  */

  576.           if (hexToInt(&ptr, &addr)
  577.               && *ptr++ == ','
  578.               && hexToInt(&ptr, &length)
  579.               && *ptr++ == ':')
  580.             {
  581.               if (hex2mem(ptr, (char *)addr, length, 1))
  582.                 strcpy(remcomOutBuffer, "OK");
  583.               else
  584.                 strcpy(remcomOutBuffer, "E03");
  585.             }
  586.           else
  587.             strcpy(remcomOutBuffer, "E02");
  588.           break;

  589.         case 'c':    /* cAA..AA    Continue at address AA..AA(optional) */
  590.           /* try to read optional parameter, pc unchanged if no parm */

  591.           if (hexToInt(&ptr, &addr))
  592.             {
  593.               registers[PC] = addr;
  594.               registers[NPC] = addr + 4;
  595.             }

  596. /* Need to flush the instruction cache here, as we may have deposited a
  597.    breakpoint, and the icache probably has no way of knowing that a data ref to
  598.    some location may have changed something that is in the instruction cache.
  599. */

  600.           flush_i_cache();
  601.           return;

  602.           /* kill the program */
  603.         case 'k' :                /* do nothing */
  604.           break;
  605. #if 0
  606.         case 't':                /* Test feature */
  607.           asm (" std %f30,[%sp]");
  608.           break;
  609. #endif
  610.         case 'r':                /* Reset */
  611.           asm ("call 0
  612.                 nop ");
  613.           break;
  614.         }                        /* switch */

  615.       /* reply to the request */
  616.       putpacket(remcomOutBuffer);
  617.     }
  618. }

  619. /* This function will generate a breakpoint exception.  It is used at the
  620.    beginning of a program to sync up with a debugger and can be used
  621.    otherwise as a quick means to stop program execution and "break" into
  622.    the debugger. */

  623. void
  624. breakpoint (void)
  625. {
  626.   if (!initialized)
  627.     return;

  628.   asm("        .globl _breakinst

  629.         _breakinst: ta 1
  630.       ");
  631. }