1 /****************************************************************************
2 * Copyright (c) 2009 by Michael Fischer. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of its contributors may
14 * be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 ****************************************************************************
33 * 28.03.09 mifi First Version, based on the original syscall.c from
34 * newlib version 1.17.0
35 ****************************************************************************/
41 #include <sys/types.h>
43 /***************************************************************************/
45 int _read_r (struct _reent *r, int file, char * ptr, int len)
56 /***************************************************************************/
58 int _lseek_r (struct _reent *r, int file, int ptr, int dir)
68 /***************************************************************************/
70 int _write_r (struct _reent *r, int file, char * ptr, int len)
79 /* For example, output string by UART */
80 for(index=0; index<len; index++)
82 if (ptr[index] == '\n')
87 uart_putc(ptr[index]);
94 /***************************************************************************/
96 int _close_r (struct _reent *r, int file)
101 /***************************************************************************/
103 /* Register name faking - works in collusion with the linker. */
104 register char * stack_ptr __asm ("sp");
106 caddr_t _sbrk_r (struct _reent *r, int incr)
108 extern char end __asm ("end"); /* Defined by the linker. */
109 static char * heap_end;
110 char * prev_heap_end;
112 if (heap_end == NULL)
115 prev_heap_end = heap_end;
117 if (heap_end + incr > stack_ptr)
119 /* Some of the libstdc++-v3 tests rely upon detecting
120 out of memory errors, so do not abort here. */
122 extern void abort (void);
124 _write (1, "_sbrk: Heap and stack collision\n", 32);
135 return (caddr_t) prev_heap_end;
138 /***************************************************************************/
140 int _fstat_r (struct _reent *r, int file, struct stat * st)
145 memset (st, 0, sizeof (* st));
146 st->st_mode = S_IFCHR;
150 /***************************************************************************/
152 int _isatty_r(struct _reent *r, int fd)