1 /* GNU/Linux/Xtensa specific low level interface, for the remote server for GDB.
2 Copyright (C) 2007-2023 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 /* Linux target op definitions for the Xtensa architecture. */
25 class xtensa_target
: public linux_process_target
29 const regs_info
*get_regs_info () override
;
31 const gdb_byte
*sw_breakpoint_from_kind (int kind
, int *size
) override
;
35 void low_arch_setup () override
;
37 bool low_cannot_fetch_register (int regno
) override
;
39 bool low_cannot_store_register (int regno
) override
;
41 bool low_supports_breakpoints () override
;
43 CORE_ADDR
low_get_pc (regcache
*regcache
) override
;
45 void low_set_pc (regcache
*regcache
, CORE_ADDR newpc
) override
;
47 bool low_breakpoint_at (CORE_ADDR pc
) override
;
50 /* The singleton target ops object. */
52 static xtensa_target the_xtensa_target
;
55 xtensa_target::low_cannot_fetch_register (int regno
)
57 gdb_assert_not_reached ("linux target op low_cannot_fetch_register "
58 "is not implemented by the target");
62 xtensa_target::low_cannot_store_register (int regno
)
64 gdb_assert_not_reached ("linux target op low_cannot_store_register "
65 "is not implemented by the target");
69 xtensa_target::low_supports_breakpoints ()
75 xtensa_target::low_get_pc (regcache
*regcache
)
77 return linux_get_pc_32bit (regcache
);
81 xtensa_target::low_set_pc (regcache
*regcache
, CORE_ADDR pc
)
83 linux_set_pc_32bit (regcache
, pc
);
86 /* Defined in auto-generated file reg-xtensa.c. */
87 void init_registers_xtensa (void);
88 extern const struct target_desc
*tdesc_xtensa
;
90 #include <asm/ptrace.h>
91 #include <xtensa-config.h>
92 #include "arch/xtensa.h"
93 #include "gdb_proc_service.h"
95 #include "xtensa-xtregs.c"
99 R_LBEG
, R_LEND
, R_LCOUNT
,
107 xtensa_fill_gregset (struct regcache
*regcache
, void *buf
)
109 elf_greg_t
* rset
= (elf_greg_t
*)buf
;
110 const struct target_desc
*tdesc
= regcache
->tdesc
;
115 /* Take care of AR registers. */
117 ar0_regnum
= find_regno (tdesc
, "ar0");
118 ptr
= (char*)&rset
[R_A0
];
120 for (i
= ar0_regnum
; i
< ar0_regnum
+ XCHAL_NUM_AREGS
; i
++)
122 collect_register (regcache
, i
, ptr
);
123 ptr
+= register_size (tdesc
, i
);
126 if (XSHAL_ABI
== XTHAL_ABI_CALL0
)
128 int a0_regnum
= find_regno (tdesc
, "a0");
129 ptr
= (char *) &rset
[R_A0
+ 4 * rset
[R_WB
]];
131 for (i
= a0_regnum
; i
< a0_regnum
+ C0_NREGS
; i
++)
133 if ((4 * rset
[R_WB
] + i
- a0_regnum
) == XCHAL_NUM_AREGS
)
134 ptr
= (char *) &rset
[R_A0
];
135 collect_register (regcache
, i
, ptr
);
136 ptr
+= register_size (tdesc
, i
);
140 /* Loop registers, if hardware has it. */
143 collect_register_by_name (regcache
, "lbeg", (char*)&rset
[R_LBEG
]);
144 collect_register_by_name (regcache
, "lend", (char*)&rset
[R_LEND
]);
145 collect_register_by_name (regcache
, "lcount", (char*)&rset
[R_LCOUNT
]);
148 collect_register_by_name (regcache
, "sar", (char*)&rset
[R_SAR
]);
149 collect_register_by_name (regcache
, "pc", (char*)&rset
[R_PC
]);
150 collect_register_by_name (regcache
, "ps", (char*)&rset
[R_PS
]);
151 collect_register_by_name (regcache
, "windowbase", (char*)&rset
[R_WB
]);
152 collect_register_by_name (regcache
, "windowstart", (char*)&rset
[R_WS
]);
154 #if XCHAL_HAVE_THREADPTR
155 collect_register_by_name (regcache
, "threadptr",
156 (char *) &rset
[R_THREADPTR
]);
161 xtensa_store_gregset (struct regcache
*regcache
, const void *buf
)
163 const elf_greg_t
* rset
= (const elf_greg_t
*)buf
;
164 const struct target_desc
*tdesc
= regcache
->tdesc
;
169 /* Take care of AR registers. */
171 ar0_regnum
= find_regno (tdesc
, "ar0");
172 ptr
= (char *)&rset
[R_A0
];
174 for (i
= ar0_regnum
; i
< ar0_regnum
+ XCHAL_NUM_AREGS
; i
++)
176 supply_register (regcache
, i
, ptr
);
177 ptr
+= register_size (tdesc
, i
);
180 if (XSHAL_ABI
== XTHAL_ABI_CALL0
)
182 int a0_regnum
= find_regno (tdesc
, "a0");
183 ptr
= (char *) &rset
[R_A0
+ (4 * rset
[R_WB
]) % XCHAL_NUM_AREGS
];
185 for (i
= a0_regnum
; i
< a0_regnum
+ C0_NREGS
; i
++)
187 if ((4 * rset
[R_WB
] + i
- a0_regnum
) == XCHAL_NUM_AREGS
)
188 ptr
= (char *) &rset
[R_A0
];
189 supply_register (regcache
, i
, ptr
);
190 ptr
+= register_size (tdesc
, i
);
194 /* Loop registers, if hardware has it. */
197 supply_register_by_name (regcache
, "lbeg", (char*)&rset
[R_LBEG
]);
198 supply_register_by_name (regcache
, "lend", (char*)&rset
[R_LEND
]);
199 supply_register_by_name (regcache
, "lcount", (char*)&rset
[R_LCOUNT
]);
202 supply_register_by_name (regcache
, "sar", (char*)&rset
[R_SAR
]);
203 supply_register_by_name (regcache
, "pc", (char*)&rset
[R_PC
]);
204 supply_register_by_name (regcache
, "ps", (char*)&rset
[R_PS
]);
205 supply_register_by_name (regcache
, "windowbase", (char*)&rset
[R_WB
]);
206 supply_register_by_name (regcache
, "windowstart", (char*)&rset
[R_WS
]);
208 #if XCHAL_HAVE_THREADPTR
209 supply_register_by_name (regcache
, "threadptr",
210 (char *) &rset
[R_THREADPTR
]);
214 /* Xtensa GNU/Linux PTRACE interface includes extended register set. */
217 xtensa_fill_xtregset (struct regcache
*regcache
, void *buf
)
219 const xtensa_regtable_t
*ptr
;
221 for (ptr
= xtensa_regmap_table
; ptr
->name
; ptr
++)
223 collect_register_by_name (regcache
, ptr
->name
,
224 (char*)buf
+ ptr
->ptrace_offset
);
229 xtensa_store_xtregset (struct regcache
*regcache
, const void *buf
)
231 const xtensa_regtable_t
*ptr
;
233 for (ptr
= xtensa_regmap_table
; ptr
->name
; ptr
++)
235 supply_register_by_name (regcache
, ptr
->name
,
236 (char*)buf
+ ptr
->ptrace_offset
);
240 static struct regset_info xtensa_regsets
[] = {
241 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, sizeof (elf_gregset_t
),
243 xtensa_fill_gregset
, xtensa_store_gregset
},
244 { PTRACE_GETXTREGS
, PTRACE_SETXTREGS
, 0, XTENSA_ELF_XTREG_SIZE
,
246 xtensa_fill_xtregset
, xtensa_store_xtregset
},
251 #define XTENSA_BREAKPOINT {0xd2,0x0f}
253 #define XTENSA_BREAKPOINT {0x2d,0xf0}
256 static const gdb_byte xtensa_breakpoint
[] = XTENSA_BREAKPOINT
;
257 #define xtensa_breakpoint_len 2
259 /* Implementation of target ops method "sw_breakpoint_from_kind". */
262 xtensa_target::sw_breakpoint_from_kind (int kind
, int *size
)
264 *size
= xtensa_breakpoint_len
;
265 return xtensa_breakpoint
;
269 xtensa_target::low_breakpoint_at (CORE_ADDR where
)
273 read_memory (where
, (unsigned char *) &insn
, xtensa_breakpoint_len
);
274 return memcmp((char *) &insn
,
275 xtensa_breakpoint
, xtensa_breakpoint_len
) == 0;
278 /* Called by libthread_db. */
281 ps_get_thread_area (struct ps_prochandle
*ph
,
282 lwpid_t lwpid
, int idx
, void **base
)
284 xtensa_elf_gregset_t regs
;
286 if (ptrace (PTRACE_GETREGS
, lwpid
, NULL
, ®s
) != 0)
289 /* IDX is the bias from the thread pointer to the beginning of the
290 thread descriptor. It has to be subtracted due to implementation
291 quirks in libthread_db. */
292 *base
= (void *) ((char *) regs
.threadptr
- idx
);
297 static struct regsets_info xtensa_regsets_info
=
299 xtensa_regsets
, /* regsets */
301 NULL
, /* disabled_regsets */
304 static struct regs_info myregs_info
=
306 NULL
, /* regset_bitmap */
312 xtensa_target::low_arch_setup ()
314 current_process ()->tdesc
= tdesc_xtensa
;
318 xtensa_target::get_regs_info ()
323 /* The linux target ops object. */
325 linux_process_target
*the_linux_target
= &the_xtensa_target
;
328 initialize_low_arch (void)
330 /* Initialize the Linux target descriptions. */
331 init_registers_xtensa ();
333 initialize_regsets_info (&xtensa_regsets_info
);