configure clean up patch from Steve Ellcey.
[external/binutils.git] / gdb / amd64-sol2-tdep.c
1 /* Target-dependent code for AMD64 Solaris.
2
3    Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4    Contributed by Joseph Myers, CodeSourcery, LLC.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 #include "defs.h"
24 #include "frame.h"
25 #include "gdbcore.h"
26 #include "regcache.h"
27 #include "osabi.h"
28 #include "symtab.h"
29
30 #include "gdb_string.h"
31
32 #include "amd64-tdep.h"
33 #include "solib-svr4.h"
34
35 /* Mapping between the general-purpose registers in gregset_t format
36    and GDB's register cache layout.  */
37
38 /* From <sys/regset.h>.  */
39 static int amd64_sol2_gregset_reg_offset[] = {
40   14 * 8,                       /* %rax */
41   11 * 8,                       /* %rbx */
42   13 * 8,                       /* %rcx */
43   12 * 8,                       /* %rdx */
44   9 * 8,                        /* %rsi */
45   8 * 8,                        /* %rdi */
46   10 * 8,                       /* %rbp */
47   20 * 8,                       /* %rsp */
48   7 * 8,                        /* %r8 ... */
49   6 * 8,
50   5 * 8,
51   4 * 8,
52   3 * 8,
53   2 * 8,
54   1 * 8,
55   0 * 8,                        /* ... %r15 */
56   17 * 8,                       /* %rip */
57   16 * 8,                       /* %eflags */
58   18 * 8,                       /* %cs */
59   21 * 8,                       /* %ss */
60   25 * 8,                       /* %ds */
61   24 * 8,                       /* %es */
62   22 * 8,                       /* %fs */
63   23 * 8                        /* %gs */
64 };
65 \f
66
67 /* Return whether the frame preceding NEXT_FRAME corresponds to a
68    Solaris sigtramp routine.  */
69
70 static int
71 amd64_sol2_sigtramp_p (struct frame_info *next_frame)
72 {
73   CORE_ADDR pc = frame_pc_unwind (next_frame);
74   char *name;
75
76   find_pc_partial_function (pc, &name, NULL, NULL);
77   return (name && (strcmp ("sigacthandler", name) == 0
78                    || strcmp (name, "ucbsigvechandler") == 0));
79 }
80
81 /* Solaris doesn't have a 'struct sigcontext', but it does have a
82    'mcontext_t' that contains the saved set of machine registers.  */
83
84 static CORE_ADDR
85 amd64_sol2_mcontext_addr (struct frame_info *next_frame)
86 {
87   CORE_ADDR sp, ucontext_addr;
88
89   sp = frame_unwind_register_unsigned (next_frame, AMD64_RSP_REGNUM);
90   ucontext_addr = get_frame_memory_unsigned (next_frame, sp + 8, 8);
91
92   return ucontext_addr + 72;
93 }
94
95 static void
96 amd64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
97 {
98   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
99
100   tdep->gregset_reg_offset = amd64_sol2_gregset_reg_offset;
101   tdep->gregset_num_regs = ARRAY_SIZE (amd64_sol2_gregset_reg_offset);
102   tdep->sizeof_gregset = 28 * 8;
103
104   amd64_init_abi (info, gdbarch);
105
106   tdep->sigtramp_p = amd64_sol2_sigtramp_p;
107   tdep->sigcontext_addr = amd64_sol2_mcontext_addr;
108   tdep->sc_reg_offset = tdep->gregset_reg_offset;
109   tdep->sc_num_regs = tdep->gregset_num_regs;
110
111   /* Solaris uses SVR4-style shared libraries.  */
112   set_solib_svr4_fetch_link_map_offsets
113     (gdbarch, svr4_lp64_fetch_link_map_offsets);
114 }
115 \f
116
117 /* Provide a prototype to silence -Wmissing-prototypes.  */
118 extern void _initialize_amd64_sol2_tdep (void);
119
120 void
121 _initialize_amd64_sol2_tdep (void)
122 {
123   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
124                           GDB_OSABI_SOLARIS, amd64_sol2_init_abi);
125 }