diff options
| author | Xiang.Lin <[email protected]> | 2023-11-08 15:09:09 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-08 02:09:09 -0500 |
| commit | da55491608e19c53d5260309a4fb2ccad930cc51 (patch) | |
| tree | 7f9c65b785c4850e314b60268ba11e8e33ad11ea /components | |
| parent | 063c8f7bec57ba63a038c1bad2fa9056fb0c5ac0 (diff) | |
[libc][picolibc] improve gcc picolibc support
Diffstat (limited to 'components')
| -rw-r--r-- | components/libc/compilers/picolibc/SConscript | 8 | ||||
| -rw-r--r-- | components/libc/compilers/picolibc/exit.c | 19 | ||||
| -rw-r--r-- | components/libc/compilers/picolibc/fcntl.h | 36 | ||||
| -rw-r--r-- | components/libc/compilers/picolibc/iob.c | 73 |
4 files changed, 135 insertions, 1 deletions
diff --git a/components/libc/compilers/picolibc/SConscript b/components/libc/compilers/picolibc/SConscript index 999f7cca56..c0de465a2f 100644 --- a/components/libc/compilers/picolibc/SConscript +++ b/components/libc/compilers/picolibc/SConscript @@ -1,10 +1,16 @@ import os from building import * -from llvm_arm import * Import('rtconfig') group = [] +if rtconfig.PLATFORM == 'gcc': + from gcc import * +elif rtconfig.PLATFORM == 'llvm-arm': + from llvm_arm import * +else: + Return('group') + picolibc_version = GetPicoLibcVersion(rtconfig) if picolibc_version and not GetDepend('RT_USING_EXTERNAL_LIBC'): diff --git a/components/libc/compilers/picolibc/exit.c b/components/libc/compilers/picolibc/exit.c new file mode 100644 index 0000000000..f3f3ce831a --- /dev/null +++ b/components/libc/compilers/picolibc/exit.c @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2006-2023, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + +#include <rtthread.h> +#include <sys/types.h> + +/* for exit() and abort() */ +rt_noreturn void _exit (int status) +{ + extern void __rt_libc_exit(int status); + __rt_libc_exit(status); + while(1); +} diff --git a/components/libc/compilers/picolibc/fcntl.h b/components/libc/compilers/picolibc/fcntl.h new file mode 100644 index 0000000000..ce8b621125 --- /dev/null +++ b/components/libc/compilers/picolibc/fcntl.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-09-02 Meco Man First version + */ + +#ifndef __FCNTL_H__ +#define __FCNTL_H__ + +#include <sys/_default_fcntl.h> + +#ifndef O_EXEC +#define O_EXEC 0x400000 +#endif + +#ifndef O_TMPFILE +#define O_TMPFILE 0x800000 +#endif + +#ifndef O_BINARY +#define O_BINARY 0x10000 +#endif + +#ifndef O_NOFOLLOW +#define O_NOFOLLOW 0x100000 +#endif + +#ifndef O_DIRECTORY +#define O_DIRECTORY 0x200000 +#endif + +#endif diff --git a/components/libc/compilers/picolibc/iob.c b/components/libc/compilers/picolibc/iob.c new file mode 100644 index 0000000000..a13eb3a0e4 --- /dev/null +++ b/components/libc/compilers/picolibc/iob.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2006-2023, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ + +#include <rtthread.h> +#include <sys/types.h> +#include <stdio.h> +#include <unistd.h> +#ifdef RT_USING_POSIX_STDIO +#include <posix/stdio.h> +#endif /* RT_USING_POSIX_STDIO */ +#define DBG_TAG "picolibc.iob" +#define DBG_LVL DBG_INFO +#include <rtdbg.h> + +#ifdef TINY_STDIO + +static int __fputc(char c, FILE *file); +static int __fgetc(FILE *file); + +static FILE __stdio_in = FDEV_SETUP_STREAM(NULL, __fgetc, NULL, _FDEV_SETUP_READ); +static FILE __stdio_out = FDEV_SETUP_STREAM(__fputc, NULL, NULL, _FDEV_SETUP_WRITE); + +#ifdef __strong_reference +#define STDIO_ALIAS(x) __strong_reference(stdout, x); +#else +#define STDIO_ALIAS(x) FILE *const x = &__stdio_out; +#endif + +FILE *const stdin = &__stdio_in; +FILE *const stdout = &__stdio_out; +STDIO_ALIAS(stderr); + +static int __fputc(char c, FILE *file) +{ + if (file == &__stdio_out) + { +#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) + rt_device_t console = rt_console_get_device(); + if (console) + { + rt_ssize_t rc = rt_device_write(console, -1, &c, 1); + return rc > 0 ? rc : -1; + } +#endif /* defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) */ + } + + return -1; +} + +static int __fgetc(FILE *file) +{ + if (file == &__stdio_in) + { +#ifdef RT_USING_POSIX_STDIO + if (rt_posix_stdio_get_console() >= 0) + { + char c; + int rc = read(STDIN_FILENO, &c, 1); + return rc == 1 ? c : EOF; + } +#endif /* RT_USING_POSIX_STDIO */ + } + + return EOF; +} + +#endif |
