x86: Move x86-specific linker options to elf_linker_x86_params
[deliverable/binutils-gdb.git] / gdb / csky-linux-tdep.c
CommitLineData
9d24df82
HAQ
1/* Target-dependent code for GNU/Linux on CSKY.
2
42a4f53d 3 Copyright (C) 2012-2019 Free Software Foundation, Inc.
9d24df82
HAQ
4
5 Contributed by C-SKY Microsystems and Mentor Graphics.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22#include "defs.h"
d55e5aa6
TT
23
24/* Local non-gdb includes. */
25#include "csky-tdep.h"
26#include "gdbarch.h"
9d24df82
HAQ
27#include "glibc-tdep.h"
28#include "linux-tdep.h"
d55e5aa6 29#include "osabi.h"
9d24df82 30#include "regset.h"
d55e5aa6 31#include "solib-svr4.h"
9d24df82
HAQ
32#include "trad-frame.h"
33#include "tramp-frame.h"
9d24df82
HAQ
34
35/* Functions, definitions, and data structures for C-Sky core file debug. */
36
37/* General regset pc, r1, r0, psr, r2-r31 for CK810. */
38#define SIZEOF_CSKY_GREGSET 34*4
39/* Float regset fesr fsr fr0-fr31 for CK810. */
40#define SIZEOF_CSKY_FREGSET 34*4
41
42/* Offset mapping table from core_section to regcache of general
43 registers for ck810. */
44static const int csky_gregset_offset[] =
45{
46 72, 1, 0, 89, 2, /* pc, r1, r0, psr, r2. */
47 3, 4, 5, 6, 7, /* r3 ~ r32. */
48 8, 9, 10, 11, 12,
49 13, 14, 15, 16, 17,
50 18, 19, 20, 21, 22,
51 23, 24, 25, 26, 27,
52 28, 29, 30, 31
53};
54
55/* Offset mapping table from core_section to regcache of float
56 registers for ck810. */
57
58static const int csky_fregset_offset[] =
59{
60 122, 123, 40, 41, 42, /* fcr, fesr, fr0 ~ fr2. */
61 43, 44, 45, 46, 47, /* fr3 ~ fr15. */
62 48, 49, 50, 51, 52,
63 53, 54, 55
64};
65
66/* Implement the supply_regset hook for GP registers in core files. */
67
68static void
69csky_supply_gregset (const struct regset *regset,
70 struct regcache *regcache, int regnum,
71 const void *regs, size_t len)
72{
73 int i, gregset_num;
74 const gdb_byte *gregs = (const gdb_byte *) regs ;
75
76 gdb_assert (len >= SIZEOF_CSKY_GREGSET);
77 gregset_num = ARRAY_SIZE (csky_gregset_offset);
78
79 for (i = 0; i < gregset_num; i++)
80 {
81 if ((regnum == csky_gregset_offset[i] || regnum == -1)
82 && csky_gregset_offset[i] != -1)
83 regcache->raw_supply (csky_gregset_offset[i], gregs + 4 * i);
84 }
85}
86
87/* Implement the collect_regset hook for GP registers in core files. */
88
89static void
90csky_collect_gregset (const struct regset *regset,
91 const struct regcache *regcache,
92 int regnum, void *gregs_buf, size_t len)
93{
94 int regno, gregset_num;
95 gdb_byte *gregs = (gdb_byte *) gregs_buf ;
96
97 gdb_assert (len >= SIZEOF_CSKY_GREGSET);
98 gregset_num = ARRAY_SIZE (csky_gregset_offset);
99
100 for (regno = 0; regno < gregset_num; regno++)
101 {
102 if ((regnum == csky_gregset_offset[regno] || regnum == -1)
103 && csky_gregset_offset[regno] != -1)
104 regcache->raw_collect (regno,
105 gregs + 4 + csky_gregset_offset[regno]);
106 }
107}
108
109/* Implement the supply_regset hook for FP registers in core files. */
110
111void
112csky_supply_fregset (const struct regset *regset,
113 struct regcache *regcache, int regnum,
114 const void *regs, size_t len)
115{
116 int i;
117 int offset = 0;
118 struct gdbarch *gdbarch = regcache->arch ();
119 const gdb_byte *fregs = (const gdb_byte *) regs;
120 int fregset_num = ARRAY_SIZE (csky_fregset_offset);
121
122 gdb_assert (len >= SIZEOF_CSKY_FREGSET);
123 for (i = 0; i < fregset_num; i++)
124 {
125 if ((regnum == csky_fregset_offset[i] || regnum == -1)
126 && csky_fregset_offset[i] != -1)
127 {
128 int num = csky_fregset_offset[i];
129 offset += register_size (gdbarch, num);
130 regcache->raw_supply (csky_fregset_offset[i], fregs + offset);
131 }
132 }
133}
134
135/* Implement the collect_regset hook for FP registers in core files. */
136
137static void
138csky_collect_fregset (const struct regset *regset,
139 const struct regcache *regcache,
140 int regnum, void *fregs_buf, size_t len)
141{
142 int regno;
143 struct gdbarch *gdbarch = regcache->arch ();
144 gdb_byte *fregs = (gdb_byte *) fregs_buf ;
145 int fregset_num = ARRAY_SIZE (csky_fregset_offset);
146 int offset = 0;
147
148 gdb_assert (len >= SIZEOF_CSKY_FREGSET);
149 for (regno = 0; regno < fregset_num; regno++)
150 {
151 if ((regnum == csky_fregset_offset[regno] || regnum == -1)
152 && csky_fregset_offset[regno] != -1)
153 {
154 offset += register_size (gdbarch, csky_fregset_offset[regno]);
155 regcache->raw_collect (regno, fregs + offset);
156 }
157 }
158}
159
160static const struct regset csky_regset_general =
161{
162 NULL,
163 csky_supply_gregset,
164 csky_collect_gregset
165};
166
167static const struct regset csky_regset_float =
168{
169 NULL,
170 csky_supply_fregset,
171 csky_collect_fregset
172};
173
174/* Iterate over core file register note sections. */
175
176static void
177csky_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
178 iterate_over_regset_sections_cb *cb,
179 void *cb_data,
180 const struct regcache *regcache)
181{
182 cb (".reg", sizeof (csky_gregset_offset), sizeof (csky_gregset_offset),
183 &csky_regset_general, NULL, cb_data);
184 cb (".reg2", sizeof (csky_fregset_offset), sizeof (csky_fregset_offset),
185 &csky_regset_float, NULL, cb_data);
186}
187
188static void
189csky_linux_rt_sigreturn_init (const struct tramp_frame *self,
190 struct frame_info *this_frame,
191 struct trad_frame_cache *this_cache,
192 CORE_ADDR func)
193{
194 int i;
195 CORE_ADDR sp = get_frame_register_unsigned (this_frame, 14);
196
197 CORE_ADDR base = sp + CSKY_SIGINFO_OFFSET + CSKY_SIGINFO_SIZE
198 + CSKY_UCONTEXT_SIGCONTEXT
199 + CSKY_SIGCONTEXT_SC_USP
200 + CSKY_SIGCONTEXT_SC_A0;
201
202 /* Set addrs of R0 ~ R13. */
203 for (i = 0; i < 14; i++)
204 trad_frame_set_reg_addr (this_cache, i, base + i * 4);
205
206 /* Set addrs of SP(R14) and R15. */
207 trad_frame_set_reg_addr (this_cache, 14, base - 4);
208 trad_frame_set_reg_addr (this_cache, 15, base + 4 * 14);
209
210 /* Set addrs of R16 ~ R31. */
211 for (i = 15; i < 31; i++)
212 trad_frame_set_reg_addr (this_cache, i, base + i * 4);
213
214 /* Set addrs of PSR and PC. */
215 trad_frame_set_reg_addr (this_cache, 89, base + 4 * 33);
216 trad_frame_set_reg_addr (this_cache, 72, base + 4 * 34);
217
218 trad_frame_set_id (this_cache, frame_id_build (sp, func));
219}
220
221static struct tramp_frame
222csky_linux_rt_sigreturn_tramp_frame = {
223 SIGTRAMP_FRAME,
224 4,
225 {
226 { CSKY_MOVI_R7_173, ULONGEST_MAX },
227 { CSKY_TRAP_0, ULONGEST_MAX },
228 { TRAMP_SENTINEL_INSN }
229 },
230 csky_linux_rt_sigreturn_init
231};
232
233/* Hook function for gdbarch_register_osabi. */
234
235static void
236csky_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
237{
238 linux_init_abi (info, gdbarch);
239
240 /* Shared library handling. */
241 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
242 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
243 set_solib_svr4_fetch_link_map_offsets (gdbarch,
244 svr4_ilp32_fetch_link_map_offsets);
245
246 /* Enable TLS support. */
247 set_gdbarch_fetch_tls_load_module_address (gdbarch,
248 svr4_fetch_objfile_link_map);
249
250 /* Core file support. */
251 set_gdbarch_iterate_over_regset_sections (
252 gdbarch, csky_linux_iterate_over_regset_sections);
253
254 /* Append tramp frame unwinder for SIGNAL. */
255
256 tramp_frame_prepend_unwinder (gdbarch,
257 &csky_linux_rt_sigreturn_tramp_frame);
258}
259
260void
261_initialize_csky_linux_tdep (void)
262{
263 gdbarch_register_osabi (bfd_arch_csky, 0, GDB_OSABI_LINUX,
264 csky_linux_init_abi);
265}
This page took 0.072993 seconds and 4 git commands to generate.