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 "gdb_string.h" 27 28 #include "i386-tdep.h" 29 #include "solib-svr4.h" 30 31 /* From <ia32/sys/reg.h>. */ 32 static int i386_sol2_gregset_reg_offset[] = 33 { 34 11 * 4, /* %eax */ 35 10 * 4, /* %ecx */ 36 9 * 4, /* %edx */ 37 8 * 4, /* %ebx */ 38 17 * 4, /* %esp */ 39 6 * 4, /* %ebp */ 40 5 * 4, /* %esi */ 41 4 * 4, /* %edi */ 42 14 * 4, /* %eip */ 43 16 * 4, /* %eflags */ 44 15 * 4, /* %cs */ 45 18 * 4, /* %ss */ 46 3 * 4, /* %ds */ 47 2 * 4, /* %es */ 48 1 * 4, /* %fs */ 49 0 * 4 /* %gs */ 50 }; 51 52 /* Return whether the frame preceding NEXT_FRAME corresponds to a 53 Solaris sigtramp routine. */ 54 55 static int 56 i386_sol2_sigtramp_p (struct frame_info *next_frame) 57 { 58 CORE_ADDR pc = frame_pc_unwind (next_frame); 59 char *name; 60 61 find_pc_partial_function (pc, &name, NULL, NULL); 62 return (name && (strcmp ("sigacthandler", name) == 0 63 || strcmp (name, "ucbsigvechandler") == 0)); 64 } 65 66 /* Solaris doesn't have a `struct sigcontext', but it does have a 67 `mcontext_t' that contains the saved set of machine registers. */ 68 69 static CORE_ADDR 70 i386_sol2_mcontext_addr (struct frame_info *next_frame) 71 { 72 CORE_ADDR sp, ucontext_addr; 73 74 sp = frame_unwind_register_unsigned (next_frame, I386_ESP_REGNUM); 75 ucontext_addr = get_frame_memory_unsigned (next_frame, sp + 8, 4); 76 77 return ucontext_addr + 36; 78 } 79 80 /* Solaris 2. */ 81 82 static void 83 i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) 84 { 85 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 86 87 /* Solaris is SVR4-based. */ 88 i386_svr4_init_abi (info, gdbarch); 89 90 /* Solaris reserves space for its FPU emulator in `fpregset_t'. 91 There is also some space reserved for the registers of a Weitek 92 math coprocessor. */ 93 tdep->gregset_reg_offset = i386_sol2_gregset_reg_offset; 94 tdep->gregset_num_regs = ARRAY_SIZE (i386_sol2_gregset_reg_offset); 95 tdep->sizeof_gregset = 19 * 4; 96 tdep->sizeof_fpregset = 380; 97 98 /* Signal trampolines are slightly different from SVR4. */ 99 tdep->sigtramp_p = i386_sol2_sigtramp_p; 100 tdep->sigcontext_addr = i386_sol2_mcontext_addr; 101 tdep->sc_reg_offset = tdep->gregset_reg_offset; 102 tdep->sc_num_regs = tdep->gregset_num_regs; 103 104 set_solib_svr4_fetch_link_map_offsets 105 (gdbarch, svr4_ilp32_fetch_link_map_offsets); 106 } 107 108 109 static enum gdb_osabi 110 i386_sol2_osabi_sniffer (bfd *abfd) 111 { 112 /* If we have a section named .SUNW_version, then it is almost 113 certainly Solaris 2. */ 114 if (bfd_get_section_by_name (abfd, ".SUNW_version")) 115 return GDB_OSABI_SOLARIS; 116 117 return GDB_OSABI_UNKNOWN; 118 } 119 120 /* Provide a prototype to silence -Wmissing-prototypes. */ 121 void _initialize_i386_sol2_tdep (void); 122 123 void 124 _initialize_i386_sol2_tdep (void) 125 { 126 /* Register an ELF OS ABI sniffer for Solaris 2 binaries. */ 127 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour, 128 i386_sol2_osabi_sniffer); 129 130 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SOLARIS, 131 i386_sol2_init_abi); 132 } 133