diff --git a/features/FEATURE_UVISOR/AUTHORS.txt b/features/FEATURE_UVISOR/AUTHORS.txt new file mode 100644 index 00000000000..387d27cd53f --- /dev/null +++ b/features/FEATURE_UVISOR/AUTHORS.txt @@ -0,0 +1,12 @@ + 519 Milosch Meriac + 420 Alessandro Angelino + 16 Niklas Hauser + 15 Jaeden Amero + 3 Hugo Vincent + 3 JaredCJR + 3 Jim Huang + 2 tonyyanxuan + 1 Aksel Skauge Mellbye + 1 Irit Arkin + 1 Nathan Chong + 1 ccli8 diff --git a/features/FEATURE_UVISOR/VERSION.txt b/features/FEATURE_UVISOR/VERSION.txt new file mode 100644 index 00000000000..7265df00877 --- /dev/null +++ b/features/FEATURE_UVISOR/VERSION.txt @@ -0,0 +1 @@ +v0.9.14-alpha diff --git a/features/FEATURE_UVISOR/importer/Makefile b/features/FEATURE_UVISOR/importer/Makefile new file mode 100644 index 00000000000..c29e38ad00f --- /dev/null +++ b/features/FEATURE_UVISOR/importer/Makefile @@ -0,0 +1,115 @@ +########################################################################### +# +# 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. +# +########################################################################### + +# Toolchain +PREFIX:=arm-none-eabi- +GDB:=$(PREFIX)gdb +OBJDUMP:=$(PREFIX)objdump + +# Translate between uVisor namespace and mbed namespace +TARGET_TRANSLATION:=MCU_K64F.kinetis EFM32.efm32 STM32F4.stm32 +TARGET_PREFIX:=../ +TARGET_SUPPORTED:=$(TARGET_PREFIX)targets/TARGET_UVISOR_SUPPORTED +TARGET_UNSUPPORTED:=$(TARGET_PREFIX)targets/TARGET_UVISOR_UNSUPPORTED +TARGET_INC:=$(TARGET_PREFIX)includes/uvisor/api +TARGET_LIB_SRC:=$(TARGET_PREFIX)source +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_DIR:=TARGET_IGNORE/uvisor +UVISOR_API:=$(UVISOR_DIR)/api +UVISOR_GIT_CFG=$(UVISOR_DIR)/.git/config + +# Derive variables from user configuration +TARGET_LIST:=$(subst .,,$(suffix $(TARGET_TRANSLATION))) +TARGET_LIST_DIR_SRC:=$(addprefix $(UVISOR_API)/lib/,$(TARGET_LIST)) +TARGET_LIST_DIR_DST:=$(addprefix $(TARGET_SUPPORTED)/,$(TARGET_LIST)) +TARGET_LIST_RELEASE:=$(addsuffix /release,$(TARGET_LIST_DIR_DST)) +TARGET_LIST_DEBUG:=$(addsuffix /debug,$(TARGET_LIST_DIR_DST)) + +.PHONY: all deploy rsync publish uvisor uvisor-compile clean cache update + +all: uvisor + +uvisor: uvisor-compile publish + +rsync: + # + # Copying uVisor into mbed library... + rm -rf $(TARGET_SUPPORTED) + mkdir -p $(TARGET_SUPPORTED) + rsync -a --exclude='*.txt' $(TARGET_LIST_DIR_SRC) $(TARGET_SUPPORTED) + # + # Copying uVisor headers to mbed includes... + rm -rf $(TARGET_INC) + mkdir -p $(TARGET_INC) + rsync -a --delete $(UVISOR_API)/inc $(TARGET_INC) + rsync -a --delete $(UVISOR_API)/rtx/inc/ $(TARGET_LIB_INC)/rtx + # + # Copying uVisor unsupported sources to unsupported target source... + mkdir -p $(TARGET_UNSUPPORTED) + cp $(UVISOR_API)/src/unsupported.c $(TARGET_UNSUPPORTED)/ + # + # Copying uVisor shared sources to mbed source... + rm -rf $(TARGET_LIB_SRC) + mkdir -p $(TARGET_LIB_SRC) + cp $(UVISOR_DIR)/core/system/src/page_allocator.c $(TARGET_LIB_SRC)/page_allocator.c_inc + rsync -a --delete $(UVISOR_API)/rtx/src/ $(TARGET_LIB_SRC)/rtx + # + # Copying licenses + cp $(UVISOR_DIR)/LICENSE* $(TARGET_SUPPORTED) + +TARGET_M%: $(TARGET_SUPPORTED)/*/*/*_m%_*.a + @printf "#\n# Copying $@ files...\n" + mkdir $(foreach file,$^,$(dir $(file))$@) + $(foreach file,$^,mv $(file) $(dir $(file))$@/lib$(notdir $(file));) + +publish: rsync TARGET_M3 TARGET_M4 + # + # Rename release directorires to TARGET_RELEASE filters... + $(foreach dir, $(TARGET_LIST_RELEASE),mv $(dir) $(dir $(dir))TARGET_RELEASE;) + # + # Rename debug directorires to TARGET_DEBUG filters... + $(foreach dir, $(TARGET_LIST_DEBUG),mv $(dir) $(dir $(dir))TARGET_DEBUG;) + # + # Rename target directorires to TARGET_* filters... + $(foreach target, $(TARGET_TRANSLATION),mv $(TARGET_SUPPORTED)/$(subst .,,$(suffix $(target))) $(TARGET_SUPPORTED)/TARGET_$(basename $(target));) + +uvisor-compile: $(UVISOR_GIT_CFG) + make -C $(UVISOR_DIR) + +update: $(UVISOR_GIT_CFG) + # + # Updating to latest uVisor library version + git -C $(UVISOR_DIR) pull --rebase + # + # Updating checked out version tag + git -C $(UVISOR_DIR) describe --tags --abbrev=40 --dirty > $(TARGET_PREFIX)VERSION.txt + # + # Updated list of authors, sorted by contributions + git -C $(UVISOR_DIR) shortlog -s -n > $(TARGET_PREFIX)AUTHORS.txt + +$(UVISOR_GIT_CFG): + rm -rf $(UVISOR_DIR) + git clone -b $(UVISOR_GIT_BRANCH) $(UVISOR_GIT_URL) $(UVISOR_DIR) + +clean: $(UVISOR_GIT_CFG) + make -C $(UVISOR_DIR) clean diff --git a/features/FEATURE_UVISOR/importer/README.md b/features/FEATURE_UVISOR/importer/README.md new file mode 100644 index 00000000000..29bcaf6d39e --- /dev/null +++ b/features/FEATURE_UVISOR/importer/README.md @@ -0,0 +1,6 @@ +# Rebuilding the uVisor mbed Library + +This directory contains scripts to import and rebuild the latest uVisor library to mbed Classic. +uVisor does not need to be re-deployed for normal application development. + +For uVisor development and code contributions please visit the [uVisor repository](https://github.com/ARMmbed/uvisor). \ No newline at end of file diff --git a/features/FEATURE_UVISOR/importer/TARGET_IGNORE/.gitignore b/features/FEATURE_UVISOR/importer/TARGET_IGNORE/.gitignore new file mode 100644 index 00000000000..12e58209fdb --- /dev/null +++ b/features/FEATURE_UVISOR/importer/TARGET_IGNORE/.gitignore @@ -0,0 +1 @@ +/uvisor \ No newline at end of file diff --git a/features/FEATURE_UVISOR/includes/uvisor-lib/rtx/process_malloc.h b/features/FEATURE_UVISOR/includes/uvisor-lib/rtx/process_malloc.h new file mode 100644 index 00000000000..1cf14ff3d41 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor-lib/rtx/process_malloc.h @@ -0,0 +1,37 @@ +/* + * 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 __RTX_PROCESS_MALLOC_H__ +#define __RTX_PROCESS_MALLOC_H__ + +#include "secure_allocator.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Allocate memory on the process heap. */ +void * malloc_p(size_t size); +/* Reallocate memory on the process heap. */ +void * realloc_p(void * ptr, size_t size); +/* Free memory on the process heap. */ +void free_p(void * ptr); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __RTX_PROCESS_MALLOC_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor-lib/rtx/rtx_box_index.h b/features/FEATURE_UVISOR/includes/uvisor-lib/rtx/rtx_box_index.h new file mode 100644 index 00000000000..ebdf45087a9 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor-lib/rtx/rtx_box_index.h @@ -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. + */ +#ifndef __RTX_BOX_INDEX_H__ +#define __RTX_BOX_INDEX_H__ + +#include "cmsis_os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct +{ + /* The uvisor box index must be placed at the beginning */ + UvisorBoxIndex index; + + /* Id of the mutex */ + osMutexId mutex_id; + /* Pointer to the data of the mutex */ + osMutexDef_t mutex; + /* Internal data of the mutex */ + int32_t mutex_data[4]; +} RtxBoxIndex; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __RTX_BOX_INDEX_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor-lib/rtx/secure_allocator.h b/features/FEATURE_UVISOR/includes/uvisor-lib/rtx/secure_allocator.h new file mode 100644 index 00000000000..75a58b43ba6 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor-lib/rtx/secure_allocator.h @@ -0,0 +1,88 @@ +/* + * 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 __SECURE_ALLOCATOR_H__ +#define __SECURE_ALLOCATOR_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Contains the allocator data and backing page table. */ +typedef void * SecureAllocator; + +/** Create an allocator in-place in an existing pool without using pages. + * Use this to turn statically allocated memory into a heap. + * Or allocate a large piece of memory and then turn that into a heap. + * + * @param mem Pointer to the origin of the memory pool + * @param bytes Length of the memory pool in bytes + * @returns the allocator or `NULL` on failure + */ +SecureAllocator secure_allocator_create_with_pool( + void * mem, + size_t bytes); + +/** Create an allocator using pages from the page heap. + * Use this to request secure dynamic memory for your process. + * Note that this memory is not guaranteed to be consecutive, therefore you + * must specify the maximum allocation size that you plan to use in this + * allocator. This function will then compute the number and size of required + * pages and request them from the secure page heap. + * + * @param total_size The minimal total size of the heap + * @param maximum_malloc_size The largest size to be allocated in one chunk + * @returns the allocator or `NULL` on failure (out of memory, + * maximum malloc size cannot be fulfilled) + */ +SecureAllocator secure_allocator_create_with_pages( + size_t total_size, + size_t maximum_malloc_size); + +/** Destroy the allocator and free the backing pages. + * An attempt to destroy a memory-pool backed allocator will fail and return + * with an error code. + * + * @retval 0 Allocator successfully destroyed. + * @retval -1 Allocator is static (memory-pool), or freeing memory pages failed. + */ +int secure_allocator_destroy( + SecureAllocator allocator); + +/** Drop-in for `malloc`. */ +void * secure_malloc( + SecureAllocator allocator, + size_t size); + +/** Drop-in for `realloc`. */ +void * secure_realloc( + SecureAllocator allocator, + void * ptr, + size_t size); + +/** Drop-in for `free`. */ +void secure_free( + SecureAllocator allocator, + void * ptr); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SECURE_ALLOCATOR_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor-lib/uvisor-lib.h b/features/FEATURE_UVISOR/includes/uvisor-lib/uvisor-lib.h new file mode 100644 index 00000000000..2375d1df7a1 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor-lib/uvisor-lib.h @@ -0,0 +1,47 @@ +/* + * 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_UVISOR_LIB_H__ +#define __UVISOR_LIB_UVISOR_LIB_H__ + +/* This file translates mbed-specific pre-processor symbols into + * uVisor-specific ones. Then the main uvisor-lib.h file is included. */ + +/* mbed uses UVISOR_SUPPORTED to determine whether the full uVisor binaries + * should be included or not. This symbol maps to the uVisor-internal symbol + * UVISOR_PRESENT. */ +/* By default uVisor is not supported. */ +#if !defined(FEATURE_UVISOR) || !defined(TARGET_UVISOR_SUPPORTED) || defined(TARGET_UVISOR_UNSUPPORTED) +#define UVISOR_PRESENT 0 +#else +#define UVISOR_PRESENT 1 +#endif + +/* Detect the target using the mbed-specific symbols and determine the MPU + * architecture accordingly. */ +#if defined(TARGET_KINETIS) +#define ARCH_MPU_KINETIS +#else +#define ARCH_MPU_ARMv7M +#endif + +/* The uVisor API main header file will use the above definitions. */ +#include "uvisor/api/inc/uvisor-lib.h" +#include "uvisor-lib/rtx/process_malloc.h" +#include "uvisor-lib/rtx/rtx_box_index.h" +#include "uvisor-lib/rtx/secure_allocator.h" + +#endif /* __UVISOR_LIB_UVISOR_LIB_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/benchmark.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/benchmark.h new file mode 100644 index 00000000000..b3e0c6c7927 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/benchmark.h @@ -0,0 +1,27 @@ +/* + * 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_API_BENCHMARK_H__ +#define __UVISOR_API_BENCHMARK_H__ + +#include "api/inc/uvisor_exports.h" +#include + +UVISOR_EXTERN void uvisor_benchmark_configure(void); +UVISOR_EXTERN void uvisor_benchmark_start(void); +UVISOR_EXTERN uint32_t uvisor_benchmark_stop(void); + +#endif /* __UVISOR_API_BENCHMARK_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/box_config.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/box_config.h new file mode 100644 index 00000000000..cf2f997f99e --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/box_config.h @@ -0,0 +1,140 @@ +/* + * 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_API_BOX_CONFIG_H__ +#define __UVISOR_API_BOX_CONFIG_H__ + +#include "api/inc/uvisor_exports.h" +#include +#include + +UVISOR_EXTERN const uint32_t __uvisor_mode; + +#define UVISOR_DISABLED 0 +#define UVISOR_PERMISSIVE 1 +#define UVISOR_ENABLED 2 + +#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, \ + sizeof(RtxBoxIndex), \ + 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) + \ + (__uvisor_box_heapsize) + \ + sizeof(RtxBoxIndex) \ + ) \ + * 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), \ + sizeof(RtxBoxIndex), \ + context_size, \ + __uvisor_box_heapsize, \ + __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 *const __uvisor_ps; + +#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 *const __uvisor_ps; + +#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 + +#define UVISOR_BOX_HEAPSIZE(heap_size) \ + static const uint32_t __uvisor_box_heapsize = heap_size; + +#define uvisor_ctx (*__uvisor_ps) + +/* 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_API_BOX_CONFIG_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/context_exports.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/context_exports.h new file mode 100644 index 00000000000..dc4c8464250 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/context_exports.h @@ -0,0 +1,26 @@ +/* + * 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_CONTEX_EXPORTS_H__ +#define __UVISOR_CONTEX_EXPORTS_H__ + +/** Maximum number of nested context switches. + * + * The same state stack is kept for all kinds of context switches that are bound + * to a function, for which uVisor keeps an internal state. */ +#define UVISOR_CONTEXT_MAX_DEPTH 16 + +#endif /* __UVISOR_CONTEX_EXPORTS_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/debug.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/debug.h new file mode 100644 index 00000000000..a170d46c79f --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/debug.h @@ -0,0 +1,25 @@ +/* + * 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_API_DEBUG_H__ +#define __UVISOR_API_DEBUG_H__ + +#include "api/inc/debug_exports.h" +#include "api/inc/uvisor_exports.h" + +UVISOR_EXTERN void uvisor_debug_init(const TUvisorDebugDriver * const driver); + +#endif /* __UVISOR_API_DEBUG_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/debug_exports.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/debug_exports.h new file mode 100644 index 00000000000..acbecee162a --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/debug_exports.h @@ -0,0 +1,33 @@ +/* + * 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_API_DEBUG_EXPORTS_H__ +#define __UVISOR_API_DEBUG_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 /* __UVISOR_API_DEBUG_EXPORTS_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/disabled.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/disabled.h new file mode 100644 index 00000000000..21b9a489d84 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/disabled.h @@ -0,0 +1,31 @@ +/* + * 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_API_DISABLED_H__ +#define __UVISOR_API_DISABLED_H__ + +#include "api/inc/uvisor_exports.h" +#include + +UVISOR_EXTERN void uvisor_disabled_switch_in(const uint32_t *dst_box_cfgtbl_ptr); +UVISOR_EXTERN void uvisor_disabled_switch_out(void); + +/* The host OS can override the implementations of these functions in case a + * different handling of IRQs is required when uVisor is disabled. */ +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_API_DISABLED_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/error.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/error.h new file mode 100644 index 00000000000..b7da1cc14b0 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/error.h @@ -0,0 +1,25 @@ +/* + * 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_API_ERROR_H__ +#define __UVISOR_API_ERROR_H__ + +#include "api/inc/halt_exports.h" +#include "api/inc/uvisor_exports.h" + +UVISOR_EXTERN void uvisor_error(THaltUserError reason); + +#endif /* __UVISOR_API_ERROR_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/export_table_exports.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/export_table_exports.h new file mode 100644 index 00000000000..b37514d6a09 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/export_table_exports.h @@ -0,0 +1,47 @@ +/* + * 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_API_EXPORT_TABLE_EXPORTS_H__ +#define __UVISOR_API_EXPORT_TABLE_EXPORTS_H__ + +#include "rt_OsEventObserver.h" +#include + +/* If this magic doesn't match what you get in a TUvisorExportTable, then you + * didn't find a TUvisorExportTable and all bets are off as to what will be + * contained in what you found. */ +#define UVISOR_EXPORT_MAGIC 0x5C9411B4 + +/* This is the export table API version. If this version doesn't match what you + * get in TUvisorExportTable, then you need a different header file to + * understand the TUvisorExportTable. */ +#define UVISOR_EXPORT_VERSION 0 + +typedef struct { + /* magic and version must be present as the first two elements in this + * table so that across various versions of the table layout, the table can + * be interpreted correctly. */ + uint32_t magic; + uint32_t version; + + OsEventObserver os_event_observer; + + /* This must be the last element of the table so that uvisor-input.S can + * export the size statically. */ + uint32_t size; +} TUvisorExportTable; + +#endif diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/halt_exports.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/halt_exports.h new file mode 100644 index 00000000000..77109373297 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/halt_exports.h @@ -0,0 +1,34 @@ +/* + * 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_API_HALT_EXPORTS_H__ +#define __UVISOR_API_HALT_EXPORTS_H__ + +#define UVISOR_ERROR_INVALID_BOX_ID (-2) +#define UVISOR_ERROR_BUFFER_TOO_SMALL (-3) +#define UVISOR_ERROR_BOX_NAMESPACE_ANONYMOUS (-4) + + +#define UVISOR_ERROR_CLASS_MASK (0xFFFF0000UL) +#define UVISOR_ERROR_MASK (0x0000FFFFUL) + +#define UVISOR_ERROR_CLASS_PAGE (1UL << 16) + +typedef enum { + USER_NOT_ALLOWED = 1, +} THaltUserError; + +#endif /* __UVISOR_API_HALT_EXPORTS_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/interrupts.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/interrupts.h new file mode 100644 index 00000000000..7459ad9367a --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/interrupts.h @@ -0,0 +1,63 @@ +/* + * 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_API_INTERRUPTS_H__ +#define __UVISOR_API_INTERRUPTS_H__ + +#include "api/inc/uvisor_exports.h" +#include + +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); + +/** Disable all interrupts for the currently active box. + * + * Calling this function from a box only affects the interrupts of that box. + * System interrupts and interrupts owned by other boxes are left untouched. + * + * Successive calls to this function increase an internal counter that is used + * by uVisor to decide when to re-enable IRQs. The related call + * ::vIRQ_EnableIRQ() decreases this counter. Only when the counter is 0 the + * interrupts are re-enabled for that box. + * + * This guarantees that code that disables IRQs will not accidentally have them + * re-enabled by a nested function that it calls before the expected call to + * ::vIRQ_EnableAll(). Example: + * + * vIRQ_DisableAll(); counter = 1; IRQs are now disabled. + * some_function(); counter = 2, then counter = 1; IRQs are still disabled. + * vIRQ_EnableAll(); counter = 0; IRQs are now re-enabled. + * + * where some_function() also has a disable/enable pair. */ +UVISOR_EXTERN void vIRQ_DisableAll(void); + +/** Re-enable all interrupts that were previously disabled for the currently + * active box. + * + * This function only re-enables interrupt if the uVisor internal counter is set + * to 0, to make sure that nested disabling of IRQs is still effective. See + * ::vIRQ_DisableAll for more information. */ +UVISOR_EXTERN void vIRQ_EnableAll(void); + +#endif /* __UVISOR_API_INTERRUPTS_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/page_allocator.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/page_allocator.h new file mode 100644 index 00000000000..56cff28d132 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/page_allocator.h @@ -0,0 +1,37 @@ +/* + * 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_API_PAGE_ALLOCATOR_H__ +#define __UVISOR_API_PAGE_ALLOCATOR_H__ + +#include "api/inc/uvisor_exports.h" +#include "api/inc/page_allocator_exports.h" +#include + +/* Allocate a number of requested pages with the requested page size. + * @param table.page_size[in] Must be equal to the current page size + * @param table.page_count[in] The number of pages to be allocated + * @param table.page_origins[out] Pointers to the page origins. The table must be large enough to hold page_count entries. + * @returns Non-zero on failure with failure class `UVISOR_ERROR_CLASS_PAGE`. See `UVISOR_ERROR_PAGE_*`. + */ +UVISOR_EXTERN int uvisor_page_malloc(UvisorPageTable * const table); + +/* Free the pages associated with the table, only if it passes validation. + * @returns Non-zero on failure with failure class `UVISOR_ERROR_CLASS_PAGE`. See `UVISOR_ERROR_PAGE_*`. + */ +UVISOR_EXTERN int uvisor_page_free(const UvisorPageTable * const table); + +#endif /* __UVISOR_API_PAGE_ALLOCATOR_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/page_allocator_exports.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/page_allocator_exports.h new file mode 100644 index 00000000000..89ee998d977 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/page_allocator_exports.h @@ -0,0 +1,61 @@ +/* + * 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_API_PAGE_ALLOCATOR_EXPORTS_H__ +#define __UVISOR_API_PAGE_ALLOCATOR_EXPORTS_H__ + +#include "api/inc/halt_exports.h" +#include +#include + + +#define UVISOR_ERROR_PAGE_OK (0) +#define UVISOR_ERROR_PAGE_OUT_OF_MEMORY (UVISOR_ERROR_CLASS_PAGE + 1) +#define UVISOR_ERROR_PAGE_INVALID_PAGE_TABLE (UVISOR_ERROR_CLASS_PAGE + 2) +#define UVISOR_ERROR_PAGE_INVALID_PAGE_SIZE (UVISOR_ERROR_CLASS_PAGE + 3) +#define UVISOR_ERROR_PAGE_INVALID_PAGE_ORIGIN (UVISOR_ERROR_CLASS_PAGE + 4) +#define UVISOR_ERROR_PAGE_INVALID_PAGE_OWNER (UVISOR_ERROR_CLASS_PAGE + 5) +#define UVISOR_ERROR_PAGE_INVALID_PAGE_COUNT (UVISOR_ERROR_CLASS_PAGE + 6) + + +/* Must be a power of 2 for MPU alignment in ARMv7-M with ARM MPU. + * Must be multiple of 32 for K64F MPU. */ +#ifndef UVISOR_PAGE_SIZE +#define UVISOR_PAGE_SIZE ((uint32_t) 16 * 1024) +#endif + +/* Return the rounded up number of pages required to hold `size`. */ +#define UVISOR_PAGES_FOR_SIZE(size) ((size + UVISOR_PAGE_SIZE - 1) / UVISOR_PAGE_SIZE) + +/* Create a page table with `count` many entries. */ +#define UVISOR_PAGE_TABLE(count) \ + struct { \ + uint32_t page_size; \ + uint32_t page_count; \ + void * page_origins[count]; \ + } + +/* Create a page table with enough pages to hold `size`. */ +#define UVISOR_PAGE_TABLE_FOR_SIZE(size) UVISOR_PAGE_TABLE(UVISOR_PAGES_FOR_SIZE(size)) + + +typedef struct { + uint32_t page_size; /* The page size in bytes. Must be multiple of `UVISOR_PAGE_SIZE`! */ + uint32_t page_count; /* The number of pages in the page table. */ + void * page_origins[1]; /* Table of pointers to the origin of each page. */ +} UvisorPageTable; + +#endif /* __UVISOR_API_PAGE_ALLOCATOR_EXPORTS_H__ */ diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/priv_sys_irq_hook_exports.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/priv_sys_irq_hook_exports.h new file mode 100644 index 00000000000..929bf51832d --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/priv_sys_irq_hook_exports.h @@ -0,0 +1,44 @@ +/* + * 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_API_PRIV_SYS_IRQ_HOOK_EXPORTS_H__ +#define __UVISOR_API_PRIV_SYS_IRQ_HOOK_EXPORTS_H__ + +/* + * Privileged system interrupt hooks + * + * In this version of uVisor, uVisor lives alongside an RTOS that requires + * running privileged code. In order for the RTOS to run any privileged code, + * uVisor must allow the RTOS to handle a subset of privileged system + * interrupts. Only the following system interrupts are hookable. Code called + * by these hooks circumvents uVisor security. HANDLE WITH CARE. */ +typedef struct { + void (*priv_svc_0)(void); + void (*priv_pendsv)(void); + void (*priv_systick)(void); +} UvisorPrivSystemIRQHooks; + +/* Use this macro to register privileged system IRQ hooks. If you don't want to + * register a particular privileged system IRQ hook, you can supply NULL for + * that hook parameter. */ +#define UVISOR_SET_PRIV_SYS_IRQ_HOOKS(priv_svc_0_, priv_pendsv_, priv_systick_) \ + UVISOR_EXTERN const UvisorPrivSystemIRQHooks __uvisor_priv_sys_irq_hooks = { \ + .priv_svc_0 = priv_svc_0_, \ + .priv_pendsv = priv_pendsv_, \ + .priv_systick = priv_systick_, \ + }; + +#endif diff --git a/features/FEATURE_UVISOR/includes/uvisor/api/inc/register_gateway.h b/features/FEATURE_UVISOR/includes/uvisor/api/inc/register_gateway.h new file mode 100644 index 00000000000..1fbf31d3a31 --- /dev/null +++ b/features/FEATURE_UVISOR/includes/uvisor/api/inc/register_gateway.h @@ -0,0 +1,219 @@ +/* + * 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_API_REGISTER_GATEWAY_H__ +#define __UVISOR_API_REGISTER_GATEWAY_H__ + +#include "api/inc/register_gateway_exports.h" +#include "api/inc/uvisor_exports.h" +#include + +/** Get the offset of a struct member. + * @internal + */ +#define __UVISOR_OFFSETOF(type, member) ((uint32_t) (&(((type *)(0))->member))) + +/** Generate the opcode of the 16-bit Thumb-2 16-bit T2 encoding of the branch + * instruction. + * @internal + * @note The branch instruction is encoded according to the Thumb-2 immediate + * encoding rules: + * : B.N