1 /* GNU/Linux/Nios II specific low level interface, for the remote server for
3 Copyright (C) 2008-2015 Free Software Foundation, Inc.
5 Contributed by Mentor Graphics, Inc.
7 This file is part of GDB.
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.
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.
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/>. */
23 #include "linux-low.h"
24 #include "elf/common.h"
25 #include <sys/ptrace.h>
27 #include "gdb_proc_service.h"
28 #include <asm/ptrace.h>
30 #ifndef PTRACE_GET_THREAD_AREA
31 #define PTRACE_GET_THREAD_AREA 25
34 /* The following definition must agree with the number of registers
35 defined in "struct user_regs" in GLIBC
36 (sysdeps/unix/sysv/linux/nios2/sys/user.h), and also with
37 NIOS2_NUM_REGS in GDB proper. */
39 #define nios2_num_regs 49
41 /* Defined in auto-generated file nios2-linux.c. */
43 void init_registers_nios2_linux (void);
44 extern const struct target_desc
*tdesc_nios2_linux
;
46 /* This union is used to convert between int and byte buffer
47 representations of register contents. */
55 /* Return the ptrace ``address'' of register REGNO. */
57 static int nios2_regmap
[] = {
58 -1, 1, 2, 3, 4, 5, 6, 7,
59 8, 9, 10, 11, 12, 13, 14, 15,
60 16, 17, 18, 19, 20, 21, 22, 23,
61 24, 25, 26, 27, 28, 29, 30, 31,
62 32, 33, 34, 35, 36, 37, 38, 39,
63 40, 41, 42, 43, 44, 45, 46, 47,
68 /* Implement the arch_setup linux_target_ops method. */
71 nios2_arch_setup (void)
73 current_process ()->tdesc
= tdesc_nios2_linux
;
76 /* Implement the cannot_fetch_register linux_target_ops method. */
79 nios2_cannot_fetch_register (int regno
)
81 if (nios2_regmap
[regno
] == -1)
87 /* Implement the cannot_store_register linux_target_ops method. */
90 nios2_cannot_store_register (int regno
)
92 if (nios2_regmap
[regno
] == -1)
98 /* Implement the get_pc linux_target_ops method. */
101 nios2_get_pc (struct regcache
*regcache
)
103 union nios2_register pc
;
105 collect_register_by_name (regcache
, "pc", pc
.buf
);
109 /* Implement the set_pc linux_target_ops method. */
112 nios2_set_pc (struct regcache
*regcache
, CORE_ADDR pc
)
114 union nios2_register newpc
;
117 supply_register_by_name (regcache
, "pc", newpc
.buf
);
120 /* Breakpoint support. */
122 static const unsigned int nios2_breakpoint
= 0x003b6ffa;
123 #define nios2_breakpoint_len 4
125 /* Implement the breakpoint_reinsert_addr linux_target_ops method. */
128 nios2_reinsert_addr (void)
130 union nios2_register ra
;
131 struct regcache
*regcache
= get_thread_regcache (current_thread
, 1);
133 collect_register_by_name (regcache
, "ra", ra
.buf
);
137 /* Implement the breakpoint_at linux_target_ops method. */
140 nios2_breakpoint_at (CORE_ADDR where
)
144 (*the_target
->read_memory
) (where
, (unsigned char *) &insn
, 4);
145 if (insn
== nios2_breakpoint
)
150 /* Fetch the thread-local storage pointer for libthread_db. */
153 ps_get_thread_area (const struct ps_prochandle
*ph
,
154 lwpid_t lwpid
, int idx
, void **base
)
156 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
159 /* IDX is the bias from the thread pointer to the beginning of the
160 thread descriptor. It has to be subtracted due to implementation
161 quirks in libthread_db. */
162 *base
= (void *) ((char *) *base
- idx
);
167 /* Helper functions to collect/supply a single register REGNO. */
170 nios2_collect_register (struct regcache
*regcache
, int regno
,
171 union nios2_register
*reg
)
173 union nios2_register tmp_reg
;
175 collect_register (regcache
, regno
, &tmp_reg
.reg32
);
176 reg
->reg32
= tmp_reg
.reg32
;
180 nios2_supply_register (struct regcache
*regcache
, int regno
,
181 const union nios2_register
*reg
)
183 supply_register (regcache
, regno
, reg
->buf
);
186 /* We have only a single register set on Nios II. */
189 nios2_fill_gregset (struct regcache
*regcache
, void *buf
)
191 union nios2_register
*regset
= buf
;
194 for (i
= 1; i
< nios2_num_regs
; i
++)
195 nios2_collect_register (regcache
, i
, regset
+ i
);
199 nios2_store_gregset (struct regcache
*regcache
, const void *buf
)
201 const union nios2_register
*regset
= buf
;
204 for (i
= 0; i
< nios2_num_regs
; i
++)
205 nios2_supply_register (regcache
, i
, regset
+ i
);
208 static struct regset_info nios2_regsets
[] =
210 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_PRSTATUS
,
211 nios2_num_regs
* 4, GENERAL_REGS
,
212 nios2_fill_gregset
, nios2_store_gregset
},
213 { 0, 0, 0, -1, -1, NULL
, NULL
}
216 static struct regsets_info nios2_regsets_info
=
218 nios2_regsets
, /* regsets */
220 NULL
, /* disabled_regsets */
223 static struct usrregs_info nios2_usrregs_info
=
229 static struct regs_info regs_info
=
231 NULL
, /* regset_bitmap */
236 static const struct regs_info
*
237 nios2_regs_info (void)
242 struct linux_target_ops the_low_target
=
246 nios2_cannot_fetch_register
,
247 nios2_cannot_store_register
,
251 (const unsigned char *) &nios2_breakpoint
,
252 nios2_breakpoint_len
,
259 initialize_low_arch (void)
261 init_registers_nios2_linux ();
263 initialize_regsets_info (&nios2_regsets_info
);