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