OSDN Git Service

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