syscalls.c

00001 /****************************************************************************
00002 *  Copyright (c) 2009 by Michael Fischer. All rights reserved.
00003 *
00004 *  Redistribution and use in source and binary forms, with or without
00005 *  modification, are permitted provided that the following conditions
00006 *  are met:
00007 *
00008 *  1. Redistributions of source code must retain the above copyright
00009 *     notice, this list of conditions and the following disclaimer.
00010 *  2. Redistributions in binary form must reproduce the above copyright
00011 *     notice, this list of conditions and the following disclaimer in the
00012 *     documentation and/or other materials provided with the distribution.
00013 *  3. Neither the name of the author nor the names of its contributors may
00014 *     be used to endorse or promote products derived from this software
00015 *     without specific prior written permission.
00016 *
00017 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00018 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
00021 *  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024 *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025 *  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027 *  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028 *  SUCH DAMAGE.
00029 *
00030 ****************************************************************************
00031 *  History:
00032 *
00033 *  28.03.09  mifi   First Version, based on the original syscall.c from
00034 *                   newlib version 1.17.0
00035 ****************************************************************************/
00036 
00037 #include <stdlib.h>
00038 #include <errno.h>
00039 #include <string.h>
00040 #include <sys/stat.h>
00041 #include <sys/types.h>
00042 
00043 /***************************************************************************/
00044 
00045 int _read_r (struct _reent *r, int file, char * ptr, int len)
00046 {
00047   r = r;
00048   file = file;
00049   ptr = ptr;
00050   len = len;
00051 
00052   errno = EINVAL;
00053   return -1;
00054 }
00055 
00056 /***************************************************************************/
00057 
00058 int _lseek_r (struct _reent *r, int file, int ptr, int dir)
00059 {
00060   r = r;
00061   file = file;
00062   ptr = ptr;
00063   dir = dir;
00064 
00065   return 0;
00066 }
00067 
00068 /***************************************************************************/
00069 
00070 int _write_r (struct _reent *r, int file, char * ptr, int len)
00071 {
00072   int index;
00073 
00074   r = r;
00075   file = file;
00076 
00077 
00078   for(index=0; index<len; index++)
00079   {
00080     if (ptr[index] == '\n')
00081     {
00082       uart1_putc('\r');
00083     }
00084 
00085     uart1_putc(ptr[index]);
00086   }
00087 
00088   return len;
00089 }
00090 
00091 /***************************************************************************/
00092 
00093 int _close_r (struct _reent *r, int file)
00094 {
00095   return 0;
00096 }
00097 
00098 /***************************************************************************/
00099 
00100 /* Register name faking - works in collusion with the linker.  */
00101 register char * stack_ptr asm ("sp");
00102 
00103 caddr_t _sbrk_r (struct _reent *r, int incr)
00104 {
00105   extern char   end asm ("end"); /* Defined by the linker.  */
00106   static char * heap_end;
00107   char *        prev_heap_end;
00108 
00109   if (heap_end == NULL)
00110     heap_end = & end;
00111 
00112   prev_heap_end = heap_end;
00113 
00114   if (heap_end + incr > stack_ptr)
00115   {
00116       /* Some of the libstdc++-v3 tests rely upon detecting
00117         out of memory errors, so do not abort here.  */
00118 #if 0
00119       extern void abort (void);
00120 
00121       _write (1, "_sbrk: Heap and stack collision\n", 32);
00122 
00123       abort ();
00124 #else
00125       errno = ENOMEM;
00126       return (caddr_t) -1;
00127 #endif
00128   }
00129 
00130   heap_end += incr;
00131 
00132   return (caddr_t) prev_heap_end;
00133 }
00134 
00135 /***************************************************************************/
00136 
00137 int _fstat_r (struct _reent *r, int file, struct stat * st)
00138 {
00139   r = r;
00140   file = file;
00141 
00142   memset (st, 0, sizeof (* st));
00143   st->st_mode = S_IFCHR;
00144   return 0;
00145 }
00146 
00147 /***************************************************************************/
00148 
00149 int _isatty_r(struct _reent *r, int fd)
00150 {
00151   r = r;
00152   fd = fd;
00153 
00154   return 1;
00155 }
00156 
00157 
00158 void _exit(void)
00159 {
00160     for(;;);
00161 }
00162 
00163 /*** EOF ***/
00164 
00165 

Generated on Mon Oct 18 07:40:46 2010 for Python-on-a-chip by  doxygen 1.5.9