From d53dc04903850fdad7b8c14351e2cf28616a0ead Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 12 Feb 2019 14:48:29 +1100 Subject: [PATCH] qemu-arm: Use gchelper code to get registers for GC scanning. --- ports/qemu-arm/Makefile | 4 ++++ ports/qemu-arm/test_main.c | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ports/qemu-arm/Makefile b/ports/qemu-arm/Makefile index b3d9cdf566..03a8afe77e 100644 --- a/ports/qemu-arm/Makefile +++ b/ports/qemu-arm/Makefile @@ -13,6 +13,7 @@ ifeq ($(BOARD),netduino2) CFLAGS += -mthumb -mcpu=cortex-m3 -mfloat-abi=soft CFLAGS += -DQEMU_SOC_STM32 LDSCRIPT = stm32.ld +SRC_BOARD_O = lib/utils/gchelper_m3.o endif ifeq ($(BOARD),microbit) @@ -20,12 +21,14 @@ CFLAGS += -mthumb -mcpu=cortex-m0 -mfloat-abi=soft CFLAGS += -DQEMU_SOC_NRF51 LDSCRIPT = nrf51.ld QEMU_EXTRA = -global nrf51-soc.flash-size=1048576 -global nrf51-soc.sram-size=262144 +SRC_BOARD_O = lib/utils/gchelper_m0.o endif ifeq ($(BOARD),mps2-an385) CFLAGS += -mthumb -mcpu=cortex-m3 -mfloat-abi=soft CFLAGS += -DQEMU_SOC_MPS2 LDSCRIPT = mps2.ld +SRC_BOARD_O = lib/utils/gchelper_m3.o endif CROSS_COMPILE = arm-none-eabi- @@ -95,6 +98,7 @@ LIB_SRC_C += $(addprefix lib/,\ OBJ_COMMON = OBJ_COMMON += $(PY_O) OBJ_COMMON += $(addprefix $(BUILD)/, $(SRC_COMMON_C:.c=.o)) +OBJ_COMMON += $(addprefix $(BUILD)/, $(SRC_BOARD_O)) OBJ_COMMON += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o)) OBJ_RUN = diff --git a/ports/qemu-arm/test_main.c b/ports/qemu-arm/test_main.c index 2cb9e73859..3a85d65f38 100644 --- a/ports/qemu-arm/test_main.c +++ b/ports/qemu-arm/test_main.c @@ -11,6 +11,7 @@ #include "py/stackctrl.h" #include "py/gc.h" #include "py/mperrno.h" +#include "lib/utils/gchelper.h" #include "tinytest.h" #include "tinytest_macros.h" @@ -33,9 +34,8 @@ void gc_collect(void) { gc_collect_start(); // get the registers and the sp - // TODO get registers - volatile mp_uint_t dummy; - void *sp = (void*)&dummy; + uintptr_t regs[10]; + uintptr_t sp = gc_helper_get_regs_and_sp(regs); // trace the stack, including the registers (since they live on the stack in this function) gc_collect_root((void**)sp, ((uint32_t)MP_STATE_THREAD(stack_top) - (uint32_t)sp) / sizeof(uint32_t));