OpenOCD
cortex_m.c File Reference
Include dependency graph for cortex_m.c:

Go to the source code of this file.

Data Structures

struct  dwt_reg
 
struct  dwt_reg_state
 

Macros

#define DHCSR_S_REGRDY_TIMEOUT   (500)
 
#define DWT_COMPARATOR(i)
 
#define MVFR0   0xE000EF40
 
#define MVFR0_DP   0x00000200
 
#define MVFR0_DP_MASK   0x00000F00
 
#define MVFR0_SP   0x00000020
 
#define MVFR0_SP_MASK   0x000000F0
 
#define MVFR1   0xE000EF44
 
#define MVFR1_MVE_F   0x00000200
 
#define MVFR1_MVE_I   0x00000100
 
#define MVFR1_MVE_MASK   0x00000F00
 

Functions

 COMMAND_HANDLER (handle_cortex_m_mask_interrupts_command)
 
 COMMAND_HANDLER (handle_cortex_m_reset_config_command)
 
 COMMAND_HANDLER (handle_cortex_m_vector_catch_command)
 
int cortex_m_add_breakpoint (struct target *target, struct breakpoint *breakpoint)
 
int cortex_m_add_watchpoint (struct target *target, struct watchpoint *watchpoint)
 
static int cortex_m_assert_reset (struct target *target)
 
static int cortex_m_clear_halt (struct target *target)
 
static void cortex_m_cumulate_dhcsr_sticky (struct cortex_m_common *cortex_m, uint32_t dhcsr)
 DCB DHCSR register contains S_RETIRE_ST and S_RESET_ST bits cleared on a read. More...
 
static int cortex_m_dcc_read (struct target *target, uint8_t *value, uint8_t *ctrl)
 
static int cortex_m_deassert_reset (struct target *target)
 
static int cortex_m_debug_entry (struct target *target)
 
void cortex_m_deinit_target (struct target *target)
 
static void cortex_m_dwt_addreg (struct target *t, struct reg *r, const struct dwt_reg *d)
 
static void cortex_m_dwt_free (struct target *target)
 
static int cortex_m_dwt_get_reg (struct reg *reg)
 
static int cortex_m_dwt_set_reg (struct reg *reg, uint8_t *buf)
 
static void cortex_m_dwt_setup (struct cortex_m_common *cm, struct target *target)
 
void cortex_m_enable_breakpoints (struct target *target)
 
static int cortex_m_enable_fpb (struct target *target)
 
void cortex_m_enable_watchpoints (struct target *target)
 
static int cortex_m_endreset_event (struct target *target)
 
int cortex_m_examine (struct target *target)
 
static int cortex_m_examine_debug_reason (struct target *target)
 
static int cortex_m_examine_exception_reason (struct target *target)
 
static int cortex_m_fast_read_all_regs (struct target *target)
 
static int cortex_m_find_mem_ap (struct adiv5_dap *swjdp, struct adiv5_ap **debug_ap)
 
static int cortex_m_halt (struct target *target)
 
static int cortex_m_halt_one (struct target *target)
 
static int cortex_m_handle_target_request (void *priv)
 
static bool cortex_m_has_tz (struct target *target)
 
static int cortex_m_hit_watchpoint (struct target *target, struct watchpoint **hit_watchpoint)
 
static int cortex_m_init_arch_info (struct target *target, struct cortex_m_common *cortex_m, struct adiv5_dap *dap)
 
static int cortex_m_init_target (struct command_context *cmd_ctx, struct target *target)
 
static int cortex_m_load_core_reg_u32 (struct target *target, uint32_t regsel, uint32_t *value)
 
static int cortex_m_poll (struct target *target)
 
static int cortex_m_poll_one (struct target *target)
 
static int cortex_m_poll_smp (struct list_head *smp_targets)
 
