Skip to content

Commit

Permalink
rtos/zephyr: arc: fetch the relinquish cause
Browse files Browse the repository at this point in the history
If a thread is preempted in an interrupt, we can read the caller-saved registers from its stack.

Signed-off-by: Bruno Mendes <bd_mendes@outlook.com>
  • Loading branch information
bdmendes committed Aug 3, 2023
1 parent d2da61b commit b186115
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/rtos/zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
/* ARC specific defines */
#define ARC_AUX_SEC_BUILD_REG 0xdb
#define ARC_REG_NUM 38
#define ARC_RELINQUISH_CAUSE_NONE 0
#define ARC_RELINQUISH_CAUSE_COOP 1
#define ARC_RELINQUISH_CAUSE_RIRQ 2
#define ARC_RELINQUISH_CAUSE_FIRQ 3

/* ARM specific defines */
#define ARM_XPSR_OFFSET 28
Expand Down Expand Up @@ -57,6 +61,8 @@ enum zephyr_offsets {
OFFSET_T_ARCH,
OFFSET_T_PREEMPT_FLOAT,
OFFSET_T_COOP_FLOAT,
OFFSET_T_ARM_EXC_RETURN,
OFFSET_T_ARC_RELINQUISH_CAUSE,
OFFSET_MAX
};

Expand Down Expand Up @@ -228,7 +234,6 @@ static struct stack_register_offset arc_cpu_saved_preempt[] = {
{ ARC_STATUS32, 4, 32 }
};


enum zephyr_symbol_values {
ZEPHYR_VAL__KERNEL,
ZEPHYR_VAL__KERNEL_OPENOCD_OFFSETS,
Expand Down Expand Up @@ -299,8 +304,8 @@ static int zephyr_get_arc_state(struct rtos *rtos, target_addr_t *addr,
if (retval != ERROR_OK)
return retval;

/* TODO check relinquish state and opt for coop or preempt */
stacking = params->cpu_saved_nofp_stacking_coop;
stacking = params->offsets[OFFSET_T_ARC_RELINQUISH_CAUSE] == ARC_RELINQUISH_CAUSE_RIRQ || ARC_RELINQUISH_CAUSE_FIRQ ?
params->cpu_saved_nofp_stacking_preempt : params->cpu_saved_nofp_stacking_coop;

/* Getting cpu saved registers into reg_list */
retval = rtos_generic_stack_read(rtos->target, stacking,
Expand Down Expand Up @@ -368,14 +373,9 @@ static int zephyr_get_arm_state(struct rtos *rtos, target_addr_t *addr,
callee_saved_reg_list[0].value);

if (params->offsets[OFFSET_T_PREEMPT_FLOAT] != UNIMPLEMENTED)
{
stacking = params->cpu_saved_fp_stacking;
}
else
{
/* TODO check relinquish state and opt for coop or preempt */
else
stacking = params->cpu_saved_nofp_stacking_coop;
}

retval = rtos_generic_stack_read(rtos->target, stacking, *addr, reg_list,
num_regs);
Expand Down Expand Up @@ -714,6 +714,7 @@ static int zephyr_update_threads(struct rtos *rtos)
}

if (rtos->symbols[ZEPHYR_VAL__KERNEL_OPENOCD_NUM_OFFSETS].address) {
/* use the number of offsets symbol issued by the kernel */
retval = target_read_u32(rtos->target,
rtos->symbols[ZEPHYR_VAL__KERNEL_OPENOCD_NUM_OFFSETS].address,
&param->num_offsets);
Expand All @@ -727,6 +728,7 @@ static int zephyr_update_threads(struct rtos *rtos)
return ERROR_FAIL;
}
} else {
/* hardcode the number of offsets based on the offsets version */
retval = target_read_u32(rtos->target,
rtos->symbols[ZEPHYR_VAL__KERNEL_OPENOCD_OFFSETS].address,
&param->offsets[OFFSET_VERSION]);
Expand All @@ -740,6 +742,7 @@ static int zephyr_update_threads(struct rtos *rtos)
param->offsets[OFFSET_VERSION]);
return ERROR_FAIL;
}

switch (param->offsets[OFFSET_VERSION]) {
case 0:
param->num_offsets = OFFSET_T_STACK_POINTER + 1;
Expand All @@ -749,6 +752,7 @@ static int zephyr_update_threads(struct rtos *rtos)
break;
}
}

/* We can fetch the whole array for version 0, as they're supposed
* to grow only */
uint32_t address;
Expand Down

0 comments on commit b186115

Please sign in to comment.