1 /* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger.
2 Copyright 2003, 2004, 2005
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
26 #include "mn10300-tdep.h"
27 #include "gdb_assert.h"
35 /* Transliterated from <asm-mn10300/elf.h>... */
36 #define MN10300_ELF_NGREG 28
37 #define MN10300_ELF_NFPREG 32
39 typedef gdb_byte mn10300_elf_greg_t[4];
40 typedef mn10300_elf_greg_t mn10300_elf_gregset_t[MN10300_ELF_NGREG];
42 typedef gdb_byte mn10300_elf_fpreg_t[4];
45 mn10300_elf_fpreg_t fpregs[MN10300_ELF_NFPREG];
47 } mn10300_elf_fpregset_t;
49 /* elf_gregset_t register indices stolen from include/asm-mn10300/ptrace.h. */
50 #define MN10300_ELF_GREGSET_T_REG_INDEX_A3 0
51 #define MN10300_ELF_GREGSET_T_REG_INDEX_A2 1
52 #define MN10300_ELF_GREGSET_T_REG_INDEX_D3 2
53 #define MN10300_ELF_GREGSET_T_REG_INDEX_D2 3
54 #define MN10300_ELF_GREGSET_T_REG_INDEX_MCVF 4
55 #define MN10300_ELF_GREGSET_T_REG_INDEX_MCRL 5
56 #define MN10300_ELF_GREGSET_T_REG_INDEX_MCRH 6
57 #define MN10300_ELF_GREGSET_T_REG_INDEX_MDRQ 7
58 #define MN10300_ELF_GREGSET_T_REG_INDEX_E1 8
59 #define MN10300_ELF_GREGSET_T_REG_INDEX_E0 9
60 #define MN10300_ELF_GREGSET_T_REG_INDEX_E7 10
61 #define MN10300_ELF_GREGSET_T_REG_INDEX_E6 11
62 #define MN10300_ELF_GREGSET_T_REG_INDEX_E5 12
63 #define MN10300_ELF_GREGSET_T_REG_INDEX_E4 13
64 #define MN10300_ELF_GREGSET_T_REG_INDEX_E3 14
65 #define MN10300_ELF_GREGSET_T_REG_INDEX_E2 15
66 #define MN10300_ELF_GREGSET_T_REG_INDEX_SP 16
67 #define MN10300_ELF_GREGSET_T_REG_INDEX_LAR 17
68 #define MN10300_ELF_GREGSET_T_REG_INDEX_LIR 18
69 #define MN10300_ELF_GREGSET_T_REG_INDEX_MDR 19
70 #define MN10300_ELF_GREGSET_T_REG_INDEX_A1 20
71 #define MN10300_ELF_GREGSET_T_REG_INDEX_A0 21
72 #define MN10300_ELF_GREGSET_T_REG_INDEX_D1 22
73 #define MN10300_ELF_GREGSET_T_REG_INDEX_D0 23
74 #define MN10300_ELF_GREGSET_T_REG_INDEX_ORIG_D0 24
75 #define MN10300_ELF_GREGSET_T_REG_INDEX_EPSW 25
76 #define MN10300_ELF_GREGSET_T_REG_INDEX_PC 26
78 /* New gdbarch API for corefile registers.
79 Given a section name and size, create a struct reg object
80 with a supply_register and a collect_register method. */
82 /* Copy register value of REGNUM from regset to regcache.
83 If REGNUM is -1, do this for all gp registers in regset. */
86 am33_supply_gregset_method (const struct regset *regset,
87 struct regcache *regcache,
88 int regnum, const void *gregs, size_t len)
90 char zerobuf[MAX_REGISTER_SIZE];
91 const mn10300_elf_greg_t *regp = (const mn10300_elf_greg_t *) gregs;
94 gdb_assert (len == sizeof (mn10300_elf_gregset_t));
98 regcache_raw_supply (regcache, E_D0_REGNUM,
99 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D0));
102 regcache_raw_supply (regcache, E_D1_REGNUM,
103 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D1));
106 regcache_raw_supply (regcache, E_D2_REGNUM,
107 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D2));
110 regcache_raw_supply (regcache, E_D3_REGNUM,
111 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D3));
114 regcache_raw_supply (regcache, E_A0_REGNUM,
115 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A0));
118 regcache_raw_supply (regcache, E_A1_REGNUM,
119 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A1));
122 regcache_raw_supply (regcache, E_A2_REGNUM,
123 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A2));
126 regcache_raw_supply (regcache, E_A3_REGNUM,
127 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A3));
130 regcache_raw_supply (regcache, E_SP_REGNUM,
131 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_SP));
134 regcache_raw_supply (regcache, E_PC_REGNUM,
135 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_PC));
138 regcache_raw_supply (regcache, E_MDR_REGNUM,
139 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MDR));
142 regcache_raw_supply (regcache, E_PSW_REGNUM,
143 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_EPSW));
146 regcache_raw_supply (regcache, E_LIR_REGNUM,
147 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_LIR));
150 regcache_raw_supply (regcache, E_LAR_REGNUM,
151 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_LAR));
154 regcache_raw_supply (regcache, E_MDRQ_REGNUM,
155 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MDRQ));
158 regcache_raw_supply (regcache, E_E0_REGNUM,
159 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E0));
162 regcache_raw_supply (regcache, E_E1_REGNUM,
163 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E1));
166 regcache_raw_supply (regcache, E_E2_REGNUM,
167 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E2));
170 regcache_raw_supply (regcache, E_E3_REGNUM,
171 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E3));
174 regcache_raw_supply (regcache, E_E4_REGNUM,
175 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E4));
178 regcache_raw_supply (regcache, E_E5_REGNUM,
179 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E5));
182 regcache_raw_supply (regcache, E_E6_REGNUM,
183 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E6));
186 regcache_raw_supply (regcache, E_E7_REGNUM,
187 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E7));
190 /* ssp, msp, and usp are inaccessible. */
192 memset (zerobuf, 0, MAX_REGISTER_SIZE);
193 regcache_raw_supply (regcache, E_E8_REGNUM, zerobuf);
196 memset (zerobuf, 0, MAX_REGISTER_SIZE);
197 regcache_raw_supply (regcache, E_E9_REGNUM, zerobuf);
200 memset (zerobuf, 0, MAX_REGISTER_SIZE);
201 regcache_raw_supply (regcache, E_E10_REGNUM, zerobuf);
205 regcache_raw_supply (regcache, E_MCRH_REGNUM,
206 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCRH));
209 regcache_raw_supply (regcache, E_MCRL_REGNUM,
210 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCRL));
213 regcache_raw_supply (regcache, E_MCVF_REGNUM,
214 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCVF));
217 /* FPCR is numbered among the GP regs, but handled as an FP reg.
220 case E_FPCR_REGNUM + 1:
221 /* The two unused registers beyond fpcr are inaccessible. */
222 memset (zerobuf, 0, MAX_REGISTER_SIZE);
223 regcache_raw_supply (regcache, E_FPCR_REGNUM + 1, zerobuf);
225 case E_FPCR_REGNUM + 2:
226 memset (zerobuf, 0, MAX_REGISTER_SIZE);
227 regcache_raw_supply (regcache, E_FPCR_REGNUM + 2, zerobuf);
229 default: /* An error, obviously, but should we error out? */
232 for (i = 0; i < MN10300_ELF_NGREG; i++)
233 am33_supply_gregset_method (regset, regcache, i, gregs, len);
239 /* Copy fp register value of REGNUM from regset to regcache.
240 If REGNUM is -1, do this for all fp registers in regset. */
243 am33_supply_fpregset_method (const struct regset *regset,
244 struct regcache *regcache,
245 int regnum, const void *fpregs, size_t len)
247 const mn10300_elf_fpregset_t *fpregset = fpregs;
249 gdb_assert (len == sizeof (mn10300_elf_fpregset_t));
255 for (i = 0; i < MN10300_ELF_NFPREG; i++)
256 am33_supply_fpregset_method (regset, regcache,
257 E_FS0_REGNUM + i, fpregs, len);
258 am33_supply_fpregset_method (regset, regcache,
259 E_FPCR_REGNUM, fpregs, len);
261 else if (regnum == E_FPCR_REGNUM)
262 regcache_raw_supply (current_regcache, E_FPCR_REGNUM,
264 else if (E_FS0_REGNUM <= regnum && regnum < E_FS0_REGNUM + MN10300_ELF_NFPREG)
265 regcache_raw_supply (current_regcache, regnum,
266 &fpregset->fpregs[regnum - E_FS0_REGNUM]);
271 /* Copy register values from regcache to regset. */
274 am33_collect_gregset_method (const struct regset *regset,
275 const struct regcache *regcache,
276 int regnum, void *gregs, size_t len)
278 mn10300_elf_gregset_t *regp = gregs;
281 gdb_assert (len == sizeof (mn10300_elf_gregset_t));
285 regcache_raw_collect (regcache, E_D0_REGNUM,
286 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D0));
289 regcache_raw_collect (regcache, E_D1_REGNUM,
290 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D1));
293 regcache_raw_collect (regcache, E_D2_REGNUM,
294 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D2));
297 regcache_raw_collect (regcache, E_D3_REGNUM,
298 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D3));
301 regcache_raw_collect (regcache, E_A0_REGNUM,
302 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A0));
305 regcache_raw_collect (regcache, E_A1_REGNUM,
306 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A1));
309 regcache_raw_collect (regcache, E_A2_REGNUM,
310 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A2));
313 regcache_raw_collect (regcache, E_A3_REGNUM,
314 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A3));
317 regcache_raw_collect (regcache, E_SP_REGNUM,
318 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_SP));
321 regcache_raw_collect (regcache, E_PC_REGNUM,
322 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_PC));
325 regcache_raw_collect (regcache, E_MDR_REGNUM,
326 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MDR));
329 regcache_raw_collect (regcache, E_PSW_REGNUM,
330 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_EPSW));
333 regcache_raw_collect (regcache, E_LIR_REGNUM,
334 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_LIR));
337 regcache_raw_collect (regcache, E_LAR_REGNUM,
338 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_LAR));
341 regcache_raw_collect (regcache, E_MDRQ_REGNUM,
342 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MDRQ));
345 regcache_raw_collect (regcache, E_E0_REGNUM,
346 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E0));
349 regcache_raw_collect (regcache, E_E1_REGNUM,
350 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E1));
353 regcache_raw_collect (regcache, E_E2_REGNUM,
354 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E2));
357 regcache_raw_collect (regcache, E_E3_REGNUM,
358 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E3));
361 regcache_raw_collect (regcache, E_E4_REGNUM,
362 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E4));
365 regcache_raw_collect (regcache, E_E5_REGNUM,
366 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E5));
369 regcache_raw_collect (regcache, E_E6_REGNUM,
370 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E6));
373 regcache_raw_collect (regcache, E_E7_REGNUM,
374 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E7));
377 /* ssp, msp, and usp are inaccessible. */
379 /* The gregset struct has noplace to put this: do nothing. */
382 /* The gregset struct has noplace to put this: do nothing. */
385 /* The gregset struct has noplace to put this: do nothing. */
388 regcache_raw_collect (regcache, E_MCRH_REGNUM,
389 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCRH));
392 regcache_raw_collect (regcache, E_MCRL_REGNUM,
393 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCRL));
396 regcache_raw_collect (regcache, E_MCVF_REGNUM,
397 (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCVF));
400 /* FPCR is numbered among the GP regs, but handled as an FP reg.
403 case E_FPCR_REGNUM + 1:
404 /* The gregset struct has noplace to put this: do nothing. */
406 case E_FPCR_REGNUM + 2:
407 /* The gregset struct has noplace to put this: do nothing. */
409 default: /* An error, obviously, but should we error out? */
412 for (i = 0; i < MN10300_ELF_NGREG; i++)
413 am33_collect_gregset_method (regset, regcache, i, gregs, len);
419 /* Copy fp register values from regcache to regset. */
422 am33_collect_fpregset_method (const struct regset *regset,
423 const struct regcache *regcache,
424 int regnum, void *fpregs, size_t len)
426 mn10300_elf_fpregset_t *fpregset = fpregs;
428 gdb_assert (len == sizeof (mn10300_elf_fpregset_t));
433 for (i = 0; i < MN10300_ELF_NFPREG; i++)
434 am33_collect_fpregset_method (regset, regcache, E_FS0_REGNUM + i,
436 am33_collect_fpregset_method (regset, regcache,
437 E_FPCR_REGNUM, fpregs, len);
439 else if (regnum == E_FPCR_REGNUM)
440 regcache_raw_collect (current_regcache, E_FPCR_REGNUM,
442 else if (E_FS0_REGNUM <= regnum
443 && regnum < E_FS0_REGNUM + MN10300_ELF_NFPREG)
444 regcache_raw_collect (current_regcache, regnum,
445 &fpregset->fpregs[regnum - E_FS0_REGNUM]);
450 /* Create a struct regset from a corefile register section. */
452 static const struct regset *
453 am33_regset_from_core_section (struct gdbarch *gdbarch,
454 const char *sect_name,
457 /* We will call regset_alloc, and pass the names of the supply and
460 if (sect_size == sizeof (mn10300_elf_fpregset_t))
461 return regset_alloc (gdbarch,
462 am33_supply_fpregset_method,
463 am33_collect_fpregset_method);
465 return regset_alloc (gdbarch,
466 am33_supply_gregset_method,
467 am33_collect_gregset_method);
470 /* AM33 Linux osabi has been recognized.
471 Now's our chance to register our corefile handling. */
474 am33_linux_init_osabi (struct gdbarch_info gdbinfo, struct gdbarch *gdbarch)
476 set_gdbarch_regset_from_core_section (gdbarch,
477 am33_regset_from_core_section);
481 _initialize_mn10300_linux_tdep (void)
483 gdbarch_register_osabi (bfd_arch_mn10300, 0,
484 GDB_OSABI_LINUX, am33_linux_init_osabi);