Removed obsolete sandbox code from ARMv7-M port.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15805 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2022-09-28 12:18:29 +00:00
parent 608e5c5614
commit bff25edf36
5 changed files with 18 additions and 357 deletions

View File

@ -106,6 +106,7 @@ include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk
# RTOS files (optional). # RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMv7-M-ALT/compilers/GCC/mk/port.mk include $(CHIBIOS)/os/common/ports/ARMv7-M-ALT/compilers/GCC/mk/port.mk
#include $(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC/mk/port.mk
# Auto-build files in ./source recursively. # Auto-build files in ./source recursively.
include $(CHIBIOS)/tools/mk/autobuild.mk include $(CHIBIOS)/tools/mk/autobuild.mk
# Other files (optional). # Other files (optional).

View File

@ -53,65 +53,6 @@
/* Module interrupt handlers. */ /* Module interrupt handlers. */
/*===========================================================================*/ /*===========================================================================*/
#if (PORT_USE_SYSCALL == TRUE) || defined(__DOXYGEN__)
__attribute__((noinline))
void port_syslock_noinline(void) {
port_lock();
__stats_start_measure_crit_thd();
__dbg_check_lock();
}
uint32_t port_get_s_psp(void) {
return (uint32_t)__sch_get_currthread()->ctx.syscall.psp;
}
__attribute__((weak))
void port_syscall(struct port_extctx *ctxp, uint32_t n) {
(void)ctxp;
(void)n;
chSysHalt("svc");
}
void port_unprivileged_jump(uint32_t pc, uint32_t psp) {
struct port_extctx *ectxp;
struct port_linkctx *lctxp;
uint32_t s_psp = __get_PSP();
uint32_t control = __get_CONTROL();
/* Creating a port_extctx context for user mode entry.*/
psp -= sizeof (struct port_extctx);
ectxp = (struct port_extctx *)psp;
/* Initializing the user mode entry context.*/
memset((void *)ectxp, 0, sizeof (struct port_extctx));
ectxp->pc = pc;
ectxp->xpsr = 0x01000000U;
#if CORTEX_USE_FPU == TRUE
ectxp->fpscr = __get_FPSCR();
#endif
/* Creating a middle context for user mode entry.*/
s_psp -= sizeof (struct port_linkctx);
lctxp = (struct port_linkctx *)s_psp;
/* CONTROL and PSP values for user mode.*/
lctxp->control = control | 1U;
lctxp->ectxp = ectxp;
/* PSP now points to the port_linkctx structure, it will be removed
by SVC.*/
__set_PSP(s_psp);
asm volatile ("svc 0");
chSysHalt("svc");
}
#endif
#if (CORTEX_SIMPLIFIED_PRIORITY == FALSE) || defined(__DOXYGEN__) #if (CORTEX_SIMPLIFIED_PRIORITY == FALSE) || defined(__DOXYGEN__)
/** /**
* @brief SVC vector. * @brief SVC vector.
@ -124,84 +65,20 @@ void SVC_Handler(void) {
/*lint -restore*/ /*lint -restore*/
uint32_t psp = __get_PSP(); uint32_t psp = __get_PSP();
#if PORT_USE_SYSCALL == TRUE /* Unstacking procedure, discarding the current exception context and
uint32_t control; positioning the stack to point to the real one.*/
/* Caller context.*/ psp += sizeof (struct port_extctx);
struct port_extctx *ectxp = (struct port_extctx *)psp;
#if defined(__GNUC__)
chDbgAssert(((uint32_t)__builtin_return_address(0) & 4U) != 0U,
"not process");
#endif
/* Checking if the SVC instruction has been used from privileged or
non-privileged mode.*/
control = __get_CONTROL();
if ((control & 1U) != 0) {
/* From non-privileged mode, it must be handled as a syscall.*/
uint32_t n, s_psp;
struct port_linkctx *lctxp;
struct port_extctx *newctxp;
/* Supervisor PSP from the thread context structure.*/
s_psp = (uint32_t)__sch_get_currthread()->ctx.syscall.psp;
/* Pushing the port_linkctx into the supervisor stack.*/
s_psp -= sizeof (struct port_linkctx);
lctxp = (struct port_linkctx *)s_psp;
lctxp->control = control;
lctxp->ectxp = ectxp;
/* Enforcing privileged mode before returning.*/
__set_CONTROL(control & ~1U);
/* Number of the SVC instruction.*/
n = (uint32_t)*(((const uint16_t *)ectxp->pc) - 1U) & 255U;
/* Building an artificial return context, we need to make this
return in the syscall dispatcher in privileged mode.*/
s_psp -= sizeof (struct port_extctx);
__set_PSP(s_psp);
newctxp = (struct port_extctx *)s_psp;
newctxp->r0 = (uint32_t)ectxp;
newctxp->r1 = n;
newctxp->pc = (uint32_t)port_syscall;
newctxp->xpsr = 0x01000000U;
#if CORTEX_USE_FPU == TRUE
newctxp->fpscr = FPU->FPDSCR;
#endif
}
else
#endif
{
/* From privileged mode, it is used for context discarding in the
preemption code.*/
/* Unstacking procedure, discarding the current exception context and
positioning the stack to point to the real one.*/
psp += sizeof (struct port_extctx);
#if CORTEX_USE_FPU == TRUE #if CORTEX_USE_FPU == TRUE
/* Enforcing unstacking of the FP part of the context.*/ /* Enforcing unstacking of the FP part of the context.*/
FPU->FPCCR &= ~FPU_FPCCR_LSPACT_Msk; FPU->FPCCR &= ~FPU_FPCCR_LSPACT_Msk;
#endif #endif
#if PORT_USE_SYSCALL == TRUE /* Restoring real position of the original stack frame.*/
{ __set_PSP(psp);
/* Restoring CONTROL and the original PSP position.*/
struct port_linkctx *lctxp = (struct port_linkctx *)psp;
__set_CONTROL((uint32_t)lctxp->control);
__set_PSP((uint32_t)lctxp->ectxp);
}
#else
/* Restoring real position of the original stack frame.*/ /* Restoring the normal interrupts status.*/
__set_PSP(psp); port_unlock_from_isr();
#endif
/* Restoring the normal interrupts status.*/
port_unlock_from_isr();
}
} }
#endif /* CORTEX_SIMPLIFIED_PRIORITY == FALSE */ #endif /* CORTEX_SIMPLIFIED_PRIORITY == FALSE */
@ -226,15 +103,6 @@ void PendSV_Handler(void) {
point to the real one.*/ point to the real one.*/
psp += sizeof (struct port_extctx); psp += sizeof (struct port_extctx);
#if PORT_USE_SYSCALL == TRUE
{
/* Restoring previous privileges by restoring CONTROL.*/
struct port_linkctx *lctxp = (struct port_linkctx *)psp;
__set_CONTROL((uint32_t)lctxp->control);
psp += sizeof (struct port_linkctx);
}
#endif
/* Restoring real position of the original stack frame.*/ /* Restoring real position of the original stack frame.*/
__set_PSP(psp); __set_PSP(psp);
} }
@ -289,7 +157,7 @@ void port_init(os_instance_t *oip) {
} }
#endif #endif
#if (PORT_ENABLE_GUARD_PAGES == TRUE) || (PORT_USE_SYSCALL == TRUE) #if PORT_ENABLE_GUARD_PAGES == TRUE
/* MPU is enabled.*/ /* MPU is enabled.*/
mpuEnable(MPU_CTRL_PRIVDEFENA); mpuEnable(MPU_CTRL_PRIVDEFENA);
#endif #endif
@ -314,55 +182,21 @@ void __port_irq_epilogue(void) {
port_lock_from_isr(); port_lock_from_isr();
if ((SCB->ICSR & SCB_ICSR_RETTOBASE_Msk) != 0U) { if ((SCB->ICSR & SCB_ICSR_RETTOBASE_Msk) != 0U) {
struct port_extctx *ectxp; struct port_extctx *ectxp;
uint32_t s_psp; uint32_t psp;
#if CORTEX_USE_FPU == TRUE #if CORTEX_USE_FPU == TRUE
/* Enforcing a lazy FPU state save by accessing the FPCSR register.*/ /* Enforcing a lazy FPU state save by accessing the FPCSR register.*/
(void) __get_FPSCR(); (void) __get_FPSCR();
#endif #endif
#if PORT_USE_SYSCALL == TRUE
{
struct port_linkctx *lctxp;
uint32_t control = __get_CONTROL();
/* Checking if the IRQ has been served in unprivileged mode.*/
if ((control & 1U) != 0U) {
/* Unprivileged mode, switching to privileged mode.*/
__set_CONTROL(control & ~1U);
/* Switching to S-PSP taking it from the thread context.*/
s_psp = (uint32_t)__sch_get_currthread()->ctx.syscall.psp;
/* Pushing the middle context for returning to the original frame
and mode.*/
s_psp = s_psp - sizeof (struct port_linkctx);
lctxp = (struct port_linkctx *)s_psp;
lctxp->control = control;
lctxp->ectxp = (struct port_extctx *)__get_PSP();
}
else {
/* Privileged mode, we are already on S-PSP.*/
uint32_t psp = __get_PSP();
/* Pushing the middle context for returning to the original frame
and mode.*/
s_psp = psp - sizeof (struct port_linkctx);
lctxp = (struct port_linkctx *)s_psp;
lctxp->control = control;
lctxp->ectxp = (struct port_extctx *)psp;
}
}
#else
s_psp = __get_PSP();
#endif
/* Adding an artificial exception return context, there is no need to /* Adding an artificial exception return context, there is no need to
populate it fully.*/ populate it fully.*/
s_psp -= sizeof (struct port_extctx); psp = __get_PSP();
psp -= sizeof (struct port_extctx);
/* The port_extctx structure is pointed by the S-PSP register.*/ /* The port_extctx structure is pointed by the S-PSP register.*/
ectxp = (struct port_extctx *)s_psp; ectxp = (struct port_extctx *)psp;
/* Setting up a fake XPSR register value.*/ /* Setting up a fake XPSR register value.*/
ectxp->xpsr = 0x01000000U; ectxp->xpsr = 0x01000000U;
@ -371,7 +205,7 @@ void __port_irq_epilogue(void) {
#endif #endif
/* Writing back the modified S-PSP value.*/ /* Writing back the modified S-PSP value.*/
__set_PSP(s_psp); __set_PSP(psp);
/* The exit sequence is different depending on if a preemption is /* The exit sequence is different depending on if a preemption is
required or not.*/ required or not.*/

View File

@ -111,24 +111,6 @@
/* Module pre-compile time settings. */ /* Module pre-compile time settings. */
/*===========================================================================*/ /*===========================================================================*/
/**
* @brief Implements a syscall interface on SVC.
*/
#if !defined(PORT_USE_SYSCALL) || defined(__DOXYGEN__)
#define PORT_USE_SYSCALL FALSE
#endif
/**
* @brief Number of MPU regions to be saved/restored during context switch.
* @note The first region is always region zero.
* @note The use of this option has an overhead of 8 bytes for each
* region for each thread.
* @note Allowed values are 0..4, zero means none.
*/
#if !defined(PORT_SWITCHED_REGIONS_NUMBER) || defined(__DOXYGEN__)
#define PORT_SWITCHED_REGIONS_NUMBER 0
#endif
/** /**
* @brief Enables stack overflow guard pages using MPU. * @brief Enables stack overflow guard pages using MPU.
* @note This option can only be enabled if also option * @note This option can only be enabled if also option
@ -142,8 +124,6 @@
/** /**
* @brief MPU region to be used to stack guards. * @brief MPU region to be used to stack guards.
* @note Make sure this region is not included in the
* @p PORT_SWITCHED_REGIONS_NUMBER regions range.
*/ */
#if !defined(PORT_USE_GUARD_MPU_REGION) || defined(__DOXYGEN__) #if !defined(PORT_USE_GUARD_MPU_REGION) || defined(__DOXYGEN__)
#define PORT_USE_GUARD_MPU_REGION MPU_REGION_7 #define PORT_USE_GUARD_MPU_REGION MPU_REGION_7
@ -235,10 +215,6 @@
/* Derived constants and error checks. */ /* Derived constants and error checks. */
/*===========================================================================*/ /*===========================================================================*/
#if (PORT_SWITCHED_REGIONS_NUMBER < 0) || (PORT_SWITCHED_REGIONS_NUMBER > 4)
#error "invalid PORT_SWITCHED_REGIONS_NUMBER value"
#endif
#if (CORTEX_FAST_PRIORITIES < 0) || \ #if (CORTEX_FAST_PRIORITIES < 0) || \
(CORTEX_FAST_PRIORITIES > (CORTEX_PRIORITY_LEVELS / 4)) (CORTEX_FAST_PRIORITIES > (CORTEX_PRIORITY_LEVELS / 4))
#error "invalid CORTEX_FAST_PRIORITIES value specified" #error "invalid CORTEX_FAST_PRIORITIES value specified"
@ -459,31 +435,12 @@ struct port_extctx {
#endif /* CORTEX_USE_FPU */ #endif /* CORTEX_USE_FPU */
}; };
#if (PORT_USE_SYSCALL == TRUE) || defined(__DOXYGEN__)
/**
* @brief Link context structure.
* @details This structure is used when there is the need to save extra
* context information that is not part of the registers stacked
* in HW.
*/
struct port_linkctx {
uint32_t control;
struct port_extctx *ectxp;
};
#endif
/** /**
* @brief System saved context. * @brief System saved context.
* @details This structure represents the inner stack frame during a context * @details This structure represents the inner stack frame during a context
* switch. * switch.
*/ */
struct port_intctx { struct port_intctx {
#if (PORT_SWITCHED_REGIONS_NUMBER > 0) || defined(__DOXYGEN__)
struct {
uint32_t rbar;
uint32_t rasr;
} regions[PORT_SWITCHED_REGIONS_NUMBER];
#endif
#if CORTEX_USE_FPU #if CORTEX_USE_FPU
uint32_t s16; uint32_t s16;
uint32_t s17; uint32_t s17;
@ -521,12 +478,6 @@ struct port_intctx {
*/ */
struct port_context { struct port_context {
struct port_intctx *sp; struct port_intctx *sp;
#if (PORT_USE_SYSCALL == TRUE) || defined(__DOXYGEN__)
struct {
uint32_t psp;
const void *p;
} syscall;
#endif
}; };
#endif /* !defined(_FROM_ASM_) */ #endif /* !defined(_FROM_ASM_) */
@ -552,55 +503,6 @@ struct port_context {
*/ */
#define PORT_THD_FUNCTION(tname, arg) void tname(void *arg) #define PORT_THD_FUNCTION(tname, arg) void tname(void *arg)
/* By default threads have no syscall context information.*/
#if (PORT_USE_SYSCALL == TRUE) || defined(__DOXYGEN__)
#define __PORT_SETUP_CONTEXT_SYSCALL(tp, wtop) \
(tp)->ctx.syscall.psp = (uint32_t)(wtop); \
(tp)->ctx.syscall.p = NULL;
#else
#define __PORT_SETUP_CONTEXT_SYSCALL(tp, wtop)
#endif
/* By default threads have all regions disabled.*/
#if (PORT_SWITCHED_REGIONS_NUMBER == 0) || defined(__DOXYGEN__)
#define __PORT_SETUP_CONTEXT_MPU(tp)
#elif (PORT_SWITCHED_REGIONS_NUMBER == 1) || defined(__DOXYGEN__)
#define __PORT_SETUP_CONTEXT_MPU(tp) \
(tp)->ctx.sp->regions[0].rbar = 0U; \
(tp)->ctx.sp->regions[0].rasr = 0U
#elif (PORT_SWITCHED_REGIONS_NUMBER == 2) || defined(__DOXYGEN__)
#define __PORT_SETUP_CONTEXT_MPU(tp) \
(tp)->ctx.sp->regions[0].rbar = 0U; \
(tp)->ctx.sp->regions[0].rasr = 0U; \
(tp)->ctx.sp->regions[1].rbar = 0U; \
(tp)->ctx.sp->regions[1].rasr = 0U
#elif (PORT_SWITCHED_REGIONS_NUMBER == 3) || defined(__DOXYGEN__)
#define __PORT_SETUP_CONTEXT_MPU(tp) \
(tp)->ctx.sp->regions[0].rbar = 0U; \
(tp)->ctx.sp->regions[0].rasr = 0U; \
(tp)->ctx.sp->regions[1].rbar = 0U; \
(tp)->ctx.sp->regions[1].rasr = 0U; \
(tp)->ctx.sp->regions[2].rbar = 0U; \
(tp)->ctx.sp->regions[2].rasr = 0U
#elif (PORT_SWITCHED_REGIONS_NUMBER == 4) || defined(__DOXYGEN__)
#define __PORT_SETUP_CONTEXT_MPU(tp) \
(tp)->ctx.sp->regions[0].rbar = 0U; \
(tp)->ctx.sp->regions[0].rasr = 0U; \
(tp)->ctx.sp->regions[1].rbar = 0U; \
(tp)->ctx.sp->regions[1].rasr = 0U; \
(tp)->ctx.sp->regions[2].rbar = 0U; \
(tp)->ctx.sp->regions[2].rasr = 0U; \
(tp)->ctx.sp->regions[3].rbar = 0U; \
(tp)->ctx.sp->regions[3].rasr = 0U
#else
/* Note, checked above.*/
#endif
/** /**
* @brief Platform dependent part of the @p chThdCreateI() API. * @brief Platform dependent part of the @p chThdCreateI() API.
* @details This code usually setup the context switching frame represented * @details This code usually setup the context switching frame represented
@ -612,8 +514,6 @@ struct port_context {
(tp)->ctx.sp->r4 = (uint32_t)(pf); \ (tp)->ctx.sp->r4 = (uint32_t)(pf); \
(tp)->ctx.sp->r5 = (uint32_t)(arg); \ (tp)->ctx.sp->r5 = (uint32_t)(arg); \
(tp)->ctx.sp->lr = (uint32_t)__port_thread_start; \ (tp)->ctx.sp->lr = (uint32_t)__port_thread_start; \
__PORT_SETUP_CONTEXT_MPU(tp); \
__PORT_SETUP_CONTEXT_SYSCALL(tp, wtop); \
} while (false) } while (false)
/** /**
@ -741,9 +641,6 @@ extern "C" {
void __port_thread_start(void); void __port_thread_start(void);
void __port_switch_from_isr(void); void __port_switch_from_isr(void);
void __port_exit_from_isr(void); void __port_exit_from_isr(void);
#if PORT_USE_SYSCALL == TRUE
void port_unprivileged_jump(uint32_t pc, uint32_t psp);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -83,43 +83,6 @@ __port_switch:
vpush {s16-s31} vpush {s16-s31}
#endif #endif
#if PORT_SWITCHED_REGIONS_NUMBER > 0
/* Saving MPU context.*/
ldr r2, =MPU_RBAR
#if PORT_SWITCHED_REGIONS_NUMBER >= 1
mov r3, #0
str r3, [r2, #-4] /* RNR */
ldm r2, {r4, r5} /* RBAR, RASR */
#endif
#if PORT_SWITCHED_REGIONS_NUMBER >= 2
add r3, #1
str r3, [r2, #-4] /* RNR */
ldm r2, {r6, r7} /* RBAR, RASR */
#endif
#if PORT_SWITCHED_REGIONS_NUMBER >= 3
add r3, #1
str r3, [r2, #-4] /* RNR */
ldm r2, {r8, r9} /* RBAR, RASR */
#endif
#if PORT_SWITCHED_REGIONS_NUMBER >= 4
add r3, #1
str r3, [r2, #-4] /* RNR */
ldm r2, {r10, r11} /* RBAR, RASR */
#endif
#if PORT_SWITCHED_REGIONS_NUMBER == 1
push {r4, r5}
#endif
#if PORT_SWITCHED_REGIONS_NUMBER == 2
push {r4, r5, r6, r7}
#endif
#if PORT_SWITCHED_REGIONS_NUMBER == 3
push {r4, r5, r6, r7, r8, r9}
#endif
#if PORT_SWITCHED_REGIONS_NUMBER == 4
push {r4, r5, r6, r7, r8, r9, r10, r11}
#endif
#endif
str sp, [r1, #CONTEXT_OFFSET] str sp, [r1, #CONTEXT_OFFSET]
#if (CORTEX_SIMPLIFIED_PRIORITY == FALSE) && \ #if (CORTEX_SIMPLIFIED_PRIORITY == FALSE) && \
((CORTEX_MODEL == 3) || (CORTEX_MODEL == 4)) ((CORTEX_MODEL == 3) || (CORTEX_MODEL == 4))
@ -131,42 +94,6 @@ __port_switch:
ldr sp, [r0, #CONTEXT_OFFSET] ldr sp, [r0, #CONTEXT_OFFSET]
#endif #endif
#if PORT_SWITCHED_REGIONS_NUMBER > 0
/* Restoring MPU context.*/
#if PORT_SWITCHED_REGIONS_NUMBER == 1
pop {r4, r5}
#endif
#if PORT_SWITCHED_REGIONS_NUMBER == 2
pop {r4, r5, r6, r7}
#endif
#if PORT_SWITCHED_REGIONS_NUMBER == 3
pop {r4, r5, r6, r7, r8, r9}
#endif
#if PORT_SWITCHED_REGIONS_NUMBER == 4
pop {r4, r5, r6, r7, r8, r9, r10, r11}
#endif
#if PORT_SWITCHED_REGIONS_NUMBER >= 1
mov r3, #0
str r3, [r2, #-4] /* RNR */
stm r2, {r4, r5} /* RBAR, RASR */
#endif
#if PORT_SWITCHED_REGIONS_NUMBER >= 2
add r3, #1
str r3, [r2, #-4] /* RNR */
stm r2, {r6, r7} /* RBAR, RASR */
#endif
#if PORT_SWITCHED_REGIONS_NUMBER >= 3
add r3, #1
str r3, [r2, #-4] /* RNR */
stm r2, {r8, r9} /* RBAR, RASR */
#endif
#if PORT_SWITCHED_REGIONS_NUMBER >= 4
add r3, #1
str r3, [r2, #-4] /* RNR */
stm r2, {r10, r11} /* RBAR, RASR */
#endif
#endif
#if CORTEX_USE_FPU #if CORTEX_USE_FPU
/* Restoring FPU context.*/ /* Restoring FPU context.*/
vpop {s16-s31} vpop {s16-s31}

View File

@ -74,6 +74,8 @@
***************************************************************************** *****************************************************************************
*** Next *** *** Next ***
- NEW: Removed obsolete sandbox code from ARMv7-M port. Now ARMv7-M-ALT is
the official port for use with sandboxes.
- NEW: Reworked HAL MAC driver, now with callback support. - NEW: Reworked HAL MAC driver, now with callback support.
- NEW: Added a para-virtualized HAL port for use in sandboxes. - NEW: Added a para-virtualized HAL port for use in sandboxes.
- NEW: Added a VIO subsystem to sandboxes supporting drivers - NEW: Added a VIO subsystem to sandboxes supporting drivers