1 /* GNU/Linux/Xtensa specific low level interface, for the remote server for GDB.
2 Copyright (C) 2007-2015 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>
29 #include "arch/xtensa.h"
30 #include "gdb_proc_service.h"
32 #include "xtensa-xtregs.c"
36 R_LBEG
, R_LEND
, R_LCOUNT
,
43 xtensa_fill_gregset (struct regcache
*regcache
, void *buf
)
45 elf_greg_t
* rset
= (elf_greg_t
*)buf
;
46 const struct target_desc
*tdesc
= regcache
->tdesc
;
51 /* Take care of AR registers. */
53 ar0_regnum
= find_regno (tdesc
, "ar0");
54 ptr
= (char*)&rset
[R_A0
];
56 for (i
= ar0_regnum
; i
< ar0_regnum
+ XCHAL_NUM_AREGS
; i
++)
58 collect_register (regcache
, i
, ptr
);
59 ptr
+= register_size (tdesc
, i
);
62 /* Loop registers, if hardware has it. */
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
]);
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
]);
78 xtensa_store_gregset (struct regcache
*regcache
, const void *buf
)
80 const elf_greg_t
* rset
= (const elf_greg_t
*)buf
;
81 const struct target_desc
*tdesc
= regcache
->tdesc
;
86 /* Take care of AR registers. */
88 ar0_regnum
= find_regno (tdesc
, "ar0");
89 ptr
= (char *)&rset
[R_A0
];
91 for (i
= ar0_regnum
; i
< ar0_regnum
+ XCHAL_NUM_AREGS
; i
++)
93 supply_register (regcache
, i
, ptr
);
94 ptr
+= register_size (tdesc
, i
);
97 /* Loop registers, if hardware has it. */
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
]);
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
]);
112 /* Xtensa GNU/Linux PTRACE interface includes extended register set. */
115 xtensa_fill_xtregset (struct regcache
*regcache
, void *buf
)
117 const xtensa_regtable_t
*ptr
;
119 for (ptr
= xtensa_regmap_table
; ptr
->name
; ptr
++)
121 collect_register_by_name (regcache
, ptr
->name
,
122 (char*)buf
+ ptr
->ptrace_offset
);
127 xtensa_store_xtregset (struct regcache
*regcache
, const void *buf
)
129 const xtensa_regtable_t
*ptr
;
131 for (ptr
= xtensa_regmap_table
; ptr
->name
; ptr
++)
133 supply_register_by_name (regcache
, ptr
->name
,
134 (char*)buf
+ ptr
->ptrace_offset
);
138 static struct regset_info xtensa_regsets
[] = {
139 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, sizeof (elf_gregset_t
),
141 xtensa_fill_gregset
, xtensa_store_gregset
},
142 { PTRACE_GETXTREGS
, PTRACE_SETXTREGS
, 0, XTENSA_ELF_XTREG_SIZE
,
144 xtensa_fill_xtregset
, xtensa_store_xtregset
},
145 { 0, 0, 0, -1, -1, NULL
, NULL
}
149 #define XTENSA_BREAKPOINT {0xd2,0x0f}
151 #define XTENSA_BREAKPOINT {0x2d,0xf0}
154 static const unsigned char xtensa_breakpoint
[] = XTENSA_BREAKPOINT
;
155 #define xtensa_breakpoint_len 2
158 xtensa_get_pc (struct regcache
*regcache
)
162 collect_register_by_name (regcache
, "pc", &pc
);
167 xtensa_set_pc (struct regcache
*regcache
, CORE_ADDR pc
)
169 unsigned long newpc
= pc
;
170 supply_register_by_name (regcache
, "pc", &newpc
);
174 xtensa_breakpoint_at (CORE_ADDR where
)
178 (*the_target
->read_memory
) (where
, (unsigned char *) &insn
,
179 xtensa_breakpoint_len
);
180 return memcmp((char *) &insn
,
181 xtensa_breakpoint
, xtensa_breakpoint_len
) == 0;
184 /* Called by libthread_db. */
187 ps_get_thread_area (const struct ps_prochandle
*ph
,
188 lwpid_t lwpid
, int idx
, void **base
)
190 xtensa_elf_gregset_t regs
;
192 if (ptrace (PTRACE_GETREGS
, lwpid
, NULL
, ®s
) != 0)
195 /* IDX is the bias from the thread pointer to the beginning of the
196 thread descriptor. It has to be subtracted due to implementation
197 quirks in libthread_db. */
198 *base
= (void *) ((char *) regs
.threadptr
- idx
);
203 static struct regsets_info xtensa_regsets_info
=
205 xtensa_regsets
, /* regsets */
207 NULL
, /* disabled_regsets */
210 static struct regs_info regs_info
=
212 NULL
, /* regset_bitmap */
218 xtensa_arch_setup (void)
220 current_process ()->tdesc
= tdesc_xtensa
;
223 static const struct regs_info
*
224 xtensa_regs_info (void)
229 struct linux_target_ops the_low_target
= {
234 NULL
, /* fetch_register */
238 xtensa_breakpoint_len
,
241 xtensa_breakpoint_at
,
246 initialize_low_arch (void)
248 /* Initialize the Linux target descriptions. */
249 init_registers_xtensa ();
251 initialize_regsets_info (&xtensa_regsets_info
);