1 /* Ravenscar PowerPC target support.
3 Copyright (C) 2011-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "ravenscar-thread.h"
26 #include "ppc-ravenscar-thread.h"
30 /* See ppc-tdep.h for register numbers. */
32 static const int powerpc_context_offsets[] =
35 NO_OFFSET, 0, 4, NO_OFFSET,
36 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
37 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
45 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
46 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
47 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
48 NO_OFFSET, NO_OFFSET, 96, 104,
55 88, NO_OFFSET, 84, NO_OFFSET,
58 NO_OFFSET, NO_OFFSET, 240
61 static const int e500_context_offsets[] =
64 NO_OFFSET, 4, 12, NO_OFFSET,
65 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
66 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
67 NO_OFFSET, 20, 28, 36,
74 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
75 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
76 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
77 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
78 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
79 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
80 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
81 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
84 172, NO_OFFSET, 168, NO_OFFSET,
86 /* CTR, XER, FPSCR, MQ */
87 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
90 NO_OFFSET, 0, 8, NO_OFFSET,
91 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
92 NO_OFFSET, NO_OFFSET, NO_OFFSET, NO_OFFSET,
93 NO_OFFSET, 16, 24, 32,
103 /* The register layout info. */
105 struct ravenscar_reg_info
107 /* A table providing the offset relative to the context structure
108 where each register is saved. */
109 const int *context_offsets;
111 /* The number of elements in the context_offsets table above. */
112 int context_offsets_size;
115 /* supply register REGNUM, which has been saved on REGISTER_ADDR, to the
119 supply_register_at_address (struct regcache *regcache, int regnum,
120 CORE_ADDR register_addr)
122 struct gdbarch *gdbarch = regcache->arch ();
123 int buf_size = register_size (gdbarch, regnum);
126 buf = (gdb_byte *) alloca (buf_size);
127 read_memory (register_addr, buf, buf_size);
128 regcache->raw_supply (regnum, buf);
131 /* Return true if, for a non-running thread, REGNUM has been saved on the
132 Thread_Descriptor. */
135 register_in_thread_descriptor_p (const struct ravenscar_reg_info *reg_info,
138 return (regnum < reg_info->context_offsets_size
139 && reg_info->context_offsets[regnum] != NO_OFFSET);
142 /* to_fetch_registers when inferior_ptid is different from the running
146 ppc_ravenscar_generic_fetch_registers
147 (const struct ravenscar_reg_info *reg_info,
148 struct regcache *regcache, int regnum)
150 struct gdbarch *gdbarch = regcache->arch ();
151 const int num_regs = gdbarch_num_regs (gdbarch);
153 CORE_ADDR current_address;
154 CORE_ADDR thread_descriptor_address;
156 /* The tid is the thread_id field, which is a pointer to the thread. */
157 thread_descriptor_address = (CORE_ADDR) inferior_ptid.tid ();
159 /* Read registers. */
160 for (current_regnum = 0; current_regnum < num_regs; current_regnum++)
162 if (register_in_thread_descriptor_p (reg_info, current_regnum))
164 current_address = thread_descriptor_address
165 + reg_info->context_offsets[current_regnum];
166 supply_register_at_address (regcache, current_regnum,
172 /* to_store_registers when inferior_ptid is different from the running
176 ppc_ravenscar_generic_store_registers
177 (const struct ravenscar_reg_info *reg_info,
178 struct regcache *regcache, int regnum)
180 struct gdbarch *gdbarch = regcache->arch ();
181 int buf_size = register_size (gdbarch, regnum);
182 gdb_byte buf[buf_size];
183 ULONGEST register_address;
185 if (register_in_thread_descriptor_p (reg_info, regnum))
187 = inferior_ptid.tid () + reg_info->context_offsets [regnum];
191 regcache->raw_collect (regnum, buf);
192 write_memory (register_address,
197 /* The ravenscar_reg_info for most PowerPC targets. */
199 static const struct ravenscar_reg_info ppc_reg_info =
201 powerpc_context_offsets,
202 ARRAY_SIZE (powerpc_context_offsets),
205 struct ppc_ravenscar_powerpc_ops : public ravenscar_arch_ops
207 void fetch_registers (struct regcache *, int) override;
208 void store_registers (struct regcache *, int) override;
212 ppc_ravenscar_powerpc_ops::fetch_registers (struct regcache *regcache, int regnum)
214 ppc_ravenscar_generic_fetch_registers (&ppc_reg_info, regcache, regnum);
218 ppc_ravenscar_powerpc_ops::store_registers (struct regcache *regcache, int regnum)
220 ppc_ravenscar_generic_store_registers (&ppc_reg_info, regcache, regnum);
223 /* The ravenscar_arch_ops vector for most PowerPC targets. */
225 static struct ppc_ravenscar_powerpc_ops ppc_ravenscar_powerpc_ops;
227 /* Register ppc_ravenscar_powerpc_ops in GDBARCH. */
230 register_ppc_ravenscar_ops (struct gdbarch *gdbarch)
232 set_gdbarch_ravenscar_ops (gdbarch, &ppc_ravenscar_powerpc_ops);
235 /* The ravenscar_reg_info for E500 targets. */
237 static const struct ravenscar_reg_info e500_reg_info =
239 e500_context_offsets,
240 ARRAY_SIZE (e500_context_offsets),
243 struct ppc_ravenscar_e500_ops : public ravenscar_arch_ops
245 void fetch_registers (struct regcache *, int) override;
246 void store_registers (struct regcache *, int) override;
250 ppc_ravenscar_e500_ops::fetch_registers (struct regcache *regcache, int regnum)
252 ppc_ravenscar_generic_fetch_registers (&e500_reg_info, regcache, regnum);
255 /* Implement the to_store_registers ravenscar_arch_ops method
259 ppc_ravenscar_e500_ops::store_registers (struct regcache *regcache, int regnum)
261 ppc_ravenscar_generic_store_registers (&e500_reg_info, regcache, regnum);
264 /* The ravenscar_arch_ops vector for E500 targets. */
266 static struct ppc_ravenscar_e500_ops ppc_ravenscar_e500_ops;
268 /* Register ppc_ravenscar_e500_ops in GDBARCH. */
271 register_e500_ravenscar_ops (struct gdbarch *gdbarch)
273 set_gdbarch_ravenscar_ops (gdbarch, &ppc_ravenscar_e500_ops);