diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..33e8699 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "uvisor"] + path = uvisor + url = git@github.com:ARMmbed/uvisor.git diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index d879fff..a41826e 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -3,10 +3,11 @@ Here you can find detailed documentation for: 1. [Configuration macros](#configuration-macros), to configure a secure box and protect data and peripherals. -2. [Secure function calls](#secure-function-call), to execute code in the context of a secure box. -3. [Low level APIs](#low-level-apis), to access uVisor functions that are not available to unprivileged code (interrupts, restricted system registers). -4. [Type definitions](#type-definitions). -5. [Error codes](#error-codes). +1. [Secure function calls](#secure-function-call), to execute code in the context of a secure box. +1. [Box Identity](#box-identity), to retrieve a box-specific ID or the namespace of the current or calling box. +1. [Low level APIs](#low-level-apis), to access uVisor functions that are not available to unprivileged code (interrupts, restricted system registers). +1. [Type definitions](#type-definitions). +1. [Error codes](#error-codes). ## Configuration macros @@ -67,6 +68,7 @@ static const UvBoxAclItem g_box_acl[] = { }; /* Configure the secure box compartment. */ +UVISOR_BOX_NAMESPACE("com.example.my-box-name"); UVISOR_BOX_CONFIG(my_box_name, g_box_acl, BOX_STACK_SIZE, BoxContext); ``` @@ -166,6 +168,45 @@ UVISOR_SET_MODE_ACL(UVISOR_ENABLED, g_background_acl); 2. This macro must be used only once in the top level yotta executable. +--- + +```C +UVISOR_BOX_NAMESPACE(static const char const namespace[]) +``` + + + + + + + + + + + + + + +
Description

Specify the namespace for a box.

+ +

The namespace of the box must be a null-terminated string no longer than MAX_BOX_NAMESPACE_LENGTH (including the terminating null). The namespace must also be stored in public flash. uVisor will verify that the namespace is null-terminated and stored in public flash at boot-time, and will halt if the namespace fails this verification.

+ +

For now, use a reverse domain name for the box namespace. If you don't have a reverse domain name, use a GUID string identifier. We currently don't verify that the namespace is globally unique, but we will perform this validation in the future.

+ +

Use of this configuration macro before UVISOR_BOX_CONFIG is required. If you do not wish to give your box a namespace, specify NULL as the namespace to create an anonymous box.

+
TypeC/C++ pre-processor macro (pseudo-function)
ParametersnamespaceThe namespace of the box
+ +Example: +```C +#include "uvisor-lib/uvisor-lib.h" + +/* Configure the secure box. */ +UVISOR_BOX_NAMESPACE("com.example.my-box-name"); +UVISOR_BOX_CONFIG(my_box_name, UVISOR_BOX_STACK_SIZE); +``` + +--- + ## Secure function call ```C @@ -218,40 +259,90 @@ uint32_t secure_sum(uint32_t op1, uint32_t op2) } ``` -## Low-level APIs +## Box Identity -Currently the following low level operations are permitted: +A box identity identifies a security domain uniquely and globally. -1. Interrupt management. +The box identity API can be used to determine the source box of an inbound secure gateway call. This can be useful for implementing complex authorization logic between mutually distrustful security domains. -### Interrupt management +uVisor provides the ability to retrieve the box ID of the current box (`uvisor_box_id_self`), or of the box that most recently called the current box through a secure gateway (`uvisor_box_id_caller`). + +The box ID number is not constant and can change between reboots. But, the box ID number can be used as a token to retrieve a constant string identifier, known as the box namespace. + +A box namespace is a static, box-specific string, that can help identify which box has which ID at run-time. In the future, the box namespace will be guaranteed to be globally unique. + +A full example using this API is available at [example-uvisor-box-id](https://github.com/ARMmbed/example-uvisor-box-id). ```C -void vIRQ_SetVectorX(uint32_t irqn, uint32_t vector, uint32_t flag) +int uvisor_box_id_self(void) ``` - + + - - - + + +
DescriptionRegister an ISR to the currently active box, with the ability to specify permissions associated with the IRQn slotGet the ID of the current box
Parameters
uint32_t irqn
IRQnReturn valueThe ID of the current box
+ +--- + +```C +int uvisor_box_id_caller(void) +``` + + - - + + - - + +
uint32_t vector
Interrupt handler; if 0 the IRQn slot is de-registered for the current - boxDescriptionGet the ID of the box that is calling the current box through the most recent secure gateway
uint32_t flag
Permission flag (currently not implemented)Return valueThe ID of the caller box, or -1 if there is no secure gateway calling box
--- +```C +int uvisor_box_namespace(int box_id, char *box_namespace, size_t length) +``` + + + + + + + + + + + + + + + + + + + + + + + +
DescriptionCopy the namespace of the specified box to the provided buffer.
Return valueReturn how many bytes were copied into box_namespace. Return UVISOR_ERROR_INVALID_BOX_ID if the provided box ID is invalid. Return UVISOR_ERROR_BUFFER_TOO_SMALL if the provided box_namespace is too small to hold MAX_BOX_NAMESPACE_LENGTH bytes. Return UVISOR_ERROR_BOX_NAMESPACE_ANONYMOUS if the box is anonymous.
Parametersint box_idThe ID of the box you want to retrieve the namespace of
char *box_namespaceThe buffer where the box namespace will be copied to
size_t lengthThe length in bytes of the provided box_namespace buffer
+ +## Low-level APIs + +Currently the following low level operations are permitted: + +1. Interrupt management. + +### Interrupt management + ```C void vIRQ_SetVector(uint32_t irqn, uint32_t vector) ``` @@ -272,12 +363,6 @@ void vIRQ_SetVector(uint32_t irqn, uint32_t vector) -**Note:** - -1. Currently `vIRQ_SetVectorX` and `vIRQ_SetVector` are mapped to the same function because the argument `flag` is not yet used to determine the permissions associated with the IRQn slot - -2. `vIRQ_SetVector` is especially kept for backward compatibility with `NVIC_SetVector` - --- ```C diff --git a/README.md b/README.md index 0bd8f36..7f3961b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +> **This library is deprecated and kept for historic purposed: please refer to the [main repository](https://github.com/ARMmbed/uvisor) for more information**. + # The `uvisor-lib` library This is a yotta module that provides a packaged version of uVisor for use in ARM mbed OS. diff --git a/module.json b/module.json index 54832ed..aa8a2f6 100644 --- a/module.json +++ b/module.json @@ -1,6 +1,6 @@ { "name": "uvisor-lib", - "version": "2.0.0", + "version": "2.1.0", "description": "Add security features to mbed", "keywords": [ "security" @@ -26,8 +26,9 @@ "type": "Apache-2.0" } ], - "dependencies": { - "cmsis-core": "^1.0.0" - }, + "extraIncludes": [ + "uvisor" + ], + "dependencies": {}, "targetDependencies": {} } diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 58a9a81..1cb4770 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -17,57 +17,51 @@ # ########################################################################### -# Detect yotta build mode. +# uVisor paths +set(UVISOR_ROOT "${CMAKE_CURRENT_LIST_DIR}/../uvisor") +set(UVISOR_API_LIB "${UVISOR_ROOT}/api/lib") +set(UVISOR_API_SRC "${UVISOR_ROOT}/api/src") + +# Detect the yotta build mode. if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") set(UVISOR_MODE "debug") else() set(UVISOR_MODE "release") endif() -# Determine the uVisor binary based on the target. -# Note: We currently only support the GCC toolchain. -set(UVISOR_SUPPORTED false) -if(TARGET_LIKE_GCC) - # Pick the correct folder based on the target family. - if(TARGET_LIKE_KINETIS) - set(UVISOR_FAMILY "kinetis") - elseif(TARGET_LIKE_STM32) - set(UVISOR_FAMILY "stm32") - elseif(TARGET_LIKE_EFM32) - set(UVISOR_FAMILY "efm32") - endif() +# Determine the uVisor configuration based on the target. +# The included files define UVISOR_CONFIGURATION, if any. +file(GLOB UVISOR_LIB_SUPPORT_FILES "${CMAKE_CURRENT_LIST_DIR}/support_*.cmake") +foreach(SUPPORT_FILE ${UVISOR_LIB_SUPPORT_FILES}) + include("${SUPPORT_FILE}") +endforeach(SUPPORT_FILE) - # Infer path to binary. - # The included file defines UVISOR_CONFIGURATION. - include(${UVISOR_FAMILY}/get_configuration.cmake) - if(NOT ("${UVISOR_CONFIGURATION}" STREQUAL "")) - set(UVISOR_SUPPORTED true) - set(UVISOR_BINARY "${UVISOR_FAMILY}/${UVISOR_MODE}/${UVISOR_CONFIGURATION}.o") - endif() +# Determine UVISOR_SUPPORTED. +# Even if a target claims that uVisor is supported (YOTTA_CFG_UVISOR_PRESENT), +# we still need to check that the uVisor code-base actually supports the target +# family. +# Note: Currently we only support targets built with GCC. +if(YOTTA_CFG_UVISOR_PRESENT AND UVISOR_CONFIGURATION AND TARGET_LIKE_GCC) + set(UVISOR_SUPPORTED true) +else() + set(UVISOR_SUPPORTED false) endif() -# Build all files if uVisor is supported, otherwise throw a warning and only -# build unsupported.cpp. if(UVISOR_SUPPORTED) - # uvisor-lib source files - file(GLOB UVISOR_SRC "*.cpp") - - add_library(uvisor-lib - ${UVISOR_BINARY} - ${UVISOR_SRC} - ) + add_library(uvisor-lib) + target_link_libraries(uvisor-lib ${UVISOR_API_LIB}/${UVISOR_FAMILY}/${UVISOR_MODE}/${UVISOR_CONFIGURATION}.a) else() + # Build unsupported.c + add_library(uvisor-lib ${UVISOR_API_SRC}/unsupported.c) + message(WARNING "\n ********************************************************************* * WARNING (uvisor-lib): unsupported platform; your code will still * * work but no security feature is provided; * * UVISOR_DISABLED is set by default * *********************************************************************") - add_library(uvisor-lib - "unsupported.cpp" - ) - # check that the yotta config option has not been mistakenly changed + # Check that the yotta config option has not been mistakenly changed. if((DEFINED YOTTA_CFG_UVISOR_PRESENT) AND ("${YOTTA_CFG_UVISOR_PRESENT}" STREQUAL "1")) message(FATAL_ERROR "\n ********************************************************************* @@ -84,3 +78,7 @@ else() *********************************************************************") endif() endif() + +# This is needed as this library does not specify any source file when the +# target supports uVisor. +set_target_properties(uvisor-lib PROPERTIES LINKER_LANGUAGE C) diff --git a/source/benchmark.cpp b/source/benchmark.cpp deleted file mode 100644 index 4dfc2d0..0000000 --- a/source/benchmark.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2013-2015, 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" - -void uvisor_benchmark_configure(void) -{ - /* in sequence: - * - initialize the benchmarking unit (default overhead = 0) - * - execute a nop measurement to assess the overhead introduced by the - * measurement itself - * - pass the computed overhead to the configuration routine to complete - * the calibration */ - UVISOR_SVC(UVISOR_SVC_ID_BENCHMARK_CFG, "", 0); - uvisor_benchmark_start(); - UVISOR_SVC(UVISOR_SVC_ID_BENCHMARK_CFG, "", uvisor_benchmark_stop()); -} - -void uvisor_benchmark_start(void) -{ - UVISOR_SVC(UVISOR_SVC_ID_BENCHMARK_RST, ""); -} - -uint32_t uvisor_benchmark_stop(void) -{ - return UVISOR_SVC(UVISOR_SVC_ID_BENCHMARK_STOP, ""); -} diff --git a/source/box_config.cpp b/source/box_config.cpp deleted file mode 100644 index 3e9d9f0..0000000 --- a/source/box_config.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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" - -int uvisor_box_id_self(void) -{ - return UVISOR_SVC(UVISOR_SVC_ID_BOX_ID_SELF, ""); -} - -int uvisor_box_id_caller(void) -{ - return UVISOR_SVC(UVISOR_SVC_ID_BOX_ID_CALLER, ""); -} - -int uvisor_box_namespace(int box_id, char *box_namespace, size_t length) -{ - return UVISOR_SVC(UVISOR_SVC_ID_BOX_NAMESPACE_FROM_ID, "", box_id, box_namespace, length); -} diff --git a/source/debug.cpp b/source/debug.cpp deleted file mode 100644 index d097e79..0000000 --- a/source/debug.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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" - -UVISOR_EXTERN void uvisor_debug_init(const TUvisorDebugDriver * const driver) -{ - UVISOR_SVC(UVISOR_SVC_ID_DEBUG_REGISTER_BOX, "", (uint32_t) driver); -} diff --git a/source/disabled.cpp b/source/disabled.cpp deleted file mode 100644 index d41864f..0000000 --- a/source/disabled.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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 "cmsis-core/cmsis_nvic.h" -#include -#include - -/* Symbols exported by the mbed linker script */ -UVISOR_EXTERN uint32_t __uvisor_cfgtbl_ptr_start; -UVISOR_EXTERN uint32_t __uvisor_cfgtbl_ptr_end; -UVISOR_EXTERN uint32_t __uvisor_bss_boxes_start; - -/* The pointer to the uVisor context is declared by each box separately. Each - * declaration will have its own type. */ -UVISOR_EXTERN void *uvisor_ctx; - -/* Flag to check that contexts have been initialized */ -static bool g_initialized = false; - -/* Array with all box context pointers */ -static void *g_uvisor_ctx_array[UVISOR_MAX_BOXES] = {0}; - -/* Call stack - * We must keep the full call stack as otherwise it's not possible to restore a - * box context after a nested call. */ -static uint8_t g_call_stack[UVISOR_SVC_CONTEXT_MAX_DEPTH]; -static int g_call_sp; - -/* Memory position pointer - * It is used to allocate chunks of memories from the allocated pool (uVisor - * boxes' .bss). */ -static uint32_t g_memory_position; - -/* Local vector table - * It holds the box ID and the vector for all registered IRQs, so that a context - * switch can be triggered before serving an interrupt. */ -typedef struct user_irq { - uint8_t box_id; - uint32_t vector; -} user_irq_t; -user_irq_t g_uvisor_disabled_vectors[NVIC_USER_IRQ_NUMBER]; - -static void uvisor_disabled_init_context(void) -{ - uint8_t box_id; - const UvisorBoxConfig **box_cfgtbl; - size_t context_size; - - if (g_initialized) { - return; - } - - /* Iterate over all box configuration tables. */ - box_id = 0; - g_memory_position = (uint32_t) &__uvisor_bss_boxes_start; - for(box_cfgtbl = (const UvisorBoxConfig**) &__uvisor_cfgtbl_ptr_start; - box_cfgtbl < (const UvisorBoxConfig**) &__uvisor_cfgtbl_ptr_end; - box_cfgtbl++) { - /* Read the context size from the box configuration table. */ - context_size = (size_t) (*box_cfgtbl)->context_size; - - /* Initialize box context. */ - /* Note: Also box 0 has technically a context, although we force it to - * be zero. */ - if (!context_size) { - g_uvisor_ctx_array[box_id] = NULL; - } else if (!box_id) { - uvisor_error(USER_NOT_ALLOWED); - } else { - /* The box context is alloated from the chunk of memory reserved to - * uVisor boxes' stacks and contexts. */ - /* FIXME Since we do not currently track separate stacks when uVisor - * is disabled, this involves a good wealth of memory waste. */ - g_uvisor_ctx_array[box_id] = (void *) g_memory_position; - memset((void *) g_memory_position, 0, UVISOR_REGION_ROUND_UP(context_size)); - g_memory_position += UVISOR_REGION_ROUND_UP(context_size); - } - box_id++; - } - - /* Do not run this again. */ - g_initialized = true; -} - -void uvisor_disabled_switch_in(const uint32_t *dst_box_cfgtbl_ptr) -{ - uint8_t dst_box_id; - - /* Read the destination box ID. */ - dst_box_id = (uint8_t) (dst_box_cfgtbl_ptr - &__uvisor_cfgtbl_ptr_start); - - /* Allocate the box contexts if they do not exist yet. */ - if (!g_initialized) { - uvisor_disabled_init_context(); - } - - uvisor_ctx = g_uvisor_ctx_array[dst_box_id]; - - /* Push state. */ - if (g_call_sp >= UVISOR_SVC_CONTEXT_MAX_DEPTH - 1) { - uvisor_error(USER_NOT_ALLOWED); - } - g_call_stack[++g_call_sp] = dst_box_id; -} - -void uvisor_disabled_switch_out(void) -{ - uint8_t src_box_id; - - /* Pop state. */ - if (g_call_sp <= 0) { - uvisor_error(USER_NOT_ALLOWED); - } - src_box_id = g_call_stack[--g_call_sp]; - - /* Restore the source context. */ - uvisor_ctx = g_uvisor_ctx_array[src_box_id]; -} - -static void uvisor_disabled_default_vector(void) -{ - uint32_t irqn, vector; - const uint32_t *dst_box_cfgtbl_ptr; - uint8_t dst_box_id; - int ipsr; - - /* Get current IRQ number, from the IPSR. - * We only allow user IRQs to be registered (NVIC). This is consistent with - * the corresponding API when uVisor is enabled. */ - irqn = 0; - ipsr = ((int) (__get_IPSR() & 0x1FF)) - NVIC_USER_IRQ_OFFSET; - if (ipsr < 0 || ipsr >= NVIC_USER_IRQ_NUMBER) { - uvisor_error(USER_NOT_ALLOWED); - } else { - irqn = (uint32_t) ipsr; - } - - /* Calculate the destination box configuration pointer. */ - dst_box_id = g_uvisor_disabled_vectors[irqn].box_id; - dst_box_cfgtbl_ptr = &__uvisor_cfgtbl_ptr_start + (uint32_t) dst_box_id; - - /* Get the IRQ handler. */ - vector = g_uvisor_disabled_vectors[irqn].vector; - if (!vector) { - uvisor_error(USER_NOT_ALLOWED); - } - - /* Switch contexts before and after executing the IRQ handler. */ - uvisor_disabled_switch_in(dst_box_cfgtbl_ptr); - ((void (*)(void)) vector)(); - uvisor_disabled_switch_out(); -} - -void uvisor_disabled_set_vector(uint32_t irqn, uint32_t vector) -{ - uint8_t box_id; - - /* Check IRQn. - * We only allow user IRQs to be registered (NVIC). This is consistent with - * the corresponding API when uVisor is enabled. */ - if (irqn >= NVIC_USER_IRQ_NUMBER) { - uvisor_error(USER_NOT_ALLOWED); - } - - /* Get current box ID. - * We use the call stack pointer to assess the currently active box ID. */ - box_id = g_call_stack[g_call_sp]; - - /* Register IRQ. - * If vector is 0 it corresponds to a de-registration. */ - g_uvisor_disabled_vectors[irqn].box_id = vector ? box_id : 0; - g_uvisor_disabled_vectors[irqn].vector = vector; - - /* Register default handler. - * The default handler performs the context switch around the actual user - * handler. */ - NVIC_SetVector((IRQn_Type) irqn, (uint32_t) &uvisor_disabled_default_vector); -} - -uint32_t uvisor_disabled_get_vector(uint32_t irqn) -{ - /* Check IRQn. - * We only allow user IRQs to be registered (NVIC). This is consistent with - * the corresponding API when uVisor is enabled. */ - if (irqn >= NVIC_USER_IRQ_NUMBER) { - uvisor_error(USER_NOT_ALLOWED); - } - - return g_uvisor_disabled_vectors[irqn].vector; -} diff --git a/source/efm32/debug/configuration_efm32_m3_p1.o b/source/efm32/debug/configuration_efm32_m3_p1.o deleted file mode 100644 index 055c4b7..0000000 Binary files a/source/efm32/debug/configuration_efm32_m3_p1.o and /dev/null differ diff --git a/source/efm32/debug/configuration_efm32_m4_p1.o b/source/efm32/debug/configuration_efm32_m4_p1.o deleted file mode 100644 index 01b7bb4..0000000 Binary files a/source/efm32/debug/configuration_efm32_m4_p1.o and /dev/null differ diff --git a/source/efm32/release/configuration_efm32_m3_p1.o b/source/efm32/release/configuration_efm32_m3_p1.o deleted file mode 100644 index 4c083a9..0000000 Binary files a/source/efm32/release/configuration_efm32_m3_p1.o and /dev/null differ diff --git a/source/efm32/release/configuration_efm32_m4_p1.o b/source/efm32/release/configuration_efm32_m4_p1.o deleted file mode 100644 index a8ec541..0000000 Binary files a/source/efm32/release/configuration_efm32_m4_p1.o and /dev/null differ diff --git a/source/efm32/version.txt b/source/efm32/version.txt deleted file mode 100644 index 78bc1ab..0000000 --- a/source/efm32/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.10.0 diff --git a/source/error.cpp b/source/error.cpp deleted file mode 100644 index 915469a..0000000 --- a/source/error.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2015, 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" - -void uvisor_error(THaltUserError reason) -{ - UVISOR_SVC(UVISOR_SVC_ID_HALT_USER_ERR, "", reason); -} diff --git a/source/interrupts.cpp b/source/interrupts.cpp deleted file mode 100644 index 828948b..0000000 --- a/source/interrupts.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2013-2015, 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" - -void vIRQ_SetVectorX(uint32_t irqn, uint32_t vector, uint32_t flag) -{ - if(__uvisor_mode == 0) { - uvisor_disabled_set_vector(irqn, vector); - } - else { - UVISOR_SVC(UVISOR_SVC_ID_ISR_SET, "", irqn, vector, flag); - } -} - -void vIRQ_SetVector(uint32_t irqn, uint32_t vector) -{ - vIRQ_SetVectorX(irqn, vector, 0); -} - -uint32_t vIRQ_GetVector(uint32_t irqn) -{ - if(__uvisor_mode == 0) { - return uvisor_disabled_get_vector(irqn); - } - else { - return UVISOR_SVC(UVISOR_SVC_ID_ISR_GET, "", irqn); - } -} - -void vIRQ_EnableIRQ(uint32_t irqn) -{ - if(__uvisor_mode == 0) { - NVIC_EnableIRQ((IRQn_Type) irqn); - } - else { - UVISOR_SVC(UVISOR_SVC_ID_IRQ_ENABLE, "", irqn); - } -} - -void vIRQ_DisableIRQ(uint32_t irqn) -{ - if(__uvisor_mode == 0) { - NVIC_DisableIRQ((IRQn_Type) irqn); - } - else { - UVISOR_SVC(UVISOR_SVC_ID_IRQ_DISABLE, "", irqn); - } -} - -void vIRQ_ClearPendingIRQ(uint32_t irqn) -{ - if(__uvisor_mode == 0) { - NVIC_ClearPendingIRQ((IRQn_Type) irqn); - } - else { - UVISOR_SVC(UVISOR_SVC_ID_IRQ_PEND_CLR, "", irqn); - } -} - -void vIRQ_SetPendingIRQ(uint32_t irqn) -{ - if(__uvisor_mode == 0) { - NVIC_SetPendingIRQ((IRQn_Type) irqn); - } - else { - UVISOR_SVC(UVISOR_SVC_ID_IRQ_PEND_SET, "", irqn); - } -} - -uint32_t vIRQ_GetPendingIRQ(uint32_t irqn) -{ - if(__uvisor_mode == 0) { - return NVIC_GetPendingIRQ((IRQn_Type) irqn); - } - else { - return UVISOR_SVC(UVISOR_SVC_ID_IRQ_PEND_GET, "", irqn); - } -} - -void vIRQ_SetPriority(uint32_t irqn, uint32_t priority) -{ - if(__uvisor_mode == 0) { - NVIC_SetPriority((IRQn_Type) irqn, priority); - } - else { - UVISOR_SVC(UVISOR_SVC_ID_IRQ_PRIO_SET, "", irqn, priority); - } -} - -uint32_t vIRQ_GetPriority(uint32_t irqn) -{ - if(__uvisor_mode == 0) { - return NVIC_GetPriority((IRQn_Type) irqn); - } - else { - return UVISOR_SVC(UVISOR_SVC_ID_IRQ_PRIO_GET, "", irqn); - } -} - -int vIRQ_GetLevel(void) -{ - /* if uVisor is disabled we use the standard priority levels */ - if (__uvisor_mode == 0) { - /* check if an IRQn is active (an ISR is being served) */ - uint32_t ipsr = __get_IPSR(); - int irqn = (int) (ipsr & 0x1FF) - NVIC_USER_IRQ_OFFSET; - if (irqn >= NVIC_NUM_VECTORS || !ipsr || !NVIC_GetActive((IRQn_Type) irqn)) { - return -1; - } - - /* return the priority level of the active IRQ */ - /* if we are in a system interrupt we do not provide the actual - * priority level, which is usually negative, since we already use -1 - * for stating "no IRQn is active". This is consistent with the - * behavior of the actual uVisor-managed API, as this call will never - * come from a system interrupt. The caller can still use this - * information to assess that an IRQn is actually active (0 = lowest - * priority) */ - if (irqn < 0) { - return 0; - } - else { - return NVIC_GetPriority((IRQn_Type) irqn); - } - } - else { - return UVISOR_SVC(UVISOR_SVC_ID_IRQ_LEVEL_GET, ""); - } -} diff --git a/source/kinetis/debug/configuration_kinetis_m4_0x1fff0000.o b/source/kinetis/debug/configuration_kinetis_m4_0x1fff0000.o deleted file mode 100644 index 18b7cfc..0000000 Binary files a/source/kinetis/debug/configuration_kinetis_m4_0x1fff0000.o and /dev/null differ diff --git a/source/kinetis/release/configuration_kinetis_m4_0x1fff0000.o b/source/kinetis/release/configuration_kinetis_m4_0x1fff0000.o deleted file mode 100644 index 0cb40cf..0000000 Binary files a/source/kinetis/release/configuration_kinetis_m4_0x1fff0000.o and /dev/null differ diff --git a/source/kinetis/version.txt b/source/kinetis/version.txt deleted file mode 100644 index 78bc1ab..0000000 --- a/source/kinetis/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.10.0 diff --git a/source/stm32/debug/configuration_stm32_m4_0x10000000_0x0.o b/source/stm32/debug/configuration_stm32_m4_0x10000000_0x0.o deleted file mode 100644 index 3d48723..0000000 Binary files a/source/stm32/debug/configuration_stm32_m4_0x10000000_0x0.o and /dev/null differ diff --git a/source/stm32/release/configuration_stm32_m4_0x10000000_0x0.o b/source/stm32/release/configuration_stm32_m4_0x10000000_0x0.o deleted file mode 100644 index fca7650..0000000 Binary files a/source/stm32/release/configuration_stm32_m4_0x10000000_0x0.o and /dev/null differ diff --git a/source/stm32/version.txt b/source/stm32/version.txt deleted file mode 100644 index 78bc1ab..0000000 --- a/source/stm32/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.10.0 diff --git a/source/support_nuvoton.cmake b/source/support_nuvoton.cmake new file mode 100644 index 0000000..817a5c7 --- /dev/null +++ b/source/support_nuvoton.cmake @@ -0,0 +1,28 @@ +########################################################################### +# +# Copyright (c) 2016-2017, Nuvoton, 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. +# +########################################################################### + +if(TARGET_LIKE_NUC472 OR TARGET_LIKE_NUC442) + # Nuvoton NUC472/442 series + set(UVISOR_FAMILY "nuc472") + set(UVISOR_CONFIGURATION "configuration_nuc472_m4_0x20000000_0x0") +elseif(TARGET_LIKE_M451 OR TARGET_LIKE_M452 OR TARGET_LIKE_M453) + # Nuvoton M451 series + set(UVISOR_FAMILY "m451") + set(UVISOR_CONFIGURATION "configuration_m451_m4_0x20000000_0x0") +endif() diff --git a/source/stm32/get_configuration.cmake b/source/support_nxp.cmake similarity index 75% rename from source/stm32/get_configuration.cmake rename to source/support_nxp.cmake index f81eec0..6fb716a 100644 --- a/source/stm32/get_configuration.cmake +++ b/source/support_nxp.cmake @@ -1,6 +1,6 @@ ########################################################################### # -# Copyright (c) 2016, ARM Limited, All Rights Reserved +# Copyright (c) 2013-2016, ARM Limited, All Rights Reserved # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -17,6 +17,10 @@ # ########################################################################### -if(TARGET_LIKE_STM32F429ZI OR TARGET_LIKE_STM32F429XI) - set(UVISOR_CONFIGURATION "configuration_stm32_m4_0x10000000_0x0") +# NXP Kinetis +if(TARGET_LIKE_KINETIS) + set(UVISOR_FAMILY "kinetis") + if(TARGET_LIKE_MK64FN1M0VMD12) + set(UVISOR_CONFIGURATION "configuration_kinetis_m4_0x1fff0000") + endif() endif() diff --git a/source/efm32/get_configuration.cmake b/source/support_silicon_labs.cmake similarity index 74% rename from source/efm32/get_configuration.cmake rename to source/support_silicon_labs.cmake index 716b128..2b1002b 100644 --- a/source/efm32/get_configuration.cmake +++ b/source/support_silicon_labs.cmake @@ -17,10 +17,12 @@ # ########################################################################### -if(TARGET_LIKE_EFM32 AND YOTTA_CFG_UVISOR_PRESENT) - if(TARGET_LIKE_CORTEX_M3) - set(UVISOR_CONFIGURATION "configuration_efm32_m3_p1") - elseif(TARGET_LIKE_CORTEX_M4) - set(UVISOR_CONFIGURATION "configuration_efm32_m4_p1") - endif() +# Silicon Labs EFM32 +if(TARGET_LIKE_EFM32) + set(UVISOR_FAMILY "efm32") + if(TARGET_LIKE_CORTEX_M3) + set(UVISOR_CONFIGURATION "configuration_efm32_m3_p1") + elseif(TARGET_LIKE_CORTEX_M4) + set(UVISOR_CONFIGURATION "configuration_efm32_m4_p1") + endif() endif() diff --git a/source/kinetis/get_configuration.cmake b/source/support_stmicroelectronics.cmake similarity index 72% rename from source/kinetis/get_configuration.cmake rename to source/support_stmicroelectronics.cmake index b8360ed..17c0735 100644 --- a/source/kinetis/get_configuration.cmake +++ b/source/support_stmicroelectronics.cmake @@ -1,6 +1,6 @@ ########################################################################### # -# Copyright (c) 2016, ARM Limited, All Rights Reserved +# Copyright (c) 2013-2016, ARM Limited, All Rights Reserved # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -17,6 +17,10 @@ # ########################################################################### -if(TARGET_LIKE_MK64FN1M0VMD12) - set(UVISOR_CONFIGURATION "configuration_kinetis_m4_0x1fff0000") +# STMicroelectronics STM32 +if(TARGET_LIKE_STM32) + set(UVISOR_FAMILY "stm32") + if(TARGET_LIKE_STM32F429ZI OR TARGET_LIKE_STM32F429XI) + set(UVISOR_CONFIGURATION "configuration_stm32_m4_0x10000000_0x0") + endif() endif() diff --git a/source/unsupported.cpp b/source/unsupported.cpp deleted file mode 100644 index d654d15..0000000 --- a/source/unsupported.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2015, 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" - -/* uvisor hook for unsupported platforms */ -UVISOR_EXTERN void __attribute__((section(".uvisor.main"))) uvisor_init(void) -{ - return; -} diff --git a/uvisor b/uvisor new file mode 160000 index 0000000..20f87e8 --- /dev/null +++ b/uvisor @@ -0,0 +1 @@ +Subproject commit 20f87e8e5449374552977ecf2051ec7df3f9dae1 diff --git a/uvisor-lib/benchmark.h b/uvisor-lib/benchmark.h deleted file mode 100644 index b9c240f..0000000 --- a/uvisor-lib/benchmark.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2013-2015, 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. - */ -#ifndef __UVISOR_LIB_BENCHMARK_H__ -#define __UVISOR_LIB_BENCHMARK_H__ - -UVISOR_EXTERN void uvisor_benchmark_configure(void); -UVISOR_EXTERN void uvisor_benchmark_start(void); -UVISOR_EXTERN uint32_t uvisor_benchmark_stop(void); - -#endif /* __UVISOR_LIB_BENCHMARK_H__ */ diff --git a/uvisor-lib/box_config.h b/uvisor-lib/box_config.h deleted file mode 100644 index 41b8530..0000000 --- a/uvisor-lib/box_config.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2013-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. - */ -#ifndef __UVISOR_LIB_BOX_CONFIG_H__ -#define __UVISOR_LIB_BOX_CONFIG_H__ - -#include - -UVISOR_EXTERN const uint32_t __uvisor_mode; - -#define UVISOR_DISABLED 0 -#define UVISOR_PERMISSIVE 1 -#define UVISOR_ENABLED 2 - -/* The maximum box namespace length is 37 so that it is exactly big enough for - * a human-readable hex string GUID (as formatted by RFC 4122) followed by a - * terminating NUL. */ -#define UVISOR_MAX_BOX_NAMESPACE_LENGTH 37 - -#define UVISOR_SET_MODE(mode) \ - UVISOR_SET_MODE_ACL_COUNT(mode, NULL, 0) - -#define UVISOR_SET_MODE_ACL(mode, acl_list) \ - UVISOR_SET_MODE_ACL_COUNT(mode, acl_list, UVISOR_ARRAY_COUNT(acl_list)) - -#define UVISOR_SET_MODE_ACL_COUNT(mode, acl_list, acl_list_count) \ - uint8_t __attribute__((section(".keep.uvisor.bss.boxes"), aligned(32))) __reserved_stack[UVISOR_STACK_BAND_SIZE]; \ - \ - UVISOR_EXTERN const uint32_t __uvisor_mode = (mode); \ - \ - static const __attribute__((section(".keep.uvisor.cfgtbl"), aligned(4))) UvisorBoxConfig main_cfg = { \ - UVISOR_BOX_MAGIC, \ - UVISOR_BOX_VERSION, \ - 0, \ - 0, \ - NULL, \ - acl_list, \ - acl_list_count \ - }; \ - \ - extern const __attribute__((section(".keep.uvisor.cfgtbl_ptr_first"), aligned(4))) void * const main_cfg_ptr = &main_cfg; - -/* this macro selects an overloaded macro (variable number of arguments) */ -#define __UVISOR_BOX_MACRO(_1, _2, _3, _4, NAME, ...) NAME - -#define __UVISOR_BOX_CONFIG(box_name, acl_list, acl_list_count, stack_size, context_size) \ - \ - uint8_t __attribute__((section(".keep.uvisor.bss.boxes"), aligned(32))) \ - box_name ## _reserved[UVISOR_STACK_SIZE_ROUND(((UVISOR_MIN_STACK(stack_size) + (context_size))*8)/6)]; \ - \ - static const __attribute__((section(".keep.uvisor.cfgtbl"), aligned(4))) UvisorBoxConfig box_name ## _cfg = { \ - UVISOR_BOX_MAGIC, \ - UVISOR_BOX_VERSION, \ - UVISOR_MIN_STACK(stack_size), \ - context_size, \ - __uvisor_box_namespace, \ - acl_list, \ - acl_list_count \ - }; \ - \ - extern const __attribute__((section(".keep.uvisor.cfgtbl_ptr"), aligned(4))) void * const box_name ## _cfg_ptr = &box_name ## _cfg; - -#define __UVISOR_BOX_CONFIG_NOCONTEXT(box_name, acl_list, stack_size) \ - __UVISOR_BOX_CONFIG(box_name, acl_list, UVISOR_ARRAY_COUNT(acl_list), stack_size, 0) \ - -#define __UVISOR_BOX_CONFIG_CONTEXT(box_name, acl_list, stack_size, context_type) \ - __UVISOR_BOX_CONFIG(box_name, acl_list, UVISOR_ARRAY_COUNT(acl_list), stack_size, sizeof(context_type)) \ - UVISOR_EXTERN context_type * const uvisor_ctx; - -#define __UVISOR_BOX_CONFIG_NOACL(box_name, stack_size, context_type) \ - __UVISOR_BOX_CONFIG(box_name, NULL, 0, stack_size, sizeof(context_type)) \ - UVISOR_EXTERN context_type * const uvisor_ctx; - -#define __UVISOR_BOX_CONFIG_NOACL_NOCONTEXT(box_name, stack_size) \ - __UVISOR_BOX_CONFIG(box_name, NULL, 0, stack_size, 0) - -#define UVISOR_BOX_CONFIG_ACL(...) \ - __UVISOR_BOX_MACRO(__VA_ARGS__, __UVISOR_BOX_CONFIG_CONTEXT, \ - __UVISOR_BOX_CONFIG_NOCONTEXT, \ - __UVISOR_BOX_CONFIG_NOACL_NOCONTEXT)(__VA_ARGS__) - -#define UVISOR_BOX_CONFIG_CTX(...) \ - __UVISOR_BOX_MACRO(__VA_ARGS__, __UVISOR_BOX_CONFIG_CONTEXT, \ - __UVISOR_BOX_CONFIG_NOACL, \ - __UVISOR_BOX_CONFIG_NOACL_NOCONTEXT)(__VA_ARGS__) - -#define UVISOR_BOX_CONFIG(...) \ - UVISOR_BOX_CONFIG_ACL(__VA_ARGS__) - -/* Use this macro before box defintion (for example, UVISOR_BOX_CONFIG) to - * define the name of your box. If you don't want a name, use this macro with - * box_namespace as NULL. */ -#define UVISOR_BOX_NAMESPACE(box_namespace) \ - static const char *const __uvisor_box_namespace = box_namespace - - -/* Return the numeric box ID of the current box. */ -UVISOR_EXTERN int uvisor_box_id_self(void); - -/* Return the numeric box ID of the box that is calling through the most recent - * secure gateway. Return -1 if there is no secure gateway calling box. */ -UVISOR_EXTERN int uvisor_box_id_caller(void); - -/* Copy the box namespace of the specified box ID to the memory provided by - * box_namespace. The box_namespace's length must be at least - * MAX_BOX_NAMESPACE_LENGTH bytes. Return how many bytes were copied into - * box_namespace. Return UVISOR_ERROR_INVALID_BOX_ID if the provided box ID is - * invalid. Return UVISOR_ERROR_BUFFER_TOO_SMALL if the provided box_namespace - * is too small to hold MAX_BOX_NAMESPACE_LENGTH bytes. Return - * UVISOR_ERROR_BOX_NAMESPACE_ANONYMOUS if the box is anonymous. */ -UVISOR_EXTERN int uvisor_box_namespace(int box_id, char *box_namespace, size_t length); - -#endif /* __UVISOR_LIB_BOX_CONFIG_H__ */ diff --git a/uvisor-lib/debug.h b/uvisor-lib/debug.h deleted file mode 100644 index 1402623..0000000 --- a/uvisor-lib/debug.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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. - */ -#ifndef __UVISOR_LIB_DEBUG_H__ -#define __UVISOR_LIB_DEBUG_H__ - -UVISOR_EXTERN void uvisor_debug_init(const TUvisorDebugDriver * const driver); - -#endif /* __UVISOR_LIB_DEBUG_H__ */ diff --git a/uvisor-lib/debug_exports.h b/uvisor-lib/debug_exports.h deleted file mode 100644 index 6aac98e..0000000 --- a/uvisor-lib/debug_exports.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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. - */ -#ifndef __DEBUG_EXPORTS_H__ -#define __DEBUG_EXPORTS_H__ - -#include "uvisor_exports.h" -#include - -/* Debug box driver -- Version 0 - * A constant instance of this struct must be instantiated by the unprivileged - * code to setup a debug box.*/ -typedef struct TUvisorDebugDriver { - uint32_t (*get_version)(void); - void (*halt_error)(int); -} TUvisorDebugDriver; - -/* Number of handlers in the debug box driver */ -#define DEBUG_BOX_HANDLERS_NUMBER (sizeof(TUvisorDebugDriver) / sizeof(void *)) - -#endif /* __DEBUG_EXPORTS_H__ */ diff --git a/uvisor-lib/disabled.h b/uvisor-lib/disabled.h deleted file mode 100644 index 0530cf8..0000000 --- a/uvisor-lib/disabled.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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. - */ -#ifndef __UVISOR_LIB_DISABLED_H__ -#define __UVISOR_LIB_DISABLED_H__ - -UVISOR_EXTERN void uvisor_disabled_switch_in(const uint32_t *dst_box_cfgtbl_ptr); -UVISOR_EXTERN void uvisor_disabled_switch_out(void); - -UVISOR_EXTERN void uvisor_disabled_set_vector(uint32_t irqn, uint32_t vector); -UVISOR_EXTERN uint32_t uvisor_disabled_get_vector(uint32_t irqn); - -#endif /* __UVISOR_LIB_DISABLED_H__ */ diff --git a/uvisor-lib/error.h b/uvisor-lib/error.h deleted file mode 100644 index 1014f2d..0000000 --- a/uvisor-lib/error.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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. - */ -#ifndef __UVISOR_LIB_ERROR_H__ -#define __UVISOR_LIB_ERROR_H__ - -#define UVISOR_ERROR_INVALID_BOX_ID (-2) -#define UVISOR_ERROR_BUFFER_TOO_SMALL (-3) -#define UVISOR_ERROR_BOX_NAMESPACE_ANONYMOUS (-4) - -UVISOR_EXTERN void uvisor_error(THaltUserError reason); - -#endif /* __UVISOR_LIB_ERROR_H__ */ diff --git a/uvisor-lib/halt_exports.h b/uvisor-lib/halt_exports.h deleted file mode 100644 index 7bd2ec7..0000000 --- a/uvisor-lib/halt_exports.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2015, 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. - */ -#ifndef __HALT_EXPORTS_H__ -#define __HALT_EXPORTS_H__ - -typedef enum { - USER_NOT_ALLOWED = 1, -} THaltUserError; - -#endif/*__HALT_EXPORTS_H__*/ diff --git a/uvisor-lib/interrupts.h b/uvisor-lib/interrupts.h deleted file mode 100644 index 162a4f1..0000000 --- a/uvisor-lib/interrupts.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2013-2015, 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. - */ -#ifndef __UVISOR_LIB_INTERRUPTS_H__ -#define __UVISOR_LIB_INTERRUPTS_H__ - -UVISOR_EXTERN void vIRQ_SetVectorX(uint32_t irqn, uint32_t vector, uint32_t flag); -UVISOR_EXTERN void vIRQ_SetVector(uint32_t irqn, uint32_t vector); -UVISOR_EXTERN uint32_t vIRQ_GetVector(uint32_t irqn); -UVISOR_EXTERN void vIRQ_EnableIRQ(uint32_t irqn); -UVISOR_EXTERN void vIRQ_DisableIRQ(uint32_t irqn); -UVISOR_EXTERN void vIRQ_ClearPendingIRQ(uint32_t irqn); -UVISOR_EXTERN void vIRQ_SetPendingIRQ(uint32_t irqn); -UVISOR_EXTERN uint32_t vIRQ_GetPendingIRQ(uint32_t irqn); -UVISOR_EXTERN void vIRQ_SetPriority(uint32_t irqn, uint32_t priority); -UVISOR_EXTERN uint32_t vIRQ_GetPriority(uint32_t irqn); -UVISOR_EXTERN int vIRQ_GetLevel(void); - -#endif /* __UVISOR_LIB_INTERRUPTS_H__ */ diff --git a/uvisor-lib/override.h b/uvisor-lib/override.h index be72fa4..f7653fc 100644 --- a/uvisor-lib/override.h +++ b/uvisor-lib/override.h @@ -14,19 +14,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* note: only include this header file if you need to use code in which you do not - * want to rename NVIC APIs into vIRQ APIs; it must be included directly in the - * source file and as the last header file; inclusion is protected by a guard which - * is dependent on the YOTTA_CFG_UVISOR_PRESENT symbol (set in the target) and the - * UVISOR_NO_HOOKS symbol (defined by uVisor) */ - #ifndef __UVISOR_LIB_OVERRIDE_H__ #define __UVISOR_LIB_OVERRIDE_H__ +/* Note: Only include this header file if you need to use code in which you do + * not want to rename NVIC APIs into vIRQ APIs. It must be included directly in + * the source file and as the last header file. Inclusion is protected by a + * guard which is dependent on the YOTTA_CFG_UVISOR_PRESENT symbol (set in the + * target) and the UVISOR_NO_HOOKS symbol (defined by uVisor) */ + #include -extern void vIRQ_SetVectorX(uint32_t irqn, uint32_t vector, uint32_t flag); extern void vIRQ_SetVector(uint32_t irqn, uint32_t vector); extern uint32_t vIRQ_GetVector(uint32_t irqn); extern void vIRQ_EnableIRQ(uint32_t irqn); @@ -37,9 +35,9 @@ extern uint32_t vIRQ_GetPendingIRQ(uint32_t irqn); extern void vIRQ_SetPriority(uint32_t irqn, uint32_t priority); extern uint32_t vIRQ_GetPriority(uint32_t irqn); -#if YOTTA_CFG_UVISOR_PRESENT == 1 && !defined(UVISOR_NO_HOOKS) +#if defined(YOTTA_CFG_UVISOR_PRESENT) && YOTTA_CFG_UVISOR_PRESENT == 1 && !defined(UVISOR_NO_HOOKS) -/* re-definition of NVIC APIs supported by uVisor */ +/* Re-definition of NVIC APIs supported by uVisor */ #define NVIC_ClearPendingIRQ(irqn) vIRQ_ClearPendingIRQ((uint32_t) (irqn)) #define NVIC_SetPendingIRQ(irqn) vIRQ_SetPendingIRQ((uint32_t) (irqn)) #define NVIC_GetPendingIRQ(irqn) vIRQ_GetPendingIRQ((uint32_t) (irqn)) @@ -50,6 +48,6 @@ extern uint32_t vIRQ_GetPriority(uint32_t irqn); #define NVIC_EnableIRQ(irqn) vIRQ_EnableIRQ((uint32_t) (irqn)) #define NVIC_DisableIRQ(irqn) vIRQ_DisableIRQ((uint32_t) (irqn)) -#endif /* YOTTA_CFG_UVISOR_PRESENT == 1 && !defined(UVISOR_NO_HOOKS) */ +#endif /* defined(YOTTA_CFG_UVISOR_PRESENT) && YOTTA_CFG_UVISOR_PRESENT == 1 && !defined(UVISOR_NO_HOOKS) */ #endif /* __UVISOR_LIB_OVERRIDE_H__ */ diff --git a/uvisor-lib/register_gateway.h b/uvisor-lib/register_gateway.h deleted file mode 100644 index 24338f2..0000000 --- a/uvisor-lib/register_gateway.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2015-2015, 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. - */ -#ifndef __UVISOR_LIB_REGISTER_GATEWAY_H__ -#define __UVISOR_LIB_REGISTER_GATEWAY_H__ - -/* register gateway operations */ -/* note: do not use special characters as these numbers will be stringified */ -#define UVISOR_OP_READ(op) (op) -#define UVISOR_OP_WRITE(op) ((1 << 4) | (op)) -#define UVISOR_OP_NOP 0x0 -#define UVISOR_OP_AND 0x1 -#define UVISOR_OP_OR 0x2 -#define UVISOR_OP_XOR 0x3 - -/* default mask for whole register operatins */ -#define __UVISOR_OP_DEFAULT_MASK 0x0 - -/* register gateway metadata */ -#if defined(__CC_ARM) - -/* TODO/FIXME */ - -#elif defined(__GNUC__) - -/* 1 argument: simple read, no mask */ -#define __UVISOR_REGISTER_GATEWAY_METADATA1(src_box, addr) \ - "b.n skip_args%=\n" \ - ".word " UVISOR_TO_STRING(UVISOR_SVC_GW_MAGIC) "\n" \ - ".word " UVISOR_TO_STRING(addr) "\n" \ - ".word " UVISOR_TO_STRING(src_box) "_cfg_ptr\n" \ - ".word " UVISOR_TO_STRING(UVISOR_OP_READ(UVISOR_OP_NOP)) "\n" \ - ".word " UVISOR_TO_STRING(__UVISOR_OP_DEFAULT_MASK) "\n" \ - "skip_args%=:\n" - -/* 2 arguments: simple write, no mask */ -#define __UVISOR_REGISTER_GATEWAY_METADATA2(src_box, addr, val) \ - "b.n skip_args%=\n" \ - ".word " UVISOR_TO_STRING(UVISOR_SVC_GW_MAGIC) "\n" \ - ".word " UVISOR_TO_STRING(addr) "\n" \ - ".word " UVISOR_TO_STRING(src_box) "_cfg_ptr\n" \ - ".word " UVISOR_TO_STRING(UVISOR_OP_WRITE(UVISOR_OP_NOP)) "\n" \ - ".word " UVISOR_TO_STRING(__UVISOR_OP_DEFAULT_MASK) "\n" \ - "skip_args%=:\n" - -/* 3 arguments: masked read */ -#define __UVISOR_REGISTER_GATEWAY_METADATA3(src_box, addr, op, mask) \ - "b.n skip_args%=\n" \ - ".word " UVISOR_TO_STRING(UVISOR_SVC_GW_MAGIC) "\n" \ - ".word " UVISOR_TO_STRING(addr) "\n" \ - ".word " UVISOR_TO_STRING(src_box) "_cfg_ptr\n" \ - ".word " UVISOR_TO_STRING(UVISOR_OP_READ(op)) "\n" \ - ".word " UVISOR_TO_STRING(mask) "\n" \ - "skip_args%=:\n" - -/* 4 arguments: masked write */ -#define __UVISOR_REGISTER_GATEWAY_METADATA4(src_box, addr, val, op, mask) \ - "b.n skip_args%=\n" \ - ".word " UVISOR_TO_STRING(UVISOR_SVC_GW_MAGIC) "\n" \ - ".word " UVISOR_TO_STRING(addr) "\n" \ - ".word " UVISOR_TO_STRING(src_box) "_cfg_ptr\n" \ - ".word " UVISOR_TO_STRING(UVISOR_OP_WRITE(op)) "\n" \ - ".word " UVISOR_TO_STRING(mask) "\n" \ - "skip_args%=:\n" - -#endif /* __CC_ARM or __GNUC__ */ - -#define __UVISOR_REGISTER_GATEWAY_METADATA(src_box, ...) \ - __UVISOR_MACRO_SELECT(_0, ##__VA_ARGS__, __UVISOR_REGISTER_GATEWAY_METADATA4, \ - __UVISOR_REGISTER_GATEWAY_METADATA3, \ - __UVISOR_REGISTER_GATEWAY_METADATA2, \ - __UVISOR_REGISTER_GATEWAY_METADATA1, \ - /* no macro for 0 args */ )(src_box, ##__VA_ARGS__) - -/* register-level gateway - read */ -/* FIXME currently only a hardcoded 32bit constant can be used for the addr field */ -#define uvisor_read(src_box, ...) \ - ({ \ - uint32_t res = UVISOR_SVC(UVISOR_SVC_ID_REGISTER_GATEWAY, \ - __UVISOR_REGISTER_GATEWAY_METADATA(src_box, ##__VA_ARGS__)); \ - res; \ - }) - -/* register-level gateway - write */ -#define uvisor_write(src_box, addr, val, ...) \ - ({ \ - UVISOR_SVC(UVISOR_SVC_ID_REGISTER_GATEWAY, \ - __UVISOR_REGISTER_GATEWAY_METADATA(src_box, addr, val, ##__VA_ARGS__), \ - val); \ - }) - -#endif /* __UVISOR_LIB_REGISTER_GATEWAY_H__ */ diff --git a/uvisor-lib/secure_access.h b/uvisor-lib/secure_access.h deleted file mode 100644 index eefcd14..0000000 --- a/uvisor-lib/secure_access.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2015, 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. - */ -#ifndef __UVISOR_LIB_SECURE_ACCESS_H__ -#define __UVISOR_LIB_SECURE_ACCESS_H__ - -/* the switch statement will be optimised away since the compiler already knows - * the sizeof(type) */ -#define ADDRESS_WRITE(type, addr, val) \ - { \ - switch(sizeof(type)) \ - { \ - case 4: \ - uvisor_write32((uint32_t volatile * volatile) (addr), (uint32_t) (val)); \ - break; \ - case 2: \ - uvisor_write16((uint16_t volatile * volatile) (addr), (uint16_t) (val)); \ - break; \ - case 1: \ - uvisor_write8((uint8_t volatile * volatile) (addr), (uint8_t ) (val)); \ - break; \ - default: \ - uvisor_error(USER_NOT_ALLOWED); \ - break; \ - } \ - } - -/* the conditional statement will be optimised away since the compiler already - * knows the sizeof(type) */ -#define ADDRESS_READ(type, addr) \ - (sizeof(type) == 4 ? uvisor_read32((uint32_t volatile * volatile) (addr)) : \ - sizeof(type) == 2 ? uvisor_read16((uint16_t volatile * volatile) (addr)) : \ - sizeof(type) == 1 ? uvisor_read8((uint8_t volatile * volatile) (addr)) : 0) - -#define UNION_READ(type, addr, fieldU, fieldB) \ - ({ \ - type res; \ - res.fieldU = ADDRESS_READ(type, addr); \ - res.fieldB; \ - }) - -static inline UVISOR_FORCEINLINE void uvisor_write32(uint32_t volatile * volatile addr, uint32_t val) -{ - UVISOR_ASM_MEMORY_ACCESS(str, uint32_t, addr, val); -} - -static inline UVISOR_FORCEINLINE void uvisor_write16(uint16_t volatile * volatile addr, uint16_t val) -{ - UVISOR_ASM_MEMORY_ACCESS(strh, uint16_t, addr, val); -} - -static inline UVISOR_FORCEINLINE void uvisor_write8(uint8_t volatile * volatile addr, uint8_t val) -{ - UVISOR_ASM_MEMORY_ACCESS(strb, uint8_t, addr, val); -} - -static inline UVISOR_FORCEINLINE uint32_t uvisor_read32(uint32_t volatile * volatile addr) -{ - return UVISOR_ASM_MEMORY_ACCESS(ldr, uint32_t, addr); -} - -static inline UVISOR_FORCEINLINE uint16_t uvisor_read16(uint16_t volatile * volatile addr) -{ - return UVISOR_ASM_MEMORY_ACCESS(ldrh, uint16_t, addr); -} - -static inline UVISOR_FORCEINLINE uint8_t uvisor_read8(uint8_t volatile * volatile addr) -{ - return UVISOR_ASM_MEMORY_ACCESS(ldrb, uint8_t, addr); -} - -#endif /* __UVISOR_LIB_SECURE_ACCESS_H__ */ diff --git a/uvisor-lib/secure_gateway.h b/uvisor-lib/secure_gateway.h deleted file mode 100644 index ac34824..0000000 --- a/uvisor-lib/secure_gateway.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2013-2015, 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. - */ -#ifndef __UVISOR_LIB_SECURE_GATEWAY_H__ -#define __UVISOR_LIB_SECURE_GATEWAY_H__ - -/* secure gateway metadata */ -#if defined(__CC_ARM) - -/* TODO/FIXME */ - -#elif defined(__GNUC__) - -#define __UVISOR_SECURE_GATEWAY_METADATA(dst_box, dst_fn) \ - "b.n skip_args%=\n" \ - ".word " UVISOR_TO_STRING(UVISOR_SVC_GW_MAGIC) "\n" \ - ".word " UVISOR_TO_STRING(dst_fn) "\n" \ - ".word " UVISOR_TO_STRING(dst_box) "_cfg_ptr\n" \ - "skip_args%=:\n" - -#endif /* __CC_ARM or __GNUC__ */ - -/* secure gateway */ -#define secure_gateway(dst_box, dst_fn, ...) \ - ({ \ - uint32_t res; \ - if (__uvisor_mode != UVISOR_DISABLED) { \ - res = UVISOR_SVC(UVISOR_SVC_ID_SECURE_GATEWAY(UVISOR_MACRO_NARGS(__VA_ARGS__)), \ - __UVISOR_SECURE_GATEWAY_METADATA(dst_box, dst_fn), ##__VA_ARGS__); \ - } \ - else { \ - uvisor_disabled_switch_in((const uint32_t *) &dst_box ## _cfg_ptr); \ - res = UVISOR_FUNCTION_CALL(dst_fn, ##__VA_ARGS__); \ - uvisor_disabled_switch_out(); \ - } \ - res; \ - }) - -#endif /* __UVISOR_LIB_SECURE_GATEWAY_H__ */ diff --git a/uvisor-lib/svc_exports.h b/uvisor-lib/svc_exports.h deleted file mode 100644 index b1db650..0000000 --- a/uvisor-lib/svc_exports.h +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2013-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. - */ -#ifndef __SVC_EXPORTS_H__ -#define __SVC_EXPORTS_H__ - -/* maximum depth of nested context switches - * this includes both IRQn and secure gateways, as they use the same state stack - * for their context switches */ -#define UVISOR_SVC_CONTEXT_MAX_DEPTH 0x10 - -/* An SVCall takes a 8bit immediate, which is used as follows: - * - * For fast APIs: - * - * 7 6 5 4 3 2 1 0 - * .---.---.---.---.---.---.---.---. - * | 1 | N | N | N | h | h | h | h | - * '---'---'---'---'---'---'---'---' - * | |_______| |___________| - * | | | - * | | | - * | | | - * | | (h) Handler index in the hardcoded table (max 16) - * | | - * | (N) Number of arguments to pass to the handler (max 4) - * | - * SVCall mode: Fast - * - * For slow APIs: - * - * 7 6 5 4 3 2 1 0 - * .---.---.---.---.---.---.---.---. - * | 0 | c | c | c | c | c | c | c | - * '---'---'---'---'---'---'---'---' - * | |_______________________| - * | | - * | | - * | (c) Handler index in the custom table (max 128) - * | - * SVCall mode: Slow - */ - -/* 1 bit of the SVCall imm8 field is used to determine the mode, fast/slow. */ -#define UVISOR_SVC_MODE_FAST 1 -#define UVISOR_SVC_MODE_SLOW 0 -#define UVISOR_SVC_MODE_BIT 7 -#define UVISOR_SVC_MODE_MASK ((uint8_t) (1 << UVISOR_SVC_MODE_BIT)) -#define UVISOR_SVC_MODE(mode) ((uint8_t) (((mode) << UVISOR_SVC_MODE_BIT) & UVISOR_SVC_MODE_MASK)) - -/* 7 or 4 bits of the SVCall imm8 field are used to determine the table index, - * depending on the mode, fast/slow. */ -#define UVISOR_SVC_FAST_INDEX_MAX (1 << 4) -#define UVISOR_SVC_SLOW_INDEX_MAX (1 << 7) -#define UVISOR_SVC_FAST_INDEX_BIT 0 -#define UVISOR_SVC_FAST_INDEX_MASK ((uint8_t) (0xF << UVISOR_SVC_FAST_INDEX_BIT)) -#define UVISOR_SVC_SLOW_INDEX_BIT 0 -#define UVISOR_SVC_SLOW_INDEX_MASK ((uint8_t) (0x7F << UVISOR_SVC_SLOW_INDEX_BIT)) -#define UVISOR_SVC_FAST_INDEX(index) ((uint8_t) (((index) << UVISOR_SVC_FAST_INDEX_BIT) & UVISOR_SVC_FAST_INDEX_MASK)) -#define UVISOR_SVC_SLOW_INDEX(index) ((uint8_t) (((index) << UVISOR_SVC_SLOW_INDEX_BIT) & UVISOR_SVC_SLOW_INDEX_MASK)) - -/* When the SVC mode is "fast", the imm8 field also contains a specification of - * the call interface (number of arguments). - * This is needed for context switches, since the stack manipulation routines - * need to know how many arguments to copy from source to destination. */ -#define UVISOR_SVC_FAST_NARGS_BIT 4 -#define UVISOR_SVC_FAST_NARGS_MASK ((uint8_t) (0x7 << UVISOR_SVC_FAST_NARGS_BIT)) -#define UVISOR_SVC_FAST_NARGS(nargs) ((uint8_t) (((nargs) << UVISOR_SVC_FAST_NARGS_BIT) & UVISOR_SVC_FAST_NARGS_MASK)) - -/* Macros to build the SVCall imm8 field. - * For slow APIs only the SVC handler index is needed. - * For fast APIs the SVC handler index and the number of arguments are needed. */ -#define UVISOR_SVC_CUSTOM_TABLE(index) ((uint8_t) (UVISOR_SVC_MODE(UVISOR_SVC_MODE_SLOW) | \ - UVISOR_SVC_SLOW_INDEX(index))) -#define UVISOR_SVC_FIXED_TABLE(index, nargs) ((uint8_t) (UVISOR_SVC_MODE(UVISOR_SVC_MODE_FAST) | \ - UVISOR_SVC_FAST_INDEX(index) | \ - UVISOR_SVC_FAST_NARGS(nargs))) - -/* SVC immediate values for custom table */ -#define UVISOR_SVC_ID_ISR_SET UVISOR_SVC_CUSTOM_TABLE(1) -#define UVISOR_SVC_ID_ISR_GET UVISOR_SVC_CUSTOM_TABLE(2) -#define UVISOR_SVC_ID_IRQ_ENABLE UVISOR_SVC_CUSTOM_TABLE(3) -#define UVISOR_SVC_ID_IRQ_DISABLE UVISOR_SVC_CUSTOM_TABLE(4) -#define UVISOR_SVC_ID_IRQ_PEND_CLR UVISOR_SVC_CUSTOM_TABLE(5) -#define UVISOR_SVC_ID_IRQ_PEND_SET UVISOR_SVC_CUSTOM_TABLE(6) -#define UVISOR_SVC_ID_IRQ_PEND_GET UVISOR_SVC_CUSTOM_TABLE(7) -#define UVISOR_SVC_ID_IRQ_PRIO_SET UVISOR_SVC_CUSTOM_TABLE(8) -#define UVISOR_SVC_ID_IRQ_PRIO_GET UVISOR_SVC_CUSTOM_TABLE(9) -#define UVISOR_SVC_ID_BENCHMARK_CFG UVISOR_SVC_CUSTOM_TABLE(10) -#define UVISOR_SVC_ID_BENCHMARK_RST UVISOR_SVC_CUSTOM_TABLE(11) -#define UVISOR_SVC_ID_BENCHMARK_STOP UVISOR_SVC_CUSTOM_TABLE(12) -#define UVISOR_SVC_ID_HALT_USER_ERR UVISOR_SVC_CUSTOM_TABLE(13) -#define UVISOR_SVC_ID_IRQ_LEVEL_GET UVISOR_SVC_CUSTOM_TABLE(14) -#define UVISOR_SVC_ID_BOX_ID_SELF UVISOR_SVC_CUSTOM_TABLE(15) -#define UVISOR_SVC_ID_BOX_ID_CALLER UVISOR_SVC_CUSTOM_TABLE(16) -#define UVISOR_SVC_ID_BOX_NAMESPACE_FROM_ID UVISOR_SVC_CUSTOM_TABLE(17) -#define UVISOR_SVC_ID_DEBUG_REBOOT UVISOR_SVC_CUSTOM_TABLE(18) -#define UVISOR_SVC_ID_DEBUG_REGISTER_BOX UVISOR_SVC_CUSTOM_TABLE(19) - -/* 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_CX_IN(nargs) UVISOR_SVC_FIXED_TABLE(1, nargs) -#define UVISOR_SVC_ID_CX_OUT UVISOR_SVC_FIXED_TABLE(2, 0) -#define UVISOR_SVC_ID_REGISTER_GATEWAY UVISOR_SVC_FIXED_TABLE(3, 0) - -/* SVC immediate values for hardcoded table (call from privileged) */ -#define UVISOR_SVC_ID_UNVIC_IN UVISOR_SVC_FIXED_TABLE(0, 0) - -/* unprivileged code uses a secure gateway to switch context */ -#define UVISOR_SVC_ID_SECURE_GATEWAY(nargs) UVISOR_SVC_ID_CX_IN(nargs) - -/* macro to execute an SVCall; additional metadata can be provided, which will - * be appended right after the svc instruction */ -/* note: the macro is implicitly overloaded to allow 0 to 4 32bits arguments */ -#if defined(__CC_ARM) - -#elif defined(__GNUC__) - -#define UVISOR_SVC(id, metadata, ...) \ - ({ \ - UVISOR_MACRO_REGS_ARGS(uint32_t, ##__VA_ARGS__); \ - UVISOR_MACRO_REGS_RETVAL(uint32_t, res); \ - asm volatile( \ - "svc %[svc_id]\n" \ - metadata \ - : UVISOR_MACRO_GCC_ASM_OUTPUT(res) \ - : UVISOR_MACRO_GCC_ASM_INPUT(__VA_ARGS__), \ - [svc_id] "I" ((id) & 0xFF) \ - ); \ - res; \ - }) - -#define UVISOR_FUNCTION_CALL(dst_fn, ...) \ - ({ \ - UVISOR_MACRO_REGS_ARGS(uint32_t, ##__VA_ARGS__); \ - UVISOR_MACRO_REGS_RETVAL(uint32_t, res); \ - asm volatile( \ - "bl " UVISOR_TO_STRING(dst_fn) "\n" \ - : UVISOR_MACRO_GCC_ASM_OUTPUT(res) \ - : UVISOR_MACRO_GCC_ASM_INPUT(__VA_ARGS__) \ - ); \ - res; \ - }) - -#endif /* defined(__CC_ARM) || defined(__GNUC__) */ - -#endif/*__SVC_EXPORTS_H__*/ diff --git a/uvisor-lib/svc_gw_exports.h b/uvisor-lib/svc_gw_exports.h deleted file mode 100644 index d708828..0000000 --- a/uvisor-lib/svc_gw_exports.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2013-2015, 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. - */ -#ifndef __SVC_GW_EXPORTS_H__ -#define __SVC_GW_EXPORTS_H__ - -#define UVISOR_SVC_GW_MAGIC 0xABCDABCD /* FIXME update with correct magic */ - -#endif/*__SVC_GW_EXPORTS_H__*/ diff --git a/uvisor-lib/unsupported.h b/uvisor-lib/unsupported.h deleted file mode 100644 index e86f418..0000000 --- a/uvisor-lib/unsupported.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * 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. - */ -#ifndef __UVISOR_LIB_UNSUPPORTED_H__ -#define __UVISOR_LIB_UNSUPPORTED_H__ - -/* uvisor hook for unsupported platforms */ -UVISOR_EXTERN void uvisor_init(void); - -/******************************************************************************* - * re-definitions from: - ******************************************************************************/ - -/* uvisor-lib/box-config.h */ - -UVISOR_EXTERN const uint32_t __uvisor_mode; - -#define UVISOR_DISABLED 0 - -#define UVISOR_SET_MODE(mode) \ - UVISOR_SET_MODE_ACL_COUNT(mode, NULL, 0) - -#define UVISOR_SET_MODE_ACL(mode, acl_list) \ - UVISOR_SET_MODE_ACL_COUNT(mode, acl_list, UVISOR_ARRAY_COUNT(acl_list)) - -#define UVISOR_SET_MODE_ACL_COUNT(mode, acl_list, acl_list_count) \ - UVISOR_EXTERN const uint32_t __uvisor_mode = UVISOR_DISABLED; \ - static const void *main_acl = acl_list; \ - extern const __attribute__((section(".keep.uvisor.cfgtbl_ptr_first"), aligned(4))) void * const main_cfg_ptr = &main_acl; - -#define __UVISOR_BOX_CONFIG_NOCONTEXT(box_name, acl_list, stack_size) \ - static const void *box_acl_ ## box_name = acl_list; \ - extern const __attribute__((section(".keep.uvisor.cfgtbl_ptr"), aligned(4))) void * const box_name ## _cfg_ptr = &box_acl_ ## box_name; - -#define __UVISOR_BOX_CONFIG_CONTEXT(box_name, acl_list, stack_size, context_type) \ - context_type box_ctx_ ## box_name; \ - context_type * const uvisor_ctx = &box_ctx_ ## box_name; \ - static const void *box_acl_ ## box_name = acl_list; \ - const __attribute__((section(".keep.uvisor.cfgtbl_ptr"), aligned(4))) volatile void *box_name ## _cfg_ptr = \ - &box_acl_ ## box_name; - -#define __UVISOR_BOX_MACRO(_1, _2, _3, _4, NAME, ...) NAME -#define UVISOR_BOX_CONFIG(...) \ - __UVISOR_BOX_MACRO(__VA_ARGS__, __UVISOR_BOX_CONFIG_CONTEXT, \ - __UVISOR_BOX_CONFIG_NOCONTEXT)(__VA_ARGS__) - -#define UVISOR_BOX_CONFIG_ACL(...) UVISOR_BOX_CONFIG(__VA_ARGS__) - -#define UVISOR_BOX_CONFIG_CTX(...) UVISOR_BOX_CONFIG(__VA_ARGS__) - -/* uvisor-lib/interrupts.h */ - -#define vIRQ_SetVectorX(irqn, vector, flag) NVIC_SetVector((IRQn_Type) (irqn), (uint32_t) (vector)) -#define vIRQ_SetVector(irqn, vector) NVIC_SetVector((IRQn_Type) (irqn), (uint32_t) (vector)) -#define vIRQ_GetVector(irqn) NVIC_GetVector((IRQn_Type) (irqn)) -#define vIRQ_EnableIRQ(irqn) NVIC_EnableIRQ((IRQn_Type) (irqn)) -#define vIRQ_DisableIRQ(irqn) NVIC_DisableIRQ((IRQn_Type) (irqn)) -#define vIRQ_ClearPendingIRQ(irqn) NVIC_ClearPendingIRQ((IRQn_Type) (irqn)) -#define vIRQ_SetPendingIRQ(irqn) NVIC_SetPendingIRQ((IRQn_Type) (irqn)) -#define vIRQ_GetPendingIRQ(irqn) NVIC_GetPendingIRQ((IRQn_Type) (irqn)) -#define vIRQ_SetPriority(irqn, priority) NVIC_SetPriority((IRQn_Type) (irqn), (uint32_t) (priority)) -#define vIRQ_GetPriority(irqn) NVIC_GetPriority((IRQn_Type) (irqn)) - -/* uvisor-lib/register_gateway.h */ - -#define UVISOR_OP_READ(op) (op) -#define UVISOR_OP_WRITE(op) ((1 << 4) | (op)) -#define UVISOR_OP_NOP 0x0 -#define UVISOR_OP_AND 0x1 -#define UVISOR_OP_OR 0x2 -#define UVISOR_OP_XOR 0x3 - -/* default mask for whole register operatins */ -#define __UVISOR_OP_DEFAULT_MASK 0x0 - -static inline UVISOR_FORCEINLINE uint32_t uvisor_read(uint32_t addr, uint32_t op, uint32_t mask) -{ - switch(op) - { - case UVISOR_OP_READ(UVISOR_OP_NOP): - return *((uint32_t *) addr); - case UVISOR_OP_READ(UVISOR_OP_AND): - return *((uint32_t *) addr) & mask; - case UVISOR_OP_READ(UVISOR_OP_OR): - return *((uint32_t *) addr) | mask; - case UVISOR_OP_READ(UVISOR_OP_XOR): - return *((uint32_t *) addr) ^ mask; - default: - /* FIXME */ - return 0; - } -} - -#define uvisor_read(addr) uvisor_read((uint32_t) (addr), UVISOR_OP_READ(UVISOR_OP_NOP), __UVISOR_OP_DEFAULT_MASK) - -static inline UVISOR_FORCEINLINE void uvisor_write(uint32_t addr, uint32_t val, uint32_t op, uint32_t mask) -{ - switch(op) - { - case UVISOR_OP_WRITE(UVISOR_OP_NOP): - *((uint32_t *) addr) = val; - case UVISOR_OP_WRITE(UVISOR_OP_AND): - *((uint32_t *) addr) &= val | ~mask; - case UVISOR_OP_WRITE(UVISOR_OP_OR): - *((uint32_t *) addr) |= val & mask; - case UVISOR_OP_WRITE(UVISOR_OP_XOR): - *((uint32_t *) addr) ^= val & mask; - default: - /* FIXME */ - return; - } -} - -#define uvisor_write(addr, val) uvisor_write((uint32_t) (addr), (uint32_t) (val), \ - UVISOR_OP_WRITE(UVISOR_OP_NOP), __UVISOR_OP_DEFAULT_MASK) - -/* uvisor-lib/secure_access.h */ - -/* the conditional statement will be optimised away since the compiler already - * knows the sizeof(type) */ -#define ADDRESS_READ(type, addr) \ - (sizeof(type) == 4 ? uvisor_read32((volatile uint32_t *) (addr)) : \ - sizeof(type) == 2 ? uvisor_read16((volatile uint16_t *) (addr)) : \ - sizeof(type) == 1 ? uvisor_read8((volatile uint8_t *) (addr)) : 0) - -/* the switch statement will be optimised away since the compiler already knows - * the sizeof(type) */ -#define ADDRESS_WRITE(type, addr, val) \ - { \ - switch(sizeof(type)) \ - { \ - case 4: \ - uvisor_write32((volatile uint32_t *) (addr), (uint32_t) (val)); \ - break; \ - case 2: \ - uvisor_write16((volatile uint16_t *) (addr), (uint16_t) (val)); \ - break; \ - case 1: \ - uvisor_write8((volatile uint8_t *) (addr), (uint8_t) (val)); \ - break; \ - } \ - } - -#define UNION_READ(type, addr, fieldU, fieldB) ((*((volatile type *) (addr))).fieldB) - -static inline UVISOR_FORCEINLINE void uvisor_write32(uint32_t volatile *addr, uint32_t val) -{ - *(addr) = val; -} - -static inline UVISOR_FORCEINLINE void uvisor_write16(uint16_t volatile *addr, uint16_t val) -{ - *(addr) = val; -} - -static inline UVISOR_FORCEINLINE void uvisor_write8(uint8_t volatile *addr, uint8_t val) -{ - *(addr) = val; -} - -static inline UVISOR_FORCEINLINE uint32_t uvisor_read32(uint32_t volatile *addr) -{ - return *(addr); -} - -static inline UVISOR_FORCEINLINE uint16_t uvisor_read16(uint16_t volatile *addr) -{ - return *(addr); -} - -static inline UVISOR_FORCEINLINE uint8_t uvisor_read8(uint8_t volatile *addr) -{ - return *(addr); -} - -/* uvisor-lib/secure_gateway.h */ - -#define secure_gateway(dst_box, dst_fn, ...) dst_fn(__VA_ARGS__) - -#endif /* __UVISOR_LIB_UNSUPPORTED_H__ */ diff --git a/uvisor-lib/unvic_exports.h b/uvisor-lib/unvic_exports.h deleted file mode 100644 index b071dc2..0000000 --- a/uvisor-lib/unvic_exports.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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. - */ -#ifndef __UNVIC_EXPORTS_H__ -#define __UNVIC_EXPORTS_H__ - -/* this value refers to the minimum allowable priority in the physical NVIC - * module, but not in the virtualised one (vIRQ) */ -#define __UVISOR_NVIC_MIN_PRIORITY ((uint32_t) 1) - -/* this is the maximum priority allowed for the vIRQ module */ -/* users of uVisor APIs can use this to determine the maximum level of - * priorities available to them */ -#define UVISOR_VIRQ_MAX_PRIORITY ((uint32_t) (1 << __NVIC_PRIO_BITS) - 1 - __UVISOR_NVIC_MIN_PRIORITY) - -#endif/*__UNVIC_EXPORTS_H__*/ diff --git a/uvisor-lib/uvisor-lib.h b/uvisor-lib/uvisor-lib.h index c741aa2..593c6cb 100644 --- a/uvisor-lib/uvisor-lib.h +++ b/uvisor-lib/uvisor-lib.h @@ -17,37 +17,31 @@ #ifndef __UVISOR_LIB_UVISOR_LIB_H__ #define __UVISOR_LIB_UVISOR_LIB_H__ -#include - -/* needed for NVIC symbols */ -#include "cmsis-core/cmsis_nvic.h" - -/* these header files are included independently from the platform */ -#include "uvisor-lib/debug_exports.h" -#include "uvisor-lib/uvisor_exports.h" -#include "uvisor-lib/vmpu_exports.h" -#include "uvisor-lib/halt_exports.h" -#include "uvisor-lib/svc_exports.h" -#include "uvisor-lib/svc_gw_exports.h" -#include "uvisor-lib/unvic_exports.h" - -/* conditionally included header files */ -#if YOTTA_CFG_UVISOR_PRESENT == 1 - -#include "uvisor-lib/benchmark.h" -#include "uvisor-lib/box_config.h" -#include "uvisor-lib/debug.h" -#include "uvisor-lib/disabled.h" -#include "uvisor-lib/error.h" -#include "uvisor-lib/interrupts.h" -#include "uvisor-lib/register_gateway.h" -#include "uvisor-lib/secure_access.h" -#include "uvisor-lib/secure_gateway.h" - -#else /* YOTTA_CFG_UVISOR_PRESENT == 1 */ - -#include "uvisor-lib/unsupported.h" - -#endif /* YOTTA_CFG_UVISOR_PRESENT == 1 */ +/* This file translates yotta-specific pre-processor symbols into + * uVisor-specific ones. Then the main uvisor-lib.h file is included. */ + +#if defined(YOTTA_CFG_UVISOR_PRESENT) && YOTTA_CFG_UVISOR_PRESENT == 1 + +#define UVISOR_PRESENT 1 + +/* Specify the MPU architecture */ +#if defined(TARGET_LIKE_ARMV7_M) + +#if defined(TARGET_LIKE_KINETIS) +#define ARCH_MPU_KINETIS +#else +#define ARCH_MPU_ARMv7M +#endif + +#endif /* defined(TARGET_LIKE_ARMV7_M) */ + +#else /* defined(YOTTA_CFG_UVISOR_PRESENT) && YOTTA_CFG_UVISOR_PRESENT == 1 */ + +/* There is no need to specify any other symbol if uVisor is unsupported. */ +#define UVISOR_PRESENT 0 + +#endif /* define(YOTTA_CFG_UVISOR_PRESENT) && YOTTA_CFG_UVISOR_PRESENT == 1 */ + +#include "uvisor/api/inc/uvisor-lib.h" #endif /* __UVISOR_LIB_UVISOR_LIB_H__ */ diff --git a/uvisor-lib/uvisor_exports.h b/uvisor-lib/uvisor_exports.h deleted file mode 100644 index fa091c8..0000000 --- a/uvisor-lib/uvisor_exports.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2013-2015, 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. - */ -#ifndef __UVISOR_EXPORTS_H__ -#define __UVISOR_EXPORTS_H__ - -/* maximum number of boxes allowed: 1 is the minimum (unprivileged box) */ -#define UVISOR_MAX_BOXES 5U - -/* extern keyword */ -#ifdef __cplusplus -#define UVISOR_EXTERN extern "C" -#else -#define UVISOR_EXTERN extern -#endif/*__CPP__*/ - -/* asm keyword */ -#ifndef asm -#define asm __asm__ -#endif - -/* compiler attributes */ -#define UVISOR_FORCEINLINE __attribute__((always_inline)) -#define UVISOR_NOINLINE __attribute__((noinline)) -#define UVISOR_PACKED __attribute__((packed)) -#define UVISOR_WEAK __attribute__((weak)) -#define UVISOR_ALIAS(f) __attribute__((weak, alias (#f))) -#define UVISOR_LINKTO(f) __attribute__((alias (#f))) -#define UVISOR_NORETURN __attribute__((noreturn)) -#define UVISOR_NAKED __attribute__((naked)) -#define UVISOR_RAMFUNC __attribute__ ((section (".ramfunc"), noinline)) - -/* array count macro */ -#define UVISOR_ARRAY_COUNT(x) (sizeof(x)/sizeof(x[0])) - -/* convert macro argument to string */ -/* note: this needs one level of indirection, accomplished with the helper macro - * __UVISOR_TO_STRING */ -#define __UVISOR_TO_STRING(x) #x -#define UVISOR_TO_STRING(x) __UVISOR_TO_STRING(x) - -/* select an overloaded macro, so that 0 to 4 arguments can be used */ -#define __UVISOR_MACRO_SELECT(_0, _1, _2, _3, _4, NAME, ...) NAME - -/* count macro arguments */ -#define UVISOR_MACRO_NARGS(...) \ - __UVISOR_MACRO_SELECT(_0, ##__VA_ARGS__, 4, 3, 2, 1, 0) - -/* declare explicit callee-saved registers to hold input arguments (0 to 4) */ -/* note: sizeof(type) must be less than or equal to 4 */ -#define UVISOR_MACRO_REGS_ARGS(type, ...) \ - __UVISOR_MACRO_SELECT(_0, ##__VA_ARGS__, __UVISOR_MACRO_REGS_ARGS4, \ - __UVISOR_MACRO_REGS_ARGS3, \ - __UVISOR_MACRO_REGS_ARGS2, \ - __UVISOR_MACRO_REGS_ARGS1, \ - __UVISOR_MACRO_REGS_ARGS0)(type, ##__VA_ARGS__) -#define __UVISOR_MACRO_REGS_ARGS0(type) -#define __UVISOR_MACRO_REGS_ARGS1(type, a0) \ - register type r0 asm("r0") = (type) a0; -#define __UVISOR_MACRO_REGS_ARGS2(type, a0, a1) \ - register type r0 asm("r0") = (type) a0; \ - register type r1 asm("r1") = (type) a1; -#define __UVISOR_MACRO_REGS_ARGS3(type, a0, a1, a2) \ - register type r0 asm("r0") = (type) a0; \ - register type r1 asm("r1") = (type) a1; \ - register type r2 asm("r2") = (type) a2; -#define __UVISOR_MACRO_REGS_ARGS4(type, a0, a1, a2, a3) \ - register type r0 asm("r0") = (type) a0; \ - register type r1 asm("r1") = (type) a1; \ - register type r2 asm("r2") = (type) a2; \ - register type r3 asm("r3") = (type) a3; - -/* declare explicit callee-saved registers to hold output values */ -/* note: currently only one output value is allowed, up to 32bits */ -#define UVISOR_MACRO_REGS_RETVAL(type, name) \ - register type name asm("r0"); - -/* declare callee-saved input/output operands for gcc-style inline asm */ -/* note: this macro requires that a C variable having the same name of the - * corresponding callee-saved register is declared; these operands follow - * the official ABI for ARMv7M (e.g. 2 input arguments of 32bits each max, - * imply that registers r0 and r1 are used) */ -/* note: gcc only */ -/* note: for 0 inputs a dummy immediate is passed to avoid errors on a misplaced - * comma in the inline assembly */ -#ifdef __GNUC__ - -#define UVISOR_MACRO_GCC_ASM_INPUT(...) \ - __UVISOR_MACRO_SELECT(_0, ##__VA_ARGS__, __UVISOR_MACRO_GCC_ASM_INPUT4, \ - __UVISOR_MACRO_GCC_ASM_INPUT3, \ - __UVISOR_MACRO_GCC_ASM_INPUT2, \ - __UVISOR_MACRO_GCC_ASM_INPUT1, \ - __UVISOR_MACRO_GCC_ASM_INPUT0)(__VA_ARGS__) -#define __UVISOR_MACRO_GCC_ASM_INPUT0() [__dummy] "I" (0) -#define __UVISOR_MACRO_GCC_ASM_INPUT1(a0) [r0] "r" (r0) -#define __UVISOR_MACRO_GCC_ASM_INPUT2(a0, a1) [r0] "r" (r0), [r1] "r" (r1) -#define __UVISOR_MACRO_GCC_ASM_INPUT3(a0, a1, a2) [r0] "r" (r0), [r1] "r" (r1), [r2] "r" (r2) -#define __UVISOR_MACRO_GCC_ASM_INPUT4(a0, a1, a2, a3) [r0] "r" (r0), [r1] "r" (r1), [r2] "r" (r2), [r3] "r" (r3) - -#define UVISOR_MACRO_GCC_ASM_OUTPUT(name) [res] "=r" (name) - -#endif /* __GNUC__ */ - -/* this macro multiplexes read/write opcodes depending on the number of - * arguments */ -#define UVISOR_ASM_MEMORY_ACCESS(opcode, type, ...) \ - __UVISOR_MACRO_SELECT(_0, ##__VA_ARGS__, /* no macro for 4 args */ , \ - /* no macro for 3 args */ , \ - __UVISOR_ASM_MEMORY_ACCESS_W, \ - __UVISOR_ASM_MEMORY_ACCESS_R, \ - /* no macro for 0 args */ )(opcode, type, ##__VA_ARGS__) -/* the macros that actually generate the assembly code for the memory access are - * toolchain-specific */ -#if defined(__CC_ARM) - -/* TODO/FIXME */ - -#elif defined(__GNUC__) - -#define __UVISOR_ASM_MEMORY_ACCESS_R(opcode, type, ...) \ - ({ \ - UVISOR_MACRO_REGS_ARGS(uint32_t, ##__VA_ARGS__); \ - UVISOR_MACRO_REGS_RETVAL(type, res); \ - asm volatile( \ - UVISOR_TO_STRING(opcode)" %[res], [%[r0]]\n" \ - UVISOR_NOP_GROUP \ - : UVISOR_MACRO_GCC_ASM_OUTPUT(res) \ - : UVISOR_MACRO_GCC_ASM_INPUT(__VA_ARGS__) \ - ); \ - res; \ - }) - -#define __UVISOR_ASM_MEMORY_ACCESS_W(opcode, type, ...) \ - UVISOR_MACRO_REGS_ARGS(uint32_t, ##__VA_ARGS__); \ - asm volatile( \ - UVISOR_TO_STRING(opcode)" %[r1], [%[r0]]\n" \ - UVISOR_NOP_GROUP \ - : \ - : UVISOR_MACRO_GCC_ASM_INPUT(__VA_ARGS__) \ - ); - -#endif /* defined(__CC_ARM) || defined(__GNUC__) */ - -#endif/*__UVISOR_EXPORTS_H__*/ diff --git a/uvisor-lib/vmpu_exports.h b/uvisor-lib/vmpu_exports.h deleted file mode 100644 index 50c22b6..0000000 --- a/uvisor-lib/vmpu_exports.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2013-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. - */ -#ifndef __VMPU_EXPORTS_H__ -#define __VMPU_EXPORTS_H__ - -#include "uvisor_exports.h" -#include - -/* supervisor user access modes */ -#define UVISOR_TACL_UEXECUTE 0x0001UL -#define UVISOR_TACL_UWRITE 0x0002UL -#define UVISOR_TACL_UREAD 0x0004UL -#define UVISOR_TACL_UACL (UVISOR_TACL_UREAD |\ - UVISOR_TACL_UWRITE |\ - UVISOR_TACL_UEXECUTE) - -/* supervisor access modes */ -#define UVISOR_TACL_SEXECUTE 0x0008UL -#define UVISOR_TACL_SWRITE 0x0010UL -#define UVISOR_TACL_SREAD 0x0020UL -#define UVISOR_TACL_SACL (UVISOR_TACL_SREAD |\ - UVISOR_TACL_SWRITE |\ - UVISOR_TACL_SEXECUTE) - -#define UVISOR_TACL_EXECUTE (UVISOR_TACL_UEXECUTE | UVISOR_TACL_SEXECUTE) - -/* all possible access control flags */ -#define UVISOR_TACL_ACCESS (UVISOR_TACL_UACL | UVISOR_TACL_SACL) - -/* various modes */ -#define UVISOR_TACL_STACK 0x0040UL -#define UVISOR_TACL_SIZE_ROUND_UP 0x0080UL -#define UVISOR_TACL_SIZE_ROUND_DOWN 0x0100UL -#define UVISOR_TACL_PERIPHERAL 0x0200UL -#define UVISOR_TACL_SHARED 0x0400UL -#define UVISOR_TACL_USER 0x0800UL -#define UVISOR_TACL_IRQ 0x1000UL - -/* subregion mask for ARMv7M */ -#if defined(ARCH_MPU_ARMv7M) || (YOTTA_CFG_UVISOR_PRESENT == 1 && !defined(TARGET_LIKE_KINETIS)) -#define UVISOR_TACL_SUBREGIONS_POS 24 -#define UVISOR_TACL_SUBREGIONS_MASK (0xFFUL<