gdbserver/linux-low: turn some more static functions into private methods
[deliverable/binutils-gdb.git] / gdbserver / linux-nios2-low.cc
CommitLineData
68f5f838
SL
1/* GNU/Linux/Nios II specific low level interface, for the remote server for
2 GDB.
b811d2c2 3 Copyright (C) 2008-2020 Free Software Foundation, Inc.
68f5f838
SL
4
5 Contributed by Mentor Graphics, Inc.
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 "server.h"
23#include "linux-low.h"
21e94bd9 24#include "elf/common.h"
5826e159 25#include "nat/gdb_ptrace.h"
68f5f838
SL
26#include <endian.h>
27#include "gdb_proc_service.h"
28#include <asm/ptrace.h>
29
30#ifndef PTRACE_GET_THREAD_AREA
31#define PTRACE_GET_THREAD_AREA 25
32#endif
33
ef0478f6
TBA
34/* Linux target op definitions for the NIOS II architecture. */
35
36class nios2_target : public linux_process_target
37{
38public:
39
aa8d21c9
TBA
40 const regs_info *get_regs_info () override;
41
797bcff5
TBA
42protected:
43
44 void low_arch_setup () override;
daca57a7
TBA
45
46 bool low_cannot_fetch_register (int regno) override;
47
48 bool low_cannot_store_register (int regno) override;
ef0478f6
TBA
49};
50
51/* The singleton target ops object. */
52
53static nios2_target the_nios2_target;
54
68f5f838
SL
55/* The following definition must agree with the number of registers
56 defined in "struct user_regs" in GLIBC
21e94bd9 57 (sysdeps/unix/sysv/linux/nios2/sys/user.h), and also with
68f5f838
SL
58 NIOS2_NUM_REGS in GDB proper. */
59
60#define nios2_num_regs 49
61
62/* Defined in auto-generated file nios2-linux.c. */
63
64void init_registers_nios2_linux (void);
3aee8918 65extern const struct target_desc *tdesc_nios2_linux;
68f5f838
SL
66
67/* This union is used to convert between int and byte buffer
68 representations of register contents. */
69
70union nios2_register
71{
72 unsigned char buf[4];
73 int reg32;
74};
75
76/* Return the ptrace ``address'' of register REGNO. */
77
78static int nios2_regmap[] = {
79 -1, 1, 2, 3, 4, 5, 6, 7,
80 8, 9, 10, 11, 12, 13, 14, 15,
81 16, 17, 18, 19, 20, 21, 22, 23,
82 24, 25, 26, 27, 28, 29, 30, 31,
83 32, 33, 34, 35, 36, 37, 38, 39,
84 40, 41, 42, 43, 44, 45, 46, 47,
85 48,
86 0
87};
88
797bcff5 89/* Implement the low_arch_setup linux target ops method. */
68f5f838 90
797bcff5
TBA
91void
92nios2_target::low_arch_setup ()
68f5f838 93{
3aee8918 94 current_process ()->tdesc = tdesc_nios2_linux;
68f5f838
SL
95}
96
daca57a7 97/* Implement the low_cannot_fetch_register linux target ops method. */
68f5f838 98
daca57a7
TBA
99bool
100nios2_target::low_cannot_fetch_register (int regno)
68f5f838 101{
daca57a7 102 return (nios2_regmap[regno] == -1);
68f5f838
SL
103}
104
daca57a7 105/* Implement the low_cannot_store_register linux target ops method. */
68f5f838 106
daca57a7
TBA
107bool
108nios2_target::low_cannot_store_register (int regno)
68f5f838 109{
daca57a7 110 return (nios2_regmap[regno] == -1);
68f5f838
SL
111}
112
af60a1ef
SL
113/* Breakpoint support. Also see comments on nios2_breakpoint_from_pc
114 in nios2-tdep.c. */
115
116#if defined(__nios2_arch__) && __nios2_arch__ == 2
117#define NIOS2_BREAKPOINT 0xb7fd0020
118#define CDX_BREAKPOINT 0xd7c9
119#else
120#define NIOS2_BREAKPOINT 0x003b6ffa
121#endif
68f5f838 122
dd373349
AT
123/* We only register the 4-byte breakpoint, even on R2 targets which also
124 support 2-byte breakpoints. Since there is no supports_z_point_type
125 function provided, gdbserver never inserts software breakpoints itself
126 and instead relies on GDB to insert the breakpoint of the correct length
127 via a memory write. */
af60a1ef 128static const unsigned int nios2_breakpoint = NIOS2_BREAKPOINT;
68f5f838
SL
129#define nios2_breakpoint_len 4
130
dd373349
AT
131/* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */
132
133static const gdb_byte *
134nios2_sw_breakpoint_from_kind (int kind, int *size)
135{
136 *size = nios2_breakpoint_len;
137 return (const gdb_byte *) &nios2_breakpoint;
138}
139
68f5f838
SL
140/* Implement the breakpoint_at linux_target_ops method. */
141
142static int
143nios2_breakpoint_at (CORE_ADDR where)
144{
145 unsigned int insn;
146
af60a1ef
SL
147 /* For R2, first check for the 2-byte CDX trap.n breakpoint encoding. */
148#if defined(__nios2_arch__) && __nios2_arch__ == 2
52405d85 149 the_target->read_memory (where, (unsigned char *) &insn, 2);
af60a1ef
SL
150 if (insn == CDX_BREAKPOINT)
151 return 1;
152#endif
153
52405d85 154 the_target->read_memory (where, (unsigned char *) &insn, 4);
68f5f838
SL
155 if (insn == nios2_breakpoint)
156 return 1;
157 return 0;
158}
159
160/* Fetch the thread-local storage pointer for libthread_db. */
161
162ps_err_e
754653a7 163ps_get_thread_area (struct ps_prochandle *ph,
68f5f838
SL
164 lwpid_t lwpid, int idx, void **base)
165{
166 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
167 return PS_ERR;
168
169 /* IDX is the bias from the thread pointer to the beginning of the
170 thread descriptor. It has to be subtracted due to implementation
171 quirks in libthread_db. */
172 *base = (void *) ((char *) *base - idx);
173
174 return PS_OK;
175}
176
68f5f838
SL
177/* Helper functions to collect/supply a single register REGNO. */
178
179static void
180nios2_collect_register (struct regcache *regcache, int regno,
181 union nios2_register *reg)
182{
183 union nios2_register tmp_reg;
184
185 collect_register (regcache, regno, &tmp_reg.reg32);
186 reg->reg32 = tmp_reg.reg32;
187}
188
189static void
190nios2_supply_register (struct regcache *regcache, int regno,
191 const union nios2_register *reg)
192{
193 supply_register (regcache, regno, reg->buf);
194}
195
196/* We have only a single register set on Nios II. */
197
198static void
199nios2_fill_gregset (struct regcache *regcache, void *buf)
200{
b1c51e36 201 union nios2_register *regset = (union nios2_register *) buf;
68f5f838
SL
202 int i;
203
204 for (i = 1; i < nios2_num_regs; i++)
205 nios2_collect_register (regcache, i, regset + i);
206}
207
208static void
209nios2_store_gregset (struct regcache *regcache, const void *buf)
210{
b1c51e36 211 const union nios2_register *regset = (union nios2_register *) buf;
68f5f838
SL
212 int i;
213
214 for (i = 0; i < nios2_num_regs; i++)
215 nios2_supply_register (regcache, i, regset + i);
216}
68f5f838 217
3aee8918 218static struct regset_info nios2_regsets[] =
68f5f838 219{
21e94bd9
SL
220 { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_PRSTATUS,
221 nios2_num_regs * 4, GENERAL_REGS,
68f5f838 222 nios2_fill_gregset, nios2_store_gregset },
50bc912a 223 NULL_REGSET
68f5f838
SL
224};
225
3aee8918
PA
226static struct regsets_info nios2_regsets_info =
227 {
228 nios2_regsets, /* regsets */
229 0, /* num_regsets */
230 NULL, /* disabled_regsets */
231 };
232
233static struct usrregs_info nios2_usrregs_info =
234 {
235 nios2_num_regs,
236 nios2_regmap,
237 };
238
aa8d21c9 239static struct regs_info myregs_info =
3aee8918
PA
240 {
241 NULL, /* regset_bitmap */
242 &nios2_usrregs_info,
243 &nios2_regsets_info
244 };
245
aa8d21c9
TBA
246const regs_info *
247nios2_target::get_regs_info ()
3aee8918 248{
aa8d21c9 249 return &myregs_info;
3aee8918
PA
250}
251
68f5f838
SL
252struct linux_target_ops the_low_target =
253{
276d4552
YQ
254 linux_get_pc_32bit,
255 linux_set_pc_32bit,
dd373349
AT
256 NULL, /* breakpoint_kind_from_pc */
257 nios2_sw_breakpoint_from_kind,
fa5308bd 258 NULL, /* get_next_pcs */
68f5f838
SL
259 0,
260 nios2_breakpoint_at,
261};
3aee8918 262
ef0478f6
TBA
263/* The linux target ops object. */
264
265linux_process_target *the_linux_target = &the_nios2_target;
266
3aee8918
PA
267void
268initialize_low_arch (void)
269{
270 init_registers_nios2_linux ();
271
272 initialize_regsets_info (&nios2_regsets_info);
273}
This page took 0.594759 seconds and 4 git commands to generate.