2 * Copyright (C) 2005 by Dominic Rath
5 * Copyright (C) 2008 by Spencer Oliver
8 * Copyright (C) 2009 by Øyvind Harboe
9 * oyvind.harboe@zylin.com
11 * Copyright (C) 2018 by Liviu Ionescu
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #ifndef OPENOCD_TARGET_ARM_H
29 #define OPENOCD_TARGET_ARM_H
31 #include <helper/command.h>
36 * Holds the interface to ARM cores.
38 * At this writing, only "classic ARM" cores built on the ARMv4 register
39 * and mode model are supported. The Thumb2-only microcontroller profile
40 * support has not yet been integrated, affecting Cortex-M parts.
44 * Represent state of an ARM core.
46 * Most numbers match the five low bits of the *PSR registers on
47 * "classic ARM" processors, which build on the ARMv4 processor
48 * modes and register set.
50 * ARM_MODE_ANY is a magic value, often used as a wildcard.
52 * Only the microcontroller cores (ARMv6-M, ARMv7-M) support ARM_MODE_THREAD,
53 * ARM_MODE_USER_THREAD, and ARM_MODE_HANDLER. Those are the only modes
64 ARM_MODE_1176_MON = 28,
68 ARM_MODE_USER_THREAD = 1,
82 /* VFPv3 internal register numbers mapping to d0:31 */
119 const char *arm_mode_name(unsigned psr_mode);
120 bool is_arm_mode(unsigned psr_mode);
122 /** The PSR "T" and "J" bits define the mode of "classic ARM" cores. */
131 /** ARM vector floating point enabled, if yes which version. */
132 enum arm_vfp_version {
139 #define ARM_COMMON_MAGIC 0x0A450A45
142 * Represents a generic ARM core, with standard application registers.
144 * There are sixteen application registers (including PC, SP, LR) and a PSR.
145 * Cortex-M series cores do not support as many core states or shadowed
146 * registers as traditional ARM cores, and only support Thumb2 instructions.
150 struct reg_cache *core_cache;
152 /** Handle to the PC; valid in all core modes. */
155 /** Handle to the CPSR/xPSR; valid in all core modes. */
158 /** Handle to the SPSR; valid only in core modes with an SPSR. */
161 /** Support for arm_reg_current() */
165 * Indicates what registers are in the ARM state core register set.
166 * ARM_MODE_ANY indicates the standard set of 37 registers,
167 * seen on for example ARM7TDMI cores. ARM_MODE_MON indicates three
168 * more registers are shadowed, for "Secure Monitor" mode.
169 * ARM_MODE_THREAD indicates a microcontroller profile core,
170 * which only shadows SP.
172 enum arm_mode core_type;
174 /** Record the current core mode: SVC, USR, or some other mode. */
175 enum arm_mode core_mode;
177 /** Record the current core state: ARM, Thumb, or otherwise. */
178 enum arm_state core_state;
180 /** Flag reporting unavailability of the BKPT instruction. */
183 /** Flag reporting armv6m based core. */
186 /** Floating point or VFP version, 0 if disabled. */
189 int (*setup_semihosting)(struct target *target, int enable);
191 /** Backpointer to the target. */
192 struct target *target;
194 /** Handle for the debug module, if one is present. */
197 /** Handle for the Embedded Trace Module, if one is present. */
198 struct etm_context *etm;
200 /* FIXME all these methods should take "struct arm *" not target */
202 /** Retrieve all core registers, for display. */
203 int (*full_context)(struct target *target);
205 /** Retrieve a single core register. */
206 int (*read_core_reg)(struct target *target, struct reg *reg,
207 int num, enum arm_mode mode);
208 int (*write_core_reg)(struct target *target, struct reg *reg,
209 int num, enum arm_mode mode, uint8_t *value);
211 /** Read coprocessor register. */
212 int (*mrc)(struct target *target, int cpnum,
213 uint32_t op1, uint32_t op2,
214 uint32_t CRn, uint32_t CRm,
217 /** Write coprocessor register. */
218 int (*mcr)(struct target *target, int cpnum,
219 uint32_t op1, uint32_t op2,
220 uint32_t CRn, uint32_t CRm,
225 /** For targets conforming to ARM Debug Interface v5,
226 * this handle references the Debug Access Port (DAP)
227 * used to make requests to the target.
229 struct adiv5_dap *dap;
232 /** Convert target handle to generic ARM target state handle. */
233 static inline struct arm *target_to_arm(struct target *target)
235 assert(target != NULL);
236 return target->arch_info;
239 static inline bool is_arm(struct arm *arm)
242 return arm->common_magic == ARM_COMMON_MAGIC;
245 struct arm_algorithm {
248 enum arm_mode core_mode;
249 enum arm_state core_state;
255 struct target *target;
260 struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm);
261 struct reg_cache *armv8_build_reg_cache(struct target *target);
263 extern const struct command_registration arm_command_handlers[];
265 int arm_arch_state(struct target *target);
266 int arm_get_gdb_reg_list(struct target *target,
267 struct reg **reg_list[], int *reg_list_size,
268 enum target_register_class reg_class);
269 int armv8_get_gdb_reg_list(struct target *target,
270 struct reg **reg_list[], int *reg_list_size,
271 enum target_register_class reg_class);
273 int arm_init_arch_info(struct target *target, struct arm *arm);
275 /* REVISIT rename this once it's usable by ARMv7-M */
276 int armv4_5_run_algorithm(struct target *target,
277 int num_mem_params, struct mem_param *mem_params,
278 int num_reg_params, struct reg_param *reg_params,
279 target_addr_t entry_point, target_addr_t exit_point,
280 int timeout_ms, void *arch_info);
281 int armv4_5_run_algorithm_inner(struct target *target,
282 int num_mem_params, struct mem_param *mem_params,
283 int num_reg_params, struct reg_param *reg_params,
284 uint32_t entry_point, uint32_t exit_point,
285 int timeout_ms, void *arch_info,
286 int (*run_it)(struct target *target, uint32_t exit_point,
287 int timeout_ms, void *arch_info));
289 int arm_checksum_memory(struct target *target,
290 target_addr_t address, uint32_t count, uint32_t *checksum);
291 int arm_blank_check_memory(struct target *target,
292 struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value);
294 void arm_set_cpsr(struct arm *arm, uint32_t cpsr);
295 struct reg *arm_reg_current(struct arm *arm, unsigned regnum);
296 struct reg *armv8_reg_current(struct arm *arm, unsigned regnum);
298 extern struct reg arm_gdb_dummy_fp_reg;
299 extern struct reg arm_gdb_dummy_fps_reg;
301 #endif /* OPENOCD_TARGET_ARM_H */