1 /* Native support for MIPS running SVR4, for GDB.
2 Copyright 1994, 1995, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
28 #include <sys/procfs.h>
29 #include <setjmp.h> /* For JB_XXX. */
31 /* Prototypes for supply_gregset etc. */
34 /* Size of elements in jmpbuf */
36 #define JB_ELEMENT_SIZE 4
39 * See the comment in m68k-tdep.c regarding the utility of these functions.
41 * These definitions are from the MIPS SVR4 ABI, so they may work for
42 * any MIPS SVR4 target.
46 supply_gregset (gregset_t
*gregsetp
)
49 greg_t
*regp
= &(*gregsetp
)[0];
50 char zerobuf
[MAX_REGISTER_SIZE
];
51 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
53 for (regi
= 0; regi
<= CXT_RA
; regi
++)
54 regcache_raw_supply (current_regcache
, regi
, (char *) (regp
+ regi
));
56 regcache_raw_supply (current_regcache
, mips_regnum (current_gdbarch
)->pc
,
57 (char *) (regp
+ CXT_EPC
));
58 regcache_raw_supply (current_regcache
, mips_regnum (current_gdbarch
)->hi
,
59 (char *) (regp
+ CXT_MDHI
));
60 regcache_raw_supply (current_regcache
, mips_regnum (current_gdbarch
)->lo
,
61 (char *) (regp
+ CXT_MDLO
));
62 regcache_raw_supply (current_regcache
, mips_regnum (current_gdbarch
)->cause
,
63 (char *) (regp
+ CXT_CAUSE
));
65 /* Fill inaccessible registers with zero. */
66 regcache_raw_supply (current_regcache
, MIPS_PS_REGNUM
, zerobuf
);
67 regcache_raw_supply (current_regcache
,
68 mips_regnum (current_gdbarch
)->badvaddr
,
70 regcache_raw_supply (current_regcache
, DEPRECATED_FP_REGNUM
, zerobuf
);
71 regcache_raw_supply (current_regcache
, MIPS_UNUSED_REGNUM
, zerobuf
);
72 for (regi
= MIPS_FIRST_EMBED_REGNUM
; regi
<= MIPS_LAST_EMBED_REGNUM
; regi
++)
73 regcache_raw_supply (current_regcache
, regi
, zerobuf
);
77 fill_gregset (gregset_t
*gregsetp
, int regno
)
80 greg_t
*regp
= &(*gregsetp
)[0];
82 for (regi
= 0; regi
<= 32; regi
++)
83 if ((regno
== -1) || (regno
== regi
))
84 *(regp
+ regi
) = *(greg_t
*) & deprecated_registers
[DEPRECATED_REGISTER_BYTE (regi
)];
86 if ((regno
== -1) || (regno
== mips_regnum (current_gdbarch
)->pc
))
87 *(regp
+ CXT_EPC
) = *(greg_t
*) & deprecated_registers
[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch
)->pc
)];
89 if ((regno
== -1) || (regno
== mips_regnum (current_gdbarch
)->cause
))
90 *(regp
+ CXT_CAUSE
) = *(greg_t
*) & deprecated_registers
[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch
)->cause
)];
92 if ((regno
== -1) || (regno
== mips_regnum (current_gdbarch
)->hi
))
93 *(regp
+ CXT_MDHI
) = *(greg_t
*) & deprecated_registers
[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch
)->hi
)];
95 if ((regno
== -1) || (regno
== mips_regnum (current_gdbarch
)->lo
))
96 *(regp
+ CXT_MDLO
) = *(greg_t
*) & deprecated_registers
[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch
)->lo
)];
100 * Now we do the same thing for floating-point registers.
101 * We don't bother to condition on FP0 regnum since any
102 * reasonable MIPS configuration has an R3010 in it.
104 * Again, see the comments in m68k-tdep.c.
108 supply_fpregset (fpregset_t
*fpregsetp
)
111 char zerobuf
[MAX_REGISTER_SIZE
];
112 memset (zerobuf
, 0, MAX_REGISTER_SIZE
);
114 for (regi
= 0; regi
< 32; regi
++)
115 regcache_raw_supply (current_regcache
,
116 mips_regnum (current_gdbarch
)->fp0
+ regi
,
117 (char *) &fpregsetp
->fp_r
.fp_regs
[regi
]);
119 regcache_raw_supply (current_regcache
,
120 mips_regnum (current_gdbarch
)->fp_control_status
,
121 (char *) &fpregsetp
->fp_csr
);
123 /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */
124 regcache_raw_supply (current_regcache
,
125 mips_regnum (current_gdbarch
)->fp_implementation_revision
,
130 fill_fpregset (fpregset_t
*fpregsetp
, int regno
)
135 for (regi
= mips_regnum (current_gdbarch
)->fp0
;
136 regi
< mips_regnum (current_gdbarch
)->fp0
+ 32; regi
++)
138 if ((regno
== -1) || (regno
== regi
))
140 from
= (char *) &deprecated_registers
[DEPRECATED_REGISTER_BYTE (regi
)];
141 to
= (char *) &(fpregsetp
->fp_r
.fp_regs
[regi
- mips_regnum (current_gdbarch
)->fp0
]);
142 memcpy (to
, from
, register_size (current_gdbarch
, regi
));
147 || (regno
== mips_regnum (current_gdbarch
)->fp_control_status
))
148 fpregsetp
->fp_csr
= *(unsigned *) &deprecated_registers
[DEPRECATED_REGISTER_BYTE (mips_regnum (current_gdbarch
)->fp_control_status
)];
152 /* Figure out where the longjmp will land.
153 We expect the first arg to be a pointer to the jmp_buf structure from which
154 we extract the pc (_JB_PC) that we will land at. The pc is copied into PC.
155 This routine returns true on success. */
158 get_longjmp_target (CORE_ADDR
*pc
)
163 buf
= alloca (TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
164 jb_addr
= read_register (MIPS_A0_REGNUM
);
166 if (target_read_memory (jb_addr
+ _JB_PC
* JB_ELEMENT_SIZE
, buf
,
167 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
170 *pc
= extract_unsigned_integer (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);