Refresh regs window in display_registers_from
[deliverable/binutils-gdb.git] / gdb / arc-linux-tdep.c
CommitLineData
8d7f0635
AK
1/* Target dependent code for GNU/Linux ARC.
2
3666a048 3 Copyright 2020-2021 Free Software Foundation, Inc.
8d7f0635
AK
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/* GDB header files. */
21#include "defs.h"
22#include "linux-tdep.h"
23#include "objfiles.h"
24#include "opcode/arc.h"
25#include "osabi.h"
26#include "solib-svr4.h"
27
28/* ARC header files. */
29#include "opcodes/arc-dis.h"
cc463201 30#include "arc-linux-tdep.h"
8d7f0635 31#include "arc-tdep.h"
cc463201
AK
32#include "arch/arc.h"
33
d8d1feb4
SM
34/* Print an "arc-linux" debug statement. */
35
36#define arc_linux_debug_printf(fmt, ...) \
37 debug_prefixed_printf_cond (arc_debug, "arc-linux", fmt, ##__VA_ARGS__)
38
cc463201
AK
39#define REGOFF(offset) (offset * ARC_REGISTER_SIZE)
40
d4af7272
AK
41/* arc_linux_sc_reg_offsets[i] is the offset of register i in the `struct
42 sigcontext'. Array index is an internal GDB register number, as defined in
43 arc-tdep.h:arc_regnum.
44
45 From <include/uapi/asm/sigcontext.h> and <include/uapi/asm/ptrace.h>.
46
47 The layout of this struct is tightly bound to "arc_regnum" enum
48 in arc-tdep.h. Any change of order in there, must be reflected
49 here as well. */
50static const int arc_linux_sc_reg_offsets[] = {
51 /* R0 - R12. */
52 REGOFF (22), REGOFF (21), REGOFF (20), REGOFF (19),
53 REGOFF (18), REGOFF (17), REGOFF (16), REGOFF (15),
54 REGOFF (14), REGOFF (13), REGOFF (12), REGOFF (11),
55 REGOFF (10),
56
57 /* R13 - R25. */
58 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
59 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
60 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
61 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
62 ARC_OFFSET_NO_REGISTER,
63
64 REGOFF (9), /* R26 (GP) */
65 REGOFF (8), /* FP */
66 REGOFF (23), /* SP */
67 ARC_OFFSET_NO_REGISTER, /* ILINK */
68 ARC_OFFSET_NO_REGISTER, /* R30 */
69 REGOFF (7), /* BLINK */
70
71 /* R32 - R59. */
72 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
73 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
74 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
75 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
76 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
77 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
78 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
79 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
80 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
81 ARC_OFFSET_NO_REGISTER,
82
83 REGOFF (4), /* LP_COUNT */
84 ARC_OFFSET_NO_REGISTER, /* RESERVED */
85 ARC_OFFSET_NO_REGISTER, /* LIMM */
86 ARC_OFFSET_NO_REGISTER, /* PCL */
87
88 REGOFF (6), /* PC */
89 REGOFF (5), /* STATUS32 */
90 REGOFF (2), /* LP_START */
91 REGOFF (3), /* LP_END */
92 REGOFF (1), /* BTA */
93};
94
cc463201
AK
95/* arc_linux_core_reg_offsets[i] is the offset in the .reg section of GDB
96 regnum i. Array index is an internal GDB register number, as defined in
97 arc-tdep.h:arc_regnum.
98
99 From include/uapi/asm/ptrace.h in the ARC Linux sources. */
100
101/* The layout of this struct is tightly bound to "arc_regnum" enum
102 in arc-tdep.h. Any change of order in there, must be reflected
103 here as well. */
104static const int arc_linux_core_reg_offsets[] = {
105 /* R0 - R12. */
106 REGOFF (22), REGOFF (21), REGOFF (20), REGOFF (19),
107 REGOFF (18), REGOFF (17), REGOFF (16), REGOFF (15),
108 REGOFF (14), REGOFF (13), REGOFF (12), REGOFF (11),
109 REGOFF (10),
110
111 /* R13 - R25. */
112 REGOFF (37), REGOFF (36), REGOFF (35), REGOFF (34),
113 REGOFF (33), REGOFF (32), REGOFF (31), REGOFF (30),
114 REGOFF (29), REGOFF (28), REGOFF (27), REGOFF (26),
115 REGOFF (25),
116
117 REGOFF (9), /* R26 (GP) */
118 REGOFF (8), /* FP */
119 REGOFF (23), /* SP */
120 ARC_OFFSET_NO_REGISTER, /* ILINK */
121 ARC_OFFSET_NO_REGISTER, /* R30 */
122 REGOFF (7), /* BLINK */
123
124 /* R32 - R59. */
125 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
126 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
127 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
128 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
129 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
130 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
131 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
132 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
133 ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER, ARC_OFFSET_NO_REGISTER,
134 ARC_OFFSET_NO_REGISTER,
135
136 REGOFF (4), /* LP_COUNT */
137 ARC_OFFSET_NO_REGISTER, /* RESERVED */
138 ARC_OFFSET_NO_REGISTER, /* LIMM */
139 ARC_OFFSET_NO_REGISTER, /* PCL */
140
141 REGOFF (39), /* PC */
142 REGOFF (5), /* STATUS32 */
143 REGOFF (2), /* LP_START */
144 REGOFF (3), /* LP_END */
145 REGOFF (1), /* BTA */
146 REGOFF (6) /* ERET */
147};
8d7f0635 148
d4af7272
AK
149/* Is THIS_FRAME a sigtramp function - the function that returns from
150 signal handler into normal execution flow? This is the case if the PC is
151 either at the start of, or in the middle of the two instructions:
152
153 mov r8, __NR_rt_sigreturn ; __NR_rt_sigreturn == 139
154 trap_s 0 ; `swi' for ARC700
155
156 On ARC uClibc Linux this function is called __default_rt_sa_restorer.
157
158 Returns TRUE if this is a sigtramp frame. */
159
160static bool
161arc_linux_is_sigtramp (struct frame_info *this_frame)
162{
163 struct gdbarch *gdbarch = get_frame_arch (this_frame);
164 CORE_ADDR pc = get_frame_pc (this_frame);
165
d8d1feb4 166 arc_linux_debug_printf ("pc=%s", paddress(gdbarch, pc));
d4af7272
AK
167
168 static const gdb_byte insns_be_hs[] = {
169 0x20, 0x8a, 0x12, 0xc2, /* mov r8,nr_rt_sigreturn */
170 0x78, 0x1e /* trap_s 0 */
171 };
172 static const gdb_byte insns_be_700[] = {
173 0x20, 0x8a, 0x12, 0xc2, /* mov r8,nr_rt_sigreturn */
174 0x22, 0x6f, 0x00, 0x3f /* swi */
175 };
176
177 gdb_byte arc_sigtramp_insns[sizeof (insns_be_700)];
178 size_t insns_sz;
179 if (arc_mach_is_arcv2 (gdbarch))
180 {
181 insns_sz = sizeof (insns_be_hs);
182 memcpy (arc_sigtramp_insns, insns_be_hs, insns_sz);
183 }
184 else
185 {
186 insns_sz = sizeof (insns_be_700);
187 memcpy (arc_sigtramp_insns, insns_be_700, insns_sz);
188 }
189 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
190 {
191 /* On little endian targets, ARC code section is in what is called
192 "middle endian", where half-words are in the big-endian order,
193 only bytes inside the halfwords are in the little endian order.
194 As a result it is very easy to convert big endian instruction to
195 little endian, since it is needed to swap bytes in the halfwords,
196 so there is no need to have information on whether that is a
197 4-byte instruction or 2-byte. */
198 gdb_assert ((insns_sz % 2) == 0);
199 for (int i = 0; i < insns_sz; i += 2)
200 std::swap (arc_sigtramp_insns[i], arc_sigtramp_insns[i+1]);
201 }
202
203 gdb_byte buf[insns_sz];
204
205 /* Read the memory at the PC. Since we are stopped, any breakpoint must
206 have been removed. */
bdec2917 207 if (!safe_frame_unwind_memory (this_frame, pc, {buf, insns_sz}))
d4af7272
AK
208 {
209 /* Failed to unwind frame. */
210 return FALSE;
211 }
212
213 /* Is that code the sigtramp instruction sequence? */
214 if (memcmp (buf, arc_sigtramp_insns, insns_sz) == 0)
215 return TRUE;
216
217 /* No - look one instruction earlier in the code... */
bdec2917 218 if (!safe_frame_unwind_memory (this_frame, pc - 4, {buf, insns_sz}))
d4af7272
AK
219 {
220 /* Failed to unwind frame. */
221 return FALSE;
222 }
223
224 return (memcmp (buf, arc_sigtramp_insns, insns_sz) == 0);
225}
226
227/* Get sigcontext structure of sigtramp frame - it contains saved
228 registers of interrupted frame.
229
230 Stack pointer points to the rt_sigframe structure, and sigcontext can
231 be found as in:
232
233 struct rt_sigframe {
234 struct siginfo info;
235 struct ucontext uc;
236 ...
237 };
238
239 struct ucontext {
240 unsigned long uc_flags;
241 struct ucontext *uc_link;
242 stack_t uc_stack;
243 struct sigcontext uc_mcontext;
244 sigset_t uc_sigmask;
245 };
246
247 sizeof (struct siginfo) == 0x80
248 offsetof (struct ucontext, uc_mcontext) == 0x14
249
250 GDB cannot include linux headers and use offsetof () because those are
251 target headers and GDB might be built for a different run host. There
252 doesn't seem to be an established mechanism to figure out those offsets
253 via gdbserver, so the only way is to hardcode values in the GDB,
254 meaning that GDB will be broken if values will change. That seems to
255 be a very unlikely scenario and other arches (aarch64, alpha, amd64,
256 etc) in GDB hardcode values. */
257
258static CORE_ADDR
259arc_linux_sigcontext_addr (struct frame_info *this_frame)
260{
261 const int ucontext_offset = 0x80;
262 const int sigcontext_offset = 0x14;
263 return get_frame_sp (this_frame) + ucontext_offset + sigcontext_offset;
264}
265
8d7f0635
AK
266/* Implement the "cannot_fetch_register" gdbarch method. */
267
268static int
269arc_linux_cannot_fetch_register (struct gdbarch *gdbarch, int regnum)
270{
271 /* Assume that register is readable if it is unknown. */
272 switch (regnum)
273 {
274 case ARC_ILINK_REGNUM:
275 case ARC_RESERVED_REGNUM:
276 case ARC_LIMM_REGNUM:
277 return true;
278 case ARC_R30_REGNUM:
279 case ARC_R58_REGNUM:
280 case ARC_R59_REGNUM:
281 return !arc_mach_is_arcv2 (gdbarch);
282 }
283 return (regnum > ARC_BLINK_REGNUM) && (regnum < ARC_LP_COUNT_REGNUM);
284}
285
286/* Implement the "cannot_store_register" gdbarch method. */
287
288static int
289arc_linux_cannot_store_register (struct gdbarch *gdbarch, int regnum)
290{
291 /* Assume that register is writable if it is unknown. */
292 switch (regnum)
293 {
294 case ARC_ILINK_REGNUM:
295 case ARC_RESERVED_REGNUM:
296 case ARC_LIMM_REGNUM:
297 case ARC_PCL_REGNUM:
298 return true;
299 case ARC_R30_REGNUM:
300 case ARC_R58_REGNUM:
301 case ARC_R59_REGNUM:
302 return !arc_mach_is_arcv2 (gdbarch);
303 }
304 return (regnum > ARC_BLINK_REGNUM) && (regnum < ARC_LP_COUNT_REGNUM);
305}
306
307/* For ARC Linux, breakpoints use the 16-bit TRAP_S 1 instruction, which
308 is 0x3e78 (little endian) or 0x783e (big endian). */
309
310static const gdb_byte arc_linux_trap_s_be[] = { 0x78, 0x3e };
311static const gdb_byte arc_linux_trap_s_le[] = { 0x3e, 0x78 };
312static const int trap_size = 2; /* Number of bytes to insert "trap". */
313
314/* Implement the "breakpoint_kind_from_pc" gdbarch method. */
315
316static int
317arc_linux_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
318{
319 return trap_size;
320}
321
322/* Implement the "sw_breakpoint_from_kind" gdbarch method. */
323
324static const gdb_byte *
325arc_linux_sw_breakpoint_from_kind (struct gdbarch *gdbarch,
326 int kind, int *size)
327{
6f2643db 328 gdb_assert (kind == trap_size);
8d7f0635
AK
329 *size = kind;
330 return ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
331 ? arc_linux_trap_s_be
332 : arc_linux_trap_s_le);
333}
334
335/* Implement the "software_single_step" gdbarch method. */
336
337static std::vector<CORE_ADDR>
338arc_linux_software_single_step (struct regcache *regcache)
339{
340 struct gdbarch *gdbarch = regcache->arch ();
341 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
342 struct disassemble_info di = arc_disassemble_info (gdbarch);
343
344 /* Read current instruction. */
345 struct arc_instruction curr_insn;
346 arc_insn_decode (regcache_read_pc (regcache), &di, arc_delayed_print_insn,
347 &curr_insn);
348 CORE_ADDR next_pc = arc_insn_get_linear_next_pc (curr_insn);
349
350 std::vector<CORE_ADDR> next_pcs;
351
352 /* For instructions with delay slots, the fall thru is not the
353 instruction immediately after the current instruction, but the one
354 after that. */
355 if (curr_insn.has_delay_slot)
356 {
357 struct arc_instruction next_insn;
358 arc_insn_decode (next_pc, &di, arc_delayed_print_insn, &next_insn);
359 next_pcs.push_back (arc_insn_get_linear_next_pc (next_insn));
360 }
361 else
362 next_pcs.push_back (next_pc);
363
364 ULONGEST status32;
365 regcache_cooked_read_unsigned (regcache, gdbarch_ps_regnum (gdbarch),
366 &status32);
367
368 if (curr_insn.is_control_flow)
369 {
370 CORE_ADDR branch_pc = arc_insn_get_branch_target (curr_insn);
371 if (branch_pc != next_pc)
372 next_pcs.push_back (branch_pc);
373 }
374 /* Is current instruction the last in a loop body? */
375 else if (tdep->has_hw_loops)
376 {
377 /* If STATUS32.L is 1, then ZD-loops are disabled. */
378 if ((status32 & ARC_STATUS32_L_MASK) == 0)
379 {
380 ULONGEST lp_end, lp_start, lp_count;
381 regcache_cooked_read_unsigned (regcache, ARC_LP_START_REGNUM,
382 &lp_start);
383 regcache_cooked_read_unsigned (regcache, ARC_LP_END_REGNUM, &lp_end);
384 regcache_cooked_read_unsigned (regcache, ARC_LP_COUNT_REGNUM,
385 &lp_count);
386
d8d1feb4
SM
387 arc_linux_debug_printf ("lp_start = %s, lp_end = %s, "
388 "lp_count = %s, next_pc = %s",
389 paddress (gdbarch, lp_start),
390 paddress (gdbarch, lp_end),
391 pulongest (lp_count),
392 paddress (gdbarch, next_pc));
8d7f0635
AK
393
394 if (next_pc == lp_end && lp_count > 1)
395 {
396 /* The instruction is in effect a jump back to the start of
397 the loop. */
398 next_pcs.push_back (lp_start);
399 }
400 }
401 }
402
403 /* Is this a delay slot? Then next PC is in BTA register. */
404 if ((status32 & ARC_STATUS32_DE_MASK) != 0)
405 {
406 ULONGEST bta;
407 regcache_cooked_read_unsigned (regcache, ARC_BTA_REGNUM, &bta);
408 next_pcs.push_back (bta);
409 }
410
411 return next_pcs;
412}
413
414/* Implement the "skip_solib_resolver" gdbarch method.
415
416 See glibc_skip_solib_resolver for details. */
417
418static CORE_ADDR
419arc_linux_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
420{
421 /* For uClibc 0.9.26+.
422
423 An unresolved PLT entry points to "__dl_linux_resolve", which calls
424 "_dl_linux_resolver" to do the resolving and then eventually jumps to
425 the function.
426
427 So we look for the symbol `_dl_linux_resolver', and if we are there,
428 gdb sets a breakpoint at the return address, and continues. */
429 struct bound_minimal_symbol resolver
430 = lookup_minimal_symbol ("_dl_linux_resolver", NULL, NULL);
431
432 if (arc_debug)
433 {
434 if (resolver.minsym != nullptr)
435 {
436 CORE_ADDR res_addr = BMSYMBOL_VALUE_ADDRESS (resolver);
d8d1feb4
SM
437 arc_linux_debug_printf ("pc = %s, resolver at %s",
438 print_core_address (gdbarch, pc),
439 print_core_address (gdbarch, res_addr));
8d7f0635
AK
440 }
441 else
d8d1feb4
SM
442 arc_linux_debug_printf ("pc = %s, no resolver found",
443 print_core_address (gdbarch, pc));
8d7f0635
AK
444 }
445
446 if (resolver.minsym != nullptr && BMSYMBOL_VALUE_ADDRESS (resolver) == pc)
447 {
448 /* Find the return address. */
449 return frame_unwind_caller_pc (get_current_frame ());
450 }
451 else
452 {
453 /* No breakpoint required. */
454 return 0;
455 }
456}
457
46023bbe
SV
458/* Populate REGCACHE with register REGNUM from BUF. */
459
460static void
461supply_register (struct regcache *regcache, int regnum, const gdb_byte *buf)
462{
463 /* Skip non-existing registers. */
464 if ((arc_linux_core_reg_offsets[regnum] == ARC_OFFSET_NO_REGISTER))
465 return;
466
467 regcache->raw_supply (regnum, buf + arc_linux_core_reg_offsets[regnum]);
468}
469
cc463201
AK
470void
471arc_linux_supply_gregset (const struct regset *regset,
472 struct regcache *regcache,
473 int regnum, const void *gregs, size_t size)
474{
475 gdb_static_assert (ARC_LAST_REGNUM
476 < ARRAY_SIZE (arc_linux_core_reg_offsets));
477
478 const bfd_byte *buf = (const bfd_byte *) gregs;
479
acf10cac 480 /* REGNUM == -1 means writing all the registers. */
46023bbe
SV
481 if (regnum == -1)
482 for (int reg = 0; reg <= ARC_LAST_REGNUM; reg++)
483 supply_register (regcache, reg, buf);
484 else if (regnum <= ARC_LAST_REGNUM)
485 supply_register (regcache, regnum, buf);
486 else
487 gdb_assert_not_reached ("Invalid regnum in arc_linux_supply_gregset.");
cc463201
AK
488}
489
490void
491arc_linux_supply_v2_regset (const struct regset *regset,
492 struct regcache *regcache, int regnum,
493 const void *v2_regs, size_t size)
494{
495 const bfd_byte *buf = (const bfd_byte *) v2_regs;
496
497 /* user_regs_arcv2 is defined in linux arch/arc/include/uapi/asm/ptrace.h. */
46023bbe
SV
498 if (regnum == -1 || regnum == ARC_R30_REGNUM)
499 regcache->raw_supply (ARC_R30_REGNUM, buf);
500 if (regnum == -1 || regnum == ARC_R58_REGNUM)
501 regcache->raw_supply (ARC_R58_REGNUM, buf + REGOFF (1));
502 if (regnum == -1 || regnum == ARC_R59_REGNUM)
503 regcache->raw_supply (ARC_R59_REGNUM, buf + REGOFF (2));
cc463201
AK
504}
505
506/* Populate BUF with register REGNUM from the REGCACHE. */
507
508static void
509collect_register (const struct regcache *regcache, struct gdbarch *gdbarch,
510 int regnum, gdb_byte *buf)
511{
10c19fad
SV
512 int offset;
513
cc463201 514 /* Skip non-existing registers. */
10c19fad 515 if (arc_linux_core_reg_offsets[regnum] == ARC_OFFSET_NO_REGISTER)
cc463201
AK
516 return;
517
518 /* The address where the execution has stopped is in pseudo-register
519 STOP_PC. However, when kernel code is returning from the exception,
520 it uses the value from ERET register. Since, TRAP_S (the breakpoint
521 instruction) commits, the ERET points to the next instruction. In
522 other words: ERET != STOP_PC. To jump back from the kernel code to
523 the correct address, ERET must be overwritten by GDB's STOP_PC. Else,
524 the program will continue at the address after the current instruction.
525 */
526 if (regnum == gdbarch_pc_regnum (gdbarch))
10c19fad
SV
527 offset = arc_linux_core_reg_offsets[ARC_ERET_REGNUM];
528 else
529 offset = arc_linux_core_reg_offsets[regnum];
530 regcache->raw_collect (regnum, buf + offset);
cc463201
AK
531}
532
533void
534arc_linux_collect_gregset (const struct regset *regset,
535 const struct regcache *regcache,
536 int regnum, void *gregs, size_t size)
537{
538 gdb_static_assert (ARC_LAST_REGNUM
539 < ARRAY_SIZE (arc_linux_core_reg_offsets));
540
541 gdb_byte *buf = (gdb_byte *) gregs;
542 struct gdbarch *gdbarch = regcache->arch ();
543
acf10cac 544 /* REGNUM == -1 means writing all the registers. */
cc463201
AK
545 if (regnum == -1)
546 for (int reg = 0; reg <= ARC_LAST_REGNUM; reg++)
547 collect_register (regcache, gdbarch, reg, buf);
548 else if (regnum <= ARC_LAST_REGNUM)
549 collect_register (regcache, gdbarch, regnum, buf);
550 else
551 gdb_assert_not_reached ("Invalid regnum in arc_linux_collect_gregset.");
552}
553
554void
555arc_linux_collect_v2_regset (const struct regset *regset,
556 const struct regcache *regcache, int regnum,
557 void *v2_regs, size_t size)
558{
559 bfd_byte *buf = (bfd_byte *) v2_regs;
560
46023bbe
SV
561 if (regnum == -1 || regnum == ARC_R30_REGNUM)
562 regcache->raw_collect (ARC_R30_REGNUM, buf);
563 if (regnum == -1 || regnum == ARC_R58_REGNUM)
564 regcache->raw_collect (ARC_R58_REGNUM, buf + REGOFF (1));
565 if (regnum == -1 || regnum == ARC_R59_REGNUM)
566 regcache->raw_collect (ARC_R59_REGNUM, buf + REGOFF (2));
cc463201
AK
567}
568
569/* Linux regset definitions. */
570
571static const struct regset arc_linux_gregset = {
572 arc_linux_core_reg_offsets,
573 arc_linux_supply_gregset,
574 arc_linux_collect_gregset,
575};
576
577static const struct regset arc_linux_v2_regset = {
578 NULL,
579 arc_linux_supply_v2_regset,
580 arc_linux_collect_v2_regset,
581};
582
583/* Implement the `iterate_over_regset_sections` gdbarch method. */
584
585static void
586arc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
587 iterate_over_regset_sections_cb *cb,
588 void *cb_data,
589 const struct regcache *regcache)
590{
591 /* There are 40 registers in Linux user_regs_struct, although some of
592 them are now just a mere paddings, kept to maintain binary
593 compatibility with older tools. */
594 const int sizeof_gregset = 40 * ARC_REGISTER_SIZE;
595
596 cb (".reg", sizeof_gregset, sizeof_gregset, &arc_linux_gregset, NULL,
597 cb_data);
598 cb (".reg-arc-v2", ARC_LINUX_SIZEOF_V2_REGSET, ARC_LINUX_SIZEOF_V2_REGSET,
599 &arc_linux_v2_regset, NULL, cb_data);
600}
601
602/* Implement the `core_read_description` gdbarch method. */
603
604static const struct target_desc *
605arc_linux_core_read_description (struct gdbarch *gdbarch,
606 struct target_ops *target,
607 bfd *abfd)
608{
609 arc_arch_features features
610 = arc_arch_features_create (abfd,
611 gdbarch_bfd_arch_info (gdbarch)->mach);
612 return arc_lookup_target_description (features);
613}
614
8d7f0635
AK
615/* Initialization specific to Linux environment. */
616
617static void
618arc_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
619{
620 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
621
d8d1feb4 622 arc_linux_debug_printf ("GNU/Linux OS/ABI initialization.");
8d7f0635 623
d4af7272
AK
624 /* Fill in target-dependent info in ARC-private structure. */
625 tdep->is_sigtramp = arc_linux_is_sigtramp;
626 tdep->sigcontext_addr = arc_linux_sigcontext_addr;
627 tdep->sc_reg_offset = arc_linux_sc_reg_offsets;
628 tdep->sc_num_regs = ARRAY_SIZE (arc_linux_sc_reg_offsets);
629
8d7f0635
AK
630 /* If we are using Linux, we have in uClibc
631 (libc/sysdeps/linux/arc/bits/setjmp.h):
632
633 typedef int __jmp_buf[13+1+1+1]; //r13-r25, fp, sp, blink
634
635 Where "blink" is a stored PC of a caller function.
636 */
637 tdep->jb_pc = 15;
638
480af54c 639 linux_init_abi (info, gdbarch, 0);
8d7f0635
AK
640
641 /* Set up target dependent GDB architecture entries. */
642 set_gdbarch_cannot_fetch_register (gdbarch, arc_linux_cannot_fetch_register);
643 set_gdbarch_cannot_store_register (gdbarch, arc_linux_cannot_store_register);
644 set_gdbarch_breakpoint_kind_from_pc (gdbarch,
645 arc_linux_breakpoint_kind_from_pc);
646 set_gdbarch_sw_breakpoint_from_kind (gdbarch,
647 arc_linux_sw_breakpoint_from_kind);
648 set_gdbarch_fetch_tls_load_module_address (gdbarch,
649 svr4_fetch_objfile_link_map);
650 set_gdbarch_software_single_step (gdbarch, arc_linux_software_single_step);
651 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
652 set_gdbarch_skip_solib_resolver (gdbarch, arc_linux_skip_solib_resolver);
cc463201
AK
653 set_gdbarch_iterate_over_regset_sections
654 (gdbarch, arc_linux_iterate_over_regset_sections);
655 set_gdbarch_core_read_description (gdbarch, arc_linux_core_read_description);
8d7f0635
AK
656
657 /* GNU/Linux uses SVR4-style shared libraries, with 32-bit ints, longs
658 and pointers (ILP32). */
659 set_solib_svr4_fetch_link_map_offsets (gdbarch,
660 svr4_ilp32_fetch_link_map_offsets);
661}
662
663/* Suppress warning from -Wmissing-prototypes. */
664extern initialize_file_ftype _initialize_arc_linux_tdep;
665
666void
667_initialize_arc_linux_tdep ()
668{
669 gdbarch_register_osabi (bfd_arch_arc, 0, GDB_OSABI_LINUX,
670 arc_linux_init_osabi);
671}
This page took 0.114049 seconds and 4 git commands to generate.