gdb/
[external/binutils.git] / gdb / tilegx-linux-tdep.c
1 /* Target-dependent code for GNU/Linux on Tilera TILE-Gx processors.
2
3    Copyright 2012 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 3 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, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21 #include "osabi.h"
22 #include "linux-tdep.h"
23 #include "glibc-tdep.h"
24 #include "solib-svr4.h"
25 #include "symtab.h"
26 #include "regcache.h"
27 #include "regset.h"
28 #include "tramp-frame.h"
29 #include "trad-frame.h"
30 #include "tilegx-tdep.h"
31
32 /* Signal trampoline support.  */
33
34 static void
35 tilegx_linux_sigframe_init (const struct tramp_frame *self,
36                             struct frame_info *this_frame,
37                             struct trad_frame_cache *this_cache,
38                             CORE_ADDR func)
39 {
40   CORE_ADDR pc = get_frame_register_unsigned (this_frame, 64);
41   CORE_ADDR sp = get_frame_register_unsigned (this_frame, 54);
42   CORE_ADDR base = sp + 16;
43   int i;
44
45   for (i = 0; i < 56; i++)
46     trad_frame_set_reg_addr (this_cache, i, base + i * 8);
47
48   trad_frame_set_reg_value (this_cache, 64, pc);
49
50   /* Save a frame ID.  */
51   trad_frame_set_id (this_cache, frame_id_build (base, func));
52 }
53
54 static const struct tramp_frame tilegx_linux_rt_sigframe =
55 {
56   SIGTRAMP_FRAME,
57   8,
58   {
59     { 0x00045fe551483000ULL, -1 }, /* { moveli r10, 139 } */
60     { 0x286b180051485000ULL, -1 }, /* { swint1 } */
61     { TRAMP_SENTINEL_INSN, -1 }
62   },
63   tilegx_linux_sigframe_init
64 };
65
66 /* Supply raw registers from REGCACHE to REGS.  */
67
68 static void
69 tilegx_linux_supply_regset (const struct regset *regset,
70                             struct regcache *regcache,
71                             int regnum, const void *regs, size_t len)
72 {
73   struct gdbarch *arch = get_regcache_arch (regcache);
74   const char *ptr = regs;
75   int i;
76
77   /* This logic must match that of struct pt_regs in "ptrace.h".  */
78   for (i = 0; i < TILEGX_NUM_EASY_REGS + 1; i++, ptr += tilegx_reg_size)
79     {
80       int gri = (i < TILEGX_NUM_EASY_REGS) ? i : TILEGX_PC_REGNUM;
81
82       if (regnum == gri || regnum == -1)
83         regcache_raw_supply (regcache, gri, ptr);
84     }
85 }
86
87 /* TILE-Gx Linux kernel register set.  */
88 static struct regset tilegx_linux_regset =
89 {
90   NULL,
91   tilegx_linux_supply_regset
92 };
93
94 static const struct regset *
95 tilegx_regset_from_core_section (struct gdbarch *gdbarch,
96                                  const char *sect_name,
97                                  size_t sect_size)
98 {
99   if (strcmp (sect_name, ".reg") == 0)
100     return &tilegx_linux_regset;
101
102   return NULL;
103 }
104
105 /* OS specific initialization of gdbarch.  */
106
107 static void
108 tilegx_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
109 {
110   int arch_size = gdbarch_addr_bit (gdbarch);
111
112   linux_init_abi (info, gdbarch);
113
114   tramp_frame_prepend_unwinder (gdbarch, &tilegx_linux_rt_sigframe);
115
116   set_gdbarch_regset_from_core_section (gdbarch,
117                                         tilegx_regset_from_core_section);
118
119   /* GNU/Linux uses SVR4-style shared libraries.  */
120   if (arch_size == 32)
121     set_solib_svr4_fetch_link_map_offsets (gdbarch,
122                                            svr4_ilp32_fetch_link_map_offsets);
123   else
124     set_solib_svr4_fetch_link_map_offsets (gdbarch,
125                                            svr4_lp64_fetch_link_map_offsets);
126
127   /* Enable TLS support.  */
128   set_gdbarch_fetch_tls_load_module_address (gdbarch,
129                                              svr4_fetch_objfile_link_map);
130
131   /* Shared library handling.  */
132   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
133   set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
134
135   set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
136 }
137
138 /* Provide a prototype to silence -Wmissing-prototypes.  */
139 extern initialize_file_ftype _initialize_tilegx_linux_tdep;
140
141 void
142 _initialize_tilegx_linux_tdep (void)
143 {
144   gdbarch_register_osabi (bfd_arch_tilegx, bfd_mach_tilegx, GDB_OSABI_LINUX,
145                           tilegx_linux_init_abi);
146 }