1130812Smarcel/* Definitions for remote debugging interface for ROM monitors. 2130812Smarcel Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000 3130812Smarcel Free Software Foundation, Inc. 4130812Smarcel Contributed by Cygnus Support. Written by Rob Savoye for Cygnus. 5130812Smarcel 6130812Smarcel This file is part of GDB. 7130812Smarcel 8130812Smarcel This program is free software; you can redistribute it and/or modify 9130812Smarcel it under the terms of the GNU General Public License as published by 10130812Smarcel the Free Software Foundation; either version 2 of the License, or 11130812Smarcel (at your option) any later version. 12130812Smarcel 13130812Smarcel This program is distributed in the hope that it will be useful, 14130812Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 15130812Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16130812Smarcel GNU General Public License for more details. 17130812Smarcel 18130812Smarcel You should have received a copy of the GNU General Public License 19130812Smarcel along with this program; if not, write to the Free Software 20130812Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 21130812Smarcel Boston, MA 02111-1307, USA. 22130812Smarcel */ 23130812Smarcel 24130812Smarcel#ifndef MONITOR_H 25130812Smarcel#define MONITOR_H 26130812Smarcel 27130812Smarcelstruct target_waitstatus; 28130812Smarcelstruct serial; 29130812Smarcel 30130812Smarcel/* This structure describes the strings necessary to give small command 31130812Smarcel sequences to the monitor, and parse the response. 32130812Smarcel 33130812Smarcel CMD is the actual command typed at the monitor. Usually this has 34130812Smarcel embedded sequences ala printf, which are substituted with the 35130812Smarcel arguments appropriate to that type of command. Ie: to examine a 36130812Smarcel register, we substitute the register name for the first arg. To 37130812Smarcel modify memory, we substitute the memory location and the new 38130812Smarcel contents for the first and second args, etc... 39130812Smarcel 40130812Smarcel RESP_DELIM used to home in on the response string, and is used to 41130812Smarcel disambiguate the answer within the pile of text returned by the 42130812Smarcel monitor. This should be a unique string that immediately precedes 43130812Smarcel the answer. Ie: if your monitor prints out `PC: 00000001= ' in 44130812Smarcel response to asking for the PC, you should use `: ' as the 45130812Smarcel RESP_DELIM. RESP_DELIM may be NULL if the res- ponse is going to 46130812Smarcel be ignored, or has no particular leading text. 47130812Smarcel 48130812Smarcel TERM is the string that the monitor outputs to indicate that it is 49130812Smarcel idle, and waiting for input. This is usually a prompt of some 50130812Smarcel sort. In the previous example, it would be `= '. It is important 51130812Smarcel that TERM really means that the monitor is idle, otherwise GDB may 52130812Smarcel try to type at it when it isn't ready for input. This is a problem 53130812Smarcel because many monitors cannot deal with type-ahead. TERM may be 54130812Smarcel NULL if the normal prompt is output. 55130812Smarcel 56130812Smarcel TERM_CMD is used to quit out of the subcommand mode and get back to 57130812Smarcel the main prompt. TERM_CMD may be NULL if it isn't necessary. It 58130812Smarcel will also be ignored if TERM is NULL. */ 59130812Smarcel 60130812Smarcelstruct memrw_cmd 61130812Smarcel { 62130812Smarcel char *cmdb; /* Command to send for byte read/write */ 63130812Smarcel char *cmdw; /* Command for word (16 bit) read/write */ 64130812Smarcel char *cmdl; /* Command for long (32 bit) read/write */ 65130812Smarcel char *cmdll; /* Command for long long (64 bit) read/write */ 66130812Smarcel char *resp_delim; /* String just prior to the desired value */ 67130812Smarcel char *term; /* Terminating string to search for */ 68130812Smarcel char *term_cmd; /* String to get out of sub-mode (if necessary) */ 69130812Smarcel }; 70130812Smarcel 71130812Smarcelstruct regrw_cmd 72130812Smarcel { 73130812Smarcel char *cmd; /* Command to send for reg read/write */ 74130812Smarcel char *resp_delim; /* String (actually a regexp if getmem) just 75130812Smarcel prior to the desired value */ 76130812Smarcel char *term; /* Terminating string to search for */ 77130812Smarcel char *term_cmd; /* String to get out of sub-mode (if necessary) */ 78130812Smarcel }; 79130812Smarcel 80130812Smarcelstruct monitor_ops 81130812Smarcel { 82130812Smarcel int flags; /* See below */ 83130812Smarcel char **init; /* List of init commands. NULL terminated. */ 84130812Smarcel char *cont; /* continue command */ 85130812Smarcel char *step; /* single step */ 86130812Smarcel char *stop; /* Interrupt program string */ 87130812Smarcel char *set_break; /* set a breakpoint. If NULL, monitor implementation 88130812Smarcel sets its own to_insert_breakpoint method. */ 89130812Smarcel char *clr_break; /* clear a breakpoint */ 90130812Smarcel char *clr_all_break; /* Clear all breakpoints */ 91130812Smarcel char *fill; /* Memory fill cmd (addr len val) */ 92130812Smarcel struct memrw_cmd setmem; /* set memory to a value */ 93130812Smarcel struct memrw_cmd getmem; /* display memory */ 94130812Smarcel struct regrw_cmd setreg; /* set a register */ 95130812Smarcel struct regrw_cmd getreg; /* get a register */ 96130812Smarcel /* Some commands can dump a bunch of registers 97130812Smarcel at once. This comes as a set of REG=VAL 98130812Smarcel pairs. This should be called for each pair 99130812Smarcel of registers that we can parse to supply 100130812Smarcel GDB with the value of a register. */ 101130812Smarcel char *dump_registers; /* Command to dump all regs at once */ 102130812Smarcel char *register_pattern; /* Pattern that picks out register from reg dump */ 103130812Smarcel void (*supply_register) (char *name, int namelen, char *val, int vallen); 104130812Smarcel void (*load_routine) (struct serial *desc, char *file, 105130812Smarcel int hashmark); /* Download routine */ 106130812Smarcel int (*dumpregs) (void); /* routine to dump all registers */ 107130812Smarcel int (*continue_hook) (void); /* Emit the continue command */ 108130812Smarcel int (*wait_filter) (char *buf, /* Maybe contains registers */ 109130812Smarcel int bufmax, 110130812Smarcel int *response_length, 111130812Smarcel struct target_waitstatus * status); 112130812Smarcel char *load; /* load command */ 113130812Smarcel char *loadresp; /* Response to load command */ 114130812Smarcel char *prompt; /* monitor command prompt */ 115130812Smarcel char *line_term; /* end-of-command delimitor */ 116130812Smarcel char *cmd_end; /* optional command terminator */ 117130812Smarcel struct target_ops *target; /* target operations */ 118130812Smarcel int stopbits; /* number of stop bits */ 119130812Smarcel char **regnames; /* array of register names in ascii */ 120130812Smarcel /* deprecated: use regname instead */ 121130812Smarcel const char *(*regname) (int index); 122130812Smarcel /* function for dynamic regname array */ 123130812Smarcel int num_breakpoints; /* If set_break != NULL, number of supported 124130812Smarcel breakpoints */ 125130812Smarcel int magic; /* Check value */ 126130812Smarcel }; 127130812Smarcel 128130812Smarcel/* The monitor ops magic number, used to detect if an ops structure doesn't 129130812Smarcel have the right number of entries filled in. */ 130130812Smarcel 131130812Smarcel#define MONITOR_OPS_MAGIC 600925 132130812Smarcel 133130812Smarcel/* Flag definitions. */ 134130812Smarcel 135130812Smarcel/* If set, then clear breakpoint command uses address, otherwise it 136130812Smarcel uses an index returned by the monitor. */ 137130812Smarcel 138130812Smarcel#define MO_CLR_BREAK_USES_ADDR 0x1 139130812Smarcel 140130812Smarcel/* If set, then memory fill command uses STARTADDR, ENDADDR+1, VALUE 141130812Smarcel as args, else it uses STARTADDR, LENGTH, VALUE as args. */ 142130812Smarcel 143130812Smarcel#define MO_FILL_USES_ADDR 0x2 144130812Smarcel 145130812Smarcel/* If set, then monitor doesn't automatically supply register dump 146130812Smarcel when coming back after a continue. */ 147130812Smarcel 148130812Smarcel#define MO_NEED_REGDUMP_AFTER_CONT 0x4 149130812Smarcel 150130812Smarcel/* getmem needs start addr and end addr */ 151130812Smarcel 152130812Smarcel#define MO_GETMEM_NEEDS_RANGE 0x8 153130812Smarcel 154130812Smarcel/* getmem can only read one loc at a time */ 155130812Smarcel 156130812Smarcel#define MO_GETMEM_READ_SINGLE 0x10 157130812Smarcel 158130812Smarcel/* handle \r\n combinations */ 159130812Smarcel 160130812Smarcel#define MO_HANDLE_NL 0x20 161130812Smarcel 162130812Smarcel/* don't expect echos in monitor_open */ 163130812Smarcel 164130812Smarcel#define MO_NO_ECHO_ON_OPEN 0x40 165130812Smarcel 166130812Smarcel/* If set, send break to stop monitor */ 167130812Smarcel 168130812Smarcel#define MO_SEND_BREAK_ON_STOP 0x80 169130812Smarcel 170130812Smarcel/* If set, target sends an ACK after each S-record */ 171130812Smarcel 172130812Smarcel#define MO_SREC_ACK 0x100 173130812Smarcel 174130812Smarcel/* Allow 0x prefix on addresses retured from monitor */ 175130812Smarcel 176130812Smarcel#define MO_HEX_PREFIX 0x200 177130812Smarcel 178130812Smarcel/* Some monitors require a different command when starting a program */ 179130812Smarcel 180130812Smarcel#define MO_RUN_FIRST_TIME 0x400 181130812Smarcel 182130812Smarcel/* Don't expect echos when getting memory */ 183130812Smarcel 184130812Smarcel#define MO_NO_ECHO_ON_SETMEM 0x800 185130812Smarcel 186130812Smarcel/* If set, then register store command expects value BEFORE regname */ 187130812Smarcel 188130812Smarcel#define MO_REGISTER_VALUE_FIRST 0x1000 189130812Smarcel 190130812Smarcel/* If set, then the monitor displays registers as pairs. */ 191130812Smarcel 192130812Smarcel#define MO_32_REGS_PAIRED 0x2000 193130812Smarcel 194130812Smarcel/* If set, then register setting happens interactively. */ 195130812Smarcel 196130812Smarcel#define MO_SETREG_INTERACTIVE 0x4000 197130812Smarcel 198130812Smarcel/* If set, then memory setting happens interactively. */ 199130812Smarcel 200130812Smarcel#define MO_SETMEM_INTERACTIVE 0x8000 201130812Smarcel 202130812Smarcel/* If set, then memory dumps are always on 16-byte boundaries, even 203130812Smarcel when less is desired. */ 204130812Smarcel 205130812Smarcel#define MO_GETMEM_16_BOUNDARY 0x10000 206130812Smarcel 207130812Smarcel/* If set, then the monitor numbers its breakpoints starting from 1. */ 208130812Smarcel 209130812Smarcel#define MO_CLR_BREAK_1_BASED 0x20000 210130812Smarcel 211130812Smarcel/* If set, then the monitor acks srecords with a plus sign. */ 212130812Smarcel 213130812Smarcel#define MO_SREC_ACK_PLUS 0x40000 214130812Smarcel 215130812Smarcel/* If set, then the monitor "acks" srecords with rotating lines. */ 216130812Smarcel 217130812Smarcel#define MO_SREC_ACK_ROTATE 0x80000 218130812Smarcel 219130812Smarcel/* If set, then remove useless address bits from memory addresses. */ 220130812Smarcel 221130812Smarcel#define MO_ADDR_BITS_REMOVE 0x100000 222130812Smarcel 223130812Smarcel/* If set, then display target program output if prefixed by ^O. */ 224130812Smarcel 225130812Smarcel#define MO_PRINT_PROGRAM_OUTPUT 0x200000 226130812Smarcel 227130812Smarcel/* Some dump bytes commands align the first data with the preceeding 228130812Smarcel 16 byte boundary. Some print blanks and start at the exactly the 229130812Smarcel requested boundary. */ 230130812Smarcel 231130812Smarcel#define MO_EXACT_DUMPADDR 0x400000 232130812Smarcel 233130812Smarcel/* Rather entering and exiting the write memory dialog for each word byte, 234130812Smarcel we can save time by transferring the whole block without exiting 235130812Smarcel the memory editing mode. You only need to worry about this 236130812Smarcel if you are doing memory downloading. 237130812Smarcel This engages a new write function registered with dcache. 238130812Smarcel */ 239130812Smarcel#define MO_HAS_BLOCKWRITES 0x800000 240130812Smarcel 241130812Smarcel#define SREC_SIZE 160 242130812Smarcel 243130812Smarcelextern void monitor_open (char *args, struct monitor_ops *ops, int from_tty); 244130812Smarcelextern void monitor_close (int quitting); 245130812Smarcelextern char *monitor_supply_register (int regno, char *valstr); 246130812Smarcelextern int monitor_expect (char *prompt, char *buf, int buflen); 247130812Smarcelextern int monitor_expect_prompt (char *buf, int buflen); 248130812Smarcel/* Note: The variable argument functions monitor_printf and 249130812Smarcel monitor_printf_noecho vararg do not take take standard format style 250130812Smarcel arguments. Instead they take custom formats interpretered directly 251130812Smarcel by monitor_vsprintf. */ 252130812Smarcelextern void monitor_printf (char *, ...); 253130812Smarcelextern void monitor_printf_noecho (char *, ...); 254130812Smarcelextern void monitor_write (char *buf, int buflen); 255130812Smarcelextern int monitor_readchar (void); 256130812Smarcelextern char *monitor_get_dev_name (void); 257130812Smarcelextern void init_monitor_ops (struct target_ops *); 258130812Smarcelextern int monitor_dump_reg_block (char *dump_cmd); 259130812Smarcel 260130812Smarcel#endif 261