aboutsummaryrefslogtreecommitdiff
path: root/mpy-cross
diff options
context:
space:
mode:
Diffstat (limited to 'mpy-cross')
-rw-r--r--mpy-cross/Makefile1
-rw-r--r--mpy-cross/gccollect.c113
-rw-r--r--mpy-cross/mpconfigport.h11
-rw-r--r--mpy-cross/mpy-cross.vcxproj3
4 files changed, 10 insertions, 118 deletions
diff --git a/mpy-cross/Makefile b/mpy-cross/Makefile
index 2116cc670..f80ee761b 100644
--- a/mpy-cross/Makefile
+++ b/mpy-cross/Makefile
@@ -48,6 +48,7 @@ LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
SRC_C = \
main.c \
gccollect.c \
+ lib/utils/gchelper_generic.c \
# Add fmode when compiling with mingw gcc
COMPILER_TARGET := $(shell $(CC) -dumpmachine)
diff --git a/mpy-cross/gccollect.c b/mpy-cross/gccollect.c
index f655a07da..120f1a225 100644
--- a/mpy-cross/gccollect.c
+++ b/mpy-cross/gccollect.c
@@ -29,120 +29,13 @@
#include "py/mpstate.h"
#include "py/gc.h"
-#if MICROPY_ENABLE_GC
-
-// Even if we have specific support for an architecture, it is
-// possible to force use of setjmp-based implementation.
-#if !MICROPY_GCREGS_SETJMP
-
-// We capture here callee-save registers, i.e. ones which may contain
-// interesting values held there by our callers. It doesn't make sense
-// to capture caller-saved registers, because they, well, put on the
-// stack already by the caller.
-#if defined(__x86_64__)
-typedef mp_uint_t regs_t[6];
-
-STATIC void gc_helper_get_regs(regs_t arr) {
- register long rbx asm ("rbx");
- register long rbp asm ("rbp");
- register long r12 asm ("r12");
- register long r13 asm ("r13");
- register long r14 asm ("r14");
- register long r15 asm ("r15");
- #ifdef __clang__
- // TODO:
- // This is dirty workaround for Clang. It tries to get around
- // uncompliant (wrt to GCC) behavior of handling register variables.
- // Application of this patch here is random, and done only to unbreak
- // MacOS build. Better, cross-arch ways to deal with Clang issues should
- // be found.
- asm ("" : "=r" (rbx));
- asm ("" : "=r" (rbp));
- asm ("" : "=r" (r12));
- asm ("" : "=r" (r13));
- asm ("" : "=r" (r14));
- asm ("" : "=r" (r15));
- #endif
- arr[0] = rbx;
- arr[1] = rbp;
- arr[2] = r12;
- arr[3] = r13;
- arr[4] = r14;
- arr[5] = r15;
-}
-
-#elif defined(__i386__)
-
-typedef mp_uint_t regs_t[4];
-
-STATIC void gc_helper_get_regs(regs_t arr) {
- register long ebx asm ("ebx");
- register long esi asm ("esi");
- register long edi asm ("edi");
- register long ebp asm ("ebp");
- arr[0] = ebx;
- arr[1] = esi;
- arr[2] = edi;
- arr[3] = ebp;
-}
-
-#elif defined(__thumb2__) || defined(__thumb__) || defined(__arm__)
-
-typedef mp_uint_t regs_t[10];
+#include "lib/utils/gchelper.h"
-STATIC void gc_helper_get_regs(regs_t arr) {
- register long r4 asm ("r4");
- register long r5 asm ("r5");
- register long r6 asm ("r6");
- register long r7 asm ("r7");
- register long r8 asm ("r8");
- register long r9 asm ("r9");
- register long r10 asm ("r10");
- register long r11 asm ("r11");
- register long r12 asm ("r12");
- register long r13 asm ("r13");
- arr[0] = r4;
- arr[1] = r5;
- arr[2] = r6;
- arr[3] = r7;
- arr[4] = r8;
- arr[5] = r9;
- arr[6] = r10;
- arr[7] = r11;
- arr[8] = r12;
- arr[9] = r13;
-}
-
-#else
-
-// If we don't have architecture-specific optimized support,
-// just fall back to setjmp-based implementation.
-#undef MICROPY_GCREGS_SETJMP
-#define MICROPY_GCREGS_SETJMP (1)
-
-#endif // Arch-specific selection
-#endif // !MICROPY_GCREGS_SETJMP
-
-// If MICROPY_GCREGS_SETJMP was requested explicitly, or if
-// we enabled it as a fallback above.
-#if MICROPY_GCREGS_SETJMP
-#include <setjmp.h>
-
-typedef jmp_buf regs_t;
-
-STATIC void gc_helper_get_regs(regs_t arr) {
- setjmp(arr);
-}
-
-#endif // MICROPY_GCREGS_SETJMP
+#if MICROPY_ENABLE_GC
void gc_collect(void) {
gc_collect_start();
- regs_t regs;
- gc_helper_get_regs(regs);
- // GC stack (and regs because we captured them)
- void **regs_ptr = (void **)(void *)&regs;
- gc_collect_root(regs_ptr, ((mp_uint_t)MP_STATE_THREAD(stack_top) - (mp_uint_t)&regs) / sizeof(mp_uint_t));
+ gc_helper_collect_regs_and_stack();
gc_collect_end();
}
diff --git a/mpy-cross/mpconfigport.h b/mpy-cross/mpconfigport.h
index f2b4ae99b..2282e5e08 100644
--- a/mpy-cross/mpconfigport.h
+++ b/mpy-cross/mpconfigport.h
@@ -68,14 +68,9 @@
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
-// Define to 1 to use undertested inefficient GC helper implementation
-// (if more efficient arch-specific one is not available).
-#ifndef MICROPY_GCREGS_SETJMP
- #ifdef __mips__
- #define MICROPY_GCREGS_SETJMP (1)
- #else
- #define MICROPY_GCREGS_SETJMP (0)
- #endif
+#if !defined(__x86_64__) || !defined(__i386__) || !defined(__thumb2__) || !defined(__thumb__) || !defined(__arm__)
+// Fall back to setjmp() implementation for discovery of GC pointers in registers.
+#define MICROPY_GCREGS_SETJMP (1)
#endif
#define MICROPY_PY___FILE__ (0)
diff --git a/mpy-cross/mpy-cross.vcxproj b/mpy-cross/mpy-cross.vcxproj
index 805580c78..74a366712 100644
--- a/mpy-cross/mpy-cross.vcxproj
+++ b/mpy-cross/mpy-cross.vcxproj
@@ -89,6 +89,9 @@
<Import Project="$(PyMsvcDir)sources.props" />
<ItemGroup>
<ClCompile Include="@(PyCoreSource)" />
+ <ClCompile Include="$(PyBaseDir)lib/utils/gchelper_generic.c" >
+ <PreprocessorDefinitions>MICROPY_GCREGS_SETJMP</PreprocessorDefinitions>
+ </ClCompile>
<ClCompile Include="$(PyBaseDir)mpy-cross\gccollect.c"/>
<ClCompile Include="$(PyBaseDir)mpy-cross\main.c"/>
<ClCompile Include="$(PyBaseDir)ports\windows\fmode.c" />