File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828#include <stdint.h>
2929
3030#include "py/mpconfig.h"
31+ #include "py/stackctrl.h"
3132#include "py/obj.h"
3233#include "py/runtime.h"
3334#include "py/gc.h"
@@ -104,9 +105,8 @@ static const char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n"
104105 ******************************************************************************/
105106
106107void TASK_Micropython (void * pvParameters ) {
107- // initialize the garbage collector with the top of our stack
108+ // get the top of the stack to initialize the garbage collector
108109 uint32_t sp = gc_helper_get_sp ();
109- gc_collect_init (sp );
110110
111111 bool safeboot = false;
112112 mptask_pre_init ();
@@ -122,6 +122,9 @@ void TASK_Micropython (void *pvParameters) {
122122 mp_thread_init ();
123123 #endif
124124
125+ // initialise the stack pointer for the main thread (must be done after mp_thread_init)
126+ mp_stack_set_top ((void * )sp );
127+
125128 // GC init
126129 gc_init (& _boot , & _eheap );
127130
Original file line number Diff line number Diff line change 2929#include <stdint.h>
3030
3131#include "py/mpconfig.h"
32+ #include "py/mpstate.h"
3233#include "py/gc.h"
3334#include "py/mpthread.h"
3435#include "gccollect.h"
3536#include "gchelper.h"
3637
37- /******************************************************************************
38- DECLARE PRIVATE DATA
39- ******************************************************************************/
40- static uint32_t stackend ;
41-
42-
4338/******************************************************************************
4439DECLARE PUBLIC FUNCTIONS
4540 ******************************************************************************/
46- void gc_collect_init (uint32_t sp ) {
47- stackend = sp ;
48- }
4941
5042void gc_collect (void ) {
5143 // start the GC
@@ -56,7 +48,7 @@ void gc_collect(void) {
5648 mp_uint_t sp = gc_helper_get_regs_and_sp (regs );
5749
5850 // trace the stack, including the registers (since they live on the stack in this function)
59- gc_collect_root ((void * * )sp , (stackend - sp ) / sizeof (uint32_t ));
51+ gc_collect_root ((void * * )sp , (( mp_uint_t ) MP_STATE_THREAD ( stack_top ) - sp ) / sizeof (uint32_t ));
6052
6153 // trace root pointers from any threads
6254 #if MICROPY_PY_THREAD
Original file line number Diff line number Diff line change @@ -38,5 +38,4 @@ extern uint32_t _eheap;
3838extern uint32_t _stack ;
3939extern uint32_t _estack ;
4040
41- void gc_collect_init (uint32_t sp );
4241void gc_collect (void );
You can’t perform that action at this time.
0 commit comments