diff options
Diffstat (limited to 'qemu-arm')
| -rw-r--r-- | qemu-arm/Makefile | 37 | ||||
| -rw-r--r-- | qemu-arm/README.md | 2 | ||||
| -rw-r--r-- | qemu-arm/main.c | 12 | ||||
| -rw-r--r-- | qemu-arm/memory.h | 2 | ||||
| -rw-r--r-- | qemu-arm/modmachine.c | 47 | ||||
| -rw-r--r-- | qemu-arm/moduos.c | 53 | ||||
| -rw-r--r-- | qemu-arm/mpconfigport.h | 16 | ||||
| -rw-r--r-- | qemu-arm/test_main.c | 15 |
8 files changed, 147 insertions, 37 deletions
diff --git a/qemu-arm/Makefile b/qemu-arm/Makefile index 0af2fc901..07aa68572 100644 --- a/qemu-arm/Makefile +++ b/qemu-arm/Makefile @@ -15,7 +15,7 @@ INC += -I$(BUILD) INC += -I../tools/tinytest/ CFLAGS_CORTEX_M3 = -mthumb -mcpu=cortex-m3 -mfloat-abi=soft -CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M3) $(COPT) \ +CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -std=gnu99 $(CFLAGS_CORTEX_M3) $(COPT) \ -ffunction-sections -fdata-sections #Debugging/Optimization @@ -34,7 +34,11 @@ endif ## - gcc-arm-none-eabi-4_8-2014q1/share/gcc-arm-none-eabi/samples/src/qemu/Makefile LDFLAGS= --specs=nano.specs --specs=rdimon.specs -Wl,--gc-sections -Wl,-Map=$(@:.elf=.map) -SRC_C = \ +SRC_COMMON_C = \ + moduos.c \ + modmachine.c \ + +SRC_RUN_C = \ main.c \ SRC_TEST_C = \ @@ -43,7 +47,7 @@ SRC_TEST_C = \ LIB_SRC_C = $(addprefix lib/,\ libm/math.c \ libm/fmodf.c \ - libm/roundf.c \ + libm/nearbyintf.c \ libm/ef_sqrt.c \ libm/kf_rem_pio2.c \ libm/kf_sin.c \ @@ -65,25 +69,24 @@ STM_SRC_C = $(addprefix stmhal/,\ pybstdio.c \ ) -SRC_S = \ +OBJ_COMMON = +OBJ_COMMON += $(PY_O) +OBJ_COMMON += $(addprefix $(BUILD)/, $(SRC_COMMON_C:.c=.o)) +OBJ_COMMON += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o)) +OBJ_COMMON += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o)) -OBJ = -OBJ += $(PY_O) -OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) -OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) -OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o)) -OBJ += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o)) +OBJ_RUN = +OBJ_RUN += $(addprefix $(BUILD)/, $(SRC_RUN_C:.c=.o)) OBJ_TEST = -OBJ_TEST += $(PY_O) OBJ_TEST += $(addprefix $(BUILD)/, $(SRC_TEST_C:.c=.o)) -OBJ_TEST += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) -OBJ_TEST += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o)) -OBJ_TEST += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o)) OBJ_TEST += $(BUILD)/tinytest.o +# All object files, needed to get dependencies correct +OBJ = $(OBJ_COMMON) $(OBJ_RUN) $(OBJ_TEST) + # List of sources for qstr extraction -SRC_QSTR += $(SRC_C) $(STM_SRC_C) +SRC_QSTR += $(SRC_COMMON_C) $(SRC_RUN_C) $(STM_SRC_C) all: run @@ -105,11 +108,11 @@ $(BUILD)/tinytest.o: $(Q)$(CC) $(CFLAGS) -DNO_FORKING -o $@ -c ../tools/tinytest/tinytest.c ## `$(LD)` doesn't seem to like `--specs` for some reason, but we can just use `$(CC)` here. -$(BUILD)/firmware.elf: $(OBJ) +$(BUILD)/firmware.elf: $(OBJ_COMMON) $(OBJ_RUN) $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) $(Q)$(SIZE) $@ -$(BUILD)/firmware-test.elf: $(OBJ_TEST) +$(BUILD)/firmware-test.elf: $(OBJ_COMMON) $(OBJ_TEST) $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) $(Q)$(SIZE) $@ diff --git a/qemu-arm/README.md b/qemu-arm/README.md index 329ae4d92..0cf93c7d5 100644 --- a/qemu-arm/README.md +++ b/qemu-arm/README.md @@ -4,7 +4,7 @@ provided by QEMU (http://qemu.org). The purposes of this port are to enable: 1. Continuous integration - - run tests agains architecture-specific parts of code base + - run tests against architecture-specific parts of code base 2. Experimentation - simulation & prototyping of anything that has architecture-specific code diff --git a/qemu-arm/main.c b/qemu-arm/main.c index b6ff73980..d5fbcd84b 100644 --- a/qemu-arm/main.c +++ b/qemu-arm/main.c @@ -1,4 +1,5 @@ #include <stdint.h> +#include <stdlib.h> #include <stdio.h> #include <string.h> #include <malloc.h> @@ -11,15 +12,12 @@ #include "py/stackctrl.h" #include "py/gc.h" #include "py/repl.h" +#include "py/mperrno.h" void do_str(const char *src, mp_parse_input_kind_t input_kind) { - mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); - if (lex == NULL) { - return; - } - nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { + mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); qstr source_name = lex->source_name; mp_parse_tree_t parse_tree = mp_parse(lex, input_kind); mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true); @@ -46,7 +44,7 @@ void gc_collect(void) { } mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - return NULL; + mp_raise_OSError(MP_ENOENT); } mp_import_stat_t mp_import_stat(const char *path) { @@ -59,4 +57,6 @@ mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); void nlr_jump_fail(void *val) { + printf("uncaught NLR\n"); + exit(1); } diff --git a/qemu-arm/memory.h b/qemu-arm/memory.h deleted file mode 100644 index f3777b0e3..000000000 --- a/qemu-arm/memory.h +++ /dev/null @@ -1,2 +0,0 @@ -// this is needed for extmod/crypto-algorithms/sha256.c -#include <string.h> diff --git a/qemu-arm/modmachine.c b/qemu-arm/modmachine.c new file mode 100644 index 000000000..0f66349a8 --- /dev/null +++ b/qemu-arm/modmachine.c @@ -0,0 +1,47 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "extmod/machine_mem.h" +#include "extmod/machine_pinbase.h" +#include "extmod/machine_signal.h" + +STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) }, + + { MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) }, + { MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) }, + { MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) }, + + { MP_ROM_QSTR(MP_QSTR_PinBase), MP_ROM_PTR(&machine_pinbase_type) }, + { MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table); + +const mp_obj_module_t mp_module_machine = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&machine_module_globals, +}; diff --git a/qemu-arm/moduos.c b/qemu-arm/moduos.c new file mode 100644 index 000000000..a48b51db0 --- /dev/null +++ b/qemu-arm/moduos.c @@ -0,0 +1,53 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "extmod/vfs.h" + +STATIC const mp_rom_map_elem_t os_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) }, + + { MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&mp_vfs_chdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&mp_vfs_getcwd_obj) }, + { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mp_vfs_ilistdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&mp_vfs_listdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mp_vfs_mkdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&mp_vfs_remove_obj) }, + { MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&mp_vfs_rename_obj) }, + { MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&mp_vfs_rmdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&mp_vfs_stat_obj) }, + { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&mp_vfs_statvfs_obj) }, + + // MicroPython extensions + { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) }, + { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); + +const mp_obj_module_t mp_module_uos = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&os_module_globals, +}; diff --git a/qemu-arm/mpconfigport.h b/qemu-arm/mpconfigport.h index 5665dc392..876751f38 100644 --- a/qemu-arm/mpconfigport.h +++ b/qemu-arm/mpconfigport.h @@ -6,7 +6,8 @@ #define MICROPY_EMIT_X64 (0) #define MICROPY_EMIT_THUMB (1) #define MICROPY_EMIT_INLINE_THUMB (1) -#define MICROPY_MEM_STATS (0) +#define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1) +#define MICROPY_MEM_STATS (1) #define MICROPY_DEBUG_PRINTERS (0) #define MICROPY_ENABLE_GC (1) #define MICROPY_STACK_CHECK (1) @@ -21,6 +22,7 @@ #define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_BUILTINS_MEMORYVIEW (1) #define MICROPY_PY_BUILTINS_SLICE_ATTRS (1) +#define MICROPY_PY_BUILTINS_POW3 (1) #define MICROPY_PY_IO (1) #define MICROPY_PY_SYS_EXIT (1) #define MICROPY_PY_SYS_MAXSIZE (1) @@ -33,12 +35,13 @@ #define MICROPY_PY_URE (1) #define MICROPY_PY_UHEAPQ (1) #define MICROPY_PY_UHASHLIB (1) +#define MICROPY_PY_MACHINE (1) +#define MICROPY_PY_MICROPYTHON_MEM_INFO (1) #define MICROPY_USE_INTERNAL_PRINTF (0) +#define MICROPY_VFS (1) // type definitions for the specific machine -#define BYTES_PER_WORD (4) - #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1)) #define MP_SSIZE_MAX (0x7fffffff) @@ -57,5 +60,12 @@ typedef long mp_off_t; #define MICROPY_PORT_BUILTINS \ { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, +// extra built-in modules to add to the list of known ones +extern const struct _mp_obj_module_t mp_module_uos; + +#define MICROPY_PORT_BUILTIN_MODULES \ + { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) }, \ + { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \ + // We need to provide a declaration/definition of alloca() #include <alloca.h> diff --git a/qemu-arm/test_main.c b/qemu-arm/test_main.c index ae2beabcd..5c07d1607 100644 --- a/qemu-arm/test_main.c +++ b/qemu-arm/test_main.c @@ -1,4 +1,5 @@ #include <stdint.h> +#include <stdlib.h> #include <stdio.h> #include <string.h> #include <malloc.h> @@ -10,7 +11,7 @@ #include "py/runtime.h" #include "py/stackctrl.h" #include "py/gc.h" -#include "py/repl.h" +#include "py/mperrno.h" #include "tinytest.h" #include "tinytest_macros.h" @@ -23,16 +24,12 @@ inline void do_str(const char *src) { gc_init(heap, (char*)heap + HEAP_SIZE); mp_init(); - mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); - if (lex == NULL) { - tt_abort_msg("Lexer initialization error"); - } - nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { + mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); qstr source_name = lex->source_name; mp_parse_tree_t parse_tree = mp_parse(lex, MP_PARSE_FILE_INPUT); - mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true); + mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, false); mp_call_function_0(module_fun); nlr_pop(); } else { @@ -79,7 +76,7 @@ void gc_collect(void) { } mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - return NULL; + mp_raise_OSError(MP_ENOENT); } mp_import_stat_t mp_import_stat(const char *path) { @@ -92,4 +89,6 @@ mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); void nlr_jump_fail(void *val) { + printf("uncaught NLR\n"); + exit(1); } |
