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