From 48026bb824fd2d9cfb00ecd040db6ef3a416bae9 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 22 Jan 2021 21:43:36 -0500 Subject: upload initial port --- ChibiOS_20.3.2/os/sb/common/sberr.h | 97 ++ ChibiOS_20.3.2/os/sb/host/compilers/GCC/sbexc.S | 170 ++++ ChibiOS_20.3.2/os/sb/host/compilers/GCC/sbhost.mk | 14 + ChibiOS_20.3.2/os/sb/host/sb.h | 151 +++ ChibiOS_20.3.2/os/sb/host/sbapi.c | 1067 +++++++++++++++++++++ ChibiOS_20.3.2/os/sb/host/sbapi.h | 127 +++ ChibiOS_20.3.2/os/sb/host/sbhost.c | 146 +++ ChibiOS_20.3.2/os/sb/host/sbhost.h | 265 +++++ ChibiOS_20.3.2/os/sb/host/sbposix.c | 136 +++ ChibiOS_20.3.2/os/sb/host/sbposix.h | 73 ++ ChibiOS_20.3.2/os/sb/user/sbuser.c | 74 ++ ChibiOS_20.3.2/os/sb/user/sbuser.h | 669 +++++++++++++ ChibiOS_20.3.2/os/sb/user/sbuser.mk | 12 + ChibiOS_20.3.2/os/sb/various/syscalls.c | 142 +++ 14 files changed, 3143 insertions(+) create mode 100644 ChibiOS_20.3.2/os/sb/common/sberr.h create mode 100644 ChibiOS_20.3.2/os/sb/host/compilers/GCC/sbexc.S create mode 100644 ChibiOS_20.3.2/os/sb/host/compilers/GCC/sbhost.mk create mode 100644 ChibiOS_20.3.2/os/sb/host/sb.h create mode 100644 ChibiOS_20.3.2/os/sb/host/sbapi.c create mode 100644 ChibiOS_20.3.2/os/sb/host/sbapi.h create mode 100644 ChibiOS_20.3.2/os/sb/host/sbhost.c create mode 100644 ChibiOS_20.3.2/os/sb/host/sbhost.h create mode 100644 ChibiOS_20.3.2/os/sb/host/sbposix.c create mode 100644 ChibiOS_20.3.2/os/sb/host/sbposix.h create mode 100644 ChibiOS_20.3.2/os/sb/user/sbuser.c create mode 100644 ChibiOS_20.3.2/os/sb/user/sbuser.h create mode 100644 ChibiOS_20.3.2/os/sb/user/sbuser.mk create mode 100644 ChibiOS_20.3.2/os/sb/various/syscalls.c (limited to 'ChibiOS_20.3.2/os/sb') diff --git a/ChibiOS_20.3.2/os/sb/common/sberr.h b/ChibiOS_20.3.2/os/sb/common/sberr.h new file mode 100644 index 0000000..b827f7d --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/common/sberr.h @@ -0,0 +1,97 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sb/common/sberr.h + * @brief ARMv7-M sandbox common macros and structures. + * + * @addtogroup ARM_SANDBOX_ERRORS + * @{ + */ + +#ifndef SBERR_H +#define SBERR_H + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/** + * @name Sandbox API error codes + * @{ + */ +#define SB_ERR_NOERROR 0U +#define SB_ERR_ENOENT ((uint32_t)(-2)) +#define SB_ERR_EFAULT ((uint32_t)(-14)) +#define SB_ERR_EBUSY ((uint32_t)(-16)) +#define SB_ERR_EINVAL ((uint32_t)(-22)) +#define SB_ERR_ESPIPE ((uint32_t)(-29)) +#define SB_ERR_EBADFD ((uint32_t)(-81)) +#define SB_ERR_ENOSYS ((uint32_t)(-88)) + +#define SB_ERR_ERRORMASK 0xFFFFFF00U +#define SB_ERR_ISERROR(x) (((uint32_t)(x) & SB_ERR_ERRORMASK) == SB_ERR_ERRORMASK) +/** @} */ + +/** + * @name Posix-like function codes + * @{ + */ +#define SB_POSIX_OPEN 1 +#define SB_POSIX_CLOSE 2 +#define SB_POSIX_READ 3 +#define SB_POSIX_WRITE 4 +#define SB_POSIX_LSEEK 5 +/** @} */ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +#endif /* SBERR_H */ + +/** @} */ diff --git a/ChibiOS_20.3.2/os/sb/host/compilers/GCC/sbexc.S b/ChibiOS_20.3.2/os/sb/host/compilers/GCC/sbexc.S new file mode 100644 index 0000000..3cccaf3 --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/host/compilers/GCC/sbexc.S @@ -0,0 +1,170 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sb/sbexc.S + * @brief Exception handlers for sandbox. + * + * @defgroup ARMV7M_SANDBOX_EXCEPTIONS SandBox Exception Vectors + * @{ + */ + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +#define FPU 0xE000EF30 + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Code section. */ +/*===========================================================================*/ + +#if !defined(__DOXYGEN__) + + .syntax unified + .cpu cortex-m3 + .thumb + + .text + + .align 2 + .thumb_func + .global port_syscall +port_syscall: + ldr r3, =sb_syscalls + ldr.w r3, [r3, r1, lsl #2] + blx r3 + svc 0 +.zombies1: b .zombies1 + + .align 2 + .thumb_func + .global HardFault_Handler +HardFault_Handler: + tst.w lr, #8 + beq.n .normal_hf + mrs r3, CONTROL + tst.w r3, #1 + bne.w .exit_thd +.normal_hf: ldr r3, =HardFault_Handler_SB + bx r3 + + .align 2 + .thumb_func + .global MemManage_Handler +MemManage_Handler: + tst.w lr, #8 + beq.n .normal_mm + mrs r3, CONTROL + tst.w r3, #1 + bne.w .exit_thd +.normal_mm: ldr r3, =MemManage_Handler_SB + bx r3 + + .align 2 + .thumb_func + .global BusFault_Handler +BusFault_Handler: + tst.w lr, #8 + beq.n .normal_bf + mrs r3, CONTROL + tst.w r3, #1 + bne.w .exit_thd +.normal_bf: ldr r3, =BusFault_Handler_SB + bx r3 + + .align 2 + .thumb_func + .global UsageFault_Handler +UsageFault_Handler: + tst.w lr, #8 + beq.n .normal_uf + mrs r3, CONTROL + tst.w r3, #1 + bne.w .exit_thd +.normal_uf: ldr r3, =UsageFault_Handler_SB + bx r3 + +/* + * Common thread-exit handler on exception. + * Makes the current exception return on chThdExit() with the PSR + * value as exit message. + */ +.exit_thd: + mov.w r4, lr + + /* This thread is going to die so going back on + S-PSP and working safely from there.*/ + bl port_get_s_psp +#if CORTEX_USE_FPU + sub.w r0, r0, #104 +#else + sub.w r0, r0, #32 + msr PSP, r0 +#endif + + /* Forcing return on exit syscall code with PSR + value as exit message.*/ + mrs r2, PSR + str r2, [r0, #0] + ldr r2, =.do_exit + str r2, [r0, #24] + ldr r2, =0x01000000 + str r2, [r0, #28] +#if CORTEX_USE_FPU + ldr r2, =FPU + ldr r2, [r2, #12] /* FPDSCR*/ + str r2, [r0, #96] /* port_extctx.fpscr */ +#endif + + /* Back to privileged mode.*/ + mrs r3, CONTROL + bic.w r3, #1 + msr CONTROL, r3 + + /* Making sure there are no chained exceptions or interrupts + in the way, we need to exit this one atomically.*/ + bl port_syslock_noinline + bx r4 + + /* Exception exit point.*/ +.do_exit: + bl chThdExitS +.zombies2: b .zombies2 + + .align 2 + .thumb_func + .weak HardFault_Handler_SB + .weak MemManage_Handler_SB + .weak BusFault_Handler_SB + .weak UsageFault_Handler_SB +HardFault_Handler_SB: +MemManage_Handler_SB: +BusFault_Handler_SB: +UsageFault_Handler_SB: + ldr r3, =_unhandled_exception + bx r3 + +#endif /* !defined(__DOXYGEN__) */ + +/** @} */ diff --git a/ChibiOS_20.3.2/os/sb/host/compilers/GCC/sbhost.mk b/ChibiOS_20.3.2/os/sb/host/compilers/GCC/sbhost.mk new file mode 100644 index 0000000..dbae38e --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/host/compilers/GCC/sbhost.mk @@ -0,0 +1,14 @@ +# List of the ChibiOS ARMv7-M sandbox host files. +SBHOSTSRC = $(CHIBIOS)/os/sb/host/sbhost.c \ + $(CHIBIOS)/os/sb/host/sbapi.c \ + $(CHIBIOS)/os/sb/host/sbposix.c + +SBHOSTASM = $(CHIBIOS)/os/sb/host/compilers/GCC/sbexc.S + +SBHOSTINC = $(CHIBIOS)/os/sb/common \ + $(CHIBIOS)/os/sb/host + +# Shared variables +ALLXASMSRC += $(SBHOSTASM) +ALLCSRC += $(SBHOSTSRC) +ALLINC += $(SBHOSTINC) diff --git a/ChibiOS_20.3.2/os/sb/host/sb.h b/ChibiOS_20.3.2/os/sb/host/sb.h new file mode 100644 index 0000000..5b58fbd --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/host/sb.h @@ -0,0 +1,151 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sb/host/sb.h + * @brief ARM sandbox macros and structures. + * + * @addtogroup ARM_SANDBOX + * @{ + */ + +#ifndef SB_H +#define SB_H + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/** + * @brief ChibiOS/SB identification macro. + */ +#define _CHIBIOS_SB_ + +/** + * @brief Stable release flag. + */ +#define CH_SB_STABLE 1 + +/** + * @name ChibiOS/SE version identification + * @{ + */ +/** + * @brief Safety Extensions version string. + */ +#define CH_SB_VERSION "1.0.0" + +/** + * @brief Safety Extensions version major number. + */ +#define CH_SB_MAJOR 1 + +/** + * @brief Safety Extensions version minor number. + */ +#define CH_SB_MINOR 0 + +/** + * @brief Safety Extensions version patch number. + */ +#define CH_SB_PATCH 0 +/** @} */ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/** + * @brief Number of memory regions for each sandbox. + */ +#if !defined(SB_NUM_REGIONS) || defined(__DOXYGEN__) +#define SB_NUM_REGIONS 2 +#endif + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/* License checks.*/ +#if !defined(CH_CUSTOMER_LIC_SB) || !defined(CH_LICENSE_FEATURES) +#error "malformed chlicense.h" +#endif + +#if CH_CUSTOMER_LIC_SB == FALSE +#error "ChibiOS/SB not licensed" +#endif + +#if (CH_LICENSE_FEATURES != CH_FEATURES_FULL) && \ + (CH_LICENSE_FEATURES != CH_FEATURES_INTERMEDIATE) && \ + (CH_LICENSE_FEATURES != CH_FEATURES_BASIC) +#error "invalid CH_LICENSE_FEATURES setting" +#endif + +#if CH_LICENSE_FEATURES != CH_FEATURES_FULL +#error "ChibiOS/SB insufficient features level" +#endif + +#if CH_CFG_ST_RESOLUTION != 32 +#error "SandBox requires CH_CFG_ST_RESOLUTION == 32" +#endif + +#if CH_CFG_INTERVALS_SIZE != 32 +#error "SandBox requires CH_CFG_INTERVALS_SIZE == 32" +#endif + +#if PORT_USE_SYSCALL == FALSE +#error "SandBox requires PORT_USE_SYSCALL == TRUE" +#endif + +#if (SB_NUM_REGIONS < 1) || (SB_NUM_REGIONS > 4) +#error "invalid SB_NUM_REGIONS value" +#endif + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +#include "sberr.h" +#include "sbhost.h" +#include "sbapi.h" +#include "sbposix.h" + +#endif /* SBHOST_H */ + +/** @} */ diff --git a/ChibiOS_20.3.2/os/sb/host/sbapi.c b/ChibiOS_20.3.2/os/sb/host/sbapi.c new file mode 100644 index 0000000..b52d16b --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/host/sbapi.c @@ -0,0 +1,1067 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sb/host/sbhost.c + * @brief ARM sandbox host API code. + * + * @addtogroup ARM_SANDBOX_HOSTAPI + * @{ + */ + +#include "ch.h" +#include "sb.h" + +#if defined(SB_INCLUDE_USERAPI) +#include "sbuserapi.h" +#endif + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/** + * @name Standard API handlers + * @{ + */ +#define SB_SVC0_HANDLER sb_api_stdio +#define SB_SVC1_HANDLER sb_api_exit +#define SB_SVC2_HANDLER sb_api_get_systime +#define SB_SVC3_HANDLER sb_api_get_frequency +#define SB_SVC4_HANDLER sb_api_sleep +#define SB_SVC5_HANDLER sb_api_sleep_until_windowed +#define SB_SVC6_HANDLER sb_api_wait_message +#define SB_SVC7_HANDLER sb_api_reply_message +#define SB_SVC8_HANDLER sb_api_wait_one_timeout +#define SB_SVC9_HANDLER sb_api_wait_any_timeout +#define SB_SVC10_HANDLER sb_api_wait_all_timeout +#define SB_SVC11_HANDLER sb_api_broadcast_flags +/** @} */ + +#define __SVC(x) asm volatile ("svc " #x) + +/* + * All handlers defaulted to a common function. + */ +#if !defined(SB_SVC0_HANDLER) +#define SB_SVC0_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC1_HANDLER) +#define SB_SVC1_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC2_HANDLER) +#define SB_SVC2_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC3_HANDLER) +#define SB_SVC3_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC4_HANDLER) +#define SB_SVC4_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC5_HANDLER) +#define SB_SVC5_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC6_HANDLER) +#define SB_SVC6_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC7_HANDLER) +#define SB_SVC7_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC8_HANDLER) +#define SB_SVC8_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC9_HANDLER) +#define SB_SVC9_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC10_HANDLER) +#define SB_SVC10_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC11_HANDLER) +#define SB_SVC11_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC12_HANDLER) +#define SB_SVC12_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC13_HANDLER) +#define SB_SVC13_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC14_HANDLER) +#define SB_SVC14_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC15_HANDLER) +#define SB_SVC15_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC16_HANDLER) +#define SB_SVC16_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC17_HANDLER) +#define SB_SVC17_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC18_HANDLER) +#define SB_SVC18_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC19_HANDLER) +#define SB_SVC19_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC20_HANDLER) +#define SB_SVC20_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC21_HANDLER) +#define SB_SVC21_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC22_HANDLER) +#define SB_SVC22_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC23_HANDLER) +#define SB_SVC23_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC24_HANDLER) +#define SB_SVC24_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC25_HANDLER) +#define SB_SVC25_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC26_HANDLER) +#define SB_SVC26_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC27_HANDLER) +#define SB_SVC27_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC28_HANDLER) +#define SB_SVC28_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC29_HANDLER) +#define SB_SVC29_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC30_HANDLER) +#define SB_SVC30_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC31_HANDLER) +#define SB_SVC31_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC32_HANDLER) +#define SB_SVC32_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC33_HANDLER) +#define SB_SVC33_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC34_HANDLER) +#define SB_SVC34_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC35_HANDLER) +#define SB_SVC35_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC36_HANDLER) +#define SB_SVC36_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC37_HANDLER) +#define SB_SVC37_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC38_HANDLER) +#define SB_SVC38_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC39_HANDLER) +#define SB_SVC39_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC40_HANDLER) +#define SB_SVC40_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC41_HANDLER) +#define SB_SVC41_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC42_HANDLER) +#define SB_SVC42_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC43_HANDLER) +#define SB_SVC43_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC44_HANDLER) +#define SB_SVC44_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC45_HANDLER) +#define SB_SVC45_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC46_HANDLER) +#define SB_SVC46_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC47_HANDLER) +#define SB_SVC47_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC48_HANDLER) +#define SB_SVC48_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC49_HANDLER) +#define SB_SVC49_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC50_HANDLER) +#define SB_SVC50_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC51_HANDLER) +#define SB_SVC51_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC52_HANDLER) +#define SB_SVC52_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC53_HANDLER) +#define SB_SVC53_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC54_HANDLER) +#define SB_SVC54_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC55_HANDLER) +#define SB_SVC55_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC56_HANDLER) +#define SB_SVC56_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC57_HANDLER) +#define SB_SVC57_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC58_HANDLER) +#define SB_SVC58_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC59_HANDLER) +#define SB_SVC59_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC60_HANDLER) +#define SB_SVC60_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC61_HANDLER) +#define SB_SVC61_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC62_HANDLER) +#define SB_SVC62_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC63_HANDLER) +#define SB_SVC63_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC64_HANDLER) +#define SB_SVC64_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC65_HANDLER) +#define SB_SVC65_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC66_HANDLER) +#define SB_SVC66_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC67_HANDLER) +#define SB_SVC67_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC68_HANDLER) +#define SB_SVC68_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC69_HANDLER) +#define SB_SVC69_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC70_HANDLER) +#define SB_SVC70_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC71_HANDLER) +#define SB_SVC71_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC72_HANDLER) +#define SB_SVC72_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC73_HANDLER) +#define SB_SVC73_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC74_HANDLER) +#define SB_SVC74_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC75_HANDLER) +#define SB_SVC75_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC76_HANDLER) +#define SB_SVC76_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC77_HANDLER) +#define SB_SVC77_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC78_HANDLER) +#define SB_SVC78_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC79_HANDLER) +#define SB_SVC79_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC80_HANDLER) +#define SB_SVC80_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC81_HANDLER) +#define SB_SVC81_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC82_HANDLER) +#define SB_SVC82_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC83_HANDLER) +#define SB_SVC83_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC84_HANDLER) +#define SB_SVC84_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC85_HANDLER) +#define SB_SVC85_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC86_HANDLER) +#define SB_SVC86_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC87_HANDLER) +#define SB_SVC87_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC88_HANDLER) +#define SB_SVC88_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC89_HANDLER) +#define SB_SVC89_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC90_HANDLER) +#define SB_SVC90_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC91_HANDLER) +#define SB_SVC91_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC92_HANDLER) +#define SB_SVC92_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC93_HANDLER) +#define SB_SVC93_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC94_HANDLER) +#define SB_SVC94_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC95_HANDLER) +#define SB_SVC95_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC96_HANDLER) +#define SB_SVC96_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC97_HANDLER) +#define SB_SVC97_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC98_HANDLER) +#define SB_SVC98_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC99_HANDLER) +#define SB_SVC99_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC100_HANDLER) +#define SB_SVC100_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC101_HANDLER) +#define SB_SVC101_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC102_HANDLER) +#define SB_SVC102_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC103_HANDLER) +#define SB_SVC103_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC104_HANDLER) +#define SB_SVC104_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC105_HANDLER) +#define SB_SVC105_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC106_HANDLER) +#define SB_SVC106_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC107_HANDLER) +#define SB_SVC107_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC108_HANDLER) +#define SB_SVC108_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC109_HANDLER) +#define SB_SVC109_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC110_HANDLER) +#define SB_SVC110_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC111_HANDLER) +#define SB_SVC111_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC112_HANDLER) +#define SB_SVC112_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC113_HANDLER) +#define SB_SVC113_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC114_HANDLER) +#define SB_SVC114_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC115_HANDLER) +#define SB_SVC115_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC116_HANDLER) +#define SB_SVC116_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC117_HANDLER) +#define SB_SVC117_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC118_HANDLER) +#define SB_SVC118_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC119_HANDLER) +#define SB_SVC119_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC120_HANDLER) +#define SB_SVC120_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC121_HANDLER) +#define SB_SVC121_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC122_HANDLER) +#define SB_SVC122_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC123_HANDLER) +#define SB_SVC123_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC124_HANDLER) +#define SB_SVC124_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC125_HANDLER) +#define SB_SVC125_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC126_HANDLER) +#define SB_SVC126_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC127_HANDLER) +#define SB_SVC127_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC128_HANDLER) +#define SB_SVC128_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC129_HANDLER) +#define SB_SVC129_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC130_HANDLER) +#define SB_SVC130_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC131_HANDLER) +#define SB_SVC131_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC132_HANDLER) +#define SB_SVC132_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC133_HANDLER) +#define SB_SVC133_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC134_HANDLER) +#define SB_SVC134_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC135_HANDLER) +#define SB_SVC135_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC136_HANDLER) +#define SB_SVC136_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC137_HANDLER) +#define SB_SVC137_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC138_HANDLER) +#define SB_SVC138_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC139_HANDLER) +#define SB_SVC139_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC140_HANDLER) +#define SB_SVC140_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC141_HANDLER) +#define SB_SVC141_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC142_HANDLER) +#define SB_SVC142_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC143_HANDLER) +#define SB_SVC143_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC144_HANDLER) +#define SB_SVC144_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC145_HANDLER) +#define SB_SVC145_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC146_HANDLER) +#define SB_SVC146_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC147_HANDLER) +#define SB_SVC147_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC148_HANDLER) +#define SB_SVC148_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC149_HANDLER) +#define SB_SVC149_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC150_HANDLER) +#define SB_SVC150_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC151_HANDLER) +#define SB_SVC151_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC152_HANDLER) +#define SB_SVC152_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC153_HANDLER) +#define SB_SVC153_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC154_HANDLER) +#define SB_SVC154_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC155_HANDLER) +#define SB_SVC155_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC156_HANDLER) +#define SB_SVC156_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC157_HANDLER) +#define SB_SVC157_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC158_HANDLER) +#define SB_SVC158_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC159_HANDLER) +#define SB_SVC159_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC160_HANDLER) +#define SB_SVC160_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC161_HANDLER) +#define SB_SVC161_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC162_HANDLER) +#define SB_SVC162_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC163_HANDLER) +#define SB_SVC163_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC164_HANDLER) +#define SB_SVC164_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC165_HANDLER) +#define SB_SVC165_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC166_HANDLER) +#define SB_SVC166_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC167_HANDLER) +#define SB_SVC167_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC168_HANDLER) +#define SB_SVC168_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC169_HANDLER) +#define SB_SVC169_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC170_HANDLER) +#define SB_SVC170_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC171_HANDLER) +#define SB_SVC171_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC172_HANDLER) +#define SB_SVC172_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC173_HANDLER) +#define SB_SVC173_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC174_HANDLER) +#define SB_SVC174_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC175_HANDLER) +#define SB_SVC175_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC176_HANDLER) +#define SB_SVC176_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC177_HANDLER) +#define SB_SVC177_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC178_HANDLER) +#define SB_SVC178_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC179_HANDLER) +#define SB_SVC179_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC180_HANDLER) +#define SB_SVC180_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC181_HANDLER) +#define SB_SVC181_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC182_HANDLER) +#define SB_SVC182_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC183_HANDLER) +#define SB_SVC183_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC184_HANDLER) +#define SB_SVC184_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC185_HANDLER) +#define SB_SVC185_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC186_HANDLER) +#define SB_SVC186_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC187_HANDLER) +#define SB_SVC187_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC188_HANDLER) +#define SB_SVC188_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC189_HANDLER) +#define SB_SVC189_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC190_HANDLER) +#define SB_SVC190_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC191_HANDLER) +#define SB_SVC191_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC192_HANDLER) +#define SB_SVC192_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC193_HANDLER) +#define SB_SVC193_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC194_HANDLER) +#define SB_SVC194_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC195_HANDLER) +#define SB_SVC195_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC196_HANDLER) +#define SB_SVC196_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC197_HANDLER) +#define SB_SVC197_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC198_HANDLER) +#define SB_SVC198_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC199_HANDLER) +#define SB_SVC199_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC200_HANDLER) +#define SB_SVC200_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC201_HANDLER) +#define SB_SVC201_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC202_HANDLER) +#define SB_SVC202_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC203_HANDLER) +#define SB_SVC203_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC204_HANDLER) +#define SB_SVC204_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC205_HANDLER) +#define SB_SVC205_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC206_HANDLER) +#define SB_SVC206_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC207_HANDLER) +#define SB_SVC207_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC208_HANDLER) +#define SB_SVC208_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC209_HANDLER) +#define SB_SVC209_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC210_HANDLER) +#define SB_SVC210_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC211_HANDLER) +#define SB_SVC211_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC212_HANDLER) +#define SB_SVC212_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC213_HANDLER) +#define SB_SVC213_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC214_HANDLER) +#define SB_SVC214_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC215_HANDLER) +#define SB_SVC215_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC216_HANDLER) +#define SB_SVC216_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC217_HANDLER) +#define SB_SVC217_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC218_HANDLER) +#define SB_SVC218_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC219_HANDLER) +#define SB_SVC219_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC220_HANDLER) +#define SB_SVC220_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC221_HANDLER) +#define SB_SVC221_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC222_HANDLER) +#define SB_SVC222_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC223_HANDLER) +#define SB_SVC223_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC224_HANDLER) +#define SB_SVC224_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC225_HANDLER) +#define SB_SVC225_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC226_HANDLER) +#define SB_SVC226_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC227_HANDLER) +#define SB_SVC227_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC228_HANDLER) +#define SB_SVC228_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC229_HANDLER) +#define SB_SVC229_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC230_HANDLER) +#define SB_SVC230_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC231_HANDLER) +#define SB_SVC231_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC232_HANDLER) +#define SB_SVC232_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC233_HANDLER) +#define SB_SVC233_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC234_HANDLER) +#define SB_SVC234_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC235_HANDLER) +#define SB_SVC235_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC236_HANDLER) +#define SB_SVC236_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC237_HANDLER) +#define SB_SVC237_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC238_HANDLER) +#define SB_SVC238_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC239_HANDLER) +#define SB_SVC239_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC240_HANDLER) +#define SB_SVC240_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC241_HANDLER) +#define SB_SVC241_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC242_HANDLER) +#define SB_SVC242_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC243_HANDLER) +#define SB_SVC243_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC244_HANDLER) +#define SB_SVC244_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC245_HANDLER) +#define SB_SVC245_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC246_HANDLER) +#define SB_SVC246_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC247_HANDLER) +#define SB_SVC247_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC248_HANDLER) +#define SB_SVC248_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC249_HANDLER) +#define SB_SVC249_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC250_HANDLER) +#define SB_SVC250_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC251_HANDLER) +#define SB_SVC251_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC252_HANDLER) +#define SB_SVC252_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC253_HANDLER) +#define SB_SVC253_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC254_HANDLER) +#define SB_SVC254_HANDLER sb_undef_handler +#endif +#if !defined(SB_SVC255_HANDLER) +#define SB_SVC255_HANDLER sb_undef_handler +#endif + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +static void sb_undef_handler(struct port_extctx *ectxp); + +const port_syscall_t sb_syscalls[256] = { + SB_SVC0_HANDLER, SB_SVC1_HANDLER, SB_SVC2_HANDLER, SB_SVC3_HANDLER, + SB_SVC4_HANDLER, SB_SVC5_HANDLER, SB_SVC6_HANDLER, SB_SVC7_HANDLER, + SB_SVC8_HANDLER, SB_SVC9_HANDLER, SB_SVC10_HANDLER, SB_SVC11_HANDLER, + SB_SVC12_HANDLER, SB_SVC13_HANDLER, SB_SVC14_HANDLER, SB_SVC15_HANDLER, + SB_SVC16_HANDLER, SB_SVC17_HANDLER, SB_SVC18_HANDLER, SB_SVC19_HANDLER, + SB_SVC20_HANDLER, SB_SVC21_HANDLER, SB_SVC22_HANDLER, SB_SVC23_HANDLER, + SB_SVC24_HANDLER, SB_SVC25_HANDLER, SB_SVC26_HANDLER, SB_SVC27_HANDLER, + SB_SVC28_HANDLER, SB_SVC29_HANDLER, SB_SVC30_HANDLER, SB_SVC31_HANDLER, + SB_SVC32_HANDLER, SB_SVC33_HANDLER, SB_SVC34_HANDLER, SB_SVC35_HANDLER, + SB_SVC36_HANDLER, SB_SVC37_HANDLER, SB_SVC38_HANDLER, SB_SVC39_HANDLER, + SB_SVC40_HANDLER, SB_SVC41_HANDLER, SB_SVC42_HANDLER, SB_SVC43_HANDLER, + SB_SVC44_HANDLER, SB_SVC45_HANDLER, SB_SVC46_HANDLER, SB_SVC47_HANDLER, + SB_SVC48_HANDLER, SB_SVC49_HANDLER, SB_SVC50_HANDLER, SB_SVC51_HANDLER, + SB_SVC52_HANDLER, SB_SVC53_HANDLER, SB_SVC54_HANDLER, SB_SVC55_HANDLER, + SB_SVC56_HANDLER, SB_SVC57_HANDLER, SB_SVC58_HANDLER, SB_SVC59_HANDLER, + SB_SVC60_HANDLER, SB_SVC61_HANDLER, SB_SVC62_HANDLER, SB_SVC63_HANDLER, + SB_SVC64_HANDLER, SB_SVC65_HANDLER, SB_SVC66_HANDLER, SB_SVC67_HANDLER, + SB_SVC68_HANDLER, SB_SVC69_HANDLER, SB_SVC70_HANDLER, SB_SVC71_HANDLER, + SB_SVC72_HANDLER, SB_SVC73_HANDLER, SB_SVC74_HANDLER, SB_SVC75_HANDLER, + SB_SVC76_HANDLER, SB_SVC77_HANDLER, SB_SVC78_HANDLER, SB_SVC79_HANDLER, + SB_SVC80_HANDLER, SB_SVC81_HANDLER, SB_SVC82_HANDLER, SB_SVC83_HANDLER, + SB_SVC84_HANDLER, SB_SVC85_HANDLER, SB_SVC86_HANDLER, SB_SVC87_HANDLER, + SB_SVC88_HANDLER, SB_SVC89_HANDLER, SB_SVC90_HANDLER, SB_SVC91_HANDLER, + SB_SVC92_HANDLER, SB_SVC93_HANDLER, SB_SVC94_HANDLER, SB_SVC95_HANDLER, + SB_SVC96_HANDLER, SB_SVC97_HANDLER, SB_SVC98_HANDLER, SB_SVC99_HANDLER, + SB_SVC100_HANDLER, SB_SVC101_HANDLER, SB_SVC102_HANDLER, SB_SVC103_HANDLER, + SB_SVC104_HANDLER, SB_SVC105_HANDLER, SB_SVC106_HANDLER, SB_SVC107_HANDLER, + SB_SVC108_HANDLER, SB_SVC109_HANDLER, SB_SVC110_HANDLER, SB_SVC111_HANDLER, + SB_SVC112_HANDLER, SB_SVC113_HANDLER, SB_SVC114_HANDLER, SB_SVC115_HANDLER, + SB_SVC116_HANDLER, SB_SVC117_HANDLER, SB_SVC118_HANDLER, SB_SVC119_HANDLER, + SB_SVC120_HANDLER, SB_SVC121_HANDLER, SB_SVC122_HANDLER, SB_SVC123_HANDLER, + SB_SVC124_HANDLER, SB_SVC125_HANDLER, SB_SVC126_HANDLER, SB_SVC127_HANDLER, + SB_SVC128_HANDLER, SB_SVC129_HANDLER, SB_SVC130_HANDLER, SB_SVC131_HANDLER, + SB_SVC132_HANDLER, SB_SVC133_HANDLER, SB_SVC134_HANDLER, SB_SVC135_HANDLER, + SB_SVC136_HANDLER, SB_SVC137_HANDLER, SB_SVC138_HANDLER, SB_SVC139_HANDLER, + SB_SVC140_HANDLER, SB_SVC141_HANDLER, SB_SVC142_HANDLER, SB_SVC143_HANDLER, + SB_SVC144_HANDLER, SB_SVC145_HANDLER, SB_SVC146_HANDLER, SB_SVC147_HANDLER, + SB_SVC148_HANDLER, SB_SVC149_HANDLER, SB_SVC150_HANDLER, SB_SVC151_HANDLER, + SB_SVC152_HANDLER, SB_SVC153_HANDLER, SB_SVC154_HANDLER, SB_SVC155_HANDLER, + SB_SVC156_HANDLER, SB_SVC157_HANDLER, SB_SVC158_HANDLER, SB_SVC159_HANDLER, + SB_SVC160_HANDLER, SB_SVC161_HANDLER, SB_SVC162_HANDLER, SB_SVC163_HANDLER, + SB_SVC164_HANDLER, SB_SVC165_HANDLER, SB_SVC166_HANDLER, SB_SVC167_HANDLER, + SB_SVC168_HANDLER, SB_SVC169_HANDLER, SB_SVC170_HANDLER, SB_SVC171_HANDLER, + SB_SVC172_HANDLER, SB_SVC173_HANDLER, SB_SVC174_HANDLER, SB_SVC175_HANDLER, + SB_SVC176_HANDLER, SB_SVC177_HANDLER, SB_SVC178_HANDLER, SB_SVC179_HANDLER, + SB_SVC180_HANDLER, SB_SVC181_HANDLER, SB_SVC182_HANDLER, SB_SVC183_HANDLER, + SB_SVC184_HANDLER, SB_SVC185_HANDLER, SB_SVC186_HANDLER, SB_SVC187_HANDLER, + SB_SVC188_HANDLER, SB_SVC189_HANDLER, SB_SVC190_HANDLER, SB_SVC191_HANDLER, + SB_SVC192_HANDLER, SB_SVC193_HANDLER, SB_SVC194_HANDLER, SB_SVC195_HANDLER, + SB_SVC196_HANDLER, SB_SVC197_HANDLER, SB_SVC198_HANDLER, SB_SVC199_HANDLER, + SB_SVC200_HANDLER, SB_SVC201_HANDLER, SB_SVC202_HANDLER, SB_SVC203_HANDLER, + SB_SVC204_HANDLER, SB_SVC205_HANDLER, SB_SVC206_HANDLER, SB_SVC207_HANDLER, + SB_SVC208_HANDLER, SB_SVC209_HANDLER, SB_SVC210_HANDLER, SB_SVC211_HANDLER, + SB_SVC212_HANDLER, SB_SVC213_HANDLER, SB_SVC214_HANDLER, SB_SVC215_HANDLER, + SB_SVC216_HANDLER, SB_SVC217_HANDLER, SB_SVC218_HANDLER, SB_SVC219_HANDLER, + SB_SVC220_HANDLER, SB_SVC221_HANDLER, SB_SVC222_HANDLER, SB_SVC223_HANDLER, + SB_SVC224_HANDLER, SB_SVC225_HANDLER, SB_SVC226_HANDLER, SB_SVC227_HANDLER, + SB_SVC228_HANDLER, SB_SVC229_HANDLER, SB_SVC230_HANDLER, SB_SVC231_HANDLER, + SB_SVC232_HANDLER, SB_SVC233_HANDLER, SB_SVC234_HANDLER, SB_SVC235_HANDLER, + SB_SVC236_HANDLER, SB_SVC237_HANDLER, SB_SVC238_HANDLER, SB_SVC239_HANDLER, + SB_SVC240_HANDLER, SB_SVC241_HANDLER, SB_SVC242_HANDLER, SB_SVC243_HANDLER, + SB_SVC244_HANDLER, SB_SVC245_HANDLER, SB_SVC246_HANDLER, SB_SVC247_HANDLER, + SB_SVC248_HANDLER, SB_SVC249_HANDLER, SB_SVC250_HANDLER, SB_SVC251_HANDLER, + SB_SVC252_HANDLER, SB_SVC253_HANDLER, SB_SVC254_HANDLER, SB_SVC255_HANDLER +}; + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +static void sb_undef_handler(struct port_extctx *ectxp) { + + ectxp->r0 = SB_ERR_ENOSYS; +} + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + +void sb_api_stdio(struct port_extctx *ectxp) { + + switch (ectxp->r0) { + case SB_POSIX_OPEN: + ectxp->r0 = sb_posix_open((const char *)ectxp->r1, + ectxp->r2); + break; + case SB_POSIX_CLOSE: + ectxp->r0 = sb_posix_close(ectxp->r1); + break; + case SB_POSIX_READ: + ectxp->r0 = sb_posix_read(ectxp->r1, + (void *)ectxp->r2, + (size_t)ectxp->r3); + break; + case SB_POSIX_WRITE: + ectxp->r0 = sb_posix_write(ectxp->r1, + (const void *)ectxp->r2, + (size_t)ectxp->r3); + break; + case SB_POSIX_LSEEK: + ectxp->r0 = sb_posix_lseek(ectxp->r1, + ectxp->r2, + ectxp->r3); + break; + default: + ectxp->r0 = SB_ERR_ENOSYS; + break; + } +} + +void sb_api_exit(struct port_extctx *ectxp) { + + chThdExit((msg_t )ectxp->r0); + + /* Cannot get here.*/ + ectxp->r0 = SB_ERR_ENOSYS; +} + +void sb_api_get_systime(struct port_extctx *ectxp) { + + ectxp->r0 = (uint32_t)chVTGetSystemTimeX(); +} + +void sb_api_get_frequency(struct port_extctx *ectxp) { + + ectxp->r0 = (uint32_t)CH_CFG_ST_FREQUENCY; +} + +void sb_api_sleep(struct port_extctx *ectxp) { + sysinterval_t interval = (sysinterval_t )ectxp->r0; + + if (interval != TIME_IMMEDIATE) { + chThdSleep(interval); + } + + ectxp->r0 = SB_ERR_NOERROR; +} + +void sb_api_sleep_until_windowed(struct port_extctx *ectxp) { + + chThdSleepUntilWindowed((systime_t )ectxp->r0, (systime_t )ectxp->r1); + + ectxp->r0 = SB_ERR_NOERROR; +} + +void sb_api_wait_message(struct port_extctx *ectxp) { +#if CH_CFG_USE_MESSAGES == TRUE + sb_class_t *sbcp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; + + if (sbcp->msg_tp == NULL) { + sbcp->msg_tp = chMsgWait(); + ectxp->r0 = (uint32_t)chMsgGet(sbcp->msg_tp); + } + else { + chMsgRelease(sbcp->msg_tp, MSG_RESET); + sbcp->msg_tp = NULL; + ectxp->r0 = SB_ERR_EBUSY; + } +#else + ectxp->r0 = SB_ERR_NOT_IMPLEMENTED; +#endif +} + +void sb_api_reply_message(struct port_extctx *ectxp) { +#if CH_CFG_USE_MESSAGES == TRUE + sb_class_t *sbcp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; + + if (sbcp->msg_tp != NULL) { + chMsgRelease(sbcp->msg_tp, (msg_t )ectxp->r0); + sbcp->msg_tp = NULL; + ectxp->r0 = SB_ERR_NOERROR; + } + else { + ectxp->r0 = SB_ERR_EBUSY; + } +#else + ectxp->r0 = SB_ERR_NOT_IMPLEMENTED; +#endif +} + +void sb_api_wait_one_timeout(struct port_extctx *ectxp) { +#if CH_CFG_USE_EVENTS == TRUE + + ectxp->r0 = (uint32_t)chEvtWaitOneTimeout((eventmask_t )ectxp->r0, + (sysinterval_t )ectxp->r1); +#else + ectxp->r0 = SB_ERR_NOT_IMPLEMENTED; +#endif +} + +void sb_api_wait_any_timeout(struct port_extctx *ectxp) { +#if CH_CFG_USE_EVENTS == TRUE + + ectxp->r0 = (uint32_t)chEvtWaitAnyTimeout((eventmask_t )ectxp->r0, + (sysinterval_t )ectxp->r1); +#else + ectxp->r0 = SB_ERR_NOT_IMPLEMENTED; +#endif +} + +void sb_api_wait_all_timeout(struct port_extctx *ectxp) { +#if CH_CFG_USE_EVENTS == TRUE + + ectxp->r0 = (uint32_t)chEvtWaitAllTimeout((eventmask_t )ectxp->r0, + (sysinterval_t )ectxp->r1); +#else + ectxp->r0 = SB_ERR_NOT_IMPLEMENTED; +#endif +} + +void sb_api_broadcast_flags(struct port_extctx *ectxp) { +#if CH_CFG_USE_EVENTS == TRUE + sb_class_t *sbcp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; + + chEvtBroadcastFlags(&sbcp->es, (eventflags_t )ectxp->r0); + ectxp->r0 = SB_ERR_NOERROR; +#else + ectxp->r0 = SB_ERR_NOT_IMPLEMENTED; +#endif +} + +/** @} */ diff --git a/ChibiOS_20.3.2/os/sb/host/sbapi.h b/ChibiOS_20.3.2/os/sb/host/sbapi.h new file mode 100644 index 0000000..e2a08d7 --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/host/sbapi.h @@ -0,0 +1,127 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sb/host/sbapi.h + * @brief ARM sandbox host API macros and structures. + * + * @addtogroup ARM_SANDBOX_HOSTAPI + * @{ + */ + +#ifndef SBAPI_H +#define SBAPI_H + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +/** + * @brief Type of a syscall handler. + */ +typedef void (*port_syscall_t)(struct port_extctx *ectx); + +/** + * @brief Sandbox Stream interface methods. + * @note Is intentionally compatible with HAL streams but we have to + * duplicate is because we don't want dependencies with HAL in + * this subsystem. + */ +struct SandboxStreamVMT { + /** + * @brief Object instance offset. + */ + size_t instance_offset; + /** + * @brief Stream write buffer method. + */ + size_t (*write)(void *instance, const uint8_t *bp, size_t n); + /** + * @brief Stream read buffer method. + */ + size_t (*read)(void *instance, uint8_t *bp, size_t n); + /** + * @brief Channel put method, blocking. + */ + msg_t (*put)(void *instance, uint8_t b); + /** + * @brief Channel get method, blocking. + */ + msg_t (*get)(void *instance); +}; + +/** + * @brief Sandbox Stream class. + * @note Is intentionally compatible with HAL streams but we have to + * duplicate is because we don't want dependencies with HAL in + * this subsystem. + */ +typedef struct { + /** + * @brief Virtual Methods Table. + */ + const struct SandboxStreamVMT *vmt; +} SandboxStream; + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void sb_api_stdio(struct port_extctx *ectxp); + void sb_api_exit(struct port_extctx *ctxp); + void sb_api_get_systime(struct port_extctx *ctxp); + void sb_api_get_frequency(struct port_extctx *ctxp); + void sb_api_sleep(struct port_extctx *ctxp); + void sb_api_sleep_until_windowed(struct port_extctx *ctxp); + void sb_api_wait_message(struct port_extctx *ctxp); + void sb_api_reply_message(struct port_extctx *ctxp); + void sb_api_wait_one_timeout(struct port_extctx *ctxp); + void sb_api_wait_any_timeout(struct port_extctx *ctxp); + void sb_api_wait_all_timeout(struct port_extctx *ctxp); + void sb_api_broadcast_flags(struct port_extctx *ctxp); +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +#endif /* SBAPI_H */ + +/** @} */ diff --git a/ChibiOS_20.3.2/os/sb/host/sbhost.c b/ChibiOS_20.3.2/os/sb/host/sbhost.c new file mode 100644 index 0000000..177a144 --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/host/sbhost.c @@ -0,0 +1,146 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sb/host/sbhost.c + * @brief ARM sandbox host code. + * + * @addtogroup ARM_SANDBOX + * @{ + */ + +#include "ch.h" +#include "sb.h" + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + +bool sb_is_valid_read_range(sb_class_t *sbcp, const void *start, size_t size) { + const sb_memory_region_t *rp = &sbcp->config->regions[0]; + + do { + if (((uint32_t)start >= rp->base) && ((uint32_t)start < rp->end) && + (size <= ((size_t)rp->base - (size_t)start))) { + return true; + } + rp++; + } while (rp < &sbcp->config->regions[SB_NUM_REGIONS]); + + return false; +} + +bool sb_is_valid_write_range(sb_class_t *sbcp, void *start, size_t size) { + const sb_memory_region_t *rp = &sbcp->config->regions[0]; + + do { + if (((uint32_t)start >= rp->base) && ((uint32_t)start < rp->end) && + (size <= ((size_t)rp->base - (size_t)start))) { + return rp->writeable; + } + rp++; + } while (rp < &sbcp->config->regions[SB_NUM_REGIONS]); + + return false; +} + +/** + * @brief Sandbox object initialization. + * + * @param[out] sbcp pointer to the sandbox object + * + * @init + */ +void sbObjectInit(sb_class_t *sbcp) { + + sbcp->config = NULL; + sbcp->tp = NULL; +#if CH_CFG_USE_MESSAGES == TRUE + sbcp->msg_tp = NULL; +#endif +#if CH_CFG_USE_EVENTS == TRUE + chEvtObjectInit(&sbcp->es); +#endif +} + +/** + * @brief Starts a sandboxed thread. + * + * @param[in] sbcp pointer to the sandbox object + * @return The function returns only if the operation failed. + * + * @api + */ +void sbStart(sb_class_t *sbcp, const sb_config_t *config) { + uint32_t pc, psp; + const sb_header_t *sbhp; + + /* Header location.*/ + sbhp = (const sb_header_t *)config->regions[config->code_region].base; + + /* Checking header magic numbers.*/ + if ((sbhp->hdr_magic1 != SB_MAGIC1) || (sbhp->hdr_magic2 != SB_MAGIC2)) { + return; + } + + /* Checking header size and alignment.*/ + if (sbhp->hdr_size != sizeof (sb_header_t)) { + return; + } + + /* PC initial address, by convention it is immediately after the header.*/ + pc = (config->regions[config->code_region].base + sizeof (sb_header_t)) | 1U; + + /* PSP initial address.*/ + psp = config->regions[config->data_region].end; + + /* Additional context information.*/ + sbcp->config = config; + sbcp->tp = chThdGetSelfX(); + sbcp->tp->ctx.syscall.p = (const void *)sbcp; + sbcp->tp->ctx.syscall.psp = __get_PSP(); + + /* Jumping to the unprivileged code.*/ + port_unprivileged_jump(pc, psp); + + /* Must never happen condition.*/ + chSysHalt("returned"); +} + +/** @} */ diff --git a/ChibiOS_20.3.2/os/sb/host/sbhost.h b/ChibiOS_20.3.2/os/sb/host/sbhost.h new file mode 100644 index 0000000..5207af1 --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/host/sbhost.h @@ -0,0 +1,265 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sb/host/sbhost.h + * @brief ARM sandbox host macros and structures. + * + * @addtogroup ARM_SANDBOX + * @{ + */ + +#ifndef SBHOST_H +#define SBHOST_H + +#include "sberr.h" +#include "sbapi.h" + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/** + * @brief Magic numbers + * @{ + */ +#define SB_MAGIC1 0xFE9154C0U +#define SB_MAGIC2 0x0C4519EFU +/** @} */ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +typedef struct { + /** + * @brief Memory range base. + * @note Zero if not used. + */ + uint32_t base; + /** + * @brief Memory range end (non inclusive). + * @note Zero if not used. + */ + uint32_t end; + /** + * @brief Writable memory range. + */ + bool writeable; +} sb_memory_region_t; + +/** + * @brief Type of a sandbox configuration structure. + */ +typedef struct { + /** + * @brief Memory region for code. + * @note It is used to locate the startup header. + */ + uint32_t code_region; + /** + * @brief Memory region for data and stack. + * @note It is used for initial PSP placement. + */ + uint32_t data_region; + /** + * @brief SandBox regions. + * @note The following memory regions are used only for pointers + * validation, not for MPU setup. + */ + sb_memory_region_t regions[SB_NUM_REGIONS]; + /** + * @brief Sandbox STDIN stream. + * @note Set this to @p NULL if standard I/O is not needed. + * @note By design you can use HAL streams here, you need to use + * a cast however. + */ + SandboxStream *stdin_stream; + /** + * @brief Sandbox STDOUT stream. + * @note Set this to @p NULL if standard I/O is not needed. + * @note By design you can use HAL streams here, you need to use + * a cast however. + */ + SandboxStream *stdout_stream; + /** + * @brief Sandbox STDERR stream. + * @note Set this to @p NULL if standard I/O is not needed. + * @note By design you can use HAL streams here, you need to use + * a cast however. + */ + SandboxStream *stderr_stream; +} sb_config_t; + +/** + * @brief Type of a sandbox object. + */ +typedef struct { + /** + * @brief Pointer to the sandbox configuration data. + */ + const sb_config_t *config; + /** + * @brief Thread running in the sandbox. + */ + thread_t *tp; +#if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__) + /** + * @brief Thread sending a message to the sandbox. + */ + thread_t *msg_tp; +#endif +#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__) + event_source_t es; +#endif +} sb_class_t; + +/** + * @brief Type of a sandbox binary image header. + */ +typedef struct { + /** + * @brief Magic number 1. + */ + uint32_t hdr_magic1; + /** + * @brief Magic number 2. + */ + uint32_t hdr_magic2; + /** + * @brief Header size, inclusive of magic numbers. + */ + uint32_t hdr_size; + /** + * @brief Used-defined parameters, defaulted to zero. + */ + uint32_t user; +} sb_header_t; + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void port_syscall(struct port_extctx *ctxp, uint32_t n); + bool sb_is_valid_read_range(sb_class_t *sbcp, const void *start, size_t size); + bool sb_is_valid_write_range(sb_class_t *sbcp, void *start, size_t size); + void sbObjectInit(sb_class_t *sbcp); + void sbStart(sb_class_t *sbcp, const sb_config_t *config); +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +#if (CH_CFG_USE_WAITEXIT == TRUE) || defined(__DOXYGEN__) +/** + * @brief Blocks the execution of the invoking thread until the sandbox + * thread terminates then the exit code is returned. + * @pre The configuration option @p CH_CFG_USE_WAITEXIT must be enabled in + * order to use this function. + * + * @param[in] sbcp pointer to the sandbox object + * @return The exit code from the terminated thread. + * + * @api + */ +static inline msg_t sbWait(sb_class_t *sbcp) { + + return chThdWait(sbcp->tp); +} +#endif /* CH_CFG_USE_WAITEXIT == TRUE */ + +#if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__) +/** + * @brief Sends a message to a sandboxed thread. + * + * @param[in] sbcp pointer to the sandbox object + * @param[in] msg message to be sent + * @return The returned message. + * @retval MSG_RESET Sandboxed thread API usage error, exchange aborted. + * + * @api + */ +static inline msg_t sbSendMessage(sb_class_t *sbcp, msg_t msg) { + + return chMsgSend(sbcp->tp, msg); +} +#endif /* CH_CFG_USE_MESSAGES == TRUE */ + +#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__) +/** + * @brief Adds a set of event flags directly to the specified sandbox. + * + * @param[in] sbcp pointer to the sandbox object + * @param[in] events the events set to be ORed + * + * @iclass + */ +static inline void sbEvtSignalI(sb_class_t *sbcp, eventmask_t events) { + + chEvtSignalI(sbcp->tp, events); +} + +/** + * @brief Adds a set of event flags directly to the specified sandbox. + * + * @param[in] sbcp pointer to the sandbox object + * @param[in] events the events set to be ORed + * + * @api + */ +static inline void sbEvtSignal(sb_class_t *sbcp, eventmask_t events) { + + chEvtSignal(sbcp->tp, events); +} + +/** + * @brief Returns the sandbox event source object. + * + * @param[in] sbcp pointer to the sandbox object + * @return The pointer to the event source object. + * + * @xclass + */ +static inline event_source_t *sbGetEventSourceX(sb_class_t *sbcp) { + + return &sbcp->es; +} +#endif /* CH_CFG_USE_EVENTS == TRUE */ + +#endif /* SBHOST_H */ + +/** @} */ diff --git a/ChibiOS_20.3.2/os/sb/host/sbposix.c b/ChibiOS_20.3.2/os/sb/host/sbposix.c new file mode 100644 index 0000000..b2f6839 --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/host/sbposix.c @@ -0,0 +1,136 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sb/host/sbposix.c + * @brief ARM sandbox host Posix API code. + * + * @addtogroup ARM_SANDBOX_HOSTAPI + * @{ + */ + +#include "ch.h" +#include "sb.h" + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + +uint32_t sb_posix_open(const char *pathname, uint32_t flags) { + + (void)pathname; + (void)flags; + + return SB_ERR_ENOENT; +} + +uint32_t sb_posix_close(uint32_t fd) { + + if ((fd == 0U) || (fd == 1U) || (fd == 2U)) { + + return SB_ERR_NOERROR; + } + + return SB_ERR_EBADFD; +} + +uint32_t sb_posix_read(uint32_t fd, uint8_t *buf, size_t count) { + sb_class_t *sbcp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; + + if (!sb_is_valid_write_range(sbcp, (void *)buf, count)) { + return SB_ERR_EFAULT; + } + + if (fd == 0U) { + SandboxStream *ssp = sbcp->config->stdin_stream; + + if ((count == 0U) || (ssp == NULL)) { + return 0U; + } + + return (uint32_t)ssp->vmt->read((void *)ssp, buf, count); + } + + return SB_ERR_EBADFD; +} + +uint32_t sb_posix_write(uint32_t fd, const uint8_t *buf, size_t count) { + sb_class_t *sbcp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; + + if (!sb_is_valid_read_range(sbcp, (const void *)buf, count)) { + return SB_ERR_EFAULT; + } + + if (fd == 1U) { + SandboxStream *ssp = sbcp->config->stdout_stream; + + if ((count == 0U) || (ssp == NULL)) { + return 0U; + } + + return (uint32_t)ssp->vmt->write((void *)ssp, buf, count); + } + + if (fd == 2U) { + SandboxStream *ssp = sbcp->config->stderr_stream; + + if ((count == 0U) || (ssp == NULL)) { + return 0U; + } + + return (uint32_t)ssp->vmt->write((void *)ssp, buf, count); + } + + return SB_ERR_EBADFD; +} + +uint32_t sb_posix_lseek(uint32_t fd, uint32_t offset, uint32_t whence) { + + (void)offset; + (void)whence; + + if ((fd == 0U) || (fd == 1U) || (fd == 2U)) { + + return SB_ERR_ESPIPE; + } + + return SB_ERR_EBADFD; +} + +/** @} */ diff --git a/ChibiOS_20.3.2/os/sb/host/sbposix.h b/ChibiOS_20.3.2/os/sb/host/sbposix.h new file mode 100644 index 0000000..9969363 --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/host/sbposix.h @@ -0,0 +1,73 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sb/host/sbposix.h + * @brief ARM sandbox host Posix API macros and structures. + * + * @addtogroup ARM_SANDBOX_POSIX + * @{ + */ + +#ifndef SBPOSIX_H +#define SBPOSIX_H + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + uint32_t sb_posix_open(const char *pathname, uint32_t flags); + uint32_t sb_posix_close(uint32_t fd); + uint32_t sb_posix_read(uint32_t fd, uint8_t *buf, size_t count); + uint32_t sb_posix_write(uint32_t fd, const uint8_t *buf, size_t count); + uint32_t sb_posix_lseek(uint32_t fd, uint32_t offset, uint32_t whence); +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +#endif /* SBPOSIX_H */ + +/** @} */ diff --git a/ChibiOS_20.3.2/os/sb/user/sbuser.c b/ChibiOS_20.3.2/os/sb/user/sbuser.c new file mode 100644 index 0000000..92838d5 --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/user/sbuser.c @@ -0,0 +1,74 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sb/user/sbuser.c + * @brief ARMv7-M sandbox user API code. + * + * @addtogroup ARMV7M_SANDBOX_API + * @{ + */ + +#include +#include +#include + +#include "sbuser.h" + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/** + * @brief Sandbox API internal state. + */ +sbapi_state_t sb; + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + +/** + * @brief API layer initialization. + * @note To be called before any other call to the "sb" functions. + * + * @init + */ +void sbApiInit(void) { + + sb.frequency = (time_conv_t)sbGetFrequency(); +} + +/** @} */ diff --git a/ChibiOS_20.3.2/os/sb/user/sbuser.h b/ChibiOS_20.3.2/os/sb/user/sbuser.h new file mode 100644 index 0000000..ed0be6f --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/user/sbuser.h @@ -0,0 +1,669 @@ +/* + ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file sb/user/sbapi.h + * @brief ARMv7-M sandbox user API macros and structures. + * + * @addtogroup ARMV7M_SANDBOX_USERAPI + * @{ + */ + +#ifndef SBUSER_H +#define SBUSER_H + +#include "sberr.h" + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +/** + * @brief Type of system time counter. + */ +typedef uint32_t systime_t; + +/** + * @brief Type of system time interval. + */ +typedef uint32_t sysinterval_t; + +/** + * @brief Type of a wide time conversion variable. + */ +typedef uint64_t time_conv_t; + +/** + * @brief Type of time in microseconds. + */ +typedef uint32_t time_usecs_t; + +/** + * @brief Type of time in milliseconds. + */ +typedef uint32_t time_msecs_t; + +/** + * @brief Type of time in seconds. + */ +typedef uint32_t time_secs_t; + +/** + * @brief Type of a message. + */ +typedef uint32_t msg_t; + +/** + * @brief Type of an event mask. + */ +typedef uint32_t eventmask_t; + +/** + * @brief Type of event flags. + */ +typedef uint32_t eventflags_t; + +/** + * @brief Type of a sandbox API internal state variables. + */ +typedef struct { + /** + * @brief System tick frequency. + */ + time_conv_t frequency; +} sbapi_state_t; + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/** + * @name Messages-related macros + * @{ + */ +#define MSG_OK (msg_t)0 +#define MSG_TIMEOUT (msg_t)-1 +#define MSG_RESET (msg_t)-2 +/** @} */ + +/** + * @name Events-related macros + * @{ + */ +#define ALL_EVENTS ((eventmask_t)-1) +#define EVENT_MASK(eid) ((eventmask_t)1 << (eventmask_t)(eid)) +/** @} */ + +/** + * @name Time and intervals related macros + * @{ + */ +#define TIME_IMMEDIATE ((sysinterval_t)0) +#define TIME_INFINITE ((sysinterval_t)-1) +#define TIME_MAX_INTERVAL ((sysinterval_t)-2) +#define TIME_MAX_SYSTIME ((systime_t)-1) +/** @} */ + +/** + * @name SVC instruction wrappers. + * @{ + */ +#define __syscall0(x) \ + asm volatile ("svc " #x : : : "memory") + +#define __syscall0r(x) \ + register uint32_t r0 asm ("r0"); \ + asm volatile ("svc " #x : "=r" (r0) : : "memory") + +#define __syscall1r(x, p1) \ + register uint32_t r0 asm ("r0") = (uint32_t)(p1); \ + asm volatile ("svc " #x : "=r" (r0) : "r" (r0) : "memory") + +#define __syscall2r(x, p1, p2) \ + register uint32_t r0 asm ("r0") = (uint32_t)(p1); \ + register uint32_t r1 asm ("r1") = (uint32_t)(p2); \ + asm volatile ("svc " #x : "=r" (r0) : "r" (r0), "r" (r1) : "memory") + +#define __syscall3r(x, p1, p2, p3) \ + register uint32_t r0 asm ("r0") = (uint32_t)(p1); \ + register uint32_t r1 asm ("r1") = (uint32_t)(p2); \ + register uint32_t r2 asm ("r2") = (uint32_t)(p3); \ + asm volatile ("svc " #x : "=r" (r0) : "r" (r0), "r" (r1), \ + "r" (r2) : "memory") + +#define __syscall4r(x, p1, p2, p3, p4) \ + register uint32_t r0 asm ("r0") = (uint32_t)(p1); \ + register uint32_t r1 asm ("r1") = (uint32_t)(p2); \ + register uint32_t r2 asm ("r2") = (uint32_t)(p3); \ + register uint32_t r3 asm ("r3") = (uint32_t)(p4); \ + asm volatile ("svc " #x : "=r" (r0) : "r" (r0), "r" (r1), \ + "r" (r2), "r" (r3) : "memory") +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +extern sbapi_state_t sb; + +#ifdef __cplusplus +extern "C" { +#endif + void sbApiInit(void); +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +/** + * @brief Posix-style file open. + * + * @param[in] pathname file to be opened + * @param[in] flags open mode + * @return The file descriptor or an error. + */ +static inline uint32_t sbFileOpen(const char *pathname, + uint32_t flags) { + + __syscall3r(0, SB_POSIX_OPEN, pathname, flags); + return r0; +} + +/** + * @brief Posix-style file close. + * + * @param[in] fd file descriptor + * @return Operation result. + */ +static inline uint32_t sbFileClose(uint32_t fd) { + + __syscall2r(0, SB_POSIX_CLOSE, fd); + return r0; +} + +/** + * @brief Posix-style file read. + * + * @param[in] fd file descriptor + * @param[out] buf buffer pointer + * @param[in] count number of bytes + * @return The number of bytes really transferred or an error. + */ +static inline size_t sbFileRead(uint32_t fd, + uint8_t *buf, + size_t count) { + + __syscall4r(0, SB_POSIX_READ, fd, buf, count); + return (size_t)r0; +} + +/** + * @brief Posix-style file write. + * + * @param[in] fd file descriptor + * @param[in] buf buffer pointer + * @param[in] count number of bytes + * @return The number of bytes really transferred or an error. + */ +static inline size_t sbFileWrite(uint32_t fd, + const uint8_t *buf, + size_t count) { + + __syscall4r(0, SB_POSIX_WRITE, fd, buf, count); + return (size_t)r0; +} + +/** + * @brief Posix-style file seek. + * + * @param[in] fd file descriptor + * @param[in] offset file offset + * @param[in] whence operation mode + * @return Operation result. + */ +static inline uint32_t sbFileSeek(uint32_t fd, + uint32_t offset, + uint32_t whence) { + + __syscall4r(0, SB_POSIX_LSEEK, fd, offset, whence); + return (size_t)r0; +} + +/** + * @brief Terminates the sandbox. + * + * @param[in] msg The exit message. + * + * @api + */ +static inline void sbExit(msg_t msg) { + + __syscall1r(1, msg); +} + +/** + * @brief Returns the system time. + * + * @return The current system time. + */ +static inline systime_t sbGetSystemTime(void) { + + __syscall0r(2); + return (systime_t)r0; +} + +/** + * @brief Returns the system time frequency. + * + * @return The system time frequency. + */ +static inline uint32_t sbGetFrequency(void) { + + __syscall0r(3); + return (uint32_t)r0; +} + +/** + * @brief Suspends the invoking thread for the specified interval. + * + * @param[in] interval the delay in system ticks + * + * @api + */ +static inline void sbSleep(sysinterval_t interval) { + + __syscall1r(4, interval); +} + +/** + * @brief Suspends the invoking thread until the system time arrives to the + * specified value. + * @note The system time is assumed to be between @p start and @p next + * else the call is assumed to have been called outside the + * allowed time interval, in this case no sleep is performed. + * + * @param[in] prev absolute system time of the previous deadline + * @param[in] next absolute system time of the next deadline + * @return the @p next parameter + * + * @api + */ +static inline void sbSleepUntil(systime_t prev, systime_t next) { + + __syscall2r(5, prev, next); +} + +/** + * @brief Waits for a message. + * + * @return The received message. + */ +static inline msg_t sbMsgWait(void) { + + __syscall0r(6); + return (uint32_t)r0; +} + +/** + * @brief Replies to a message. + * + * @param[in] msg the reply message + * + * @api + */ +static inline uint32_t sbMsgReply(msg_t msg) { + + __syscall1r(7, msg); + return (uint32_t)r0; +} + +/** + * @brief Waits for exactly one of the specified events. + * @details The function waits for one event among those specified in + * @p events to become pending then the event is cleared and returned. + * @note One and only one event is served in the function, the one with the + * lowest event id. The function is meant to be invoked into a loop + * in order to serve all the pending events.
+ * This means that Event Listeners with a lower event identifier have + * an higher priority. + * + * @param[in] events events that the function should wait + * for, @p ALL_EVENTS enables all the events + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The mask of the lowest event id served and cleared. + * @retval 0 if the operation has timed out. + * + * @api + */ +static inline eventmask_t sbEventWaitOneTimeout(eventmask_t events, + sysinterval_t timeout) { + + __syscall2r(8, events, timeout); + return (uint32_t)r0; +} + +/** + * @brief Waits for any of the specified events. + * @details The function waits for any event among those specified in + * @p events to become pending then the events are cleared and + * returned. + * + * @param[in] events events that the function should wait + * for, @p ALL_EVENTS enables all the events + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The mask of the served and cleared events. + * @retval 0 if the operation has timed out. + * + * @api + */ +static inline eventmask_t sbEventWaitAnyTimeout(eventmask_t events, + sysinterval_t timeout) { + + __syscall2r(9, events, timeout); + return (uint32_t)r0; +} + +/** + * @brief Waits for all the specified events. + * @details The function waits for all the events specified in @p events to + * become pending then the events are cleared and returned. + * + * @param[in] events events that the function should wait + * for, @p ALL_EVENTS requires all the events + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_IMMEDIATE immediate timeout. + * - @a TIME_INFINITE no timeout. + * . + * @return The mask of the served and cleared events. + * @retval 0 if the operation has timed out. + * + * @api + */ +static inline eventmask_t sbEventWaitAllTimeout(eventmask_t events, + sysinterval_t timeout) { + + __syscall2r(10, events, timeout); + return (uint32_t)r0; +} + +/** + * @brief Signals all the Event Listeners registered on the specified Event + * Source. + * + * @param[in] flags the flags set to be added to the listener flags mask + * + * @api + */ +static inline uint32_t sbEventBroadcastFlags(eventflags_t flags) { + + __syscall1r(11, flags); + return (uint32_t)r0; +} + +/** + * @brief Seconds to time interval. + * @details Converts from seconds to system ticks number. + * @note The result is rounded upward to the next tick boundary. + * + * @param[in] secs number of seconds + * @return The number of ticks. + * + * @special + */ +static inline sysinterval_t sbTimeS2I(time_secs_t secs) { + time_conv_t ticks; + + ticks = (time_conv_t)secs * sb.frequency; + +/* sbDbgAssert(ticks <= (time_conv_t)TIME_MAX_INTERVAL, + "conversion overflow");*/ + + return (sysinterval_t)ticks; +} + +/** + * @brief Milliseconds to time interval. + * @details Converts from milliseconds to system ticks number. + * @note The result is rounded upward to the next tick boundary. + * + * @param[in] msec number of milliseconds + * @return The number of ticks. + * + * @special + */ +static inline sysinterval_t sbTimeMS2I(time_msecs_t msec) { + time_conv_t ticks; + + ticks = (((time_conv_t)msec * sb.frequency) + + (time_conv_t)999) / (time_conv_t)1000; + +/* chDbgAssert(ticks <= (time_conv_t)TIME_MAX_INTERVAL, + "conversion overflow");*/ + + return (sysinterval_t)ticks; +} + +/** + * @brief Microseconds to time interval. + * @details Converts from microseconds to system ticks number. + * @note The result is rounded upward to the next tick boundary. + * + * @param[in] usec number of microseconds + * @return The number of ticks. + * + * @special + */ +static inline sysinterval_t sbTimeUS2I(time_usecs_t usec) { + time_conv_t ticks; + + ticks = (((time_conv_t)usec * sb.frequency) + + (time_conv_t)999999) / (time_conv_t)1000000; + +/* chDbgAssert(ticks <= (time_conv_t)TIME_MAX_INTERVAL, + "conversion overflow");*/ + + return (sysinterval_t)ticks; +} + +/** + * @brief Time interval to seconds. + * @details Converts from system interval to seconds. + * @note The result is rounded up to the next second boundary. + * + * @param[in] interval interval in ticks + * @return The number of seconds. + * + * @special + */ +static inline time_secs_t sbTimeI2S(sysinterval_t interval) { + time_conv_t secs; + + secs = ((time_conv_t)interval + + sb.frequency - + (time_conv_t)1) / sb.frequency; + +/* sbDbgAssert(secs < (time_conv_t)((time_secs_t)-1), + "conversion overflow");*/ + + return (time_secs_t)secs; +} + +/** + * @brief Time interval to milliseconds. + * @details Converts from system interval to milliseconds. + * @note The result is rounded up to the next millisecond boundary. + * + * @param[in] interval interval in ticks + * @return The number of milliseconds. + * + * @special + */ +static inline time_msecs_t sbTimeI2MS(sysinterval_t interval) { + time_conv_t msecs; + + msecs = (((time_conv_t)interval * (time_conv_t)1000) + + sb.frequency - (time_conv_t)1) / + sb.frequency; + +/* sbDbgAssert(msecs < (time_conv_t)((time_msecs_t)-1), + "conversion overflow");*/ + + return (time_msecs_t)msecs; +} + +/** + * @brief Time interval to microseconds. + * @details Converts from system interval to microseconds. + * @note The result is rounded up to the next microsecond boundary. + * + * @param[in] interval interval in ticks + * @return The number of microseconds. + * + * @special + */ +static inline time_usecs_t sbTimeI2US(sysinterval_t interval) { + time_conv_t usecs; + + usecs = (((time_conv_t)interval * (time_conv_t)1000000) + + sb.frequency - (time_conv_t)1) / sb.frequency; + +/* sbDbgAssert(usecs <= (time_conv_t)((time_usecs_t)-1), + "conversion overflow");*/ + + return (time_usecs_t)usecs; +} + +/** + * @brief Adds an interval to a system time returning a system time. + * + * @param[in] systime base system time + * @param[in] interval interval to be added + * @return The new system time. + * + * @xclass + */ +static inline systime_t sbTimeAddX(systime_t systime, sysinterval_t interval) { + + return systime + (systime_t)interval; +} + +/** + * @brief Subtracts two system times returning an interval. + * + * @param[in] start first system time + * @param[in] end second system time + * @return The interval representing the time difference. + * + * @xclass + */ +static inline sysinterval_t sbTimeDiffX(systime_t start, systime_t end) { + + return (sysinterval_t)((systime_t)(end - start)); +} + +/** + * @brief Checks if the specified time is within the specified time range. + * @note When start==end then the function returns always true because the + * whole time range is specified. + * + * @param[in] time the time to be verified + * @param[in] start the start of the time window (inclusive) + * @param[in] end the end of the time window (non inclusive) + * @retval true current time within the specified time window. + * @retval false current time not within the specified time window. + * + * @xclass + */ +static inline bool sbTimeIsInRangeX(systime_t time, systime_t start, systime_t end) { + + return (bool)((systime_t)((systime_t)time - (systime_t)start) < + (systime_t)((systime_t)end - (systime_t)start)); +} + +/** + * @brief Delays the invoking thread for the specified number of seconds. + * @note The specified time is rounded up to a value allowed by the real + * system tick clock. + * + * @param[in] secs time in seconds + * + * @api + */ +static inline void sbSleepSeconds(time_secs_t secs) { + + sbSleep(sbTimeS2I(secs)); +} + +/** + * @brief Delays the invoking thread for the specified number of + * milliseconds. + * @note The specified time is rounded up to a value allowed by the real + * system tick clock. + * + * @param[in] msecs time in milliseconds + * + * @api + */ +static inline void sbSleepMilliseconds(time_msecs_t msecs) { + + sbSleep(sbTimeMS2I(msecs)); +} + +/** + * @brief Delays the invoking thread for the specified number of + * microseconds. + * @note The specified time is rounded up to a value allowed by the real + * system tick clock. + * + * @param[in] usecs time in microseconds + * + * @api + */ +static inline void sbSleepMicroseconds(time_usecs_t usecs) { + + sbSleep(sbTimeUS2I(usecs)); +} + +#endif /* SBUSER_H */ + +/** @} */ diff --git a/ChibiOS_20.3.2/os/sb/user/sbuser.mk b/ChibiOS_20.3.2/os/sb/user/sbuser.mk new file mode 100644 index 0000000..fcf16f3 --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/user/sbuser.mk @@ -0,0 +1,12 @@ +# List of the ChibiOS ARMv7-M sandbox user files. +SBUSERSRC = $(CHIBIOS)/os/sb/user/sbuser.c + +SBUSERASM = + +SBUSERINC = $(CHIBIOS)/os/sb/common \ + $(CHIBIOS)/os/sb/user + +# Shared variables +ALLXASMSRC += $(SBUSERASM) +ALLCSRC += $(SBUSERSRC) +ALLINC += $(SBUSERINC) diff --git a/ChibiOS_20.3.2/os/sb/various/syscalls.c b/ChibiOS_20.3.2/os/sb/various/syscalls.c new file mode 100644 index 0000000..4d3ae0f --- /dev/null +++ b/ChibiOS_20.3.2/os/sb/various/syscalls.c @@ -0,0 +1,142 @@ +/* + ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + + 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 +#include +#include +#include +#include +#include +#include +#include + +#include "sbuser.h" + +#define MAKERR(e) (-(int)(e)) + +__attribute__((used)) +int _close_r(struct _reent *r, int file) { + uint32_t err; + + err = sbFileClose((uint32_t)file); + if (SB_ERR_ISERROR(err)) { + __errno_r(r) = MAKERR(err); + return -1; + } + + return 0; +} + +__attribute__((used)) +int _write_r(struct _reent *r, int file, char * ptr, int len) { + uint32_t err; + + err = sbFileWrite((uint32_t)file, (const uint8_t *)ptr, (size_t)len); + if (SB_ERR_ISERROR(err)) { + __errno_r(r) = MAKERR(err); + return -1; + } + + return (int)err; +} + +__attribute__((used)) +int _read_r(struct _reent *r, int file, char * ptr, int len) { + uint32_t err; + + err = sbFileRead((uint32_t)file, (uint8_t *)ptr, (size_t)len); + if (SB_ERR_ISERROR(err)) { + __errno_r(r) = MAKERR(err); + return -1; + } + + return (int)err; +} + +__attribute__((used)) +int _lseek_r(struct _reent *r, int file, int ptr, int dir) { + uint32_t err; + + err = sbFileSeek((uint32_t)file, (uint32_t)ptr, (uint32_t)dir); + if (SB_ERR_ISERROR(err)) { + __errno_r(r) = MAKERR(err); + return -1; + } + + return (int)err; +} + +__attribute__((used)) +int _fstat_r(struct _reent *r, int file, struct stat * st) { + (void)r; + (void)file; + + memset(st, 0, sizeof(*st)); + st->st_mode = S_IFCHR; + return 0; +} + +__attribute__((used)) +int _isatty_r(struct _reent *r, int fd) { + (void)r; + (void)fd; + + return 1; +} + +__attribute__((used)) +caddr_t _sbrk_r(struct _reent *r, int incr) { + extern uint8_t __heap_end__, __heap_base__; + static uint8_t *p = &__heap_base__; + uint8_t *prevp; + + prevp = p; + if ((p + incr > &__heap_end__) || + (p + incr < &__heap_base__)) { + __errno_r(r) = ENOMEM; + return (caddr_t)-1; + } + + p += incr; + return (caddr_t)prevp; +} + +__attribute__((used)) +int _getpid_r(struct _reent *r) { + + (void)r; + + return 1; +} + +__attribute__((used)) +int _kill_r(struct _reent *r, int pid, int sig) { + + (void)pid; + (void)sig; + + __errno_r(r) = EINVAL; + return -1; +} + +__attribute__((used)) +void _exit(int code) { + + sbExit((msg_t)code); + while (true); +} + +/*** EOF ***/ -- cgit v1.2.3