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,
523 LOG_ERROR(
"current target isn't an ARMV7M target");
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++) {
566 LOG_ERROR(
"BUG: register '%s' not found", reg_params[i].reg_name);
571 LOG_ERROR(
"BUG: register '%s' size doesn't match reg_params[i].size",
572 reg_params[i].reg_name);
598 armv7m_algorithm_info->
core_mode != core_mode) {
603 LOG_INFO(
"ARM_MODE_HANDLER not currently supported, using ARM_MODE_THREAD instead");
614 armv7m_algorithm_info->
core_mode = core_mode;
623 int num_mem_params,
struct mem_param *mem_params,
624 int num_reg_params,
struct reg_param *reg_params,
636 LOG_ERROR(
"current target isn't an ARMV7M target");
655 if (pc != exit_point) {
663 for (
int i = 0; i < num_mem_params; i++) {
667 mem_params[i].value);
674 for (
int i = 0; i < num_reg_params; i++) {
681 LOG_ERROR(
"BUG: register '%s' not found", reg_params[i].reg_name);
687 "BUG: register '%s' size doesn't match reg_params[i].size",
688 reg_params[i].reg_name);
703 if (regvalue != armv7m_algorithm_info->
context[i]) {
704 LOG_DEBUG(
"restoring register %s with value 0x%8.8" PRIx32,
707 0, 32, armv7m_algorithm_info->
context[i]);
741 LOG_USER(
"[%s] halted due to %s, current mode: %s %s\n"
742 "xPSR: %#8.8" PRIx32
" pc: %#8.8" PRIx32
" %csp: %#8.8" PRIx32
"%s%s",
749 (
ctrl & 0x02) ?
'p' :
'm',
770 struct reg *reg_list = calloc(num_regs,
sizeof(
struct reg));
771 struct arm_reg *arch_info = calloc(num_regs,
sizeof(
struct arm_reg));
776 cache->
name =
"arm v7m registers";
782 for (i = 0; i < num_regs; i++) {
790 reg_list[i].
dirty =
false;
791 reg_list[i].
valid =
false;
799 reg_list[i].
exist =
true;
802 if (reg_list[i].hidden)
810 LOG_ERROR(
"unable to allocate feature list");
816 LOG_ERROR(
"unable to allocate reg type list");
839 for (i = 0; i < cache->
num_regs; i++) {
890 static const uint8_t cortex_m_crc_code[] = {
891 #include "../../contrib/loaders/checksum/armv7m_crc.inc"
899 sizeof(cortex_m_crc_code), (uint8_t *)cortex_m_crc_code);
912 unsigned int timeout = 20000 * (1 + (
count / (1024 * 1024)));
915 crc_algorithm->
address + (
sizeof(cortex_m_crc_code) - 6),
921 LOG_ERROR(
"error executing cortex_m crc algorithm");
942 static bool timed_out;
944 static const uint8_t erase_check_code[] = {
945 #include "../../contrib/loaders/erase_check/armv7m_erase_check.inc"
948 const uint32_t code_size =
sizeof(erase_check_code);
952 &erase_check_algorithm) !=
ERROR_OK)
956 code_size, erase_check_code);
970 int blocks_to_check = avail /
sizeof(
struct algo_block) - 1;
971 if (num_blocks < blocks_to_check)
972 blocks_to_check = num_blocks;
974 struct algo_block *params = malloc((blocks_to_check+1)*
sizeof(
struct algo_block));
981 uint32_t total_size = 0;
982 for (i = 0; i < blocks_to_check; i++) {
983 total_size += blocks[i].
size;
985 blocks[i].
size /
sizeof(uint32_t));
991 uint32_t param_size = (blocks_to_check + 1) *
sizeof(
struct algo_block);
999 param_size, (uint8_t *)params);
1003 uint32_t erased_word = erased_value | (erased_value << 8)
1004 | (erased_value << 16) | (erased_value << 24);
1006 LOG_DEBUG(
"Starting erase check of %d blocks, parameters@"
1016 buf_set_u32(reg_params[1].value, 0, 32, erased_word);
1019 unsigned int timeout = (timed_out ? 30000 : 2000) + total_size * 3 / 1000;
1024 erase_check_algorithm->
address,
1025 erase_check_algorithm->
address + (code_size - 2),
1030 if (retval !=
ERROR_OK && !timed_out)
1034 param_size, (uint8_t *)params);
1038 for (i = 0; i < blocks_to_check; i++) {
1040 (uint8_t *)&(params[i].result));
1041 if (result != 0 && result != 1)
1044 blocks[i].
result = result;
1047 LOG_INFO(
"Slow CPU clock: %d blocks checked, %d remain. Continuing...", i, num_blocks-i);
1069 bool result =
false;
1082 if ((
op & 0xFF00) == 0xBE00) {
1088 LOG_DEBUG(
"Skipping over BKPT instruction");
1094 *inst_found = result;
1103 .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_USER(expr ...)
#define LOG_TARGET_WARNING(target, fmt_str,...)
#define LOG_TARGET_ERROR(target, fmt_str,...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(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
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
#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.