40 #define _DEBUG_INSTRUCTION_EXECUTION_
44 "",
"Reset",
"NMI",
"HardFault",
45 "MemManage",
"BusFault",
"UsageFault",
"SecureFault",
46 "RESERVED",
"RESERVED",
"RESERVED",
"SVCall",
47 "DebugMonitor",
"RESERVED",
"PendSV",
"SysTick"
162 #define ARMV7M_NUM_REGS ARRAY_SIZE(armv7m_regs)
182 for (i = cache->
num_regs - 1; i >= 0; i--) {
206 static char enamebuf[32];
209 return "Invalid exception";
212 sprintf(enamebuf,
"External Interrupt(%i)",
number - 16);
248 switch (arm_reg_id) {
279 LOG_ERROR(
"Bad register ID %u", arm_reg_id);
285 unsigned int *reg32_id, uint32_t *
offset)
288 switch (arm_reg_id) {
317 assert(num == (
int)r->
number);
327 unsigned int reg32_id;
350 assert(r->
size == 32 || r->
size == 64);
388 assert(num == (
int)r->
number);
390 if (value != r->
value) {
398 unsigned int reg32_id;
422 assert(r->
size == 32 || r->
size == 64);
470 *reg_list = malloc(
sizeof(
struct reg *) *
size);
474 for (i = 0; i <
size; i++)
477 *reg_list_size =
size;
484 int num_mem_params,
struct mem_param *mem_params,
485 int num_reg_params,
struct reg_param *reg_params,
487 unsigned int timeout_ms,
void *arch_info)
492 num_mem_params, mem_params,
493 num_reg_params, reg_params,
494 entry_point, exit_point,
499 num_mem_params, mem_params,
500 num_reg_params, reg_params,
501 exit_point, timeout_ms,
509 int num_mem_params,
struct mem_param *mem_params,
510 int num_reg_params,
struct reg_param *reg_params,
547 for (
int i = 0; i < num_mem_params; i++) {
552 mem_params[i].
value);
557 for (
int i = 0; i < num_reg_params; i++) {
572 reg_params[i].reg_name);
598 armv7m_algorithm_info->
core_mode != core_mode) {
615 armv7m_algorithm_info->
core_mode = core_mode;
624 int num_mem_params,
struct mem_param *mem_params,
625 int num_reg_params,
struct reg_param *reg_params,
656 if (pc != exit_point) {
664 for (
int i = 0; i < num_mem_params; i++) {
668 mem_params[i].value);
675 for (
int i = 0; i < num_reg_params; i++) {
683 reg_params[i].reg_name);
689 "BUG: register '%s' size doesn't match reg_params[i].size",
690 reg_params[i].reg_name);
705 if (regvalue != armv7m_algorithm_info->
context[i]) {
709 0, 32, armv7m_algorithm_info->
context[i]);
744 "xPSR: %#8.8" PRIx32
" pc: %#8.8" PRIx32
" %csp: %#8.8" PRIx32
"%s%s",
750 (
ctrl & 0x02) ?
'p' :
'm',
771 struct reg *reg_list = calloc(num_regs,
sizeof(
struct reg));
772 struct arm_reg *arch_info = calloc(num_regs,
sizeof(
struct arm_reg));
777 cache->
name =
"arm v7m registers";
783 for (i = 0; i < num_regs; i++) {
791 reg_list[i].
dirty =
false;
792 reg_list[i].
valid =
false;
800 reg_list[i].
exist =
true;
803 if (reg_list[i].hidden)
840 for (i = 0; i < cache->
num_regs; i++) {
891 static const uint8_t cortex_m_crc_code[] = {
892 #include "../../contrib/loaders/checksum/armv7m_crc.inc"
900 sizeof(cortex_m_crc_code), (uint8_t *)cortex_m_crc_code);
913 unsigned int timeout = 20000 * (1 + (
count / (1024 * 1024)));
916 crc_algorithm->
address + (
sizeof(cortex_m_crc_code) - 6),
943 static bool timed_out;
945 static const uint8_t erase_check_code[] = {
946 #include "../../contrib/loaders/erase_check/armv7m_erase_check.inc"
949 const uint32_t code_size =
sizeof(erase_check_code);
953 &erase_check_algorithm) !=
ERROR_OK)
957 code_size, erase_check_code);
971 int blocks_to_check = avail /
sizeof(
struct algo_block) - 1;
972 if (num_blocks < blocks_to_check)
973 blocks_to_check = num_blocks;
975 struct algo_block *params = malloc((blocks_to_check+1)*
sizeof(
struct algo_block));
982 uint32_t total_size = 0;
983 for (i = 0; i < blocks_to_check; i++) {
984 total_size += blocks[i].
size;
986 blocks[i].
size /
sizeof(uint32_t));
992 uint32_t param_size = (blocks_to_check + 1) *
sizeof(
struct algo_block);
1000 param_size, (uint8_t *)params);
1004 uint32_t erased_word = erased_value | (erased_value << 8)
1005 | (erased_value << 16) | (erased_value << 24);
1017 buf_set_u32(reg_params[1].value, 0, 32, erased_word);
1020 unsigned int timeout = (timed_out ? 30000 : 2000) + total_size * 3 / 1000;
1025 erase_check_algorithm->
address,
1026 erase_check_algorithm->
address + (code_size - 2),
1031 if (retval !=
ERROR_OK && !timed_out)
1035 param_size, (uint8_t *)params);
1039 for (i = 0; i < blocks_to_check; i++) {
1041 (uint8_t *)&(params[i].result));
1042 if (result != 0 && result != 1)
1045 blocks[i].
result = result;
1071 bool result =
false;
1084 if ((
op & 0xFF00) == 0xBE00) {
1096 *inst_found = result;
1105 .help =
"ARM command group",
void init_reg_param(struct reg_param *param, char *reg_name, uint32_t size, enum param_direction direction)
void destroy_reg_param(struct reg_param *param)
const struct command_registration arm_all_profiles_command_handlers[]
arm_mode
Represent state of an ARM core.
static struct arm * target_to_arm(const struct target *target)
Convert target handle to generic ARM target state handle.
int arm_init_arch_info(struct target *target, struct arm *arm)
const char * arm_mode_name(unsigned int psr_mode)
Map PSR mode bits to the name of an ARM processor operating mode.
@ ARM_CORE_TYPE_M_PROFILE
int armv7m_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Returns generic ARM userspace registers to GDB.
int armv7m_maybe_skip_bkpt_inst(struct target *target, bool *inst_found)
void armv7m_free_reg_cache(struct target *target)
static int armv7m_setup_semihosting(struct target *target, int enable)
const int armv7m_psp_reg_map[ARMV7M_NUM_CORE_REGS]
uint32_t armv7m_map_id_to_regsel(unsigned int arm_reg_id)
static const struct @78 armv7m_regs[]
static int armv7m_write_core_reg(struct target *target, struct reg *r, int num, enum arm_mode mode, uint8_t *value)
struct reg_cache * armv7m_build_reg_cache(struct target *target)
Builds cache of architecturally defined registers.
static int armv7m_read_core_reg(struct target *target, struct reg *r, int num, enum arm_mode mode)
const int armv7m_msp_reg_map[ARMV7M_NUM_CORE_REGS]
int armv7m_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Runs a Thumb algorithm in the target.
static int armv7m_set_core_reg(struct reg *reg, uint8_t *buf)
int armv7m_checksum_memory(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
Generates a CRC32 checksum of a memory region.
int armv7m_wait_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Waits for an algorithm in the target.
bool armv7m_map_reg_packing(unsigned int arm_reg_id, unsigned int *reg32_id, uint32_t *offset)
int armv7m_blank_check_memory(struct target *target, struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value)
Checks an array of memory regions whether they are erased.
static const char *const armv7m_exception_strings[]
int armv7m_arch_state(struct target *target)
Logs summary of ARMv7-M state for a halted target.
int armv7m_restore_context(struct target *target)
Restores target context using the cache of core registers set up by armv7m_build_reg_cache(),...
const char * armv7m_exception_string(int number)
Maps ISR number (from xPSR) to name.
static int armv7m_get_core_reg(struct reg *reg)
int armv7m_start_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, void *arch_info)
Starts a Thumb algorithm in the target.
static const struct reg_arch_type armv7m_reg_type
const struct command_registration armv7m_command_handlers[]
int armv7m_init_arch_info(struct target *target, struct armv7m_common *armv7m)
Sets up target as a generic ARMv7-M core.
@ ARMV8M_PMSK_BPRI_FLTMSK_CTRL_NS
@ ARMV7M_PMSK_BPRI_FLTMSK_CTRL
@ ARMV8M_PMSK_BPRI_FLTMSK_CTRL_S
@ ARMV8M_REGSEL_PMSK_BPRI_FLTMSK_CTRL_S
@ ARMV7M_REGSEL_PMSK_BPRI_FLTMSK_CTRL
@ ARMV8M_REGSEL_PMSK_BPRI_FLTMSK_CTRL_NS
static struct armv7m_common * target_to_armv7m(struct target *target)
#define ARMV7M_NUM_CORE_REGS
#define ARMV7M_COMMON_MAGIC
void * buf_cpy(const void *from, void *_to, unsigned int size)
Copies size bits out of from and into to.
Support functions to access arbitrary bits in a byte array.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
static uint64_t buf_get_u64(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 64-bit word.
#define ERROR_COMMAND_SYNTAX_ERROR
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
enum esirisc_reg_num number
static uint16_t direction
#define LOG_TARGET_INFO(target, fmt_str,...)
#define LOG_TARGET_WARNING(target, fmt_str,...)
#define LOG_TARGET_USER(target, fmt_str,...)
#define LOG_TARGET_ERROR(target, fmt_str,...)
#define LOG_TARGET_DEBUG(target, fmt_str,...)
#define LOG_ERROR(expr ...)
struct reg * register_get_by_name(struct reg_cache *first, const char *name, bool search_all)
struct reg_cache ** register_get_last_cache_p(struct reg_cache **first)
struct rtt_control ctrl
Control block.
size_t size
Size of the control block search area.
Represents a generic ARM core, with standard application registers.
enum arm_core_type core_type
Indicates what registers are in the ARM state core register set.
enum arm_mode core_mode
Record the current core mode: SVC, USR, or some other mode.
struct reg * cpsr
Handle to the CPSR/xPSR; valid in all core modes.
struct reg * pc
Handle to the PC; valid in all core modes.
int(* write_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode, uint8_t *value)
int(* setup_semihosting)(struct target *target, int enable)
int(* read_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode)
Retrieve a single core register.
struct reg_cache * core_cache
enum arm_state core_state
Record the current core state: ARM, Thumb, or otherwise.
unsigned int common_magic
uint32_t context[ARMV7M_LAST_REG]
struct armv7m_trace_config trace_config
void(* pre_restore_context)(struct target *target)
unsigned int common_magic
int(* store_core_reg_u32)(struct target *target, uint32_t regsel, uint32_t value)
int(* load_core_reg_u32)(struct target *target, uint32_t regsel, uint32_t *value)
uint32_t itm_ter[8]
Bitmask of currently enabled ITM stimuli.
unsigned int trace_bus_id
Identifier for multi-source trace stream formatting.
int(* get)(struct reg *reg)
struct reg_feature * feature
struct reg_data_type * reg_data_type
const struct reg_arch_type * type
bool hit_fileio
A flag reporting whether semihosting fileio operation is active.
bool is_fileio
A flag reporting whether semihosting fileio is active.
bool is_active
A flag reporting whether semihosting is active.
struct semihosting * semihosting
enum target_debug_reason debug_reason
struct reg_cache * reg_cache
int target_halt(struct target *target)
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
uint32_t target_get_working_area_avail(struct target *target)
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
int target_read_u16(struct target *target, target_addr_t address, uint16_t *value)
const char * debug_reason_name(const struct target *t)
int target_wait_state(struct target *target, enum target_state state, unsigned int ms)
uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
int target_resume(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
Make the target (re)start executing using its saved execution context (possibly with some modificatio...
#define ERROR_TARGET_NOT_HALTED
#define ERROR_TARGET_INVALID
#define ERROR_TARGET_TIMEOUT
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
#define ERROR_TARGET_ALGO_EXIT
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.