1 /* Target-dependent code for GNU/Linux on MIPS processors.
2 Copyright 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. */
24 #include "solib-svr4.h"
26 /* Copied from <asm/elf.h>. */
30 typedef unsigned char elf_greg_t[4];
31 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
33 typedef unsigned char elf_fpreg_t[8];
34 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
36 /* 0 - 31 are integer registers, 32 - 63 are fp registers. */
51 #define EF_CP0_BADVADDR 41
52 #define EF_CP0_STATUS 42
53 #define EF_CP0_CAUSE 43
57 /* Figure out where the longjmp will land.
58 We expect the first arg to be a pointer to the jmp_buf structure from
59 which we extract the pc (MIPS_LINUX_JB_PC) that we will land at. The pc
60 is copied into PC. This routine returns 1 on success. */
63 mips_linux_get_longjmp_target (CORE_ADDR *pc)
66 char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
68 jb_addr = read_register (A0_REGNUM);
70 if (target_read_memory (jb_addr
71 + MIPS_LINUX_JB_PC * MIPS_LINUX_JB_ELEMENT_SIZE,
72 buf, TARGET_PTR_BIT / TARGET_CHAR_BIT))
75 *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
80 /* Unpack an elf_gregset_t into GDB's register cache. */
83 supply_gregset (elf_gregset_t *gregsetp)
86 elf_greg_t *regp = *gregsetp;
87 char *zerobuf = alloca (MAX_REGISTER_RAW_SIZE);
89 memset (zerobuf, 0, MAX_REGISTER_RAW_SIZE);
91 for (regi = EF_REG0; regi <= EF_REG31; regi++)
92 supply_register ((regi - EF_REG0), (char *)(regp + regi));
94 supply_register (LO_REGNUM, (char *)(regp + EF_LO));
95 supply_register (HI_REGNUM, (char *)(regp + EF_HI));
97 supply_register (PC_REGNUM, (char *)(regp + EF_CP0_EPC));
98 supply_register (BADVADDR_REGNUM, (char *)(regp + EF_CP0_BADVADDR));
99 supply_register (PS_REGNUM, (char *)(regp + EF_CP0_STATUS));
100 supply_register (CAUSE_REGNUM, (char *)(regp + EF_CP0_CAUSE));
102 /* Fill inaccessible registers with zero. */
103 supply_register (FP_REGNUM, zerobuf);
104 supply_register (UNUSED_REGNUM, zerobuf);
105 for (regi = FIRST_EMBED_REGNUM; regi < LAST_EMBED_REGNUM; regi++)
106 supply_register (regi, zerobuf);
109 /* Pack our registers (or one register) into an elf_gregset_t. */
112 fill_gregset (elf_gregset_t *gregsetp, int regno)
115 elf_greg_t *regp = *gregsetp;
120 memset (regp, 0, sizeof (elf_gregset_t));
121 for (regi = 0; regi < 32; regi++)
122 fill_gregset (gregsetp, regi);
123 fill_gregset (gregsetp, LO_REGNUM);
124 fill_gregset (gregsetp, HI_REGNUM);
125 fill_gregset (gregsetp, PC_REGNUM);
126 fill_gregset (gregsetp, BADVADDR_REGNUM);
127 fill_gregset (gregsetp, PS_REGNUM);
128 fill_gregset (gregsetp, CAUSE_REGNUM);
135 src = ®isters[REGISTER_BYTE (regno)];
136 dst = regp + regno + EF_REG0;
137 memcpy (dst, src, sizeof (elf_greg_t));
151 regaddr = EF_CP0_EPC;
153 case BADVADDR_REGNUM:
154 regaddr = EF_CP0_BADVADDR;
157 regaddr = EF_CP0_STATUS;
160 regaddr = EF_CP0_CAUSE;
166 src = ®isters[REGISTER_BYTE (regno)];
167 dst = regp + regaddr;
168 memcpy (dst, src, sizeof (elf_greg_t));
172 /* Likewise, unpack an elf_fpregset_t. */
175 supply_fpregset (elf_fpregset_t *fpregsetp)
178 char *zerobuf = alloca (MAX_REGISTER_RAW_SIZE);
180 memset (zerobuf, 0, MAX_REGISTER_RAW_SIZE);
182 for (regi = 0; regi < 32; regi++)
183 supply_register (FP0_REGNUM + regi,
184 (char *)(*fpregsetp + regi));
186 supply_register (FCRCS_REGNUM, (char *)(*fpregsetp + 32));
188 /* FIXME: how can we supply FCRIR_REGNUM? The ABI doesn't tell us. */
189 supply_register (FCRIR_REGNUM, zerobuf);
192 /* Likewise, pack one or all floating point registers into an
196 fill_fpregset (elf_fpregset_t *fpregsetp, int regno)
200 if ((regno >= FP0_REGNUM) && (regno < FP0_REGNUM + 32))
202 from = (char *) ®isters[REGISTER_BYTE (regno)];
203 to = (char *) (*fpregsetp + regno - FP0_REGNUM);
204 memcpy (to, from, REGISTER_RAW_SIZE (regno - FP0_REGNUM));
206 else if (regno == FCRCS_REGNUM)
208 from = (char *) ®isters[REGISTER_BYTE (regno)];
209 to = (char *) (*fpregsetp + 32);
210 memcpy (to, from, REGISTER_RAW_SIZE (regno));
212 else if (regno == -1)
216 for (regi = 0; regi < 32; regi++)
217 fill_fpregset (fpregsetp, FP0_REGNUM + regi);
218 fill_fpregset(fpregsetp, FCRCS_REGNUM);
222 /* Map gdb internal register number to ptrace ``address''.
223 These ``addresses'' are normally defined in <asm/ptrace.h>. */
226 register_addr (int regno, CORE_ADDR blockend)
230 if (regno < 0 || regno >= NUM_REGS)
231 error ("Bogon register number %d.", regno);
235 else if ((regno >= FP0_REGNUM) && (regno < FP0_REGNUM + 32))
236 regaddr = FPR_BASE + (regno - FP0_REGNUM);
237 else if (regno == PC_REGNUM)
239 else if (regno == CAUSE_REGNUM)
241 else if (regno == BADVADDR_REGNUM)
243 else if (regno == LO_REGNUM)
245 else if (regno == HI_REGNUM)
247 else if (regno == FCRCS_REGNUM)
249 else if (regno == FCRIR_REGNUM)
252 error ("Unknowable register number %d.", regno);
257 /* Use a local version of this function to get the correct types for
258 regsets, until multi-arch core support is ready. */
261 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
262 int which, CORE_ADDR reg_addr)
264 elf_gregset_t gregset;
265 elf_fpregset_t fpregset;
269 if (core_reg_size != sizeof (gregset))
271 warning ("wrong size gregset struct in core file");
275 memcpy ((char *) &gregset, core_reg_sect, sizeof (gregset));
276 supply_gregset (&gregset);
281 if (core_reg_size != sizeof (fpregset))
283 warning ("wrong size fpregset struct in core file");
287 memcpy ((char *) &fpregset, core_reg_sect, sizeof (fpregset));
288 supply_fpregset (&fpregset);
293 /* Register that we are able to handle ELF file formats using standard
294 procfs "regset" structures. */
296 static struct core_fns regset_core_fns =
298 bfd_target_elf_flavour, /* core_flavour */
299 default_check_format, /* check_format */
300 default_core_sniffer, /* core_sniffer */
301 fetch_core_registers, /* core_read_registers */
305 /* Fetch (and possibly build) an appropriate link_map_offsets
306 structure for native GNU/Linux MIPS targets using the struct offsets
307 defined in link.h (but without actual reference to that file).
309 This makes it possible to access GNU/Linux MIPS shared libraries from a
310 GDB that was built on a different host platform (for cross debugging). */
312 struct link_map_offsets *
313 mips_linux_svr4_fetch_link_map_offsets (void)
315 static struct link_map_offsets lmo;
316 static struct link_map_offsets *lmp = NULL;
322 lmo.r_debug_size = 8; /* The actual size is 20 bytes, but
323 this is all we need. */
324 lmo.r_map_offset = 4;
327 lmo.link_map_size = 20;
329 lmo.l_addr_offset = 0;
332 lmo.l_name_offset = 4;
335 lmo.l_next_offset = 12;
338 lmo.l_prev_offset = 16;
346 _initialize_mips_linux_tdep (void)
348 add_core_fns (®set_core_fns);