Skip to content

Commit af09cb5

Browse files
committed
Move continuation stack from .bss onto sys stack
1 parent 3a110aa commit af09cb5

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

cores/esp8266/cont_util.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#define CONT_STACKGUARD 0xfeefeffe
2727

2828
void cont_init(cont_t* cont) {
29+
memset(cont, 0, sizeof(cont_t));
30+
2931
cont->stack_guard1 = CONT_STACKGUARD;
3032
cont->stack_guard2 = CONT_STACKGUARD;
3133
cont->stack_end = cont->stack + (sizeof(cont->stack) / 4);

cores/esp8266/core_esp8266_main.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ extern "C" {
4040

4141
#define OPTIMISTIC_YIELD_TIME_US 16000
4242

43+
44+
extern "C" void call_user_start();
45+
4346
struct rst_info resetInfo;
4447

4548
extern "C" {
@@ -76,14 +79,14 @@ void preloop_update_frequency() {
7679
extern void (*__init_array_start)(void);
7780
extern void (*__init_array_end)(void);
7881

79-
cont_t g_cont __attribute__ ((aligned (16)));
82+
cont_t* g_pcont __attribute__((section(".noinit")));
8083
static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
8184

8285
static uint32_t g_micros_at_task_start;
8386

8487
extern "C" void esp_yield() {
85-
if (cont_can_yield(&g_cont)) {
86-
cont_yield(&g_cont);
88+
if (cont_can_yield(g_pcont)) {
89+
cont_yield(g_pcont);
8790
}
8891
}
8992

@@ -92,7 +95,7 @@ extern "C" void esp_schedule() {
9295
}
9396

9497
extern "C" void __yield() {
95-
if (cont_can_yield(&g_cont)) {
98+
if (cont_can_yield(g_pcont)) {
9699
esp_schedule();
97100
esp_yield();
98101
}
@@ -104,7 +107,7 @@ extern "C" void __yield() {
104107
extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
105108

106109
extern "C" void optimistic_yield(uint32_t interval_us) {
107-
if (cont_can_yield(&g_cont) &&
110+
if (cont_can_yield(g_pcont) &&
108111
(system_get_time() - g_micros_at_task_start) > interval_us)
109112
{
110113
yield();
@@ -126,8 +129,8 @@ static void loop_wrapper() {
126129
static void loop_task(os_event_t *events) {
127130
(void) events;
128131
g_micros_at_task_start = system_get_time();
129-
cont_run(&g_cont, &loop_wrapper);
130-
if (cont_check(&g_cont) != 0) {
132+
cont_run(g_pcont, &loop_wrapper);
133+
if (cont_check(g_pcont) != 0) {
131134
panic();
132135
}
133136
}
@@ -146,6 +149,12 @@ void init_done() {
146149
}
147150

148151

152+
extern "C" void ICACHE_RAM_ATTR app_entry(void) {
153+
cont_t s_cont __attribute__((aligned(16)));
154+
g_pcont = &s_cont;
155+
call_user_start();
156+
}
157+
149158
extern "C" void user_init(void) {
150159
struct rst_info *rtc_info_ptr = system_get_rst_info();
151160
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));
@@ -156,7 +165,7 @@ extern "C" void user_init(void) {
156165

157166
initVariant();
158167

159-
cont_init(&g_cont);
168+
cont_init(g_pcont);
160169

161170
ets_task(loop_task,
162171
LOOP_TASK_PRIORITY, g_loop_queue,

cores/esp8266/core_esp8266_postmortem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
extern void __real_system_restart_local();
3434

35-
extern cont_t g_cont;
35+
extern cont_t* g_pcont;
3636

3737
// These will be pointers to PROGMEM const strings
3838
static const char* s_panic_file = 0;
@@ -131,8 +131,8 @@ void __wrap_system_restart_local() {
131131
ets_printf_P("\nSoft WDT reset\n");
132132
}
133133

134-
uint32_t cont_stack_start = (uint32_t) &(g_cont.stack);
135-
uint32_t cont_stack_end = (uint32_t) g_cont.stack_end;
134+
uint32_t cont_stack_start = (uint32_t) &(g_pcont->stack);
135+
uint32_t cont_stack_end = (uint32_t) g_pcont->stack_end;
136136
uint32_t stack_end;
137137

138138
// amount of stack taken by interrupt or exception handler

platform.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ compiler.c.flags=-c {compiler.warning_flags} -Os -g -Wpointer-arith -Wno-implici
3737
compiler.S.cmd=xtensa-lx106-elf-gcc
3838
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls
3939

40-
compiler.c.elf.flags=-g {compiler.warning_flags} -Os -nostdlib -Wl,--no-check-sections -u call_user_start {build.float} -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-L{compiler.libc.path}/lib" "-T{build.flash_ld}" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read
40+
compiler.c.elf.flags=-g {compiler.warning_flags} -Os -nostdlib -Wl,--no-check-sections -u app_entry {build.float} -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-L{compiler.libc.path}/lib" "-T{build.flash_ld}" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read
4141

4242
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
4343
compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc

tools/sdk/ld/eagle.app.v6.common.ld

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PHDRS
99
irom0_0_phdr PT_LOAD;
1010
}
1111
/* Default entry point: */
12-
ENTRY(call_user_start)
12+
ENTRY(app_entry)
1313
EXTERN(_DebugExceptionVector)
1414
EXTERN(_DoubleExceptionVector)
1515
EXTERN(_KernelExceptionVector)
@@ -75,6 +75,10 @@ SECTIONS
7575
_Pri_3_HandlerAddress = ABSOLUTE(.);
7676
_data_end = ABSOLUTE(.);
7777
} >dram0_0_seg :dram0_0_phdr
78+
.noinit : ALIGN(4)
79+
{
80+
*(.noinit)
81+
} >dram0_0_seg :dram0_0_phdr
7882
.irom0.text : ALIGN(4)
7983
{
8084
_irom0_text_start = ABSOLUTE(.);

tools/sdk/ld/eagle.app.v6.common.ld.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ PHDRS
1212

1313

1414
/* Default entry point: */
15-
ENTRY(call_user_start)
15+
ENTRY(app_entry)
1616
EXTERN(_DebugExceptionVector)
1717
EXTERN(_DoubleExceptionVector)
1818
EXTERN(_KernelExceptionVector)
@@ -83,6 +83,11 @@ SECTIONS
8383
_Pri_3_HandlerAddress = ABSOLUTE(.);
8484
_data_end = ABSOLUTE(.);
8585
} >dram0_0_seg :dram0_0_phdr
86+
87+
.noinit : ALIGN(4)
88+
{
89+
*(.noinit)
90+
} >dram0_0_seg :dram0_0_phdr
8691

8792
#ifdef VTABLES_IN_DRAM
8893
#include "eagle.app.v6.common.ld.vtables.h"

0 commit comments

Comments
 (0)