OSDN Git Service

aabe4af206b8d2834b7ce4b680cf6782f0a4e190
[pf3gnuchains/pf3gnuchains3x.git] / gdb / mn10300-linux-tdep.c
1 /* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger.
2
3    Copyright (C) 2003, 2004, 2005, 2006, 2007 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 "gdb_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
35 #include <stdlib.h>
36
37 /* Transliterated from <asm-mn10300/elf.h>...  */
38 #define MN10300_ELF_NGREG 28
39 #define MN10300_ELF_NFPREG 32
40
41 typedef gdb_byte   mn10300_elf_greg_t[4];
42 typedef mn10300_elf_greg_t mn10300_elf_gregset_t[MN10300_ELF_NGREG];
43
44 typedef gdb_byte   mn10300_elf_fpreg_t[4];
45 typedef struct
46 {
47   mn10300_elf_fpreg_t fpregs[MN10300_ELF_NFPREG];
48   gdb_byte    fpcr[4];
49 } mn10300_elf_fpregset_t;
50
51 /* elf_gregset_t register indices stolen from include/asm-mn10300/ptrace.h.  */
52 #define MN10300_ELF_GREGSET_T_REG_INDEX_A3      0
53 #define MN10300_ELF_GREGSET_T_REG_INDEX_A2      1
54 #define MN10300_ELF_GREGSET_T_REG_INDEX_D3      2
55 #define MN10300_ELF_GREGSET_T_REG_INDEX_D2      3
56 #define MN10300_ELF_GREGSET_T_REG_INDEX_MCVF    4
57 #define MN10300_ELF_GREGSET_T_REG_INDEX_MCRL    5
58 #define MN10300_ELF_GREGSET_T_REG_INDEX_MCRH    6
59 #define MN10300_ELF_GREGSET_T_REG_INDEX_MDRQ    7
60 #define MN10300_ELF_GREGSET_T_REG_INDEX_E1      8
61 #define MN10300_ELF_GREGSET_T_REG_INDEX_E0      9
62 #define MN10300_ELF_GREGSET_T_REG_INDEX_E7      10
63 #define MN10300_ELF_GREGSET_T_REG_INDEX_E6      11
64 #define MN10300_ELF_GREGSET_T_REG_INDEX_E5      12
65 #define MN10300_ELF_GREGSET_T_REG_INDEX_E4      13
66 #define MN10300_ELF_GREGSET_T_REG_INDEX_E3      14
67 #define MN10300_ELF_GREGSET_T_REG_INDEX_E2      15
68 #define MN10300_ELF_GREGSET_T_REG_INDEX_SP      16
69 #define MN10300_ELF_GREGSET_T_REG_INDEX_LAR     17
70 #define MN10300_ELF_GREGSET_T_REG_INDEX_LIR     18
71 #define MN10300_ELF_GREGSET_T_REG_INDEX_MDR     19
72 #define MN10300_ELF_GREGSET_T_REG_INDEX_A1      20
73 #define MN10300_ELF_GREGSET_T_REG_INDEX_A0      21
74 #define MN10300_ELF_GREGSET_T_REG_INDEX_D1      22
75 #define MN10300_ELF_GREGSET_T_REG_INDEX_D0      23
76 #define MN10300_ELF_GREGSET_T_REG_INDEX_ORIG_D0 24
77 #define MN10300_ELF_GREGSET_T_REG_INDEX_EPSW    25
78 #define MN10300_ELF_GREGSET_T_REG_INDEX_PC      26
79
80 /* New gdbarch API for corefile registers.
81    Given a section name and size, create a struct reg object
82    with a supply_register and a collect_register method.  */
83
84 /* Copy register value of REGNUM from regset to regcache.  
85    If REGNUM is -1, do this for all gp registers in regset.  */
86
87 static void
88 am33_supply_gregset_method (const struct regset *regset, 
89                             struct regcache *regcache, 
90                             int regnum, const void *gregs, size_t len)
91 {
92   char zerobuf[MAX_REGISTER_SIZE];
93   const mn10300_elf_greg_t *regp = (const mn10300_elf_greg_t *) gregs;
94   int i;
95
96   gdb_assert (len == sizeof (mn10300_elf_gregset_t));
97
98   switch (regnum) {
99   case E_D0_REGNUM:
100     regcache_raw_supply (regcache, E_D0_REGNUM, 
101                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D0));
102     break;
103   case E_D1_REGNUM:
104     regcache_raw_supply (regcache, E_D1_REGNUM, 
105                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D1));
106     break;
107   case E_D2_REGNUM:
108     regcache_raw_supply (regcache, E_D2_REGNUM, 
109                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D2));
110     break;
111   case E_D3_REGNUM:
112     regcache_raw_supply (regcache, E_D3_REGNUM, 
113                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_D3));
114     break;
115   case E_A0_REGNUM:
116     regcache_raw_supply (regcache, E_A0_REGNUM, 
117                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A0));
118     break;
119   case E_A1_REGNUM:
120     regcache_raw_supply (regcache, E_A1_REGNUM, 
121                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A1));
122     break;
123   case E_A2_REGNUM:
124     regcache_raw_supply (regcache, E_A2_REGNUM, 
125                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A2));
126     break;
127   case E_A3_REGNUM:
128     regcache_raw_supply (regcache, E_A3_REGNUM, 
129                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_A3));
130     break;
131   case E_SP_REGNUM:
132     regcache_raw_supply (regcache, E_SP_REGNUM, 
133                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_SP));
134     break;
135   case E_PC_REGNUM:
136     regcache_raw_supply (regcache, E_PC_REGNUM, 
137                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_PC));
138     break;
139   case E_MDR_REGNUM:
140     regcache_raw_supply (regcache, E_MDR_REGNUM, 
141                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MDR));
142     break;
143   case E_PSW_REGNUM:
144     regcache_raw_supply (regcache, E_PSW_REGNUM, 
145                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_EPSW));
146     break;
147   case E_LIR_REGNUM:
148     regcache_raw_supply (regcache, E_LIR_REGNUM, 
149                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_LIR));
150     break;
151   case E_LAR_REGNUM:
152     regcache_raw_supply (regcache, E_LAR_REGNUM, 
153                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_LAR));
154     break;
155   case E_MDRQ_REGNUM:
156     regcache_raw_supply (regcache, E_MDRQ_REGNUM, 
157                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MDRQ));
158     break;
159   case E_E0_REGNUM:
160     regcache_raw_supply (regcache, E_E0_REGNUM,   
161                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E0));
162     break;
163   case E_E1_REGNUM:
164     regcache_raw_supply (regcache, E_E1_REGNUM,
165                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E1));
166     break;
167   case E_E2_REGNUM:
168     regcache_raw_supply (regcache, E_E2_REGNUM, 
169                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E2));
170     break;
171   case E_E3_REGNUM:
172     regcache_raw_supply (regcache, E_E3_REGNUM, 
173                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E3));
174     break;
175   case E_E4_REGNUM:
176     regcache_raw_supply (regcache, E_E4_REGNUM, 
177                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E4));
178     break;
179   case E_E5_REGNUM:
180     regcache_raw_supply (regcache, E_E5_REGNUM, 
181                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E5));
182     break;
183   case E_E6_REGNUM:
184     regcache_raw_supply (regcache, E_E6_REGNUM, 
185                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E6));
186     break;
187   case E_E7_REGNUM:
188     regcache_raw_supply (regcache, E_E7_REGNUM, 
189                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_E7));
190     break;
191
192     /* ssp, msp, and usp are inaccessible.  */
193   case E_E8_REGNUM:
194     memset (zerobuf, 0, MAX_REGISTER_SIZE);
195     regcache_raw_supply (regcache, E_E8_REGNUM, zerobuf);
196     break;
197   case E_E9_REGNUM:
198     memset (zerobuf, 0, MAX_REGISTER_SIZE);
199     regcache_raw_supply (regcache, E_E9_REGNUM, zerobuf);
200     break;
201   case E_E10_REGNUM:
202     memset (zerobuf, 0, MAX_REGISTER_SIZE);
203     regcache_raw_supply (regcache, E_E10_REGNUM, zerobuf);
204
205     break;
206   case E_MCRH_REGNUM:
207     regcache_raw_supply (regcache, E_MCRH_REGNUM, 
208                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCRH));
209     break;
210   case E_MCRL_REGNUM:
211     regcache_raw_supply (regcache, E_MCRL_REGNUM, 
212                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCRL));
213     break;
214   case E_MCVF_REGNUM:
215     regcache_raw_supply (regcache, E_MCVF_REGNUM, 
216                          (regp + MN10300_ELF_GREGSET_T_REG_INDEX_MCVF));
217     break;
218   case E_FPCR_REGNUM:
219     /* FPCR is numbered among the GP regs, but handled as an FP reg.
220        Do nothing.  */
221     break;
222   case E_FPCR_REGNUM + 1:
223     /* The two unused registers beyond fpcr are inaccessible.  */
224     memset (zerobuf, 0, MAX_REGISTER_SIZE);
225     regcache_raw_supply (regcache, E_FPCR_REGNUM + 1, zerobuf);
226     break;
227   case E_FPCR_REGNUM + 2:
228     memset (zerobuf, 0, MAX_REGISTER_SIZE);
229     regcache_raw_supply (regcache, E_FPCR_REGNUM + 2, zerobuf);
230     break;
231   default:      /* An error, obviously, but should we error out?  */
232     break;
233   case -1:
234     for (i = 0; i < MN10300_ELF_NGREG; i++)
235       am33_supply_gregset_method (regset, regcache, i, gregs, len);
236     break;
237   }
238   return;
239 }
240
241 /* Copy fp register value of REGNUM from regset to regcache.  
242    If REGNUM is -1, do this for all fp registers in regset. */
243
244 static void
245 am33_supply_fpregset_method (const struct regset *regset, 
246                              struct regcache *regcache, 
247                              int regnum, const void *fpregs, size_t len)
248 {
249   const mn10300_elf_fpregset_t *fpregset = fpregs;
250
251   gdb_assert (len == sizeof (mn10300_elf_fpregset_t));
252
253   if (regnum == -1)
254     {
255       int i;
256
257       for (i = 0; i < MN10300_ELF_NFPREG; i++)
258         am33_supply_fpregset_method (regset, regcache,
259                                      E_FS0_REGNUM + i, fpregs, len);
260       am33_supply_fpregset_method (regset, regcache, 
261                                    E_FPCR_REGNUM, fpregs, len);
262     }
263   else if (regnum == E_FPCR_REGNUM)
264     regcache_raw_supply (regcache, E_FPCR_REGNUM, 
265                          &fpregset->fpcr);
266   else if (E_FS0_REGNUM <= regnum && 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 /* Create a struct regset from a corefile register section.  */
453
454 static const struct regset *
455 am33_regset_from_core_section (struct gdbarch *gdbarch, 
456                                const char *sect_name, 
457                                size_t sect_size)
458 {
459   /* We will call regset_alloc, and pass the names of the supply and
460      collect methods.  */
461
462   if (sect_size == sizeof (mn10300_elf_fpregset_t))
463     return regset_alloc (gdbarch, 
464                          am33_supply_fpregset_method,
465                          am33_collect_fpregset_method);
466   else
467     return regset_alloc (gdbarch, 
468                          am33_supply_gregset_method,
469                          am33_collect_gregset_method);
470 }
471 \f
472 static void
473 am33_linux_sigframe_cache_init (const struct tramp_frame *self,
474                                 struct frame_info *next_frame,
475                                 struct trad_frame_cache *this_cache,
476                                 CORE_ADDR func);
477
478 static const struct tramp_frame am33_linux_sigframe = {
479   SIGTRAMP_FRAME,
480   1,
481   {
482     /* mov     119,d0 */
483     { 0x2c, -1 },
484     { 0x77, -1 },
485     { 0x00, -1 },
486     /* syscall 0 */
487     { 0xf0, -1 },
488     { 0xe0, -1 },
489     { TRAMP_SENTINEL_INSN, -1 }
490   },
491   am33_linux_sigframe_cache_init
492 };
493
494 static const struct tramp_frame am33_linux_rt_sigframe = {
495   SIGTRAMP_FRAME,
496   1,
497   {
498     /* mov     173,d0 */
499     { 0x2c, -1 },
500     { 0xad, -1 },
501     { 0x00, -1 },
502     /* syscall 0 */
503     { 0xf0, -1 },
504     { 0xe0, -1 },
505     { TRAMP_SENTINEL_INSN, -1 }
506   },
507   am33_linux_sigframe_cache_init
508 };
509
510 /* Relevant struct definitions for signal handling...
511
512 From arch/mn10300/kernel/sigframe.h:
513
514 struct sigframe
515 {
516         void (*pretcode)(void);
517         int sig;
518         struct sigcontext sc;
519         struct fpucontext fpuctx;
520         unsigned long extramask[_NSIG_WORDS-1];
521         char retcode[8];
522 };
523
524 struct rt_sigframe
525 {
526         void (*pretcode)(void);
527         int sig;
528         struct siginfo *pinfo;
529         void *puc;
530         struct siginfo info;
531         struct ucontext uc;
532         struct fpucontext fpuctx;
533         char retcode[8];
534 };
535
536 From include/asm-mn10300/ucontext.h:
537
538 struct ucontext {
539         unsigned long     uc_flags;
540         struct ucontext  *uc_link;
541         stack_t           uc_stack;
542         struct sigcontext uc_mcontext;
543         sigset_t          uc_sigmask;
544 };
545
546 From include/asm-mn10300/sigcontext.h:
547
548 struct fpucontext {
549         unsigned long   fs[32];
550         unsigned long   fpcr;
551 };
552
553 struct sigcontext {
554         unsigned long   d0;
555         unsigned long   d1;
556         unsigned long   d2;
557         unsigned long   d3;
558         unsigned long   a0;
559         unsigned long   a1;
560         unsigned long   a2;
561         unsigned long   a3;
562         unsigned long   e0;
563         unsigned long   e1;
564         unsigned long   e2;
565         unsigned long   e3;
566         unsigned long   e4;
567         unsigned long   e5;
568         unsigned long   e6;
569         unsigned long   e7;
570         unsigned long   lar;
571         unsigned long   lir;
572         unsigned long   mdr;
573         unsigned long   mcvf;
574         unsigned long   mcrl;
575         unsigned long   mcrh;
576         unsigned long   mdrq;
577         unsigned long   sp;
578         unsigned long   epsw;
579         unsigned long   pc;
580         struct fpucontext *fpucontext;
581         unsigned long   oldmask;
582 }; */
583
584
585 #define AM33_SIGCONTEXT_D0 0
586 #define AM33_SIGCONTEXT_D1 4
587 #define AM33_SIGCONTEXT_D2 8
588 #define AM33_SIGCONTEXT_D3 12
589 #define AM33_SIGCONTEXT_A0 16
590 #define AM33_SIGCONTEXT_A1 20
591 #define AM33_SIGCONTEXT_A2 24
592 #define AM33_SIGCONTEXT_A3 28
593 #define AM33_SIGCONTEXT_E0 32
594 #define AM33_SIGCONTEXT_E1 36
595 #define AM33_SIGCONTEXT_E2 40
596 #define AM33_SIGCONTEXT_E3 44
597 #define AM33_SIGCONTEXT_E4 48
598 #define AM33_SIGCONTEXT_E5 52
599 #define AM33_SIGCONTEXT_E6 56
600 #define AM33_SIGCONTEXT_E7 60
601 #define AM33_SIGCONTEXT_LAR 64
602 #define AM33_SIGCONTEXT_LIR 68
603 #define AM33_SIGCONTEXT_MDR 72
604 #define AM33_SIGCONTEXT_MCVF 76
605 #define AM33_SIGCONTEXT_MCRL 80
606 #define AM33_SIGCONTEXT_MCRH 84
607 #define AM33_SIGCONTEXT_MDRQ 88
608 #define AM33_SIGCONTEXT_SP 92
609 #define AM33_SIGCONTEXT_EPSW 96
610 #define AM33_SIGCONTEXT_PC 100
611 #define AM33_SIGCONTEXT_FPUCONTEXT 104
612
613
614 static void
615 am33_linux_sigframe_cache_init (const struct tramp_frame *self,
616                                 struct frame_info *next_frame,
617                                 struct trad_frame_cache *this_cache,
618                                 CORE_ADDR func)
619 {
620   CORE_ADDR sc_base, fpubase;
621   int i;
622
623   sc_base = frame_unwind_register_unsigned (next_frame, E_SP_REGNUM);
624   if (self == &am33_linux_sigframe)
625     {
626       sc_base += 8;
627     }
628   else
629     {
630       sc_base += 12;
631       sc_base = get_frame_memory_unsigned (next_frame, sc_base, 4);
632       sc_base += 20;
633     }
634
635   trad_frame_set_reg_addr (this_cache, E_D0_REGNUM,
636                            sc_base + AM33_SIGCONTEXT_D0);
637   trad_frame_set_reg_addr (this_cache, E_D1_REGNUM,
638                            sc_base + AM33_SIGCONTEXT_D1);
639   trad_frame_set_reg_addr (this_cache, E_D2_REGNUM,
640                            sc_base + AM33_SIGCONTEXT_D2);
641   trad_frame_set_reg_addr (this_cache, E_D3_REGNUM,
642                            sc_base + AM33_SIGCONTEXT_D3);
643
644   trad_frame_set_reg_addr (this_cache, E_A0_REGNUM,
645                            sc_base + AM33_SIGCONTEXT_A0);
646   trad_frame_set_reg_addr (this_cache, E_A1_REGNUM,
647                            sc_base + AM33_SIGCONTEXT_A1);
648   trad_frame_set_reg_addr (this_cache, E_A2_REGNUM,
649                            sc_base + AM33_SIGCONTEXT_A2);
650   trad_frame_set_reg_addr (this_cache, E_A3_REGNUM,
651                            sc_base + AM33_SIGCONTEXT_A3);
652
653   trad_frame_set_reg_addr (this_cache, E_E0_REGNUM,
654                            sc_base + AM33_SIGCONTEXT_E0);
655   trad_frame_set_reg_addr (this_cache, E_E1_REGNUM,
656                            sc_base + AM33_SIGCONTEXT_E1);
657   trad_frame_set_reg_addr (this_cache, E_E2_REGNUM,
658                            sc_base + AM33_SIGCONTEXT_E2);
659   trad_frame_set_reg_addr (this_cache, E_E3_REGNUM,
660                            sc_base + AM33_SIGCONTEXT_E3);
661   trad_frame_set_reg_addr (this_cache, E_E4_REGNUM,
662                            sc_base + AM33_SIGCONTEXT_E4);
663   trad_frame_set_reg_addr (this_cache, E_E5_REGNUM,
664                            sc_base + AM33_SIGCONTEXT_E5);
665   trad_frame_set_reg_addr (this_cache, E_E6_REGNUM,
666                            sc_base + AM33_SIGCONTEXT_E6);
667   trad_frame_set_reg_addr (this_cache, E_E7_REGNUM,
668                            sc_base + AM33_SIGCONTEXT_E7);
669
670   trad_frame_set_reg_addr (this_cache, E_LAR_REGNUM,
671                            sc_base + AM33_SIGCONTEXT_LAR);
672   trad_frame_set_reg_addr (this_cache, E_LIR_REGNUM,
673                            sc_base + AM33_SIGCONTEXT_LIR);
674   trad_frame_set_reg_addr (this_cache, E_MDR_REGNUM,
675                            sc_base + AM33_SIGCONTEXT_MDR);
676   trad_frame_set_reg_addr (this_cache, E_MCVF_REGNUM,
677                            sc_base + AM33_SIGCONTEXT_MCVF);
678   trad_frame_set_reg_addr (this_cache, E_MCRL_REGNUM,
679                            sc_base + AM33_SIGCONTEXT_MCRL);
680   trad_frame_set_reg_addr (this_cache, E_MDRQ_REGNUM,
681                            sc_base + AM33_SIGCONTEXT_MDRQ);
682
683   trad_frame_set_reg_addr (this_cache, E_SP_REGNUM,
684                            sc_base + AM33_SIGCONTEXT_SP);
685   trad_frame_set_reg_addr (this_cache, E_PSW_REGNUM,
686                            sc_base + AM33_SIGCONTEXT_EPSW);
687   trad_frame_set_reg_addr (this_cache, E_PC_REGNUM,
688                            sc_base + AM33_SIGCONTEXT_PC);
689
690   fpubase = get_frame_memory_unsigned (next_frame,
691                                        sc_base + AM33_SIGCONTEXT_FPUCONTEXT, 4);
692   if (fpubase)
693     {
694       for (i = 0; i < 32; i++)
695         {
696           trad_frame_set_reg_addr (this_cache, E_FS0_REGNUM + i,
697                                    fpubase + 4 * i);
698         }
699       trad_frame_set_reg_addr (this_cache, E_FPCR_REGNUM, fpubase + 4 * 32);
700     }
701
702   trad_frame_set_id (this_cache, frame_id_build (sc_base, func));
703 }
704 \f
705 /* AM33 GNU/Linux osabi has been recognized.
706    Now's our chance to register our corefile handling.  */
707
708 static void
709 am33_linux_init_osabi (struct gdbarch_info gdbinfo, struct gdbarch *gdbarch)
710 {
711   set_gdbarch_regset_from_core_section (gdbarch, 
712                                         am33_regset_from_core_section);
713   set_solib_svr4_fetch_link_map_offsets
714     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
715
716   tramp_frame_prepend_unwinder (gdbarch, &am33_linux_sigframe);
717   tramp_frame_prepend_unwinder (gdbarch, &am33_linux_rt_sigframe);
718 }
719
720 void
721 _initialize_mn10300_linux_tdep (void)
722 {
723   gdbarch_register_osabi (bfd_arch_mn10300, 0,
724                           GDB_OSABI_LINUX, am33_linux_init_osabi);
725 }
726