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--) {
203 static char enamebuf[32];
206 return "Invalid exception";
209 sprintf(enamebuf,
"External Interrupt(%i)",
number - 16);
245 switch (arm_reg_id) {
276 LOG_ERROR(
"Bad register ID %u", arm_reg_id);
282 unsigned int *reg32_id, uint32_t *
offset)
285 switch (arm_reg_id) {
314 assert(num == (
int)r->
number);
324 unsigned int reg32_id;
347 assert(r->
size == 32 || r->
size == 64);
385 assert(num == (
int)r->
number);
387 if (value != r->
value) {
395 unsigned int reg32_id;
419 assert(r->
size == 32 || r->
size == 64);
467 *reg_list = malloc(
sizeof(
struct reg *) *
size);
471 for (i = 0; i <
size; i++)
474 *reg_list_size =
size;
481 int num_mem_params,
struct mem_param *mem_params,
482 int num_reg_params,
struct reg_param *reg_params,
484 int timeout_ms,
void *arch_info)
489 num_mem_params, mem_params,
490 num_reg_params, reg_params,
491 entry_point, exit_point,
496 num_mem_params, mem_params,
497 num_reg_params, reg_params,
498 exit_point, timeout_ms,
506 int num_mem_params,
struct mem_param *mem_params,
507 int num_reg_params,
struct reg_param *reg_params,
520 LOG_ERROR(
"current target isn't an ARMV7M target");
544 for (
int i = 0; i < num_mem_params; i++) {
549 mem_params[i].
value);
554 for (
int i = 0; i < num_reg_params; i++) {
563 LOG_ERROR(
"BUG: register '%s' not found", reg_params[i].reg_name);
568 LOG_ERROR(
"BUG: register '%s' size doesn't match reg_params[i].size",
569 reg_params[i].reg_name);
595 armv7m_algorithm_info->
core_mode != core_mode) {
600 LOG_INFO(
"ARM_MODE_HANDLER not currently supported, using ARM_MODE_THREAD instead");
611 armv7m_algorithm_info->
core_mode = core_mode;
620 int num_mem_params,
struct mem_param *mem_params,
621 int num_reg_params,
struct reg_param *reg_params,
633 LOG_ERROR(
"current target isn't an ARMV7M target");
652 if (pc != exit_point) {
660 for (
int i = 0; i < num_mem_params; i++) {
664 mem_params[i].value);
671 for (
int i = 0; i < num_reg_params; i++) {
678 LOG_ERROR(
"BUG: register '%s' not found", reg_params[i].reg_name);
684 "BUG: register '%s' size doesn't match reg_params[i].size",
685 reg_params[i].reg_name);
700 if (regvalue != armv7m_algorithm_info->
context[i]) {
701 LOG_DEBUG(
"restoring register %s with value 0x%8.8" PRIx32,
704 0, 32, armv7m_algorithm_info->
context[i]);
738 LOG_USER(
"[%s] halted due to %s, current mode: %s %s\n"
739 "xPSR: %#8.8" PRIx32
" pc: %#8.8" PRIx32
" %csp: %#8.8" PRIx32
"%s%s",
746 (
ctrl & 0x02) ?
'p' :
'm',
767 struct reg *reg_list = calloc(num_regs,
sizeof(
struct reg));
768 struct arm_reg *arch_info = calloc(num_regs,
sizeof(
struct arm_reg));
773 cache->
name =
"arm v7m registers";
779 for (i = 0; i < num_regs; i++) {
787 reg_list[i].
dirty =
false;
788 reg_list[i].
valid =
false;
796 reg_list[i].
exist =
true;
799 if (reg_list[i].hidden)
807 LOG_ERROR(
"unable to allocate feature list");
813 LOG_ERROR(
"unable to allocate reg type list");
836 for (i = 0; i < cache->
num_regs; i++) {
887 static const uint8_t cortex_m_crc_code[] = {
888 #include "../../contrib/loaders/checksum/armv7m_crc.inc"
896 sizeof(cortex_m_crc_code), (uint8_t *)cortex_m_crc_code);
912 crc_algorithm->
address + (
sizeof(cortex_m_crc_code) - 6),
918 LOG_ERROR(
"error executing cortex_m crc algorithm");
939 static bool timed_out;
941 static const uint8_t erase_check_code[] = {
942 #include "../../contrib/loaders/erase_check/armv7m_erase_check.inc"
945 const uint32_t code_size =
sizeof(erase_check_code);
949 &erase_check_algorithm) !=
ERROR_OK)
953 code_size, erase_check_code);
967 int blocks_to_check = avail /
sizeof(
struct algo_block) - 1;
968 if (num_blocks < blocks_to_check)
969 blocks_to_check = num_blocks;
971 struct algo_block *params = malloc((blocks_to_check+1)*
sizeof(
struct algo_block));
978 uint32_t total_size = 0;
979 for (i = 0; i < blocks_to_check; i++) {
980 total_size += blocks[i].
size;
982 blocks[i].
size /
sizeof(uint32_t));
988 uint32_t param_size = (blocks_to_check + 1) *
sizeof(
struct algo_block);
996 param_size, (uint8_t *)params);
1000 uint32_t erased_word = erased_value | (erased_value << 8)
1001 | (erased_value << 16) | (erased_value << 24);
1003 LOG_DEBUG(
"Starting erase check of %d blocks, parameters@"
1013 buf_set_u32(reg_params[1].value, 0, 32, erased_word);
1016 int timeout = (timed_out ? 30000 : 2000) + total_size * 3 / 1000;
1021 erase_check_algorithm->
address,
1022 erase_check_algorithm->
address + (code_size - 2),
1027 if (retval !=
ERROR_OK && !timed_out)
1031 param_size, (uint8_t *)params);
1035 for (i = 0; i < blocks_to_check; i++) {
1037 (uint8_t *)&(params[i].result));
1038 if (result != 0 && result != 1)
1041 blocks[i].
result = result;
1044 LOG_INFO(
"Slow CPU clock: %d blocks checked, %d remain. Continuing...", i, num_blocks-i);
1066 bool result =
false;
1079 if ((
op & 0xFF00) == 0xBE00) {
1085 LOG_DEBUG(
"Skipping over BKPT instruction");
1091 *inst_found = result;
1100 .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.
const char * arm_mode_name(unsigned psr_mode)
Map PSR mode bits to the name of an ARM processor operating mode.
static struct arm * target_to_arm(struct target *target)
Convert target handle to generic ARM target state handle.
int arm_init_arch_info(struct target *target, struct arm *arm)
@ 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 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_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, int timeout_ms, void *arch_info)
Waits for an 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.
bool armv7m_map_reg_packing(unsigned int arm_reg_id, unsigned int *reg32_id, uint32_t *offset)
static const struct @74 armv7m_regs[]
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.
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, int timeout_ms, void *arch_info)
Runs 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_REGSEL_PMSK_BPRI_FLTMSK_CTRL_S
@ ARMV7M_REGSEL_PMSK_BPRI_FLTMSK_CTRL
@ ARMV8M_REGSEL_PMSK_BPRI_FLTMSK_CTRL_NS
@ ARMV8M_PMSK_BPRI_FLTMSK_CTRL_NS
@ ARMV7M_PMSK_BPRI_FLTMSK_CTRL
@ ARMV8M_PMSK_BPRI_FLTMSK_CTRL_S
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 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 first, unsigned 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 first, unsigned 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 first, unsigned 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_WARNING(expr ...)
#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)
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_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, int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
int target_read_u16(struct target *target, target_addr_t address, uint16_t *value)
uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
const char * debug_reason_name(struct target *t)
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...
int target_wait_state(struct target *target, enum target_state state, int ms)
#define ERROR_TARGET_NOT_HALTED
#define ERROR_TARGET_INVALID
static const char * target_name(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.