Skip to content
Snippets Groups Projects
Verified Commit 6718f078 authored by Damien George's avatar Damien George Committed by dos
Browse files

esp32/gccollect: Make level arg volatile to force recursive function.

Otherwise the compiler may inline the gc_collect_inner() function and/or
remove the recursion, which is necessary to spill all the windowed
registers to the C stack.
parent c28df70d
No related branches found
No related tags found
No related merge requests found
Pipeline #9067 passed
...@@ -39,30 +39,25 @@ ...@@ -39,30 +39,25 @@
#include "xtensa/hal.h" #include "xtensa/hal.h"
static void gc_collect_inner(int level) { // The level argument must be volatile to force the compiler to emit code that
// will call this function recursively, to nest the C stack.
static void gc_collect_inner(volatile unsigned int level) {
if (level < XCHAL_NUM_AREGS / 8) { if (level < XCHAL_NUM_AREGS / 8) {
// Go deeper on the stack to spill more registers from the register window.
gc_collect_inner(level + 1); gc_collect_inner(level + 1);
if (level != 0) { } else {
return; // Deep enough so that all registers are on the C stack, now trace the stack.
}
}
if (level == XCHAL_NUM_AREGS / 8) {
// get the sp
volatile uint32_t sp = (uint32_t)esp_cpu_get_sp(); volatile uint32_t sp = (uint32_t)esp_cpu_get_sp();
gc_collect_root((void **)sp, ((mp_uint_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t)); gc_collect_root((void **)sp, ((mp_uint_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t));
return;
} }
// trace root pointers from any threads
#if MICROPY_PY_THREAD
mp_thread_gc_others();
#endif
} }
void gc_collect(void) { void gc_collect(void) {
gc_collect_start(); gc_collect_start();
gc_collect_inner(0); gc_collect_inner(0);
#if MICROPY_PY_THREAD
mp_thread_gc_others();
#endif
gc_collect_end(); gc_collect_end();
} }
...@@ -90,3 +85,4 @@ size_t gc_get_max_new_split(void) { ...@@ -90,3 +85,4 @@ size_t gc_get_max_new_split(void) {
} }
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment