Skip to content

Commit 127e480

Browse files
committed
ports/cheriot-rtos: Most tests now pass (but not in paste mode).
Signed-off-by: Duncan Lowther <[email protected]>
1 parent 006f492 commit 127e480

File tree

12 files changed

+477
-162
lines changed

12 files changed

+477
-162
lines changed

ports/cheriot-rtos/Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ INC += -I$(BUILD)
2727

2828
INC += $(SYS_INC)
2929
CFLAGS_CHERIOT_A7 = -target riscv32-unknown-unknown -mcpu=cheriot -mabi=cheriot -mxcheri-rvc -mrelax -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-builtin -fno-exceptions -fno-asynchronous-unwind-tables -fno-c++-static-destructors -fno-rtti
30-
CFLAGS += $(INC) -Wall -Werror -std=c99 -nostdlib $(CFLAGS_CHERIOT_A7) $(COPT) -DNO_ALLOCA_H -DCHERIOT_IBEX -DIBEX -DSUNBURST -DSUNBURST_SHADOW_BASE=0x30000000 -DSUNBURST_SHADOW_SIZE=0x4000 -DCPU_TIMER_HZ=33000000 -DTICK_RATE_HZ=100 -DCHERIOT_NO_AMBIENT_MALLOC -DDEVICE_EXISTS_shadow -DDEVICE_EXISTS_clint -DDEVICE_EXISTS_uart -DDEVICE_EXISTS_gpio -DDEVICE_EXISTS_gpio -DDEVICE_EXISTS_plic -DREVOKABLE_MEMORY_START=0x00100080
30+
CFLAGS += $(INC) -Wall -Werror -std=c2x -nostdlib $(CFLAGS_CHERIOT_A7) $(COPT) -DNO_ALLOCA_H -DCHERIOT_IBEX -DIBEX -DSUNBURST -DSUNBURST_SHADOW_BASE=0x30000000 -DSUNBURST_SHADOW_SIZE=0x4000 -DCPU_TIMER_HZ=33000000 -DTICK_RATE_HZ=100 -DCHERIOT_NO_AMBIENT_MALLOC -DDEVICE_EXISTS_shadow -DDEVICE_EXISTS_clint -DDEVICE_EXISTS_uart -DDEVICE_EXISTS_gpio -DDEVICE_EXISTS_gpio -DDEVICE_EXISTS_plic -DREVOKABLE_MEMORY_START=0x00100080
3131
LDFLAGS += --script=cheriot-a7-100t.ld --relax
3232

3333
CSUPEROPT = -Os # save some code space
@@ -52,13 +52,13 @@ SRC_C = mp_entry.c \
5252

5353
SRC_CXX =
5454

55-
SRC_QSTR += shared/readline/readline.c shared/runtime/pyexec.c
55+
SRC_QSTR += shared/readline/readline.c shared/runtime/pyexec.c mp_entry.c
5656

5757
SRC_HAL_C = shared/runtime/stdout_helpers.c
5858
SRC_HAL_CXX = uart_core.cpp
5959

60-
SRC_MAIN_C = main.c
61-
SRC_MAIN_CXX =
60+
SRC_MAIN_C =
61+
SRC_MAIN_CXX = main.cpp
6262

6363
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
6464
OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o))
@@ -68,11 +68,12 @@ OBJ_HAL += $(addprefix $(BUILD)/, $(SRC_HAL_C:.c=.o))
6868
OBJ_HAL += $(addprefix $(BUILD)/, $(SRC_HAL_CXX:.cpp=.o))
6969

7070
OBJ_MAIN += $(addprefix $(BUILD)/, $(SRC_MAIN_C:.c=.o))
71-
OBJ_MAIN += $(addprefix $(BUILD)/, $(SRC_MAINL_CXX:.cpp=.o))
71+
OBJ_MAIN += $(addprefix $(BUILD)/, $(SRC_MAIN_CXX:.cpp=.o))
7272

7373
$(OBJ): CFLAGS += -DMP_VM_COMP -cheri-compartment=mp_vm
7474
$(OBJ_HAL): CFLAGS += -cheri-compartment=mp_hal
7575
$(OBJ_MAIN): CFLAGS += -cheri-compartment=main
76+
$(BUILD)/mp_entry.o: CFLAGS += -UCHERIOT_NO_AMBIENT_MALLOC
7677

7778
all: $(BUILD)/micropython.uf2
7879

@@ -81,7 +82,7 @@ all_objects : $(OBJ) $(OBJ_HAL) $(OBJ_MAIN)
8182

8283
$(BUILD)/_frozen_mpy.c: $(TOP)/tests/frozen/frozentest.mpy $(BUILD)/genhdr/qstrdefs.generated.h
8384
$(ECHO) "MISC freezing bytecode"
84-
$(Q)$(TOP)/tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@
85+
$(Q)$(TOP)/tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=mpz $< > $@
8586

