1# If the Newlib functions in ROM aren't used (eg because the external SPI RAM workaround is active), these functions will
2# be linked into the application directly instead. Normally, they would end up in flash, which is undesirable because esp-idf
3# and/or applications may assume that because these functions normally are in ROM, they are accessible even when flash is
4# inaccessible. To work around this, this ld fragment places these functions in RAM instead. If the ROM functions are used,
5# these defines do nothing, so they can still be included in that situation.
6#
7#
8# Note: the only difference between esp32-spiram-rom-functions-c.lf
9# and esp32-spiram-rom-functions-psram-workaround.lf is the archive name.
10
11[mapping:libc]
12archive:
13  if NEWLIB_NANO_FORMAT = y:
14    libc_nano.a
15  else:
16    libc.a
17entries:
18  if SPIRAM_CACHE_WORKAROUND = y:
19    # The following libs are either used in a lot of places or in critical
20    # code. (such as panic or abort)
21    # Thus, they shall always be placed in IRAM.
22    lib_a-itoa (noflash)
23    lib_a-memcmp (noflash)
24    lib_a-memcpy (noflash)
25    lib_a-memset (noflash)
26    lib_a-strcat (noflash)
27    lib_a-strcmp (noflash)
28    lib_a-strlen (noflash)
29
30    if SPIRAM_CACHE_LIBJMP_IN_IRAM = y:
31        lib_a-longjmp (noflash)
32        lib_a-setjmp (noflash)
33
34    if SPIRAM_CACHE_LIBMATH_IN_IRAM = y:
35        lib_a-abs (noflash)
36        lib_a-div (noflash)
37        lib_a-labs (noflash)
38        lib_a-ldiv (noflash)
39        lib_a-quorem (noflash)
40        lib_a-s_fpclassify (noflash)
41        lib_a-sf_nan (noflash)
42
43    if SPIRAM_CACHE_LIBNUMPARSER_IN_IRAM = y:
44        lib_a-utoa (noflash)
45        lib_a-atoi (noflash)
46        lib_a-atol (noflash)
47        lib_a-strtol (noflash)
48        lib_a-strtoul (noflash)
49
50    if SPIRAM_CACHE_LIBIO_IN_IRAM = y:
51        lib_a-wcrtomb (noflash)
52        lib_a-fvwrite (noflash)
53        lib_a-wbuf (noflash)
54        lib_a-wsetup (noflash)
55        lib_a-fputwc (noflash)
56        lib_a-wctomb_r (noflash)
57        lib_a-ungetc (noflash)
58        lib_a-makebuf (noflash)
59        lib_a-fflush (noflash)
60        lib_a-refill (noflash)
61        lib_a-sccl (noflash)
62
63    if SPIRAM_CACHE_LIBTIME_IN_IRAM = y:
64        lib_a-asctime (noflash)
65        lib_a-asctime_r (noflash)
66        lib_a-ctime (noflash)
67        lib_a-ctime_r (noflash)
68        lib_a-lcltime (noflash)
69        lib_a-lcltime_r (noflash)
70        lib_a-gmtime (noflash)
71        lib_a-gmtime_r (noflash)
72        lib_a-strftime (noflash)
73        lib_a-mktime (noflash)
74        lib_a-tzset_r (noflash)
75        lib_a-tzset (noflash)
76        lib_a-time (noflash)
77        lib_a-gettzinfo (noflash)
78        lib_a-systimes (noflash)
79        lib_a-month_lengths (noflash)
80        lib_a-timelocal (noflash)
81        lib_a-tzvars (noflash)
82        lib_a-tzlock (noflash)
83        lib_a-tzcalc_limits (noflash)
84        lib_a-strptime (noflash)
85
86    if SPIRAM_CACHE_LIBCHAR_IN_IRAM = y:
87        lib_a-ctype_ (noflash)
88        lib_a-toupper (noflash)
89        lib_a-tolower (noflash)
90        lib_a-toascii (noflash)
91        lib_a-strupr (noflash)
92        lib_a-bzero (noflash)
93        lib_a-isalnum (noflash)
94        lib_a-isalpha (noflash)
95        lib_a-isascii (noflash)
96        lib_a-isblank (noflash)
97        lib_a-iscntrl (noflash)
98        lib_a-isdigit (noflash)
99        lib_a-isgraph (noflash)
100        lib_a-islower (noflash)
101        lib_a-isprint (noflash)
102        lib_a-ispunct (noflash)
103        lib_a-isspace (noflash)
104        lib_a-isupper (noflash)
105
106    if SPIRAM_CACHE_LIBMEM_IN_IRAM = y:
107        lib_a-memccpy (noflash)
108        lib_a-memchr (noflash)
109        lib_a-memmove (noflash)
110        lib_a-memrchr (noflash)
111
112    if SPIRAM_CACHE_LIBSTR_IN_IRAM = y:
113        lib_a-strcasecmp (noflash)
114        lib_a-strcasestr (noflash)
115        lib_a-strchr (noflash)
116        lib_a-strcoll (noflash)
117        lib_a-strcpy (noflash)
118        lib_a-strcspn (noflash)
119        lib_a-strdup (noflash)
120        lib_a-strdup_r (noflash)
121        lib_a-strlcat (noflash)
122        lib_a-strlcpy (noflash)
123        lib_a-strlwr (noflash)
124        lib_a-strncasecmp (noflash)
125        lib_a-strncat (noflash)
126        lib_a-strncmp (noflash)
127        lib_a-strncpy (noflash)
128        lib_a-strndup (noflash)
129        lib_a-strndup_r (noflash)
130        lib_a-strnlen (noflash)
131        lib_a-strrchr (noflash)
132        lib_a-strsep (noflash)
133        lib_a-strspn (noflash)
134        lib_a-strstr (noflash)
135        lib_a-strtok_r (noflash)
136        lib_a-strupr (noflash)
137
138    if SPIRAM_CACHE_LIBRAND_IN_IRAM = y:
139        lib_a-srand (noflash)
140        lib_a-rand (noflash)
141        lib_a-rand_r (noflash)
142
143    if SPIRAM_CACHE_LIBENV_IN_IRAM = y:
144        lib_a-environ (noflash)
145        lib_a-envlock (noflash)
146        lib_a-getenv_r (noflash)
147
148    if SPIRAM_CACHE_LIBFILE_IN_IRAM = y:
149        lock (noflash)
150        isatty (noflash)
151        lib_a-fclose (noflash)
152        lib_a-open (noflash)
153        lib_a-close (noflash)
154        lib_a-creat (noflash)
155        lib_a-read (noflash)
156        lib_a-rshift (noflash)
157        lib_a-sbrk (noflash)
158        lib_a-stdio (noflash)
159        lib_a-syssbrk (noflash)
160        lib_a-sysclose (noflash)
161        lib_a-sysopen (noflash)
162        creat (noflash)
163        lib_a-sysread (noflash)
164        lib_a-syswrite (noflash)
165        lib_a-impure (noflash)
166        lib_a-fwalk (noflash)
167        lib_a-findfp (noflash)
168
169    if SPIRAM_CACHE_LIBMISC_IN_IRAM = y:
170        lib_a-raise (noflash)
171        lib_a-system (noflash)
172