Commit | Line | Data |
---|---|---|
1525d545 | 1 | /* GNU/Linux/Xtensa specific low level interface, for the remote server for GDB. |
32d0add0 | 2 | Copyright (C) 2007-2015 Free Software Foundation, Inc. |
1525d545 MG |
3 | |
4 | This file is part of GDB. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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/>. */ | |
18 | ||
19 | ||
20 | #include "server.h" | |
21 | #include "linux-low.h" | |
22 | ||
d05b4ac3 UW |
23 | /* Defined in auto-generated file reg-xtensa.c. */ |
24 | void init_registers_xtensa (void); | |
3aee8918 | 25 | extern const struct target_desc *tdesc_xtensa; |
d05b4ac3 | 26 | |
e671835b | 27 | #include <asm/ptrace.h> |
1525d545 | 28 | #include <xtensa-config.h> |
40045d91 MF |
29 | #include "arch/xtensa.h" |
30 | #include "gdb_proc_service.h" | |
1525d545 MG |
31 | |
32 | #include "xtensa-xtregs.c" | |
33 | ||
34 | enum regnum { | |
35 | R_PC=0, R_PS, | |
36 | R_LBEG, R_LEND, R_LCOUNT, | |
37 | R_SAR, | |
38 | R_WS, R_WB, | |
1b3f6016 | 39 | R_A0 = 64 |
1525d545 MG |
40 | }; |
41 | ||
42 | static void | |
442ea881 | 43 | xtensa_fill_gregset (struct regcache *regcache, void *buf) |
1525d545 MG |
44 | { |
45 | elf_greg_t* rset = (elf_greg_t*)buf; | |
3aee8918 | 46 | const struct target_desc *tdesc = regcache->tdesc; |
1525d545 MG |
47 | int ar0_regnum; |
48 | char *ptr; | |
49 | int i; | |
50 | ||
51 | /* Take care of AR registers. */ | |
52 | ||
3aee8918 | 53 | ar0_regnum = find_regno (tdesc, "ar0"); |
1525d545 MG |
54 | ptr = (char*)&rset[R_A0]; |
55 | ||
56 | for (i = ar0_regnum; i < ar0_regnum + XCHAL_NUM_AREGS; i++) | |
57 | { | |
442ea881 | 58 | collect_register (regcache, i, ptr); |
3aee8918 | 59 | ptr += register_size (tdesc, i); |
1525d545 MG |
60 | } |
61 | ||
62 | /* Loop registers, if hardware has it. */ | |
63 | ||
a2d5a9d7 | 64 | #if XCHAL_HAVE_LOOPS |
442ea881 PA |
65 | collect_register_by_name (regcache, "lbeg", (char*)&rset[R_LBEG]); |
66 | collect_register_by_name (regcache, "lend", (char*)&rset[R_LEND]); | |
67 | collect_register_by_name (regcache, "lcount", (char*)&rset[R_LCOUNT]); | |
1525d545 MG |
68 | #endif |
69 | ||
442ea881 PA |
70 | collect_register_by_name (regcache, "sar", (char*)&rset[R_SAR]); |
71 | collect_register_by_name (regcache, "pc", (char*)&rset[R_PC]); | |
72 | collect_register_by_name (regcache, "ps", (char*)&rset[R_PS]); | |
73 | collect_register_by_name (regcache, "windowbase", (char*)&rset[R_WB]); | |
74 | collect_register_by_name (regcache, "windowstart", (char*)&rset[R_WS]); | |
1525d545 MG |
75 | } |
76 | ||
77 | static void | |
442ea881 | 78 | xtensa_store_gregset (struct regcache *regcache, const void *buf) |
1525d545 MG |
79 | { |
80 | const elf_greg_t* rset = (const elf_greg_t*)buf; | |
3aee8918 | 81 | const struct target_desc *tdesc = regcache->tdesc; |
1525d545 MG |
82 | int ar0_regnum; |
83 | char *ptr; | |
84 | int i; | |
85 | ||
86 | /* Take care of AR registers. */ | |
87 | ||
3aee8918 | 88 | ar0_regnum = find_regno (tdesc, "ar0"); |
1525d545 MG |
89 | ptr = (char *)&rset[R_A0]; |
90 | ||
91 | for (i = ar0_regnum; i < ar0_regnum + XCHAL_NUM_AREGS; i++) | |
92 | { | |
442ea881 | 93 | supply_register (regcache, i, ptr); |
3aee8918 | 94 | ptr += register_size (tdesc, i); |
1525d545 MG |
95 | } |
96 | ||
97 | /* Loop registers, if hardware has it. */ | |
98 | ||
a2d5a9d7 | 99 | #if XCHAL_HAVE_LOOPS |
442ea881 PA |
100 | supply_register_by_name (regcache, "lbeg", (char*)&rset[R_LBEG]); |
101 | supply_register_by_name (regcache, "lend", (char*)&rset[R_LEND]); | |
102 | supply_register_by_name (regcache, "lcount", (char*)&rset[R_LCOUNT]); | |
1525d545 MG |
103 | #endif |
104 | ||
442ea881 PA |
105 | supply_register_by_name (regcache, "sar", (char*)&rset[R_SAR]); |
106 | supply_register_by_name (regcache, "pc", (char*)&rset[R_PC]); | |
107 | supply_register_by_name (regcache, "ps", (char*)&rset[R_PS]); | |
108 | supply_register_by_name (regcache, "windowbase", (char*)&rset[R_WB]); | |
109 | supply_register_by_name (regcache, "windowstart", (char*)&rset[R_WS]); | |
1525d545 MG |
110 | } |
111 | ||
112 | /* Xtensa GNU/Linux PTRACE interface includes extended register set. */ | |
113 | ||
114 | static void | |
442ea881 | 115 | xtensa_fill_xtregset (struct regcache *regcache, void *buf) |
1525d545 MG |
116 | { |
117 | const xtensa_regtable_t *ptr; | |
118 | ||
119 | for (ptr = xtensa_regmap_table; ptr->name; ptr++) | |
120 | { | |
442ea881 | 121 | collect_register_by_name (regcache, ptr->name, |
1525d545 MG |
122 | (char*)buf + ptr->ptrace_offset); |
123 | } | |
124 | } | |
125 | ||
126 | static void | |
442ea881 | 127 | xtensa_store_xtregset (struct regcache *regcache, const void *buf) |
1525d545 MG |
128 | { |
129 | const xtensa_regtable_t *ptr; | |
130 | ||
131 | for (ptr = xtensa_regmap_table; ptr->name; ptr++) | |
132 | { | |
442ea881 | 133 | supply_register_by_name (regcache, ptr->name, |
1525d545 MG |
134 | (char*)buf + ptr->ptrace_offset); |
135 | } | |
136 | } | |
137 | ||
3aee8918 | 138 | static struct regset_info xtensa_regsets[] = { |
1570b33e | 139 | { PTRACE_GETREGS, PTRACE_SETREGS, 0, sizeof (elf_gregset_t), |
1525d545 MG |
140 | GENERAL_REGS, |
141 | xtensa_fill_gregset, xtensa_store_gregset }, | |
1570b33e | 142 | { PTRACE_GETXTREGS, PTRACE_SETXTREGS, 0, XTENSA_ELF_XTREG_SIZE, |
1525d545 MG |
143 | EXTENDED_REGS, |
144 | xtensa_fill_xtregset, xtensa_store_xtregset }, | |
1570b33e | 145 | { 0, 0, 0, -1, -1, NULL, NULL } |
1525d545 MG |
146 | }; |
147 | ||
148 | #if XCHAL_HAVE_BE | |
149 | #define XTENSA_BREAKPOINT {0xd2,0x0f} | |
150 | #else | |
151 | #define XTENSA_BREAKPOINT {0x2d,0xf0} | |
152 | #endif | |
153 | ||
dd373349 | 154 | static const gdb_byte xtensa_breakpoint[] = XTENSA_BREAKPOINT; |
1525d545 MG |
155 | #define xtensa_breakpoint_len 2 |
156 | ||
dd373349 AT |
157 | /* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */ |
158 | ||
159 | static const gdb_byte * | |
160 | xtensa_sw_breakpoint_from_kind (int kind, int *size) | |
161 | { | |
162 | *size = xtensa_breakpoint_len; | |
163 | return xtensa_breakpoint; | |
164 | } | |
165 | ||
1525d545 | 166 | static CORE_ADDR |
442ea881 | 167 | xtensa_get_pc (struct regcache *regcache) |
1525d545 MG |
168 | { |
169 | unsigned long pc; | |
170 | ||
442ea881 | 171 | collect_register_by_name (regcache, "pc", &pc); |
1525d545 MG |
172 | return pc; |
173 | } | |
174 | ||
175 | static void | |
442ea881 | 176 | xtensa_set_pc (struct regcache *regcache, CORE_ADDR pc) |
1525d545 MG |
177 | { |
178 | unsigned long newpc = pc; | |
442ea881 | 179 | supply_register_by_name (regcache, "pc", &newpc); |
1525d545 MG |
180 | } |
181 | ||
182 | static int | |
183 | xtensa_breakpoint_at (CORE_ADDR where) | |
184 | { | |
185 | unsigned long insn; | |
186 | ||
187 | (*the_target->read_memory) (where, (unsigned char *) &insn, | |
188 | xtensa_breakpoint_len); | |
493e2a69 MS |
189 | return memcmp((char *) &insn, |
190 | xtensa_breakpoint, xtensa_breakpoint_len) == 0; | |
1525d545 MG |
191 | } |
192 | ||
40045d91 MF |
193 | /* Called by libthread_db. */ |
194 | ||
195 | ps_err_e | |
196 | ps_get_thread_area (const struct ps_prochandle *ph, | |
197 | lwpid_t lwpid, int idx, void **base) | |
198 | { | |
199 | xtensa_elf_gregset_t regs; | |
200 | ||
201 | if (ptrace (PTRACE_GETREGS, lwpid, NULL, ®s) != 0) | |
202 | return PS_ERR; | |
203 | ||
204 | /* IDX is the bias from the thread pointer to the beginning of the | |
205 | thread descriptor. It has to be subtracted due to implementation | |
206 | quirks in libthread_db. */ | |
207 | *base = (void *) ((char *) regs.threadptr - idx); | |
208 | ||
209 | return PS_OK; | |
210 | } | |
211 | ||
3aee8918 PA |
212 | static struct regsets_info xtensa_regsets_info = |
213 | { | |
214 | xtensa_regsets, /* regsets */ | |
215 | 0, /* num_regsets */ | |
216 | NULL, /* disabled_regsets */ | |
217 | }; | |
218 | ||
3aee8918 PA |
219 | static struct regs_info regs_info = |
220 | { | |
221 | NULL, /* regset_bitmap */ | |
deb44829 | 222 | NULL, /* usrregs */ |
3aee8918 PA |
223 | &xtensa_regsets_info |
224 | }; | |
225 | ||
226 | static void | |
227 | xtensa_arch_setup (void) | |
228 | { | |
229 | current_process ()->tdesc = tdesc_xtensa; | |
230 | } | |
231 | ||
232 | static const struct regs_info * | |
233 | xtensa_regs_info (void) | |
234 | { | |
235 | return ®s_info; | |
236 | } | |
237 | ||
1525d545 | 238 | struct linux_target_ops the_low_target = { |
3aee8918 PA |
239 | xtensa_arch_setup, |
240 | xtensa_regs_info, | |
1525d545 MG |
241 | 0, |
242 | 0, | |
c14dfd32 | 243 | NULL, /* fetch_register */ |
1525d545 MG |
244 | xtensa_get_pc, |
245 | xtensa_set_pc, | |
dd373349 AT |
246 | NULL, /* breakpoint_kind_from_pc */ |
247 | xtensa_sw_breakpoint_from_kind, | |
1525d545 MG |
248 | NULL, |
249 | 0, | |
250 | xtensa_breakpoint_at, | |
251 | }; | |
3aee8918 PA |
252 | |
253 | ||
254 | void | |
255 | initialize_low_arch (void) | |
256 | { | |
257 | /* Initialize the Linux target descriptions. */ | |
258 | init_registers_xtensa (); | |
259 | ||
260 | initialize_regsets_info (&xtensa_regsets_info); | |
261 | } |