]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/remote-d10v.c
import gdb-1999-05-25 snapshot
[thirdparty/binutils-gdb.git] / gdb / remote-d10v.c
1 /* Remote target communications for d10v connected via a serial line.
2 Copyright 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997 Free
3 Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #include "defs.h"
22 #include "gdb_string.h"
23 #include <fcntl.h>
24 #include "frame.h"
25 #include "inferior.h"
26 #include "bfd.h"
27 #include "symfile.h"
28 #include "target.h"
29 #include "wait.h"
30 /*#include "terminal.h"*/
31 #include "gdbcmd.h"
32 #include "objfiles.h"
33 #include "gdb-stabs.h"
34 #include "gdbthread.h"
35
36 #include "dcache.h"
37
38 #ifdef USG
39 #include <sys/types.h>
40 #endif
41
42 #include <signal.h>
43 #include "serial.h"
44
45 /* Prototypes for local functions */
46
47 extern void _initialize_remote_d10v PARAMS ((void));
48
49 static void remote_d10v_open PARAMS ((char *name, int from_tty));
50
51 /* Define the target subroutine names */
52 static struct target_ops remote_d10v_ops;
53
54 /* Open a connection to a remote debugger.
55 NAME is the filename used for communication. */
56
57 static void
58 remote_d10v_open (name, from_tty)
59 char *name;
60 int from_tty;
61 {
62 pop_target ();
63 push_remote_target (name, from_tty);
64 }
65
66
67 /* Translate a GDB virtual ADDR/LEN into a format the remote target
68 understands. Returns number of bytes that can be transfered
69 starting at taddr, ZERO if no bytes can be transfered. */
70 void
71 remote_d10v_translate_xfer_address (memaddr, nr_bytes, targ_addr, targ_len)
72 CORE_ADDR memaddr;
73 int nr_bytes;
74 CORE_ADDR *targ_addr;
75 int *targ_len;
76 {
77 CORE_ADDR phys;
78 CORE_ADDR seg;
79 CORE_ADDR off;
80 char *from = "unknown";
81 char *to = "unknown";
82 unsigned short imap0 = read_register (IMAP0_REGNUM);
83 unsigned short imap1 = read_register (IMAP1_REGNUM);
84 unsigned short dmap = read_register (DMAP_REGNUM);
85
86 /* GDB interprets addresses as:
87
88 0x00xxxxxx: Logical data address segment (DMAP translated memory)
89 0x01xxxxxx: Logical instruction address segment (IMAP translated memory)
90 0x10xxxxxx: Physical data memory segment (On-chip data memory)
91 0x11xxxxxx: Physical instruction memory segment (On-chip insn memory)
92 0x12xxxxxx: Phisical unified memory segment (Unified memory)
93
94 The remote d10v board interprets addresses as:
95
96 0x00xxxxxx: Phisical unified memory segment (Unified memory)
97 0x01xxxxxx: Physical instruction memory segment (On-chip insn memory)
98 0x02xxxxxx: Physical data memory segment (On-chip data memory)
99
100 Translate according to current IMAP/dmap registers */
101
102 enum {
103 targ_unified = 0x00000000,
104 targ_insn = 0x01000000,
105 targ_data = 0x02000000,
106 };
107
108 seg = (memaddr >> 24);
109 off = (memaddr & 0xffffffL);
110
111 switch (seg)
112 {
113 case 0x00: /* in logical data address segment */
114 {
115 from = "logical-data";
116 if (off <= 0x7fffL)
117 {
118 /* On chip data */
119 phys = targ_data + off;
120 if (off + nr_bytes > 0x7fffL)
121 /* don't cross VM boundary */
122 nr_bytes = 0x7fffL - off + 1;
123 to = "chip-data";
124 }
125 else if (off <= 0xbfffL)
126 {
127 short map = dmap;
128 if (map & 0x1000)
129 {
130 /* Instruction memory */
131 phys = targ_insn | ((map & 0xf) << 14) | (off & 0x3fff);
132 to = "chip-insn";
133 }
134 else
135 {
136 /* Unified memory */
137 phys = targ_unified | ((map & 0x3ff) << 14) | (off & 0x3fff);
138 to = "unified";
139 }
140 if (off + nr_bytes > 0xbfffL)
141 /* don't cross VM boundary */
142 nr_bytes = (0xbfffL - off + 1);
143 }
144 else
145 {
146 /* Logical address out side of data segments, not supported */
147 *targ_len = 0;
148 return;
149 }
150 break;
151 }
152
153 case 0x01: /* in logical instruction address segment */
154 {
155 short map;
156 from = "logical-insn";
157 if (off <= 0x1ffffL)
158 {
159 map = imap0;
160 }
161 else if (off <= 0x3ffffL)
162 {
163 map = imap1;
164 }
165 else
166 {
167 /* Logical address outside of IMAP[01] segment, not
168 supported */
169 *targ_len = 0;
170 return;
171 }
172 if ((off & 0x1ffff) + nr_bytes > 0x1ffffL)
173 {
174 /* don't cross VM boundary */
175 nr_bytes = 0x1ffffL - (off & 0x1ffffL) + 1;
176 }
177 if (map & 0x1000)
178 /* Instruction memory */
179 {
180 phys = targ_insn | off;
181 to = "chip-insn";
182 }
183 else
184 {
185 phys = ((map & 0x7fL) << 17) + (off & 0x1ffffL);
186 if (phys > 0xffffffL)
187 {
188 /* Address outside of unified address segment */
189 *targ_len = 0;
190 return;
191 }
192 phys |= targ_unified;
193 to = "unified";
194 }
195 break;
196 }
197
198 case 0x10: /* Physical data memory segment */
199 from = "phys-data";
200 phys = targ_data | off;
201 to = "chip-data";
202 break;
203
204 case 0x11: /* Physical instruction memory */
205 from = "phys-insn";
206 phys = targ_insn | off;
207 to = "chip-insn";
208 break;
209
210 case 0x12: /* Physical unified memory */
211 from = "phys-unified";
212 phys = targ_unified | off;
213 to = "unified";
214 break;
215
216 default:
217 *targ_len = 0;
218 return;
219 }
220
221
222 *targ_addr = phys;
223 *targ_len = nr_bytes;
224 }
225
226
227 void
228 _initialize_remote_d10v ()
229 {
230 remote_d10v_ops.to_shortname = "d10v";
231 remote_d10v_ops.to_longname = "Remote d10v serial target in gdb-specific protocol";
232 remote_d10v_ops.to_doc = "Use a remote d10v via a serial line, using a gdb-specific protocol.\n\
233 Specify the serial device it is connected to (e.g. /dev/ttya).";
234 remote_d10v_ops.to_open = remote_d10v_open;
235
236 add_target (&remote_d10v_ops);
237 }