summaryrefslogtreecommitdiff
path: root/components/libc
diff options
context:
space:
mode:
author[email protected] <[email protected]>2012-11-22 03:39:22 +0000
committer[email protected] <[email protected]>2012-11-22 03:39:22 +0000
commit74bf69110ea5250a6ba795ab68ee067f19235150 (patch)
treee658bc4819565caeff06ee6e91f9f731b5e50c0c /components/libc
parent3968445d4a1ceece9cce84bd18ba56eeeb166a90 (diff)
add support of arm standard c library, support using armcc to compile lua
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2429 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/libc')
-rw-r--r--components/libc/armlibc/Sconscript16
-rw-r--r--components/libc/armlibc/mem_std.c19
-rw-r--r--components/libc/armlibc/stubs.c146
3 files changed, 181 insertions, 0 deletions
diff --git a/components/libc/armlibc/Sconscript b/components/libc/armlibc/Sconscript
new file mode 100644
index 0000000000..11aba6b4f8
--- /dev/null
+++ b/components/libc/armlibc/Sconscript
@@ -0,0 +1,16 @@
+Import('rtconfig')
+from building import *
+
+if GetDepend('RT_USING_ARM_LIBC') and rtconfig.CROSS_TOOL != 'keil':
+ print '================ERROR=============================='
+ print 'Please use ARM CC compiler if using ARM C library'
+ print '==================================================='
+ exit(0)
+
+cwd = GetCurrentDir()
+src = Glob('*.c')
+CPPPATH = [cwd]
+
+group = DefineGroup('libc', src, depend = ['RT_USING_ARM_LIBC'], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/libc/armlibc/mem_std.c b/components/libc/armlibc/mem_std.c
new file mode 100644
index 0000000000..7e9c036377
--- /dev/null
+++ b/components/libc/armlibc/mem_std.c
@@ -0,0 +1,19 @@
+
+#include "rtthread.h"
+
+#pragma import(__use_no_heap)
+
+void * malloc(int n)
+{
+ return rt_malloc(n);
+}
+
+void * realloc(void *rmem, rt_size_t newsize)
+{
+ return rt_realloc(rmem, newsize);
+}
+
+void free(void *rmem)
+{
+ rt_free(rmem);
+}
diff --git a/components/libc/armlibc/stubs.c b/components/libc/armlibc/stubs.c
new file mode 100644
index 0000000000..17be36ab20
--- /dev/null
+++ b/components/libc/armlibc/stubs.c
@@ -0,0 +1,146 @@
+/**
+ * reimplement arm c library's basic functions
+ */
+
+#include <string.h>
+#include <rt_sys.h>
+
+#include "rtthread.h"
+
+#pragma import(__use_no_semihosting_swi)
+
+int remove(const char *filename)
+{
+ RT_ASSERT(0);
+ for(;;);
+}
+
+/* rename() */
+
+int system(const char *string)
+{
+ RT_ASSERT(0);
+ for(;;);
+}
+
+/* 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";
+
+FILEHANDLE _sys_open(const char *name, int openmode)
+{
+ /* 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 0;
+#else
+ /* TODO: adjust open file mode */
+ return open(name, openmode, 0);
+#endif
+}
+
+int _sys_close(FILEHANDLE fh)
+{
+#ifndef RT_USING_DFS
+ return 0;
+#else
+ if (fh < 3)
+ return 0;
+
+ return close(fh);
+#endif
+}
+
+int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
+{
+ if (fh == STDIN)
+ {
+ /* TODO */
+
+ return 0;
+ }
+
+#ifndef RT_USING_DFS
+ return 0;
+#else
+ return read(fh, buf, len);
+#endif
+}
+
+int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
+{
+ if ((fh == STDOUT) || (fh == STDERR))
+ {
+#ifndef RT_USING_CONSOLE
+ return 0;
+#else
+ rt_device_t console_device;
+ extern rt_device_t rt_console_get_device(void);
+
+ console_device = rt_console_get_device();
+ if (console_device != 0) rt_device_write(console_device, 0, buf, len);
+ return len;
+#endif
+ }
+
+#ifndef RT_USING_DFS
+ return 0;
+#else
+ return write(fh, buf, len);
+#endif
+}
+
+int _sys_seek(FILEHANDLE fh, long pos)
+{
+#ifndef RT_USING_DFS
+ return 0;
+#else
+ /* TODO: adjust last parameter */
+ return lseek(fh, pos, 0);
+#endif
+}
+
+int _sys_tmpnam(char *name, int fileno, unsigned maxlength)
+{
+ return 0;
+}
+
+char *_sys_command_string(char *cmd, int len)
+{
+ return cmd;
+}
+
+void _ttywrch(int ch)
+{
+
+}
+
+void _sys_exit(int return_code)
+{
+ while (1);
+}
+
+long _sys_flen(FILEHANDLE fh)
+{
+ return 0;
+}
+
+int _sys_istty(FILEHANDLE fh)
+{
+ return 0;
+}
+
+
+