• Main Page
  • Modules
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

syscalls.c

Go to the documentation of this file.
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 #include "uart/uart.h"
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   r = r;
00073   file = file;
00074   ptr = ptr;
00075 
00076 #if 1
00077   int index;
00078 
00079   /* For example, output string by UART */
00080   for(index=0; index<len; index++)
00081   {
00082     if (ptr[index] == '\n')
00083     {
00084       UARTTransmitByte('\r',UART_CH_0);
00085     }
00086 
00087     UARTTransmitByte(ptr[index],UART_CH_0);
00088   }
00089 #endif
00090 
00091   
00092   return len;
00093 }
00094 
00095 /***************************************************************************/
00096 
00097 int _close_r (struct _reent *r, int file)
00098 {
00099   return 0;
00100 }
00101 
00102 /***************************************************************************/
00103 
00104 /* Register name faking - works in collusion with the linker.  */
00105 register char * stack_ptr asm ("sp");
00106 
00107 caddr_t _sbrk_r (struct _reent *r, int incr)
00108 {
00109   extern char   end asm ("end"); /* Defined by the linker.  */
00110   static char * heap_end;
00111   unsigned long n;
00112   char *        prev_heap_end;
00113   if (heap_end == NULL)
00114     heap_end = &end;
00115   
00116   prev_heap_end = heap_end;
00117   
00118   if (heap_end + incr > stack_ptr)
00119   {
00120           uart_puts("\n Heap > stack");
00121       /* Some of the libstdc++-v3 tests rely upon detecting
00122         out of memory errors, so do not abort here.  */
00123 #if 0
00124       extern void DABT_Routine(void);
00125 
00126       n = (unsigned long)stack_ptr;
00127 
00128       uart_puts("0x");
00129       uart_putc('0' + ((n>>7) & 0xf));
00130       uart_putc('0' + ((n>>6) & 0xf));
00131       uart_putc('0' + ((n>>5) & 0xf));
00132       uart_putc('0' + ((n>>4) & 0xf));
00133       uart_putc('0' + ((n>>3) & 0xf));
00134       uart_putc('0' + ((n>>2) & 0xf));
00135       uart_putc('0' + ((n>>1) & 0xf));
00136       uart_putc('0' + ((n) & 0xf));
00137       uart_putc(' ');
00138 
00139       n = (unsigned long)(heap_end);
00140 
00141       uart_puts("0x");
00142       uart_putc('0' + ((n>>7) & 0xf));
00143       uart_putc('0' + ((n>>6) & 0xf));
00144       uart_putc('0' + ((n>>5) & 0xf));
00145       uart_putc('0' + ((n>>4) & 0xf));
00146       uart_putc('0' + ((n>>3) & 0xf));
00147       uart_putc('0' + ((n>>2) & 0xf));
00148       uart_putc('0' + ((n>>1) & 0xf));
00149       uart_putc('0' + ((n) & 0xf));
00150       uart_putc(' ');
00151 
00152       uart_puts("_sbrk: Heap and stack collision\n");
00153       
00154       DABT_Routine ();
00155 #else
00156       errno = ENOMEM;
00157       return (caddr_t) -1;
00158 #endif
00159   }
00160   
00161   heap_end += incr;
00162 
00163   return (caddr_t) prev_heap_end;
00164 }
00165 
00166 /***************************************************************************/
00167 
00168 int _fstat_r (struct _reent *r, int file, struct stat * st)
00169 {
00170   r = r; 
00171   file = file;
00172    
00173   memset (st, 0, sizeof (* st));
00174   st->st_mode = S_IFCHR;
00175   return 0;
00176 }
00177 
00178 /***************************************************************************/
00179 
00180 int _isatty_r(struct _reent *r, int fd)
00181 {
00182   r = r;
00183   fd = fd;
00184    
00185   return 1;
00186 }
00187 
00188 /*** EOF ***/
00189 
00190 

Generated on Fri Jun 17 2011 01:55:43 for Mult-UIP by  doxygen 1.7.1