• R/O
  • SSH
  • HTTPS

chibios: Commit


Commit MetaInfo

Revision12977 (tree)
Time2019-09-07 23:35:52
Authorgdisirio

Log Message

Implemented support for multiple sandboxes.

Change Summary

Incremental Difference

--- trunk/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/cfg/chconf.h (revision 12976)
+++ trunk/demos/STM32/RT-STM32L476-DISCOVERY-SB_HOST/cfg/chconf.h (revision 12977)
@@ -756,6 +756,9 @@
756756 /* Port-specific settings (override port settings defaulted in chcore.h). */
757757 /*===========================================================================*/
758758
759+#define PORT_USE_SYSCALL TRUE
760+#define PORT_SWITCHED_REGIONS_NUMBER 0
761+
759762 #endif /* CHCONF_H */
760763
761764 /** @} */
--- trunk/os/common/ports/ARMCMx/chcore_v7m.c (revision 12976)
+++ trunk/os/common/ports/ARMCMx/chcore_v7m.c (revision 12977)
@@ -122,7 +122,6 @@
122122 /*lint -save -e9075 [8.4] All symbols are invoked from asm context.*/
123123 void SVC_Handler(void) {
124124 /*lint -restore*/
125- uint32_t control;
126125 uint32_t psp = __get_PSP();
127126
128127 chDbgAssert(((uint32_t)__builtin_return_address(0) & 4U) == 0U,
@@ -129,6 +128,7 @@
129128 "not process");
130129
131130 #if PORT_USE_SYSCALL == TRUE
131+ uint32_t control;
132132 /* Caller context.*/
133133 struct port_extctx *ectxp = (struct port_extctx *)psp;
134134
--- trunk/os/common/ports/ARMCMx/chcore_v7m.h (revision 12976)
+++ trunk/os/common/ports/ARMCMx/chcore_v7m.h (revision 12977)
@@ -74,10 +74,21 @@
7474 * @brief Implements a syscall interface on SVC.
7575 */
7676 #if !defined(PORT_USE_SYSCALL) || defined(__DOXYGEN__)
77-#define PORT_USE_SYSCALL TRUE
77+#define PORT_USE_SYSCALL FALSE
7878 #endif
7979
8080 /**
81+ * @brief Number of MPU regions to be saved/restored during context switch.
82+ * @note The first region is always region zero.
83+ * @note The use of this option has an overhead of 8 bytes for each
84+ * region for each thread.
85+ * @note Allowed values are 0..4, zero means none.
86+ */
87+#if !defined(PORT_SWITCHED_REGIONS_NUMBER) || defined(__DOXYGEN__)
88+#define PORT_SWITCHED_REGIONS_NUMBER 0
89+#endif
90+
91+/**
8192 * @brief Enables stack overflow guard pages using MPU.
8293 * @note This option can only be enabled if also option
8394 * @p CH_DBG_ENABLE_STACK_CHECK is enabled.
@@ -90,9 +101,11 @@
90101
91102 /**
92103 * @brief MPU region to be used to stack guards.
104+ * @note Make sure this region is not included in the
105+ * @p PORT_SWITCHED_REGIONS_NUMBER regions range.
93106 */
94-#if !defined(PORT_USE_MPU_REGION) || defined(__DOXYGEN__)
95-#define PORT_USE_MPU_REGION MPU_REGION_7
107+#if !defined(PORT_USE_GUARD_MPU_REGION) || defined(__DOXYGEN__)
108+#define PORT_USE_GUARD_MPU_REGION MPU_REGION_7
96109 #endif
97110
98111 /**
@@ -177,6 +190,10 @@
177190 /* Derived constants and error checks. */
178191 /*===========================================================================*/
179192
193+#if (PORT_SWITCHED_REGIONS_NUMBER < 0) || (PORT_SWITCHED_REGIONS_NUMBER > 4)
194+#error "invalid PORT_SWITCHED_REGIONS_NUMBER value"
195+#endif
196+
180197 #if !defined(_FROM_ASM_)
181198 /**
182199 * @brief MPU guard page size.
@@ -370,6 +387,12 @@
370387 #endif
371388
372389 struct port_intctx {
390+#if (PORT_SWITCHED_REGIONS_NUMBER > 0) || defined(__DOXYGEN__)
391+ struct {
392+ uint32_t rbar;
393+ uint32_t rasr;
394+ } regions[PORT_SWITCHED_REGIONS_NUMBER];
395+#endif
373396 #if CORTEX_USE_FPU
374397 regarm_t s16;
375398 regarm_t s17;
@@ -404,7 +427,7 @@
404427 #if (PORT_USE_SYSCALL == TRUE) || defined(__DOXYGEN__)
405428 struct {
406429 regarm_t psp;
407- const void *regions;
430+ const void *p;
408431 } syscall;
409432 #endif
410433 };
@@ -414,14 +437,49 @@
414437 /* Module macros. */
415438 /*===========================================================================*/
416439
440+/* By default threads have no syscall context information.*/
417441 #if (PORT_USE_SYSCALL == TRUE) || defined(__DOXYGEN__)
418442 #define __PORT_SETUP_CONTEXT_SYSCALL(tp, wtop) \
419443 (tp)->ctx.syscall.psp = (regarm_t)(wtop); \
420- (tp)->ctx.syscall.regions = NULL;
444+ (tp)->ctx.syscall.p = NULL;
421445 #else
422446 #define __PORT_SETUP_CONTEXT_SYSCALL(tp, wtop)
423447 #endif
424448
449+/* By default threads have all regions disabled.*/
450+#if (PORT_SWITCHED_REGIONS_NUMBER == 0) || defined(__DOXYGEN__)
451+#define __PORT_SETUP_CONTEXT_MPU(tp)
452+#elif (PORT_SWITCHED_REGIONS_NUMBER == 1) || defined(__DOXYGEN__)
453+#define __PORT_SETUP_CONTEXT_MPU(tp) \
454+ (tp)->ctx.sp->regions[0].rbar = 0U; \
455+ (tp)->ctx.sp->regions[0].rasr = 0U
456+#elif (PORT_SWITCHED_REGIONS_NUMBER == 2) || defined(__DOXYGEN__)
457+#define __PORT_SETUP_CONTEXT_MPU(tp) \
458+ (tp)->ctx.sp->regions[0].rbar = 0U; \
459+ (tp)->ctx.sp->regions[0].rasr = 0U; \
460+ (tp)->ctx.sp->regions[1].rbar = 0U; \
461+ (tp)->ctx.sp->regions[1].rasr = 0U
462+#elif (PORT_SWITCHED_REGIONS_NUMBER == 3) || defined(__DOXYGEN__)
463+#define __PORT_SETUP_CONTEXT_MPU(tp) \
464+ (tp)->ctx.sp->regions[0].rbar = 0U; \
465+ (tp)->ctx.sp->regions[0].rasr = 0U; \
466+ (tp)->ctx.sp->regions[1].rbar = 0U; \
467+ (tp)->ctx.sp->regions[1].rasr = 0U; \
468+ (tp)->ctx.sp->regions[2].rbar = 0U; \
469+ (tp)->ctx.sp->regions[2].rasr = 0U
470+#elif (PORT_SWITCHED_REGIONS_NUMBER == 4) || defined(__DOXYGEN__)
471+#define __PORT_SETUP_CONTEXT_MPU(tp) \
472+ (tp)->ctx.sp->regions[0].rbar = 0U; \
473+ (tp)->ctx.sp->regions[0].rasr = 0U; \
474+ (tp)->ctx.sp->regions[1].rbar = 0U; \
475+ (tp)->ctx.sp->regions[1].rasr = 0U; \
476+ (tp)->ctx.sp->regions[2].rbar = 0U; \
477+ (tp)->ctx.sp->regions[2].rasr = 0U; \
478+ (tp)->ctx.sp->regions[3].rbar = 0U; \
479+ (tp)->ctx.sp->regions[3].rasr = 0U
480+#else
481+#endif
482+
425483 /**
426484 * @brief Platform dependent part of the @p chThdCreateI() API.
427485 * @details This code usually setup the context switching frame represented
@@ -433,9 +491,12 @@
433491 (tp)->ctx.sp->r4 = (regarm_t)(pf); \
434492 (tp)->ctx.sp->r5 = (regarm_t)(arg); \
435493 (tp)->ctx.sp->lr = (regarm_t)_port_thread_start; \
436- __PORT_SETUP_CONTEXT_SYSCALL(tp, wtop) \
494+ __PORT_SETUP_CONTEXT_MPU(tp); \
495+ __PORT_SETUP_CONTEXT_SYSCALL(tp, wtop); \
437496 }
438497
498+// __PORT_SETUP_CONTEXT_MPU(tp)
499+
439500 /**
440501 * @brief Computes the thread working area global size.
441502 * @note There is no need to perform alignments in this macro.
@@ -524,8 +585,8 @@
524585 _port_switch(ntp, otp); \
525586 \
526587 /* Setting up the guard page for the switched-in thread.*/ \
527- mpuSetRegionAddress(PORT_USE_MPU_REGION, \
528- chThdGetSelfX()->wabase); \
588+ mpuSetRegionAddress(PORT_USE_GUARD_MPU_REGION, \
589+ chThdGetSelfX()->wabase); \
529590 }
530591 #endif
531592 #endif
@@ -559,7 +620,7 @@
559620 *
560621 * @return The interrupts status.
561622 */
562-static inline syssts_t port_get_irq_status(void) {
623+__STATIC_FORCEINLINE syssts_t port_get_irq_status(void) {
563624 syssts_t sts;
564625
565626 #if CORTEX_SIMPLIFIED_PRIORITY == FALSE
@@ -579,7 +640,7 @@
579640 * @retval false the word specified a disabled interrupts status.
580641 * @retval true the word specified an enabled interrupts status.
581642 */
582-static inline bool port_irq_enabled(syssts_t sts) {
643+__STATIC_FORCEINLINE bool port_irq_enabled(syssts_t sts) {
583644
584645 #if CORTEX_SIMPLIFIED_PRIORITY == FALSE
585646 return sts == (syssts_t)CORTEX_BASEPRI_DISABLED;
@@ -595,7 +656,7 @@
595656 * @retval false not running in ISR mode.
596657 * @retval true running in ISR mode.
597658 */
598-static inline bool port_is_isr_context(void) {
659+__STATIC_FORCEINLINE bool port_is_isr_context(void) {
599660
600661 return (bool)((__get_IPSR() & 0x1FFU) != 0U);
601662 }
@@ -605,7 +666,7 @@
605666 * @details In this port this function raises the base priority to kernel
606667 * level.
607668 */
608-static inline void port_lock(void) {
669+__STATIC_FORCEINLINE void port_lock(void) {
609670
610671 #if CORTEX_SIMPLIFIED_PRIORITY == FALSE
611672 #if defined(__CM7_REV)
@@ -629,7 +690,7 @@
629690 * @details In this port this function lowers the base priority to user
630691 * level.
631692 */
632-static inline void port_unlock(void) {
693+__STATIC_FORCEINLINE void port_unlock(void) {
633694
634695 #if CORTEX_SIMPLIFIED_PRIORITY == FALSE
635696 __set_BASEPRI(CORTEX_BASEPRI_DISABLED);
@@ -644,7 +705,7 @@
644705 * level.
645706 * @note Same as @p port_lock() in this port.
646707 */
647-static inline void port_lock_from_isr(void) {
708+__STATIC_FORCEINLINE void port_lock_from_isr(void) {
648709
649710 port_lock();
650711 }
@@ -655,7 +716,7 @@
655716 * level.
656717 * @note Same as @p port_unlock() in this port.
657718 */
658-static inline void port_unlock_from_isr(void) {
719+__STATIC_FORCEINLINE void port_unlock_from_isr(void) {
659720
660721 port_unlock();
661722 }
@@ -665,7 +726,7 @@
665726 * @note In this port it disables all the interrupt sources by raising
666727 * the priority mask to level 0.
667728 */
668-static inline void port_disable(void) {
729+__STATIC_FORCEINLINE void port_disable(void) {
669730
670731 __disable_irq();
671732 }
@@ -675,7 +736,7 @@
675736 * @note Interrupt sources above kernel level remains enabled.
676737 * @note In this port it raises/lowers the base priority to kernel level.
677738 */
678-static inline void port_suspend(void) {
739+__STATIC_FORCEINLINE void port_suspend(void) {
679740
680741 #if (CORTEX_SIMPLIFIED_PRIORITY == FALSE) || defined(__DOXYGEN__)
681742 __set_BASEPRI(CORTEX_BASEPRI_KERNEL);
@@ -689,7 +750,7 @@
689750 * @brief Enables all the interrupt sources.
690751 * @note In this port it lowers the base priority to user level.
691752 */
692-static inline void port_enable(void) {
753+__STATIC_FORCEINLINE void port_enable(void) {
693754
694755 #if (CORTEX_SIMPLIFIED_PRIORITY == FALSE) || defined(__DOXYGEN__)
695756 __set_BASEPRI(CORTEX_BASEPRI_DISABLED);
@@ -705,7 +766,7 @@
705766 * modes.
706767 * @note Implemented as an inlined @p WFI instruction.
707768 */
708-static inline void port_wait_for_interrupt(void) {
769+__STATIC_FORCEINLINE void port_wait_for_interrupt(void) {
709770
710771 #if CORTEX_ENABLE_WFI_IDLE == TRUE
711772 __WFI();
@@ -717,7 +778,7 @@
717778 *
718779 * @return The realtime counter value.
719780 */
720-static inline rtcnt_t port_rt_get_counter_value(void) {
781+__STATIC_FORCEINLINE rtcnt_t port_rt_get_counter_value(void) {
721782
722783 return DWT->CYCCNT;
723784 }
Show on old repository browser