2020-01-20 00:31:28 -05:00
|
|
|
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
|
2016-10-25 10:12:07 -04:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2021-06-03 01:09:52 -04:00
|
|
|
#include "sdkconfig.h"
|
2016-10-25 10:12:07 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include <sys/reent.h>
|
2021-03-17 06:48:05 -04:00
|
|
|
#include <assert.h>
|
2016-11-02 05:17:28 -04:00
|
|
|
#include "esp_newlib.h"
|
2020-12-29 20:31:16 -05:00
|
|
|
#include "esp_attr.h"
|
2020-05-03 17:15:58 -04:00
|
|
|
#include "soc/soc_caps.h"
|
2021-05-18 00:54:38 -04:00
|
|
|
#include "esp_rom_caps.h"
|
2016-10-25 10:12:07 -04:00
|
|
|
|
2020-01-20 00:31:28 -05:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
|
|
|
#include "esp32/rom/libc_stubs.h"
|
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
|
|
|
#include "esp32s2/rom/libc_stubs.h"
|
2020-07-29 01:13:51 -04:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
|
|
|
#include "esp32s3/rom/libc_stubs.h"
|
2020-12-29 20:31:16 -05:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32C3
|
|
|
|
#include "esp32c3/rom/libc_stubs.h"
|
2021-06-10 07:47:41 -04:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32H2
|
|
|
|
#include "esp32h2/rom/libc_stubs.h"
|
2020-01-20 00:31:28 -05:00
|
|
|
#endif
|
|
|
|
|
2016-10-25 10:12:07 -04:00
|
|
|
static struct _reent s_reent;
|
|
|
|
|
|
|
|
extern int _printf_float(struct _reent *rptr,
|
|
|
|
void *pdata,
|
|
|
|
FILE * fp,
|
2019-03-19 07:57:20 -04:00
|
|
|
int (*pfunc) (struct _reent *, FILE *, const char *, size_t len),
|
2016-10-25 10:12:07 -04:00
|
|
|
va_list * ap);
|
|
|
|
|
|
|
|
|
|
|
|
extern int _scanf_float(struct _reent *rptr,
|
|
|
|
void *pdata,
|
|
|
|
FILE *fp,
|
|
|
|
va_list *ap);
|
|
|
|
|
2018-08-07 16:26:05 -04:00
|
|
|
static void raise_r_stub(struct _reent *rptr)
|
|
|
|
{
|
|
|
|
_raise_r(rptr, 0);
|
|
|
|
}
|
2016-10-25 10:12:07 -04:00
|
|
|
|
|
|
|
static struct syscall_stub_table s_stub_table = {
|
|
|
|
.__getreent = &__getreent,
|
|
|
|
._malloc_r = &_malloc_r,
|
|
|
|
._free_r = &_free_r,
|
|
|
|
._realloc_r = &_realloc_r,
|
|
|
|
._calloc_r = &_calloc_r,
|
|
|
|
._abort = &abort,
|
|
|
|
._system_r = &_system_r,
|
2020-03-20 08:39:59 -04:00
|
|
|
._rename_r = &_rename_r,
|
2016-10-25 10:12:07 -04:00
|
|
|
._times_r = &_times_r,
|
|
|
|
._gettimeofday_r = &_gettimeofday_r,
|
2018-08-07 16:26:05 -04:00
|
|
|
._raise_r = &raise_r_stub,
|
2020-03-20 08:39:59 -04:00
|
|
|
._unlink_r = &_unlink_r,
|
|
|
|
._link_r = &_link_r,
|
|
|
|
._stat_r = &_stat_r,
|
|
|
|
._fstat_r = &_fstat_r,
|
2016-10-25 10:12:07 -04:00
|
|
|
._sbrk_r = &_sbrk_r,
|
|
|
|
._getpid_r = &_getpid_r,
|
|
|
|
._kill_r = &_kill_r,
|
|
|
|
._exit_r = NULL, // never called in ROM
|
2020-03-20 08:39:59 -04:00
|
|
|
._close_r = &_close_r,
|
|
|
|
._open_r = &_open_r,
|
|
|
|
._write_r = (int (*)(struct _reent *r, int, const void *, int)) &_write_r,
|
|
|
|
._lseek_r = (int (*)(struct _reent *r, int, int, int)) &_lseek_r,
|
|
|
|
._read_r = (int (*)(struct _reent *r, int, void *, int)) &_read_r,
|
2021-05-18 00:54:38 -04:00
|
|
|
#if ESP_ROM_HAS_RETARGETABLE_LOCKING
|
2020-12-29 20:31:16 -05:00
|
|
|
._retarget_lock_init = &__retarget_lock_init,
|
|
|
|
._retarget_lock_init_recursive = &__retarget_lock_init_recursive,
|
|
|
|
._retarget_lock_close = &__retarget_lock_close,
|
|
|
|
._retarget_lock_close_recursive = &__retarget_lock_close_recursive,
|
|
|
|
._retarget_lock_acquire = &__retarget_lock_acquire,
|
|
|
|
._retarget_lock_acquire_recursive = &__retarget_lock_acquire_recursive,
|
|
|
|
._retarget_lock_try_acquire = &__retarget_lock_try_acquire,
|
|
|
|
._retarget_lock_try_acquire_recursive = &__retarget_lock_try_acquire_recursive,
|
|
|
|
._retarget_lock_release = &__retarget_lock_release,
|
|
|
|
._retarget_lock_release_recursive = &__retarget_lock_release_recursive,
|
|
|
|
#else
|
2016-10-25 10:12:07 -04:00
|
|
|
._lock_init = &_lock_init,
|
|
|
|
._lock_init_recursive = &_lock_init_recursive,
|
|
|
|
._lock_close = &_lock_close,
|
2018-09-26 08:46:15 -04:00
|
|
|
._lock_close_recursive = &_lock_close_recursive,
|
2016-10-25 10:12:07 -04:00
|
|
|
._lock_acquire = &_lock_acquire,
|
|
|
|
._lock_acquire_recursive = &_lock_acquire_recursive,
|
|
|
|
._lock_try_acquire = &_lock_try_acquire,
|
|
|
|
._lock_try_acquire_recursive = &_lock_try_acquire_recursive,
|
|
|
|
._lock_release = &_lock_release,
|
|
|
|
._lock_release_recursive = &_lock_release_recursive,
|
2020-12-29 20:31:16 -05:00
|
|
|
#endif
|
2016-11-07 05:43:29 -05:00
|
|
|
#ifdef CONFIG_NEWLIB_NANO_FORMAT
|
2016-10-25 10:12:07 -04:00
|
|
|
._printf_float = &_printf_float,
|
|
|
|
._scanf_float = &_scanf_float,
|
2016-11-07 05:43:29 -05:00
|
|
|
#else
|
|
|
|
._printf_float = NULL,
|
|
|
|
._scanf_float = NULL,
|
|
|
|
#endif
|
2021-06-10 07:47:41 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2
|
2020-12-29 23:57:58 -05:00
|
|
|
/* TODO IDF-2570 : mark that this assert failed in ROM, to avoid confusion between IDF & ROM
|
2020-12-29 20:31:16 -05:00
|
|
|
assertion failures (as function names & source file names will be similar)
|
|
|
|
*/
|
|
|
|
.__assert_func = __assert_func,
|
|
|
|
|
|
|
|
/* We don't expect either ROM code or IDF to ever call __sinit, so it's implemented as abort() for now.
|
|
|
|
|
|
|
|
esp_reent_init() does this job inside IDF.
|
|
|
|
|
|
|
|
Kept in the syscall table in case we find a need for it later.
|
|
|
|
*/
|
|
|
|
.__sinit = (void *)abort,
|
|
|
|
._cleanup_r = &_cleanup_r,
|
|
|
|
#endif
|
2016-10-25 10:12:07 -04:00
|
|
|
};
|
|
|
|
|
2020-12-29 20:31:16 -05:00
|
|
|
void esp_newlib_init(void)
|
2016-10-25 10:12:07 -04:00
|
|
|
{
|
2020-12-29 20:31:16 -05:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
|
|
|
syscall_table_ptr_pro = syscall_table_ptr_app = &s_stub_table;
|
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
2016-10-25 10:12:07 -04:00
|
|
|
syscall_table_ptr_pro = &s_stub_table;
|
2021-06-10 07:47:41 -04:00
|
|
|
#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2
|
2020-12-29 20:31:16 -05:00
|
|
|
syscall_table_ptr = &s_stub_table;
|
2020-01-20 00:31:28 -05:00
|
|
|
#endif
|
2020-12-29 20:31:16 -05:00
|
|
|
|
2016-10-25 10:12:07 -04:00
|
|
|
_GLOBAL_REENT = &s_reent;
|
2020-12-29 20:31:16 -05:00
|
|
|
|
2016-10-25 10:12:07 -04:00
|
|
|
environ = malloc(sizeof(char*));
|
|
|
|
environ[0] = NULL;
|
2020-12-29 20:31:16 -05:00
|
|
|
|
|
|
|
esp_newlib_locks_init();
|
2016-10-25 10:12:07 -04:00
|
|
|
}
|
2020-12-29 20:31:16 -05:00
|
|
|
|
|
|
|
void esp_setup_newlib_syscalls(void) __attribute__((alias("esp_newlib_init")));
|