int cortex_m_profiling (struct target *target, uint32_t *samples, uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
 
static int cortex_m_queue_reg_read (struct target *target, uint32_t regsel, uint32_t *reg_value, uint32_t *dhcsr)
 
static int cortex_m_read_dhcsr_atomic_sticky (struct target *target)
 Read DCB DHCSR register to cortex_m->dcb_dhcsr and cumulate sticky bits in cortex_m->dcb_dhcsr_cumulated_sticky. More...
 
static int cortex_m_read_memory (struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
 
int cortex_m_remove_breakpoint (struct target *target, struct breakpoint *breakpoint)
 
int cortex_m_remove_watchpoint (struct target *target, struct watchpoint *watchpoint)
 
static int cortex_m_restart_one (struct target *target, bool debug_execution)
 
static int cortex_m_restore_one (struct target *target, bool current, target_addr_t *address, bool handle_breakpoints, bool debug_execution)
 
static int cortex_m_restore_smp (struct target *target, bool handle_breakpoints)
 
static int cortex_m_resume (struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
 
int cortex_m_set_breakpoint (struct target *target, struct breakpoint *breakpoint)
 
static int cortex_m_set_maskints (struct target *target, bool mask)
 
static int cortex_m_set_maskints_for_halt (struct target *target)
 
static int cortex_m_set_maskints_for_run (struct target *target)
 
static int cortex_m_set_maskints_for_step (struct target *target)
 
static int cortex_m_set_watchpoint (struct target *target, struct watchpoint *watchpoint)
 
static int cortex_m_single_step_core (struct target *target)
 
static int cortex_m_slow_read_all_regs (struct target *target)
 
static int cortex_m_smp_halt_all (struct list_head *smp_targets)
 
static int cortex_m_smp_post_halt_poll (struct list_head *smp_targets)
 
static int cortex_m_soft_reset_halt (struct target *target)
 
static int cortex_m_step (struct target *target, int current, target_addr_t address, int handle_breakpoints)
 
static int cortex_m_store_core_reg_u32 (struct target *target, uint32_t num, uint32_t value)
 
static int cortex_m_target_create (struct target *target, Jim_Interp *interp)
 
static int cortex_m_target_request_data (struct target *target, uint32_t size, uint8_t *buffer)
 
int cortex_m_unset_breakpoint (struct target *target, struct breakpoint *breakpoint)
 
static int cortex_m_unset_watchpoint (struct target *target, struct watchpoint *watchpoint)
 
static int cortex_m_verify_pointer (struct command_invocation *cmd, struct cortex_m_common *cm)
 
static int cortex_m_write_debug_halt_mask (struct target *target, uint32_t mask_on, uint32_t mask_off)
 
static int cortex_m_write_memory (struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
 

Variables

static const struct command_registration cortex_m_command_handlers []
 
static const struct command_registration cortex_m_exec_command_handlers []
 
static const struct cortex_m_part_info cortex_m_parts []
 
struct target_type cortexm_target
 
static const struct dwt_reg dwt_base_regs []
 
static const struct dwt_reg dwt_comp []
 
static const struct reg_arch_type dwt_reg_type
 

Macro Definition Documentation

◆ DHCSR_S_REGRDY_TIMEOUT

#define DHCSR_S_REGRDY_TIMEOUT   (500)

Definition at line 48 of file cortex_m.c.

◆ DWT_COMPARATOR

#define DWT_COMPARATOR (   i)
Value:
{ DWT_COMP0 + 0x10 * (i), "dwt_" #i "_comp", 32, }, \
{ DWT_MASK0 + 0x10 * (i), "dwt_" #i "_mask", 4, }, \
{ DWT_FUNCTION0 + 0x10 * (i), "dwt_" #i "_function", 32, }
#define DWT_FUNCTION0
Definition: cortex_m.h:94
#define DWT_MASK0
Definition: cortex_m.h:93
#define DWT_COMP0
Definition: cortex_m.h:92

◆ MVFR0

#define MVFR0   0xE000EF40

Definition at line 2467 of file cortex_m.c.

◆ MVFR0_DP

#define MVFR0_DP   0x00000200

Definition at line 2471 of file cortex_m.c.

◆ MVFR0_DP_MASK

#define MVFR0_DP_MASK   0x00000F00

Definition at line 2470 of file cortex_m.c.

◆ MVFR0_SP

#define MVFR0_SP   0x00000020

Definition at line 2469 of file cortex_m.c.

◆ MVFR0_SP_MASK

#define MVFR0_SP_MASK   0x000000F0

Definition at line 2468 of file cortex_m.c.

◆ MVFR1

#define MVFR1   0xE000EF44

Definition at line 2473 of file cortex_m.c.

◆ MVFR1_MVE_F

#define MVFR1_MVE_F   0x00000200

Definition at line 2476 of file cortex_m.c.

◆ MVFR1_MVE_I

#define MVFR1_MVE_I   0x00000100

Definition at line 2475 of file cortex_m.c.

◆ MVFR1_MVE_MASK

#define MVFR1_MVE_MASK   0x00000F00

Definition at line 2474 of file cortex_m.c.

Function Documentation

◆ COMMAND_HANDLER() [1/3]

◆ COMMAND_HANDLER() [2/3]

◆ COMMAND_HANDLER() [3/3]

◆ cortex_m_add_breakpoint()

int cortex_m_add_breakpoint ( struct target target,
struct breakpoint breakpoint 
)

◆ cortex_m_add_watchpoint()

◆ cortex_m_assert_reset()

◆ cortex_m_clear_halt()

◆ cortex_m_cumulate_dhcsr_sticky()

static void cortex_m_cumulate_dhcsr_sticky ( struct cortex_m_common cortex_m,
uint32_t  dhcsr 
)
inlinestatic

DCB DHCSR register contains S_RETIRE_ST and S_RESET_ST bits cleared on a read.

Call this helper function each time DHCSR is read to preserve S_RESET_ST state in case of a reset event was detected.

Definition at line 147 of file cortex_m.c.

References cortex_m_common::dcb_dhcsr_cumulated_sticky.

Referenced by cortex_m_examine(), cortex_m_fast_read_all_regs(), cortex_m_load_core_reg_u32(), and cortex_m_read_dhcsr_atomic_sticky().

◆ cortex_m_dcc_read()

static int cortex_m_dcc_read ( struct target target,
uint8_t *  value,
uint8_t *  ctrl 
)
static

◆ cortex_m_deassert_reset()

◆ cortex_m_debug_entry()

◆ cortex_m_deinit_target()

◆ cortex_m_dwt_addreg()

static void cortex_m_dwt_addreg ( struct target t,
struct reg r,
const struct dwt_reg d 
)
static

◆ cortex_m_dwt_free()

◆ cortex_m_dwt_get_reg()

static int cortex_m_dwt_get_reg ( struct reg reg)
static

Definition at line 2274 of file cortex_m.c.

References reg::arch_info, buf_set_u32(), ERROR_OK, state, and target_read_u32().

◆ cortex_m_dwt_set_reg()

static int cortex_m_dwt_set_reg ( struct reg reg,
uint8_t *  buf 
)
static

Definition at line 2287 of file cortex_m.c.

References reg::arch_info, buf_get_u32(), reg::size, state, and target_write_u32().

◆ cortex_m_dwt_setup()

◆ cortex_m_enable_breakpoints()

void cortex_m_enable_breakpoints ( struct target target)

◆ cortex_m_enable_fpb()

static int cortex_m_enable_fpb ( struct target target)
static

◆ cortex_m_enable_watchpoints()

void cortex_m_enable_watchpoints ( struct target target)

◆ cortex_m_endreset_event()

◆ cortex_m_examine()

int cortex_m_examine ( struct target target)

Definition at line 2487 of file cortex_m.c.

References cortex_m_common::apsel, arm::arch, cortex_m_part_info::arch, armv7m_common::arm, ARM_ARCH_V7M, ARM_CPUID_IMPLEMENTOR_MASK, ARM_CPUID_PARTNO_MASK, cortex_m_common::armv7m, ARMV7M_FPU_FIRST_REG, ARMV7M_FPU_LAST_REG, armv7m_trace_itm_config(), ARMV8M_FIRST_REG, ARMV8M_LAST_REG, ARRAY_SIZE, C_DEBUGEN, C_HALT, C_MASKINTS, C_STEP, arm::core_cache, cortex_m_common::core_info, CORTEX_M7_PARTNO, cortex_m_cumulate_dhcsr_sticky(), cortex_m_dwt_free(), cortex_m_dwt_setup(), CORTEX_M_F_HAS_FPV4, CORTEX_M_F_HAS_FPV5, CORTEX_M_F_TAR_AUTOINCR_BLOCK_4K, cortex_m_find_mem_ap(), cortex_m_has_tz(), cortex_m_parts, CPUID, arm::dap, dap_get_ap(), DBGKEY, DCB_DEMCR, DCB_DHCSR, cortex_m_common::dcb_dhcsr, cortex_m_common::dcb_dhcsr_sticky_is_recent, armv7m_common::debug_ap, armv7m_common::demcr, DP_APSEL_INVALID, cortex_m_common::dwt_num_comp, ERROR_FAIL, ERROR_OK, reg::exist, cortex_m_part_info::flags, FP_COMP0, cortex_m_common::fp_comparator_list, FP_CTRL, armv7m_common::fp_feature, FP_NONE, cortex_m_common::fp_num_code, cortex_m_common::fp_num_lit, cortex_m_common::fp_rev, cortex_m_common::fpb_enabled, cortex_m_fp_comparator::fpcr_address, FPCR_CODE, FPCR_LITERAL, FPV4_SP, FPV5_DP, FPV5_MVE_F, FPV5_MVE_I, FPV5_SP, armv7m_common::is_hla_target, armv7m_trace_config::itm_deferred_config, LOG_ERROR, LOG_TARGET_DEBUG, LOG_TARGET_ERROR, LOG_TARGET_INFO, LOG_TARGET_WARNING, cortex_m_common::maskints_erratum, mem_ap_init(), adiv5_ap::memaccess_tck, MVFR0, MVFR0_DP, MVFR0_DP_MASK, MVFR0_SP, MVFR0_SP_MASK, MVFR1, MVFR1_MVE_F, MVFR1_MVE_I, MVFR1_MVE_MASK, cortex_m_part_info::name, reg_cache::reg_list, S_RESET_ST, adiv5_ap::tar_autoincr_block, target_read_u32(), target_set_examined(), target_to_armv7m(), target_to_cm(), target_was_examined(), target_write_u32(), armv7m_common::trace_config, TRCENA, cortex_m_fp_comparator::type, and cortex_m_common::vectreset_supported.

◆ cortex_m_examine_debug_reason()

◆ cortex_m_examine_exception_reason()

◆ cortex_m_fast_read_all_regs()

◆ cortex_m_find_mem_ap()

static int cortex_m_find_mem_ap ( struct adiv5_dap swjdp,
struct adiv5_ap **  debug_ap 
)
static

◆ cortex_m_halt()

static int cortex_m_halt ( struct target target)
static

◆ cortex_m_halt_one()

◆ cortex_m_handle_target_request()

static int cortex_m_handle_target_request ( void *  priv)
static

◆ cortex_m_has_tz()

static bool cortex_m_has_tz ( struct target target)
static

◆ cortex_m_hit_watchpoint()

static int cortex_m_hit_watchpoint ( struct target target,
struct watchpoint **  hit_watchpoint 
)
static

◆ cortex_m_init_arch_info()

◆ cortex_m_init_target()

static int cortex_m_init_target ( struct command_context cmd_ctx,
struct target target 
)
static

Definition at line 2171 of file cortex_m.c.

References arm_semihosting_init(), armv7m_build_reg_cache(), and ERROR_OK.

◆ cortex_m_load_core_reg_u32()

◆ cortex_m_poll()

static int cortex_m_poll ( struct target target)
static

◆ cortex_m_poll_one()

◆ cortex_m_poll_smp()

◆ cortex_m_profiling()

int cortex_m_profiling ( struct target target,
uint32_t *  samples,
uint32_t  max_num_samples,
uint32_t *  num_samples,
uint32_t  seconds 
)

◆ cortex_m_queue_reg_read()

static int cortex_m_queue_reg_read ( struct target target,
uint32_t  regsel,
uint32_t *  reg_value,
uint32_t *  dhcsr 
)
static

◆ cortex_m_read_dhcsr_atomic_sticky()

static int cortex_m_read_dhcsr_atomic_sticky ( struct target target)
static

◆ cortex_m_read_memory()

static int cortex_m_read_memory ( struct target target,
target_addr_t  address,
uint32_t  size,
uint32_t  count,
uint8_t *  buffer 
)
static

◆ cortex_m_remove_breakpoint()

int cortex_m_remove_breakpoint ( struct target target,
struct breakpoint breakpoint 
)

Definition at line 1915 of file cortex_m.c.

References cortex_m_unset_breakpoint(), ERROR_OK, and breakpoint::is_set.

◆ cortex_m_remove_watchpoint()

int cortex_m_remove_watchpoint ( struct target target,
struct watchpoint watchpoint 
)

◆ cortex_m_restart_one()

◆ cortex_m_restore_one()

◆ cortex_m_restore_smp()

static int cortex_m_restore_smp ( struct target target,
bool  handle_breakpoints 
)
static

◆ cortex_m_resume()

static int cortex_m_resume ( struct target target,
int  current,
target_addr_t  address,
int  handle_breakpoints,
int  debug_execution 
)
static

◆ cortex_m_set_breakpoint()

◆ cortex_m_set_maskints()

static int cortex_m_set_maskints ( struct target target,
bool  mask 
)
static

◆ cortex_m_set_maskints_for_halt()

◆ cortex_m_set_maskints_for_run()

◆ cortex_m_set_maskints_for_step()

static int cortex_m_set_maskints_for_step ( struct target target)
static

◆ cortex_m_set_watchpoint()

◆ cortex_m_single_step_core()

static int cortex_m_single_step_core ( struct target target)
static

◆ cortex_m_slow_read_all_regs()

◆ cortex_m_smp_halt_all()

static int cortex_m_smp_halt_all ( struct list_head smp_targets)
static

◆ cortex_m_smp_post_halt_poll()

static int cortex_m_smp_post_halt_poll ( struct list_head smp_targets)
static

◆ cortex_m_soft_reset_halt()

◆ cortex_m_step()

◆ cortex_m_store_core_reg_u32()

◆ cortex_m_target_create()

◆ cortex_m_target_request_data()

static int cortex_m_target_request_data ( struct target target,
uint32_t  size,
uint8_t *  buffer 
)
static

Definition at line 2725 of file cortex_m.c.

References buffer, cortex_m_dcc_read(), ctrl, ERROR_OK, and size.

◆ cortex_m_unset_breakpoint()

◆ cortex_m_unset_watchpoint()

◆ cortex_m_verify_pointer()

static int cortex_m_verify_pointer ( struct command_invocation cmd,
struct cortex_m_common cm 
)
static

Definition at line 2832 of file cortex_m.c.

References cmd, command_print(), ERROR_OK, ERROR_TARGET_INVALID, and is_cortex_m_with_dap_access().

Referenced by COMMAND_HANDLER().

◆ cortex_m_write_debug_halt_mask()

◆ cortex_m_write_memory()

static int cortex_m_write_memory ( struct target target,
target_addr_t  address,
uint32_t  size,
uint32_t  count,
const uint8_t *  buffer 
)
static

Variable Documentation

◆ cortex_m_command_handlers

const struct command_registration cortex_m_command_handlers[]
static
Initial value:
= {
{
},
{
},
{
},
{
.name = "cortex_m",
.mode = COMMAND_EXEC,
.help = "Cortex-M command group",
.usage = "",
},
{
},
}
const struct command_registration arm_tpiu_deprecated_command_handlers[]
const struct command_registration armv7m_command_handlers[]
Definition: armv7m.c:1099
const struct command_registration armv7m_trace_command_handlers[]
Definition: armv7m_trace.c:140
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_EXEC
Definition: command.h:40
static const struct command_registration cortex_m_exec_command_handlers[]
Definition: cortex_m.c:3020
const struct command_registration rtt_target_command_handlers[]
Definition: rtt/tcl.c:261
const char * name
Definition: command.h:235
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
Definition: command.h:249

Definition at line 2975 of file cortex_m.c.

◆ cortex_m_exec_command_handlers

const struct command_registration cortex_m_exec_command_handlers[]
static
Initial value:
= {
{
.name = "maskisr",
.handler = handle_cortex_m_mask_interrupts_command,
.mode = COMMAND_EXEC,
.help = "mask cortex_m interrupts",
.usage = "['auto'|'on'|'off'|'steponly']",
},
{
.name = "vector_catch",
.handler = handle_cortex_m_vector_catch_command,
.mode = COMMAND_EXEC,
.help = "configure hardware vectors to trigger debug entry",
.usage = "['all'|'none'|('bus_err'|'chk_err'|...)*]",
},
{
.name = "reset_config",
.handler = handle_cortex_m_reset_config_command,
.mode = COMMAND_ANY,
.help = "configure software reset handling",
.usage = "['sysresetreq'|'vectreset']",
},
{
},
}
@ COMMAND_ANY
Definition: command.h:42
const struct command_registration smp_command_handlers[]
Definition: smp.c:153

Definition at line 2975 of file cortex_m.c.

◆ cortex_m_parts

const struct cortex_m_part_info cortex_m_parts[]
static

Definition at line 1 of file cortex_m.c.

Referenced by cortex_m_examine().

◆ cortexm_target

struct target_type cortexm_target

Definition at line 2975 of file cortex_m.c.

◆ dwt_base_regs

const struct dwt_reg dwt_base_regs[]
static
Initial value:
= {
{ DWT_CTRL, "dwt_ctrl", 32, },
{ DWT_CYCCNT, "dwt_cyccnt", 32, },
}
#define DWT_CYCCNT
Definition: cortex_m.h:90
#define DWT_CTRL
Definition: cortex_m.h:89

Definition at line 2287 of file cortex_m.c.

Referenced by cortex_m_dwt_setup().

◆ dwt_comp

const struct dwt_reg dwt_comp[]
static
Initial value:

Definition at line 2287 of file cortex_m.c.

Referenced by cortex_m_dwt_setup().

◆ dwt_reg_type

const struct reg_arch_type dwt_reg_type
static
Initial value:
= {
}
static int cortex_m_dwt_get_reg(struct reg *reg)
Definition: cortex_m.c:2274
static int cortex_m_dwt_set_reg(struct reg *reg, uint8_t *buf)
Definition: cortex_m.c:2287

Definition at line 2287 of file cortex_m.c.

Referenced by cortex_m_dwt_addreg().