From 11ab92947ee57ff83bc7d6f0cd0d68b58373b975 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Fri, 26 Aug 1994 06:15:17 +0000 Subject: [PATCH] Initial revision --- bare/Makefile | 54 ++++++++++++++ sysdeps/i960/Implies | 2 + sysdeps/i960/ffs.c | 43 +++++++++++ sysdeps/standalone/Subdirs | 4 ++ sysdeps/standalone/brk.c | 68 ++++++++++++++++++ sysdeps/standalone/close.c | 42 +++++++++++ sysdeps/standalone/filedesc.h | 48 +++++++++++++ sysdeps/standalone/open.c | 124 ++++++++++++++++++++++++++++++++ sysdeps/standalone/read.c | 85 ++++++++++++++++++++++ sysdeps/standalone/standalone.h | 32 +++++++++ sysdeps/standalone/stdio_lim.h | 27 +++++++ sysdeps/standalone/write.c | 72 +++++++++++++++++++ 12 files changed, 601 insertions(+) create mode 100644 bare/Makefile create mode 100644 sysdeps/i960/Implies create mode 100644 sysdeps/i960/ffs.c create mode 100644 sysdeps/standalone/Subdirs create mode 100644 sysdeps/standalone/brk.c create mode 100644 sysdeps/standalone/close.c create mode 100644 sysdeps/standalone/filedesc.h create mode 100644 sysdeps/standalone/open.c create mode 100644 sysdeps/standalone/read.c create mode 100644 sysdeps/standalone/standalone.h create mode 100644 sysdeps/standalone/stdio_lim.h create mode 100644 sysdeps/standalone/write.c diff --git a/bare/Makefile b/bare/Makefile new file mode 100644 index 0000000000..bb1807f9c7 --- /dev/null +++ b/bare/Makefile @@ -0,0 +1,54 @@ +# Copyright (C) 1994 Free Software Foundation, Inc. +# Contributed by Joel Sherrill (jsherril@redstone-emh2.army.mil), +# On-Line Applications Research Corporation. +# +# This file is part of the GNU C Library. +# +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# The GNU C Library 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 +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with the GNU C Library; see the file COPYING.LIB. If +# not, write to the Free Software Foundation, Inc., 675 Mass Ave, +# Cambridge, MA 02139, USA. + +subdir := bare + +bare-routines := brdinit console strtsupp +extra-objs = $(bare-routines:%=%.o) +distribute = $(bare-routines:%=%.c) + +install-lib = lib$(config-vendor).a + +include ../Rules + +# +# For bare targets, the $(config-vendor) is the name of the board. +# We will place the board dependent code ONLY in a library which +# is board dependent. This way many target boards can share a +# single libc.a. To resolve all symbols and successfully link +# a program, the application must link against libc.a and libMY_TARGET.a. +# For example, the target specific library for the Motorola MVME135 +# board will be named libmvme135.a. To link a program for the +# MVME135, one must link against -lc and -lmvme135. +# + +lib: $(objpfx)lib$(config-vendor).a + +$(objpfx)lib$(config-vendor).a: $(bare-routines:%=$(objpfx)%.o) +# This library is small enough that it's simplest to recreate the archive +# from scratch each time. + rm -f $@ +ifdef objdir + cd $(objdir); $(AR) cq$(verbose) $@ $(^:$(objpfx)%=%) +else + $(AR) cq$(verbose) $@ $^ +endif + $(RANLIB) $@ diff --git a/sysdeps/i960/Implies b/sysdeps/i960/Implies new file mode 100644 index 0000000000..f8c4079ab5 --- /dev/null +++ b/sysdeps/i960/Implies @@ -0,0 +1,2 @@ +# i960 family uses IEEE 754 floating point. +ieee754 diff --git a/sysdeps/i960/ffs.c b/sysdeps/i960/ffs.c new file mode 100644 index 0000000000..62b8742da7 --- /dev/null +++ b/sysdeps/i960/ffs.c @@ -0,0 +1,43 @@ +/* ffs -- find first set bit in a word, counted from least significant end. + For i960 Core architecture + Copyright (C) 1994 Free Software Foundation, Inc. + Contributed by Joel Sherrill (jsherril@redstone-emh2.army.mil), + On-Line Applications Research Corporation. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include +#include + +#undef ffs + +#if defined (__GNUC__) && defined (__i960__) + +int +DEFUN(ffs, (x), int x) +{ + int cnt; + + asm("scanbit %1,%0" : "=d" (cnt) : "rm" (x & -x)); + + return cnt; +} + +#else + +#include + +#endif diff --git a/sysdeps/standalone/Subdirs b/sysdeps/standalone/Subdirs new file mode 100644 index 0000000000..4125ae86db --- /dev/null +++ b/sysdeps/standalone/Subdirs @@ -0,0 +1,4 @@ +# The `bare' subdirectory defines some structure for a target-specific +# library of functions which are actually implemented in +# sysdeps/standalone/CPU/TARGET. +bare diff --git a/sysdeps/standalone/brk.c b/sysdeps/standalone/brk.c new file mode 100644 index 0000000000..be9174c8dd --- /dev/null +++ b/sysdeps/standalone/brk.c @@ -0,0 +1,68 @@ +/* Copyright (C) 1991, 1994 Free Software Foundation, Inc. + Ported to standalone by Joel Sherrill jsherril@redstone-emh2.army.mil, + On-Line Applications Research Corporation. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include +#include + +PTR __curbrk; +PTR __rorig; +PTR __rlimit; + +int +DEFUN(__brk, (inaddr), PTR inaddr) +{ + + if ( ( (void *)inaddr > (void *)__rlimit ) || + ( (void *)inaddr < (void *)__rorig ) ) + return -1; + + __curbrk = inaddr; + return 0; +} + +/* Initialization Code for Memory Allocation */ + +PTR __C_heap_start; +int __C_heap_size; + +#ifdef HAVE_GNU_LD +static +#endif +void +DEFUN(__NONE_set_memvals, (argc, argv, envp), + int argc AND char **argv AND char **envp) +{ + + __rorig = + __curbrk = __C_heap_start; + __rlimit = __curbrk + __C_heap_size; + + (void) &__NONE_set_memvals; /* Avoid "defined but not used" warning. */ +} + +#ifdef HAVE_GNU_LD + +#include + +text_set_element (__libc_subinit, __NONE_set_memvals); + +#endif + diff --git a/sysdeps/standalone/close.c b/sysdeps/standalone/close.c new file mode 100644 index 0000000000..d7674ae676 --- /dev/null +++ b/sysdeps/standalone/close.c @@ -0,0 +1,42 @@ +/* Copyright (C) 1994 Free Software Foundation, Inc. + Ported to standalone by Joel Sherrill jsherril@redstone-emh2.army.mil, + On-Line Applications Research Corporation. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include +#include +#include + +#include +#include "filedesc.h" + +/* Close the file descriptor FD. */ +int +DEFUN(__close, (fd), int fd) +{ + if ( !__FD_Is_valid( fd ) || !__FD_Table[ fd ].in_use ) + { + errno = EBADF; + return -1; + } + + __FD_Table[ fd ].in_use = 0; + return 0; +} + diff --git a/sysdeps/standalone/filedesc.h b/sysdeps/standalone/filedesc.h new file mode 100644 index 0000000000..bf3b6a9f0c --- /dev/null +++ b/sysdeps/standalone/filedesc.h @@ -0,0 +1,48 @@ +/* Copyright (C) 1994 Free Software Foundation, Inc. + Ported to standalone by Joel Sherrill jsherril@redstone-emh2.army.mil, + On-Line Applications Research Corporation. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +/* + * This is the file descriptor used by the no OS implementation + * of __open, __read, __write, and __close. + */ + +#ifndef __FILEDESC_h +#define __FILEDESC_h + +#include + +#ifndef __DECLARE_FILE_DESCRIPTORS__ +#define FILEDESC_EXTERN extern +#else +#define FILEDESC_EXTERN +#endif + +typedef struct { + int in_use; /* 1 if in use, 0 otherwise */ + int flags; /* Flags from open */ +} __no_os_file_descriptor; + +#define __FD_Is_valid( _fd ) \ + ( (_fd) >= 0 && (_fd) < FOPEN_MAX ) + +FILEDESC_EXTERN __no_os_file_descriptor __FD_Table[ FOPEN_MAX ]; + +#endif diff --git a/sysdeps/standalone/open.c b/sysdeps/standalone/open.c new file mode 100644 index 0000000000..fdcaf65134 --- /dev/null +++ b/sysdeps/standalone/open.c @@ -0,0 +1,124 @@ +/* Copyright (C) 1994 Free Software Foundation, Inc. + Ported to standalone by Joel Sherrill jsherril@redstone-emh2.army.mil, + On-Line Applications Research Corporation. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#define __DECLARE_FILE_DESCRIPTORS__ + +#include "filedesc.h" + +/* Open FILE with access OFLAG. If OFLAG includes O_CREAT, + a third argument is the file protection. */ +int +DEFUN(__open, (file, oflag), CONST char *file AND int oflag DOTS) +{ + int mode; + int newfd; + int index; + + if (file == NULL) + { + errno = EINVAL; + return -1; + } + + if (oflag & O_CREAT) + { + va_list arg; + va_start(arg, oflag); + mode = va_arg(arg, int); + va_end(arg); + } + + /* + * Find an open slot. + */ + + newfd = -1; + + for ( index=0 ; index< FOPEN_MAX ; index++ ) + if ( !__FD_Table[ index ].in_use ) { + newfd = index; + break; + } + + if ( newfd == -1 ) { + errno = ENFILE; + return -1; + } + + /* + * Initialize the open slot + */ + + __FD_Table[ newfd ].in_use = 1; + __FD_Table[ newfd ].flags = oflag; + + return newfd; +} + +/* Initialization Code for Console I/O */ + +#ifdef HAVE_GNU_LD +static +#endif +void +DEFUN(__NONE_init_console_io, (argc, argv, envp), + int argc AND char **argv AND char **envp) +{ + int index; + + for ( index=0 ; index< FOPEN_MAX ; index++ ) + __FD_Table[ index ].in_use = 0; + + stdin = fopen( "", "r" ); + + stdout = fopen( "", "w" ); + + stderr = fopen( "", "w" ); + + /* + * Line buffer the standard input and output and use no buffering for + * standard error. + */ + + setvbuf( stdin, NULL, _IOLBF, BUFSIZ ); + setvbuf( stdout, NULL, _IOLBF, BUFSIZ ); + setvbuf( stderr, NULL, _IONBF, BUFSIZ ); + + (void) &__NONE_init_console_io; /* Avoid "defined but not used" warning. */ +} + +#ifdef HAVE_GNU_LD + +#include + +text_set_element (__libc_subinit, __NONE_init_console_io); + +#endif diff --git a/sysdeps/standalone/read.c b/sysdeps/standalone/read.c new file mode 100644 index 0000000000..1c87b1103a --- /dev/null +++ b/sysdeps/standalone/read.c @@ -0,0 +1,85 @@ +/* Copyright (C) 1994 Free Software Foundation, Inc. + Ported to standalone by Joel Sherrill jsherril@redstone-emh2.army.mil, + On-Line Applications Research Corporation. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include +#include +#include +#include + +#include "filedesc.h" +#include +#include + +/* Read NBYTES into BUF from FD. Return the number read or -1. */ +ssize_t +DEFUN(__read, (fd, buf, nbytes), + int fd AND PTR buf AND size_t nbytes) +{ + char *buffer = (char *) buf; + int data; + int poll; + + errno = 0; + + if (nbytes == 0) + return 0; + + if ( !__FD_Is_valid( fd ) || !__FD_Table[ fd ].in_use ) + { + errno = EBADF; + return -1; + } + if (buf == NULL) + { + errno = EINVAL; + return -1; + } + + if ( __FD_Table[ fd ].flags & O_WRONLY ) /* is it write only? */ + { + errno = EBADF; + return -1; + } + + /* If this is a non-blocking fd, then we want to poll the console. */ + + poll = ( __FD_Table[ fd ].flags & O_NONBLOCK ) ? 1 : 0; + + /* Read a single character. This is a cheap way to insure that the + upper layers get every character because _Console_Getc can't timeout + or otherwise know when to stop. */ + + + data = _Console_Getc(poll); + + if ( data == -1 ) /* if no data return */ + return -1; + + (void) _Console_Putc(data); /* echo the character */ + + if ( data == '\r' ) { /* translate CR -> CR/LF */ + (void) _Console_Putc('\n'); + data = '\n'; + } + + *buffer = data; + return 1; +} diff --git a/sysdeps/standalone/standalone.h b/sysdeps/standalone/standalone.h new file mode 100644 index 0000000000..07f83559c7 --- /dev/null +++ b/sysdeps/standalone/standalone.h @@ -0,0 +1,32 @@ +/* Copyright (C) 1994 Free Software Foundation, Inc. + Contributed by Joel Sherrill (jsherril@redstone-emh2.army.mil), + On-Line Applications Research Corporation. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#ifndef _STANDALONE_H +#define _STANDALONE_H + +#include + +extern void _Board_Initialize __PP ((void)); + +extern int _Console_Putc __P ((char c)); +extern int _Console_Getc __P ((int poll)); + +#endif diff --git a/sysdeps/standalone/stdio_lim.h b/sysdeps/standalone/stdio_lim.h new file mode 100644 index 0000000000..5552bc4325 --- /dev/null +++ b/sysdeps/standalone/stdio_lim.h @@ -0,0 +1,27 @@ +/* Copyright (C) 1994 Free Software Foundation, Inc. + Ported to standalone by Joel Sherrill jsherril@redstone-emh2.army.mil, + On-Line Applications Research Corporation. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#define L_tmpnam 1 +#define TMPMAX 0 +#define L_ctermid 1 +#define L_cuserid 1 +#define FOPEN_MAX 16 +#define FILENAME_MAX 14 diff --git a/sysdeps/standalone/write.c b/sysdeps/standalone/write.c new file mode 100644 index 0000000000..22c01a4f04 --- /dev/null +++ b/sysdeps/standalone/write.c @@ -0,0 +1,72 @@ +/* Copyright (C) 1994 Free Software Foundation, Inc. + Ported to standalone by Joel Sherrill jsherril@redstone-emh2.army.mil, + On-Line Applications Research Corporation. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include +#include +#include +#include +#include + +#include "filedesc.h" +#include +#include + +/* Write NBYTES of BUF to FD. Return the number written, or -1. */ +ssize_t +DEFUN(__write, (fd, buf, nbytes), + int fd AND CONST PTR buf AND size_t nbytes) +{ + int count; + CONST char *data = buf; + + if (nbytes == 0) + return 0; + if ( !__FD_Is_valid( fd ) || !__FD_Table[ fd ].in_use ) + { + errno = EBADF; + return -1; + } + if (buf == NULL) + { + errno = EINVAL; + return -1; + } + + if ( !(__FD_Table[ fd ].flags & (O_WRONLY|O_RDWR)) ) /* is it writeable? */ + { + errno = EBADF; + return -1; + } + + /* + * All open file descriptors are mapped to the console. + */ + + for ( count=0 ; count != nbytes ; count++ ) { + if ( _Console_Putc(data[ count ]) == -1 ) + return -1; + if ( data[count] == '\n' && _Console_Putc('\r') == -1 ) + return -1; + } + + return count; +} +