first
This commit is contained in:
8
rt-thread/components/libc/compilers/picolibc/README.md
Normal file
8
rt-thread/components/libc/compilers/picolibc/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# PICOLIBC (LLVM-ARM) porting for RT-Thread
|
||||
|
||||
https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm
|
||||
|
||||
https://github.com/picolibc/picolibc
|
||||
|
||||
|
||||
|
35
rt-thread/components/libc/compilers/picolibc/SConscript
Normal file
35
rt-thread/components/libc/compilers/picolibc/SConscript
Normal file
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
from building 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'):
|
||||
print('PicoLibc version: ' + picolibc_version)
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
CPPDEFINES = ['RT_USING_PICOLIBC', 'RT_USING_LIBC', '_POSIX_C_SOURCE=1', '__PICOLIBC_ERRNO_FUNCTION=pico_get_errno'] # identify this is Newlib, and only enable POSIX.1-1990
|
||||
# LIBS = ['c', 'm'] # link libc and libm
|
||||
AddDepend(['RT_USING_PICOLIBC', 'RT_USING_LIBC'])
|
||||
|
||||
group = group + DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)#, LIBS = LIBS)
|
||||
|
||||
list = os.listdir(cwd)
|
||||
for d in list:
|
||||
path = os.path.join(cwd, d)
|
||||
if os.path.isfile(os.path.join(path, 'SConscript')):
|
||||
group = group + SConscript(os.path.join(d, 'SConscript'))
|
||||
|
||||
Return('group')
|
19
rt-thread/components/libc/compilers/picolibc/exit.c
Normal file
19
rt-thread/components/libc/compilers/picolibc/exit.c
Normal file
@@ -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>
|
||||
#include <posix/stdlib.h>
|
||||
|
||||
/* for exit() and abort() */
|
||||
rt_noreturn void _exit (int status)
|
||||
{
|
||||
__rt_libc_exit(status);
|
||||
while(1);
|
||||
}
|
36
rt-thread/components/libc/compilers/picolibc/fcntl.h
Normal file
36
rt-thread/components/libc/compilers/picolibc/fcntl.h
Normal file
@@ -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
|
73
rt-thread/components/libc/compilers/picolibc/iob.c
Normal file
73
rt-thread/components/libc/compilers/picolibc/iob.c
Normal file
@@ -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
|
60
rt-thread/components/libc/compilers/picolibc/syscall.c
Normal file
60
rt-thread/components/libc/compilers/picolibc/syscall.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-05-17 Flybreak the first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* global errno */
|
||||
static volatile int __pico_errno;
|
||||
|
||||
int *pico_get_errno(void)
|
||||
{
|
||||
rt_thread_t tid = RT_NULL;
|
||||
|
||||
if (rt_interrupt_get_nest() != 0)
|
||||
{
|
||||
/* it's in interrupt context */
|
||||
return (int *)&__pico_errno;
|
||||
}
|
||||
|
||||
tid = rt_thread_self();
|
||||
if (tid == RT_NULL)
|
||||
{
|
||||
return (int *)&__pico_errno;
|
||||
}
|
||||
|
||||
return (int *)&tid->error;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
void *malloc(size_t n)
|
||||
{
|
||||
return rt_malloc(n);
|
||||
}
|
||||
RTM_EXPORT(malloc);
|
||||
|
||||
void *realloc(void *rmem, size_t newsize)
|
||||
{
|
||||
return rt_realloc(rmem, newsize);
|
||||
}
|
||||
RTM_EXPORT(realloc);
|
||||
|
||||
void *calloc(size_t nelem, size_t elsize)
|
||||
{
|
||||
return rt_calloc(nelem, elsize);
|
||||
}
|
||||
RTM_EXPORT(calloc);
|
||||
|
||||
void free(void *rmem)
|
||||
{
|
||||
rt_free(rmem);
|
||||
}
|
||||
RTM_EXPORT(free);
|
||||
#endif /* RT_USING_HEAP */
|
Reference in New Issue
Block a user