From 2c885336592b747fbad13c23c656934ec2913f72 Mon Sep 17 00:00:00 2001 From: bernard Date: Sat, 31 Jan 2015 21:59:58 +0800 Subject: [PATCH] [LIBC] fix compiling issue for dlib (IAR). --- components/libc/SConscript | 2 + components/libc/dlib/SConscript | 2 +- components/libc/dlib/rmtx.c | 1 + components/libc/dlib/syscall_close.c | 43 +++++++++ .../libc/dlib/{syscalls.c => syscall_lseek.c} | 37 ++----- components/libc/dlib/syscall_mem.c | 44 +++++++++ components/libc/dlib/syscall_open.c | 96 ++++++++++++------- components/libc/dlib/syscall_read.c | 6 +- components/libc/dlib/syscall_remove.c | 38 ++++++++ components/libc/dlib/syscall_write.c | 7 +- 10 files changed, 204 insertions(+), 72 deletions(-) create mode 100644 components/libc/dlib/syscall_close.c rename components/libc/dlib/{syscalls.c => syscall_lseek.c} (74%) create mode 100644 components/libc/dlib/syscall_mem.c create mode 100644 components/libc/dlib/syscall_remove.c diff --git a/components/libc/SConscript b/components/libc/SConscript index 799ecccb36..4ca00c5b86 100644 --- a/components/libc/SConscript +++ b/components/libc/SConscript @@ -11,6 +11,8 @@ if GetDepend('RT_USING_LIBC'): objs = objs + SConscript('newlib/SConscript') elif rtconfig.PLATFORM == 'armcc': objs = objs + SConscript('armlibc/SConscript') + elif rtconfig.PLATFORM == 'iar': + objs = objs + SConscript('dlib/SConscript') else: if rtconfig.PLATFORM == 'gcc': objs = objs + SConscript('minilibc/SConscript') diff --git a/components/libc/dlib/SConscript b/components/libc/dlib/SConscript index f0e53a9f3e..a6b7554a07 100644 --- a/components/libc/dlib/SConscript +++ b/components/libc/dlib/SConscript @@ -10,6 +10,6 @@ CPPDEFINES = ['RT_USING_DLIBC'] if rtconfig.PLATFORM == 'iar': group = DefineGroup('dlib', src, depend = ['RT_USING_LIBC'], - CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) + CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/dlib/rmtx.c b/components/libc/dlib/rmtx.c index d6ce920d67..4bf7140271 100644 --- a/components/libc/dlib/rmtx.c +++ b/components/libc/dlib/rmtx.c @@ -30,6 +30,7 @@ */ #if _DLIB_THREAD_SUPPORT +typedef void* _Rmtx; void _Mtxinit(_Rmtx *m) { rt_mutex_t mutex; diff --git a/components/libc/dlib/syscall_close.c b/components/libc/dlib/syscall_close.c new file mode 100644 index 0000000000..5792bb3806 --- /dev/null +++ b/components/libc/dlib/syscall_close.c @@ -0,0 +1,43 @@ +/* + * File : syscall_close.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-01-28 Bernard first version + */ +#include +#ifdef RT_USING_DFS +#include +#endif +#include + +#pragma module_name = "?__close" +int __close(int handle) +{ + if (handle == _LLIO_STDOUT || + handle == _LLIO_STDERR || + handle == _LLIO_STDIN) + return _LLIO_ERROR; + +#ifdef RT_USING_DFS + return close(handle); +#else + return 0; +#endif +} diff --git a/components/libc/dlib/syscalls.c b/components/libc/dlib/syscall_lseek.c similarity index 74% rename from components/libc/dlib/syscalls.c rename to components/libc/dlib/syscall_lseek.c index f1802a98b8..950ba52f65 100644 --- a/components/libc/dlib/syscalls.c +++ b/components/libc/dlib/syscall_lseek.c @@ -1,5 +1,5 @@ /* - * File : syscalls.c + * File : syscall_lseek.c * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team * @@ -23,46 +23,21 @@ */ #include #ifdef RT_USING_DFS -#include +#include #endif #include -#pragma module_name = "?__close" -int __close(int handle) -{ - if (handle == _LLIO_STDOUT || - handle == _LLIO_STDERR || - handle == _LLIO_STDIN) - return _LLIO_ERROR; - -#ifdef RT_USING_DFS - return close(handle); -#else - return 0; -#endif -} - -#pragma module_name = "?remove" -int remove(const char *val) -{ -#ifdef RT_USING_DFS - dfs_file_unlink(val); -#endif - - return 0; -} - #pragma module_name = "?__lseek" long __lseek(int handle, long offset, int whence) { -#ifdef RT_USING_DFS -#endif - if (handle == _LLIO_STDOUT || handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; +#ifdef RT_USING_DFS return lseek(handle, offset, whence); +#else + return _LLIO_ERROR; +#endif } - diff --git a/components/libc/dlib/syscall_mem.c b/components/libc/dlib/syscall_mem.c new file mode 100644 index 0000000000..10eb298b9c --- /dev/null +++ b/components/libc/dlib/syscall_mem.c @@ -0,0 +1,44 @@ +/* + * File : syscall_mem.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-01-28 Bernard first version + */ +#include + +void *malloc(rt_size_t n) +{ + return rt_malloc(n); +} + +void *realloc(void *rmem, rt_size_t newsize) +{ + return rt_realloc(rmem, newsize); +} + +void *calloc(rt_size_t nelem, rt_size_t elsize) +{ + return rt_calloc(nelem, elsize); +} + +void free(void *rmem) +{ + rt_free(rmem); +} diff --git a/components/libc/dlib/syscall_open.c b/components/libc/dlib/syscall_open.c index 0aa0caf0cd..95fa43b9c6 100644 --- a/components/libc/dlib/syscall_open.c +++ b/components/libc/dlib/syscall_open.c @@ -1,26 +1,26 @@ /* - * File : syscall_open.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2015-01-28 Bernard first version - */ +* File : syscall_open.c +* This file is part of RT-Thread RTOS +* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +* +* Change Logs: +* Date Author Notes +* 2015-01-28 Bernard first version +*/ #include #include @@ -32,33 +32,57 @@ int __open(const char *filename, int mode) { - if (mode & _LLIO_CREAT) +#ifndef RT_USING_DFS + return -1; +#else + int handle; + int open_mode = O_RDONLY; + + if (mode & _LLIO_CREAT) + { + open_mode |= O_CREAT; + + /* Check what we should do with it if it exists. */ + if (mode & _LLIO_APPEND) { + /* Append to the existing file. */ + open_mode |= O_APPEND; } - if (mode & _LLIO_TEXT) + if (mode & _LLIO_TRUNC) { - /* we didn't support text mode */ + /* Truncate the existsing file. */ + open_mode |= O_TRUNC; } - - switch (mode & _LLIO_RDWRMASK) - { + } + + if (mode & _LLIO_TEXT) + { + /* we didn't support text mode */ + } + + switch (mode & _LLIO_RDWRMASK) + { case _LLIO_RDONLY: - /* The file should be opened for read only. */ break; - + case _LLIO_WRONLY: - /* The file should be opened for write only. */ + open_mode |= O_WRONLY; break; - + case _LLIO_RDWR: /* The file should be opened for both reads and writes. */ + open_mode |= O_RDWR; break; - + default: return -1; } - - return handle; + + handle = open(filename, open_mode, 0); + if (handle < 0) + return -1; + + return handle + _LLIO_STDERR + 1; +#endif } - diff --git a/components/libc/dlib/syscall_read.c b/components/libc/dlib/syscall_read.c index f109badb55..aa13654189 100644 --- a/components/libc/dlib/syscall_read.c +++ b/components/libc/dlib/syscall_read.c @@ -23,6 +23,9 @@ */ #include +#ifdef RT_USING_DFS +#include +#endif #include #pragma module_name = "?__read" @@ -44,8 +47,7 @@ size_t __read(int handle, unsigned char *buf, size_t len) #ifndef RT_USING_DFS return _LLIO_ERROR; #else - size = read(handle - STDERR - 1, buf, len); + size = read(handle - _LLIO_STDERR - 1, buf, len); return size; #endif } - diff --git a/components/libc/dlib/syscall_remove.c b/components/libc/dlib/syscall_remove.c new file mode 100644 index 0000000000..b7dd9477b7 --- /dev/null +++ b/components/libc/dlib/syscall_remove.c @@ -0,0 +1,38 @@ +/* + * File : syscall_remove.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-01-28 Bernard first version + */ +#include +#ifdef RT_USING_DFS +#include +#endif +#include + +#pragma module_name = "?remove" +int remove(const char *val) +{ +#ifdef RT_USING_DFS + dfs_file_unlink(val); +#endif + + return 0; +} diff --git a/components/libc/dlib/syscall_write.c b/components/libc/dlib/syscall_write.c index 5f21bf9bb9..a7140b9818 100644 --- a/components/libc/dlib/syscall_write.c +++ b/components/libc/dlib/syscall_write.c @@ -23,6 +23,9 @@ */ #include +#ifdef RT_USING_DFS +#include +#endif #include #pragma module_name = "?__write" @@ -47,12 +50,12 @@ size_t __write(int handle, const unsigned char *buf, size_t len) #endif } - if (handle == STDIN) return -1; + if (handle == _LLIO_STDIN) return -1; #ifndef RT_USING_DFS return _LLIO_ERROR; #else - size = write(handle - STDERR - 1, buf, len); + size = write(handle - _LLIO_STDERR - 1, buf, len); return size; #endif }