8687
$(BUILD)/xmake.lua: xmake.lua.top xmake.lua.bottom
8788
cat xmake.lua.top > $@

ports/cheriot-rtos/main.c renamed to ports/cheriot-rtos/main.cpp

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,54 @@
1111
void __cheri_compartment("main") entry(void) {
1212
*MMIO_CAPABILITY(uint32_t, gpio) = 0xaa;
1313
printf("Test\n");
14-
mp_vminit();
14+
MicropythonContext ctx = MicropythonContext::create(0xc000).value();
15+
#ifdef TEST_COMPARMENT_ENTRIES
1516
while(1) switch(mp_hal_stdin_rx_chr()) {
1617
#if MICROPY_ENABLE_COMPILER
1718
case 'r':
18-
if(!mp_friendly_repl()) continue;
19+
if(!ctx.friendly_repl()) continue;
1920
printf("REPL exited with a failure\n");
2021
return;
2122
#endif
2223
case 's':
23-
if(!mp_exec_str_single("print('foo', 7*8*9, [ 'bar', 'baz' ])")) continue;
24+
if(!ctx.exec_str_single("print('foo', 7*8*9, [ 'bar', 'baz' ])")) continue;
2425
printf("String execution exited with a failure\n");
2526
case 'f':
26-
if(!mp_exec_frozen_module("frozentest.py")) continue;
27+
if(!ctx.exec_frozen_module("frozentest.py")) continue;
2728
printf("Frozen module exited with a failure\n");
2829
return;
29-
break;
30-
case 'q':
31-
mp_vmexit();
32-
printf("VM Exited");
30+
case 'e':
31+
if(!ctx.exec_str_file("def foo(a,b):\n print(a)\n return b*b\nprint('created function `foo`')")) {
32+
std::optional<int> ret = ctx.exec_func<int>("foo", "bar", 7);
33+
if(ret) {
34+
printf("Call to python `foo('bar', 7)` returned %d\n", *ret);
35+
continue;
36+
} else {
37+
printf("Call to python `foo('bar', 7)` failed.\n");
38+
return;
39+
}
40+
} else {
41+
printf("File-mode string execution exited with a failure\n");
42+
return;
43+
}
44+
case 'q':
45+
printf("Exiting\n");
3346
return;
3447
}
48+
#else
49+
int ret = 0;
50+
do {
51+
while(!ret) ret = ctx.var_repl();
52+
printf("soft reboot\r\n");
53+
ret = ctx.restart();
54+
} while(!ret);
55+
printf("Restart failed with code %d\n", ret);
56+
return;
57+
#endif
3558
}
3659

3760
enum ErrorRecoveryBehaviour compartment_error_handler(struct ErrorState *frame, size_t mcause, size_t mtval) {
38-
static const char * const cheri_exc_code[32] = { "NONE", "BOUNDS", "TAG", "SEAL" , "04" , "05" , "06", "07",
61+
static const char * const cheri_exc_code[32] = { "UNWIND", "BOUNDS", "TAG", "SEAL" , "04" , "05" , "06", "07",
3962
"08", "09", "0a", "0b", "0c", "0d", "0e", "0f",
4063
"10", "EXEC", "LOAD", "STORE", "14", "STCAP", "STLOC", "17",
4164
"SYSREG", "19", "1a", "1b", "1c", "1d", "1e", "1f" };
@@ -44,7 +67,7 @@ enum ErrorRecoveryBehaviour compartment_error_handler(struct ErrorState *frame,
4467

4568
if(mcause == 0x1c) {
4669
printf("CHERI fault (type %s):\n", cheri_exc_code[mtval & 0x1f]);
47-
printf("\tat %p\n", frame->pcc);
70+
printf("\tat %p in compartment 'main'\n", frame->pcc);
4871
if(mtval & 0x400) { // S=1, special register
4972
switch(mtval >> 5) {
5073
case 0x20: printf("\ton PCC\n"); break;
@@ -54,10 +77,13 @@ enum ErrorRecoveryBehaviour compartment_error_handler(struct ErrorState *frame,
5477
case 0x3f: printf("\ton MEPCC\n"); break;
5578
default: printf("on unknown special register %ld\n", (mtval >> 5) & 0x1f);
5679
}
57-
} else {
80+
} else if(mtval) {
5881
int errreg = mtval >> 5;
59-
void * errcap = frame->registers[errreg - 1];
82+
void * errcap = errreg ? frame->registers[errreg - 1] : NULL;
6083
printf("\ton capability %p [base %lx, len %lx, perms %lx] in register c%s\n", errcap, __builtin_cheri_base_get(errcap), __builtin_cheri_length_get(errcap), __builtin_cheri_perms_get(errcap), reg_names[errreg]);
84+
} else {
85+
printf("\r\n\x04\x04\r\n");
86+
return InstallContext;
6187
}
6288
}
6389
else {

0 commit comments

Comments
 (0)