diff --git a/features/FEATURE_UVISOR/AUTHORS.txt b/features/FEATURE_UVISOR/AUTHORS.txt index 327498aaf37..075768f5e56 100644 --- a/features/FEATURE_UVISOR/AUTHORS.txt +++ b/features/FEATURE_UVISOR/AUTHORS.txt @@ -1,7 +1,7 @@ - 523 Milosch Meriac - 422 Alessandro Angelino - 17 Niklas Hauser - 16 Jaeden Amero + 513 Milosch Meriac + 424 Alessandro Angelino + 18 Jaeden Amero + 18 Niklas Hauser 3 Hugo Vincent 3 JaredCJR 3 Jim Huang diff --git a/features/FEATURE_UVISOR/VERSION.txt b/features/FEATURE_UVISOR/VERSION.txt index 5b5438bc02b..bd64f9e2244 100644 --- a/features/FEATURE_UVISOR/VERSION.txt +++ b/features/FEATURE_UVISOR/VERSION.txt @@ -1 +1 @@ -v0.9.14-alpha-8-g1f0a4b9b181476c65d396838d61465ea5363e23b +v0.9.17-alpha diff --git a/features/FEATURE_UVISOR/importer/Makefile b/features/FEATURE_UVISOR/importer/Makefile index c29e38ad00f..5508cfdaa30 100644 --- a/features/FEATURE_UVISOR/importer/Makefile +++ b/features/FEATURE_UVISOR/importer/Makefile @@ -33,7 +33,7 @@ TARGET_LIB_INC:=$(TARGET_PREFIX)includes/uvisor-lib # uVisor source directory - hidden from mbed via TARGET_IGNORE UVISOR_GIT_URL:=https://github.com/ARMmbed/uvisor -UVISOR_GIT_BRANCH:=dev +UVISOR_GIT_BRANCH:=unstable UVISOR_DIR:=TARGET_IGNORE/uvisor UVISOR_API:=$(UVISOR_DIR)/api UVISOR_GIT_CFG=$(UVISOR_DIR)/.git/config diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/box_config.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/box_config.h index cf2f997f99e..a34962c555e 100644 --- a/features/FEATURE_UVISOR/includes/uvisor/api/inc/box_config.h +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/box_config.h @@ -45,6 +45,8 @@ UVISOR_EXTERN const uint32_t __uvisor_mode; sizeof(RtxBoxIndex), \ 0, \ 0, \ + 0, \ + 0, \ NULL, \ acl_list, \ acl_list_count \ @@ -76,6 +78,8 @@ UVISOR_EXTERN const uint32_t __uvisor_mode; sizeof(RtxBoxIndex), \ context_size, \ __uvisor_box_heapsize, \ + __uvisor_box_main_function, \ + __uvisor_box_main_priority, \ __uvisor_box_namespace, \ acl_list, \ acl_list_count \ @@ -116,6 +120,13 @@ UVISOR_EXTERN const uint32_t __uvisor_mode; #define UVISOR_BOX_NAMESPACE(box_namespace) \ static const char *const __uvisor_box_namespace = box_namespace +/* Use this macro before UVISOR_BOX_CONFIG to define the function the main + * thread of your box will use for its body. If you don't want a main thread, + * too bad: you have to have one. */ +#define UVISOR_BOX_MAIN(function, priority) \ + static void (*const __uvisor_box_main_function)(void const *) = (function); \ + static const int32_t __uvisor_box_main_priority = (priority); + #define UVISOR_BOX_HEAPSIZE(heap_size) \ static const uint32_t __uvisor_box_heapsize = heap_size; diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/svc_exports.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/svc_exports.h index ae59b3d4283..f58d4126fc9 100644 --- a/features/FEATURE_UVISOR/includes/uvisor/api/inc/svc_exports.h +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/svc_exports.h @@ -116,6 +116,7 @@ /* SVC immediate values for hardcoded table (call from unprivileged) */ #define UVISOR_SVC_ID_UNVIC_OUT UVISOR_SVC_FIXED_TABLE(0, 0) #define UVISOR_SVC_ID_REGISTER_GATEWAY UVISOR_SVC_FIXED_TABLE(3, 0) +#define UVISOR_SVC_ID_BOX_MAIN_NEXT UVISOR_SVC_FIXED_TABLE(5, 0) /* SVC immediate values for hardcoded table (call from privileged) */ #define UVISOR_SVC_ID_UNVIC_IN UVISOR_SVC_FIXED_TABLE(0, 0) diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/vmpu_exports.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/vmpu_exports.h index 1e141b72961..b5aa192744c 100644 --- a/features/FEATURE_UVISOR/includes/uvisor/api/inc/vmpu_exports.h +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/vmpu_exports.h @@ -158,6 +158,9 @@ typedef struct { /* Contains user provided size of box heap without guards of buffers. */ uint32_t heap_size; + void (*main_function)(void const *argument); + int32_t main_priority; + const char * box_namespace; const UvisorBoxAclItem * const acl_list; uint32_t acl_count; diff --git a/features/FEATURE_UVISOR/mbed_lib.json b/features/FEATURE_UVISOR/mbed_lib.json new file mode 100644 index 00000000000..d00efbd901f --- /dev/null +++ b/features/FEATURE_UVISOR/mbed_lib.json @@ -0,0 +1,4 @@ +{ + "name": "uvisor-lib", + "macros": ["CMSIS_NVIC_VIRTUAL", "CMSIS_VECTAB_VIRTUAL"] +} diff --git a/features/FEATURE_UVISOR/source/rtx/box_main.c b/features/FEATURE_UVISOR/source/rtx/box_main.c new file mode 100644 index 00000000000..209d8c87a1c --- /dev/null +++ b/features/FEATURE_UVISOR/source/rtx/box_main.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "uvisor-lib/uvisor-lib.h" +#include "mbed_interface.h" +#include "cmsis_os.h" +#include +#include + +/* This function is called by uVisor in unprivileged mode to create box main + * threads. */ +void __uvisor_lib_box_main_handler( + void (*function)(void const *), + int32_t priority, + uint32_t stack_pointer, + uint32_t stack_size) +{ + osThreadId thread_id; + osThreadDef_t thread_def; + thread_def.pthread = function; + thread_def.tpriority = priority; + thread_def.stacksize = stack_size; + thread_def.stack_pointer = malloc(stack_size); /* XXX */ + + thread_id = osThreadCreate(&thread_def, NULL); + + if (thread_id == NULL) { + mbed_die(); + } +} diff --git a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_DEBUG/TARGET_M3/libconfiguration_efm32_m3_p1.a b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_DEBUG/TARGET_M3/libconfiguration_efm32_m3_p1.a index f8b0831020a..a8454eb272f 100644 Binary files a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_DEBUG/TARGET_M3/libconfiguration_efm32_m3_p1.a and b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_DEBUG/TARGET_M3/libconfiguration_efm32_m3_p1.a differ diff --git a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_DEBUG/TARGET_M4/libconfiguration_efm32_m4_p1.a b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_DEBUG/TARGET_M4/libconfiguration_efm32_m4_p1.a index 7e87e9d3ec1..c34b503dac3 100644 Binary files a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_DEBUG/TARGET_M4/libconfiguration_efm32_m4_p1.a and b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_DEBUG/TARGET_M4/libconfiguration_efm32_m4_p1.a differ diff --git a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_RELEASE/TARGET_M3/libconfiguration_efm32_m3_p1.a b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_RELEASE/TARGET_M3/libconfiguration_efm32_m3_p1.a index bb5ce778951..6116046eafe 100644 Binary files a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_RELEASE/TARGET_M3/libconfiguration_efm32_m3_p1.a and b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_RELEASE/TARGET_M3/libconfiguration_efm32_m3_p1.a differ diff --git a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_RELEASE/TARGET_M4/libconfiguration_efm32_m4_p1.a b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_RELEASE/TARGET_M4/libconfiguration_efm32_m4_p1.a index b81335ba4c8..8f391776fa6 100644 Binary files a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_RELEASE/TARGET_M4/libconfiguration_efm32_m4_p1.a and b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_EFM32/TARGET_RELEASE/TARGET_M4/libconfiguration_efm32_m4_p1.a differ diff --git a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_MCU_K64F/TARGET_DEBUG/TARGET_M4/libconfiguration_kinetis_m4_0x1fff0000.a b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_MCU_K64F/TARGET_DEBUG/TARGET_M4/libconfiguration_kinetis_m4_0x1fff0000.a index e489c799a7d..1f1a3c0dd84 100644 Binary files a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_MCU_K64F/TARGET_DEBUG/TARGET_M4/libconfiguration_kinetis_m4_0x1fff0000.a and b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_MCU_K64F/TARGET_DEBUG/TARGET_M4/libconfiguration_kinetis_m4_0x1fff0000.a differ diff --git a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_MCU_K64F/TARGET_RELEASE/TARGET_M4/libconfiguration_kinetis_m4_0x1fff0000.a b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_MCU_K64F/TARGET_RELEASE/TARGET_M4/libconfiguration_kinetis_m4_0x1fff0000.a index 97c6688221c..52fdcdcacd1 100644 Binary files a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_MCU_K64F/TARGET_RELEASE/TARGET_M4/libconfiguration_kinetis_m4_0x1fff0000.a and b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_MCU_K64F/TARGET_RELEASE/TARGET_M4/libconfiguration_kinetis_m4_0x1fff0000.a differ diff --git a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_STM32F4/TARGET_DEBUG/TARGET_M4/libconfiguration_stm32_m4_0x10000000_0x0.a b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_STM32F4/TARGET_DEBUG/TARGET_M4/libconfiguration_stm32_m4_0x10000000_0x0.a index d2f445c7ca6..5edef91250d 100644 Binary files a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_STM32F4/TARGET_DEBUG/TARGET_M4/libconfiguration_stm32_m4_0x10000000_0x0.a and b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_STM32F4/TARGET_DEBUG/TARGET_M4/libconfiguration_stm32_m4_0x10000000_0x0.a differ diff --git a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_STM32F4/TARGET_RELEASE/TARGET_M4/libconfiguration_stm32_m4_0x10000000_0x0.a b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_STM32F4/TARGET_RELEASE/TARGET_M4/libconfiguration_stm32_m4_0x10000000_0x0.a index 92f80e1953c..138583120f1 100644 Binary files a/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_STM32F4/TARGET_RELEASE/TARGET_M4/libconfiguration_stm32_m4_0x10000000_0x0.a and b/features/FEATURE_UVISOR/targets/TARGET_UVISOR_SUPPORTED/TARGET_STM32F4/TARGET_RELEASE/TARGET_M4/libconfiguration_stm32_m4_0x10000000_0x0.a differ diff --git a/rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.c b/rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.c index ce5df964268..7e08e38f6af 100644 --- a/rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.c +++ b/rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.c @@ -505,10 +505,6 @@ osStatus svcKernelStart (void) { if (os_running) { return osOK; } - if (osEventObs && osEventObs->pre_start) { - osEventObs->pre_start(); - } - rt_tsk_prio(0U, os_tsk.run->prio_base); // Restore priority if (os_tsk.run->task_id == 0xFFU) { // Idle Thread __set_PSP(os_tsk.run->tsk_stack + (8U*4U)); // Setup PSP @@ -567,6 +563,15 @@ osStatus osKernelStart (void) { if (__get_IPSR() != 0U) { return osErrorISR; // Not allowed in ISR } + + /* Call the pre-start event (from unprivileged mode) if the handler exists + * and the kernel is not running. */ + /* FIXME osEventObs needs to be readable but not writable from unprivileged + * code. */ + if (!osKernelRunning() && osEventObs && osEventObs->pre_start) { + osEventObs->pre_start(); + } + switch (__get_CONTROL() & 0x03U) { case 0x00U: // Privileged Thread mode & MSP __set_PSP((uint32_t)(stack + 8)); // Initial PSP diff --git a/rtos/rtx/TARGET_CORTEX_M/rt_OsEventObserver.c b/rtos/rtx/TARGET_CORTEX_M/rt_OsEventObserver.c index d1292f61e46..4335811d471 100644 --- a/rtos/rtx/TARGET_CORTEX_M/rt_OsEventObserver.c +++ b/rtos/rtx/TARGET_CORTEX_M/rt_OsEventObserver.c @@ -51,5 +51,11 @@ const OsEventObserver *osEventObs; void osRegisterForOsEvents(const OsEventObserver *observer) { + static uint8_t has_been_called = 0; + if (has_been_called) { + return; + } + has_been_called = 1; + osEventObs = observer; }