Commit | Line | Data |
---|---|---|
c906108c SS |
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 | ||
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" | |
28 | ||
29 | #include <sys/time.h> | |
30 | #include <sys/procfs.h> | |
31 | #include <setjmp.h> /* For JB_XXX. */ | |
32 | ||
c60c0f5f MS |
33 | /* Prototypes for supply_gregset etc. */ |
34 | #include "gregset.h" | |
35 | ||
c906108c SS |
36 | /* Size of elements in jmpbuf */ |
37 | ||
38 | #define JB_ELEMENT_SIZE 4 | |
39 | ||
40 | typedef unsigned int greg_t; /* why isn't this defined? */ | |
41 | ||
a14ed312 | 42 | static void fetch_core_registers (char *, unsigned int, int, CORE_ADDR); |
c906108c SS |
43 | |
44 | /* | |
45 | * See the comment in m68k-tdep.c regarding the utility of these functions. | |
46 | */ | |
47 | ||
c5aa993b | 48 | void |
fba45db2 | 49 | supply_gregset (gregset_t *gregsetp) |
c906108c SS |
50 | { |
51 | register int regi; | |
c5aa993b JM |
52 | register greg_t *regp = (greg_t *) (gregsetp->gp_regs); |
53 | static char zerobuf[MAX_REGISTER_RAW_SIZE] = | |
54 | {0}; | |
c906108c SS |
55 | |
56 | /* FIXME: somewhere, there should be a #define for the meaning | |
57 | of this magic number 32; we should use that. */ | |
c5aa993b JM |
58 | for (regi = 0; regi < 32; regi++) |
59 | supply_register (regi, (char *) (regp + regi)); | |
c906108c | 60 | |
c5aa993b JM |
61 | supply_register (PC_REGNUM, (char *) &(gregsetp->gp_pc)); |
62 | supply_register (HI_REGNUM, (char *) &(gregsetp->gp_mdhi)); | |
63 | supply_register (LO_REGNUM, (char *) &(gregsetp->gp_mdlo)); | |
64 | supply_register (CAUSE_REGNUM, (char *) &(gregsetp->gp_cause)); | |
c906108c SS |
65 | |
66 | /* Fill inaccessible registers with zero. */ | |
67 | supply_register (BADVADDR_REGNUM, zerobuf); | |
68 | } | |
69 | ||
70 | void | |
fba45db2 | 71 | fill_gregset (gregset_t *gregsetp, int regno) |
c906108c SS |
72 | { |
73 | int regi; | |
c5aa993b | 74 | register greg_t *regp = (greg_t *) (gregsetp->gp_regs); |
c906108c | 75 | |
c5aa993b | 76 | /* same FIXME as above wrt 32 */ |
c906108c SS |
77 | for (regi = 0; regi < 32; regi++) |
78 | if ((regno == -1) || (regno == regi)) | |
c5aa993b | 79 | *(regp + regi) = *(greg_t *) & registers[REGISTER_BYTE (regi)]; |
c906108c SS |
80 | |
81 | if ((regno == -1) || (regno == PC_REGNUM)) | |
c5aa993b | 82 | gregsetp->gp_pc = *(greg_t *) & registers[REGISTER_BYTE (PC_REGNUM)]; |
c906108c SS |
83 | |
84 | if ((regno == -1) || (regno == CAUSE_REGNUM)) | |
c5aa993b | 85 | gregsetp->gp_cause = *(greg_t *) & registers[REGISTER_BYTE (CAUSE_REGNUM)]; |
c906108c SS |
86 | |
87 | if ((regno == -1) || (regno == HI_REGNUM)) | |
c5aa993b | 88 | gregsetp->gp_mdhi = *(greg_t *) & registers[REGISTER_BYTE (HI_REGNUM)]; |
c906108c SS |
89 | |
90 | if ((regno == -1) || (regno == LO_REGNUM)) | |
c5aa993b | 91 | gregsetp->gp_mdlo = *(greg_t *) & registers[REGISTER_BYTE (LO_REGNUM)]; |
c906108c SS |
92 | } |
93 | ||
94 | /* | |
95 | * Now we do the same thing for floating-point registers. | |
96 | * We don't bother to condition on FP0_REGNUM since any | |
97 | * reasonable MIPS configuration has an R3010 in it. | |
98 | * | |
99 | * Again, see the comments in m68k-tdep.c. | |
100 | */ | |
101 | ||
102 | void | |
fba45db2 | 103 | supply_fpregset (fpregset_t *fpregsetp) |
c906108c SS |
104 | { |
105 | register int regi; | |
c5aa993b JM |
106 | static char zerobuf[MAX_REGISTER_RAW_SIZE] = |
107 | {0}; | |
c906108c SS |
108 | |
109 | for (regi = 0; regi < 32; regi++) | |
110 | supply_register (FP0_REGNUM + regi, | |
c5aa993b | 111 | (char *) &fpregsetp->fp_r.fp_regs[regi]); |
c906108c | 112 | |
c5aa993b | 113 | supply_register (FCRCS_REGNUM, (char *) &fpregsetp->fp_csr); |
c906108c SS |
114 | |
115 | /* FIXME: how can we supply FCRIR_REGNUM? SGI doesn't tell us. */ | |
116 | supply_register (FCRIR_REGNUM, zerobuf); | |
117 | } | |
118 | ||
119 | void | |
fba45db2 | 120 | fill_fpregset (fpregset_t *fpregsetp, int regno) |
c906108c SS |
121 | { |
122 | int regi; | |
123 | char *from, *to; | |
124 | ||
125 | for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++) | |
126 | { | |
127 | if ((regno == -1) || (regno == regi)) | |
128 | { | |
129 | from = (char *) ®isters[REGISTER_BYTE (regi)]; | |
130 | to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]); | |
c5aa993b | 131 | memcpy (to, from, REGISTER_RAW_SIZE (regi)); |
c906108c SS |
132 | } |
133 | } | |
134 | ||
135 | if ((regno == -1) || (regno == FCRCS_REGNUM)) | |
c5aa993b | 136 | fpregsetp->fp_csr = *(unsigned *) ®isters[REGISTER_BYTE (FCRCS_REGNUM)]; |
c906108c SS |
137 | } |
138 | ||
139 | ||
140 | /* Figure out where the longjmp will land. | |
141 | We expect the first arg to be a pointer to the jmp_buf structure from which | |
142 | we extract the pc (JB_PC) that we will land at. The pc is copied into PC. | |
143 | This routine returns true on success. */ | |
144 | ||
145 | int | |
fba45db2 | 146 | get_longjmp_target (CORE_ADDR *pc) |
c906108c | 147 | { |
35fc8285 | 148 | char *buf; |
c906108c SS |
149 | CORE_ADDR jb_addr; |
150 | ||
35fc8285 | 151 | buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c906108c SS |
152 | jb_addr = read_register (A0_REGNUM); |
153 | ||
154 | if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf, | |
155 | TARGET_PTR_BIT / TARGET_CHAR_BIT)) | |
156 | return 0; | |
157 | ||
158 | *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
159 | ||
160 | return 1; | |
161 | } | |
162 | ||
16bce26c KB |
163 | /* Provide registers to GDB from a core file. |
164 | ||
165 | CORE_REG_SECT points to an array of bytes, which were obtained from | |
166 | a core file which BFD thinks might contain register contents. | |
167 | CORE_REG_SIZE is its size. | |
168 | ||
169 | Normally, WHICH says which register set corelow suspects this is: | |
170 | 0 --- the general-purpose register set | |
171 | 2 --- the floating-point register set | |
172 | However, for Irix 4, WHICH isn't used. | |
173 | ||
174 | REG_ADDR is also unused. */ | |
175 | ||
c906108c | 176 | static void |
16bce26c KB |
177 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, |
178 | int which, CORE_ADDR reg_addr) | |
c906108c SS |
179 | { |
180 | if (core_reg_size != REGISTER_BYTES) | |
181 | { | |
182 | warning ("wrong size gregset struct in core file"); | |
183 | return; | |
184 | } | |
185 | ||
c5aa993b | 186 | memcpy ((char *) registers, core_reg_sect, core_reg_size); |
c906108c | 187 | } |
c906108c | 188 | \f |
c5aa993b | 189 | |
c906108c SS |
190 | /* Register that we are able to handle irix4 core file formats. |
191 | FIXME: is this really bfd_target_unknown_flavour? */ | |
192 | ||
193 | static struct core_fns irix4_core_fns = | |
194 | { | |
2acceee2 JM |
195 | bfd_target_unknown_flavour, /* core_flavour */ |
196 | default_check_format, /* check_format */ | |
197 | default_core_sniffer, /* core_sniffer */ | |
198 | fetch_core_registers, /* core_read_registers */ | |
199 | NULL /* next */ | |
c906108c SS |
200 | }; |
201 | ||
202 | void | |
fba45db2 | 203 | _initialize_core_irix4 (void) |
c906108c SS |
204 | { |
205 | add_core_fns (&irix4_core_fns); | |
206 | } |