|
3 | 3 | #include <string.h>
|
4 | 4 | #include <compartment.h>
|
5 | 5 |
|
6 |
| -#include "py/builtin.h" |
7 |
| -#include "py/compile.h" |
8 |
| -#include "py/runtime.h" |
9 |
| -#include "py/repl.h" |
10 |
| -#include "py/gc.h" |
11 |
| -#include "py/mperrno.h" |
12 |
| -#include "shared/runtime/pyexec.h" |
13 |
| - |
14 |
| -#if MICROPY_ENABLE_COMPILER |
15 |
| -void do_str(const char *src, mp_parse_input_kind_t input_kind) { |
16 |
| - nlr_buf_t nlr; |
17 |
| - if (nlr_push(&nlr) == 0) { |
18 |
| - mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); |
19 |
| - qstr source_name = lex->source_name; |
20 |
| - mp_parse_tree_t parse_tree = mp_parse(lex, input_kind); |
21 |
| - mp_obj_t module_fun = mp_compile(&parse_tree, source_name, true); |
22 |
| - mp_call_function_0(module_fun); |
23 |
| - nlr_pop(); |
24 |
| - } else { |
25 |
| - // uncaught exception |
26 |
| - mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val); |
27 |
| - } |
28 |
| -} |
29 |
| -#endif |
30 |
| - |
31 |
| -static char *stack_top; |
32 |
| -#if MICROPY_ENABLE_GC |
33 |
| -static char heap[16384]; //[MICROPY_HEAP_SIZE]; |
34 |
| -#endif |
| 6 | +#include "mp_entry.h" |
| 7 | +#include "mphalport.h" |
35 | 8 |
|
36 | 9 | #include <stdio.h>
|
37 | 10 |
|
38 |
| -void __cheri_compartment("mp_main") mp_main(void) { |
39 |
| - MP_STATE_THREAD_HACK_INIT |
| 11 | +void __cheri_compartment("main") entry(void) { |
40 | 12 | *MMIO_CAPABILITY(uint32_t, gpio) = 0xaa;
|
41 | 13 | printf("Test\n");
|
42 |
| - int stack_dummy; |
43 |
| - stack_top = (char *)&stack_dummy; |
44 |
| - #if MICROPY_ENABLE_GC |
45 |
| - gc_init(heap, heap + sizeof(heap)); |
46 |
| - printf("GC initialised\n"); |
47 |
| - #endif |
48 |
| - mp_init(); |
49 |
| - printf("Micropython initialised\n"); |
50 |
| - #if MICROPY_ENABLE_COMPILER |
51 |
| - #if MICROPY_REPL_EVENT_DRIVEN |
52 |
| - pyexec_event_repl_init(); |
53 |
| - for (;;) { |
54 |
| - int c = mp_hal_stdin_rx_chr(); |
55 |
| - if (pyexec_event_repl_process_char(c)) { |
56 |
| - break; |
57 |
| - } |
| 14 | + mp_vminit(); |
| 15 | + while(1) switch(mp_hal_stdin_rx_chr()) { |
| 16 | + #if MICROPY_ENABLE_COMPILER |
| 17 | + case 'r': |
| 18 | + if(!mp_friendly_repl()) continue; |
| 19 | + printf("REPL exited with a failure\n"); |
| 20 | + return; |
| 21 | + #endif |
| 22 | + case 's': |
| 23 | + if(!mp_exec_str_single("print('foo', 7*8*9, [ 'bar', 'baz' ])")) continue; |
| 24 | + printf("String execution exited with a failure\n"); |
| 25 | + case 'f': |
| 26 | + if(!mp_exec_frozen_module("frozentest.py")) continue; |
| 27 | + printf("Frozen module exited with a failure\n"); |
| 28 | + return; |
| 29 | + break; |
| 30 | + case 'q': |
| 31 | + mp_vmexit(); |
| 32 | + printf("VM Exited"); |
| 33 | + return; |
58 | 34 | }
|
59 |
| - #else |
60 |
| - pyexec_friendly_repl(); |
61 |
| - #endif |
62 |
| - // do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT); |
63 |
| - // do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT); |
64 |
| - #else |
65 |
| -#error "We don't want to be using frozen modules" |
66 |
| - pyexec_frozen_module("frozentest.py", false); |
67 |
| - #endif |
68 |
| - mp_deinit(); |
69 | 35 | }
|
70 | 36 |
|
71 | 37 | enum ErrorRecoveryBehaviour compartment_error_handler(struct ErrorState *frame, size_t mcause, size_t mtval) {
|
@@ -107,46 +73,7 @@ enum ErrorRecoveryBehaviour compartment_error_handler(struct ErrorState *frame,
|
107 | 73 | if(__builtin_cheri_tag_get(stack)) for(int i = 0; i < 32; i++) {
|
108 | 74 | printf("\t\t+%02x : %p [base %lx, len %lx, perms %lx, tag %d]\n", sizeof(void*)*i, stack[i], __builtin_cheri_base_get(stack[i]), __builtin_cheri_length_get(stack[i]), __builtin_cheri_perms_get(stack[i]), __builtin_cheri_tag_get(stack[i]));
|
109 | 75 | }
|
110 |
| - while(1);//mp_raise_OSError(mcause); |
111 |
| -} |
112 |
| - |
113 |
| - |
114 |
| -#if MICROPY_ENABLE_GC |
115 |
| -void gc_collect(void) { |
116 |
| - // WARNING: This gc_collect implementation doesn't try to get root |
117 |
| - // pointers from CPU registers, and thus may function incorrectly. |
118 |
| - void *dummy; |
119 |
| - gc_collect_start(); |
120 |
| - gc_collect_root(&dummy, ((mp_uint_t)stack_top - (mp_uint_t)&dummy) / sizeof(mp_uint_t)); |
121 |
| - gc_collect_end(); |
122 |
| - gc_dump_info(&mp_plat_print); |
123 |
| -} |
124 |
| -#endif |
125 |
| - |
126 |
| -mp_lexer_t *mp_lexer_new_from_file(qstr filename) { |
127 |
| - mp_raise_OSError(MP_ENOENT); |
| 76 | + while(1); |
128 | 77 | }
|
129 | 78 |
|
130 |
| -mp_import_stat_t mp_import_stat(const char *path) { |
131 |
| - return MP_IMPORT_STAT_NO_EXIST; |
132 |
| -} |
133 |
| - |
134 |
| -void nlr_jump_fail(void *val) { |
135 |
| - while (1) { |
136 |
| - ; |
137 |
| - } |
138 |
| -} |
139 |
| - |
140 |
| -void NORETURN __fatal_error(const char *msg) { |
141 |
| - while (1) { |
142 |
| - ; |
143 |
| - } |
144 |
| -} |
145 |
| - |
146 |
| -#ifndef NDEBUG |
147 |
| -void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) { |
148 |
| - printf("Assertion '%s' failed, at file %s:%d\n", expr, file, line); |
149 |
| - __fatal_error("Assertion failed"); |
150 |
| -} |
151 |
| -#endif |
152 | 79 |
|
0 commit comments