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