gdb/ppcbug-rom.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Remote debugging interface for PPCbug (PowerPC) Rom monitor
  2.    for GDB, the GNU debugger.
  3.    Copyright (C) 1995-2015 Free Software Foundation, Inc.

  4.    Written by Stu Grossman of Cygnus Support

  5.    This file is part of GDB.

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

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

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

  16. #include "defs.h"
  17. #include "gdbcore.h"
  18. #include "target.h"
  19. #include "monitor.h"
  20. #include "serial.h"
  21. #include "regcache.h"

  22. static void
  23. ppcbug_supply_register (struct regcache *regcache, char *regname,
  24.                         int regnamelen, char *val, int vallen)
  25. {
  26.   int regno = 0;

  27.   if (regnamelen < 2 || regnamelen > 4)
  28.     return;

  29.   switch (regname[0])
  30.     {
  31.     case 'R':
  32.       if (regname[1] < '0' || regname[1] > '9')
  33.         return;
  34.       if (regnamelen == 2)
  35.         regno = regname[1] - '0';
  36.       else if (regnamelen == 3 && regname[2] >= '0' && regname[2] <= '9')
  37.         regno = (regname[1] - '0') * 10 + (regname[2] - '0');
  38.       else
  39.         return;
  40.       break;
  41.     case 'F':
  42.       if (regname[1] != 'R' || regname[2] < '0' || regname[2] > '9')
  43.         return;
  44.       if (regnamelen == 3)
  45.         regno = 32 + regname[2] - '0';
  46.       else if (regnamelen == 4 && regname[3] >= '0' && regname[3] <= '9')
  47.         regno = 32 + (regname[2] - '0') * 10 + (regname[3] - '0');
  48.       else
  49.         return;
  50.       break;
  51.     case 'I':
  52.       if (regnamelen != 2 || regname[1] != 'P')
  53.         return;
  54.       regno = 64;
  55.       break;
  56.     case 'M':
  57.       if (regnamelen != 3 || regname[1] != 'S' || regname[2] != 'R')
  58.         return;
  59.       regno = 65;
  60.       break;
  61.     case 'C':
  62.       if (regnamelen != 2 || regname[1] != 'R')
  63.         return;
  64.       regno = 66;
  65.       break;
  66.     case 'S':
  67.       if (regnamelen != 4 || regname[1] != 'P' || regname[2] != 'R')
  68.         return;
  69.       else if (regname[3] == '8')
  70.         regno = 67;
  71.       else if (regname[3] == '9')
  72.         regno = 68;
  73.       else if (regname[3] == '1')
  74.         regno = 69;
  75.       else if (regname[3] == '0')
  76.         regno = 70;
  77.       else
  78.         return;
  79.       break;
  80.     default:
  81.       return;
  82.     }

  83.   monitor_supply_register (regcache, regno, val);
  84. }

  85. /*
  86. * This array of registers needs to match the indexes used by GDB.  The
  87. * whole reason this exists is because the various ROM monitors use
  88. * different names than GDB does, and don't support all the
  89. * registers either.  So, typing "info reg sp" becomes an "A7".
  90. */

  91. static char *ppcbug_regnames[] =
  92. {
  93.   "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  94.   "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  95.   "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  96.   "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",

  97.   "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
  98.   "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
  99.   "fr16", "fr17", "fr18", "fr19", "fr20", "fr21", "fr22", "fr23",
  100.   "fr24", "fr25", "fr26", "fr27", "fr28", "fr29", "fr30", "fr31",

  101. /* pc      ps      cnd     lr      cnt     xer     mq */
  102.   "ip", "msr", "cr", "spr8", "spr9", "spr1", "spr0"
  103. };

  104. /*
  105. * Define the monitor command strings.  Since these are passed directly
  106. * through to a printf style function, we need can include formatting
  107. * strings.  We also need a CR or LF on the end.
  108. */

  109. static struct target_ops ppcbug_ops0;
  110. static struct target_ops ppcbug_ops1;

  111. static char *ppcbug_inits[] =
  112. {"\r", NULL};

  113. static void
  114. init_ppc_cmds (char *LOAD_CMD,
  115.                struct monitor_ops *OPS,
  116.                struct target_ops *targops)
  117. {
  118.   OPS->flags = MO_CLR_BREAK_USES_ADDR | MO_HANDLE_NL;
  119.   OPS->init = ppcbug_inits;        /* Init strings */
  120.   OPS->cont = "g\r";                /* continue command */
  121.   OPS->step = "t\r";                /* single step */
  122.   OPS->stop = NULL;                /* interrupt command */
  123.   OPS->set_break = "br %x\r";        /* set a breakpoint */
  124.   OPS->clr_break = "nobr %x\r";        /* clear a breakpoint */
  125.   OPS->clr_all_break = "nobr\r";        /* clear all breakpoints */
  126.   OPS->fill = "bf %x:%x %x;b\r";        /* fill (start count val) */
  127.   OPS->setmem.cmdb = "ms %x %02x\r";        /* setmem.cmdb (addr, value) */
  128.   OPS->setmem.cmdw = "ms %x %04x\r";        /* setmem.cmdw (addr, value) */
  129.   OPS->setmem.cmdl = "ms %x %08x\r";        /* setmem.cmdl (addr, value) */
  130.   OPS->setmem.cmdll = NULL;        /* setmem.cmdll (addr, value) */
  131.   OPS->setmem.resp_delim = NULL;        /* setreg.resp_delim */
  132.   OPS->setmem.term = NULL;        /* setreg.term */
  133.   OPS->setmem.term_cmd = NULL;        /* setreg.term_cmd */
  134.   OPS->getmem.cmdb = "md %x:%x;b\r";        /* getmem.cmdb (addr, len) */
  135.   OPS->getmem.cmdw = "md %x:%x;b\r";        /* getmem.cmdw (addr, len) */
  136.   OPS->getmem.cmdl = "md %x:%x;b\r";        /* getmem.cmdl (addr, len) */
  137.   OPS->getmem.cmdll = NULL;        /* getmem.cmdll (addr, len) */
  138.   OPS->getmem.resp_delim = " ";        /* getmem.resp_delim */
  139.   OPS->getmem.term = NULL;        /* getmem.term */
  140.   OPS->getmem.term_cmd = NULL;        /* getmem.term_cmd */
  141.   OPS->setreg.cmd = "rs %s %x\r";        /* setreg.cmd (name, value) */
  142.   OPS->setreg.resp_delim = NULL;        /* setreg.resp_delim */
  143.   OPS->setreg.term = NULL;        /* setreg.term */
  144.   OPS->setreg.term_cmd = NULL;        /* setreg.term_cmd */
  145.   OPS->getreg.cmd = "rs %s\r";        /* getreg.cmd (name) */
  146.   OPS->getreg.resp_delim = "=";        /* getreg.resp_delim */
  147.   OPS->getreg.term = NULL;        /* getreg.term */
  148.   OPS->getreg.term_cmd = NULL;        /* getreg.term_cmd */
  149.                                 /* register_pattern */
  150.   OPS->register_pattern = "\\(\\w+\\) +=\\([0-9a-fA-F]+\\b\\)";
  151.   OPS->supply_register = ppcbug_supply_register;
  152.   OPS->dump_registers = "rd\r";        /* dump all registers */
  153.   OPS->load = LOAD_CMD;                /* download command */
  154.   OPS->loadresp = NULL;                /* load response */
  155.   OPS->prompt = "PPC1-Bug>";        /* monitor command prompt */
  156.   OPS->line_term = "\r";        /* end-of-line terminator */
  157.   OPS->cmd_end = NULL;                /* optional command terminator */
  158.   OPS->target = targops;        /* target operations */
  159.   OPS->stopbits = SERIAL_1_STOPBITS;        /* number of stop bits */
  160.   OPS->regnames = ppcbug_regnames;        /* registers names */
  161.   OPS->magic = MONITOR_OPS_MAGIC;        /* magic */
  162. }


  163. static struct monitor_ops ppcbug_cmds0;
  164. static struct monitor_ops ppcbug_cmds1;

  165. static void
  166. ppcbug_open0 (const char *args, int from_tty)
  167. {
  168.   monitor_open (args, &ppcbug_cmds0, from_tty);
  169. }

  170. static void
  171. ppcbug_open1 (const char *args, int from_tty)
  172. {
  173.   monitor_open (args, &ppcbug_cmds1, from_tty);
  174. }

  175. extern initialize_file_ftype _initialize_ppcbug_rom; /* -Wmissing-prototypes */

  176. void
  177. _initialize_ppcbug_rom (void)
  178. {
  179.   init_ppc_cmds ("lo 0\r", &ppcbug_cmds0, &ppcbug_ops0);
  180.   init_ppc_cmds ("lo 1\r", &ppcbug_cmds1, &ppcbug_ops1);
  181.   init_monitor_ops (&ppcbug_ops0);

  182.   ppcbug_ops0.to_shortname = "ppcbug";
  183.   ppcbug_ops0.to_longname = "PowerPC PPCBug monitor on port 0";
  184.   ppcbug_ops0.to_doc = "Debug via the PowerPC PPCBug monitor using port 0.\n\
  185. Specify the serial device it is connected to (e.g. /dev/ttya).";
  186.   ppcbug_ops0.to_open = ppcbug_open0;

  187.   add_target (&ppcbug_ops0);

  188.   init_monitor_ops (&ppcbug_ops1);

  189.   ppcbug_ops1.to_shortname = "ppcbug1";
  190.   ppcbug_ops1.to_longname = "PowerPC PPCBug monitor on port 1";
  191.   ppcbug_ops1.to_doc = "Debug via the PowerPC PPCBug monitor using port 1.\n\
  192. Specify the serial device it is connected to (e.g. /dev/ttya).";
  193.   ppcbug_ops1.to_open = ppcbug_open1;

  194.   add_target (&ppcbug_ops1);
  195. }