Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Native support for the SGI Iris running IRIX version 4, for GDB. |
b6ba6518 KB |
2 | Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1996, 1999, 2000, |
3 | 2001 Free Software Foundation, Inc. | |
c906108c SS |
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 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
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. | |
c906108c | 14 | |
c5aa993b JM |
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. | |
c906108c | 19 | |
c5aa993b JM |
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, | |
23 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
24 | |
25 | #include "defs.h" | |
26 | #include "inferior.h" | |
27 | #include "gdbcore.h" | |
4e052eda | 28 | #include "regcache.h" |
c906108c SS |
29 | |
30 | #include <sys/time.h> | |
31 | #include <sys/procfs.h> | |
32 | #include <setjmp.h> /* For JB_XXX. */ | |
33 | ||
c60c0f5f MS |
34 | /* Prototypes for supply_gregset etc. */ |
35 | #include "gregset.h" | |
36 | ||
c906108c SS |
37 | /* Size of elements in jmpbuf */ |
38 | ||
39 | #define JB_ELEMENT_SIZE 4 | |
40 | ||
41 | typedef unsigned int greg_t; /* why isn't this defined? */ | |
42 | ||
a14ed312 | 43 | static void fetch_core_registers (char *, unsigned int, int, CORE_ADDR); |
c906108c SS |
44 | |
45 | /* | |
46 | * See the comment in m68k-tdep.c regarding the utility of these functions. | |
47 | */ | |
48 | ||
c5aa993b | 49 | void |
fba45db2 | 50 | supply_gregset (gregset_t *gregsetp) |
c906108c SS |
51 | { |
52 | register int regi; | |
c5aa993b | 53 | register greg_t *regp = (greg_t *) (gregsetp->gp_regs); |
6789195b AC |
54 | char *zerobuf = alloca (max_register_size (current_gdbarch)); |
55 | memset (zerobuf, 0, max_register_size (current_gdbarch)); | |
c906108c SS |
56 | |
57 | /* FIXME: somewhere, there should be a #define for the meaning | |
58 | of this magic number 32; we should use that. */ | |
c5aa993b JM |
59 | for (regi = 0; regi < 32; regi++) |
60 | supply_register (regi, (char *) (regp + regi)); | |
c906108c | 61 | |
c5aa993b JM |
62 | supply_register (PC_REGNUM, (char *) &(gregsetp->gp_pc)); |
63 | supply_register (HI_REGNUM, (char *) &(gregsetp->gp_mdhi)); | |
64 | supply_register (LO_REGNUM, (char *) &(gregsetp->gp_mdlo)); | |
65 | supply_register (CAUSE_REGNUM, (char *) &(gregsetp->gp_cause)); | |
c906108c SS |
66 | |
67 | /* Fill inaccessible registers with zero. */ | |
68 | supply_register (BADVADDR_REGNUM, zerobuf); | |
69 | } | |
70 | ||
71 | void | |
fba45db2 | 72 | fill_gregset (gregset_t *gregsetp, int regno) |
c906108c SS |
73 | { |
74 | int regi; | |
c5aa993b | 75 | register greg_t *regp = (greg_t *) (gregsetp->gp_regs); |
c906108c | 76 | |
c5aa993b | 77 | /* same FIXME as above wrt 32 */ |
c906108c SS |
78 | for (regi = 0; regi < 32; regi++) |
79 | if ((regno == -1) || (regno == regi)) | |
524d7c18 | 80 | *(regp + regi) = *(greg_t *) & deprecated_registers[REGISTER_BYTE (regi)]; |
c906108c SS |
81 | |
82 | if ((regno == -1) || (regno == PC_REGNUM)) | |
524d7c18 | 83 | gregsetp->gp_pc = *(greg_t *) & deprecated_registers[REGISTER_BYTE (PC_REGNUM)]; |
c906108c SS |
84 | |
85 | if ((regno == -1) || (regno == CAUSE_REGNUM)) | |
524d7c18 | 86 | gregsetp->gp_cause = *(greg_t *) & deprecated_registers[REGISTER_BYTE (CAUSE_REGNUM)]; |
c906108c SS |
87 | |
88 | if ((regno == -1) || (regno == HI_REGNUM)) | |
524d7c18 | 89 | gregsetp->gp_mdhi = *(greg_t *) & deprecated_registers[REGISTER_BYTE (HI_REGNUM)]; |
c906108c SS |
90 | |
91 | if ((regno == -1) || (regno == LO_REGNUM)) | |
524d7c18 | 92 | gregsetp->gp_mdlo = *(greg_t *) & deprecated_registers[REGISTER_BYTE (LO_REGNUM)]; |
c906108c SS |
93 | } |
94 | ||
95 | /* | |
96 | * Now we do the same thing for floating-point registers. | |
97 | * We don't bother to condition on FP0_REGNUM since any | |
98 | * reasonable MIPS configuration has an R3010 in it. | |
99 | * | |
100 | * Again, see the comments in m68k-tdep.c. | |
101 | */ | |
102 | ||
103 | void | |
fba45db2 | 104 | supply_fpregset (fpregset_t *fpregsetp) |
c906108c SS |
105 | { |
106 | register int regi; | |
6789195b AC |
107 | char *zerobuf = alloca (max_register_size (current_gdbarch)); |
108 | memset (zerobuf, 0, max_register_size (current_gdbarch)); | |
c906108c SS |
109 | |
110 | for (regi = 0; regi < 32; regi++) | |
111 | supply_register (FP0_REGNUM + regi, | |
c5aa993b | 112 | (char *) &fpregsetp->fp_r.fp_regs[regi]); |
c906108c | 113 | |
c5aa993b | 114 | supply_register (FCRCS_REGNUM, (char *) &fpregsetp->fp_csr); |
c906108c SS |
115 | |
116 | /* FIXME: how can we supply FCRIR_REGNUM? SGI doesn't tell us. */ | |
117 | supply_register (FCRIR_REGNUM, zerobuf); | |
118 | } | |
119 | ||
120 | void | |
fba45db2 | 121 | fill_fpregset (fpregset_t *fpregsetp, int regno) |
c906108c SS |
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 | { | |
524d7c18 | 130 | from = (char *) &deprecated_registers[REGISTER_BYTE (regi)]; |
c906108c | 131 | to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]); |
c5aa993b | 132 | memcpy (to, from, REGISTER_RAW_SIZE (regi)); |
c906108c SS |
133 | } |
134 | } | |
135 | ||
136 | if ((regno == -1) || (regno == FCRCS_REGNUM)) | |
524d7c18 | 137 | fpregsetp->fp_csr = *(unsigned *) &deprecated_registers[REGISTER_BYTE (FCRCS_REGNUM)]; |
c906108c SS |
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 | |
fba45db2 | 147 | get_longjmp_target (CORE_ADDR *pc) |
c906108c | 148 | { |
35fc8285 | 149 | char *buf; |
c906108c SS |
150 | CORE_ADDR jb_addr; |
151 | ||
35fc8285 | 152 | buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c906108c SS |
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 | ||
16bce26c KB |
164 | /* Provide registers to GDB from a core file. |
165 | ||
166 | CORE_REG_SECT points to an array of bytes, which were obtained from | |
167 | a core file which BFD thinks might contain register contents. | |
168 | CORE_REG_SIZE is its size. | |
169 | ||
170 | Normally, WHICH says which register set corelow suspects this is: | |
171 | 0 --- the general-purpose register set | |
172 | 2 --- the floating-point register set | |
173 | However, for Irix 4, WHICH isn't used. | |
174 | ||
175 | REG_ADDR is also unused. */ | |
176 | ||
c906108c | 177 | static void |
16bce26c KB |
178 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, |
179 | int which, CORE_ADDR reg_addr) | |
c906108c SS |
180 | { |
181 | if (core_reg_size != REGISTER_BYTES) | |
182 | { | |
183 | warning ("wrong size gregset struct in core file"); | |
184 | return; | |
185 | } | |
186 | ||
524d7c18 | 187 | memcpy ((char *) deprecated_registers, core_reg_sect, core_reg_size); |
c906108c | 188 | } |
c906108c | 189 | \f |
c5aa993b | 190 | |
c906108c SS |
191 | /* Register that we are able to handle irix4 core file formats. |
192 | FIXME: is this really bfd_target_unknown_flavour? */ | |
193 | ||
194 | static struct core_fns irix4_core_fns = | |
195 | { | |
2acceee2 JM |
196 | bfd_target_unknown_flavour, /* core_flavour */ |
197 | default_check_format, /* check_format */ | |
198 | default_core_sniffer, /* core_sniffer */ | |
199 | fetch_core_registers, /* core_read_registers */ | |
200 | NULL /* next */ | |
c906108c SS |
201 | }; |
202 | ||
203 | void | |
fba45db2 | 204 | _initialize_core_irix4 (void) |
c906108c SS |
205 | { |
206 | add_core_fns (&irix4_core_fns); | |
207 | } |