1 /* GNU/Linux/Xtensa specific low level interface, for the remote server for GDB.
2 Copyright (C) 2007-2014 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 /* Defined in auto-generated file reg-xtensa.c. */
24 void init_registers_xtensa (void);
25 extern const struct target_desc *tdesc_xtensa;
27 #include <asm/ptrace.h>
28 #include <xtensa-config.h>
30 #include "xtensa-xtregs.c"
34 R_LBEG, R_LEND, R_LCOUNT,
41 xtensa_fill_gregset (struct regcache *regcache, void *buf)
43 elf_greg_t* rset = (elf_greg_t*)buf;
44 const struct target_desc *tdesc = regcache->tdesc;
49 /* Take care of AR registers. */
51 ar0_regnum = find_regno (tdesc, "ar0");
52 ptr = (char*)&rset[R_A0];
54 for (i = ar0_regnum; i < ar0_regnum + XCHAL_NUM_AREGS; i++)
56 collect_register (regcache, i, ptr);
57 ptr += register_size (tdesc, i);
60 /* Loop registers, if hardware has it. */
63 collect_register_by_name (regcache, "lbeg", (char*)&rset[R_LBEG]);
64 collect_register_by_name (regcache, "lend", (char*)&rset[R_LEND]);
65 collect_register_by_name (regcache, "lcount", (char*)&rset[R_LCOUNT]);
68 collect_register_by_name (regcache, "sar", (char*)&rset[R_SAR]);
69 collect_register_by_name (regcache, "pc", (char*)&rset[R_PC]);
70 collect_register_by_name (regcache, "ps", (char*)&rset[R_PS]);
71 collect_register_by_name (regcache, "windowbase", (char*)&rset[R_WB]);
72 collect_register_by_name (regcache, "windowstart", (char*)&rset[R_WS]);
76 xtensa_store_gregset (struct regcache *regcache, const void *buf)
78 const elf_greg_t* rset = (const elf_greg_t*)buf;
79 const struct target_desc *tdesc = regcache->tdesc;
84 /* Take care of AR registers. */
86 ar0_regnum = find_regno (tdesc, "ar0");
87 ptr = (char *)&rset[R_A0];
89 for (i = ar0_regnum; i < ar0_regnum + XCHAL_NUM_AREGS; i++)
91 supply_register (regcache, i, ptr);
92 ptr += register_size (tdesc, i);
95 /* Loop registers, if hardware has it. */
98 supply_register_by_name (regcache, "lbeg", (char*)&rset[R_LBEG]);
99 supply_register_by_name (regcache, "lend", (char*)&rset[R_LEND]);
100 supply_register_by_name (regcache, "lcount", (char*)&rset[R_LCOUNT]);
103 supply_register_by_name (regcache, "sar", (char*)&rset[R_SAR]);
104 supply_register_by_name (regcache, "pc", (char*)&rset[R_PC]);
105 supply_register_by_name (regcache, "ps", (char*)&rset[R_PS]);
106 supply_register_by_name (regcache, "windowbase", (char*)&rset[R_WB]);
107 supply_register_by_name (regcache, "windowstart", (char*)&rset[R_WS]);
110 /* Xtensa GNU/Linux PTRACE interface includes extended register set. */
113 xtensa_fill_xtregset (struct regcache *regcache, void *buf)
115 const xtensa_regtable_t *ptr;
117 for (ptr = xtensa_regmap_table; ptr->name; ptr++)
119 collect_register_by_name (regcache, ptr->name,
120 (char*)buf + ptr->ptrace_offset);
125 xtensa_store_xtregset (struct regcache *regcache, const void *buf)
127 const xtensa_regtable_t *ptr;
129 for (ptr = xtensa_regmap_table; ptr->name; ptr++)
131 supply_register_by_name (regcache, ptr->name,
132 (char*)buf + ptr->ptrace_offset);
136 static struct regset_info xtensa_regsets[] = {
137 { PTRACE_GETREGS, PTRACE_SETREGS, 0, sizeof (elf_gregset_t),
139 xtensa_fill_gregset, xtensa_store_gregset },
140 { PTRACE_GETXTREGS, PTRACE_SETXTREGS, 0, XTENSA_ELF_XTREG_SIZE,
142 xtensa_fill_xtregset, xtensa_store_xtregset },
143 { 0, 0, 0, -1, -1, NULL, NULL }
147 #define XTENSA_BREAKPOINT {0xd2,0x0f}
149 #define XTENSA_BREAKPOINT {0x2d,0xf0}
152 static const unsigned char xtensa_breakpoint[] = XTENSA_BREAKPOINT;
153 #define xtensa_breakpoint_len 2
156 xtensa_get_pc (struct regcache *regcache)
160 collect_register_by_name (regcache, "pc", &pc);
165 xtensa_set_pc (struct regcache *regcache, CORE_ADDR pc)
167 unsigned long newpc = pc;
168 supply_register_by_name (regcache, "pc", &newpc);
172 xtensa_breakpoint_at (CORE_ADDR where)
176 (*the_target->read_memory) (where, (unsigned char *) &insn,
177 xtensa_breakpoint_len);
178 return memcmp((char *) &insn,
179 xtensa_breakpoint, xtensa_breakpoint_len) == 0;
182 static struct regsets_info xtensa_regsets_info =
184 xtensa_regsets, /* regsets */
186 NULL, /* disabled_regsets */
189 static struct usrregs_info xtensa_usrregs_info =
195 static struct regs_info regs_info =
197 NULL, /* regset_bitmap */
198 &xtensa_usrregs_info,
203 xtensa_arch_setup (void)
205 current_process ()->tdesc = tdesc_xtensa;
208 static const struct regs_info *
209 xtensa_regs_info (void)
214 struct linux_target_ops the_low_target = {
219 NULL, /* fetch_register */
223 xtensa_breakpoint_len,
226 xtensa_breakpoint_at,
231 initialize_low_arch (void)
233 /* Initialize the Linux target descriptions. */
234 init_registers_xtensa ();
236 initialize_regsets_info (&xtensa_regsets_info);