1 /* Native-dependent code for GDB, for NYU Ultra3 running Sym1 OS.
2 Copyright (C) 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
28 #include <sys/types.h>
29 #include <sys/param.h>
31 #include <sys/ioctl.h>
39 static void fetch_core_registers PARAMS ((char *, unsigned, int, CORE_ADDR));
41 /* Assumes support for AMD's Binary Compatibility Standard
42 for ptrace(). If you define ULTRA3, the ultra3 extensions to
43 ptrace() are used allowing the reading of more than one register
46 This file assumes KERNEL_DEBUGGING is turned off. This means
47 that if the user/gdb tries to read gr64-gr95 or any of the
48 protected special registers we silently return -1 (see the
49 CANNOT_STORE/FETCH_REGISTER macros). */
52 #if !defined (offsetof)
53 # define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
57 struct ptrace_user pt_struct;
59 /* Get all available registers from the inferior. Registers that are
60 * defined in REGISTER_NAMES, but not available to the user/gdb are
61 * supplied as -1. This may include gr64-gr95 and the protected special
66 fetch_inferior_registers (regno)
69 register int i,j,ret_val=0;
73 fetch_register (regno);
77 /* Global Registers */
80 ptrace (PT_READ_STRUCT, inferior_pid,
81 (PTRACE_ARG3_TYPE) register_addr(GR96_REGNUM,0),
82 (int)&pt_struct.pt_gr[0], 32*4);
84 perror_with_name ("reading global registers");
86 } else for (regno=GR96_REGNUM, j=0 ; j<32 ; regno++, j++) {
87 supply_register (regno, &pt_struct.pt_gr[j]);
90 for (regno=GR96_REGNUM ; !ret_val && regno < GR96_REGNUM+32 ; regno++)
91 fetch_register(regno);
97 ptrace (PT_READ_STRUCT, inferior_pid,
98 (PTRACE_ARG3_TYPE) register_addr(LR0_REGNUM,0),
99 (int)&pt_struct.pt_lr[0], 128*4);
101 perror_with_name ("reading local registers");
103 } else for (regno=LR0_REGNUM, j=0 ; j<128 ; regno++, j++) {
104 supply_register (regno, &pt_struct.pt_lr[j]);
107 for (regno=LR0_REGNUM ; !ret_val && regno < LR0_REGNUM+128 ; regno++)
108 fetch_register(regno);
111 /* Special Registers */
112 fetch_register(GR1_REGNUM);
113 fetch_register(CPS_REGNUM);
114 fetch_register(PC_REGNUM);
115 fetch_register(NPC_REGNUM);
116 fetch_register(PC2_REGNUM);
117 fetch_register(IPC_REGNUM);
118 fetch_register(IPA_REGNUM);
119 fetch_register(IPB_REGNUM);
120 fetch_register(Q_REGNUM);
121 fetch_register(BP_REGNUM);
122 fetch_register(FC_REGNUM);
124 /* Fake any registers that are in REGISTER_NAMES, but not available to gdb */
128 /* Store our register values back into the inferior.
129 * If REGNO is -1, do this for all registers.
130 * Otherwise, REGNO specifies which register (so we can save time).
131 * NOTE: Assumes AMD's binary compatibility standard.
135 store_inferior_registers (regno)
138 register unsigned int regaddr;
143 if (CANNOT_STORE_REGISTER(regno))
145 regaddr = register_addr (regno, 0);
147 ptrace (PT_WRITE_U, inferior_pid,
148 (PTRACE_ARG3_TYPE) regaddr, read_register(regno));
151 sprintf (buf, "writing register %s (#%d)", REGISTER_NAME (regno), regno);
152 perror_with_name (buf);
158 pt_struct.pt_gr1 = read_register(GR1_REGNUM);
159 for (regno = GR96_REGNUM; regno < GR96_REGNUM+32; regno++)
160 pt_struct.pt_gr[regno] = read_register(regno);
161 for (regno = LR0_REGNUM; regno < LR0_REGNUM+128; regno++)
162 pt_struct.pt_gr[regno] = read_register(regno);
164 ptrace (PT_WRITE_STRUCT, inferior_pid,
165 (PTRACE_ARG3_TYPE) register_addr(GR1_REGNUM,0),
166 (int)&pt_struct.pt_gr1,(1*32*128)*4);
169 sprintf (buf, "writing all local/global registers");
170 perror_with_name (buf);
172 pt_struct.pt_psr = read_register(CPS_REGNUM);
173 pt_struct.pt_pc0 = read_register(NPC_REGNUM);
174 pt_struct.pt_pc1 = read_register(PC_REGNUM);
175 pt_struct.pt_pc2 = read_register(PC2_REGNUM);
176 pt_struct.pt_ipc = read_register(IPC_REGNUM);
177 pt_struct.pt_ipa = read_register(IPA_REGNUM);
178 pt_struct.pt_ipb = read_register(IPB_REGNUM);
179 pt_struct.pt_q = read_register(Q_REGNUM);
180 pt_struct.pt_bp = read_register(BP_REGNUM);
181 pt_struct.pt_fc = read_register(FC_REGNUM);
183 ptrace (PT_WRITE_STRUCT, inferior_pid,
184 (PTRACE_ARG3_TYPE) register_addr(CPS_REGNUM,0),
185 (int)&pt_struct.pt_psr,(10)*4);
188 sprintf (buf, "writing all special registers");
189 perror_with_name (buf);
193 store_inferior_registers(GR1_REGNUM);
194 for (regno=GR96_REGNUM ; regno<GR96_REGNUM+32 ; regno++)
195 store_inferior_registers(regno);
196 for (regno=LR0_REGNUM ; regno<LR0_REGNUM+128 ; regno++)
197 store_inferior_registers(regno);
198 store_inferior_registers(CPS_REGNUM);
199 store_inferior_registers(PC_REGNUM);
200 store_inferior_registers(NPC_REGNUM);
201 store_inferior_registers(PC2_REGNUM);
202 store_inferior_registers(IPC_REGNUM);
203 store_inferior_registers(IPA_REGNUM);
204 store_inferior_registers(IPB_REGNUM);
205 store_inferior_registers(Q_REGNUM);
206 store_inferior_registers(BP_REGNUM);
207 store_inferior_registers(FC_REGNUM);
213 * Fetch an individual register (and supply it).
214 * return 0 on success, -1 on failure.
215 * NOTE: Assumes AMD's Binary Compatibility Standard for ptrace().
218 fetch_register (regno)
224 if (CANNOT_FETCH_REGISTER(regno)) {
226 supply_register (regno, &val);
229 val = ptrace (PT_READ_U, inferior_pid,
230 (PTRACE_ARG3_TYPE) register_addr(regno,0), 0);
232 sprintf(buf,"reading register %s (#%d)",REGISTER_NAME (regno), regno);
233 perror_with_name (buf);
235 supply_register (regno, &val);
242 * Read AMD's Binary Compatibilty Standard conforming core file.
243 * struct ptrace_user is the first thing in the core file
247 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
248 char *core_reg_sect; /* Unused in this version */
249 unsigned core_reg_size; /* Unused in this version */
250 int which; /* Unused in this version */
251 CORE_ADDR reg_addr; /* Unused in this version */
257 for (regno = 0 ; regno < NUM_REGS; regno++) {
258 if (!CANNOT_FETCH_REGISTER(regno)) {
259 val = bfd_seek (core_bfd, (file_ptr) register_addr (regno, 0), SEEK_SET);
260 if (val < 0 || (val = bfd_read (buf, sizeof buf, 1, core_bfd)) < 0) {
261 char * buffer = (char *) alloca (strlen (REGISTER_NAME (regno)) + 35);
262 strcpy (buffer, "Reading core register ");
263 strcat (buffer, REGISTER_NAME (regno));
264 perror_with_name (buffer);
266 supply_register (regno, buf);
270 /* Fake any registers that are in REGISTER_NAMES, but not available to gdb */
276 * Takes a register number as defined in tm.h via REGISTER_NAMES, and maps
277 * it to an offset in a struct ptrace_user defined by AMD's BCS.
278 * That is, it defines the mapping between gdb register numbers and items in
279 * a struct ptrace_user.
280 * A register protection scheme is set up here. If a register not
281 * available to the user is specified in 'regno', then an address that
282 * will cause ptrace() to fail is returned.
285 register_addr (regno,blockend)
289 if ((regno >= LR0_REGNUM) && (regno < LR0_REGNUM + 128)) {
290 return(offsetof(struct ptrace_user,pt_lr[regno-LR0_REGNUM]));
291 } else if ((regno >= GR96_REGNUM) && (regno < GR96_REGNUM + 32)) {
292 return(offsetof(struct ptrace_user,pt_gr[regno-GR96_REGNUM]));
295 case GR1_REGNUM: return(offsetof(struct ptrace_user,pt_gr1));
296 case CPS_REGNUM: return(offsetof(struct ptrace_user,pt_psr));
297 case NPC_REGNUM: return(offsetof(struct ptrace_user,pt_pc0));
298 case PC_REGNUM: return(offsetof(struct ptrace_user,pt_pc1));
299 case PC2_REGNUM: return(offsetof(struct ptrace_user,pt_pc2));
300 case IPC_REGNUM: return(offsetof(struct ptrace_user,pt_ipc));
301 case IPA_REGNUM: return(offsetof(struct ptrace_user,pt_ipa));
302 case IPB_REGNUM: return(offsetof(struct ptrace_user,pt_ipb));
303 case Q_REGNUM: return(offsetof(struct ptrace_user,pt_q));
304 case BP_REGNUM: return(offsetof(struct ptrace_user,pt_bp));
305 case FC_REGNUM: return(offsetof(struct ptrace_user,pt_fc));
307 fprintf_filtered(gdb_stderr,"register_addr():Bad register %s (%d)\n",
308 REGISTER_NAME (regno), regno);
309 return(0xffffffff); /* Should make ptrace() fail */
315 /* Register that we are able to handle ultra3 core file formats.
316 FIXME: is this really bfd_target_unknown_flavour? */
318 static struct core_fns ultra3_core_fns =
320 bfd_target_unknown_flavour,
321 fetch_core_registers,
326 _initialize_core_ultra3 ()
328 add_core_fns (&ultra3_core_fns);