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 (JB_PC) that we will land at. The pc is copied
60 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 + JB_PC * JB_ELEMENT_SIZE, buf,
71 TARGET_PTR_BIT / TARGET_CHAR_BIT))
74 *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
79 /* Unpack an elf_gregset_t into GDB's register cache. */
82 supply_gregset (elf_gregset_t *gregsetp)
85 elf_greg_t *regp = *gregsetp;
86 static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0};
88 for (regi = EF_REG0; regi <= EF_REG31; regi++)
89 supply_register ((regi - EF_REG0), (char *)(regp + regi));
91 supply_register (LO_REGNUM, (char *)(regp + EF_LO));
92 supply_register (HI_REGNUM, (char *)(regp + EF_HI));
94 supply_register (PC_REGNUM, (char *)(regp + EF_CP0_EPC));
95 supply_register (BADVADDR_REGNUM, (char *)(regp + EF_CP0_BADVADDR));
96 supply_register (PS_REGNUM, (char *)(regp + EF_CP0_STATUS));
97 supply_register (CAUSE_REGNUM, (char *)(regp + EF_CP0_CAUSE));
99 /* Fill inaccessible registers with zero. */
100 supply_register (FP_REGNUM, zerobuf);
101 supply_register (UNUSED_REGNUM, zerobuf);
102 for (regi = FIRST_EMBED_REGNUM; regi < LAST_EMBED_REGNUM; regi++)
103 supply_register (regi, zerobuf);
106 /* Pack our registers (or one register) into an elf_gregset_t. */
109 fill_gregset (elf_gregset_t *gregsetp, int regno)
112 elf_greg_t *regp = *gregsetp;
117 memset (regp, 0, sizeof (elf_gregset_t));
118 for (regi = 0; regi < 32; regi++)
119 fill_gregset (gregsetp, regi);
120 fill_gregset (gregsetp, LO_REGNUM);
121 fill_gregset (gregsetp, HI_REGNUM);
122 fill_gregset (gregsetp, PC_REGNUM);
123 fill_gregset (gregsetp, BADVADDR_REGNUM);
124 fill_gregset (gregsetp, PS_REGNUM);
125 fill_gregset (gregsetp, CAUSE_REGNUM);
132 src = ®isters[REGISTER_BYTE (regno)];
133 dst = regp + regno + EF_REG0;
134 memcpy (dst, src, sizeof (elf_greg_t));
148 regaddr = EF_CP0_EPC;
150 case BADVADDR_REGNUM:
151 regaddr = EF_CP0_BADVADDR;
154 regaddr = EF_CP0_STATUS;
157 regaddr = EF_CP0_CAUSE;
163 src = ®isters[REGISTER_BYTE (regno)];
164 dst = regp + regaddr;
165 memcpy (dst, src, sizeof (elf_greg_t));
169 /* Likewise, unpack an elf_fpregset_t. */
172 supply_fpregset (elf_fpregset_t *fpregsetp)
175 static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0};
177 for (regi = 0; regi < 32; regi++)
178 supply_register (FP0_REGNUM + regi,
179 (char *)(*fpregsetp + regi));
181 supply_register (FCRCS_REGNUM, (char *)(*fpregsetp + 32));
183 /* FIXME: how can we supply FCRIR_REGNUM? The ABI doesn't tell us. */
184 supply_register (FCRIR_REGNUM, zerobuf);
187 /* Likewise, pack one or all floating point registers into an
191 fill_fpregset (elf_fpregset_t *fpregsetp, int regno)
195 if ((regno >= FP0_REGNUM) && (regno < FP0_REGNUM + 32))
197 from = (char *) ®isters[REGISTER_BYTE (regno)];
198 to = (char *) (*fpregsetp + regno - FP0_REGNUM);
199 memcpy (to, from, REGISTER_RAW_SIZE (regno - FP0_REGNUM));
201 else if (regno == FCRCS_REGNUM)
203 from = (char *) ®isters[REGISTER_BYTE (regno)];
204 to = (char *) (*fpregsetp + 32);
205 memcpy (to, from, REGISTER_RAW_SIZE (regno));
207 else if (regno == -1)
211 for (regi = 0; regi < 32; regi++)
212 fill_fpregset (fpregsetp, FP0_REGNUM + regi);
213 fill_fpregset(fpregsetp, FCRCS_REGNUM);
217 /* Map gdb internal register number to ptrace ``address''.
218 These ``addresses'' are normally defined in <asm/ptrace.h>. */
221 register_addr (int regno, CORE_ADDR blockend)
225 if (regno < 0 || regno >= NUM_REGS)
226 error ("Bogon register number %d.", regno);
230 else if ((regno >= FP0_REGNUM) && (regno < FP0_REGNUM + 32))
231 regaddr = FPR_BASE + (regno - FP0_REGNUM);
232 else if (regno == PC_REGNUM)
234 else if (regno == CAUSE_REGNUM)
236 else if (regno == BADVADDR_REGNUM)
238 else if (regno == LO_REGNUM)
240 else if (regno == HI_REGNUM)
242 else if (regno == FCRCS_REGNUM)
244 else if (regno == FCRIR_REGNUM)
247 error ("Unknowable register number %d.", regno);
252 /* Use a local version of this function to get the correct types for
253 regsets, until multi-arch core support is ready. */
256 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
257 int which, CORE_ADDR reg_addr)
259 elf_gregset_t gregset;
260 elf_fpregset_t fpregset;
264 if (core_reg_size != sizeof (gregset))
266 warning ("wrong size gregset struct in core file");
270 memcpy ((char *) &gregset, core_reg_sect, sizeof (gregset));
271 supply_gregset (&gregset);
276 if (core_reg_size != sizeof (fpregset))
278 warning ("wrong size fpregset struct in core file");
282 memcpy ((char *) &fpregset, core_reg_sect, sizeof (fpregset));
283 supply_fpregset (&fpregset);
288 /* Register that we are able to handle ELF file formats using standard
289 procfs "regset" structures. */
291 static struct core_fns regset_core_fns =
293 bfd_target_elf_flavour, /* core_flavour */
294 default_check_format, /* check_format */
295 default_core_sniffer, /* core_sniffer */
296 fetch_core_registers, /* core_read_registers */
300 /* Fetch (and possibly build) an appropriate link_map_offsets
301 structure for native GNU/Linux MIPS targets using the struct offsets
302 defined in link.h (but without actual reference to that file).
304 This makes it possible to access GNU/Linux MIPS shared libraries from a
305 GDB that was built on a different host platform (for cross debugging). */
307 struct link_map_offsets *
308 mips_linux_svr4_fetch_link_map_offsets (void)
310 static struct link_map_offsets lmo;
311 static struct link_map_offsets *lmp = NULL;
317 lmo.r_debug_size = 8; /* The actual size is 20 bytes, but
318 this is all we need. */
319 lmo.r_map_offset = 4;
322 lmo.link_map_size = 20;
324 lmo.l_addr_offset = 0;
327 lmo.l_name_offset = 4;
330 lmo.l_next_offset = 12;
333 lmo.l_prev_offset = 16;
341 _initialize_mips_linux_tdep (void)
343 add_core_fns (®set_core_fns);