1 /* Target-dependent code for NetBSD/arm.
2 
3    Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
4    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 "gdb_string.h"
25 
26 #include "arm-tdep.h"
27 #include "solib-svr4.h"
28 
29 /* Description of the longjmp buffer.  */
30 #define ARM_NBSD_JB_PC 24
31 #define ARM_NBSD_JB_ELEMENT_SIZE INT_REGISTER_SIZE
32 
33 /* For compatibility with previous implemenations of GDB on arm/NetBSD,
34    override the default little-endian breakpoint.  */
35 static const char arm_nbsd_arm_le_breakpoint[] = {0x11, 0x00, 0x00, 0xe6};
36 static const char arm_nbsd_arm_be_breakpoint[] = {0xe6, 0x00, 0x00, 0x11};
37 static const char arm_nbsd_thumb_le_breakpoint[] = {0xfe, 0xde};
38 static const char arm_nbsd_thumb_be_breakpoint[] = {0xde, 0xfe};
39 
40 static void
arm_netbsd_init_abi_common(struct gdbarch_info info,struct gdbarch * gdbarch)41 arm_netbsd_init_abi_common (struct gdbarch_info info,
42 			    struct gdbarch *gdbarch)
43 {
44   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
45 
46   tdep->lowest_pc = 0x8000;
47   switch (info.byte_order)
48     {
49     case BFD_ENDIAN_LITTLE:
50       tdep->arm_breakpoint = arm_nbsd_arm_le_breakpoint;
51       tdep->thumb_breakpoint = arm_nbsd_thumb_le_breakpoint;
52       tdep->arm_breakpoint_size = sizeof (arm_nbsd_arm_le_breakpoint);
53       tdep->thumb_breakpoint_size = sizeof (arm_nbsd_thumb_le_breakpoint);
54       break;
55 
56     case BFD_ENDIAN_BIG:
57       tdep->arm_breakpoint = arm_nbsd_arm_be_breakpoint;
58       tdep->thumb_breakpoint = arm_nbsd_thumb_be_breakpoint;
59       tdep->arm_breakpoint_size = sizeof (arm_nbsd_arm_be_breakpoint);
60       tdep->thumb_breakpoint_size = sizeof (arm_nbsd_thumb_be_breakpoint);
61       break;
62 
63     default:
64       internal_error (__FILE__, __LINE__,
65 		      _("arm_gdbarch_init: bad byte order for float format"));
66     }
67 
68   tdep->jb_pc = ARM_NBSD_JB_PC;
69   tdep->jb_elt_size = ARM_NBSD_JB_ELEMENT_SIZE;
70 
71   /* Single stepping.  */
72   set_gdbarch_software_single_step (gdbarch, arm_software_single_step);
73 }
74 
75 static void
arm_netbsd_aout_init_abi(struct gdbarch_info info,struct gdbarch * gdbarch)76 arm_netbsd_aout_init_abi (struct gdbarch_info info,
77 			  struct gdbarch *gdbarch)
78 {
79   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
80 
81   arm_netbsd_init_abi_common (info, gdbarch);
82   if (tdep->fp_model == ARM_FLOAT_AUTO)
83     tdep->fp_model = ARM_FLOAT_SOFT_FPA;
84 }
85 
86 static void
arm_netbsd_elf_init_abi(struct gdbarch_info info,struct gdbarch * gdbarch)87 arm_netbsd_elf_init_abi (struct gdbarch_info info,
88 			 struct gdbarch *gdbarch)
89 {
90   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
91 
92   arm_netbsd_init_abi_common (info, gdbarch);
93   if (tdep->fp_model == ARM_FLOAT_AUTO)
94     tdep->fp_model = ARM_FLOAT_SOFT_VFP;
95 
96   /* NetBSD ELF uses SVR4-style shared libraries.  */
97   set_solib_svr4_fetch_link_map_offsets
98     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
99 }
100 
101 static enum gdb_osabi
arm_netbsd_aout_osabi_sniffer(bfd * abfd)102 arm_netbsd_aout_osabi_sniffer (bfd *abfd)
103 {
104   if (strcmp (bfd_get_target (abfd), "a.out-arm-netbsd") == 0)
105     return GDB_OSABI_NETBSD_AOUT;
106 
107   return GDB_OSABI_UNKNOWN;
108 }
109 
110 /* Provide a prototype to silence -Wmissing-prototypes.  */
111 extern initialize_file_ftype _initialize_arm_netbsd_tdep;
112 
113 void
_initialize_arm_netbsd_tdep(void)114 _initialize_arm_netbsd_tdep (void)
115 {
116   gdbarch_register_osabi_sniffer (bfd_arch_arm, bfd_target_aout_flavour,
117 				  arm_netbsd_aout_osabi_sniffer);
118 
119   gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_NETBSD_AOUT,
120                           arm_netbsd_aout_init_abi);
121   gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_NETBSD_ELF,
122                           arm_netbsd_elf_init_abi);
123 }
124