Skip to content

Commit a975ef4

Browse files
authored
Merge pull request #3695 from cwalther/movable
Add movable supervisor allocations
2 parents 299b6ef + d6f8a43 commit a975ef4

File tree

20 files changed

+363
-231
lines changed

20 files changed

+363
-231
lines changed

main.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ void start_mp(supervisor_allocation* heap) {
123123
// to recover from limit hit. (Limit is measured in bytes.)
124124
mp_stack_ctrl_init();
125125

126-
if (stack_alloc != NULL) {
127-
mp_stack_set_limit(stack_alloc->length - 1024);
126+
if (stack_get_bottom() != NULL) {
127+
mp_stack_set_limit(stack_get_length() - 1024);
128128
}
129129

130130

131131
#if MICROPY_MAX_STACK_USAGE
132132
// _ezero (same as _ebss) is an int, so start 4 bytes above it.
133-
if (stack_alloc != NULL) {
134-
mp_stack_set_bottom(stack_alloc->ptr);
133+
if (stack_get_bottom() != NULL) {
134+
mp_stack_set_bottom(stack_get_bottom());
135135
mp_stack_fill_with_sentinel();
136136
}
137137
#endif
@@ -148,7 +148,7 @@ void start_mp(supervisor_allocation* heap) {
148148
#endif
149149

150150
#if MICROPY_ENABLE_GC
151-
gc_init(heap->ptr, heap->ptr + heap->length / 4);
151+
gc_init(heap->ptr, heap->ptr + get_allocation_length(heap) / 4);
152152
#endif
153153
mp_init();
154154
mp_obj_list_init(mp_sys_path, 0);
@@ -451,9 +451,6 @@ int __attribute__((used)) main(void) {
451451
// initialise the cpu and peripherals
452452
safe_mode_t safe_mode = port_init();
453453

454-
// Init memory after the port in case the port needs to set aside memory.
455-
memory_init();
456-
457454
// Turn on LEDs
458455
init_status_leds();
459456
rgb_led_status_init();

ports/atmel-samd/supervisor/port.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ void reset_cpu(void) {
390390
reset();
391391
}
392392

393-
supervisor_allocation* port_fixed_stack(void) {
394-
return NULL;
393+
bool port_has_fixed_stack(void) {
394+
return false;
395395
}
396396

397397
uint32_t *port_stack_get_limit(void) {

ports/cxd56/supervisor/port.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,8 @@ void reset_to_bootloader(void) {
9898
}
9999
}
100100

101-
supervisor_allocation _fixed_stack;
102-
103-
supervisor_allocation* port_fixed_stack(void) {
104-
_fixed_stack.ptr = port_stack_get_limit();
105-
_fixed_stack.length = (port_stack_get_top() - port_stack_get_limit()) * sizeof(uint32_t);
106-
return &_fixed_stack;
101+
bool port_has_fixed_stack(void) {
102+
return true;
107103
}
108104

109105
uint32_t *port_stack_get_limit(void) {

ports/esp32s2/supervisor/port.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,8 @@ uint32_t *port_stack_get_top(void) {
193193
return port_stack_get_limit() + ESP_TASK_MAIN_STACK / (sizeof(uint32_t) / sizeof(StackType_t));
194194
}
195195

196-
supervisor_allocation _fixed_stack;
197-
198-
supervisor_allocation* port_fixed_stack(void) {
199-
_fixed_stack.ptr = port_stack_get_limit();
200-
_fixed_stack.length = (port_stack_get_top() - port_stack_get_limit()) * sizeof(uint32_t);
201-
return &_fixed_stack;
196+
bool port_has_fixed_stack(void) {
197+
return true;
202198
}
203199

204200
// Place the word to save just after our BSS section that gets blanked.

ports/litex/supervisor/port.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ void reset_cpu(void) {
9898
for(;;) {}
9999
}
100100

101-
supervisor_allocation* port_fixed_stack(void) {
102-
return NULL;
101+
bool port_has_fixed_stack(void) {
102+
return false;
103103
}
104104

105105
uint32_t *port_heap_get_bottom(void) {

ports/mimxrt10xx/supervisor/port.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,8 @@ uint32_t *port_stack_get_top(void) {
334334
return &_ld_stack_top;
335335
}
336336

337-
supervisor_allocation _fixed_stack;
338-
supervisor_allocation* port_fixed_stack(void) {
339-
_fixed_stack.ptr = port_stack_get_limit();
340-
_fixed_stack.length = (port_stack_get_top() - port_stack_get_limit()) * sizeof(uint32_t);
341-
return &_fixed_stack;
337+
bool port_has_fixed_stack(void) {
338+
return true;
342339
}
343340

344341
uint32_t *port_heap_get_bottom(void) {

ports/nrf/supervisor/port.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ uint32_t *port_heap_get_top(void) {
251251
return port_stack_get_top();
252252
}
253253

254-
supervisor_allocation* port_fixed_stack(void) {
255-
return NULL;
254+
bool port_has_fixed_stack(void) {
255+
return false;
256256
}
257257

258258
uint32_t *port_stack_get_limit(void) {

ports/stm/supervisor/port.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ uint32_t *port_heap_get_top(void) {
267267
return &_ld_heap_end;
268268
}
269269

270-
supervisor_allocation* port_fixed_stack(void) {
271-
return NULL;
270+
bool port_has_fixed_stack(void) {
271+
return false;
272272
}
273273

274274
uint32_t *port_stack_get_limit(void) {

py/circuitpy_mpconfig.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,17 +860,20 @@ extern const struct _mp_obj_module_t wifi_module;
860860

861861
#include "supervisor/flash_root_pointers.h"
862862

863+
// From supervisor/memory.c
864+
struct _supervisor_allocation_node;
865+
863866
#define CIRCUITPY_COMMON_ROOT_POINTERS \
864867
const char *readline_hist[8]; \
865868
vstr_t *repl_line; \
866869
mp_obj_t rtc_time_source; \
867870
GAMEPAD_ROOT_POINTERS \
868871
mp_obj_t pew_singleton; \
869-
mp_obj_t terminal_tilegrid_tiles; \
870872
BOARD_UART_ROOT_POINTER \
871873
FLASH_ROOT_POINTERS \
872874
MEMORYMONITOR_ROOT_POINTERS \
873875
NETWORK_ROOT_POINTERS \
876+
struct _supervisor_allocation_node* first_embedded_allocation; \
874877

875878
void supervisor_run_background_tasks_if_tick(void);
876879
#define RUN_BACKGROUND_TASKS (supervisor_run_background_tasks_if_tick())

shared-module/rgbmatrix/RGBMatrix.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
7878
// verify that the matrix is big enough
7979
mp_get_index(mp_obj_get_type(self->framebuffer), self->bufinfo.len, MP_OBJ_NEW_SMALL_INT(self->bufsize-1), false);
8080
} else {
81-
_PM_free(self->bufinfo.buf);
82-
_PM_free(self->protomatter.rgbPins);
83-
_PM_free(self->protomatter.addr);
84-
_PM_free(self->protomatter.screenData);
81+
common_hal_rgbmatrix_free_impl(self->bufinfo.buf);
82+
common_hal_rgbmatrix_free_impl(self->protomatter.rgbPins);
83+
common_hal_rgbmatrix_free_impl(self->protomatter.addr);
84+
common_hal_rgbmatrix_free_impl(self->protomatter.screenData);
8585

8686
self->framebuffer = NULL;
8787
self->bufinfo.buf = common_hal_rgbmatrix_allocator_impl(self->bufsize);
@@ -180,9 +180,6 @@ void common_hal_rgbmatrix_rgbmatrix_deinit(rgbmatrix_rgbmatrix_obj_t* self) {
180180

181181
void rgbmatrix_rgbmatrix_collect_ptrs(rgbmatrix_rgbmatrix_obj_t* self) {
182182
gc_collect_ptr(self->framebuffer);
183-
gc_collect_ptr(self->protomatter.rgbPins);
184-
gc_collect_ptr(self->protomatter.addr);
185-
gc_collect_ptr(self->protomatter.screenData);
186183
}
187184

188185
void common_hal_rgbmatrix_rgbmatrix_set_paused(rgbmatrix_rgbmatrix_obj_t* self, bool paused) {
@@ -217,18 +214,10 @@ int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self) {
217214
}
218215

219216
void *common_hal_rgbmatrix_allocator_impl(size_t sz) {
220-
if (gc_alloc_possible()) {
221-
return m_malloc_maybe(sz + sizeof(void*), true);
222-
} else {
223-
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
224-
return allocation ? allocation->ptr : NULL;
225-
}
217+
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false, true);
218+
return allocation ? allocation->ptr : NULL;
226219
}
227220

228221
void common_hal_rgbmatrix_free_impl(void *ptr_in) {
229-
supervisor_allocation *allocation = allocation_from_ptr(ptr_in);
230-
231-
if (allocation) {
232-
free_memory(allocation);
233-
}
222+
free_memory(allocation_from_ptr(ptr_in));
234223
}

0 commit comments

Comments
 (0)