1 /* GNU/Linux/Xtensa specific low level interface, for the remote server for GDB.
2 Copyright (C) 2007-2020 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "linux-low.h"
23 /* Linux target op definitions for the Xtensa architecture. */
25 class xtensa_target
: public linux_process_target
29 const regs_info
*get_regs_info () override
;
31 const gdb_byte
*sw_breakpoint_from_kind (int kind
, int *size
) override
;
35 void low_arch_setup () override
;
37 bool low_cannot_fetch_register (int regno
) override
;
39 bool low_cannot_store_register (int regno
) override
;
41 bool low_supports_breakpoints () override
;
43 CORE_ADDR
low_get_pc (regcache
*regcache
) override
;
45 void low_set_pc (regcache
*regcache
, CORE_ADDR newpc
) override
;
48 /* The singleton target ops object. */
50 static xtensa_target the_xtensa_target
;
53 xtensa_target::low_cannot_fetch_register (int regno
)
55 gdb_assert_not_reached ("linux target op low_cannot_fetch_register "
56 "is not implemented by the target");
60 xtensa_target::low_cannot_store_register (int regno
)
62 gdb_assert_not_reached ("linux target op low_cannot_store_register "
63 "is not implemented by the target");
67 xtensa_target::low_supports_breakpoints ()
73 xtensa_target::low_get_pc (regcache
*regcache
)
75 return linux_get_pc_32bit (regcache
);
79 xtensa_target::low_set_pc (regcache
*regcache
, CORE_ADDR pc
)
81 linux_set_pc_32bit (regcache
, pc
);
84 /* Defined in auto-generated file reg-xtensa.c. */
85 void init_registers_xtensa (void);
86 extern const struct target_desc
*tdesc_xtensa
;
88 #include <asm/ptrace.h>
89 #include <xtensa-config.h>
90 #include "arch/xtensa.h"
91 #include "gdb_proc_service.h"
93 #include "xtensa-xtregs.c"
97 R_LBEG
, R_LEND
, R_LCOUNT
,
105 xtensa_fill_gregset (struct regcache
*regcache
, void *buf
)
107 elf_greg_t
* rset
= (elf_greg_t
*)buf
;
108 const struct target_desc
*tdesc
= regcache
->tdesc
;
113 /* Take care of AR registers. */
115 ar0_regnum
= find_regno (tdesc
, "ar0");
116 ptr
= (char*)&rset
[R_A0
];
118 for (i
= ar0_regnum
; i
< ar0_regnum
+ XCHAL_NUM_AREGS
; i
++)
120 collect_register (regcache
, i
, ptr
);
121 ptr
+= register_size (tdesc
, i
);
124 if (XSHAL_ABI
== XTHAL_ABI_CALL0
)
126 int a0_regnum
= find_regno (tdesc
, "a0");
127 ptr
= (char *) &rset
[R_A0
+ 4 * rset
[R_WB
]];
129 for (i
= a0_regnum
; i
< a0_regnum
+ C0_NREGS
; i
++)
131 if ((4 * rset
[R_WB
] + i
- a0_regnum
) == XCHAL_NUM_AREGS
)
132 ptr
= (char *) &rset
[R_A0
];
133 collect_register (regcache
, i
, ptr
);
134 ptr
+= register_size (tdesc
, i
);
138 /* Loop registers, if hardware has it. */
141 collect_register_by_name (regcache
, "lbeg", (char*)&rset
[R_LBEG
]);
142 collect_register_by_name (regcache
, "lend", (char*)&rset
[R_LEND
]);
143 collect_register_by_name (regcache
, "lcount", (char*)&rset
[R_LCOUNT
]);
146 collect_register_by_name (regcache
, "sar", (char*)&rset
[R_SAR
]);
147 collect_register_by_name (regcache
, "pc", (char*)&rset
[R_PC
]);
148 collect_register_by_name (regcache
, "ps", (char*)&rset
[R_PS
]);
149 collect_register_by_name (regcache
, "windowbase", (char*)&rset
[R_WB
]);
150 collect_register_by_name (regcache
, "windowstart", (char*)&rset
[R_WS
]);
152 #if XCHAL_HAVE_THREADPTR
153 collect_register_by_name (regcache
, "threadptr",
154 (char *) &rset
[R_THREADPTR
]);
159 xtensa_store_gregset (struct regcache
*regcache
, const void *buf
)
161 const elf_greg_t
* rset
= (const elf_greg_t
*)buf
;
162 const struct target_desc
*tdesc
= regcache
->tdesc
;
167 /* Take care of AR registers. */
169 ar0_regnum
= find_regno (tdesc
, "ar0");
170 ptr
= (char *)&rset
[R_A0
];
172 for (i
= ar0_regnum
; i
< ar0_regnum
+ XCHAL_NUM_AREGS
; i
++)
174 supply_register (regcache
, i
, ptr
);
175 ptr
+= register_size (tdesc
, i
);
178 if (XSHAL_ABI
== XTHAL_ABI_CALL0
)
180 int a0_regnum
= find_regno (tdesc
, "a0");
181 ptr
= (char *) &rset
[R_A0
+ (4 * rset
[R_WB
]) % XCHAL_NUM_AREGS
];
183 for (i
= a0_regnum
; i
< a0_regnum
+ C0_NREGS
; i
++)
185 if ((4 * rset
[R_WB
] + i
- a0_regnum
) == XCHAL_NUM_AREGS
)
186 ptr
= (char *) &rset
[R_A0
];
187 supply_register (regcache
, i
, ptr
);
188 ptr
+= register_size (tdesc
, i
);
192 /* Loop registers, if hardware has it. */
195 supply_register_by_name (regcache
, "lbeg", (char*)&rset
[R_LBEG
]);
196 supply_register_by_name (regcache
, "lend", (char*)&rset
[R_LEND
]);
197 supply_register_by_name (regcache
, "lcount", (char*)&rset
[R_LCOUNT
]);
200 supply_register_by_name (regcache
, "sar", (char*)&rset
[R_SAR
]);
201 supply_register_by_name (regcache
, "pc", (char*)&rset
[R_PC
]);
202 supply_register_by_name (regcache
, "ps", (char*)&rset
[R_PS
]);
203 supply_register_by_name (regcache
, "windowbase", (char*)&rset
[R_WB
]);
204 supply_register_by_name (regcache
, "windowstart", (char*)&rset
[R_WS
]);
206 #if XCHAL_HAVE_THREADPTR
207 supply_register_by_name (regcache
, "threadptr",
208 (char *) &rset
[R_THREADPTR
]);
212 /* Xtensa GNU/Linux PTRACE interface includes extended register set. */
215 xtensa_fill_xtregset (struct regcache
*regcache
, void *buf
)
217 const xtensa_regtable_t
*ptr
;
219 for (ptr
= xtensa_regmap_table
; ptr
->name
; ptr
++)
221 collect_register_by_name (regcache
, ptr
->name
,
222 (char*)buf
+ ptr
->ptrace_offset
);
227 xtensa_store_xtregset (struct regcache
*regcache
, const void *buf
)
229 const xtensa_regtable_t
*ptr
;
231 for (ptr
= xtensa_regmap_table
; ptr
->name
; ptr
++)
233 supply_register_by_name (regcache
, ptr
->name
,
234 (char*)buf
+ ptr
->ptrace_offset
);
238 static struct regset_info xtensa_regsets
[] = {
239 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, sizeof (elf_gregset_t
),
241 xtensa_fill_gregset
, xtensa_store_gregset
},
242 { PTRACE_GETXTREGS
, PTRACE_SETXTREGS
, 0, XTENSA_ELF_XTREG_SIZE
,
244 xtensa_fill_xtregset
, xtensa_store_xtregset
},
249 #define XTENSA_BREAKPOINT {0xd2,0x0f}
251 #define XTENSA_BREAKPOINT {0x2d,0xf0}
254 static const gdb_byte xtensa_breakpoint
[] = XTENSA_BREAKPOINT
;
255 #define xtensa_breakpoint_len 2
257 /* Implementation of target ops method "sw_breakpoint_from_kind". */
260 xtensa_target::sw_breakpoint_from_kind (int kind
, int *size
)
262 *size
= xtensa_breakpoint_len
;
263 return xtensa_breakpoint
;
267 xtensa_breakpoint_at (CORE_ADDR where
)
271 the_target
->read_memory (where
, (unsigned char *) &insn
,
272 xtensa_breakpoint_len
);
273 return memcmp((char *) &insn
,
274 xtensa_breakpoint
, xtensa_breakpoint_len
) == 0;
277 /* Called by libthread_db. */
280 ps_get_thread_area (struct ps_prochandle
*ph
,
281 lwpid_t lwpid
, int idx
, void **base
)
283 xtensa_elf_gregset_t regs
;
285 if (ptrace (PTRACE_GETREGS
, lwpid
, NULL
, ®s
) != 0)
288 /* IDX is the bias from the thread pointer to the beginning of the
289 thread descriptor. It has to be subtracted due to implementation
290 quirks in libthread_db. */
291 *base
= (void *) ((char *) regs
.threadptr
- idx
);
296 static struct regsets_info xtensa_regsets_info
=
298 xtensa_regsets
, /* regsets */
300 NULL
, /* disabled_regsets */
303 static struct regs_info myregs_info
=
305 NULL
, /* regset_bitmap */
311 xtensa_target::low_arch_setup ()
313 current_process ()->tdesc
= tdesc_xtensa
;
316 /* Support for hardware single step. */
319 xtensa_supports_hardware_single_step (void)
325 xtensa_target::get_regs_info ()
330 struct linux_target_ops the_low_target
= {
331 xtensa_breakpoint_at
,
332 NULL
, /* supports_z_point_type */
333 NULL
, /* insert_point */
334 NULL
, /* remove_point */
335 NULL
, /* stopped_by_watchpoint */
336 NULL
, /* stopped_data_address */
337 NULL
, /* collect_ptrace_register */
338 NULL
, /* supply_ptrace_register */
339 NULL
, /* siginfo_fixup */
340 NULL
, /* new_process */
341 NULL
, /* delete_process */
342 NULL
, /* new_thread */
343 NULL
, /* delete_thread */
345 NULL
, /* prepare_to_resume */
346 NULL
, /* process_qsupported */
347 NULL
, /* supports_tracepoints */
348 NULL
, /* get_thread_area */
349 NULL
, /* install_fast_tracepoint_jump_pad */
351 NULL
, /* get_min_fast_tracepoint_insn_len */
352 NULL
, /* supports_range_stepping */
353 xtensa_supports_hardware_single_step
,
356 /* The linux target ops object. */
358 linux_process_target
*the_linux_target
= &the_xtensa_target
;
361 initialize_low_arch (void)
363 /* Initialize the Linux target descriptions. */
364 init_registers_xtensa ();
366 initialize_regsets_info (&xtensa_regsets_info
);