]>
Commit | Line | Data |
---|---|---|
75c9abc6 | 1 | /* Target-dependent code for GNU/Linux on MIPS processors. |
a094c6fb | 2 | |
0fb0cc75 | 3 | Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009 |
76a9d10f | 4 | Free Software Foundation, Inc. |
2aa830e4 DJ |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
2aa830e4 DJ |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
2aa830e4 DJ |
20 | |
21 | #include "defs.h" | |
22 | #include "gdbcore.h" | |
23 | #include "target.h" | |
24 | #include "solib-svr4.h" | |
19ed69dd | 25 | #include "osabi.h" |
96f026fc | 26 | #include "mips-tdep.h" |
19ed69dd | 27 | #include "gdb_string.h" |
96f026fc | 28 | #include "gdb_assert.h" |
6de918a6 | 29 | #include "frame.h" |
2fdf551c | 30 | #include "regcache.h" |
5792a79b DJ |
31 | #include "trad-frame.h" |
32 | #include "tramp-frame.h" | |
e6bb342a | 33 | #include "gdbtypes.h" |
5ea03926 | 34 | #include "solib.h" |
7d522c90 DJ |
35 | #include "solib-svr4.h" |
36 | #include "solist.h" | |
982e9687 | 37 | #include "symtab.h" |
822b6570 | 38 | #include "target-descriptions.h" |
d37eb719 | 39 | #include "mips-linux-tdep.h" |
db5f024e | 40 | #include "glibc-tdep.h" |
2aa830e4 | 41 | |
7d522c90 DJ |
42 | static struct target_so_ops mips_svr4_so_ops; |
43 | ||
2aa830e4 | 44 | /* Figure out where the longjmp will land. |
295093a4 MS |
45 | We expect the first arg to be a pointer to the jmp_buf structure |
46 | from which we extract the pc (MIPS_LINUX_JB_PC) that we will land | |
47 | at. The pc is copied into PC. This routine returns 1 on | |
48 | success. */ | |
2aa830e4 | 49 | |
19ed69dd KB |
50 | #define MIPS_LINUX_JB_ELEMENT_SIZE 4 |
51 | #define MIPS_LINUX_JB_PC 0 | |
52 | ||
53 | static int | |
60ade65d | 54 | mips_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc) |
2aa830e4 DJ |
55 | { |
56 | CORE_ADDR jb_addr; | |
2eb4d78b UW |
57 | struct gdbarch *gdbarch = get_frame_arch (frame); |
58 | char buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT]; | |
2aa830e4 | 59 | |
60ade65d | 60 | jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM); |
2aa830e4 | 61 | |
bf072999 | 62 | if (target_read_memory (jb_addr |
819844ad | 63 | + MIPS_LINUX_JB_PC * MIPS_LINUX_JB_ELEMENT_SIZE, |
2eb4d78b | 64 | buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT)) |
2aa830e4 DJ |
65 | return 0; |
66 | ||
819844ad | 67 | *pc = extract_unsigned_integer (buf, |
2eb4d78b | 68 | gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT); |
2aa830e4 DJ |
69 | |
70 | return 1; | |
71 | } | |
72 | ||
4246e332 | 73 | /* Transform the bits comprising a 32-bit register to the right size |
23a6d369 AC |
74 | for regcache_raw_supply(). This is needed when mips_isa_regsize() |
75 | is 8. */ | |
96f026fc KB |
76 | |
77 | static void | |
28f5035f | 78 | supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr) |
96f026fc | 79 | { |
d37eb719 | 80 | gdb_byte buf[MAX_REGISTER_SIZE]; |
2eb4d78b UW |
81 | store_signed_integer (buf, |
82 | register_size (get_regcache_arch (regcache), regnum), | |
96f026fc | 83 | extract_signed_integer (addr, 4)); |
28f5035f | 84 | regcache_raw_supply (regcache, regnum, buf); |
96f026fc KB |
85 | } |
86 | ||
2aa830e4 DJ |
87 | /* Unpack an elf_gregset_t into GDB's register cache. */ |
88 | ||
d37eb719 | 89 | void |
28f5035f UW |
90 | mips_supply_gregset (struct regcache *regcache, |
91 | const mips_elf_gregset_t *gregsetp) | |
2aa830e4 DJ |
92 | { |
93 | int regi; | |
28f5035f | 94 | const mips_elf_greg_t *regp = *gregsetp; |
d9d9c31f | 95 | char zerobuf[MAX_REGISTER_SIZE]; |
2eb4d78b | 96 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
bf072999 | 97 | |
d9d9c31f | 98 | memset (zerobuf, 0, MAX_REGISTER_SIZE); |
2aa830e4 | 99 | |
822b6570 | 100 | for (regi = EF_REG0 + 1; regi <= EF_REG31; regi++) |
28f5035f | 101 | supply_32bit_reg (regcache, regi - EF_REG0, regp + regi); |
2aa830e4 | 102 | |
2eb4d78b | 103 | if (mips_linux_restart_reg_p (gdbarch)) |
822b6570 DJ |
104 | supply_32bit_reg (regcache, MIPS_RESTART_REGNUM, regp + EF_REG0); |
105 | ||
2eb4d78b UW |
106 | supply_32bit_reg (regcache, mips_regnum (gdbarch)->lo, regp + EF_LO); |
107 | supply_32bit_reg (regcache, mips_regnum (gdbarch)->hi, regp + EF_HI); | |
56cea623 | 108 | |
2eb4d78b | 109 | supply_32bit_reg (regcache, mips_regnum (gdbarch)->pc, |
28f5035f | 110 | regp + EF_CP0_EPC); |
2eb4d78b | 111 | supply_32bit_reg (regcache, mips_regnum (gdbarch)->badvaddr, |
28f5035f UW |
112 | regp + EF_CP0_BADVADDR); |
113 | supply_32bit_reg (regcache, MIPS_PS_REGNUM, regp + EF_CP0_STATUS); | |
2eb4d78b | 114 | supply_32bit_reg (regcache, mips_regnum (gdbarch)->cause, |
28f5035f | 115 | regp + EF_CP0_CAUSE); |
2aa830e4 DJ |
116 | |
117 | /* Fill inaccessible registers with zero. */ | |
822b6570 | 118 | regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf); |
28f5035f | 119 | regcache_raw_supply (regcache, MIPS_UNUSED_REGNUM, zerobuf); |
295093a4 | 120 | for (regi = MIPS_FIRST_EMBED_REGNUM; |
822b6570 | 121 | regi <= MIPS_LAST_EMBED_REGNUM; |
295093a4 | 122 | regi++) |
28f5035f | 123 | regcache_raw_supply (regcache, regi, zerobuf); |
2aa830e4 DJ |
124 | } |
125 | ||
126 | /* Pack our registers (or one register) into an elf_gregset_t. */ | |
127 | ||
d37eb719 | 128 | void |
28f5035f UW |
129 | mips_fill_gregset (const struct regcache *regcache, |
130 | mips_elf_gregset_t *gregsetp, int regno) | |
2aa830e4 | 131 | { |
2eb4d78b | 132 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
2aa830e4 | 133 | int regaddr, regi; |
d37eb719 | 134 | mips_elf_greg_t *regp = *gregsetp; |
96f026fc | 135 | void *dst; |
2aa830e4 DJ |
136 | |
137 | if (regno == -1) | |
138 | { | |
d37eb719 | 139 | memset (regp, 0, sizeof (mips_elf_gregset_t)); |
822b6570 | 140 | for (regi = 1; regi < 32; regi++) |
28f5035f | 141 | mips_fill_gregset (regcache, gregsetp, regi); |
2eb4d78b UW |
142 | mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo); |
143 | mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi); | |
144 | mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc); | |
145 | mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr); | |
28f5035f | 146 | mips_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM); |
2eb4d78b | 147 | mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause); |
822b6570 | 148 | mips_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM); |
2aa830e4 DJ |
149 | return; |
150 | } | |
151 | ||
822b6570 | 152 | if (regno > 0 && regno < 32) |
2aa830e4 | 153 | { |
2aa830e4 | 154 | dst = regp + regno + EF_REG0; |
28f5035f | 155 | regcache_raw_collect (regcache, regno, dst); |
2aa830e4 DJ |
156 | return; |
157 | } | |
158 | ||
2eb4d78b UW |
159 | if (regno == mips_regnum (gdbarch)->lo) |
160 | regaddr = EF_LO; | |
161 | else if (regno == mips_regnum (gdbarch)->hi) | |
56cea623 | 162 | regaddr = EF_HI; |
2eb4d78b | 163 | else if (regno == mips_regnum (gdbarch)->pc) |
56cea623 | 164 | regaddr = EF_CP0_EPC; |
2eb4d78b | 165 | else if (regno == mips_regnum (gdbarch)->badvaddr) |
56cea623 | 166 | regaddr = EF_CP0_BADVADDR; |
24e05951 | 167 | else if (regno == MIPS_PS_REGNUM) |
56cea623 | 168 | regaddr = EF_CP0_STATUS; |
2eb4d78b | 169 | else if (regno == mips_regnum (gdbarch)->cause) |
56cea623 | 170 | regaddr = EF_CP0_CAUSE; |
2eb4d78b | 171 | else if (mips_linux_restart_reg_p (gdbarch) |
822b6570 DJ |
172 | && regno == MIPS_RESTART_REGNUM) |
173 | regaddr = EF_REG0; | |
56cea623 AC |
174 | else |
175 | regaddr = -1; | |
2aa830e4 DJ |
176 | |
177 | if (regaddr != -1) | |
178 | { | |
2aa830e4 | 179 | dst = regp + regaddr; |
28f5035f | 180 | regcache_raw_collect (regcache, regno, dst); |
2aa830e4 DJ |
181 | } |
182 | } | |
183 | ||
184 | /* Likewise, unpack an elf_fpregset_t. */ | |
185 | ||
d37eb719 | 186 | void |
28f5035f UW |
187 | mips_supply_fpregset (struct regcache *regcache, |
188 | const mips_elf_fpregset_t *fpregsetp) | |
2aa830e4 | 189 | { |
2eb4d78b | 190 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
52f0bd74 | 191 | int regi; |
d9d9c31f | 192 | char zerobuf[MAX_REGISTER_SIZE]; |
bf072999 | 193 | |
d9d9c31f | 194 | memset (zerobuf, 0, MAX_REGISTER_SIZE); |
2aa830e4 DJ |
195 | |
196 | for (regi = 0; regi < 32; regi++) | |
3e8c568d | 197 | regcache_raw_supply (regcache, |
2eb4d78b | 198 | gdbarch_fp0_regnum (gdbarch) + regi, |
3e8c568d | 199 | *fpregsetp + regi); |
2aa830e4 | 200 | |
28f5035f | 201 | regcache_raw_supply (regcache, |
2eb4d78b | 202 | mips_regnum (gdbarch)->fp_control_status, |
28f5035f | 203 | *fpregsetp + 32); |
2aa830e4 | 204 | |
295093a4 | 205 | /* FIXME: how can we supply FCRIR? The ABI doesn't tell us. */ |
28f5035f | 206 | regcache_raw_supply (regcache, |
2eb4d78b | 207 | mips_regnum (gdbarch)->fp_implementation_revision, |
23a6d369 | 208 | zerobuf); |
2aa830e4 DJ |
209 | } |
210 | ||
211 | /* Likewise, pack one or all floating point registers into an | |
212 | elf_fpregset_t. */ | |
213 | ||
d37eb719 | 214 | void |
28f5035f UW |
215 | mips_fill_fpregset (const struct regcache *regcache, |
216 | mips_elf_fpregset_t *fpregsetp, int regno) | |
2aa830e4 | 217 | { |
2eb4d78b | 218 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
2aa830e4 DJ |
219 | char *from, *to; |
220 | ||
2eb4d78b UW |
221 | if ((regno >= gdbarch_fp0_regnum (gdbarch)) |
222 | && (regno < gdbarch_fp0_regnum (gdbarch) + 32)) | |
2aa830e4 | 223 | { |
2eb4d78b | 224 | to = (char *) (*fpregsetp + regno - gdbarch_fp0_regnum (gdbarch)); |
28f5035f | 225 | regcache_raw_collect (regcache, regno, to); |
2aa830e4 | 226 | } |
2eb4d78b | 227 | else if (regno == mips_regnum (gdbarch)->fp_control_status) |
2aa830e4 | 228 | { |
2aa830e4 | 229 | to = (char *) (*fpregsetp + 32); |
28f5035f | 230 | regcache_raw_collect (regcache, regno, to); |
2aa830e4 DJ |
231 | } |
232 | else if (regno == -1) | |
233 | { | |
234 | int regi; | |
235 | ||
236 | for (regi = 0; regi < 32; regi++) | |
3e8c568d | 237 | mips_fill_fpregset (regcache, fpregsetp, |
2eb4d78b | 238 | gdbarch_fp0_regnum (gdbarch) + regi); |
28f5035f | 239 | mips_fill_fpregset (regcache, fpregsetp, |
2eb4d78b | 240 | mips_regnum (gdbarch)->fp_control_status); |
2aa830e4 DJ |
241 | } |
242 | } | |
243 | ||
96f026fc KB |
244 | /* Support for 64-bit ABIs. */ |
245 | ||
96f026fc | 246 | /* Figure out where the longjmp will land. |
295093a4 MS |
247 | We expect the first arg to be a pointer to the jmp_buf structure |
248 | from which we extract the pc (MIPS_LINUX_JB_PC) that we will land | |
249 | at. The pc is copied into PC. This routine returns 1 on | |
250 | success. */ | |
96f026fc KB |
251 | |
252 | /* Details about jmp_buf. */ | |
253 | ||
254 | #define MIPS64_LINUX_JB_PC 0 | |
255 | ||
256 | static int | |
60ade65d | 257 | mips64_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc) |
96f026fc KB |
258 | { |
259 | CORE_ADDR jb_addr; | |
2eb4d78b UW |
260 | struct gdbarch *gdbarch = get_frame_arch (frame); |
261 | void *buf = alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT); | |
262 | int element_size = gdbarch_ptr_bit (gdbarch) == 32 ? 4 : 8; | |
96f026fc | 263 | |
60ade65d | 264 | jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM); |
96f026fc KB |
265 | |
266 | if (target_read_memory (jb_addr + MIPS64_LINUX_JB_PC * element_size, | |
819844ad | 267 | buf, |
2eb4d78b | 268 | gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT)) |
96f026fc KB |
269 | return 0; |
270 | ||
819844ad | 271 | *pc = extract_unsigned_integer (buf, |
2eb4d78b | 272 | gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT); |
96f026fc KB |
273 | |
274 | return 1; | |
275 | } | |
276 | ||
d37eb719 DJ |
277 | /* Register set support functions. These operate on standard 64-bit |
278 | regsets, but work whether the target is 32-bit or 64-bit. A 32-bit | |
279 | target will still use the 64-bit format for PTRACE_GETREGS. */ | |
280 | ||
281 | /* Supply a 64-bit register. */ | |
96f026fc | 282 | |
63807e1d | 283 | static void |
28f5035f UW |
284 | supply_64bit_reg (struct regcache *regcache, int regnum, |
285 | const gdb_byte *buf) | |
d37eb719 | 286 | { |
2eb4d78b UW |
287 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
288 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG | |
289 | && register_size (gdbarch, regnum) == 4) | |
28f5035f | 290 | regcache_raw_supply (regcache, regnum, buf + 4); |
d37eb719 | 291 | else |
28f5035f | 292 | regcache_raw_supply (regcache, regnum, buf); |
d37eb719 DJ |
293 | } |
294 | ||
295 | /* Unpack a 64-bit elf_gregset_t into GDB's register cache. */ | |
296 | ||
297 | void | |
28f5035f UW |
298 | mips64_supply_gregset (struct regcache *regcache, |
299 | const mips64_elf_gregset_t *gregsetp) | |
96f026fc KB |
300 | { |
301 | int regi; | |
28f5035f | 302 | const mips64_elf_greg_t *regp = *gregsetp; |
d37eb719 | 303 | gdb_byte zerobuf[MAX_REGISTER_SIZE]; |
2eb4d78b | 304 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
96f026fc | 305 | |
d9d9c31f | 306 | memset (zerobuf, 0, MAX_REGISTER_SIZE); |
96f026fc | 307 | |
822b6570 | 308 | for (regi = MIPS64_EF_REG0 + 1; regi <= MIPS64_EF_REG31; regi++) |
28f5035f UW |
309 | supply_64bit_reg (regcache, regi - MIPS64_EF_REG0, |
310 | (const gdb_byte *)(regp + regi)); | |
311 | ||
2eb4d78b | 312 | if (mips_linux_restart_reg_p (gdbarch)) |
822b6570 DJ |
313 | supply_64bit_reg (regcache, MIPS_RESTART_REGNUM, |
314 | (const gdb_byte *)(regp + MIPS64_EF_REG0)); | |
315 | ||
2eb4d78b | 316 | supply_64bit_reg (regcache, mips_regnum (gdbarch)->lo, |
28f5035f | 317 | (const gdb_byte *) (regp + MIPS64_EF_LO)); |
2eb4d78b | 318 | supply_64bit_reg (regcache, mips_regnum (gdbarch)->hi, |
28f5035f UW |
319 | (const gdb_byte *) (regp + MIPS64_EF_HI)); |
320 | ||
2eb4d78b | 321 | supply_64bit_reg (regcache, mips_regnum (gdbarch)->pc, |
28f5035f | 322 | (const gdb_byte *) (regp + MIPS64_EF_CP0_EPC)); |
2eb4d78b | 323 | supply_64bit_reg (regcache, mips_regnum (gdbarch)->badvaddr, |
28f5035f UW |
324 | (const gdb_byte *) (regp + MIPS64_EF_CP0_BADVADDR)); |
325 | supply_64bit_reg (regcache, MIPS_PS_REGNUM, | |
326 | (const gdb_byte *) (regp + MIPS64_EF_CP0_STATUS)); | |
2eb4d78b | 327 | supply_64bit_reg (regcache, mips_regnum (gdbarch)->cause, |
28f5035f | 328 | (const gdb_byte *) (regp + MIPS64_EF_CP0_CAUSE)); |
96f026fc KB |
329 | |
330 | /* Fill inaccessible registers with zero. */ | |
822b6570 | 331 | regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf); |
28f5035f | 332 | regcache_raw_supply (regcache, MIPS_UNUSED_REGNUM, zerobuf); |
295093a4 | 333 | for (regi = MIPS_FIRST_EMBED_REGNUM; |
822b6570 | 334 | regi <= MIPS_LAST_EMBED_REGNUM; |
295093a4 | 335 | regi++) |
28f5035f | 336 | regcache_raw_supply (regcache, regi, zerobuf); |
96f026fc KB |
337 | } |
338 | ||
d37eb719 | 339 | /* Pack our registers (or one register) into a 64-bit elf_gregset_t. */ |
96f026fc | 340 | |
d37eb719 | 341 | void |
28f5035f UW |
342 | mips64_fill_gregset (const struct regcache *regcache, |
343 | mips64_elf_gregset_t *gregsetp, int regno) | |
96f026fc | 344 | { |
2eb4d78b | 345 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
96f026fc KB |
346 | int regaddr, regi; |
347 | mips64_elf_greg_t *regp = *gregsetp; | |
2ba93934 | 348 | void *dst; |
96f026fc KB |
349 | |
350 | if (regno == -1) | |
351 | { | |
352 | memset (regp, 0, sizeof (mips64_elf_gregset_t)); | |
822b6570 | 353 | for (regi = 1; regi < 32; regi++) |
28f5035f | 354 | mips64_fill_gregset (regcache, gregsetp, regi); |
2eb4d78b UW |
355 | mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo); |
356 | mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi); | |
357 | mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc); | |
358 | mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr); | |
28f5035f | 359 | mips64_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM); |
2eb4d78b | 360 | mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause); |
822b6570 | 361 | mips64_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM); |
96f026fc KB |
362 | return; |
363 | } | |
364 | ||
822b6570 | 365 | if (regno > 0 && regno < 32) |
d37eb719 | 366 | regaddr = regno + MIPS64_EF_REG0; |
2eb4d78b | 367 | else if (regno == mips_regnum (gdbarch)->lo) |
56cea623 | 368 | regaddr = MIPS64_EF_LO; |
2eb4d78b | 369 | else if (regno == mips_regnum (gdbarch)->hi) |
56cea623 | 370 | regaddr = MIPS64_EF_HI; |
2eb4d78b | 371 | else if (regno == mips_regnum (gdbarch)->pc) |
56cea623 | 372 | regaddr = MIPS64_EF_CP0_EPC; |
2eb4d78b | 373 | else if (regno == mips_regnum (gdbarch)->badvaddr) |
56cea623 | 374 | regaddr = MIPS64_EF_CP0_BADVADDR; |
24e05951 | 375 | else if (regno == MIPS_PS_REGNUM) |
56cea623 | 376 | regaddr = MIPS64_EF_CP0_STATUS; |
2eb4d78b | 377 | else if (regno == mips_regnum (gdbarch)->cause) |
56cea623 | 378 | regaddr = MIPS64_EF_CP0_CAUSE; |
2eb4d78b | 379 | else if (mips_linux_restart_reg_p (gdbarch) |
822b6570 DJ |
380 | && regno == MIPS_RESTART_REGNUM) |
381 | regaddr = MIPS64_EF_REG0; | |
56cea623 AC |
382 | else |
383 | regaddr = -1; | |
96f026fc KB |
384 | |
385 | if (regaddr != -1) | |
386 | { | |
d37eb719 DJ |
387 | gdb_byte buf[MAX_REGISTER_SIZE]; |
388 | LONGEST val; | |
389 | ||
28f5035f | 390 | regcache_raw_collect (regcache, regno, buf); |
2eb4d78b | 391 | val = extract_signed_integer (buf, register_size (gdbarch, regno)); |
96f026fc | 392 | dst = regp + regaddr; |
d37eb719 | 393 | store_signed_integer (dst, 8, val); |
96f026fc KB |
394 | } |
395 | } | |
396 | ||
397 | /* Likewise, unpack an elf_fpregset_t. */ | |
398 | ||
d37eb719 | 399 | void |
28f5035f UW |
400 | mips64_supply_fpregset (struct regcache *regcache, |
401 | const mips64_elf_fpregset_t *fpregsetp) | |
96f026fc | 402 | { |
2eb4d78b | 403 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
52f0bd74 | 404 | int regi; |
96f026fc | 405 | |
d37eb719 DJ |
406 | /* See mips_linux_o32_sigframe_init for a description of the |
407 | peculiar FP register layout. */ | |
2eb4d78b | 408 | if (register_size (gdbarch, gdbarch_fp0_regnum (gdbarch)) == 4) |
d37eb719 DJ |
409 | for (regi = 0; regi < 32; regi++) |
410 | { | |
28f5035f | 411 | const gdb_byte *reg_ptr = (const gdb_byte *)(*fpregsetp + (regi & ~1)); |
2eb4d78b | 412 | if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1)) |
d37eb719 | 413 | reg_ptr += 4; |
3e8c568d | 414 | regcache_raw_supply (regcache, |
2eb4d78b | 415 | gdbarch_fp0_regnum (gdbarch) + regi, |
3e8c568d | 416 | reg_ptr); |
d37eb719 DJ |
417 | } |
418 | else | |
419 | for (regi = 0; regi < 32; regi++) | |
3e8c568d | 420 | regcache_raw_supply (regcache, |
2eb4d78b | 421 | gdbarch_fp0_regnum (gdbarch) + regi, |
28f5035f | 422 | (const char *)(*fpregsetp + regi)); |
d37eb719 | 423 | |
2eb4d78b | 424 | supply_32bit_reg (regcache, mips_regnum (gdbarch)->fp_control_status, |
28f5035f | 425 | (const gdb_byte *)(*fpregsetp + 32)); |
d37eb719 DJ |
426 | |
427 | /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't | |
428 | include it - but the result of PTRACE_GETFPREGS does. The best we | |
429 | can do is to assume that its value is present. */ | |
28f5035f | 430 | supply_32bit_reg (regcache, |
2eb4d78b | 431 | mips_regnum (gdbarch)->fp_implementation_revision, |
28f5035f | 432 | (const gdb_byte *)(*fpregsetp + 32) + 4); |
96f026fc KB |
433 | } |
434 | ||
435 | /* Likewise, pack one or all floating point registers into an | |
436 | elf_fpregset_t. */ | |
437 | ||
d37eb719 | 438 | void |
28f5035f UW |
439 | mips64_fill_fpregset (const struct regcache *regcache, |
440 | mips64_elf_fpregset_t *fpregsetp, int regno) | |
96f026fc | 441 | { |
2eb4d78b | 442 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
d37eb719 | 443 | gdb_byte *to; |
96f026fc | 444 | |
2eb4d78b UW |
445 | if ((regno >= gdbarch_fp0_regnum (gdbarch)) |
446 | && (regno < gdbarch_fp0_regnum (gdbarch) + 32)) | |
96f026fc | 447 | { |
d37eb719 DJ |
448 | /* See mips_linux_o32_sigframe_init for a description of the |
449 | peculiar FP register layout. */ | |
2eb4d78b | 450 | if (register_size (gdbarch, regno) == 4) |
d37eb719 | 451 | { |
2eb4d78b | 452 | int regi = regno - gdbarch_fp0_regnum (gdbarch); |
d37eb719 DJ |
453 | |
454 | to = (gdb_byte *) (*fpregsetp + (regi & ~1)); | |
2eb4d78b | 455 | if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1)) |
d37eb719 | 456 | to += 4; |
28f5035f | 457 | regcache_raw_collect (regcache, regno, to); |
d37eb719 DJ |
458 | } |
459 | else | |
460 | { | |
2eb4d78b | 461 | to = (gdb_byte *) (*fpregsetp + regno - gdbarch_fp0_regnum (gdbarch)); |
28f5035f | 462 | regcache_raw_collect (regcache, regno, to); |
d37eb719 | 463 | } |
96f026fc | 464 | } |
2eb4d78b | 465 | else if (regno == mips_regnum (gdbarch)->fp_control_status) |
96f026fc | 466 | { |
d37eb719 DJ |
467 | gdb_byte buf[MAX_REGISTER_SIZE]; |
468 | LONGEST val; | |
469 | ||
28f5035f | 470 | regcache_raw_collect (regcache, regno, buf); |
2eb4d78b | 471 | val = extract_signed_integer (buf, register_size (gdbarch, regno)); |
d37eb719 DJ |
472 | to = (gdb_byte *) (*fpregsetp + 32); |
473 | store_signed_integer (to, 4, val); | |
474 | } | |
2eb4d78b | 475 | else if (regno == mips_regnum (gdbarch)->fp_implementation_revision) |
d37eb719 DJ |
476 | { |
477 | gdb_byte buf[MAX_REGISTER_SIZE]; | |
478 | LONGEST val; | |
479 | ||
28f5035f | 480 | regcache_raw_collect (regcache, regno, buf); |
2eb4d78b | 481 | val = extract_signed_integer (buf, register_size (gdbarch, regno)); |
d37eb719 DJ |
482 | to = (gdb_byte *) (*fpregsetp + 32) + 4; |
483 | store_signed_integer (to, 4, val); | |
96f026fc KB |
484 | } |
485 | else if (regno == -1) | |
486 | { | |
487 | int regi; | |
488 | ||
489 | for (regi = 0; regi < 32; regi++) | |
3e8c568d | 490 | mips64_fill_fpregset (regcache, fpregsetp, |
2eb4d78b | 491 | gdbarch_fp0_regnum (gdbarch) + regi); |
28f5035f | 492 | mips64_fill_fpregset (regcache, fpregsetp, |
2eb4d78b | 493 | mips_regnum (gdbarch)->fp_control_status); |
28f5035f | 494 | mips64_fill_fpregset (regcache, fpregsetp, |
2eb4d78b UW |
495 | (mips_regnum (gdbarch) |
496 | ->fp_implementation_revision)); | |
96f026fc KB |
497 | } |
498 | } | |
499 | ||
500 | ||
2aa830e4 DJ |
501 | /* Use a local version of this function to get the correct types for |
502 | regsets, until multi-arch core support is ready. */ | |
503 | ||
504 | static void | |
9eefc95f UW |
505 | fetch_core_registers (struct regcache *regcache, |
506 | char *core_reg_sect, unsigned core_reg_size, | |
2aa830e4 DJ |
507 | int which, CORE_ADDR reg_addr) |
508 | { | |
d37eb719 DJ |
509 | mips_elf_gregset_t gregset; |
510 | mips_elf_fpregset_t fpregset; | |
96f026fc KB |
511 | mips64_elf_gregset_t gregset64; |
512 | mips64_elf_fpregset_t fpregset64; | |
2aa830e4 DJ |
513 | |
514 | if (which == 0) | |
515 | { | |
96f026fc | 516 | if (core_reg_size == sizeof (gregset)) |
2aa830e4 | 517 | { |
96f026fc | 518 | memcpy ((char *) &gregset, core_reg_sect, sizeof (gregset)); |
9eefc95f | 519 | mips_supply_gregset (regcache, |
28f5035f | 520 | (const mips_elf_gregset_t *) &gregset); |
96f026fc KB |
521 | } |
522 | else if (core_reg_size == sizeof (gregset64)) | |
523 | { | |
524 | memcpy ((char *) &gregset64, core_reg_sect, sizeof (gregset64)); | |
9eefc95f | 525 | mips64_supply_gregset (regcache, |
28f5035f | 526 | (const mips64_elf_gregset_t *) &gregset64); |
2aa830e4 DJ |
527 | } |
528 | else | |
529 | { | |
8a3fe4f8 | 530 | warning (_("wrong size gregset struct in core file")); |
2aa830e4 DJ |
531 | } |
532 | } | |
533 | else if (which == 2) | |
534 | { | |
96f026fc | 535 | if (core_reg_size == sizeof (fpregset)) |
2aa830e4 | 536 | { |
96f026fc | 537 | memcpy ((char *) &fpregset, core_reg_sect, sizeof (fpregset)); |
9eefc95f | 538 | mips_supply_fpregset (regcache, |
28f5035f | 539 | (const mips_elf_fpregset_t *) &fpregset); |
96f026fc KB |
540 | } |
541 | else if (core_reg_size == sizeof (fpregset64)) | |
542 | { | |
295093a4 MS |
543 | memcpy ((char *) &fpregset64, core_reg_sect, |
544 | sizeof (fpregset64)); | |
9eefc95f | 545 | mips64_supply_fpregset (regcache, |
28f5035f | 546 | (const mips64_elf_fpregset_t *) &fpregset64); |
2aa830e4 DJ |
547 | } |
548 | else | |
549 | { | |
8a3fe4f8 | 550 | warning (_("wrong size fpregset struct in core file")); |
2aa830e4 DJ |
551 | } |
552 | } | |
553 | } | |
554 | ||
555 | /* Register that we are able to handle ELF file formats using standard | |
556 | procfs "regset" structures. */ | |
557 | ||
558 | static struct core_fns regset_core_fns = | |
559 | { | |
560 | bfd_target_elf_flavour, /* core_flavour */ | |
561 | default_check_format, /* check_format */ | |
562 | default_core_sniffer, /* core_sniffer */ | |
563 | fetch_core_registers, /* core_read_registers */ | |
564 | NULL /* next */ | |
565 | }; | |
566 | ||
4eb0ad19 DJ |
567 | static const struct target_desc * |
568 | mips_linux_core_read_description (struct gdbarch *gdbarch, | |
569 | struct target_ops *target, | |
570 | bfd *abfd) | |
571 | { | |
572 | asection *section = bfd_get_section_by_name (abfd, ".reg"); | |
573 | if (! section) | |
574 | return NULL; | |
575 | ||
576 | switch (bfd_section_size (abfd, section)) | |
577 | { | |
578 | case sizeof (mips_elf_gregset_t): | |
579 | return mips_tdesc_gp32; | |
580 | ||
581 | case sizeof (mips64_elf_gregset_t): | |
582 | return mips_tdesc_gp64; | |
583 | ||
584 | default: | |
585 | return NULL; | |
586 | } | |
587 | } | |
588 | ||
96f026fc | 589 | |
295093a4 MS |
590 | /* Check the code at PC for a dynamic linker lazy resolution stub. |
591 | Because they aren't in the .plt section, we pattern-match on the | |
592 | code generated by GNU ld. They look like this: | |
6de918a6 DJ |
593 | |
594 | lw t9,0x8010(gp) | |
595 | addu t7,ra | |
596 | jalr t9,ra | |
597 | addiu t8,zero,INDEX | |
598 | ||
295093a4 MS |
599 | (with the appropriate doubleword instructions for N64). Also |
600 | return the dynamic symbol index used in the last instruction. */ | |
6de918a6 DJ |
601 | |
602 | static int | |
603 | mips_linux_in_dynsym_stub (CORE_ADDR pc, char *name) | |
604 | { | |
605 | unsigned char buf[28], *p; | |
606 | ULONGEST insn, insn1; | |
1cf3db46 | 607 | int n64 = (mips_abi (target_gdbarch) == MIPS_ABI_N64); |
6de918a6 DJ |
608 | |
609 | read_memory (pc - 12, buf, 28); | |
610 | ||
611 | if (n64) | |
612 | { | |
613 | /* ld t9,0x8010(gp) */ | |
614 | insn1 = 0xdf998010; | |
615 | } | |
616 | else | |
617 | { | |
618 | /* lw t9,0x8010(gp) */ | |
619 | insn1 = 0x8f998010; | |
620 | } | |
621 | ||
622 | p = buf + 12; | |
623 | while (p >= buf) | |
624 | { | |
625 | insn = extract_unsigned_integer (p, 4); | |
626 | if (insn == insn1) | |
627 | break; | |
628 | p -= 4; | |
629 | } | |
630 | if (p < buf) | |
631 | return 0; | |
632 | ||
633 | insn = extract_unsigned_integer (p + 4, 4); | |
634 | if (n64) | |
635 | { | |
636 | /* daddu t7,ra */ | |
637 | if (insn != 0x03e0782d) | |
638 | return 0; | |
639 | } | |
640 | else | |
641 | { | |
642 | /* addu t7,ra */ | |
643 | if (insn != 0x03e07821) | |
644 | return 0; | |
645 | } | |
295093a4 | 646 | |
6de918a6 DJ |
647 | insn = extract_unsigned_integer (p + 8, 4); |
648 | /* jalr t9,ra */ | |
649 | if (insn != 0x0320f809) | |
650 | return 0; | |
651 | ||
652 | insn = extract_unsigned_integer (p + 12, 4); | |
653 | if (n64) | |
654 | { | |
655 | /* daddiu t8,zero,0 */ | |
656 | if ((insn & 0xffff0000) != 0x64180000) | |
657 | return 0; | |
658 | } | |
659 | else | |
660 | { | |
661 | /* addiu t8,zero,0 */ | |
662 | if ((insn & 0xffff0000) != 0x24180000) | |
663 | return 0; | |
664 | } | |
665 | ||
666 | return (insn & 0xffff); | |
667 | } | |
668 | ||
295093a4 | 669 | /* Return non-zero iff PC belongs to the dynamic linker resolution |
db5f024e | 670 | code, a PLT entry, or a lazy binding stub. */ |
6de918a6 | 671 | |
7d522c90 | 672 | static int |
6de918a6 DJ |
673 | mips_linux_in_dynsym_resolve_code (CORE_ADDR pc) |
674 | { | |
295093a4 | 675 | /* Check whether PC is in the dynamic linker. This also checks |
db5f024e | 676 | whether it is in the .plt section, used by non-PIC executables. */ |
7d522c90 | 677 | if (svr4_in_dynsym_resolve_code (pc)) |
6de918a6 DJ |
678 | return 1; |
679 | ||
295093a4 MS |
680 | /* Pattern match for the stub. It would be nice if there were a |
681 | more efficient way to avoid this check. */ | |
6de918a6 DJ |
682 | if (mips_linux_in_dynsym_stub (pc, NULL)) |
683 | return 1; | |
684 | ||
685 | return 0; | |
686 | } | |
687 | ||
688 | /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c, | |
689 | and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc | |
690 | implementation of this triggers at "fixup" from the same objfile as | |
c4c5b7ba | 691 | "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at |
db5f024e DJ |
692 | "__dl_runtime_resolve" directly. An unresolved lazy binding |
693 | stub will point to _dl_runtime_resolve, which will first call | |
c4c5b7ba AC |
694 | __dl_runtime_resolve, and then pass control to the resolved |
695 | function. */ | |
6de918a6 DJ |
696 | |
697 | static CORE_ADDR | |
698 | mips_linux_skip_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) | |
699 | { | |
700 | struct minimal_symbol *resolver; | |
701 | ||
702 | resolver = lookup_minimal_symbol ("__dl_runtime_resolve", NULL, NULL); | |
703 | ||
704 | if (resolver && SYMBOL_VALUE_ADDRESS (resolver) == pc) | |
eb2f4a08 | 705 | return frame_pc_unwind (get_current_frame ()); |
6de918a6 | 706 | |
db5f024e | 707 | return glibc_skip_solib_resolver (gdbarch, pc); |
295093a4 | 708 | } |
6de918a6 | 709 | |
5792a79b DJ |
710 | /* Signal trampoline support. There are four supported layouts for a |
711 | signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and | |
712 | n64 rt_sigframe. We handle them all independently; not the most | |
713 | efficient way, but simplest. First, declare all the unwinders. */ | |
714 | ||
715 | static void mips_linux_o32_sigframe_init (const struct tramp_frame *self, | |
b8a22b94 | 716 | struct frame_info *this_frame, |
5792a79b DJ |
717 | struct trad_frame_cache *this_cache, |
718 | CORE_ADDR func); | |
719 | ||
720 | static void mips_linux_n32n64_sigframe_init (const struct tramp_frame *self, | |
b8a22b94 | 721 | struct frame_info *this_frame, |
5792a79b DJ |
722 | struct trad_frame_cache *this_cache, |
723 | CORE_ADDR func); | |
724 | ||
725 | #define MIPS_NR_LINUX 4000 | |
726 | #define MIPS_NR_N64_LINUX 5000 | |
727 | #define MIPS_NR_N32_LINUX 6000 | |
728 | ||
729 | #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119 | |
730 | #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193 | |
731 | #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211 | |
732 | #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211 | |
733 | ||
734 | #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn | |
735 | #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn | |
736 | #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn | |
737 | #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn | |
738 | #define MIPS_INST_SYSCALL 0x0000000c | |
739 | ||
2cd8546d AC |
740 | static const struct tramp_frame mips_linux_o32_sigframe = { |
741 | SIGTRAMP_FRAME, | |
5792a79b | 742 | 4, |
2cd8546d AC |
743 | { |
744 | { MIPS_INST_LI_V0_SIGRETURN, -1 }, | |
745 | { MIPS_INST_SYSCALL, -1 }, | |
746 | { TRAMP_SENTINEL_INSN, -1 } | |
747 | }, | |
5792a79b DJ |
748 | mips_linux_o32_sigframe_init |
749 | }; | |
750 | ||
2cd8546d AC |
751 | static const struct tramp_frame mips_linux_o32_rt_sigframe = { |
752 | SIGTRAMP_FRAME, | |
5792a79b | 753 | 4, |
2cd8546d AC |
754 | { |
755 | { MIPS_INST_LI_V0_RT_SIGRETURN, -1 }, | |
756 | { MIPS_INST_SYSCALL, -1 }, | |
757 | { TRAMP_SENTINEL_INSN, -1 } }, | |
5792a79b DJ |
758 | mips_linux_o32_sigframe_init |
759 | }; | |
760 | ||
2cd8546d AC |
761 | static const struct tramp_frame mips_linux_n32_rt_sigframe = { |
762 | SIGTRAMP_FRAME, | |
5792a79b | 763 | 4, |
2cd8546d AC |
764 | { |
765 | { MIPS_INST_LI_V0_N32_RT_SIGRETURN, -1 }, | |
766 | { MIPS_INST_SYSCALL, -1 }, | |
767 | { TRAMP_SENTINEL_INSN, -1 } | |
768 | }, | |
5792a79b DJ |
769 | mips_linux_n32n64_sigframe_init |
770 | }; | |
771 | ||
2cd8546d AC |
772 | static const struct tramp_frame mips_linux_n64_rt_sigframe = { |
773 | SIGTRAMP_FRAME, | |
5792a79b | 774 | 4, |
fcbd8a5c TS |
775 | { |
776 | { MIPS_INST_LI_V0_N64_RT_SIGRETURN, -1 }, | |
777 | { MIPS_INST_SYSCALL, -1 }, | |
778 | { TRAMP_SENTINEL_INSN, -1 } | |
779 | }, | |
5792a79b DJ |
780 | mips_linux_n32n64_sigframe_init |
781 | }; | |
782 | ||
783 | /* *INDENT-OFF* */ | |
784 | /* The unwinder for o32 signal frames. The legacy structures look | |
785 | like this: | |
786 | ||
787 | struct sigframe { | |
788 | u32 sf_ass[4]; [argument save space for o32] | |
789 | u32 sf_code[2]; [signal trampoline] | |
790 | struct sigcontext sf_sc; | |
791 | sigset_t sf_mask; | |
792 | }; | |
793 | ||
794 | struct sigcontext { | |
795 | unsigned int sc_regmask; [Unused] | |
796 | unsigned int sc_status; | |
797 | unsigned long long sc_pc; | |
798 | unsigned long long sc_regs[32]; | |
799 | unsigned long long sc_fpregs[32]; | |
800 | unsigned int sc_ownedfp; | |
801 | unsigned int sc_fpc_csr; | |
802 | unsigned int sc_fpc_eir; [Unused] | |
803 | unsigned int sc_used_math; | |
804 | unsigned int sc_ssflags; [Unused] | |
805 | [Alignment hole of four bytes] | |
806 | unsigned long long sc_mdhi; | |
807 | unsigned long long sc_mdlo; | |
808 | ||
809 | unsigned int sc_cause; [Unused] | |
810 | unsigned int sc_badvaddr; [Unused] | |
811 | ||
812 | unsigned long sc_sigset[4]; [kernel's sigset_t] | |
813 | }; | |
814 | ||
815 | The RT signal frames look like this: | |
816 | ||
817 | struct rt_sigframe { | |
818 | u32 rs_ass[4]; [argument save space for o32] | |
819 | u32 rs_code[2] [signal trampoline] | |
820 | struct siginfo rs_info; | |
821 | struct ucontext rs_uc; | |
822 | }; | |
823 | ||
824 | struct ucontext { | |
825 | unsigned long uc_flags; | |
826 | struct ucontext *uc_link; | |
827 | stack_t uc_stack; | |
828 | [Alignment hole of four bytes] | |
829 | struct sigcontext uc_mcontext; | |
830 | sigset_t uc_sigmask; | |
831 | }; */ | |
832 | /* *INDENT-ON* */ | |
833 | ||
834 | #define SIGFRAME_CODE_OFFSET (4 * 4) | |
835 | #define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4) | |
836 | ||
837 | #define RTSIGFRAME_SIGINFO_SIZE 128 | |
838 | #define STACK_T_SIZE (3 * 4) | |
839 | #define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4) | |
840 | #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \ | |
841 | + RTSIGFRAME_SIGINFO_SIZE \ | |
842 | + UCONTEXT_SIGCONTEXT_OFFSET) | |
843 | ||
844 | #define SIGCONTEXT_PC (1 * 8) | |
845 | #define SIGCONTEXT_REGS (2 * 8) | |
846 | #define SIGCONTEXT_FPREGS (34 * 8) | |
847 | #define SIGCONTEXT_FPCSR (66 * 8 + 4) | |
848 | #define SIGCONTEXT_HI (69 * 8) | |
849 | #define SIGCONTEXT_LO (70 * 8) | |
850 | #define SIGCONTEXT_CAUSE (71 * 8 + 0) | |
851 | #define SIGCONTEXT_BADVADDR (71 * 8 + 4) | |
852 | ||
853 | #define SIGCONTEXT_REG_SIZE 8 | |
854 | ||
855 | static void | |
856 | mips_linux_o32_sigframe_init (const struct tramp_frame *self, | |
b8a22b94 | 857 | struct frame_info *this_frame, |
5792a79b DJ |
858 | struct trad_frame_cache *this_cache, |
859 | CORE_ADDR func) | |
860 | { | |
b8a22b94 | 861 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
5792a79b DJ |
862 | int ireg, reg_position; |
863 | CORE_ADDR sigcontext_base = func - SIGFRAME_CODE_OFFSET; | |
2eb4d78b | 864 | const struct mips_regnum *regs = mips_regnum (gdbarch); |
37c4d197 | 865 | CORE_ADDR regs_base; |
5792a79b DJ |
866 | |
867 | if (self == &mips_linux_o32_sigframe) | |
868 | sigcontext_base += SIGFRAME_SIGCONTEXT_OFFSET; | |
869 | else | |
870 | sigcontext_base += RTSIGFRAME_SIGCONTEXT_OFFSET; | |
295093a4 MS |
871 | |
872 | /* I'm not proud of this hack. Eventually we will have the | |
873 | infrastructure to indicate the size of saved registers on a | |
874 | per-frame basis, but right now we don't; the kernel saves eight | |
37c4d197 DJ |
875 | bytes but we only want four. Use regs_base to access any |
876 | 64-bit fields. */ | |
2eb4d78b | 877 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
37c4d197 DJ |
878 | regs_base = sigcontext_base + 4; |
879 | else | |
880 | regs_base = sigcontext_base; | |
5792a79b | 881 | |
2eb4d78b | 882 | if (mips_linux_restart_reg_p (gdbarch)) |
822b6570 DJ |
883 | trad_frame_set_reg_addr (this_cache, |
884 | (MIPS_RESTART_REGNUM | |
2eb4d78b | 885 | + gdbarch_num_regs (gdbarch)), |
822b6570 | 886 | regs_base + SIGCONTEXT_REGS); |
5792a79b DJ |
887 | |
888 | for (ireg = 1; ireg < 32; ireg++) | |
295093a4 | 889 | trad_frame_set_reg_addr (this_cache, |
f57d151a | 890 | ireg + MIPS_ZERO_REGNUM |
2eb4d78b | 891 | + gdbarch_num_regs (gdbarch), |
37c4d197 | 892 | regs_base + SIGCONTEXT_REGS |
5792a79b DJ |
893 | + ireg * SIGCONTEXT_REG_SIZE); |
894 | ||
37c4d197 DJ |
895 | /* The way that floating point registers are saved, unfortunately, |
896 | depends on the architecture the kernel is built for. For the r3000 and | |
897 | tx39, four bytes of each register are at the beginning of each of the | |
898 | 32 eight byte slots. For everything else, the registers are saved | |
899 | using double precision; only the even-numbered slots are initialized, | |
900 | and the high bits are the odd-numbered register. Assume the latter | |
901 | layout, since we can't tell, and it's much more common. Which bits are | |
902 | the "high" bits depends on endianness. */ | |
5792a79b | 903 | for (ireg = 0; ireg < 32; ireg++) |
2eb4d78b | 904 | if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (ireg & 1)) |
f57d151a UW |
905 | trad_frame_set_reg_addr (this_cache, |
906 | ireg + regs->fp0 + | |
2eb4d78b | 907 | gdbarch_num_regs (gdbarch), |
37c4d197 DJ |
908 | sigcontext_base + SIGCONTEXT_FPREGS + 4 |
909 | + (ireg & ~1) * SIGCONTEXT_REG_SIZE); | |
910 | else | |
f57d151a UW |
911 | trad_frame_set_reg_addr (this_cache, |
912 | ireg + regs->fp0 | |
2eb4d78b | 913 | + gdbarch_num_regs (gdbarch), |
37c4d197 DJ |
914 | sigcontext_base + SIGCONTEXT_FPREGS |
915 | + (ireg & ~1) * SIGCONTEXT_REG_SIZE); | |
5792a79b | 916 | |
f57d151a | 917 | trad_frame_set_reg_addr (this_cache, |
2eb4d78b | 918 | regs->pc + gdbarch_num_regs (gdbarch), |
37c4d197 | 919 | regs_base + SIGCONTEXT_PC); |
5792a79b | 920 | |
295093a4 | 921 | trad_frame_set_reg_addr (this_cache, |
f57d151a | 922 | regs->fp_control_status |
2eb4d78b | 923 | + gdbarch_num_regs (gdbarch), |
5792a79b | 924 | sigcontext_base + SIGCONTEXT_FPCSR); |
f57d151a | 925 | trad_frame_set_reg_addr (this_cache, |
2eb4d78b | 926 | regs->hi + gdbarch_num_regs (gdbarch), |
37c4d197 | 927 | regs_base + SIGCONTEXT_HI); |
f57d151a | 928 | trad_frame_set_reg_addr (this_cache, |
2eb4d78b | 929 | regs->lo + gdbarch_num_regs (gdbarch), |
37c4d197 | 930 | regs_base + SIGCONTEXT_LO); |
f57d151a | 931 | trad_frame_set_reg_addr (this_cache, |
2eb4d78b | 932 | regs->cause + gdbarch_num_regs (gdbarch), |
5792a79b | 933 | sigcontext_base + SIGCONTEXT_CAUSE); |
f57d151a | 934 | trad_frame_set_reg_addr (this_cache, |
2eb4d78b | 935 | regs->badvaddr + gdbarch_num_regs (gdbarch), |
5792a79b DJ |
936 | sigcontext_base + SIGCONTEXT_BADVADDR); |
937 | ||
938 | /* Choice of the bottom of the sigframe is somewhat arbitrary. */ | |
939 | trad_frame_set_id (this_cache, | |
295093a4 MS |
940 | frame_id_build (func - SIGFRAME_CODE_OFFSET, |
941 | func)); | |
5792a79b DJ |
942 | } |
943 | ||
944 | /* *INDENT-OFF* */ | |
945 | /* For N32/N64 things look different. There is no non-rt signal frame. | |
946 | ||
947 | struct rt_sigframe_n32 { | |
948 | u32 rs_ass[4]; [ argument save space for o32 ] | |
949 | u32 rs_code[2]; [ signal trampoline ] | |
950 | struct siginfo rs_info; | |
951 | struct ucontextn32 rs_uc; | |
952 | }; | |
953 | ||
954 | struct ucontextn32 { | |
955 | u32 uc_flags; | |
956 | s32 uc_link; | |
957 | stack32_t uc_stack; | |
958 | struct sigcontext uc_mcontext; | |
959 | sigset_t uc_sigmask; [ mask last for extensibility ] | |
960 | }; | |
295093a4 | 961 | |
e741f4d4 | 962 | struct rt_sigframe { |
5792a79b DJ |
963 | u32 rs_ass[4]; [ argument save space for o32 ] |
964 | u32 rs_code[2]; [ signal trampoline ] | |
965 | struct siginfo rs_info; | |
966 | struct ucontext rs_uc; | |
967 | }; | |
968 | ||
969 | struct ucontext { | |
970 | unsigned long uc_flags; | |
971 | struct ucontext *uc_link; | |
972 | stack_t uc_stack; | |
973 | struct sigcontext uc_mcontext; | |
974 | sigset_t uc_sigmask; [ mask last for extensibility ] | |
975 | }; | |
976 | ||
977 | And the sigcontext is different (this is for both n32 and n64): | |
978 | ||
979 | struct sigcontext { | |
980 | unsigned long long sc_regs[32]; | |
981 | unsigned long long sc_fpregs[32]; | |
982 | unsigned long long sc_mdhi; | |
e741f4d4 DJ |
983 | unsigned long long sc_hi1; |
984 | unsigned long long sc_hi2; | |
985 | unsigned long long sc_hi3; | |
5792a79b | 986 | unsigned long long sc_mdlo; |
e741f4d4 DJ |
987 | unsigned long long sc_lo1; |
988 | unsigned long long sc_lo2; | |
989 | unsigned long long sc_lo3; | |
5792a79b | 990 | unsigned long long sc_pc; |
5792a79b | 991 | unsigned int sc_fpc_csr; |
5792a79b | 992 | unsigned int sc_used_math; |
e741f4d4 DJ |
993 | unsigned int sc_dsp; |
994 | unsigned int sc_reserved; | |
995 | }; | |
996 | ||
997 | That is the post-2.6.12 definition of the 64-bit sigcontext; before | |
998 | then, there were no hi1-hi3 or lo1-lo3. Cause and badvaddr were | |
999 | included too. */ | |
5792a79b DJ |
1000 | /* *INDENT-ON* */ |
1001 | ||
1002 | #define N32_STACK_T_SIZE STACK_T_SIZE | |
1003 | #define N64_STACK_T_SIZE (2 * 8 + 4) | |
1004 | #define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4) | |
1005 | #define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4) | |
1006 | #define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \ | |
1007 | + RTSIGFRAME_SIGINFO_SIZE \ | |
1008 | + N32_UCONTEXT_SIGCONTEXT_OFFSET) | |
1009 | #define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \ | |
1010 | + RTSIGFRAME_SIGINFO_SIZE \ | |
1011 | + N64_UCONTEXT_SIGCONTEXT_OFFSET) | |
1012 | ||
1013 | #define N64_SIGCONTEXT_REGS (0 * 8) | |
1014 | #define N64_SIGCONTEXT_FPREGS (32 * 8) | |
1015 | #define N64_SIGCONTEXT_HI (64 * 8) | |
e741f4d4 DJ |
1016 | #define N64_SIGCONTEXT_LO (68 * 8) |
1017 | #define N64_SIGCONTEXT_PC (72 * 8) | |
1018 | #define N64_SIGCONTEXT_FPCSR (73 * 8) | |
5792a79b DJ |
1019 | |
1020 | #define N64_SIGCONTEXT_REG_SIZE 8 | |
295093a4 | 1021 | |
5792a79b DJ |
1022 | static void |
1023 | mips_linux_n32n64_sigframe_init (const struct tramp_frame *self, | |
b8a22b94 | 1024 | struct frame_info *this_frame, |
5792a79b DJ |
1025 | struct trad_frame_cache *this_cache, |
1026 | CORE_ADDR func) | |
1027 | { | |
b8a22b94 | 1028 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
5792a79b DJ |
1029 | int ireg, reg_position; |
1030 | CORE_ADDR sigcontext_base = func - SIGFRAME_CODE_OFFSET; | |
2eb4d78b | 1031 | const struct mips_regnum *regs = mips_regnum (gdbarch); |
5792a79b DJ |
1032 | |
1033 | if (self == &mips_linux_n32_rt_sigframe) | |
1034 | sigcontext_base += N32_SIGFRAME_SIGCONTEXT_OFFSET; | |
1035 | else | |
1036 | sigcontext_base += N64_SIGFRAME_SIGCONTEXT_OFFSET; | |
295093a4 | 1037 | |
2eb4d78b | 1038 | if (mips_linux_restart_reg_p (gdbarch)) |
822b6570 DJ |
1039 | trad_frame_set_reg_addr (this_cache, |
1040 | (MIPS_RESTART_REGNUM | |
2eb4d78b | 1041 | + gdbarch_num_regs (gdbarch)), |
822b6570 | 1042 | sigcontext_base + N64_SIGCONTEXT_REGS); |
5792a79b DJ |
1043 | |
1044 | for (ireg = 1; ireg < 32; ireg++) | |
295093a4 | 1045 | trad_frame_set_reg_addr (this_cache, |
f57d151a | 1046 | ireg + MIPS_ZERO_REGNUM |
2eb4d78b | 1047 | + gdbarch_num_regs (gdbarch), |
5792a79b DJ |
1048 | sigcontext_base + N64_SIGCONTEXT_REGS |
1049 | + ireg * N64_SIGCONTEXT_REG_SIZE); | |
1050 | ||
1051 | for (ireg = 0; ireg < 32; ireg++) | |
f57d151a UW |
1052 | trad_frame_set_reg_addr (this_cache, |
1053 | ireg + regs->fp0 | |
2eb4d78b | 1054 | + gdbarch_num_regs (gdbarch), |
5792a79b DJ |
1055 | sigcontext_base + N64_SIGCONTEXT_FPREGS |
1056 | + ireg * N64_SIGCONTEXT_REG_SIZE); | |
1057 | ||
f57d151a | 1058 | trad_frame_set_reg_addr (this_cache, |
2eb4d78b | 1059 | regs->pc + gdbarch_num_regs (gdbarch), |
5792a79b DJ |
1060 | sigcontext_base + N64_SIGCONTEXT_PC); |
1061 | ||
295093a4 | 1062 | trad_frame_set_reg_addr (this_cache, |
f57d151a | 1063 | regs->fp_control_status |
2eb4d78b | 1064 | + gdbarch_num_regs (gdbarch), |
5792a79b | 1065 | sigcontext_base + N64_SIGCONTEXT_FPCSR); |
f57d151a | 1066 | trad_frame_set_reg_addr (this_cache, |
2eb4d78b | 1067 | regs->hi + gdbarch_num_regs (gdbarch), |
5792a79b | 1068 | sigcontext_base + N64_SIGCONTEXT_HI); |
f57d151a | 1069 | trad_frame_set_reg_addr (this_cache, |
2eb4d78b | 1070 | regs->lo + gdbarch_num_regs (gdbarch), |
5792a79b | 1071 | sigcontext_base + N64_SIGCONTEXT_LO); |
5792a79b DJ |
1072 | |
1073 | /* Choice of the bottom of the sigframe is somewhat arbitrary. */ | |
1074 | trad_frame_set_id (this_cache, | |
295093a4 MS |
1075 | frame_id_build (func - SIGFRAME_CODE_OFFSET, |
1076 | func)); | |
5792a79b DJ |
1077 | } |
1078 | ||
822b6570 | 1079 | static void |
61a1198a | 1080 | mips_linux_write_pc (struct regcache *regcache, CORE_ADDR pc) |
822b6570 | 1081 | { |
2eb4d78b UW |
1082 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
1083 | regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc); | |
822b6570 DJ |
1084 | |
1085 | /* Clear the syscall restart flag. */ | |
2eb4d78b | 1086 | if (mips_linux_restart_reg_p (gdbarch)) |
61a1198a | 1087 | regcache_cooked_write_unsigned (regcache, MIPS_RESTART_REGNUM, 0); |
822b6570 DJ |
1088 | } |
1089 | ||
1090 | /* Return 1 if MIPS_RESTART_REGNUM is usable. */ | |
1091 | ||
1092 | int | |
1093 | mips_linux_restart_reg_p (struct gdbarch *gdbarch) | |
1094 | { | |
1095 | /* If we do not have a target description with registers, then | |
1096 | MIPS_RESTART_REGNUM will not be included in the register set. */ | |
1097 | if (!tdesc_has_registers (gdbarch_target_desc (gdbarch))) | |
1098 | return 0; | |
1099 | ||
1100 | /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will | |
1101 | either be GPR-sized or missing. */ | |
1102 | return register_size (gdbarch, MIPS_RESTART_REGNUM) > 0; | |
1103 | } | |
9f62d0e2 | 1104 | |
e38d4e1a DJ |
1105 | /* When FRAME is at a syscall instruction, return the PC of the next |
1106 | instruction to be executed. */ | |
1107 | ||
63807e1d | 1108 | static CORE_ADDR |
e38d4e1a DJ |
1109 | mips_linux_syscall_next_pc (struct frame_info *frame) |
1110 | { | |
1111 | CORE_ADDR pc = get_frame_pc (frame); | |
1112 | ULONGEST v0 = get_frame_register_unsigned (frame, MIPS_V0_REGNUM); | |
1113 | ||
1114 | /* If we are about to make a sigreturn syscall, use the unwinder to | |
1115 | decode the signal frame. */ | |
1116 | if (v0 == MIPS_NR_sigreturn | |
1117 | || v0 == MIPS_NR_rt_sigreturn | |
1118 | || v0 == MIPS_NR_N64_rt_sigreturn | |
1119 | || v0 == MIPS_NR_N32_rt_sigreturn) | |
1120 | return frame_pc_unwind (get_current_frame ()); | |
1121 | ||
1122 | return pc + 4; | |
1123 | } | |
1124 | ||
5792a79b DJ |
1125 | /* Initialize one of the GNU/Linux OS ABIs. */ |
1126 | ||
19ed69dd | 1127 | static void |
295093a4 MS |
1128 | mips_linux_init_abi (struct gdbarch_info info, |
1129 | struct gdbarch *gdbarch) | |
19ed69dd | 1130 | { |
96f026fc KB |
1131 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
1132 | enum mips_abi abi = mips_abi (gdbarch); | |
822b6570 | 1133 | struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info; |
96f026fc KB |
1134 | |
1135 | switch (abi) | |
1136 | { | |
1137 | case MIPS_ABI_O32: | |
1138 | set_gdbarch_get_longjmp_target (gdbarch, | |
1139 | mips_linux_get_longjmp_target); | |
1140 | set_solib_svr4_fetch_link_map_offsets | |
76a9d10f | 1141 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); |
fb2be677 AC |
1142 | tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_sigframe); |
1143 | tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_rt_sigframe); | |
96f026fc KB |
1144 | break; |
1145 | case MIPS_ABI_N32: | |
1146 | set_gdbarch_get_longjmp_target (gdbarch, | |
1147 | mips_linux_get_longjmp_target); | |
1148 | set_solib_svr4_fetch_link_map_offsets | |
76a9d10f | 1149 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); |
d05f6826 DJ |
1150 | set_gdbarch_long_double_bit (gdbarch, 128); |
1151 | /* These floatformats should probably be renamed. MIPS uses | |
1152 | the same 128-bit IEEE floating point format that IA-64 uses, | |
1153 | except that the quiet/signalling NaN bit is reversed (GDB | |
1154 | does not distinguish between quiet and signalling NaNs). */ | |
8da61cc4 | 1155 | set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad); |
fb2be677 | 1156 | tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n32_rt_sigframe); |
96f026fc KB |
1157 | break; |
1158 | case MIPS_ABI_N64: | |
1159 | set_gdbarch_get_longjmp_target (gdbarch, | |
1160 | mips64_linux_get_longjmp_target); | |
1161 | set_solib_svr4_fetch_link_map_offsets | |
76a9d10f | 1162 | (gdbarch, svr4_lp64_fetch_link_map_offsets); |
d05f6826 DJ |
1163 | set_gdbarch_long_double_bit (gdbarch, 128); |
1164 | /* These floatformats should probably be renamed. MIPS uses | |
1165 | the same 128-bit IEEE floating point format that IA-64 uses, | |
1166 | except that the quiet/signalling NaN bit is reversed (GDB | |
1167 | does not distinguish between quiet and signalling NaNs). */ | |
8da61cc4 | 1168 | set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad); |
fb2be677 | 1169 | tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n64_rt_sigframe); |
96f026fc KB |
1170 | break; |
1171 | default: | |
96f026fc KB |
1172 | break; |
1173 | } | |
6de918a6 DJ |
1174 | |
1175 | set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver); | |
1176 | ||
0d0266c6 | 1177 | set_gdbarch_software_single_step (gdbarch, mips_software_single_step); |
b2756930 KB |
1178 | |
1179 | /* Enable TLS support. */ | |
1180 | set_gdbarch_fetch_tls_load_module_address (gdbarch, | |
1181 | svr4_fetch_objfile_link_map); | |
7d522c90 DJ |
1182 | |
1183 | /* Initialize this lazily, to avoid an initialization order | |
1184 | dependency on solib-svr4.c's _initialize routine. */ | |
1185 | if (mips_svr4_so_ops.in_dynsym_resolve_code == NULL) | |
1186 | { | |
1187 | mips_svr4_so_ops = svr4_so_ops; | |
1188 | mips_svr4_so_ops.in_dynsym_resolve_code | |
1189 | = mips_linux_in_dynsym_resolve_code; | |
1190 | } | |
1191 | set_solib_ops (gdbarch, &mips_svr4_so_ops); | |
822b6570 DJ |
1192 | |
1193 | set_gdbarch_write_pc (gdbarch, mips_linux_write_pc); | |
1194 | ||
4eb0ad19 DJ |
1195 | set_gdbarch_core_read_description (gdbarch, |
1196 | mips_linux_core_read_description); | |
1197 | ||
e38d4e1a DJ |
1198 | tdep->syscall_next_pc = mips_linux_syscall_next_pc; |
1199 | ||
822b6570 DJ |
1200 | if (tdesc_data) |
1201 | { | |
1202 | const struct tdesc_feature *feature; | |
1203 | ||
1204 | /* If we have target-described registers, then we can safely | |
1205 | reserve a number for MIPS_RESTART_REGNUM (whether it is | |
1206 | described or not). */ | |
1207 | gdb_assert (gdbarch_num_regs (gdbarch) <= MIPS_RESTART_REGNUM); | |
1208 | set_gdbarch_num_regs (gdbarch, MIPS_RESTART_REGNUM + 1); | |
1209 | ||
1210 | /* If it's present, then assign it to the reserved number. */ | |
1211 | feature = tdesc_find_feature (info.target_desc, | |
1212 | "org.gnu.gdb.mips.linux"); | |
1213 | if (feature != NULL) | |
1214 | tdesc_numbered_register (feature, tdesc_data, MIPS_RESTART_REGNUM, | |
1215 | "restart"); | |
1216 | } | |
19ed69dd KB |
1217 | } |
1218 | ||
63807e1d PA |
1219 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
1220 | extern initialize_file_ftype _initialize_mips_linux_tdep; | |
1221 | ||
2aa830e4 | 1222 | void |
d1bacddc | 1223 | _initialize_mips_linux_tdep (void) |
2aa830e4 | 1224 | { |
96f026fc KB |
1225 | const struct bfd_arch_info *arch_info; |
1226 | ||
96f026fc KB |
1227 | for (arch_info = bfd_lookup_arch (bfd_arch_mips, 0); |
1228 | arch_info != NULL; | |
1229 | arch_info = arch_info->next) | |
1230 | { | |
295093a4 MS |
1231 | gdbarch_register_osabi (bfd_arch_mips, arch_info->mach, |
1232 | GDB_OSABI_LINUX, | |
96f026fc KB |
1233 | mips_linux_init_abi); |
1234 | } | |
1235 | ||
00e32a35 | 1236 | deprecated_add_core_fns (®set_core_fns); |
2aa830e4 | 1237 | } |