Trap handler context
A trap handler runs with supervisor privileges within the MPU context that combines the kernel and the task that installed the trap (trap installer task). Union of Protection Set 1 (kernel) and Protection Set 2 (task) is used to merge MPU settings of a trap installer task and kernel. If the installer task no longer exists, the trap is executed only in the kernel context. If there is a need to access the task context of a task that caused a trap, a user must ensure correct access rights. Otherwise, it may cause another MPU trap.
Context Save Area (CSA) structures are linked, and users can use them to get information about the execution state when a trap occurs. The csa argument passed to the function is the lower context of the last processed function. The upper context was previously stored by hardware, and accessing it through the lower context is possible. CSAs can be iterated so the user can back-track an execution flow of the application.
There is a flag for recognition if the pointer stored in PCXI (Previous Context Information — is part of both the lower and the upper CSA structure) points to lower or upper CSA. This flag bit is PCXI.UL.
if (csa->lower.PCXI.UL)
/* PCXI points to upper CSA */
else
/* PCXI points to lower CSA */
/* =========================== pxdef.h definition =========================== */
/* CSA block */
typedef union
{
TC_CSA_UPPER_T upper; /* < upper CSA block */
TC_CSA_LOWER_T lower; /* < lower CSA block */
} TC_CSA_t;
/******************************************************************************/
//! get the absolute pointer to the csa
static inline __attribute__((always_inline)) TC_CSA_t *CSA2PTR(PxPCXI_t csa)
{
TC_CSA_t *pcsa;
__asm__ volatile (
"sha.h %0, %1, 12\n\t" // shift segment into bit 28-31
"insert %0, %0, %1, 6,16" // move offset into bits 0-22
: "=&d" (pcsa) : "d" (csa) );
return pcsa;
}
/* ======================== trap handler definition ======================== */
/* Class 1 (MPU) trap handler */
PxBool_t Trap_Hdn_01(..., TC_CSA_t *csa)
{
TC_CSA_t *csa_upper = CSA2PTR(csa->lower.PCXI);
...