Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #515 from errordeveloper/qemu
Qemu
- Loading branch information
Showing
5 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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- | ||
|
||
INC = -I. | ||
INC += -I$(PY_SRC) | ||
INC += -I$(BUILD) | ||
|
||
CFLAGS_CORTEX_M3 = -mthumb -mcpu=cortex-m3 | ||
CFLAGS = $(INC) -Wall -Werror -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#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) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <stdint.h> | ||
|
||
// 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 }, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// qstrs specific to this port |