Skip to content

Commit fbea810

Browse files
committed
esp8266: Change bignum from mpz to longlong; move some rodata to iram.
Some rodata items can go in iram/irom segment, but not others. With this patch ESP now has 24256 bytes of heap ram. It passes 228 out of 248 tests from tests/basics directory.
1 parent 5f10065 commit fbea810

5 files changed

Lines changed: 81 additions & 39 deletions

File tree

esp8266/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LDFLAGS = -nostdlib -T esp8266.ld -Map=$(@:.elf=.map) --cref
2727
LIBS = -L$(ESP_SDK)/lib -lmain -ljson -llwip -lpp -lnet80211 -lwpa -lphy -lnet80211
2828

2929
LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
30-
LIBS += -L $(dir $(LIBGCC_FILE_NAME)) -lgcc
30+
LIBS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc
3131

3232
# Debugging/Optimization
3333
ifeq ($(DEBUG), 1)
@@ -40,6 +40,7 @@ LDFLAGS += --gc-sections
4040
endif
4141

4242
SRC_C = \
43+
strtoll.c \
4344
main.c \
4445
esp_mphal.c \
4546
gccollect.c \

esp8266/esp8266.ld

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,64 @@ SECTIONS
5252
*(.dport.rodata)
5353
_dport0_rodata_end = ABSOLUTE(.);
5454
} >dport0_0_seg :dport0_0_phdr
55-
55+
5656
.dport0.literal : ALIGN(4)
5757
{
5858
_dport0_literal_start = ABSOLUTE(.);
5959
*(.dport0.literal)
6060
*(.dport.literal)
6161
_dport0_literal_end = ABSOLUTE(.);
6262
} >dport0_0_seg :dport0_0_phdr
63-
63+
6464
.dport0.data : ALIGN(4)
6565
{
6666
_dport0_data_start = ABSOLUTE(.);
6767
*(.dport0.data)
6868
*(.dport.data)
6969
_dport0_data_end = ABSOLUTE(.);
7070
} >dport0_0_seg :dport0_0_phdr
71-
71+
72+
.irom0.text : ALIGN(4)
73+
{
74+
_irom0_text_start = ABSOLUTE(.);
75+
*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
76+
*py*.o*(.literal* .text*)
77+
*gccollect.o*(.literal* .text*)
78+
*gchelper.o*(.literal* .text*)
79+
_irom0_text_end = ABSOLUTE(.);
80+
} >irom0_0_seg :irom0_0_phdr
81+
82+
.text : ALIGN(4)
83+
{
84+
_stext = .;
85+
_text_start = ABSOLUTE(.);
86+
*(.entry.text)
87+
*(.init.literal)
88+
*(.init)
89+
*(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
90+
*(.fini.literal)
91+
*(.fini)
92+
*(.gnu.version)
93+
*qstr.o(.rodata.const_pool)
94+
*.o(.rodata.mp_type_*)
95+
/*
96+
can't put these here for some reason...
97+
*builtin.o(.rodata.mp_builtin_*_obj)
98+
*parse.o(.rodata.rule_*)
99+
*/
100+
_text_end = ABSOLUTE(.);
101+
_etext = .;
102+
} >iram1_0_seg :iram1_0_phdr
103+
104+
.lit4 : ALIGN(4)
105+
{
106+
_lit4_start = ABSOLUTE(.);
107+
*(*.lit4)
108+
*(.lit4.*)
109+
*(.gnu.linkonce.lit4.*)
110+
_lit4_end = ABSOLUTE(.);
111+
} >iram1_0_seg :iram1_0_phdr
112+
72113
.data : ALIGN(4)
73114
{
74115
_data_start = ABSOLUTE(.);
@@ -85,7 +126,7 @@ SECTIONS
85126
*(.jcr)
86127
_data_end = ABSOLUTE(.);
87128
} >dram0_0_seg :dram0_0_phdr
88-
129+
89130
.rodata : ALIGN(4)
90131
{
91132
_rodata_start = ABSOLUTE(.);
@@ -123,7 +164,7 @@ SECTIONS
123164
_bss_table_end = ABSOLUTE(.);
124165
_rodata_end = ABSOLUTE(.);
125166
} >dram0_0_seg :dram0_0_phdr
126-
167+
127168
.bss ALIGN(8) (NOLOAD) : ALIGN(4)
128169
{
129170
. = ALIGN (8);
@@ -145,38 +186,6 @@ SECTIONS
145186
_bss_end = ABSOLUTE(.);
146187
_heap_start = ABSOLUTE(.);
147188
} >dram0_0_seg :dram0_0_bss_phdr
148-
149-
.irom0.text : ALIGN(4)
150-
{
151-
_irom0_text_start = ABSOLUTE(.);
152-
*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
153-
*py*.o*(.literal* .text*)
154-
_irom0_text_end = ABSOLUTE(.);
155-
} >irom0_0_seg :irom0_0_phdr
156-
157-
.text : ALIGN(4)
158-
{
159-
_stext = .;
160-
_text_start = ABSOLUTE(.);
161-
*(.entry.text)
162-
*(.init.literal)
163-
*(.init)
164-
*(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
165-
*(.fini.literal)
166-
*(.fini)
167-
*(.gnu.version)
168-
_text_end = ABSOLUTE(.);
169-
_etext = .;
170-
} >iram1_0_seg :iram1_0_phdr
171-
172-
.lit4 : ALIGN(4)
173-
{
174-
_lit4_start = ABSOLUTE(.);
175-
*(*.lit4)
176-
*(.lit4.*)
177-
*(.gnu.linkonce.lit4.*)
178-
_lit4_end = ABSOLUTE(.);
179-
} >iram1_0_seg :iram1_0_phdr
180189
}
181190

182191
/* get ROM code address */

esp8266/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include MICROPY_HAL_H
4545

4646
void user_init(void) {
47+
soft_reset:
4748
//mp_stack_set_limit((char*)&_ram_end - (char*)&_heap_end - 1024);
4849
mp_hal_init();
4950
gc_init(&_heap_start, &_heap_end);
@@ -65,6 +66,8 @@ void user_init(void) {
6566
}
6667
}
6768
}
69+
70+
goto soft_reset;
6871
}
6972

7073
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {

esp8266/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#define MICROPY_PY_SYS_EXIT (1)
3232
#define MICROPY_PY_SYS_STDFILES (1)
3333
#define MICROPY_CPYTHON_COMPAT (0)
34-
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
34+
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG)
3535
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
3636
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
3737

esp8266/strtoll.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdlib.h>
2+
3+
// assumes endptr != NULL
4+
// doesn't check for sign
5+
// doesn't check for base-prefix
6+
long long int strtoll(const char *nptr, char **endptr, int base) {
7+
long long val = 0;
8+
9+
for (; *nptr; nptr++) {
10+
int v = *nptr;
11+
if ('0' <= v && v <= '9') {
12+
v -= '0';
13+
} else if ('A' <= v && v <= 'Z') {
14+
v -= 'A' - 10;
15+
} else if ('a' <= v && v <= 'z') {
16+
v -= 'a' - 10;
17+
} else {
18+
break;
19+
}
20+
if (v >= base) {
21+
break;
22+
}
23+
val = val * base + v;
24+
}
25+
26+
*endptr = (char*)nptr;
27+
28+
return val;
29+
}

0 commit comments

Comments
 (0)