forked from Imagelibrary/rtems
Merged newlib's libgloss support for rtems into this directory. This
should simplify the build process.
This commit is contained in:
@@ -13,6 +13,8 @@
|
|||||||
#ifndef _RTEMS_LIBIO_H
|
#ifndef _RTEMS_LIBIO_H
|
||||||
#define _RTEMS_LIBIO_H
|
#define _RTEMS_LIBIO_H
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
typedef unsigned32 rtems_libio_offset_t;
|
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_config(rtems_configuration_table *config, unsigned32 max_fds);
|
||||||
void rtems_libio_init(void);
|
void rtems_libio_init(void);
|
||||||
|
|
||||||
int __open(const char *pathname, unsigned32 flag, unsigned32 mode);
|
int __rtems_open(const char *pathname, unsigned32 flag, unsigned32 mode);
|
||||||
int __close(int fd);
|
int __rtems_close(int fd);
|
||||||
int __read(int fd, void *buffer, unsigned32 count);
|
int __rtems_read(int fd, void *buffer, unsigned32 count);
|
||||||
int __write(int fd, const void *buffer, unsigned32 count);
|
int __rtems_write(int fd, const void *buffer, unsigned32 count);
|
||||||
int __ioctl(int fd, unsigned32 command, void *buffer);
|
int __rtems_ioctl(int fd, unsigned32 command, void *buffer);
|
||||||
int __lseek(int fd, rtems_libio_offset_t offset, int whence);
|
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 */
|
#endif /* _RTEMS_LIBIO_H */
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ rtems_libio_t *rtems_libio_last_iop;
|
|||||||
|
|
||||||
#define rtems_libio_check_fd(fd) \
|
#define rtems_libio_check_fd(fd) \
|
||||||
do { \
|
do { \
|
||||||
if ((fd) >= rtems_libio_number_iops) \
|
if ((unsigned32) (fd) >= rtems_libio_number_iops) \
|
||||||
{ \
|
{ \
|
||||||
errno = EBADF; \
|
errno = EBADF; \
|
||||||
return -1; \
|
return -1; \
|
||||||
@@ -243,7 +243,7 @@ rtems_libio_free(rtems_libio_t *iop)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__open(
|
__rtems_open(
|
||||||
const char *pathname,
|
const char *pathname,
|
||||||
unsigned32 flag,
|
unsigned32 flag,
|
||||||
unsigned32 mode)
|
unsigned32 mode)
|
||||||
@@ -254,10 +254,12 @@ __open(
|
|||||||
rtems_libio_open_close_args_t args;
|
rtems_libio_open_close_args_t args;
|
||||||
|
|
||||||
if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) {
|
if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) {
|
||||||
|
/*
|
||||||
if ( rc == RTEMS_UNSATISFIED ) {
|
if ( rc == RTEMS_UNSATISFIED ) {
|
||||||
puts( "open -- ENOSYS case" );
|
puts( "open -- ENOSYS case" );
|
||||||
assert( 0 );
|
assert( 0 );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +293,7 @@ done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__close(
|
__rtems_close(
|
||||||
int fd
|
int fd
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -316,7 +318,7 @@ __close(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__read(
|
__rtems_read(
|
||||||
int fd,
|
int fd,
|
||||||
void * buffer,
|
void * buffer,
|
||||||
unsigned32 count
|
unsigned32 count
|
||||||
@@ -352,7 +354,7 @@ __read(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__write(
|
__rtems_write(
|
||||||
int fd,
|
int fd,
|
||||||
const void *buffer,
|
const void *buffer,
|
||||||
unsigned32 count
|
unsigned32 count
|
||||||
@@ -388,7 +390,7 @@ __write(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__ioctl(
|
__rtems_ioctl(
|
||||||
int fd,
|
int fd,
|
||||||
unsigned32 command,
|
unsigned32 command,
|
||||||
void * buffer)
|
void * buffer)
|
||||||
@@ -420,7 +422,7 @@ __ioctl(
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
__lseek(
|
__rtems_lseek(
|
||||||
int fd,
|
int fd,
|
||||||
rtems_libio_offset_t offset,
|
rtems_libio_offset_t offset,
|
||||||
int whence
|
int whence
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ size_t RTEMS_Malloc_Sbrk_amount;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MALLOC_STATS
|
#ifdef MALLOC_STATS
|
||||||
#define MSBUMP(f,n) malloc_stats.f += (n)
|
#define MSBUMP(f,n) rtems_malloc_stats.f += (n)
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
unsigned32 space_available; /* current size of malloc area */
|
unsigned32 space_available; /* current size of malloc area */
|
||||||
@@ -48,9 +48,9 @@ struct {
|
|||||||
unsigned32 max_depth; /* most ever malloc'd at 1 time */
|
unsigned32 max_depth; /* most ever malloc'd at 1 time */
|
||||||
unsigned64 lifetime_allocated;
|
unsigned64 lifetime_allocated;
|
||||||
unsigned64 lifetime_freed;
|
unsigned64 lifetime_freed;
|
||||||
} malloc_stats;
|
} rtems_malloc_stats;
|
||||||
|
|
||||||
#else /* No malloc_stats */
|
#else /* No rtems_malloc_stats */
|
||||||
#define MSBUMP(f,n)
|
#define MSBUMP(f,n)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ void RTEMS_Malloc_Initialize(
|
|||||||
|
|
||||||
#ifdef MALLOC_STATS
|
#ifdef MALLOC_STATS
|
||||||
/* zero all the stats */
|
/* zero all the stats */
|
||||||
(void) memset(&malloc_stats, 0, sizeof(malloc_stats));
|
(void) memset(&rtems_malloc_stats, 0, sizeof(rtems_malloc_stats));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MSBUMP(space_available, length);
|
MSBUMP(space_available, length);
|
||||||
@@ -201,9 +201,9 @@ void *malloc(
|
|||||||
unsigned32 current_depth;
|
unsigned32 current_depth;
|
||||||
status = rtems_region_get_segment_size(RTEMS_Malloc_Heap, return_this, &actual_size);
|
status = rtems_region_get_segment_size(RTEMS_Malloc_Heap, return_this, &actual_size);
|
||||||
MSBUMP(lifetime_allocated, actual_size);
|
MSBUMP(lifetime_allocated, actual_size);
|
||||||
current_depth = malloc_stats.lifetime_allocated - malloc_stats.lifetime_freed;
|
current_depth = rtems_malloc_stats.lifetime_allocated - rtems_malloc_stats.lifetime_freed;
|
||||||
if (current_depth > malloc_stats.max_depth)
|
if (current_depth > rtems_malloc_stats.max_depth)
|
||||||
malloc_stats.max_depth = current_depth;
|
rtems_malloc_stats.max_depth = current_depth;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -314,23 +314,23 @@ void free(
|
|||||||
|
|
||||||
void malloc_dump(void)
|
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("Malloc stats\n");
|
||||||
printf(" avail:%uk allocated:%uk (%d%%) max:%uk (%d%%) lifetime:%Luk freed:%Luk\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,
|
(unsigned int) allocated / 1024,
|
||||||
/* avoid float! */
|
/* avoid float! */
|
||||||
(allocated * 100) / malloc_stats.space_available,
|
(allocated * 100) / rtems_malloc_stats.space_available,
|
||||||
(unsigned int) malloc_stats.max_depth / 1024,
|
(unsigned int) rtems_malloc_stats.max_depth / 1024,
|
||||||
(malloc_stats.max_depth * 100) / malloc_stats.space_available,
|
(rtems_malloc_stats.max_depth * 100) / rtems_malloc_stats.space_available,
|
||||||
(unsigned64) malloc_stats.lifetime_allocated / 1024,
|
(unsigned64) rtems_malloc_stats.lifetime_allocated / 1024,
|
||||||
(unsigned64) malloc_stats.lifetime_freed / 1024);
|
(unsigned64) rtems_malloc_stats.lifetime_freed / 1024);
|
||||||
printf(" Call counts: malloc:%d free:%d realloc:%d calloc:%d\n",
|
printf(" Call counts: malloc:%d free:%d realloc:%d calloc:%d\n",
|
||||||
malloc_stats.malloc_calls,
|
rtems_malloc_stats.malloc_calls,
|
||||||
malloc_stats.free_calls,
|
rtems_malloc_stats.free_calls,
|
||||||
malloc_stats.realloc_calls,
|
rtems_malloc_stats.realloc_calls,
|
||||||
malloc_stats.calloc_calls);
|
rtems_malloc_stats.calloc_calls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#if defined(RTEMS_NEWLIB)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT (c) 1994 by Division Incorporated
|
* COPYRIGHT (c) 1994 by Division Incorporated
|
||||||
@@ -30,6 +29,8 @@
|
|||||||
|
|
||||||
#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
|
#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
|
||||||
#include <rtems.h>
|
#include <rtems.h>
|
||||||
|
|
||||||
|
#if defined(RTEMS_NEWLIB)
|
||||||
#include <libcsupport.h>
|
#include <libcsupport.h>
|
||||||
#include <stdlib.h> /* for free() */
|
#include <stdlib.h> /* for free() */
|
||||||
#include <string.h> /* for memset() */
|
#include <string.h> /* for memset() */
|
||||||
@@ -346,6 +347,8 @@ int get_errno()
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#if !defined(RTEMS_UNIX) && !defined(__GO32__) && !defined(_AM29K)
|
#if !defined(RTEMS_UNIX) && !defined(__GO32__) && !defined(_AM29K)
|
||||||
void _exit(int status)
|
void _exit(int status)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#ifndef _RTEMS_LIBIO_H
|
#ifndef _RTEMS_LIBIO_H
|
||||||
#define _RTEMS_LIBIO_H
|
#define _RTEMS_LIBIO_H
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
typedef unsigned32 rtems_libio_offset_t;
|
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_config(rtems_configuration_table *config, unsigned32 max_fds);
|
||||||
void rtems_libio_init(void);
|
void rtems_libio_init(void);
|
||||||
|
|
||||||
int __open(const char *pathname, unsigned32 flag, unsigned32 mode);
|
int __rtems_open(const char *pathname, unsigned32 flag, unsigned32 mode);
|
||||||
int __close(int fd);
|
int __rtems_close(int fd);
|
||||||
int __read(int fd, void *buffer, unsigned32 count);
|
int __rtems_read(int fd, void *buffer, unsigned32 count);
|
||||||
int __write(int fd, const void *buffer, unsigned32 count);
|
int __rtems_write(int fd, const void *buffer, unsigned32 count);
|
||||||
int __ioctl(int fd, unsigned32 command, void *buffer);
|
int __rtems_ioctl(int fd, unsigned32 command, void *buffer);
|
||||||
int __lseek(int fd, rtems_libio_offset_t offset, int whence);
|
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 */
|
#endif /* _RTEMS_LIBIO_H */
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ rtems_libio_t *rtems_libio_last_iop;
|
|||||||
|
|
||||||
#define rtems_libio_check_fd(fd) \
|
#define rtems_libio_check_fd(fd) \
|
||||||
do { \
|
do { \
|
||||||
if ((fd) >= rtems_libio_number_iops) \
|
if ((unsigned32) (fd) >= rtems_libio_number_iops) \
|
||||||
{ \
|
{ \
|
||||||
errno = EBADF; \
|
errno = EBADF; \
|
||||||
return -1; \
|
return -1; \
|
||||||
@@ -243,7 +243,7 @@ rtems_libio_free(rtems_libio_t *iop)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__open(
|
__rtems_open(
|
||||||
const char *pathname,
|
const char *pathname,
|
||||||
unsigned32 flag,
|
unsigned32 flag,
|
||||||
unsigned32 mode)
|
unsigned32 mode)
|
||||||
@@ -254,10 +254,12 @@ __open(
|
|||||||
rtems_libio_open_close_args_t args;
|
rtems_libio_open_close_args_t args;
|
||||||
|
|
||||||
if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) {
|
if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) {
|
||||||
|
/*
|
||||||
if ( rc == RTEMS_UNSATISFIED ) {
|
if ( rc == RTEMS_UNSATISFIED ) {
|
||||||
puts( "open -- ENOSYS case" );
|
puts( "open -- ENOSYS case" );
|
||||||
assert( 0 );
|
assert( 0 );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +293,7 @@ done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__close(
|
__rtems_close(
|
||||||
int fd
|
int fd
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -316,7 +318,7 @@ __close(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__read(
|
__rtems_read(
|
||||||
int fd,
|
int fd,
|
||||||
void * buffer,
|
void * buffer,
|
||||||
unsigned32 count
|
unsigned32 count
|
||||||
@@ -352,7 +354,7 @@ __read(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__write(
|
__rtems_write(
|
||||||
int fd,
|
int fd,
|
||||||
const void *buffer,
|
const void *buffer,
|
||||||
unsigned32 count
|
unsigned32 count
|
||||||
@@ -388,7 +390,7 @@ __write(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__ioctl(
|
__rtems_ioctl(
|
||||||
int fd,
|
int fd,
|
||||||
unsigned32 command,
|
unsigned32 command,
|
||||||
void * buffer)
|
void * buffer)
|
||||||
@@ -420,7 +422,7 @@ __ioctl(
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
__lseek(
|
__rtems_lseek(
|
||||||
int fd,
|
int fd,
|
||||||
rtems_libio_offset_t offset,
|
rtems_libio_offset_t offset,
|
||||||
int whence
|
int whence
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#ifndef _RTEMS_LIBIO_H
|
#ifndef _RTEMS_LIBIO_H
|
||||||
#define _RTEMS_LIBIO_H
|
#define _RTEMS_LIBIO_H
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
typedef unsigned32 rtems_libio_offset_t;
|
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_config(rtems_configuration_table *config, unsigned32 max_fds);
|
||||||
void rtems_libio_init(void);
|
void rtems_libio_init(void);
|
||||||
|
|
||||||
int __open(const char *pathname, unsigned32 flag, unsigned32 mode);
|
int __rtems_open(const char *pathname, unsigned32 flag, unsigned32 mode);
|
||||||
int __close(int fd);
|
int __rtems_close(int fd);
|
||||||
int __read(int fd, void *buffer, unsigned32 count);
|
int __rtems_read(int fd, void *buffer, unsigned32 count);
|
||||||
int __write(int fd, const void *buffer, unsigned32 count);
|
int __rtems_write(int fd, const void *buffer, unsigned32 count);
|
||||||
int __ioctl(int fd, unsigned32 command, void *buffer);
|
int __rtems_ioctl(int fd, unsigned32 command, void *buffer);
|
||||||
int __lseek(int fd, rtems_libio_offset_t offset, int whence);
|
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 */
|
#endif /* _RTEMS_LIBIO_H */
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ size_t RTEMS_Malloc_Sbrk_amount;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MALLOC_STATS
|
#ifdef MALLOC_STATS
|
||||||
#define MSBUMP(f,n) malloc_stats.f += (n)
|
#define MSBUMP(f,n) rtems_malloc_stats.f += (n)
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
unsigned32 space_available; /* current size of malloc area */
|
unsigned32 space_available; /* current size of malloc area */
|
||||||
@@ -48,9 +48,9 @@ struct {
|
|||||||
unsigned32 max_depth; /* most ever malloc'd at 1 time */
|
unsigned32 max_depth; /* most ever malloc'd at 1 time */
|
||||||
unsigned64 lifetime_allocated;
|
unsigned64 lifetime_allocated;
|
||||||
unsigned64 lifetime_freed;
|
unsigned64 lifetime_freed;
|
||||||
} malloc_stats;
|
} rtems_malloc_stats;
|
||||||
|
|
||||||
#else /* No malloc_stats */
|
#else /* No rtems_malloc_stats */
|
||||||
#define MSBUMP(f,n)
|
#define MSBUMP(f,n)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ void RTEMS_Malloc_Initialize(
|
|||||||
|
|
||||||
#ifdef MALLOC_STATS
|
#ifdef MALLOC_STATS
|
||||||
/* zero all the stats */
|
/* zero all the stats */
|
||||||
(void) memset(&malloc_stats, 0, sizeof(malloc_stats));
|
(void) memset(&rtems_malloc_stats, 0, sizeof(rtems_malloc_stats));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MSBUMP(space_available, length);
|
MSBUMP(space_available, length);
|
||||||
@@ -201,9 +201,9 @@ void *malloc(
|
|||||||
unsigned32 current_depth;
|
unsigned32 current_depth;
|
||||||
status = rtems_region_get_segment_size(RTEMS_Malloc_Heap, return_this, &actual_size);
|
status = rtems_region_get_segment_size(RTEMS_Malloc_Heap, return_this, &actual_size);
|
||||||
MSBUMP(lifetime_allocated, actual_size);
|
MSBUMP(lifetime_allocated, actual_size);
|
||||||
current_depth = malloc_stats.lifetime_allocated - malloc_stats.lifetime_freed;
|
current_depth = rtems_malloc_stats.lifetime_allocated - rtems_malloc_stats.lifetime_freed;
|
||||||
if (current_depth > malloc_stats.max_depth)
|
if (current_depth > rtems_malloc_stats.max_depth)
|
||||||
malloc_stats.max_depth = current_depth;
|
rtems_malloc_stats.max_depth = current_depth;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -314,23 +314,23 @@ void free(
|
|||||||
|
|
||||||
void malloc_dump(void)
|
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("Malloc stats\n");
|
||||||
printf(" avail:%uk allocated:%uk (%d%%) max:%uk (%d%%) lifetime:%Luk freed:%Luk\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,
|
(unsigned int) allocated / 1024,
|
||||||
/* avoid float! */
|
/* avoid float! */
|
||||||
(allocated * 100) / malloc_stats.space_available,
|
(allocated * 100) / rtems_malloc_stats.space_available,
|
||||||
(unsigned int) malloc_stats.max_depth / 1024,
|
(unsigned int) rtems_malloc_stats.max_depth / 1024,
|
||||||
(malloc_stats.max_depth * 100) / malloc_stats.space_available,
|
(rtems_malloc_stats.max_depth * 100) / rtems_malloc_stats.space_available,
|
||||||
(unsigned64) malloc_stats.lifetime_allocated / 1024,
|
(unsigned64) rtems_malloc_stats.lifetime_allocated / 1024,
|
||||||
(unsigned64) malloc_stats.lifetime_freed / 1024);
|
(unsigned64) rtems_malloc_stats.lifetime_freed / 1024);
|
||||||
printf(" Call counts: malloc:%d free:%d realloc:%d calloc:%d\n",
|
printf(" Call counts: malloc:%d free:%d realloc:%d calloc:%d\n",
|
||||||
malloc_stats.malloc_calls,
|
rtems_malloc_stats.malloc_calls,
|
||||||
malloc_stats.free_calls,
|
rtems_malloc_stats.free_calls,
|
||||||
malloc_stats.realloc_calls,
|
rtems_malloc_stats.realloc_calls,
|
||||||
malloc_stats.calloc_calls);
|
rtems_malloc_stats.calloc_calls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#if defined(RTEMS_NEWLIB)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT (c) 1994 by Division Incorporated
|
* COPYRIGHT (c) 1994 by Division Incorporated
|
||||||
@@ -30,6 +29,8 @@
|
|||||||
|
|
||||||
#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
|
#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
|
||||||
#include <rtems.h>
|
#include <rtems.h>
|
||||||
|
|
||||||
|
#if defined(RTEMS_NEWLIB)
|
||||||
#include <libcsupport.h>
|
#include <libcsupport.h>
|
||||||
#include <stdlib.h> /* for free() */
|
#include <stdlib.h> /* for free() */
|
||||||
#include <string.h> /* for memset() */
|
#include <string.h> /* for memset() */
|
||||||
@@ -346,6 +347,8 @@ int get_errno()
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#if !defined(RTEMS_UNIX) && !defined(__GO32__) && !defined(_AM29K)
|
#if !defined(RTEMS_UNIX) && !defined(__GO32__) && !defined(_AM29K)
|
||||||
void _exit(int status)
|
void _exit(int status)
|
||||||
{
|
{
|
||||||
|
|||||||
90
c/src/lib/libc/newlibif.c
Normal file
90
c/src/lib/libc/newlibif.c
Normal file
@@ -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 <rtems.h>
|
||||||
|
#if defined(RTEMS_NEWLIB)
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#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
|
||||||
@@ -23,16 +23,19 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h> /* only for puts */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fstat, stat, and isatty must lie consistently and report that everything
|
* fstat, stat, and isatty must lie consistently and report that everything
|
||||||
* is a tty or stdout will not be line buffered.
|
* 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 ) {
|
if ( _fd > 2 ) {
|
||||||
puts( "__fstat -- only stdio supported" );
|
puts( "__rtems_fstat -- only stdio supported" );
|
||||||
assert( 0 );
|
assert( 0 );
|
||||||
}
|
}
|
||||||
_sbuf->st_mode = S_IFCHR;
|
_sbuf->st_mode = S_IFCHR;
|
||||||
@@ -42,7 +45,7 @@ int __fstat(int _fd, struct stat* _sbuf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int __isatty(int _fd)
|
int __rtems_isatty(int _fd)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -52,7 +55,7 @@ int stat( const char *path, struct stat *buf )
|
|||||||
if ( strncmp( "/dev/", path, 5 ) ) {
|
if ( strncmp( "/dev/", path, 5 ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return __fstat( 0, buf );
|
return __rtems_fstat( 0, buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
int link( const char *existing, const char *new )
|
int link( const char *existing, const char *new )
|
||||||
@@ -67,4 +70,28 @@ int unlink( const char *path )
|
|||||||
return -1;
|
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
|
#endif
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#ifndef _RTEMS_LIBIO_H
|
#ifndef _RTEMS_LIBIO_H
|
||||||
#define _RTEMS_LIBIO_H
|
#define _RTEMS_LIBIO_H
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
typedef unsigned32 rtems_libio_offset_t;
|
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_config(rtems_configuration_table *config, unsigned32 max_fds);
|
||||||
void rtems_libio_init(void);
|
void rtems_libio_init(void);
|
||||||
|
|
||||||
int __open(const char *pathname, unsigned32 flag, unsigned32 mode);
|
int __rtems_open(const char *pathname, unsigned32 flag, unsigned32 mode);
|
||||||
int __close(int fd);
|
int __rtems_close(int fd);
|
||||||
int __read(int fd, void *buffer, unsigned32 count);
|
int __rtems_read(int fd, void *buffer, unsigned32 count);
|
||||||
int __write(int fd, const void *buffer, unsigned32 count);
|
int __rtems_write(int fd, const void *buffer, unsigned32 count);
|
||||||
int __ioctl(int fd, unsigned32 command, void *buffer);
|
int __rtems_ioctl(int fd, unsigned32 command, void *buffer);
|
||||||
int __lseek(int fd, rtems_libio_offset_t offset, int whence);
|
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 */
|
#endif /* _RTEMS_LIBIO_H */
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ rtems_libio_t *rtems_libio_last_iop;
|
|||||||
|
|
||||||
#define rtems_libio_check_fd(fd) \
|
#define rtems_libio_check_fd(fd) \
|
||||||
do { \
|
do { \
|
||||||
if ((fd) >= rtems_libio_number_iops) \
|
if ((unsigned32) (fd) >= rtems_libio_number_iops) \
|
||||||
{ \
|
{ \
|
||||||
errno = EBADF; \
|
errno = EBADF; \
|
||||||
return -1; \
|
return -1; \
|
||||||
@@ -243,7 +243,7 @@ rtems_libio_free(rtems_libio_t *iop)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__open(
|
__rtems_open(
|
||||||
const char *pathname,
|
const char *pathname,
|
||||||
unsigned32 flag,
|
unsigned32 flag,
|
||||||
unsigned32 mode)
|
unsigned32 mode)
|
||||||
@@ -254,10 +254,12 @@ __open(
|
|||||||
rtems_libio_open_close_args_t args;
|
rtems_libio_open_close_args_t args;
|
||||||
|
|
||||||
if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) {
|
if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) {
|
||||||
|
/*
|
||||||
if ( rc == RTEMS_UNSATISFIED ) {
|
if ( rc == RTEMS_UNSATISFIED ) {
|
||||||
puts( "open -- ENOSYS case" );
|
puts( "open -- ENOSYS case" );
|
||||||
assert( 0 );
|
assert( 0 );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +293,7 @@ done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__close(
|
__rtems_close(
|
||||||
int fd
|
int fd
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -316,7 +318,7 @@ __close(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__read(
|
__rtems_read(
|
||||||
int fd,
|
int fd,
|
||||||
void * buffer,
|
void * buffer,
|
||||||
unsigned32 count
|
unsigned32 count
|
||||||
@@ -352,7 +354,7 @@ __read(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__write(
|
__rtems_write(
|
||||||
int fd,
|
int fd,
|
||||||
const void *buffer,
|
const void *buffer,
|
||||||
unsigned32 count
|
unsigned32 count
|
||||||
@@ -388,7 +390,7 @@ __write(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__ioctl(
|
__rtems_ioctl(
|
||||||
int fd,
|
int fd,
|
||||||
unsigned32 command,
|
unsigned32 command,
|
||||||
void * buffer)
|
void * buffer)
|
||||||
@@ -420,7 +422,7 @@ __ioctl(
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
__lseek(
|
__rtems_lseek(
|
||||||
int fd,
|
int fd,
|
||||||
rtems_libio_offset_t offset,
|
rtems_libio_offset_t offset,
|
||||||
int whence
|
int whence
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ size_t RTEMS_Malloc_Sbrk_amount;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MALLOC_STATS
|
#ifdef MALLOC_STATS
|
||||||
#define MSBUMP(f,n) malloc_stats.f += (n)
|
#define MSBUMP(f,n) rtems_malloc_stats.f += (n)
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
unsigned32 space_available; /* current size of malloc area */
|
unsigned32 space_available; /* current size of malloc area */
|
||||||
@@ -48,9 +48,9 @@ struct {
|
|||||||
unsigned32 max_depth; /* most ever malloc'd at 1 time */
|
unsigned32 max_depth; /* most ever malloc'd at 1 time */
|
||||||
unsigned64 lifetime_allocated;
|
unsigned64 lifetime_allocated;
|
||||||
unsigned64 lifetime_freed;
|
unsigned64 lifetime_freed;
|
||||||
} malloc_stats;
|
} rtems_malloc_stats;
|
||||||
|
|
||||||
#else /* No malloc_stats */
|
#else /* No rtems_malloc_stats */
|
||||||
#define MSBUMP(f,n)
|
#define MSBUMP(f,n)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ void RTEMS_Malloc_Initialize(
|
|||||||
|
|
||||||
#ifdef MALLOC_STATS
|
#ifdef MALLOC_STATS
|
||||||
/* zero all the stats */
|
/* zero all the stats */
|
||||||
(void) memset(&malloc_stats, 0, sizeof(malloc_stats));
|
(void) memset(&rtems_malloc_stats, 0, sizeof(rtems_malloc_stats));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MSBUMP(space_available, length);
|
MSBUMP(space_available, length);
|
||||||
@@ -201,9 +201,9 @@ void *malloc(
|
|||||||
unsigned32 current_depth;
|
unsigned32 current_depth;
|
||||||
status = rtems_region_get_segment_size(RTEMS_Malloc_Heap, return_this, &actual_size);
|
status = rtems_region_get_segment_size(RTEMS_Malloc_Heap, return_this, &actual_size);
|
||||||
MSBUMP(lifetime_allocated, actual_size);
|
MSBUMP(lifetime_allocated, actual_size);
|
||||||
current_depth = malloc_stats.lifetime_allocated - malloc_stats.lifetime_freed;
|
current_depth = rtems_malloc_stats.lifetime_allocated - rtems_malloc_stats.lifetime_freed;
|
||||||
if (current_depth > malloc_stats.max_depth)
|
if (current_depth > rtems_malloc_stats.max_depth)
|
||||||
malloc_stats.max_depth = current_depth;
|
rtems_malloc_stats.max_depth = current_depth;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -314,23 +314,23 @@ void free(
|
|||||||
|
|
||||||
void malloc_dump(void)
|
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("Malloc stats\n");
|
||||||
printf(" avail:%uk allocated:%uk (%d%%) max:%uk (%d%%) lifetime:%Luk freed:%Luk\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,
|
(unsigned int) allocated / 1024,
|
||||||
/* avoid float! */
|
/* avoid float! */
|
||||||
(allocated * 100) / malloc_stats.space_available,
|
(allocated * 100) / rtems_malloc_stats.space_available,
|
||||||
(unsigned int) malloc_stats.max_depth / 1024,
|
(unsigned int) rtems_malloc_stats.max_depth / 1024,
|
||||||
(malloc_stats.max_depth * 100) / malloc_stats.space_available,
|
(rtems_malloc_stats.max_depth * 100) / rtems_malloc_stats.space_available,
|
||||||
(unsigned64) malloc_stats.lifetime_allocated / 1024,
|
(unsigned64) rtems_malloc_stats.lifetime_allocated / 1024,
|
||||||
(unsigned64) malloc_stats.lifetime_freed / 1024);
|
(unsigned64) rtems_malloc_stats.lifetime_freed / 1024);
|
||||||
printf(" Call counts: malloc:%d free:%d realloc:%d calloc:%d\n",
|
printf(" Call counts: malloc:%d free:%d realloc:%d calloc:%d\n",
|
||||||
malloc_stats.malloc_calls,
|
rtems_malloc_stats.malloc_calls,
|
||||||
malloc_stats.free_calls,
|
rtems_malloc_stats.free_calls,
|
||||||
malloc_stats.realloc_calls,
|
rtems_malloc_stats.realloc_calls,
|
||||||
malloc_stats.calloc_calls);
|
rtems_malloc_stats.calloc_calls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#if defined(RTEMS_NEWLIB)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT (c) 1994 by Division Incorporated
|
* COPYRIGHT (c) 1994 by Division Incorporated
|
||||||
@@ -30,6 +29,8 @@
|
|||||||
|
|
||||||
#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
|
#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
|
||||||
#include <rtems.h>
|
#include <rtems.h>
|
||||||
|
|
||||||
|
#if defined(RTEMS_NEWLIB)
|
||||||
#include <libcsupport.h>
|
#include <libcsupport.h>
|
||||||
#include <stdlib.h> /* for free() */
|
#include <stdlib.h> /* for free() */
|
||||||
#include <string.h> /* for memset() */
|
#include <string.h> /* for memset() */
|
||||||
@@ -346,6 +347,8 @@ int get_errno()
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#if !defined(RTEMS_UNIX) && !defined(__GO32__) && !defined(_AM29K)
|
#if !defined(RTEMS_UNIX) && !defined(__GO32__) && !defined(_AM29K)
|
||||||
void _exit(int status)
|
void _exit(int status)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user