Move stdlib.h to common-defs.h
[external/binutils.git] / gdb / mn10300-linux-tdep.c
1 /* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger.
2
3    Copyright (C) 2003-2014 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
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 3 of the License, or
10    (at your option) any later version.
11
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.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21 #include "gdbcore.h"
22 #include <string.h>
23 #include "regcache.h"
24 #include "mn10300-tdep.h"
25 #include "gdb_assert.h"
26 #include "bfd.h"
27 #include "elf-bfd.h"
28 #include "osabi.h"
29 #include "regset.h"
30 #include "solib-svr4.h"
31 #include "frame.h"
32 #include "trad-frame.h"
33 #include "tramp-frame.h"
34 #include "linux-tdep.h"
35
36 /* Transliterated from <asm-mn10300/elf.h>...  */
37 #define MN10300_ELF_NGREG 28
38 #define MN10300_ELF_NFPREG 32
39
40 typedef gdb_byte   mn10300_elf_greg_t[4];
41 typedef mn10300_elf_greg_t mn10300_elf_gregset_t[MN10300_ELF_NGREG];
42
43 typedef gdb_byte   mn10300_elf_fpreg_t[4];
44 typedef struct
45 {
46   mn10300_elf_fpreg_t fpregs[MN10300_ELF_NFPREG];
47   gdb_byte    fpcr[4];
48 } mn10300_elf_fpregset_t;
49
50 /* elf_gregset_t register indices stolen from include/asm-mn10300/ptrace.h.  */
51 #define MN10300_ELF_GREGSET_T_REG_INDEX_A3      0
52 #define MN10300_ELF_GREGSET_T_REG_INDEX_A2      1
53 #define MN10300_ELF_GREGSET_T_REG_INDEX_D3      2
54 #define MN10300_ELF_GREGSET_T_REG_INDEX_D2      3
55 #define MN10300_ELF_GREGSET_T_REG_INDEX_MCVF    4
56 #define MN10300_ELF_GREGSET_T_REG_INDEX_MCRL    5
57 #define MN10300_ELF_GREGSET_T_REG_INDEX_MCRH    6
58 #define MN10300_ELF_GREGSET_T_REG_INDEX_MDRQ    7
59 #define MN10300_ELF_GREGSET_T_REG_INDEX_E1      8
60 #define MN10300_ELF_GREGSET_T_REG_INDEX_E0      9
61 #define MN10300_ELF_GREGSET_T_REG_INDEX_E7      10
62 #define MN10300_ELF_GREGSET_T_REG_INDEX_E6      11
63 #define MN10300_ELF_GREGSET_T_REG_INDEX_E5      12
64 #define MN10300_ELF_GREGSET_T_REG_INDEX_E4      13
65 #define MN10300_ELF_GREGSET_T_REG_INDEX_E3      14
66 #define MN10300_ELF_GREGSET_T_REG_INDEX_E2      15
67 #define MN10300_ELF_GREGSET_T_REG_INDEX_SP      16
68 #define MN10300_ELF_GREGSET_T_REG_INDEX_LAR     17
69 #define MN10300_ELF_GREGSET_T_REG_INDEX_LIR     18
70 #define MN10300_ELF_GREGSET_T_REG_INDEX_MDR     19
71 #define MN10300_ELF_GREGSET_T_REG_INDEX_A1      20
72 #define MN10300_ELF_GREGSET_T_REG_INDEX_A0      21
73 #define MN10300_ELF_GREGSET_T_REG_INDEX_D1      22
74 #define MN10300_ELF_GREGSET_T_REG_INDEX_D0      23
75 #define MN10300_ELF_GREGSET_T_REG_INDEX_ORIG_D0 24
76 #define MN10300_ELF_GREGSET_T_REG_INDEX_EPSW    25
77 #define MN10300_ELF_GREGSET_T_REG_INDEX_PC      26
78
79 /* New gdbarch API for corefile registers.
80    Given a section name and size, create a struct reg object
81    with a supply_register and a collect_register method.  */
82
83 /* Copy register value of REGNUM from regset to regcache.
84    If REGNUM is -1, do this for all gp registers in regset.  */
85
86 static void
87 am33_supply_gregset_method (const struct regset *regset, 
88                             struct regcache *regcache, 
89                             int regnum, const void *gregs, size_t len)
90 {
91   char zerobuf[MAX_REGISTER_SIZE];
92   const mn10300_elf_greg_t *regp = (const mn10300_elf_greg_t *) gregs;
93   int i;
94
95   gdb_assert (len == sizeof (mn10300_elf_gregset_t));
96
97   switch (regnum) {
98   case E_D0_REGNUM:
99     regcache_raw_supply (regcache, E_D0_REGNUM, 
100                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D0));
101     break;
102   case E_D1_REGNUM:
103     regcache_raw_supply (regcache, E_D1_REGNUM, 
104                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D1));
105     break;
106   case E_D2_REGNUM:
107     regcache_raw_supply (regcache, E_D2_REGNUM, 
108                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D2));
109     break;
110   case E_D3_REGNUM:
111     regcache_raw_supply (regcache, E_D3_REGNUM, 
112                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D3));
113     break;
114   case E_A0_REGNUM:
115     regcache_raw_supply (regcache, E_A0_REGNUM, 
116                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A0));
117     break;
118   case E_A1_REGNUM:
119     regcache_raw_supply (regcache, E_A1_REGNUM, 
120                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A1));
121     break;
122   case E_A2_REGNUM:
123     regcache_raw_supply (regcache, E_A2_REGNUM, 
124                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A2));
125     break;
126   case E_A3_REGNUM:
127     regcache_raw_supply (regcache, E_A3_REGNUM, 
128                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A3));
129     break;
130   case E_SP_REGNUM:
131     regcache_raw_supply (regcache, E_SP_REGNUM, 
132                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_SP));
133     break;
134   case E_PC_REGNUM:
135     regcache_raw_supply (regcache, E_PC_REGNUM, 
136                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_PC));
137     break;
138   case E_MDR_REGNUM:
139     regcache_raw_supply (regcache, E_MDR_REGNUM, 
140                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MDR));
141     break;
142   case E_PSW_REGNUM:
143     regcache_raw_supply (regcache, E_PSW_REGNUM, 
144                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_EPSW));
145     break;
146   case E_LIR_REGNUM:
147     regcache_raw_supply (regcache, E_LIR_REGNUM, 
148                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_LIR));
149     break;
150   case E_LAR_REGNUM:
151     regcache_raw_supply (regcache, E_LAR_REGNUM, 
152                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_LAR));
153     break;
154   case E_MDRQ_REGNUM:
155     regcache_raw_supply (regcache, E_MDRQ_REGNUM, 
156                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MDRQ));
157     break;
158   case E_E0_REGNUM:
159     regcache_raw_supply (regcache, E_E0_REGNUM,   
160                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E0));
161     break;
162   case E_E1_REGNUM:
163     regcache_raw_supply (regcache, E_E1_REGNUM,
164                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E1));
165     break;
166   case E_E2_REGNUM:
167     regcache_raw_supply (regcache, E_E2_REGNUM, 
168                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E2));
169     break;
170   case E_E3_REGNUM:
171     regcache_raw_supply (regcache, E_E3_REGNUM, 
172                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E3));
173     break;
174   case E_E4_REGNUM:
175     regcache_raw_supply (regcache, E_E4_REGNUM, 
176                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E4));
177     break;
178   case E_E5_REGNUM:
179     regcache_raw_supply (regcache, E_E5_REGNUM, 
180                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E5));
181     break;
182   case E_E6_REGNUM:
183     regcache_raw_supply (regcache, E_E6_REGNUM, 
184                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E6));
185     break;
186   case E_E7_REGNUM:
187     regcache_raw_supply (regcache, E_E7_REGNUM, 
188                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E7));
189     break;
190
191     /* ssp, msp, and usp are inaccessible.  */
192   case E_E8_REGNUM:
193     memset (zerobuf, 0, MAX_REGISTER_SIZE);
194     regcache_raw_supply (regcache, E_E8_REGNUM, zerobuf);
195     break;
196   case E_E9_REGNUM:
197     memset (zerobuf, 0, MAX_REGISTER_SIZE);
198     regcache_raw_supply (regcache, E_E9_REGNUM, zerobuf);
199     break;
200   case E_E10_REGNUM:
201     memset (zerobuf, 0, MAX_REGISTER_SIZE);
202     regcache_raw_supply (regcache, E_E10_REGNUM, zerobuf);
203
204     break;
205   case E_MCRH_REGNUM:
206     regcache_raw_supply (regcache, E_MCRH_REGNUM, 
207                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCRH));
208     break;
209   case E_MCRL_REGNUM:
210     regcache_raw_supply (regcache, E_MCRL_REGNUM, 
211                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCRL));
212     break;
213   case E_MCVF_REGNUM:
214     regcache_raw_supply (regcache, E_MCVF_REGNUM, 
215                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCVF));
216     break;
217   case E_FPCR_REGNUM:
218     /* FPCR is numbered among the GP regs, but handled as an FP reg.
219        Do nothing.  */
220     break;
221   case E_FPCR_REGNUM + 1:
222     /* The two unused registers beyond fpcr are inaccessible.  */
223     memset (zerobuf, 0, MAX_REGISTER_SIZE);
224     regcache_raw_supply (regcache, E_FPCR_REGNUM + 1, zerobuf);
225     break;
226   case E_FPCR_REGNUM + 2:
227     memset (zerobuf, 0, MAX_REGISTER_SIZE);
228     regcache_raw_supply (regcache, E_FPCR_REGNUM + 2, zerobuf);
229     break;
230   default:      /* An error, obviously, but should we error out?  */
231     break;
232   case -1:
233     for (i = 0; i < MN10300_ELF_NGREG; i++)
234       am33_supply_gregset_method (regset, regcache, i, gregs, len);
235     break;
236   }
237   return;
238 }
239
240 /* Copy fp register value of REGNUM from regset to regcache.
241    If REGNUM is -1, do this for all fp registers in regset.  */
242
243 static void
244 am33_supply_fpregset_method (const struct regset *regset, 
245                              struct regcache *regcache, 
246                              int regnum, const void *fpregs, size_t len)
247 {
248   const mn10300_elf_fpregset_t *fpregset = fpregs;
249
250   gdb_assert (len == sizeof (mn10300_elf_fpregset_t));
251
252   if (regnum == -1)
253     {
254       int i;
255
256       for (i = 0; i < MN10300_ELF_NFPREG; i++)
257         am33_supply_fpregset_method (regset, regcache,
258                                      E_FS0_REGNUM + i, fpregs, len);
259       am33_supply_fpregset_method (regset, regcache, 
260                                    E_FPCR_REGNUM, fpregs, len);
261     }
262   else if (regnum == E_FPCR_REGNUM)
263     regcache_raw_supply (regcache, E_FPCR_REGNUM, 
264                          &fpregset->fpcr);
265   else if (E_FS0_REGNUM <= regnum
266            && regnum < E_FS0_REGNUM + MN10300_ELF_NFPREG)
267     regcache_raw_supply (regcache, regnum, 
268                          &fpregset->fpregs[regnum - E_FS0_REGNUM]);
269
270   return;
271 }
272
273 /* Copy register values from regcache to regset.  */
274
275 static void
276 am33_collect_gregset_method (const struct regset *regset, 
277                              const struct regcache *regcache, 
278                              int regnum, void *gregs, size_t len)
279 {
280   mn10300_elf_gregset_t *regp = gregs;
281   int i;
282
283   gdb_assert (len == sizeof (mn10300_elf_gregset_t));
284
285   switch (regnum) {
286   case E_D0_REGNUM:
287     regcache_raw_collect (regcache, E_D0_REGNUM, 
288                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D0));
289     break;
290   case E_D1_REGNUM:
291     regcache_raw_collect (regcache, E_D1_REGNUM, 
292                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D1));
293     break;
294   case E_D2_REGNUM:
295     regcache_raw_collect (regcache, E_D2_REGNUM, 
296                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D2));
297     break;
298   case E_D3_REGNUM:
299     regcache_raw_collect (regcache, E_D3_REGNUM, 
300                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D3));
301     break;
302   case E_A0_REGNUM:
303     regcache_raw_collect (regcache, E_A0_REGNUM, 
304                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A0));
305     break;
306   case E_A1_REGNUM:
307     regcache_raw_collect (regcache, E_A1_REGNUM, 
308                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A1));
309     break;
310   case E_A2_REGNUM:
311     regcache_raw_collect (regcache, E_A2_REGNUM, 
312                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A2));
313     break;
314   case E_A3_REGNUM:
315     regcache_raw_collect (regcache, E_A3_REGNUM, 
316                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A3));
317     break;
318   case E_SP_REGNUM:
319     regcache_raw_collect (regcache, E_SP_REGNUM, 
320                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_SP));
321     break;
322   case E_PC_REGNUM:
323     regcache_raw_collect (regcache, E_PC_REGNUM, 
324                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_PC));
325     break;
326   case E_MDR_REGNUM:
327     regcache_raw_collect (regcache, E_MDR_REGNUM, 
328                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MDR));
329     break;
330   case E_PSW_REGNUM:
331     regcache_raw_collect (regcache, E_PSW_REGNUM, 
332                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_EPSW));
333     break;
334   case E_LIR_REGNUM:
335     regcache_raw_collect (regcache, E_LIR_REGNUM, 
336                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_LIR));
337     break;
338   case E_LAR_REGNUM:
339     regcache_raw_collect (regcache, E_LAR_REGNUM, 
340                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_LAR));
341     break;
342   case E_MDRQ_REGNUM:
343     regcache_raw_collect (regcache, E_MDRQ_REGNUM, 
344                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MDRQ));
345     break;
346   case E_E0_REGNUM:
347     regcache_raw_collect (regcache, E_E0_REGNUM,   
348                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E0));
349     break;
350   case E_E1_REGNUM:
351     regcache_raw_collect (regcache, E_E1_REGNUM,
352                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E1));
353     break;
354   case E_E2_REGNUM:
355     regcache_raw_collect (regcache, E_E2_REGNUM, 
356                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E2));
357     break;
358   case E_E3_REGNUM:
359     regcache_raw_collect (regcache, E_E3_REGNUM, 
360                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E3));
361     break;
362   case E_E4_REGNUM:
363     regcache_raw_collect (regcache, E_E4_REGNUM, 
364                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E4));
365     break;
366   case E_E5_REGNUM:
367     regcache_raw_collect (regcache, E_E5_REGNUM, 
368                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E5));
369     break;
370   case E_E6_REGNUM:
371     regcache_raw_collect (regcache, E_E6_REGNUM, 
372                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E6));
373     break;
374   case E_E7_REGNUM:
375     regcache_raw_collect (regcache, E_E7_REGNUM, 
376                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E7));
377     break;
378
379     /* ssp, msp, and usp are inaccessible.  */
380   case E_E8_REGNUM:
381     /* The gregset struct has noplace to put this: do nothing.  */
382     break;
383   case E_E9_REGNUM:
384     /* The gregset struct has noplace to put this: do nothing.  */
385     break;
386   case E_E10_REGNUM:
387     /* The gregset struct has noplace to put this: do nothing.  */
388     break;
389   case E_MCRH_REGNUM:
390     regcache_raw_collect (regcache, E_MCRH_REGNUM, 
391                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCRH));
392     break;
393   case E_MCRL_REGNUM:
394     regcache_raw_collect (regcache, E_MCRL_REGNUM, 
395                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCRL));
396     break;
397   case E_MCVF_REGNUM:
398     regcache_raw_collect (regcache, E_MCVF_REGNUM, 
399                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCVF));
400     break;
401   case E_FPCR_REGNUM:
402     /* FPCR is numbered among the GP regs, but handled as an FP reg.
403        Do nothing.  */
404     break;
405   case E_FPCR_REGNUM + 1:
406     /* The gregset struct has noplace to put this: do nothing.  */
407     break;
408   case E_FPCR_REGNUM + 2:
409     /* The gregset struct has noplace to put this: do nothing.  */
410     break;
411   default:      /* An error, obviously, but should we error out?  */
412     break;
413   case -1:
414     for (i = 0; i < MN10300_ELF_NGREG; i++)
415       am33_collect_gregset_method (regset, regcache, i, gregs, len);
416     break;
417   }
418   return;
419 }
420
421 /* Copy fp register values from regcache to regset.  */
422
423 static void
424 am33_collect_fpregset_method (const struct regset *regset, 
425                               const struct regcache *regcache, 
426                               int regnum, void *fpregs, size_t len)
427 {
428   mn10300_elf_fpregset_t *fpregset = fpregs;
429
430   gdb_assert (len == sizeof (mn10300_elf_fpregset_t));
431
432   if (regnum == -1)
433     {
434       int i;
435       for (i = 0; i < MN10300_ELF_NFPREG; i++)
436         am33_collect_fpregset_method (regset, regcache, E_FS0_REGNUM + i,
437                                       fpregs, len);
438       am33_collect_fpregset_method (regset, regcache, 
439                                     E_FPCR_REGNUM, fpregs, len);
440     }
441   else if (regnum == E_FPCR_REGNUM)
442     regcache_raw_collect (regcache, E_FPCR_REGNUM, 
443                           &fpregset->fpcr);
444   else if (E_FS0_REGNUM <= regnum
445            && regnum < E_FS0_REGNUM + MN10300_ELF_NFPREG)
446     regcache_raw_collect (regcache, regnum, 
447                           &fpregset->fpregs[regnum - E_FS0_REGNUM]);
448
449   return;
450 }
451
452 static const struct regset am33_gregset =
453   {
454     NULL, am33_supply_gregset_method, am33_collect_gregset_method
455   };
456
457 static const struct regset am33_fpregset =
458   {
459     NULL, am33_supply_fpregset_method, am33_collect_fpregset_method
460   };
461
462 /* Create a struct regset from a corefile register section.  */
463
464 static const struct regset *
465 am33_regset_from_core_section (struct gdbarch *gdbarch, 
466                                const char *sect_name, 
467                                size_t sect_size)
468 {
469   if (sect_size == sizeof (mn10300_elf_fpregset_t))
470     return &am33_fpregset;
471   else
472     return &am33_gregset;
473 }
474 \f
475 static void
476 am33_linux_sigframe_cache_init (const struct tramp_frame *self,
477                                 struct frame_info *this_frame,
478                                 struct trad_frame_cache *this_cache,
479                                 CORE_ADDR func);
480
481 static const struct tramp_frame am33_linux_sigframe = {
482   SIGTRAMP_FRAME,
483   1,
484   {
485     /* mov     119,d0 */
486     { 0x2c, -1 },
487     { 0x77, -1 },
488     { 0x00, -1 },
489     /* syscall 0 */
490     { 0xf0, -1 },
491     { 0xe0, -1 },
492     { TRAMP_SENTINEL_INSN, -1 }
493   },
494   am33_linux_sigframe_cache_init
495 };
496
497 static const struct tramp_frame am33_linux_rt_sigframe = {
498   SIGTRAMP_FRAME,
499   1,
500   {
501     /* mov     173,d0 */
502     { 0x2c, -1 },
503     { 0xad, -1 },
504     { 0x00, -1 },
505     /* syscall 0 */
506     { 0xf0, -1 },
507     { 0xe0, -1 },
508     { TRAMP_SENTINEL_INSN, -1 }
509   },
510   am33_linux_sigframe_cache_init
511 };
512
513 /* Relevant struct definitions for signal handling...
514
515 From arch/mn10300/kernel/sigframe.h:
516
517 struct sigframe
518 {
519         void (*pretcode)(void);
520         int sig;
521         struct sigcontext *psc;
522         struct sigcontext sc;
523         struct fpucontext fpuctx;
524         unsigned long extramask[_NSIG_WORDS-1];
525         char retcode[8];
526 };
527
528 struct rt_sigframe
529 {
530         void (*pretcode)(void);
531         int sig;
532         struct siginfo *pinfo;
533         void *puc;
534         struct siginfo info;
535         struct ucontext uc;
536         struct fpucontext fpuctx;
537         char retcode[8];
538 };
539
540 From include/asm-mn10300/ucontext.h:
541
542 struct ucontext {
543         unsigned long     uc_flags;
544         struct ucontext  *uc_link;
545         stack_t           uc_stack;
546         struct sigcontext uc_mcontext;
547         sigset_t          uc_sigmask;
548 };
549
550 From include/asm-mn10300/sigcontext.h:
551
552 struct fpucontext {
553         unsigned long   fs[32];
554         unsigned long   fpcr;
555 };
556
557 struct sigcontext {
558         unsigned long   d0;
559         unsigned long   d1;
560         unsigned long   d2;
561         unsigned long   d3;
562         unsigned long   a0;
563         unsigned long   a1;
564         unsigned long   a2;
565         unsigned long   a3;
566         unsigned long   e0;
567         unsigned long   e1;
568         unsigned long   e2;
569         unsigned long   e3;
570         unsigned long   e4;
571         unsigned long   e5;
572         unsigned long   e6;
573         unsigned long   e7;
574         unsigned long   lar;
575         unsigned long   lir;
576         unsigned long   mdr;
577         unsigned long   mcvf;
578         unsigned long   mcrl;
579         unsigned long   mcrh;
580         unsigned long   mdrq;
581         unsigned long   sp;
582         unsigned long   epsw;
583         unsigned long   pc;
584         struct fpucontext *fpucontext;
585         unsigned long   oldmask;
586 }; */
587
588
589 #define AM33_SIGCONTEXT_D0 0
590 #define AM33_SIGCONTEXT_D1 4
591 #define AM33_SIGCONTEXT_D2 8
592 #define AM33_SIGCONTEXT_D3 12
593 #define AM33_SIGCONTEXT_A0 16
594 #define AM33_SIGCONTEXT_A1 20
595 #define AM33_SIGCONTEXT_A2 24
596 #define AM33_SIGCONTEXT_A3 28
597 #define AM33_SIGCONTEXT_E0 32
598 #define AM33_SIGCONTEXT_E1 36
599 #define AM33_SIGCONTEXT_E2 40
600 #define AM33_SIGCONTEXT_E3 44
601 #define AM33_SIGCONTEXT_E4 48
602 #define AM33_SIGCONTEXT_E5 52
603 #define AM33_SIGCONTEXT_E6 56
604 #define AM33_SIGCONTEXT_E7 60
605 #define AM33_SIGCONTEXT_LAR 64
606 #define AM33_SIGCONTEXT_LIR 68
607 #define AM33_SIGCONTEXT_MDR 72
608 #define AM33_SIGCONTEXT_MCVF 76
609 #define AM33_SIGCONTEXT_MCRL 80
610 #define AM33_SIGCONTEXT_MCRH 84
611 #define AM33_SIGCONTEXT_MDRQ 88
612 #define AM33_SIGCONTEXT_SP 92
613 #define AM33_SIGCONTEXT_EPSW 96
614 #define AM33_SIGCONTEXT_PC 100
615 #define AM33_SIGCONTEXT_FPUCONTEXT 104
616
617
618 static void
619 am33_linux_sigframe_cache_init (const struct tramp_frame *self,
620                                 struct frame_info *this_frame,
621                                 struct trad_frame_cache *this_cache,
622                                 CORE_ADDR func)
623 {
624   CORE_ADDR sc_base, fpubase;
625   int i;
626
627   sc_base = get_frame_register_unsigned (this_frame, E_SP_REGNUM);
628   if (self == &am33_linux_sigframe)
629     {
630       sc_base += 8;
631       sc_base = get_frame_memory_unsigned (this_frame, sc_base, 4);
632     }
633   else
634     {
635       sc_base += 12;
636       sc_base = get_frame_memory_unsigned (this_frame, sc_base, 4);
637       sc_base += 20;
638     }
639
640   trad_frame_set_reg_addr (this_cache, E_D0_REGNUM,
641                            sc_base + AM33_SIGCONTEXT_D0);
642   trad_frame_set_reg_addr (this_cache, E_D1_REGNUM,
643                            sc_base + AM33_SIGCONTEXT_D1);
644   trad_frame_set_reg_addr (this_cache, E_D2_REGNUM,
645                            sc_base + AM33_SIGCONTEXT_D2);
646   trad_frame_set_reg_addr (this_cache, E_D3_REGNUM,
647                            sc_base + AM33_SIGCONTEXT_D3);
648
649   trad_frame_set_reg_addr (this_cache, E_A0_REGNUM,
650                            sc_base + AM33_SIGCONTEXT_A0);
651   trad_frame_set_reg_addr (this_cache, E_A1_REGNUM,
652                            sc_base + AM33_SIGCONTEXT_A1);
653   trad_frame_set_reg_addr (this_cache, E_A2_REGNUM,
654                            sc_base + AM33_SIGCONTEXT_A2);
655   trad_frame_set_reg_addr (this_cache, E_A3_REGNUM,
656                            sc_base + AM33_SIGCONTEXT_A3);
657
658   trad_frame_set_reg_addr (this_cache, E_E0_REGNUM,
659                            sc_base + AM33_SIGCONTEXT_E0);
660   trad_frame_set_reg_addr (this_cache, E_E1_REGNUM,
661                            sc_base + AM33_SIGCONTEXT_E1);
662   trad_frame_set_reg_addr (this_cache, E_E2_REGNUM,
663                            sc_base + AM33_SIGCONTEXT_E2);
664   trad_frame_set_reg_addr (this_cache, E_E3_REGNUM,
665                            sc_base + AM33_SIGCONTEXT_E3);
666   trad_frame_set_reg_addr (this_cache, E_E4_REGNUM,
667                            sc_base + AM33_SIGCONTEXT_E4);
668   trad_frame_set_reg_addr (this_cache, E_E5_REGNUM,
669                            sc_base + AM33_SIGCONTEXT_E5);
670   trad_frame_set_reg_addr (this_cache, E_E6_REGNUM,
671                            sc_base + AM33_SIGCONTEXT_E6);
672   trad_frame_set_reg_addr (this_cache, E_E7_REGNUM,
673                            sc_base + AM33_SIGCONTEXT_E7);
674
675   trad_frame_set_reg_addr (this_cache, E_LAR_REGNUM,
676                            sc_base + AM33_SIGCONTEXT_LAR);
677   trad_frame_set_reg_addr (this_cache, E_LIR_REGNUM,
678                            sc_base + AM33_SIGCONTEXT_LIR);
679   trad_frame_set_reg_addr (this_cache, E_MDR_REGNUM,
680                            sc_base + AM33_SIGCONTEXT_MDR);
681   trad_frame_set_reg_addr (this_cache, E_MCVF_REGNUM,
682                            sc_base + AM33_SIGCONTEXT_MCVF);
683   trad_frame_set_reg_addr (this_cache, E_MCRL_REGNUM,
684                            sc_base + AM33_SIGCONTEXT_MCRL);
685   trad_frame_set_reg_addr (this_cache, E_MDRQ_REGNUM,
686                            sc_base + AM33_SIGCONTEXT_MDRQ);
687
688   trad_frame_set_reg_addr (this_cache, E_SP_REGNUM,
689                            sc_base + AM33_SIGCONTEXT_SP);
690   trad_frame_set_reg_addr (this_cache, E_PSW_REGNUM,
691                            sc_base + AM33_SIGCONTEXT_EPSW);
692   trad_frame_set_reg_addr (this_cache, E_PC_REGNUM,
693                            sc_base + AM33_SIGCONTEXT_PC);
694
695   fpubase = get_frame_memory_unsigned (this_frame,
696                                        sc_base + AM33_SIGCONTEXT_FPUCONTEXT,
697                                        4);
698   if (fpubase)
699     {
700       for (i = 0; i < 32; i++)
701         {
702           trad_frame_set_reg_addr (this_cache, E_FS0_REGNUM + i,
703                                    fpubase + 4 * i);
704         }
705       trad_frame_set_reg_addr (this_cache, E_FPCR_REGNUM, fpubase + 4 * 32);
706     }
707
708   trad_frame_set_id (this_cache, frame_id_build (sc_base, func));
709 }
710 \f
711 /* AM33 GNU/Linux osabi has been recognized.
712    Now's our chance to register our corefile handling.  */
713
714 static void
715 am33_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
716 {
717   linux_init_abi (info, gdbarch);
718
719   set_gdbarch_regset_from_core_section (gdbarch, 
720                                         am33_regset_from_core_section);
721   set_solib_svr4_fetch_link_map_offsets
722     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
723
724   tramp_frame_prepend_unwinder (gdbarch, &am33_linux_sigframe);
725   tramp_frame_prepend_unwinder (gdbarch, &am33_linux_rt_sigframe);
726 }
727
728 /* Provide a prototype to silence -Wmissing-prototypes.  */
729 extern initialize_file_ftype _initialize_mn10300_linux_tdep;
730
731 void
732 _initialize_mn10300_linux_tdep (void)
733 {
734   gdbarch_register_osabi (bfd_arch_mn10300, 0,
735                           GDB_OSABI_LINUX, am33_linux_init_osabi);
736 }
737