1130812Smarcel/* Remote debugging interface for CPU32Bug Rom monitor for GDB, the GNU debugger. 2130812Smarcel Copyright 1995, 1996, 1998, 1999, 2000, 2001 3130812Smarcel Free Software Foundation, Inc. 4130812Smarcel 5130812Smarcel Written by Stu Grossman of Cygnus Support 6130812Smarcel 7130812Smarcel This file is part of GDB. 8130812Smarcel 9130812Smarcel This program is free software; you can redistribute it and/or modify 10130812Smarcel it under the terms of the GNU General Public License as published by 11130812Smarcel the Free Software Foundation; either version 2 of the License, or 12130812Smarcel (at your option) any later version. 13130812Smarcel 14130812Smarcel This program is distributed in the hope that it will be useful, 15130812Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 16130812Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17130812Smarcel GNU General Public License for more details. 18130812Smarcel 19130812Smarcel You should have received a copy of the GNU General Public License 20130812Smarcel along with this program; if not, write to the Free Software 21130812Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 22130812Smarcel Boston, MA 02111-1307, USA. */ 23130812Smarcel 24130812Smarcel#include "defs.h" 25130812Smarcel#include "gdbcore.h" 26130812Smarcel#include "target.h" 27130812Smarcel#include "monitor.h" 28130812Smarcel#include "serial.h" 29130812Smarcel#include "regcache.h" 30130812Smarcel 31130812Smarcel#include "m68k-tdep.h" 32130812Smarcel 33130812Smarcelstatic void cpu32bug_open (char *args, int from_tty); 34130812Smarcel 35130812Smarcelstatic void 36130812Smarcelcpu32bug_supply_register (char *regname, int regnamelen, char *val, int vallen) 37130812Smarcel{ 38130812Smarcel int regno; 39130812Smarcel 40130812Smarcel if (regnamelen != 2) 41130812Smarcel return; 42130812Smarcel 43130812Smarcel switch (regname[0]) 44130812Smarcel { 45130812Smarcel case 'S': 46130812Smarcel if (regname[1] != 'R') 47130812Smarcel return; 48130812Smarcel regno = PS_REGNUM; 49130812Smarcel break; 50130812Smarcel case 'P': 51130812Smarcel if (regname[1] != 'C') 52130812Smarcel return; 53130812Smarcel regno = PC_REGNUM; 54130812Smarcel break; 55130812Smarcel case 'D': 56130812Smarcel if (regname[1] < '0' || regname[1] > '7') 57130812Smarcel return; 58130812Smarcel regno = regname[1] - '0' + M68K_D0_REGNUM; 59130812Smarcel break; 60130812Smarcel case 'A': 61130812Smarcel if (regname[1] < '0' || regname[1] > '7') 62130812Smarcel return; 63130812Smarcel regno = regname[1] - '0' + M68K_A0_REGNUM; 64130812Smarcel break; 65130812Smarcel default: 66130812Smarcel return; 67130812Smarcel } 68130812Smarcel 69130812Smarcel monitor_supply_register (regno, val); 70130812Smarcel} 71130812Smarcel 72130812Smarcel/* 73130812Smarcel * This array of registers needs to match the indexes used by GDB. The 74130812Smarcel * whole reason this exists is because the various ROM monitors use 75130812Smarcel * different names than GDB does, and don't support all the 76130812Smarcel * registers either. So, typing "info reg sp" becomes an "A7". 77130812Smarcel */ 78130812Smarcel 79130812Smarcelstatic const char * 80130812Smarcelcpu32bug_regname (int index) 81130812Smarcel{ 82130812Smarcel static char *regnames[] = 83130812Smarcel { 84130812Smarcel "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", 85130812Smarcel "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", 86130812Smarcel "SR", "PC" 87130812Smarcel }; 88130812Smarcel 89130812Smarcel if ((index >= (sizeof (regnames) / sizeof (regnames[0]))) 90130812Smarcel || (index < 0) || (index >= NUM_REGS)) 91130812Smarcel return NULL; 92130812Smarcel else 93130812Smarcel return regnames[index]; 94130812Smarcel} 95130812Smarcel 96130812Smarcel/* 97130812Smarcel * Define the monitor command strings. Since these are passed directly 98130812Smarcel * through to a printf style function, we need can include formatting 99130812Smarcel * strings. We also need a CR or LF on the end. 100130812Smarcel */ 101130812Smarcel 102130812Smarcelstatic struct target_ops cpu32bug_ops; 103130812Smarcel 104130812Smarcelstatic char *cpu32bug_inits[] = 105130812Smarcel{"\r", NULL}; 106130812Smarcel 107130812Smarcelstatic struct monitor_ops cpu32bug_cmds; 108130812Smarcel 109130812Smarcelstatic void 110130812Smarcelinit_cpu32bug_cmds (void) 111130812Smarcel{ 112130812Smarcel cpu32bug_cmds.flags = MO_CLR_BREAK_USES_ADDR; 113130812Smarcel cpu32bug_cmds.init = cpu32bug_inits; /* Init strings */ 114130812Smarcel cpu32bug_cmds.cont = "g\r"; /* continue command */ 115130812Smarcel cpu32bug_cmds.step = "t\r"; /* single step */ 116130812Smarcel cpu32bug_cmds.stop = NULL; /* interrupt command */ 117130812Smarcel cpu32bug_cmds.set_break = "br %x\r"; /* set a breakpoint */ 118130812Smarcel cpu32bug_cmds.clr_break = "nobr %x\r"; /* clear a breakpoint */ 119130812Smarcel cpu32bug_cmds.clr_all_break = "nobr\r"; /* clear all breakpoints */ 120130812Smarcel cpu32bug_cmds.fill = "bf %x:%x %x;b\r"; /* fill (start count val) */ 121130812Smarcel cpu32bug_cmds.setmem.cmdb = "ms %x %02x\r"; /* setmem.cmdb (addr, value) */ 122130812Smarcel cpu32bug_cmds.setmem.cmdw = "ms %x %04x\r"; /* setmem.cmdw (addr, value) */ 123130812Smarcel cpu32bug_cmds.setmem.cmdl = "ms %x %08x\r"; /* setmem.cmdl (addr, value) */ 124130812Smarcel cpu32bug_cmds.setmem.cmdll = NULL; /* setmem.cmdll (addr, value) */ 125130812Smarcel cpu32bug_cmds.setmem.resp_delim = NULL; /* setreg.resp_delim */ 126130812Smarcel cpu32bug_cmds.setmem.term = NULL; /* setreg.term */ 127130812Smarcel cpu32bug_cmds.setmem.term_cmd = NULL; /* setreg.term_cmd */ 128130812Smarcel cpu32bug_cmds.getmem.cmdb = "md %x:%x;b\r"; /* getmem.cmdb (addr, len) */ 129130812Smarcel cpu32bug_cmds.getmem.cmdw = "md %x:%x;b\r"; /* getmem.cmdw (addr, len) */ 130130812Smarcel cpu32bug_cmds.getmem.cmdl = "md %x:%x;b\r"; /* getmem.cmdl (addr, len) */ 131130812Smarcel cpu32bug_cmds.getmem.cmdll = NULL; /* getmem.cmdll (addr, len) */ 132130812Smarcel cpu32bug_cmds.getmem.resp_delim = " "; /* getmem.resp_delim */ 133130812Smarcel cpu32bug_cmds.getmem.term = NULL; /* getmem.term */ 134130812Smarcel cpu32bug_cmds.getmem.term_cmd = NULL; /* getmem.term_cmd */ 135130812Smarcel cpu32bug_cmds.setreg.cmd = "rs %s %x\r"; /* setreg.cmd (name, value) */ 136130812Smarcel cpu32bug_cmds.setreg.resp_delim = NULL; /* setreg.resp_delim */ 137130812Smarcel cpu32bug_cmds.setreg.term = NULL; /* setreg.term */ 138130812Smarcel cpu32bug_cmds.setreg.term_cmd = NULL; /* setreg.term_cmd */ 139130812Smarcel cpu32bug_cmds.getreg.cmd = "rs %s\r"; /* getreg.cmd (name) */ 140130812Smarcel cpu32bug_cmds.getreg.resp_delim = "="; /* getreg.resp_delim */ 141130812Smarcel cpu32bug_cmds.getreg.term = NULL; /* getreg.term */ 142130812Smarcel cpu32bug_cmds.getreg.term_cmd = NULL; /* getreg.term_cmd */ 143130812Smarcel cpu32bug_cmds.dump_registers = "rd\r"; /* dump_registers */ 144130812Smarcel cpu32bug_cmds.register_pattern = "\\(\\w+\\) +=\\([0-9a-fA-F]+\\b\\)"; /* register_pattern */ 145130812Smarcel cpu32bug_cmds.supply_register = cpu32bug_supply_register; /* supply_register */ 146130812Smarcel cpu32bug_cmds.load_routine = NULL; /* load_routine (defaults to SRECs) */ 147130812Smarcel cpu32bug_cmds.load = "lo\r"; /* download command */ 148130812Smarcel cpu32bug_cmds.loadresp = "\n"; /* load response */ 149130812Smarcel cpu32bug_cmds.prompt = "CPU32Bug>"; /* monitor command prompt */ 150130812Smarcel cpu32bug_cmds.line_term = "\r"; /* end-of-line terminator */ 151130812Smarcel cpu32bug_cmds.cmd_end = NULL; /* optional command terminator */ 152130812Smarcel cpu32bug_cmds.target = &cpu32bug_ops; /* target operations */ 153130812Smarcel cpu32bug_cmds.stopbits = SERIAL_1_STOPBITS; /* number of stop bits */ 154130812Smarcel cpu32bug_cmds.regnames = NULL; /* registers names */ 155130812Smarcel cpu32bug_cmds.regname = cpu32bug_regname; 156130812Smarcel cpu32bug_cmds.magic = MONITOR_OPS_MAGIC; /* magic */ 157130812Smarcel}; /* init_cpu32bug_cmds */ 158130812Smarcel 159130812Smarcelstatic void 160130812Smarcelcpu32bug_open (char *args, int from_tty) 161130812Smarcel{ 162130812Smarcel monitor_open (args, &cpu32bug_cmds, from_tty); 163130812Smarcel} 164130812Smarcel 165130812Smarcelextern initialize_file_ftype _initialize_cpu32bug_rom; /* -Wmissing-prototypes */ 166130812Smarcel 167130812Smarcelvoid 168130812Smarcel_initialize_cpu32bug_rom (void) 169130812Smarcel{ 170130812Smarcel init_cpu32bug_cmds (); 171130812Smarcel init_monitor_ops (&cpu32bug_ops); 172130812Smarcel 173130812Smarcel cpu32bug_ops.to_shortname = "cpu32bug"; 174130812Smarcel cpu32bug_ops.to_longname = "CPU32Bug monitor"; 175130812Smarcel cpu32bug_ops.to_doc = "Debug via the CPU32Bug monitor.\n\ 176130812SmarcelSpecify the serial device it is connected to (e.g. /dev/ttya)."; 177130812Smarcel cpu32bug_ops.to_open = cpu32bug_open; 178130812Smarcel 179130812Smarcel add_target (&cpu32bug_ops); 180130812Smarcel} 181