From 2face99cfe9ab9c050e6d8299130bec00bf9653e Mon Sep 17 00:00:00 2001 From: Ilya Dmitrichenko Date: Mon, 21 Apr 2014 21:02:31 +0100 Subject: qemu-arm: more generic port name. --- cortex-m3-qemu/Makefile | 53 ---------------------------- cortex-m3-qemu/main.c | 80 ------------------------------------------- cortex-m3-qemu/mpconfigport.h | 34 ------------------ cortex-m3-qemu/qstrdefsport.h | 1 - qemu-arm/Makefile | 53 ++++++++++++++++++++++++++++ qemu-arm/main.c | 80 +++++++++++++++++++++++++++++++++++++++++++ qemu-arm/mpconfigport.h | 34 ++++++++++++++++++ qemu-arm/qstrdefsport.h | 1 + 8 files changed, 168 insertions(+), 168 deletions(-) delete mode 100644 cortex-m3-qemu/Makefile delete mode 100644 cortex-m3-qemu/main.c delete mode 100644 cortex-m3-qemu/mpconfigport.h delete mode 100644 cortex-m3-qemu/qstrdefsport.h create mode 100644 qemu-arm/Makefile create mode 100644 qemu-arm/main.c create mode 100644 qemu-arm/mpconfigport.h create mode 100644 qemu-arm/qstrdefsport.h diff --git a/cortex-m3-qemu/Makefile b/cortex-m3-qemu/Makefile deleted file mode 100644 index c40507286..000000000 --- a/cortex-m3-qemu/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -include ../py/mkenv.mk --include mpconfigport.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include ../py/py.mk - -CROSS_COMPILE = arm-none-eabi- - -CFLAGS_CORTEX_M3 = -mthumb -mcpu=cortex-m3 -CFLAGS = -I. -I$(PY_SRC) -Wall -ansi -std=gnu99 $(CFLAGS_CORTEX_M3) $(COPT) \ - -flto -ffunction-sections -fdata-sections - -#Debugging/Optimization -ifeq ($(DEBUG), 1) -CFLAGS += -g -DPENDSV_DEBUG -COPT = -O0 -else -COPT += -Os -DNDEBUG -endif - -## With CoudeSourcery it's actually a little different, you just need `-T generic-m-hosted.ld`. -## Although for some reason `$(LD)` will not find that linker script, it works with `$(CC)`. -## It turns out that this is specific to CoudeSourcery, and ARM version of GCC ships something -## else instead and according to the following files, this is what we need to pass to `$(CC). -## - gcc-arm-none-eabi-4_8-2014q1/share/gcc-arm-none-eabi/samples/src/makefile.conf -## - 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 = \ - main.c \ - -SRC_S = \ - -OBJ = -OBJ += $(PY_O) -OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) -OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) - -all: run - -run: $(BUILD)/flash.elf - - qemu-system-arm -cpu cortex-m3 -nographic -monitor null -serial null -semihosting -kernel $(BUILD)/flash.elf - -## `$(LD)` doesn't seem to like `--specs` for some reason, but we can just use `$(CC)` here. -$(BUILD)/flash.elf: $(OBJ) - $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) - $(Q)$(SIZE) $@ - -include ../py/mkrules.mk diff --git a/cortex-m3-qemu/main.c b/cortex-m3-qemu/main.c deleted file mode 100644 index 6ecc9a4b2..000000000 --- a/cortex-m3-qemu/main.c +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include - -#include "nlr.h" -#include "misc.h" -#include "mpconfig.h" -#include "qstr.h" -#include "lexer.h" -#include "parse.h" -#include "obj.h" -#include "parsehelper.h" -#include "compile.h" -#include "runtime0.h" -#include "runtime.h" -#include "repl.h" - -void do_str(const char *src) { - mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); - if (lex == NULL) { - return; - } - - mp_parse_error_kind_t parse_error_kind; - mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT, &parse_error_kind); - - if (pn == MP_PARSE_NODE_NULL) { - // parse error - mp_parse_show_exception(lex, parse_error_kind); - mp_lexer_free(lex); - return; - } - - // parse okay - qstr source_name = mp_lexer_source_name(lex); - mp_lexer_free(lex); - mp_obj_t module_fun = mp_compile(pn, source_name, MP_EMIT_OPT_NONE, true); - mp_parse_node_free(pn); - - if (module_fun == mp_const_none) { - // compile error - return; - } - - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - mp_call_function_0(module_fun); - nlr_pop(); - } else { - // uncaught exception - mp_obj_print_exception((mp_obj_t)nlr.ret_val); - } -} - -int main(int argc, char **argv) { - qstr_init(); - mp_init(); - do_str("print('hello world!')"); - mp_deinit(); - return 0; -} - -void gc_collect(void) { -} - -mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - return NULL; -} - -mp_import_stat_t mp_import_stat(const char *path) { - return MP_IMPORT_STAT_NO_EXIST; -} - -mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args) { - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_open_obj, 1, 2, mp_builtin_open); - -void nlr_jump_fail(void *val) { -} diff --git a/cortex-m3-qemu/mpconfigport.h b/cortex-m3-qemu/mpconfigport.h deleted file mode 100644 index 7f4c37890..000000000 --- a/cortex-m3-qemu/mpconfigport.h +++ /dev/null @@ -1,34 +0,0 @@ -#include - -// options to control how Micro Python is built - -#define MICROPY_EMIT_X64 (0) -#define MICROPY_EMIT_THUMB (0) -#define MICROPY_EMIT_INLINE_THUMB (0) -#define MICROPY_MEM_STATS (0) -#define MICROPY_DEBUG_PRINTERS (0) -#define MICROPY_ENABLE_GC (0) -#define MICROPY_ENABLE_REPL_HELPERS (0) -#define MICROPY_ENABLE_LEXER_UNIX (0) -#define MICROPY_ENABLE_SOURCE_LINE (0) -#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE) -#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE) -#define MICROPY_PATH_MAX (512) - -// type definitions for the specific machine - -#define BYTES_PER_WORD (4) - -#define UINT_FMT "%lu" -#define INT_FMT "%ld" - -typedef int32_t machine_int_t; // must be pointer size -typedef uint32_t machine_uint_t; // must be pointer size -typedef void *machine_ptr_t; // must be of pointer size -typedef const void *machine_const_ptr_t; // must be of pointer size - -// extra built in names to add to the global namespace -extern const struct _mp_obj_fun_native_t mp_builtin_open_obj; -#define MICROPY_EXTRA_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, - diff --git a/cortex-m3-qemu/qstrdefsport.h b/cortex-m3-qemu/qstrdefsport.h deleted file mode 100644 index 3ba897069..000000000 --- a/cortex-m3-qemu/qstrdefsport.h +++ /dev/null @@ -1 +0,0 @@ -// qstrs specific to this port diff --git a/qemu-arm/Makefile b/qemu-arm/Makefile new file mode 100644 index 000000000..c40507286 --- /dev/null +++ b/qemu-arm/Makefile @@ -0,0 +1,53 @@ +include ../py/mkenv.mk +-include mpconfigport.mk + +# qstr definitions (must come before including py.mk) +QSTR_DEFS = qstrdefsport.h + +# include py core make definitions +include ../py/py.mk + +CROSS_COMPILE = arm-none-eabi- + +CFLAGS_CORTEX_M3 = -mthumb -mcpu=cortex-m3 +CFLAGS = -I. -I$(PY_SRC) -Wall -ansi -std=gnu99 $(CFLAGS_CORTEX_M3) $(COPT) \ + -flto -ffunction-sections -fdata-sections + +#Debugging/Optimization +ifeq ($(DEBUG), 1) +CFLAGS += -g -DPENDSV_DEBUG +COPT = -O0 +else +COPT += -Os -DNDEBUG +endif + +## With CoudeSourcery it's actually a little different, you just need `-T generic-m-hosted.ld`. +## Although for some reason `$(LD)` will not find that linker script, it works with `$(CC)`. +## It turns out that this is specific to CoudeSourcery, and ARM version of GCC ships something +## else instead and according to the following files, this is what we need to pass to `$(CC). +## - gcc-arm-none-eabi-4_8-2014q1/share/gcc-arm-none-eabi/samples/src/makefile.conf +## - 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 = \ + main.c \ + +SRC_S = \ + +OBJ = +OBJ += $(PY_O) +OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) + +all: run + +run: $(BUILD)/flash.elf + + qemu-system-arm -cpu cortex-m3 -nographic -monitor null -serial null -semihosting -kernel $(BUILD)/flash.elf + +## `$(LD)` doesn't seem to like `--specs` for some reason, but we can just use `$(CC)` here. +$(BUILD)/flash.elf: $(OBJ) + $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) + $(Q)$(SIZE) $@ + +include ../py/mkrules.mk diff --git a/qemu-arm/main.c b/qemu-arm/main.c new file mode 100644 index 000000000..6ecc9a4b2 --- /dev/null +++ b/qemu-arm/main.c @@ -0,0 +1,80 @@ +#include +#include +#include + +#include "nlr.h" +#include "misc.h" +#include "mpconfig.h" +#include "qstr.h" +#include "lexer.h" +#include "parse.h" +#include "obj.h" +#include "parsehelper.h" +#include "compile.h" +#include "runtime0.h" +#include "runtime.h" +#include "repl.h" + +void do_str(const char *src) { + mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); + if (lex == NULL) { + return; + } + + mp_parse_error_kind_t parse_error_kind; + mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT, &parse_error_kind); + + if (pn == MP_PARSE_NODE_NULL) { + // parse error + mp_parse_show_exception(lex, parse_error_kind); + mp_lexer_free(lex); + return; + } + + // parse okay + qstr source_name = mp_lexer_source_name(lex); + mp_lexer_free(lex); + mp_obj_t module_fun = mp_compile(pn, source_name, MP_EMIT_OPT_NONE, true); + mp_parse_node_free(pn); + + if (module_fun == mp_const_none) { + // compile error + return; + } + + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_call_function_0(module_fun); + nlr_pop(); + } else { + // uncaught exception + mp_obj_print_exception((mp_obj_t)nlr.ret_val); + } +} + +int main(int argc, char **argv) { + qstr_init(); + mp_init(); + do_str("print('hello world!')"); + mp_deinit(); + return 0; +} + +void gc_collect(void) { +} + +mp_lexer_t *mp_lexer_new_from_file(const char *filename) { + return NULL; +} + +mp_import_stat_t mp_import_stat(const char *path) { + return MP_IMPORT_STAT_NO_EXIST; +} + +mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args) { + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_open_obj, 1, 2, mp_builtin_open); + +void nlr_jump_fail(void *val) { +} diff --git a/qemu-arm/mpconfigport.h b/qemu-arm/mpconfigport.h new file mode 100644 index 000000000..7f4c37890 --- /dev/null +++ b/qemu-arm/mpconfigport.h @@ -0,0 +1,34 @@ +#include + +// options to control how Micro Python is built + +#define MICROPY_EMIT_X64 (0) +#define MICROPY_EMIT_THUMB (0) +#define MICROPY_EMIT_INLINE_THUMB (0) +#define MICROPY_MEM_STATS (0) +#define MICROPY_DEBUG_PRINTERS (0) +#define MICROPY_ENABLE_GC (0) +#define MICROPY_ENABLE_REPL_HELPERS (0) +#define MICROPY_ENABLE_LEXER_UNIX (0) +#define MICROPY_ENABLE_SOURCE_LINE (0) +#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE) +#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE) +#define MICROPY_PATH_MAX (512) + +// type definitions for the specific machine + +#define BYTES_PER_WORD (4) + +#define UINT_FMT "%lu" +#define INT_FMT "%ld" + +typedef int32_t machine_int_t; // must be pointer size +typedef uint32_t machine_uint_t; // must be pointer size +typedef void *machine_ptr_t; // must be of pointer size +typedef const void *machine_const_ptr_t; // must be of pointer size + +// extra built in names to add to the global namespace +extern const struct _mp_obj_fun_native_t mp_builtin_open_obj; +#define MICROPY_EXTRA_BUILTINS \ + { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, + diff --git a/qemu-arm/qstrdefsport.h b/qemu-arm/qstrdefsport.h new file mode 100644 index 000000000..3ba897069 --- /dev/null +++ b/qemu-arm/qstrdefsport.h @@ -0,0 +1 @@ +// qstrs specific to this port -- cgit v1.2.3