mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-12-25 16:57:20 +00:00
[libc] Change libc stubs to compiler folder.
This commit is contained in:
12
components/libc/compilers/armlibc/SConscript
Normal file
12
components/libc/compilers/armlibc/SConscript
Normal file
@@ -0,0 +1,12 @@
|
||||
from building import *
|
||||
|
||||
src = Glob('*.c')
|
||||
cwd = GetCurrentDir()
|
||||
|
||||
CPPPATH = [cwd]
|
||||
CPPDEFINES = ['RT_USING_ARM_LIBC']
|
||||
|
||||
group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
|
||||
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
|
||||
|
||||
Return('group')
|
||||
8
components/libc/compilers/armlibc/fcntl.h
Normal file
8
components/libc/compilers/armlibc/fcntl.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef FCNTL_H__
|
||||
#define FCNTL_H__
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_posix.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
41
components/libc/compilers/armlibc/libc_syms.c
Normal file
41
components/libc/compilers/armlibc/libc_syms.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <rtm.h>
|
||||
|
||||
/* some export routines for module */
|
||||
|
||||
RTM_EXPORT(strstr);
|
||||
RTM_EXPORT(strlen);
|
||||
RTM_EXPORT(strchr);
|
||||
RTM_EXPORT(strcpy);
|
||||
RTM_EXPORT(strncpy);
|
||||
RTM_EXPORT(strcmp);
|
||||
RTM_EXPORT(strncmp);
|
||||
RTM_EXPORT(strcat);
|
||||
RTM_EXPORT(strtol);
|
||||
|
||||
RTM_EXPORT(memcpy);
|
||||
RTM_EXPORT(memcmp);
|
||||
RTM_EXPORT(memmove);
|
||||
RTM_EXPORT(memset);
|
||||
RTM_EXPORT(memchr);
|
||||
|
||||
RTM_EXPORT(toupper);
|
||||
RTM_EXPORT(atoi);
|
||||
|
||||
#ifdef RT_USING_RTC
|
||||
RTM_EXPORT(localtime);
|
||||
RTM_EXPORT(time);
|
||||
#endif
|
||||
|
||||
/* import the full stdio for printf */
|
||||
#if defined(RT_USING_MODULE) && defined(__MICROLIB)
|
||||
#error "[RT_USING_LIBC] Please use standard libc but not microlib."
|
||||
#endif
|
||||
|
||||
RTM_EXPORT(puts);
|
||||
RTM_EXPORT(printf);
|
||||
43
components/libc/compilers/armlibc/mem_std.c
Normal file
43
components/libc/compilers/armlibc/mem_std.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* File : mem_std.c
|
||||
* Brief : implement standard memory routins.
|
||||
*
|
||||
* This file is part of Device File System in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2014, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE.
|
||||
*
|
||||
* Change Logs:
|
||||
* 2014-08-03 bernard Add file header.
|
||||
*/
|
||||
|
||||
#include "rtthread.h"
|
||||
|
||||
/* avoid the heap and heap-using library functions supplied by arm */
|
||||
#pragma import(__use_no_heap)
|
||||
|
||||
void *malloc(int n)
|
||||
{
|
||||
return rt_malloc(n);
|
||||
}
|
||||
RTM_EXPORT(malloc);
|
||||
|
||||
void *realloc(void *rmem, rt_size_t newsize)
|
||||
{
|
||||
return rt_realloc(rmem, newsize);
|
||||
}
|
||||
RTM_EXPORT(realloc);
|
||||
|
||||
void *calloc(rt_size_t nelem, rt_size_t elsize)
|
||||
{
|
||||
return rt_calloc(nelem, elsize);
|
||||
}
|
||||
RTM_EXPORT(calloc);
|
||||
|
||||
void free(void *rmem)
|
||||
{
|
||||
rt_free(rmem);
|
||||
}
|
||||
RTM_EXPORT(free);
|
||||
291
components/libc/compilers/armlibc/stubs.c
Normal file
291
components/libc/compilers/armlibc/stubs.c
Normal file
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* File : stubs.c
|
||||
* Brief : reimplement some basic functions of arm standard c library
|
||||
*
|
||||
* This file is part of Device File System in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-11-23 Yihui The first version
|
||||
* 2013-11-24 aozima fixed _sys_read()/_sys_write() issues.
|
||||
* 2014-08-03 bernard If using msh, use system() implementation
|
||||
* in msh.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <rt_sys.h>
|
||||
|
||||
#include "rtthread.h"
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
#include "dfs_posix.h"
|
||||
#endif
|
||||
|
||||
#pragma import(__use_no_semihosting_swi)
|
||||
|
||||
/* TODO: Standard IO device handles. */
|
||||
#define STDIN 1
|
||||
#define STDOUT 2
|
||||
#define STDERR 3
|
||||
|
||||
/* Standard IO device name defines. */
|
||||
const char __stdin_name[] = "STDIN";
|
||||
const char __stdout_name[] = "STDOUT";
|
||||
const char __stderr_name[] = "STDERR";
|
||||
|
||||
/**
|
||||
* required by fopen() and freopen().
|
||||
*
|
||||
* @param name - file name with path.
|
||||
* @param openmode - a bitmap hose bits mostly correspond directly to
|
||||
* the ISO mode specification.
|
||||
* @return -1 if an error occurs.
|
||||
*/
|
||||
FILEHANDLE _sys_open(const char *name, int openmode)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
int fd;
|
||||
int mode = O_RDONLY;
|
||||
#endif
|
||||
|
||||
/* Register standard Input Output devices. */
|
||||
if (strcmp(name, __stdin_name) == 0)
|
||||
return (STDIN);
|
||||
if (strcmp(name, __stdout_name) == 0)
|
||||
return (STDOUT);
|
||||
if (strcmp(name, __stderr_name) == 0)
|
||||
return (STDERR);
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return -1;
|
||||
#else
|
||||
/* Correct openmode from fopen to open */
|
||||
if (openmode & OPEN_PLUS)
|
||||
{
|
||||
if (openmode & OPEN_W)
|
||||
{
|
||||
mode |= (O_RDWR | O_TRUNC | O_CREAT);
|
||||
}
|
||||
else if (openmode & OPEN_A)
|
||||
{
|
||||
mode |= (O_RDWR | O_APPEND | O_CREAT);
|
||||
}
|
||||
else
|
||||
mode |= O_RDWR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (openmode & OPEN_W)
|
||||
{
|
||||
mode |= (O_WRONLY | O_TRUNC | O_CREAT);
|
||||
}
|
||||
else if (openmode & OPEN_A)
|
||||
{
|
||||
mode |= (O_WRONLY | O_APPEND | O_CREAT);
|
||||
}
|
||||
}
|
||||
|
||||
fd = open(name, mode, 0);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
else
|
||||
return fd + STDERR + 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int _sys_close(FILEHANDLE fh)
|
||||
{
|
||||
#ifndef RT_USING_DFS
|
||||
return 0;
|
||||
#else
|
||||
if (fh < STDERR)
|
||||
return 0;
|
||||
|
||||
return close(fh - STDERR - 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* read data
|
||||
*
|
||||
* @param fh - file handle
|
||||
* @param buf - buffer to save read data
|
||||
* @param len - max length of data buffer
|
||||
* @param mode - useless, for historical reasons
|
||||
* @return The number of bytes not read.
|
||||
*/
|
||||
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
int size;
|
||||
#endif
|
||||
|
||||
if (fh == STDIN)
|
||||
{
|
||||
/* TODO */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((fh == STDOUT) || (fh == STDERR))
|
||||
return -1;
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return 0;
|
||||
#else
|
||||
size = read(fh - STDERR - 1, buf, len);
|
||||
if (size >= 0)
|
||||
return len - size;
|
||||
else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* write data
|
||||
*
|
||||
* @param fh - file handle
|
||||
* @param buf - data buffer
|
||||
* @param len - buffer length
|
||||
* @param mode - useless, for historical reasons
|
||||
* @return a positive number representing the number of characters not written.
|
||||
*/
|
||||
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
int size;
|
||||
#endif
|
||||
|
||||
if ((fh == STDOUT) || (fh == STDERR))
|
||||
{
|
||||
#ifndef RT_USING_CONSOLE
|
||||
return 0;
|
||||
#else
|
||||
rt_device_t console_device;
|
||||
|
||||
console_device = rt_console_get_device();
|
||||
if (console_device != 0) rt_device_write(console_device, 0, buf, len);
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (fh == STDIN)
|
||||
return -1;
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return 0;
|
||||
#else
|
||||
size = write(fh - STDERR - 1, buf, len);
|
||||
if (size >= 0)
|
||||
return len - size;
|
||||
else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* put he file pointer at offset pos from the beginning of the file.
|
||||
*
|
||||
* @param pos - offset
|
||||
* @return the current file position, or -1 on failed
|
||||
*/
|
||||
int _sys_seek(FILEHANDLE fh, long pos)
|
||||
{
|
||||
if (fh < STDERR)
|
||||
return -1;
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return -1;
|
||||
#else
|
||||
|
||||
/* position is relative to the start of file fh */
|
||||
return lseek(fh - STDERR - 1, pos, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* used by tmpnam() or tmpfile()
|
||||
*/
|
||||
int _sys_tmpnam(char *name, int fileno, unsigned maxlength)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *_sys_command_string(char *cmd, int len)
|
||||
{
|
||||
/* no support */
|
||||
return cmd;
|
||||
}
|
||||
|
||||
/* This function writes a character to the console. */
|
||||
void _ttywrch(int ch)
|
||||
{
|
||||
#ifdef RT_USING_CONSOLE
|
||||
char c;
|
||||
|
||||
c = (char)ch;
|
||||
rt_kprintf(&c);
|
||||
#endif
|
||||
}
|
||||
|
||||
void _sys_exit(int return_code)
|
||||
{
|
||||
/* TODO: perhaps exit the thread which is invoking this function */
|
||||
while (1);
|
||||
}
|
||||
|
||||
/**
|
||||
* return current length of file.
|
||||
*
|
||||
* @param fh - file handle
|
||||
* @return file length, or -1 on failed
|
||||
*/
|
||||
long _sys_flen(FILEHANDLE fh)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _sys_istty(FILEHANDLE fh)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int remove(const char *filename)
|
||||
{
|
||||
#ifndef RT_USING_DFS
|
||||
return -1;
|
||||
#else
|
||||
return unlink(filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS)
|
||||
/* use system(const char *string) implementation in the msh */
|
||||
#else
|
||||
int system(const char *string)
|
||||
{
|
||||
RT_ASSERT(0);
|
||||
for (;;);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __MICROLIB
|
||||
#include <stdio.h>
|
||||
|
||||
int fputc(int c, FILE *f)
|
||||
{
|
||||
char ch = c;
|
||||
|
||||
rt_kprintf(&ch);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fgetc(FILE *f) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
1
components/libc/compilers/armlibc/sys/README.md
Normal file
1
components/libc/compilers/armlibc/sys/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Because Keil MDK leaks some system header file, we put them in here.
|
||||
80
components/libc/compilers/armlibc/sys/errno.h
Normal file
80
components/libc/compilers/armlibc/sys/errno.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#ifndef SYS_ERRNO_H__
|
||||
#define SYS_ERRNO_H__
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
|
||||
#include <dfs_def.h>
|
||||
|
||||
/* using device error codes */
|
||||
#define ENOENT DFS_STATUS_ENOENT
|
||||
#define EIO DFS_STATUS_EIO
|
||||
#define ENXIO DFS_STATUS_ENXIO
|
||||
#define EBADF DFS_STATUS_EBADF
|
||||
#define EAGAIN DFS_STATUS_EAGAIN
|
||||
#define ENOMEM DFS_STATUS_ENOMEM
|
||||
#define EBUSY DFS_STATUS_EBUSY
|
||||
#define EEXIST DFS_STATUS_EEXIST
|
||||
#define EXDEV DFS_STATUS_EXDEV
|
||||
#define ENODEV DFS_STATUS_ENODEV
|
||||
#define ENOTDIR DFS_STATUS_ENOTDIR
|
||||
#define EISDIR DFS_STATUS_EISDIR
|
||||
#define EINVAL DFS_STATUS_EINVAL
|
||||
#define ENOSPC DFS_STATUS_ENOSPC
|
||||
#define EROFS DFS_STATUS_EROFS
|
||||
#define ENOSYS DFS_STATUS_ENOSYS
|
||||
#define ENOTEMPTY DFS_STATUS_ENOTEMPTY
|
||||
|
||||
#else
|
||||
|
||||
/* error codes */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define EBADF 9 /* Bad file number */
|
||||
#define EAGAIN 11 /* Try again */
|
||||
#define ENOMEM 12 /* no memory */
|
||||
#define EBUSY 16 /* Device or resource busy */
|
||||
#define EEXIST 17 /* File exists */
|
||||
#define EXDEV 18 /* Cross-device link */
|
||||
#define ENODEV 19 /* No such device */
|
||||
#define ENOTDIR 20 /* Not a directory */
|
||||
#define EISDIR 21 /* Is a directory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#define EROFS 30 /* Read-only file system */
|
||||
#define ENOSYS 38 /* Function not implemented */
|
||||
#define ENOTEMPTY 39 /* Directory not empty */
|
||||
|
||||
#endif
|
||||
|
||||
#define EPERM 1 /* Not super-user */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EFAULT 14 /* Bad address */
|
||||
#define ENFILE 23 /* Too many open files in system */
|
||||
#define ERANGE 34 /* Math result not representable */
|
||||
#define EDEADLK 45 /* Deadlock condition */
|
||||
#define EBADMSG 77 /* Trying to read unreadable message */
|
||||
#define EMSGSIZE 90 /* Message too long */
|
||||
#define ENOPROTOOPT 92 /* Protocol not available */
|
||||
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
|
||||
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
|
||||
#define EADDRINUSE 98 /* Address already in use */
|
||||
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
|
||||
#define ENETDOWN 100 /* Network is down */
|
||||
#define ENETUNREACH 101 /* Network is unreachable */
|
||||
#define ECONNABORTED 103 /* Software caused connection abort */
|
||||
#define ECONNRESET 104 /* Connection reset by peer */
|
||||
#define ENOBUFS 105 /* No buffer space available */
|
||||
#define EISCONN 106 /* Transport endpoint is already connected */
|
||||
#define ENOTCONN 107 /* Transport endpoint is not connected */
|
||||
#define EINPROGRESS 115 /* Operation now in progress */
|
||||
#define ETIMEDOUT 116 /* Connection timed out */
|
||||
#define EHOSTUNREACH 113 /* No route to host */
|
||||
#define EALREADY 114 /* Operation already in progress */
|
||||
#define ENOTSUP 134 /* Not supported */
|
||||
#define ENSRNOTFOUND 163 /* Domain name not found */
|
||||
#define EWOULDBLOCK EAGAIN /* Operation would block */
|
||||
|
||||
#endif
|
||||
0
components/libc/compilers/armlibc/sys/stat.h
Normal file
0
components/libc/compilers/armlibc/sys/stat.h
Normal file
45
components/libc/compilers/armlibc/sys/time.h
Normal file
45
components/libc/compilers/armlibc/sys/time.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef _SYS_TIME_H_
|
||||
#define _SYS_TIME_H_
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _TIMEVAL_DEFINED
|
||||
#define _TIMEVAL_DEFINED
|
||||
/*
|
||||
* Structure returned by gettimeofday(2) system call,
|
||||
* and used in other calls.
|
||||
*/
|
||||
struct timeval {
|
||||
long tv_sec; /* seconds */
|
||||
long tv_usec; /* and microseconds */
|
||||
};
|
||||
#endif /* _TIMEVAL_DEFINED */
|
||||
|
||||
#ifndef _TIMESPEC_DEFINED
|
||||
#define _TIMESPEC_DEFINED
|
||||
/*
|
||||
* Structure defined by POSIX.1b to be like a timeval.
|
||||
*/
|
||||
struct timespec {
|
||||
time_t tv_sec; /* seconds */
|
||||
long tv_nsec; /* and nanoseconds */
|
||||
};
|
||||
#endif /* _TIMESPEC_DEFINED */
|
||||
|
||||
struct timezone {
|
||||
int tz_minuteswest; /* minutes west of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
|
||||
int gettimeofday(struct timeval *tp, void *ignore);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_TIME_H_ */
|
||||
14
components/libc/compilers/armlibc/sys/types.h
Normal file
14
components/libc/compilers/armlibc/sys/types.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __TYPES_H__
|
||||
#define __TYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
typedef rt_int32_t clockid_t;
|
||||
typedef rt_int32_t key_t; /* Used for interprocess communication. */
|
||||
typedef rt_int32_t pid_t; /* Used for process IDs and process group IDs. */
|
||||
typedef signed long ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
|
||||
typedef int mode_t;
|
||||
|
||||
#endif
|
||||
36
components/libc/compilers/armlibc/sys/unistd.h
Normal file
36
components/libc/compilers/armlibc/sys/unistd.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef _SYS_UNISTD_H
|
||||
#define _SYS_UNISTD_H
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_posix.h>
|
||||
#else
|
||||
#define _FREAD 0x0001 /* read enabled */
|
||||
#define _FWRITE 0x0002 /* write enabled */
|
||||
#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */
|
||||
#define _FMARK 0x0010 /* internal; mark during gc() */
|
||||
#define _FDEFER 0x0020 /* internal; defer for next gc pass */
|
||||
#define _FASYNC 0x0040 /* signal pgrp when data ready */
|
||||
#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */
|
||||
#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */
|
||||
#define _FCREAT 0x0200 /* open with file create */
|
||||
#define _FTRUNC 0x0400 /* open with truncation */
|
||||
#define _FEXCL 0x0800 /* error on open if file exists */
|
||||
#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */
|
||||
#define _FSYNC 0x2000 /* do all writes synchronously */
|
||||
#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
|
||||
#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */
|
||||
#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */
|
||||
|
||||
#define O_RDONLY 0 /* +1 == FREAD */
|
||||
#define O_WRONLY 1 /* +1 == FWRITE */
|
||||
#define O_RDWR 2 /* +1 == FREAD|FWRITE */
|
||||
#define O_APPEND _FAPPEND
|
||||
#define O_CREAT _FCREAT
|
||||
#define O_TRUNC _FTRUNC
|
||||
#define O_EXCL _FEXCL
|
||||
#define O_SYNC _FSYNC
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_UNISTD_H */
|
||||
1
components/libc/compilers/armlibc/unistd.h
Normal file
1
components/libc/compilers/armlibc/unistd.h
Normal file
@@ -0,0 +1 @@
|
||||
#include "sys/unistd.h"
|
||||
Reference in New Issue
Block a user