diff --git a/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/main.c b/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/main.c
index 88172d081..11f9c70b9 100644
--- a/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/main.c
+++ b/demos/STM32/RT-STM32G474RE-NUCLEO64-SB_HOST_STATIC/main.c
@@ -40,6 +40,19 @@ static const sb_config_t sb_config1 = {
.stderr_stream = (SandboxStream *)&LPSIOD1
};
+/* Sandbox 2 configuration.*/
+static const sb_config_t sb_config2 = {
+ .code_region = 0U,
+ .data_region = 1U,
+ .regions = {
+ {(uint32_t)&__flash2_base__, (uint32_t)&__flash2_end__, false},
+ {(uint32_t)&__ram2_base__, (uint32_t)&__ram2_end__, true}
+ },
+ .stdin_stream = (SandboxStream *)&LPSIOD1,
+ .stdout_stream = (SandboxStream *)&LPSIOD1,
+ .stderr_stream = (SandboxStream *)&LPSIOD1
+};
+
/* Sandbox objects.*/
sb_class_t sbx1, sbx2;
@@ -61,7 +74,7 @@ static THD_FUNCTION(Thread1, arg) {
(void) sbSendMessage(&sbx1, (msg_t)i);
palSetLine(LINE_LED_GREEN);
chThdSleepMilliseconds(500);
-// (void) sbSendMessage(&sbx1, (msg_t)i);
+ (void) sbSendMessage(&sbx2, (msg_t)i);
i++;
}
}
@@ -94,7 +107,9 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+10, Thread1, NULL);
/*
- * Creating a static box using MPU.
+ * Creating **static** boxes using MPU.
+ * Note: The two regions cover both sandbox 1 and 2, there is no
+ * isolation among them.
*/
mpuConfigureRegion(MPU_REGION_0,
0x08070000U,
@@ -106,22 +121,10 @@ int main(void) {
0x2001E000U,
MPU_RASR_ATTR_AP_RW_RW |
MPU_RASR_ATTR_CACHEABLE_WB_WA |
- MPU_RASR_SIZE_4K |
+ MPU_RASR_SIZE_8K |
MPU_RASR_ENABLE);
-#if 0
- unprivileged_thread_descriptor_t utd = {
- .name = "unprivileged",
- .wbase = waUnprivileged1,
- .wend = THD_WORKING_AREA_END(waUnprivileged1),
- .prio = NORMALPRIO + 1,
- .u_pc = 0x08070011U,
- .u_psp = 0x2001F000U,
- .arg = NULL
- };
- chThdCreateUnprivileged(&utd);
-#endif
- /* Starting sandboxed thread.*/
+ /* Starting sandboxed thread 1.*/
utp1 = sbStartThread(&sbx1, &sb_config1, "sbx1",
waUnprivileged1, sizeof (waUnprivileged1),
NORMALPRIO - 1);
@@ -129,6 +132,14 @@ int main(void) {
chSysHalt("sbx1 failed");
}
+ /* Starting sandboxed thread 2.*/
+ utp1 = sbStartThread(&sbx2, &sb_config2, "sbx2",
+ waUnprivileged1, sizeof (waUnprivileged1),
+ NORMALPRIO - 1);
+ if (utp1 == NULL) {
+ chSysHalt("sbx2 failed");
+ }
+
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state.
diff --git a/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/.cproject b/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/.cproject
new file mode 100644
index 000000000..f6982e145
--- /dev/null
+++ b/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/.cproject
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/.project b/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/.project
new file mode 100644
index 000000000..d0998a083
--- /dev/null
+++ b/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/.project
@@ -0,0 +1,33 @@
+
+
+ SB-CLIENT-32k-08078000-4k-2001F000
+
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
+
+ os
+ 2
+ CHIBIOS/os
+
+
+
diff --git a/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/Makefile b/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/Makefile
new file mode 100644
index 000000000..c986da7d8
--- /dev/null
+++ b/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/Makefile
@@ -0,0 +1,191 @@
+##############################################################################
+# Build global options
+# NOTE: Can be overridden externally.
+#
+
+# Compiler options here.
+ifeq ($(USE_OPT),)
+ USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16
+endif
+
+# C specific options here (added to USE_OPT).
+ifeq ($(USE_COPT),)
+ USE_COPT =
+endif
+
+# C++ specific options here (added to USE_OPT).
+ifeq ($(USE_CPPOPT),)
+ USE_CPPOPT = -fno-rtti
+endif
+
+# Enable this if you want the linker to remove unused code and data.
+ifeq ($(USE_LINK_GC),)
+ USE_LINK_GC = yes
+endif
+
+# Linker extra options here.
+ifeq ($(USE_LDOPT),)
+ USE_LDOPT =
+endif
+
+# Enable this if you want link time optimizations (LTO).
+ifeq ($(USE_LTO),)
+ USE_LTO = yes
+endif
+
+# Enable this if you want to see the full log while compiling.
+ifeq ($(USE_VERBOSE_COMPILE),)
+ USE_VERBOSE_COMPILE = no
+endif
+
+# If enabled, this option makes the build process faster by not compiling
+# modules not used in the current configuration.
+ifeq ($(USE_SMART_BUILD),)
+ USE_SMART_BUILD = yes
+endif
+
+#
+# Build global options
+##############################################################################
+
+##############################################################################
+# Architecture or project specific options
+#
+
+# Stack size to be allocated to the Cortex-M process stack. This stack is
+# the stack used by the main() thread.
+ifeq ($(USE_PROCESS_STACKSIZE),)
+ USE_PROCESS_STACKSIZE = 0x400
+endif
+
+# Stack size to the allocated to the Cortex-M main/exceptions stack. This
+# stack is used for processing interrupts and exceptions.
+ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
+ USE_EXCEPTIONS_STACKSIZE = 0x400
+endif
+
+# Enables the use of FPU (no, softfp, hard).
+ifeq ($(USE_FPU),)
+ USE_FPU = no
+endif
+
+# FPU-related options.
+ifeq ($(USE_FPU_OPT),)
+ USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16
+endif
+
+#
+# Architecture or project specific options
+##############################################################################
+
+##############################################################################
+# Project, target, sources and paths
+#
+
+# Define project name here
+PROJECT = sb
+
+# Target settings.
+MCU = cortex-m4
+
+# Imported source files and paths.
+CHIBIOS := ../../..
+CONFDIR := ./cfg
+BUILDDIR := ./build
+DEPDIR := ./.dep
+
+# Licensing files.
+include $(CHIBIOS)/os/license/license.mk
+# Startup files.
+include $(CHIBIOS)/os/common/startup/ARMCMx-SB/compilers/GCC/mk/startup.mk
+# HAL-OSAL files (optional).
+#include $(CHIBIOS)/os/hal/hal.mk
+#include $(CHIBIOS)/os/hal/ports/STM32/STM32L4xx/platform.mk
+#include $(CHIBIOS)/os/hal/boards/ST_STM32L476_DISCOVERY/board.mk
+#include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk
+# RTOS files (optional).
+#include $(CHIBIOS)/os/rt/rt.mk
+#include $(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC/mk/port.mk
+include $(CHIBIOS)/os/sb/user/sbuser.mk
+# Auto-build files in ./source recursively.
+include $(CHIBIOS)/tools/mk/autobuild.mk
+# Other files (optional).
+#include $(CHIBIOS)/os/test/test.mk
+#include $(CHIBIOS)/test/rt/rt_test.mk
+#include $(CHIBIOS)/test/oslib/oslib_test.mk
+
+# Define linker script file here.
+LDSCRIPT= ./sandbox.ld
+
+# C sources that can be compiled in ARM or THUMB mode depending on the global
+# setting.
+CSRC = $(ALLCSRC) \
+ $(TESTSRC) \
+ $(CHIBIOS)/os/sb/various/syscalls.c \
+ main.c
+
+# C++ sources that can be compiled in ARM or THUMB mode depending on the global
+# setting.
+CPPSRC = $(ALLCPPSRC)
+
+# List ASM source files here.
+ASMSRC = $(ALLASMSRC)
+
+# List ASM with preprocessor source files here.
+ASMXSRC = $(ALLXASMSRC)
+
+# Inclusion directories.
+INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC)
+
+# Define C warning options here.
+CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
+
+# Define C++ warning options here.
+CPPWARN = -Wall -Wextra -Wundef
+
+#
+# Project, target, sources and paths
+##############################################################################
+
+##############################################################################
+# Start of user section
+#
+
+# List all user C define here, like -D_DEBUG=1
+UDEFS =
+
+# Define ASM defines here
+UADEFS =
+
+# List all user directories here
+UINCDIR =
+
+# List the user directory to look for the libraries here
+ULIBDIR =
+
+# List all user libraries here
+ULIBS =
+
+#
+# End of user section
+##############################################################################
+
+##############################################################################
+# Common rules
+#
+
+RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk
+include $(RULESPATH)/arm-none-eabi.mk
+include $(RULESPATH)/rules.mk
+
+#
+# Common rules
+##############################################################################
+
+##############################################################################
+# Custom rules
+#
+
+#
+# Custom rules
+##############################################################################
diff --git a/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/main.c b/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/main.c
new file mode 100644
index 000000000..97de8c18d
--- /dev/null
+++ b/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/main.c
@@ -0,0 +1,46 @@
+/*
+ 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 "sbuser.h"
+
+/*
+ * Application entry point.
+ */
+int main(void) {
+
+ /* API layer initialization.*/
+ sbApiInit();
+
+#if 0
+ /* Test for exception on interrupt.*/
+ asm volatile ("mov r0, #64");
+ asm volatile ("mov sp, r0");
+ while (true) {
+ }
+#endif
+ while (true) {
+ msg_t msg = sbMsgWait();
+ printf("#2 Hello World (%u)!!\r\n", (unsigned)msg);
+// sbFileWrite(1U, (const uint8_t *)"#2 Hello World!!\r\n", 15U);
+ sbMsgReply(msg);
+// sbSleepMilliseconds(500);
+ }
+}
diff --git a/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/sandbox.ld b/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/sandbox.ld
new file mode 100644
index 000000000..2a7a022b0
--- /dev/null
+++ b/demos/various/SB-CLIENT-32k-08078000-4k-2001F000/sandbox.ld
@@ -0,0 +1,33 @@
+/*
+ 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.
+*/
+
+/*
+ * Sandbox memory setup.
+ */
+MEMORY
+{
+ flash0 (rx) : org = 0x08078000, len = 32k
+ ram0 (wx) : org = 0x2001F000, len = 4k
+}
+
+/* Flash region to be used for exception vectors.*/
+REGION_ALIAS("CODE_SPACE", flash0);
+
+/* RAM region to be used for data.*/
+REGION_ALIAS("DATA_SPACE", ram0);
+
+/* Generic rules inclusion.*/
+INCLUDE rules.ld