]> Git Repo - binutils.git/blob - gdb/sparclet-rom.c
* remote.texi: Update list of stubs in the GDB distribution.
[binutils.git] / gdb / sparclet-rom.c
1 /* Remote target glue for the SPARC Sparclet ROM monitor.
2    Copyright 1995, 1996 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20
21 #include "defs.h"
22 #include "gdbcore.h"
23 #include "target.h"
24 #include "monitor.h"
25 #include "serial.h"
26 #include "srec.h"
27 #include "symtab.h"
28 #include "symfile.h" /* for generic_load */
29
30 #if !defined (HAVE_TERMIOS) && !defined (HAVE_TERMIO) && !defined (HAVE_SGTTY)
31 #define HAVE_SGTTY
32 #endif
33
34 #ifdef HAVE_SGTTY
35 #include <sys/ioctl.h>
36 #endif
37
38 #include <sys/types.h>  /* Needed by file.h on Sys V */
39 #include <sys/file.h>
40 #include <signal.h>
41 #include <sys/stat.h>
42
43 #define USE_GENERIC_LOAD
44 #define USE_SW_BREAKS
45
46 static struct target_ops sparclet_ops;
47
48 static void sparclet_open PARAMS ((char *args, int from_tty));
49
50 #ifdef USE_GENERIC_LOAD
51
52 static void
53 sparclet_load_gen (filename, from_tty) 
54     char *filename;
55     int from_tty;
56 {
57   extern int inferior_pid;
58
59   generic_load (filename, from_tty);
60   /* Finally, make the PC point at the start address */
61   if (exec_bfd)
62     write_pc (bfd_get_start_address (exec_bfd));
63
64   inferior_pid = 0;             /* No process now */
65 }
66
67 #else
68
69 static void
70 sparclet_xmodem_load (desc, file, hashmark)
71      serial_t desc;
72      char *file;
73      int hashmark;
74 {
75   bfd *abfd;
76   asection *s;
77   char *buffer;
78   int i;
79
80   buffer = alloca (XMODEM_PACKETSIZE);
81   abfd = bfd_openr (file, 0);
82   if (!abfd)
83     {
84       printf_filtered ("Unable to open file %s\n", file);
85       return;
86     }
87   if (bfd_check_format (abfd, bfd_object) == 0)
88     {
89       printf_filtered ("File is not an object file\n");
90       return;
91     }
92   for (s = abfd->sections; s; s = s->next)
93     if (s->flags & SEC_LOAD)
94       {
95         bfd_size_type section_size;
96         printf_filtered ("%s\t: 0x%4x .. 0x%4x  ", s->name, s->vma,
97                          s->vma + s->_raw_size);
98         gdb_flush (gdb_stdout);
99         monitor_printf (current_monitor->load, s->vma);
100         if (current_monitor->loadresp)
101           monitor_expect (current_monitor->loadresp, NULL, 0);
102         xmodem_init_xfer (desc);
103         section_size = bfd_section_size (abfd, s);
104         for (i = 0; i < section_size; i += XMODEM_DATASIZE)
105           {
106             int numbytes;
107             numbytes = min (XMODEM_DATASIZE, section_size - i);
108             bfd_get_section_contents (abfd, s, buffer + XMODEM_DATAOFFSET, i,
109                                       numbytes);
110             xmodem_send_packet (desc, buffer, numbytes, hashmark);
111             if (hashmark)
112               {
113                 putchar_unfiltered ('#');
114                 gdb_flush (gdb_stdout);
115               }
116           }                     /* Per-packet (or S-record) loop */
117         xmodem_finish_xfer (desc);
118         monitor_expect_prompt (NULL, 0);
119         putchar_unfiltered ('\n');
120       }                         /* Loadable sections */
121   if (hashmark) 
122     putchar_unfiltered ('\n');
123 }
124
125 static void
126 sparclet_load (desc, file, hashmark)
127      serial_t desc;
128      char *file;
129      int hashmark;
130 {
131 ???
132 }
133 #endif /* USE_GENERIC_LOAD */
134
135 /* This array of registers need to match the indexes used by GDB.
136    This exists because the various ROM monitors use different strings
137    than does GDB, and don't necessarily support all the registers
138    either. So, typing "info reg sp" becomes a "r30".  */
139
140 /*PSR 0x00000080  impl ver icc AW LE EE EC EF PIL S PS ET CWP  WIM
141                 0x0  0x0 0x0  0  0  0  0  0 0x0 1  0  0 0x00 0x2
142                                                              0000010
143        INS        LOCALS       OUTS      GLOBALS
144  0  0x00000000  0x00000000  0x00000000  0x00000000
145  1  0x00000000  0x00000000  0x00000000  0x00000000
146  2  0x00000000  0x00000000  0x00000000  0x00000000
147  3  0x00000000  0x00000000  0x00000000  0x00000000
148  4  0x00000000  0x00000000  0x00000000  0x00000000
149  5  0x00000000  0x00001000  0x00000000  0x00000000
150  6  0x00000000  0x00000000  0x123f0000  0x00000000
151  7  0x00000000  0x00000000  0x00000000  0x00000000
152 pc:  0x12010000 0x00000000    unimp
153 npc: 0x12010004 0x00001000    unimp     0x1000
154 tbr: 0x00000000
155 y:   0x00000000
156 */
157 /* these correspond to the offsets from tm-* files from config directories */
158
159 /* is wim part of psr?? */
160 /* monitor wants lower case */
161 static char *sparclet_regnames[NUM_REGS] = REGISTER_NAMES;
162
163 /* Define the monitor command strings. Since these are passed directly
164    through to a printf style function, we may include formatting
165    strings. We also need a CR or LF on the end.  */
166
167 /* need to pause the monitor for timing reasons, so slow it down */
168
169 static char *sparclet_inits[] = {"\n\r\r\n", NULL};
170
171 static struct monitor_ops sparclet_cmds =
172 {
173   MO_CLR_BREAK_USES_ADDR
174     | MO_HEX_PREFIX
175     | MO_HANDLE_NL
176     | MO_NO_ECHO_ON_OPEN
177     | MO_NO_ECHO_ON_SETMEM
178     | MO_RUN_FIRST_TIME
179     | MO_GETMEM_READ_SINGLE,    /* flags */
180   sparclet_inits,                       /* Init strings */
181   "cont\r",                     /* continue command */
182   "step\r",                     /* single step */
183   "\r",                 /* break interrupts the program */
184   "+bp %x\r",                           /* set a breakpoint */
185                                 /* can't use "br" because only 2 hw bps are supported */
186   "-bp %x\r",                           /* clear a breakpoint */
187   "-bp\r",                              /* clear all breakpoints */
188   NULL,                         /* fill (start end val) */
189                                 /* can't use "fi" because it takes words, not bytes */
190   {
191     /* ex [addr] [-n count] [-b|-s|-l]          default: ex cur -n 1 -b */
192     "ex %x -b\r%x\rq\r",                        /* setmem.cmdb (addr, value) */
193     "ex %x -s\r%x\rq\r",                /* setmem.cmdw (addr, value) */
194     "ex %x -l\r%x\rq\r",         
195     NULL,                       /* setmem.cmdll (addr, value) */
196     NULL, /*": ",                       /* setmem.resp_delim */
197     NULL, /*"? ",                       /* setmem.term */
198     NULL, /*"q\r",                      /* setmem.term_cmd */
199   },
200   {
201     /* since the parsing of multiple bytes is difficult due to
202        interspersed addresses, we'll only read 1 value at a time, 
203        even tho these can handle a count */
204     /* we can use -n to set count to read, but may have to parse? */
205     "ex %x -n 1 -b\r",          /* getmem.cmdb (addr, #bytes) */
206     "ex %x -n 1 -s\r",          /* getmem.cmdw (addr, #swords) */
207     "ex %x -n 1 -l\r",          /* getmem.cmdl (addr, #words) */
208     NULL,               /* getmem.cmdll (addr, #dwords) */
209     ": ",                       /* getmem.resp_delim */
210     NULL,                       /* getmem.term */
211     NULL,                       /* getmem.term_cmd */
212   },
213   {
214     "reg %s 0x%x\r",            /* setreg.cmd (name, value) */
215     NULL,                       /* setreg.resp_delim */
216     NULL,                       /* setreg.term */
217     NULL                        /* setreg.term_cmd */
218   },
219   {
220     "reg %s\r",         /* getreg.cmd (name) */
221     ": ",                       /* getreg.resp_delim */
222     NULL,                       /* getreg.term */
223     NULL,                       /* getreg.term_cmd */
224   },
225   "reg\r",                      /* dump_registers */
226   "\\(\\w+\\)=\\([0-9a-fA-F]+\\)",      /* register_pattern */
227   NULL,                         /* supply_register */
228 #ifdef USE_GENERIC_LOAD
229   NULL,                         /* load_routine (defaults to SRECs) */
230   NULL,                         /* download command */
231   NULL,                         /* load response */
232 #else
233   sparclet_load,                        /* load_routine (defaults to SRECs) */
234   /* load [c|a] [s|f|r] [addr count] */
235   "load a s %x\r",                      /* download command */
236   "load: ",             /* load response */
237 #endif
238   "monitor>",                           /* monitor command prompt */
239   /* yikes!  gdb core dumps without this delimitor!! */
240   "\r",                 /* end-of-command delimitor */
241   NULL,                         /* optional command terminator */
242   &sparclet_ops,                        /* target operations */
243   SERIAL_1_STOPBITS,            /* number of stop bits */
244   sparclet_regnames,            /* registers names */
245   MONITOR_OPS_MAGIC             /* magic */
246 };
247
248 static void
249 sparclet_open (args, from_tty)
250      char *args;
251      int from_tty;
252 {
253   monitor_open (args, &sparclet_cmds, from_tty);
254 }
255
256 void
257 _initialize_sparclet ()
258 {
259   init_monitor_ops (&sparclet_ops);
260
261   sparclet_ops.to_shortname = "sparclet"; /* for the target command */
262   sparclet_ops.to_longname = "SPARC Sparclet monitor";
263 #ifdef USE_GENERIC_LOAD
264   sparclet_ops.to_load = sparclet_load_gen; /* FIXME - should go back and try "do" */
265 #endif
266 #ifdef USE_SW_BREAKS
267   /* use SW breaks; target only supports 2 HW breakpoints */
268   sparclet_ops.to_insert_breakpoint = memory_insert_breakpoint; 
269   sparclet_ops.to_remove_breakpoint = memory_remove_breakpoint; 
270 #endif
271
272   sparclet_ops.to_doc = 
273     "Use a board running the Sparclet debug monitor.\n\
274 Specify the serial device it is connected to (e.g. /dev/ttya).";
275
276   sparclet_ops.to_open = sparclet_open;
277   add_target (&sparclet_ops);
278 }
279
This page took 0.040409 seconds and 4 git commands to generate.