1/* Target-dependent code for the MIPS architecture running on IRIX,
2   for GDB, the GNU Debugger.
3
4   Copyright (C) 2002, 2007 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.  */
20
21#include "defs.h"
22#include "osabi.h"
23
24#include "elf-bfd.h"
25
26static void
27mips_irix_elf_osabi_sniff_abi_tag_sections (bfd *abfd, asection *sect,
28                                            void *obj)
29{
30  enum gdb_osabi *os_ident_ptr = obj;
31  const char *name;
32  unsigned int sectsize;
33
34  name = bfd_get_section_name (abfd, sect);
35  sectsize = bfd_section_size (abfd, sect);
36
37  if (strncmp (name, ".MIPS.", 6) == 0 && sectsize > 0)
38    {
39      /* The presence of a section named with a ".MIPS." prefix is
40         indicative of an IRIX binary.  */
41      *os_ident_ptr = GDB_OSABI_IRIX;
42    }
43}
44
45static enum gdb_osabi
46mips_irix_elf_osabi_sniffer (bfd *abfd)
47{
48  unsigned int elfosabi;
49  enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
50
51  /* If the generic sniffer gets a hit, return and let other sniffers
52     get a crack at it.  */
53  bfd_map_over_sections (abfd,
54			 generic_elf_osabi_sniff_abi_tag_sections,
55			 &osabi);
56  if (osabi != GDB_OSABI_UNKNOWN)
57    return GDB_OSABI_UNKNOWN;
58
59  elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
60
61  if (elfosabi == ELFOSABI_NONE)
62    {
63      /* When elfosabi is ELFOSABI_NONE (0), then the ELF structures in the
64	 file are conforming to the base specification for that machine
65	 (there are no OS-specific extensions).  In order to determine the
66	 real OS in use we must look for OS notes that have been added.
67
68	 For IRIX, we simply look for sections named with .MIPS. as
69	 prefixes.  */
70      bfd_map_over_sections (abfd,
71			     mips_irix_elf_osabi_sniff_abi_tag_sections,
72			     &osabi);
73    }
74  return osabi;
75}
76
77static void
78mips_irix_init_abi (struct gdbarch_info info,
79                    struct gdbarch *gdbarch)
80{
81}
82
83void
84_initialize_mips_irix_tdep (void)
85{
86  /* Register an ELF OS ABI sniffer for IRIX binaries.  */
87  gdbarch_register_osabi_sniffer (bfd_arch_mips,
88				  bfd_target_elf_flavour,
89				  mips_irix_elf_osabi_sniffer);
90
91  gdbarch_register_osabi (bfd_arch_mips, 0, GDB_OSABI_IRIX,
92			  mips_irix_init_abi);
93}
94