* i386-sol2-tdep.c: Include "solib-svr4.h".
[external/binutils.git] / gdb / i386-sol2-tdep.c
1 /* Target-dependent code for Solaris x86.
2
3    Copyright 2002, 2003, 2004 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 2 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, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.  */
21
22 #include "defs.h"
23 #include "value.h"
24 #include "osabi.h"
25
26 #include "i386-tdep.h"
27 #include "solib-svr4.h"
28
29 /* From <ia32/sys/reg.h>.  */
30 static int i386_sol2_gregset_reg_offset[] =
31 {
32   11 * 4,                       /* %eax */
33   10 * 4,                       /* %ecx */
34   9 * 4,                        /* %edx */
35   8 * 4,                        /* %ebx */
36   17 * 4,                       /* %esp */
37   6 * 4,                        /* %ebp */
38   5 * 4,                        /* %esi */
39   4 * 4,                        /* %edi */
40   14 * 4,                       /* %eip */
41   16 * 4,                       /* %eflags */
42   15 * 4,                       /* %cs */
43   18 * 4,                       /* %ss */
44   3 * 4,                        /* %ds */
45   2 * 4,                        /* %es */
46   1 * 4,                        /* %fs */
47   0 * 4                         /* %gs */
48 };
49
50 static int
51 i386_sol2_sigtramp_p (struct frame_info *next_frame)
52 {
53   CORE_ADDR pc = frame_pc_unwind (next_frame);
54
55   /* Signal handler frames under Solaris 2 are recognized by a return
56      address of 0xffffffff.  */
57   return (pc == 0xffffffff);
58 }
59
60 /* Solaris doesn't have a `struct sigcontext', but it does have a
61    `mcontext_t' that contains the saved set of machine registers.  */
62
63 static CORE_ADDR
64 i386_sol2_mcontext_addr (struct frame_info *next_frame)
65 {
66   CORE_ADDR sp, ucontext_addr;
67
68   sp = frame_unwind_register_unsigned (next_frame, I386_ESP_REGNUM);
69   ucontext_addr = get_frame_memory_unsigned (next_frame, sp + 8, 4);
70
71   return ucontext_addr + 36;
72 }
73
74 /* Solaris 2.  */
75
76 static void
77 i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
78 {
79   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
80
81   /* Solaris is SVR4-based.  */
82   i386_svr4_init_abi (info, gdbarch);
83
84   /* Solaris reserves space for its FPU emulator in `fpregset_t'.
85      There is also some space reserved for the registers of a Weitek
86      math coprocessor.  */
87   tdep->gregset_reg_offset = i386_sol2_gregset_reg_offset;
88   tdep->gregset_num_regs = ARRAY_SIZE (i386_sol2_gregset_reg_offset);
89   tdep->sizeof_gregset = 19 * 4;
90   tdep->sizeof_fpregset = 380;
91
92   /* Signal trampolines are slightly different from SVR4.  */
93   tdep->sigtramp_p = i386_sol2_sigtramp_p;
94   tdep->sigcontext_addr = i386_sol2_mcontext_addr;
95   tdep->sc_reg_offset = tdep->gregset_reg_offset;
96   tdep->sc_num_regs = tdep->gregset_num_regs;
97
98   set_solib_svr4_fetch_link_map_offsets
99     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
100 }
101 \f
102
103 static enum gdb_osabi
104 i386_sol2_osabi_sniffer (bfd *abfd)
105 {
106   /* If we have a section named .SUNW_version, then it is almost
107      certainly Solaris 2.  */
108   if (bfd_get_section_by_name (abfd, ".SUNW_version"))
109     return GDB_OSABI_SOLARIS;
110
111   return GDB_OSABI_UNKNOWN;
112 }
113
114 /* Provide a prototype to silence -Wmissing-prototypes.  */
115 void _initialize_i386_sol2_tdep (void);
116
117 void
118 _initialize_i386_sol2_tdep (void)
119 {
120   /* Register an ELF OS ABI sniffer for Solaris 2 binaries.  */
121   gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
122                                   i386_sol2_osabi_sniffer);
123
124   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SOLARIS,
125                           i386_sol2_init_abi);
126 }