gdb/microblaze-rom.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Remote debugging interface to Xilinx MicroBlaze.

  2.    Copyright (C) 2009-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "gdbcore.h"
  16. #include "target.h"
  17. #include "monitor.h"
  18. #include "serial.h"
  19. #include "regcache.h"

  20. void _initialize_picobug_rom (void);

  21. static char *picobug_inits[] =
  22. {"\r", NULL};

  23. static struct target_ops picobug_ops;
  24. static struct monitor_ops picobug_cmds;

  25. /* Picobug only supports a subset of registers from MCore.  In reality,
  26.    it doesn't support ss1, either.  */
  27. static char *picobug_regnames[] = {
  28.   "r0",   "r1",   "r2",   "r3",   "r4",   "r5",   "r6",   "r7",
  29.   "r8",   "r9",   "r10""r11""r12""r13""r14""r15",
  30.   0,      0,      0,      0,      0,      0,      0,      0,
  31.   0,      0,      0,      0,      0,      0,      0,      0,
  32.   "psr""vbr""epsr", "fpsr", "epc""fpc"0,      "ss1",
  33.   "ss2""ss3""ss4"0,      0,      0,      0,      0,
  34.   0,      0,      0,      0,      0,      0,      0,      0,
  35.   0,      0,      0,      0,      0,      0,      0,      0,
  36.   "pc" };



  37. static void
  38. picobug_open (const char *args, int from_tty)
  39. {
  40.   monitor_open (args, &picobug_cmds, from_tty);
  41. }
  42. /* We choose to write our own dumpregs routine, since the output of
  43.    the register dumping is rather difficult to encapsulate in a
  44.    regexp:

  45. picobug> rd
  46.      pc 2f00031e      epc 2f00031e      fpc 00000000
  47.     psr 80000101     epsr 80000101     fpsr 00000000
  48. ss0-ss4 bad0beef 00000000 00000000 00000000 00000000      vbr 30005c00
  49.   r0-r7 2f0fff4c 00000090 00000001 00000002 00000003 00000004 00000005 00000006
  50. r8-r15 2f0fff64 00000000 00000000 00000000 00000000 00000000 00000000 2f00031e
  51. */

  52. static int
  53. picobug_dumpregs (struct regcache *regcache)
  54. {
  55.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  56.   char buf[1024];
  57.   int resp_len;
  58.   char *p;

  59.   /* Send the dump register command to the monitor and
  60.      get the reply.  */
  61.   monitor_printf (picobug_cmds.dump_registers);
  62.   resp_len = monitor_expect_prompt (buf, sizeof (buf));

  63.   p = strtok (buf, " \t\r\n");
  64.   while (p)
  65.     {
  66.       if (strchr (p, '-'))
  67.         {
  68.           /* Got a range.  Either r0-r7, r8-r15 or ss0-ss4.  */
  69.           if (strncmp (p, "r0", 2) == 0 || strncmp (p, "r8", 2) == 0)
  70.             {
  71.               int rn = (p[1] == '0' ? 0 : 8);
  72.               int i = 0;

  73.               /* Get the next 8 values and record them.  */
  74.               while (i < 8)
  75.                 {
  76.                   p = strtok (NULL, " \t\r\n");
  77.                   if (p)
  78.                     monitor_supply_register (regcache, rn + i, p);
  79.                   i++;
  80.                 }
  81.             }
  82.           else if (strncmp (p, "ss", 2) == 0)
  83.             {
  84.               /* Get the next five values, ignoring the first.  */
  85.               int rn;
  86.               p = strtok (NULL, " \t\r\n");
  87.               for (rn = 39; rn < 43; rn++)
  88.                 {
  89.                   p = strtok (NULL, " \t\r\n");
  90.                   if (p)
  91.                     monitor_supply_register (regcache, rn, p);
  92.                 }
  93.             }
  94.           else
  95.             {
  96.               break;
  97.             }
  98.         }
  99.       else
  100.         {
  101.           /* Simple register type, paired.  */
  102.           char *name = p;
  103.           int i;

  104.           /* Get and record value.  */
  105.           p = strtok (NULL, " \t\r\n");
  106.           if (p)
  107.             {
  108.               for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
  109.                 {
  110.                   if (picobug_regnames[i]
  111.                       && strcmp (picobug_regnames[i], name) == 0)
  112.                     break;
  113.                 }

  114.               if (i <= gdbarch_num_regs (gdbarch))
  115.                 monitor_supply_register (regcache, i, p);
  116.             }
  117.         }
  118.       p = strtok (NULL, " \t\r\n");
  119.     }

  120.   return 0;
  121. }

  122. static void
  123. init_picobug_cmds (void)
  124. {
  125.   picobug_cmds.flags = MO_GETMEM_NEEDS_RANGE | MO_CLR_BREAK_USES_ADDR
  126.                        | MO_PRINT_PROGRAM_OUTPUT;

  127.   picobug_cmds.init = picobug_inits;                /* Init strings                */
  128.   picobug_cmds.cont = "g\n";                        /* continue command        */
  129.   picobug_cmds.step = "s\n";                        /* single step                */
  130.   picobug_cmds.set_break = "br %x\n";                /* set a breakpoint        */
  131.   picobug_cmds.clr_break = "nobr %x\n";                /* clear a breakpoint        */
  132.   picobug_cmds.clr_all_break = "nobr\n";        /* clear all breakpoints */
  133.   picobug_cmds.setmem.cmdb = "mm %x %x ;b\n";        /* setmem.cmdb (addr, value) */
  134.   picobug_cmds.setmem.cmdw = "mm %x %x ;h\n";        /* setmem.cmdw (addr, value) */
  135.   picobug_cmds.setmem.cmdl = "mm %x %x ;w\n";        /* setmem.cmdl (addr, value) */
  136.   picobug_cmds.getmem.cmdb = "md %x %x\n";        /* getmem.cmdb (start addr,
  137.                                                    end addr)                 */
  138.   picobug_cmds.getmem.resp_delim = ":";                /* getmem.resp_delim        */
  139.   picobug_cmds.setreg.cmd = "rm %s %x\n";        /* setreg.cmd (name, value) */
  140.   picobug_cmds.getreg.cmd = "rd %s\n";                /* getreg.cmd (name)        */
  141.   picobug_cmds.getreg.resp_delim = ":";                /* getreg.resp_delim        */
  142.   picobug_cmds.dump_registers = "rd\n";                /* dump_registers        */
  143.   picobug_cmds.dumpregs = picobug_dumpregs;        /* dump registers parser */
  144.   picobug_cmds.load = "lo\n";                        /* download command        */
  145.   picobug_cmds.prompt = "picobug> ";                /* monitor command prompt */
  146.   picobug_cmds.line_term = "\n";                /* end-of-line terminator */
  147.   picobug_cmds.target = &picobug_ops;                /* target operations        */
  148.   picobug_cmds.stopbits = SERIAL_1_STOPBITS;        /* number of stop bits        */
  149.   picobug_cmds.regnames = picobug_regnames;        /* registers names        */
  150.   picobug_cmds.num_breakpoints = 20;                /* number of breakpoints */
  151.   picobug_cmds.magic = MONITOR_OPS_MAGIC;        /* magic                */
  152. }

  153. void
  154. _initialize_picobug_rom (void)
  155. {
  156.   int i;

  157.   /* Initialize m32r RevC monitor target.  */
  158.   init_picobug_cmds ();
  159.   init_monitor_ops (&picobug_ops);
  160.   picobug_ops.to_shortname = "picobug";
  161.   picobug_ops.to_longname = "picobug monitor";
  162.   picobug_ops.to_doc = "Debug via the picobug monitor.\n\
  163. Specify the serial device it is connected to (e.g. /dev/ttya).";
  164.   picobug_ops.to_open = picobug_open;

  165.   add_target (&picobug_ops);
  166. }