summaryrefslogtreecommitdiff
path: root/components/libc/compilers/armlibc
diff options
context:
space:
mode:
authorguo <[email protected]>2021-09-28 10:36:54 +0800
committerGitHub <[email protected]>2021-09-28 10:36:54 +0800
commit55a302cd092758a44b589d65470a69d9e8ae4ced (patch)
treee60fc53994c426007e9eb4877e5bd123f124ef39 /components/libc/compilers/armlibc
parent00727d6b6db92dc1cf98f028f26fd6168594b905 (diff)
parent00d42ef73cff61ecda7ff006b077a73e1a4ff669 (diff)
Merge branch 'master' into usbh_construct
Diffstat (limited to 'components/libc/compilers/armlibc')
-rw-r--r--components/libc/compilers/armlibc/dirent.h62
-rw-r--r--components/libc/compilers/armlibc/fcntl.h18
-rw-r--r--components/libc/compilers/armlibc/libc.c7
-rw-r--r--components/libc/compilers/armlibc/libc.h11
-rw-r--r--components/libc/compilers/armlibc/libc_syms.c2
-rw-r--r--components/libc/compilers/armlibc/mem_std.c5
-rw-r--r--components/libc/compilers/armlibc/stdio.c28
-rw-r--r--components/libc/compilers/armlibc/sys/README.md1
-rw-r--r--components/libc/compilers/armlibc/sys/errno.h14
-rw-r--r--components/libc/compilers/armlibc/sys/ioctl.h15
-rw-r--r--components/libc/compilers/armlibc/sys/mman.h58
-rw-r--r--components/libc/compilers/armlibc/sys/stat.h8
-rw-r--r--components/libc/compilers/armlibc/sys/types.h28
-rw-r--r--components/libc/compilers/armlibc/sys/unistd.h83
-rw-r--r--components/libc/compilers/armlibc/syscalls.c39
-rw-r--r--components/libc/compilers/armlibc/unistd.h10
16 files changed, 40 insertions, 349 deletions
diff --git a/components/libc/compilers/armlibc/dirent.h b/components/libc/compilers/armlibc/dirent.h
deleted file mode 100644
index d3bc58cbc5..0000000000
--- a/components/libc/compilers/armlibc/dirent.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef __RTT_DIRENT_H__
-#define __RTT_DIRENT_H__
-
-#include <rtthread.h>
-#include <rtlibc.h>
-
-/*
-* dirent.h - format of directory entries
- * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
- */
-
-/* File types */
-#define FT_REGULAR 0 /* regular file */
-#define FT_SOCKET 1 /* socket file */
-#define FT_DIRECTORY 2 /* directory */
-#define FT_USER 3 /* user defined */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef HAVE_DIR_STRUCTURE
-typedef struct
-{
- int fd; /* directory file */
- char buf[512];
- int num;
- int cur;
-} DIR;
-#endif
-
-#ifndef HAVE_DIRENT_STRUCTURE
-struct dirent
-{
- rt_uint8_t d_type; /* The type of the file */
- rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
- rt_uint16_t d_reclen; /* length of this record */
- char d_name[256]; /* The null-terminated file name */
-};
-#endif
-
-int closedir(DIR *);
-DIR *opendir(const char *);
-struct dirent *readdir(DIR *);
-int readdir_r(DIR *, struct dirent *, struct dirent **);
-void rewinddir(DIR *);
-void seekdir(DIR *, long int);
-long telldir(DIR *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/libc/compilers/armlibc/fcntl.h b/components/libc/compilers/armlibc/fcntl.h
deleted file mode 100644
index 3e650a8471..0000000000
--- a/components/libc/compilers/armlibc/fcntl.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef FCNTL_H__
-#define FCNTL_H__
-
-#include <rtconfig.h>
-
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
-
-#endif
diff --git a/components/libc/compilers/armlibc/libc.c b/components/libc/compilers/armlibc/libc.c
index fee390d4b4..889c687309 100644
--- a/components/libc/compilers/armlibc/libc.c
+++ b/components/libc/compilers/armlibc/libc.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,11 +7,8 @@
* Date Author Notes
* 2017/10/15 bernard the first version
*/
-#include <stdio.h>
-#include <stdlib.h>
-
+#include <fcntl.h>
#include <rtthread.h>
-
#include "libc.h"
#ifdef RT_USING_PTHREADS
diff --git a/components/libc/compilers/armlibc/libc.h b/components/libc/compilers/armlibc/libc.h
index b9b1b6212d..5c1613728e 100644
--- a/components/libc/compilers/armlibc/libc.h
+++ b/components/libc/compilers/armlibc/libc.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -10,17 +10,14 @@
#ifndef __RTT_LIBC_H__
#define __RTT_LIBC_H__
-#include <stddef.h>
-
#ifdef __cplusplus
extern "C" {
#endif
-int libc_system_init(void);
-int libc_stdio_set_console(const char* device_name, int mode);
+int libc_system_init(void);
int libc_stdio_get_console(void);
-int libc_stdio_read(void* buffer, size_t size);
-int libc_stdio_write(const void* buffer, size_t size);
+int libc_stdio_set_console(const char* device_name, int mode);
+
#ifdef __cplusplus
}
#endif
diff --git a/components/libc/compilers/armlibc/libc_syms.c b/components/libc/compilers/armlibc/libc_syms.c
index a2e8af17f1..829d57b559 100644
--- a/components/libc/compilers/armlibc/libc_syms.c
+++ b/components/libc/compilers/armlibc/libc_syms.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/libc/compilers/armlibc/mem_std.c b/components/libc/compilers/armlibc/mem_std.c
index e160104a25..fbfd17eee1 100644
--- a/components/libc/compilers/armlibc/mem_std.c
+++ b/components/libc/compilers/armlibc/mem_std.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -7,7 +7,8 @@
* 2014-08-03 bernard Add file header.
*/
-#include "rtthread.h"
+#include <rtthread.h>
+#include <stddef.h>
#ifdef RT_USING_HEAP
diff --git a/components/libc/compilers/armlibc/stdio.c b/components/libc/compilers/armlibc/stdio.c
index 5262a4dd92..7dd9dbfe3f 100644
--- a/components/libc/compilers/armlibc/stdio.c
+++ b/components/libc/compilers/armlibc/stdio.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -21,6 +21,7 @@
#define STDIO_DEVICE_NAME_MAX 32
static int std_fd = -1;
+
int libc_stdio_set_console(const char* device_name, int mode)
{
int fd;
@@ -47,29 +48,4 @@ int libc_stdio_get_console(void)
return std_fd;
}
-int libc_stdio_read(void *buffer, size_t size)
-{
- if (std_fd >= 0)
- {
- return read(std_fd, buffer, size);
- }
- else
- {
- rt_kprintf("Illegal stdio input!\n");
- return 0;
- }
-}
-
-int libc_stdio_write(const void *buffer, size_t size)
-{
- if (std_fd >= 0)
- {
- return write(std_fd, buffer, size);
- }
- else
- {
- rt_kprintf("Illegal stdio output!\n");
- return size;
- }
-}
#endif
diff --git a/components/libc/compilers/armlibc/sys/README.md b/components/libc/compilers/armlibc/sys/README.md
deleted file mode 100644
index 7ad10a7d43..0000000000
--- a/components/libc/compilers/armlibc/sys/README.md
+++ /dev/null
@@ -1 +0,0 @@
-Because Keil MDK leaks some system header file, we put them in here. \ No newline at end of file
diff --git a/components/libc/compilers/armlibc/sys/errno.h b/components/libc/compilers/armlibc/sys/errno.h
deleted file mode 100644
index 9c4307ebfb..0000000000
--- a/components/libc/compilers/armlibc/sys/errno.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#ifndef SYS_ERRNO_H__
-#define SYS_ERRNO_H__
-
-#include <rtthread.h>
-
-#endif
diff --git a/components/libc/compilers/armlibc/sys/ioctl.h b/components/libc/compilers/armlibc/sys/ioctl.h
deleted file mode 100644
index 033a57014a..0000000000
--- a/components/libc/compilers/armlibc/sys/ioctl.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-09-01 Meco Man First Version
- */
-#ifndef _SYS_IOCTL_H
-#define _SYS_IOCTL_H
-
-
-
-#endif
diff --git a/components/libc/compilers/armlibc/sys/mman.h b/components/libc/compilers/armlibc/sys/mman.h
deleted file mode 100644
index 8c61b32b7c..0000000000
--- a/components/libc/compilers/armlibc/sys/mman.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017/11/30 Bernard The first version.
- */
-
-#ifndef _SYS_MMAN_H
-#define _SYS_MMAN_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAP_FAILED ((void *) -1)
-
-#define MAP_SHARED 0x01
-#define MAP_PRIVATE 0x02
-#define MAP_TYPE 0x0f
-#define MAP_FIXED 0x10
-#define MAP_ANON 0x20
-#define MAP_ANONYMOUS MAP_ANON
-#define MAP_NORESERVE 0x4000
-#define MAP_GROWSDOWN 0x0100
-#define MAP_DENYWRITE 0x0800
-#define MAP_EXECUTABLE 0x1000
-#define MAP_LOCKED 0x2000
-#define MAP_POPULATE 0x8000
-#define MAP_NONBLOCK 0x10000
-#define MAP_STACK 0x20000
-#define MAP_HUGETLB 0x40000
-#define MAP_FILE 0
-
-#define PROT_NONE 0
-#define PROT_READ 1
-#define PROT_WRITE 2
-#define PROT_EXEC 4
-#define PROT_GROWSDOWN 0x01000000
-#define PROT_GROWSUP 0x02000000
-
-#define MS_ASYNC 1
-#define MS_INVALIDATE 2
-#define MS_SYNC 4
-
-#define MCL_CURRENT 1
-#define MCL_FUTURE 2
-#define MCL_ONFAULT 4
-
-void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
-int munmap (void *start, size_t len);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/components/libc/compilers/armlibc/sys/stat.h b/components/libc/compilers/armlibc/sys/stat.h
deleted file mode 100644
index ce95230e88..0000000000
--- a/components/libc/compilers/armlibc/sys/stat.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
diff --git a/components/libc/compilers/armlibc/sys/types.h b/components/libc/compilers/armlibc/sys/types.h
deleted file mode 100644
index d1e457b36f..0000000000
--- a/components/libc/compilers/armlibc/sys/types.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-09-05 Meco Man fix bugs
- * 2020-12-16 Meco Man add useconds_t
- */
-#ifndef __TYPES_H__
-#define __TYPES_H__
-
-#include <stdint.h>
-
-typedef int32_t clockid_t;
-typedef int32_t key_t; /* Used for interprocess communication. */
-typedef int pid_t; /* Used for process IDs and process group IDs. */
-typedef unsigned short uid_t;
-typedef unsigned short gid_t;
-#ifndef ARCH_CPU_64BIT
-typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
-#else
-typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
-#endif
-typedef unsigned long useconds_t; /* microseconds (unsigned) */
-
-#endif
diff --git a/components/libc/compilers/armlibc/sys/unistd.h b/components/libc/compilers/armlibc/sys/unistd.h
deleted file mode 100644
index ee1e1c4db9..0000000000
--- a/components/libc/compilers/armlibc/sys/unistd.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-12-16 Meco Man add usleep
- */
-#ifndef _SYS_UNISTD_H
-#define _SYS_UNISTD_H
-
-#include <rtconfig.h>
-#include "types.h"
-
-#ifdef RT_USING_DFS
-
-#define STDIN_FILENO 0 /* standard input file descriptor */
-#define STDOUT_FILENO 1 /* standard output file descriptor */
-#define STDERR_FILENO 2 /* standard error file descriptor */
-
-#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 */
-
-
-#ifndef O_RDONLY
-#define O_RDONLY 0 /* +1 == FREAD */
-#endif
-#ifndef O_WRONLY
-#define O_WRONLY 1 /* +1 == FWRITE */
-#endif
-#ifndef O_RDWR
-#define O_RDWR 2 /* +1 == FREAD|FWRITE */
-#endif
-#ifndef O_APPEND
-#define O_APPEND _FAPPEND
-#endif
-#ifndef O_CREAT
-#define O_CREAT _FCREAT
-#endif
-#ifndef O_TRUNC
-#define O_TRUNC _FTRUNC
-#endif
-#ifndef O_EXCL
-#define O_EXCL _FEXCL
-#endif
-#ifndef O_SYNC
-#define O_SYNC _FSYNC
-#endif
-
-#endif
-
-
-int isatty (int fd);
-char * ttyname (int desc);
-
-unsigned int sleep(unsigned int seconds);
-int usleep(useconds_t usec);
-
-pid_t getpid(void);
-pid_t getppid(void);
-uid_t getuid(void);
-uid_t geteuid(void);
-gid_t getgid(void);
-gid_t getegid(void);
-
-#endif /* _SYS_UNISTD_H */
diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c
index d17460b413..7d8ec2e8b4 100644
--- a/components/libc/compilers/armlibc/syscalls.c
+++ b/components/libc/compilers/armlibc/syscalls.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -9,7 +9,7 @@
* 2013-11-24 aozima fixed _sys_read()/_sys_write() issues.
* 2014-08-03 bernard If using msh, use system() implementation
* in msh.
- * 2020-08-05 Meco Man fixed _sys_flen() compiling-warning when
+ * 2020-08-05 Meco Man fixed _sys_flen() compiling-warning when
* RT_USING_DFS is not defined
* 2020-02-13 Meco Man re-implement exit() and abort()
* 2020-02-14 Meco Man implement _sys_tmpnam()
@@ -25,6 +25,10 @@
#include <dfs_posix.h>
#endif
+#define DBG_TAG "armlibc.syscalls"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
#ifdef __CLANG_ARM
__asm(".global __use_no_semihosting\n\t");
#else
@@ -146,16 +150,22 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
if (fh == STDIN)
{
#ifdef RT_USING_POSIX
- size = libc_stdio_read(buf, len);
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard output before initializing libc");
+ return 0;
+ }
+ size = read(STDIN_FILENO, buf, len);
return len - size;
#else
/* no stdin */
return -1;
#endif
}
-
- if ((fh == STDOUT) || (fh == STDERR))
+ else if ((fh == STDOUT) || (fh == STDERR))
+ {
return -1;
+ }
#ifndef RT_USING_DFS
return 0;
@@ -185,7 +195,12 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
return 0;
#else
#ifdef RT_USING_POSIX
- size = libc_stdio_write(buf, len);
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard input before initializing libc");
+ return 0;
+ }
+ size = write(STDOUT_FILENO, buf, len);
return len - size;
#else
if (rt_console_get_device())
@@ -198,8 +213,10 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
#endif
#endif
}
-
- if (fh == STDIN) return -1;
+ else if (fh == STDIN)
+ {
+ return -1;
+ }
#ifndef RT_USING_DFS
return 0;
@@ -302,7 +319,7 @@ int remove(const char *filename)
#endif
}
-#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS)
+#if defined(RT_USING_FINSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS)
/* use system(const char *string) implementation in the msh */
#else
int system(const char *string)
@@ -315,7 +332,7 @@ int system(const char *string)
#ifdef __MICROLIB
#include <stdio.h>
-int fputc(int c, FILE *f)
+int fputc(int c, FILE *f)
{
char ch[2] = {0};
@@ -324,7 +341,7 @@ int fputc(int c, FILE *f)
return 1;
}
-int fgetc(FILE *f)
+int fgetc(FILE *f)
{
#ifdef RT_USING_POSIX
char ch;
diff --git a/components/libc/compilers/armlibc/unistd.h b/components/libc/compilers/armlibc/unistd.h
deleted file mode 100644
index 736fc219a8..0000000000
--- a/components/libc/compilers/armlibc/unistd.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- */
-#include "sys/unistd.h"
-