From dcec5a4d60405c206b1fab8630534e917fdf9857 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 29 Jan 1997 00:29:25 +0000 Subject: Merged newlib's libgloss support for rtems into this directory. This should simplify the build process. --- c/src/exec/libcsupport/include/rtems/libio.h | 16 +++-- c/src/exec/libcsupport/src/libio.c | 16 ++--- c/src/exec/libcsupport/src/malloc.c | 36 +++++------ c/src/exec/libcsupport/src/newlibc.c | 5 +- c/src/lib/include/rtems/libio.h | 16 +++-- c/src/lib/libc/libio.c | 16 ++--- c/src/lib/libc/libio.h | 16 +++-- c/src/lib/libc/malloc.c | 36 +++++------ c/src/lib/libc/newlibc.c | 5 +- c/src/lib/libc/newlibif.c | 90 ++++++++++++++++++++++++++++ c/src/lib/libc/syscalls.c | 35 +++++++++-- 11 files changed, 213 insertions(+), 74 deletions(-) create mode 100644 c/src/lib/libc/newlibif.c (limited to 'c/src') diff --git a/c/src/exec/libcsupport/include/rtems/libio.h b/c/src/exec/libcsupport/include/rtems/libio.h index 07d72620b1..b518100484 100644 --- a/c/src/exec/libcsupport/include/rtems/libio.h +++ b/c/src/exec/libcsupport/include/rtems/libio.h @@ -13,6 +13,8 @@ #ifndef _RTEMS_LIBIO_H #define _RTEMS_LIBIO_H +#include + typedef unsigned32 rtems_libio_offset_t; /* @@ -88,11 +90,13 @@ typedef struct { void rtems_libio_config(rtems_configuration_table *config, unsigned32 max_fds); void rtems_libio_init(void); -int __open(const char *pathname, unsigned32 flag, unsigned32 mode); -int __close(int fd); -int __read(int fd, void *buffer, unsigned32 count); -int __write(int fd, const void *buffer, unsigned32 count); -int __ioctl(int fd, unsigned32 command, void *buffer); -int __lseek(int fd, rtems_libio_offset_t offset, int whence); +int __rtems_open(const char *pathname, unsigned32 flag, unsigned32 mode); +int __rtems_close(int fd); +int __rtems_read(int fd, void *buffer, unsigned32 count); +int __rtems_write(int fd, const void *buffer, unsigned32 count); +int __rtems_ioctl(int fd, unsigned32 command, void *buffer); +int __rtems_lseek(int fd, rtems_libio_offset_t offset, int whence); +int __rtems_fstat(int _fd, struct stat* _sbuf); +int __rtems_isatty(int _fd); #endif /* _RTEMS_LIBIO_H */ diff --git a/c/src/exec/libcsupport/src/libio.c b/c/src/exec/libcsupport/src/libio.c index 26448d20a4..3a7325c422 100644 --- a/c/src/exec/libcsupport/src/libio.c +++ b/c/src/exec/libcsupport/src/libio.c @@ -46,7 +46,7 @@ rtems_libio_t *rtems_libio_last_iop; #define rtems_libio_check_fd(fd) \ do { \ - if ((fd) >= rtems_libio_number_iops) \ + if ((unsigned32) (fd) >= rtems_libio_number_iops) \ { \ errno = EBADF; \ return -1; \ @@ -243,7 +243,7 @@ rtems_libio_free(rtems_libio_t *iop) } int -__open( +__rtems_open( const char *pathname, unsigned32 flag, unsigned32 mode) @@ -254,10 +254,12 @@ __open( rtems_libio_open_close_args_t args; if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) { +/* if ( rc == RTEMS_UNSATISFIED ) { puts( "open -- ENOSYS case" ); assert( 0 ); } +*/ goto done; } @@ -291,7 +293,7 @@ done: } int -__close( +__rtems_close( int fd ) { @@ -316,7 +318,7 @@ __close( } int -__read( +__rtems_read( int fd, void * buffer, unsigned32 count @@ -352,7 +354,7 @@ __read( } int -__write( +__rtems_write( int fd, const void *buffer, unsigned32 count @@ -388,7 +390,7 @@ __write( } int -__ioctl( +__rtems_ioctl( int fd, unsigned32 command, void * buffer) @@ -420,7 +422,7 @@ __ioctl( int -__lseek( +__rtems_lseek( int fd, rtems_libio_offset_t offset, int whence diff --git a/c/src/exec/libcsupport/src/malloc.c b/c/src/exec/libcsupport/src/malloc.c index 61969c1d24..e8288a3bd3 100644 --- a/c/src/exec/libcsupport/src/malloc.c +++ b/c/src/exec/libcsupport/src/malloc.c @@ -37,7 +37,7 @@ size_t RTEMS_Malloc_Sbrk_amount; #endif #ifdef MALLOC_STATS -#define MSBUMP(f,n) malloc_stats.f += (n) +#define MSBUMP(f,n) rtems_malloc_stats.f += (n) struct { unsigned32 space_available; /* current size of malloc area */ @@ -48,9 +48,9 @@ struct { unsigned32 max_depth; /* most ever malloc'd at 1 time */ unsigned64 lifetime_allocated; unsigned64 lifetime_freed; -} malloc_stats; +} rtems_malloc_stats; -#else /* No malloc_stats */ +#else /* No rtems_malloc_stats */ #define MSBUMP(f,n) #endif @@ -115,7 +115,7 @@ void RTEMS_Malloc_Initialize( #ifdef MALLOC_STATS /* zero all the stats */ - (void) memset(&malloc_stats, 0, sizeof(malloc_stats)); + (void) memset(&rtems_malloc_stats, 0, sizeof(rtems_malloc_stats)); #endif MSBUMP(space_available, length); @@ -201,9 +201,9 @@ void *malloc( unsigned32 current_depth; status = rtems_region_get_segment_size(RTEMS_Malloc_Heap, return_this, &actual_size); MSBUMP(lifetime_allocated, actual_size); - current_depth = malloc_stats.lifetime_allocated - malloc_stats.lifetime_freed; - if (current_depth > malloc_stats.max_depth) - malloc_stats.max_depth = current_depth; + current_depth = rtems_malloc_stats.lifetime_allocated - rtems_malloc_stats.lifetime_freed; + if (current_depth > rtems_malloc_stats.max_depth) + rtems_malloc_stats.max_depth = current_depth; } #endif @@ -314,23 +314,23 @@ void free( void malloc_dump(void) { - unsigned32 allocated = malloc_stats.lifetime_allocated - malloc_stats.lifetime_freed; + unsigned32 allocated = rtems_malloc_stats.lifetime_allocated - rtems_malloc_stats.lifetime_freed; printf("Malloc stats\n"); printf(" avail:%uk allocated:%uk (%d%%) max:%uk (%d%%) lifetime:%Luk freed:%Luk\n", - (unsigned int) malloc_stats.space_available / 1024, + (unsigned int) rtems_malloc_stats.space_available / 1024, (unsigned int) allocated / 1024, /* avoid float! */ - (allocated * 100) / malloc_stats.space_available, - (unsigned int) malloc_stats.max_depth / 1024, - (malloc_stats.max_depth * 100) / malloc_stats.space_available, - (unsigned64) malloc_stats.lifetime_allocated / 1024, - (unsigned64) malloc_stats.lifetime_freed / 1024); + (allocated * 100) / rtems_malloc_stats.space_available, + (unsigned int) rtems_malloc_stats.max_depth / 1024, + (rtems_malloc_stats.max_depth * 100) / rtems_malloc_stats.space_available, + (unsigned64) rtems_malloc_stats.lifetime_allocated / 1024, + (unsigned64) rtems_malloc_stats.lifetime_freed / 1024); printf(" Call counts: malloc:%d free:%d realloc:%d calloc:%d\n", - malloc_stats.malloc_calls, - malloc_stats.free_calls, - malloc_stats.realloc_calls, - malloc_stats.calloc_calls); + rtems_malloc_stats.malloc_calls, + rtems_malloc_stats.free_calls, + rtems_malloc_stats.realloc_calls, + rtems_malloc_stats.calloc_calls); } diff --git a/c/src/exec/libcsupport/src/newlibc.c b/c/src/exec/libcsupport/src/newlibc.c index 2909c0e541..bd2d7133ed 100644 --- a/c/src/exec/libcsupport/src/newlibc.c +++ b/c/src/exec/libcsupport/src/newlibc.c @@ -1,4 +1,3 @@ -#if defined(RTEMS_NEWLIB) /* * COPYRIGHT (c) 1994 by Division Incorporated @@ -30,6 +29,8 @@ #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ #include + +#if defined(RTEMS_NEWLIB) #include #include /* for free() */ #include /* for memset() */ @@ -346,6 +347,8 @@ int get_errno() * */ +#include + #if !defined(RTEMS_UNIX) && !defined(__GO32__) && !defined(_AM29K) void _exit(int status) { diff --git a/c/src/lib/include/rtems/libio.h b/c/src/lib/include/rtems/libio.h index 07d72620b1..b518100484 100644 --- a/c/src/lib/include/rtems/libio.h +++ b/c/src/lib/include/rtems/libio.h @@ -13,6 +13,8 @@ #ifndef _RTEMS_LIBIO_H #define _RTEMS_LIBIO_H +#include + typedef unsigned32 rtems_libio_offset_t; /* @@ -88,11 +90,13 @@ typedef struct { void rtems_libio_config(rtems_configuration_table *config, unsigned32 max_fds); void rtems_libio_init(void); -int __open(const char *pathname, unsigned32 flag, unsigned32 mode); -int __close(int fd); -int __read(int fd, void *buffer, unsigned32 count); -int __write(int fd, const void *buffer, unsigned32 count); -int __ioctl(int fd, unsigned32 command, void *buffer); -int __lseek(int fd, rtems_libio_offset_t offset, int whence); +int __rtems_open(const char *pathname, unsigned32 flag, unsigned32 mode); +int __rtems_close(int fd); +int __rtems_read(int fd, void *buffer, unsigned32 count); +int __rtems_write(int fd, const void *buffer, unsigned32 count); +int __rtems_ioctl(int fd, unsigned32 command, void *buffer); +int __rtems_lseek(int fd, rtems_libio_offset_t offset, int whence); +int __rtems_fstat(int _fd, struct stat* _sbuf); +int __rtems_isatty(int _fd); #endif /* _RTEMS_LIBIO_H */ diff --git a/c/src/lib/libc/libio.c b/c/src/lib/libc/libio.c index 26448d20a4..3a7325c422 100644 --- a/c/src/lib/libc/libio.c +++ b/c/src/lib/libc/libio.c @@ -46,7 +46,7 @@ rtems_libio_t *rtems_libio_last_iop; #define rtems_libio_check_fd(fd) \ do { \ - if ((fd) >= rtems_libio_number_iops) \ + if ((unsigned32) (fd) >= rtems_libio_number_iops) \ { \ errno = EBADF; \ return -1; \ @@ -243,7 +243,7 @@ rtems_libio_free(rtems_libio_t *iop) } int -__open( +__rtems_open( const char *pathname, unsigned32 flag, unsigned32 mode) @@ -254,10 +254,12 @@ __open( rtems_libio_open_close_args_t args; if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) { +/* if ( rc == RTEMS_UNSATISFIED ) { puts( "open -- ENOSYS case" ); assert( 0 ); } +*/ goto done; } @@ -291,7 +293,7 @@ done: } int -__close( +__rtems_close( int fd ) { @@ -316,7 +318,7 @@ __close( } int -__read( +__rtems_read( int fd, void * buffer, unsigned32 count @@ -352,7 +354,7 @@ __read( } int -__write( +__rtems_write( int fd, const void *buffer, unsigned32 count @@ -388,7 +390,7 @@ __write( } int -__ioctl( +__rtems_ioctl( int fd, unsigned32 command, void * buffer) @@ -420,7 +422,7 @@ __ioctl( int -__lseek( +__rtems_lseek( int fd, rtems_libio_offset_t offset, int whence diff --git a/c/src/lib/libc/libio.h b/c/src/lib/libc/libio.h index 07d72620b1..b518100484 100644 --- a/c/src/lib/libc/libio.h +++ b/c/src/lib/libc/libio.h @@ -13,6 +13,8 @@ #ifndef _RTEMS_LIBIO_H #define _RTEMS_LIBIO_H +#include + typedef unsigned32 rtems_libio_offset_t; /* @@ -88,11 +90,13 @@ typedef struct { void rtems_libio_config(rtems_configuration_table *config, unsigned32 max_fds); void rtems_libio_init(void); -int __open(const char *pathname, unsigned32 flag, unsigned32 mode); -int __close(int fd); -int __read(int fd, void *buffer, unsigned32 count); -int __write(int fd, const void *buffer, unsigned32 count); -int __ioctl(int fd, unsigned32 command, void *buffer); -int __lseek(int fd, rtems_libio_offset_t offset, int whence); +int __rtems_open(const char *pathname, unsigned32 flag, unsigned32 mode); +int __rtems_close(int fd); +int __rtems_read(int fd, void *buffer, unsigned32 count); +int __rtems_write(int fd, const void *buffer, unsigned32 count); +int __rtems_ioctl(int fd, unsigned32 command, void *buffer); +int __rtems_lseek(int fd, rtems_libio_offset_t offset, int whence); +int __rtems_fstat(int _fd, struct stat* _sbuf); +int __rtems_isatty(int _fd); #endif /* _RTEMS_LIBIO_H */ diff --git a/c/src/lib/libc/malloc.c b/c/src/lib/libc/malloc.c index 61969c1d24..e8288a3bd3 100644 --- a/c/src/lib/libc/malloc.c +++ b/c/src/lib/libc/malloc.c @@ -37,7 +37,7 @@ size_t RTEMS_Malloc_Sbrk_amount; #endif #ifdef MALLOC_STATS -#define MSBUMP(f,n) malloc_stats.f += (n) +#define MSBUMP(f,n) rtems_malloc_stats.f += (n) struct { unsigned32 space_available; /* current size of malloc area */ @@ -48,9 +48,9 @@ struct { unsigned32 max_depth; /* most ever malloc'd at 1 time */ unsigned64 lifetime_allocated; unsigned64 lifetime_freed; -} malloc_stats; +} rtems_malloc_stats; -#else /* No malloc_stats */ +#else /* No rtems_malloc_stats */ #define MSBUMP(f,n) #endif @@ -115,7 +115,7 @@ void RTEMS_Malloc_Initialize( #ifdef MALLOC_STATS /* zero all the stats */ - (void) memset(&malloc_stats, 0, sizeof(malloc_stats)); + (void) memset(&rtems_malloc_stats, 0, sizeof(rtems_malloc_stats)); #endif MSBUMP(space_available, length); @@ -201,9 +201,9 @@ void *malloc( unsigned32 current_depth; status = rtems_region_get_segment_size(RTEMS_Malloc_Heap, return_this, &actual_size); MSBUMP(lifetime_allocated, actual_size); - current_depth = malloc_stats.lifetime_allocated - malloc_stats.lifetime_freed; - if (current_depth > malloc_stats.max_depth) - malloc_stats.max_depth = current_depth; + current_depth = rtems_malloc_stats.lifetime_allocated - rtems_malloc_stats.lifetime_freed; + if (current_depth > rtems_malloc_stats.max_depth) + rtems_malloc_stats.max_depth = current_depth; } #endif @@ -314,23 +314,23 @@ void free( void malloc_dump(void) { - unsigned32 allocated = malloc_stats.lifetime_allocated - malloc_stats.lifetime_freed; + unsigned32 allocated = rtems_malloc_stats.lifetime_allocated - rtems_malloc_stats.lifetime_freed; printf("Malloc stats\n"); printf(" avail:%uk allocated:%uk (%d%%) max:%uk (%d%%) lifetime:%Luk freed:%Luk\n", - (unsigned int) malloc_stats.space_available / 1024, + (unsigned int) rtems_malloc_stats.space_available / 1024, (unsigned int) allocated / 1024, /* avoid float! */ - (allocated * 100) / malloc_stats.space_available, - (unsigned int) malloc_stats.max_depth / 1024, - (malloc_stats.max_depth * 100) / malloc_stats.space_available, - (unsigned64) malloc_stats.lifetime_allocated / 1024, - (unsigned64) malloc_stats.lifetime_freed / 1024); + (allocated * 100) / rtems_malloc_stats.space_available, + (unsigned int) rtems_malloc_stats.max_depth / 1024, + (rtems_malloc_stats.max_depth * 100) / rtems_malloc_stats.space_available, + (unsigned64) rtems_malloc_stats.lifetime_allocated / 1024, + (unsigned64) rtems_malloc_stats.lifetime_freed / 1024); printf(" Call counts: malloc:%d free:%d realloc:%d calloc:%d\n", - malloc_stats.malloc_calls, - malloc_stats.free_calls, - malloc_stats.realloc_calls, - malloc_stats.calloc_calls); + rtems_malloc_stats.malloc_calls, + rtems_malloc_stats.free_calls, + rtems_malloc_stats.realloc_calls, + rtems_malloc_stats.calloc_calls); } diff --git a/c/src/lib/libc/newlibc.c b/c/src/lib/libc/newlibc.c index 2909c0e541..bd2d7133ed 100644 --- a/c/src/lib/libc/newlibc.c +++ b/c/src/lib/libc/newlibc.c @@ -1,4 +1,3 @@ -#if defined(RTEMS_NEWLIB) /* * COPYRIGHT (c) 1994 by Division Incorporated @@ -30,6 +29,8 @@ #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ #include + +#if defined(RTEMS_NEWLIB) #include #include /* for free() */ #include /* for memset() */ @@ -346,6 +347,8 @@ int get_errno() * */ +#include + #if !defined(RTEMS_UNIX) && !defined(__GO32__) && !defined(_AM29K) void _exit(int status) { diff --git a/c/src/lib/libc/newlibif.c b/c/src/lib/libc/newlibif.c new file mode 100644 index 0000000000..5b59554428 --- /dev/null +++ b/c/src/lib/libc/newlibif.c @@ -0,0 +1,90 @@ + +/* + * This file contains the glue which maps newlib system calls onto their + * RTEMS implementations. This formerly was in the file + * libgloss/rtems/iface.c which was installed as rtems.o. Merging this + * into the RTEMS source tree minimizes the files which must be linked + * to build an rtems application. + * + * $Id$ + * + */ + +#include +#if defined(RTEMS_NEWLIB) + +#include +#include +#include + +#include "internal.h" +#include "libio.h" + +int +read(int fd, + char *buf, + int nbytes) +{ + return __rtems_read(fd, buf, nbytes); +} + +int +write(int fd, + char *buf, + int nbytes) +{ + return __rtems_write(fd, buf, nbytes); +} + +int +open(char *buf, + int flags, + int mode) +{ + return __rtems_open(buf, flags, mode); +} + +int +close(int fd) +{ + return __rtems_close(fd); +} + +/* + * isatty -- returns 1 if connected to a terminal device, + * returns 0 if not. + */ +int +isatty(int fd) +{ + return __rtems_isatty(fd); +} + +/* + * lseek -- move read/write pointer. Since a serial port + * is non-seekable, we return an error. + */ +off_t +lseek(int fd, + off_t offset, + int whence) +{ + return __rtems_lseek(fd, offset, whence); +} + +/* + * fstat -- get status of a file. Since we have no file + * system, we just return an error. + */ +int +fstat(int fd, + struct stat *buf) +{ + return __rtems_fstat(fd, buf); +} + +/* + * getpid and kill are provided directly by rtems + */ + +#endif diff --git a/c/src/lib/libc/syscalls.c b/c/src/lib/libc/syscalls.c index af17dd1375..44b967b50c 100644 --- a/c/src/lib/libc/syscalls.c +++ b/c/src/lib/libc/syscalls.c @@ -23,16 +23,19 @@ #include #include #include +#include +#include +#include /* only for puts */ /* * fstat, stat, and isatty must lie consistently and report that everything * is a tty or stdout will not be line buffered. */ -int __fstat(int _fd, struct stat* _sbuf) +int __rtems_fstat(int _fd, struct stat* _sbuf) { if ( _fd > 2 ) { - puts( "__fstat -- only stdio supported" ); + puts( "__rtems_fstat -- only stdio supported" ); assert( 0 ); } _sbuf->st_mode = S_IFCHR; @@ -42,7 +45,7 @@ int __fstat(int _fd, struct stat* _sbuf) return 0; } -int __isatty(int _fd) +int __rtems_isatty(int _fd) { return 1; } @@ -52,7 +55,7 @@ int stat( const char *path, struct stat *buf ) if ( strncmp( "/dev/", path, 5 ) ) { return -1; } - return __fstat( 0, buf ); + return __rtems_fstat( 0, buf ); } int link( const char *existing, const char *new ) @@ -67,4 +70,28 @@ int unlink( const char *path ) return -1; } +char *getcwd( char *_buf, size_t _size) { +/* assert( FALSE ); */ + errno = ENOSYS; + return 0; +} +int fork() { + puts( "fork -- not supported!!!" ); + assert( 0 ); + errno = ENOSYS; + return -1; +} +int execv(const char *_path, char * const _argv[] ) { + puts( "execv -- not supported!!!" ); + assert( 0 ); + errno = ENOSYS; + return -1; +} +int wait() { + puts( "wait -- not supported!!!" ); + assert( 0 ); + errno = ENOSYS; + return -1; +} + #endif -- cgit v1.2.3