]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/irix4-nat.c
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / irix4-nat.c
1 /* Native support for the SGI Iris running IRIX version 4, for GDB.
2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1995
3 Free Software Foundation, Inc.
4 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
5 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
6 Implemented for Irix 4.x by Garrett A. Wollman.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23
24 #include "defs.h"
25 #include "inferior.h"
26 #include "gdbcore.h"
27
28 #include <sys/time.h>
29 #include <sys/procfs.h>
30 #include <setjmp.h> /* For JB_XXX. */
31
32 /* Size of elements in jmpbuf */
33
34 #define JB_ELEMENT_SIZE 4
35
36 typedef unsigned int greg_t; /* why isn't this defined? */
37
38 static void
39 fetch_core_registers PARAMS ((char *, unsigned int, int, CORE_ADDR));
40
41 /*
42 * See the comment in m68k-tdep.c regarding the utility of these functions.
43 */
44
45 void
46 supply_gregset (gregsetp)
47 gregset_t *gregsetp;
48 {
49 register int regi;
50 register greg_t *regp = (greg_t *)(gregsetp->gp_regs);
51 static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0};
52
53 /* FIXME: somewhere, there should be a #define for the meaning
54 of this magic number 32; we should use that. */
55 for(regi = 0; regi < 32; regi++)
56 supply_register (regi, (char *)(regp + regi));
57
58 supply_register (PC_REGNUM, (char *)&(gregsetp->gp_pc));
59 supply_register (HI_REGNUM, (char *)&(gregsetp->gp_mdhi));
60 supply_register (LO_REGNUM, (char *)&(gregsetp->gp_mdlo));
61 supply_register (CAUSE_REGNUM, (char *)&(gregsetp->gp_cause));
62
63 /* Fill inaccessible registers with zero. */
64 supply_register (BADVADDR_REGNUM, zerobuf);
65 }
66
67 void
68 fill_gregset (gregsetp, regno)
69 gregset_t *gregsetp;
70 int regno;
71 {
72 int regi;
73 register greg_t *regp = (greg_t *)(gregsetp->gp_regs);
74
75 /* same FIXME as above wrt 32*/
76 for (regi = 0; regi < 32; regi++)
77 if ((regno == -1) || (regno == regi))
78 *(regp + regi) = *(greg_t *) &registers[REGISTER_BYTE (regi)];
79
80 if ((regno == -1) || (regno == PC_REGNUM))
81 gregsetp->gp_pc = *(greg_t *) &registers[REGISTER_BYTE (PC_REGNUM)];
82
83 if ((regno == -1) || (regno == CAUSE_REGNUM))
84 gregsetp->gp_cause = *(greg_t *) &registers[REGISTER_BYTE (CAUSE_REGNUM)];
85
86 if ((regno == -1) || (regno == HI_REGNUM))
87 gregsetp->gp_mdhi = *(greg_t *) &registers[REGISTER_BYTE (HI_REGNUM)];
88
89 if ((regno == -1) || (regno == LO_REGNUM))
90 gregsetp->gp_mdlo = *(greg_t *) &registers[REGISTER_BYTE (LO_REGNUM)];
91 }
92
93 /*
94 * Now we do the same thing for floating-point registers.
95 * We don't bother to condition on FP0_REGNUM since any
96 * reasonable MIPS configuration has an R3010 in it.
97 *
98 * Again, see the comments in m68k-tdep.c.
99 */
100
101 void
102 supply_fpregset (fpregsetp)
103 fpregset_t *fpregsetp;
104 {
105 register int regi;
106 static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0};
107
108 for (regi = 0; regi < 32; regi++)
109 supply_register (FP0_REGNUM + regi,
110 (char *)&fpregsetp->fp_r.fp_regs[regi]);
111
112 supply_register (FCRCS_REGNUM, (char *)&fpregsetp->fp_csr);
113
114 /* FIXME: how can we supply FCRIR_REGNUM? SGI doesn't tell us. */
115 supply_register (FCRIR_REGNUM, zerobuf);
116 }
117
118 void
119 fill_fpregset (fpregsetp, regno)
120 fpregset_t *fpregsetp;
121 int regno;
122 {
123 int regi;
124 char *from, *to;
125
126 for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++)
127 {
128 if ((regno == -1) || (regno == regi))
129 {
130 from = (char *) &registers[REGISTER_BYTE (regi)];
131 to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]);
132 memcpy(to, from, REGISTER_RAW_SIZE (regi));
133 }
134 }
135
136 if ((regno == -1) || (regno == FCRCS_REGNUM))
137 fpregsetp->fp_csr = *(unsigned *) &registers[REGISTER_BYTE(FCRCS_REGNUM)];
138 }
139
140
141 /* Figure out where the longjmp will land.
142 We expect the first arg to be a pointer to the jmp_buf structure from which
143 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
144 This routine returns true on success. */
145
146 int
147 get_longjmp_target (pc)
148 CORE_ADDR *pc;
149 {
150 char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
151 CORE_ADDR jb_addr;
152
153 jb_addr = read_register (A0_REGNUM);
154
155 if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
156 TARGET_PTR_BIT / TARGET_CHAR_BIT))
157 return 0;
158
159 *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
160
161 return 1;
162 }
163
164 static void
165 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
166 char *core_reg_sect;
167 unsigned core_reg_size;
168 int which; /* Unused */
169 CORE_ADDR reg_addr; /* Unused */
170 {
171 if (core_reg_size != REGISTER_BYTES)
172 {
173 warning ("wrong size gregset struct in core file");
174 return;
175 }
176
177 memcpy ((char *)registers, core_reg_sect, core_reg_size);
178 }
179
180 \f
181 /* Register that we are able to handle irix4 core file formats.
182 FIXME: is this really bfd_target_unknown_flavour? */
183
184 static struct core_fns irix4_core_fns =
185 {
186 bfd_target_unknown_flavour,
187 fetch_core_registers,
188 NULL
189 };
190
191 void
192 _initialize_core_irix4 ()
193 {
194 add_core_fns (&irix4_core_fns);
195 }