-/* -------------------------------- Arctic Core ------------------------------
- * Arctic Core - the open source AUTOSAR platform http://arccore.com
- *
- * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
- *
- * This source code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published by the
- * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
- *
- * This program 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 General Public License
- * for more details.
- * -------------------------------- Arctic Core ------------------------------*/
-
-
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include "Std_Types.h"
-#include "Ramlog.h"
-
-#if defined(CFG_ARM_CM3)
-#include "irq.h"
-#include "core_cm3.h"
-#endif
-
-
-#if defined(CFG_ARM)
-#define open _open
-#define exit _exit
-#define fstat _fstat
-#define getpid _getpid
-#define kill _kill
-#define close _close
-#define isatty _isatty
-#define sbrk _sbrk
-#define read _read
-#define write _write
-#define lseek _lseek
-#endif
-
-// Operation on Winidea terminal buffer
-#define TWBUFF_SIZE 0x100
-#define TRBUFF_SIZE 0x100
-
-#define TBUFF_PTR 2
-
-#define TWBUFF_LEN (TWBUFF_SIZE+TBUFF_PTR)
-#define TRBUFF_LEN (TRBUFF_SIZE+TBUFF_PTR)
-#define TWBUFF_TPTR (g_TWBuffer[TWBUFF_SIZE+0])
-#define TWBUFF_CPTR (g_TWBuffer[TWBUFF_SIZE+1])
-#define TWBUFF_INC(n) ((n + 1)&(TWBUFF_SIZE-1))
-#define TWBUFF_FULL() (TWBUFF_TPTR==((TWBUFF_CPTR-1)&(TWBUFF_SIZE-1)))
-
-#ifdef USE_WINIDEA_TERM
-static volatile unsigned char g_TWBuffer[TWBUFF_LEN] __attribute__ ((aligned (0x100))); // Transmit to WinIDEA terminal
-static volatile unsigned char g_TRBuffer[TRBUFF_LEN] __attribute__ ((aligned (0x100)));
-static volatile char g_TConn __attribute__ ((section (".winidea_port")));
-#endif
-
-#define FILE_RAMLOG 3
-
-/*
- * T32 stuff
- */
-
-// This must be in un-cached space....
-static volatile char t32_outport __attribute__ ((section (".t32_outport")));
-
-
-
-
-void t32_writebyte(char c)
-{
- /* T32 can hang here for several reasons;
- * - term.view e:address.offset(v.address(t32_outport)) e:0
- */
-
- while (t32_outport != 0 ) ; /* wait until port is free */
- t32_outport = c; /* send character */
-}
-
-/*
- * clib support
- */
-
-/* Do nothing */
-int close( int fd ) {
- (void)fd;
- return (-1);
-}
-
-char *__env[1] = { 0 };
-char **environ = __env;
-
-
-#include <errno.h>
-#undef errno
-extern int errno;
-
-int execve(char *name, char **argv, char **env){
- (void)name;
- (void)argv;
- (void)env;
- errno=ENOMEM;
- return -1;
-}
-
-int fork() {
- errno=EAGAIN;
- return -1;
-}
-
-#include <sys/stat.h>
-int fstat(int file, struct stat *st) {
- (void)file;
- st->st_mode = S_IFCHR;
- return 0;
-}
-
-/* Returns 1 if connected to a terminal. T32 can be a terminal
- */
-
-int isatty( int fd )
-{
- (void)fd;
- return 1;
-}
-
-/*
-int fstat( int fd, struct stat *buf )
-{
- buf->st_mode = S_IFCHR;
- buf->st_blksize = 0;
-
- return (0);
-}
-*/
-
-/* reposition read/write file offset
- * We can't seek, return error.*/
-off_t lseek( int fd, off_t offset,int whence)
-{
- (void)fd;
- (void)offset;
- (void)whence;
-
- errno = ESPIPE;
- return ((off_t)-1);
-}
-
-int open(const char *name, int flags, int mode){
- (void)name;
- (void)flags;
- (void)mode;
-
- if( strcmp(name,"ramlog") == 0 ) {
- return FILE_RAMLOG;
- }
-
- return -1;
-}
-
-int read( int fd, char *buf, int nbytes )
-{
- (void)fd;
- (void)buf;
- (void)nbytes;
-#ifdef USE_WINIDEA_TERM
- (void)g_TRBuffer[0];
-#endif
-
- /* Only support write for now, return 0 read */
- return 0;
-}
-
-
-int write( int fd, char *buf, int nbytes)
-{
- //(void)fd; // Normally 0- ?, 1-stdout, 2-stderr,
- // Added 3-ramlog,
-
- if( fd < 3 ) {
-#ifdef USE_WINIDEA_TERM
- if (g_TConn)
- {
- unsigned char nCnt,nLen;
- for(nCnt=0; nCnt<nbytes; nCnt++)
- {
- while(TWBUFF_FULL());
- nLen=TWBUFF_TPTR;
- g_TWBuffer[nLen]=buf[nCnt];
- nLen=TWBUFF_INC(nLen);
- TWBUFF_TPTR=nLen;
- }
- }
-#endif
-
-#ifdef USE_T32_TERM
- for (int i = 0; i < nbytes; i++) {
- if (*(buf + i) == '\n') {
- t32_writebyte ('\r');
-// t32_writebyte ('\n');
- }
- t32_writebyte (*(buf + i));
- }
-#endif
-#ifdef USE_ARM_ITM_TERM
- for (int i = 0; i < nbytes; i++) {
- ITM_SendChar(*(buf + i));
- }
-#endif
-
- }
- else
- {
-#if defined(USE_RAMLOG)
- /* RAMLOG support */
- if(fd == FILE_RAMLOG) {
- for (int i = 0; i < nbytes; i++) {
- ramlog_chr (*(buf + i));
- }
- }
-#endif
- }
-
- return (nbytes);
-}
-
-int arc_putchar(int c) {
- char cc = c;
- write( 1,&cc,1);
-
- return 0;
-}
-
-/* If we use malloc and it runs out of memory it calls sbrk()
- */
-#if 1
-
-extern char _end[];
-
-//static char *curbrk = _end;
-
-#ifndef HEAPSIZE
-#define HEAPSIZE 16000
-#endif
-
-/*
- * The heap sadly have alignment that depends on the pagesize that
- * you compile malloc newlib with. From what I can tell from the
- * code that is a pagesize of 4096.
- */
-
-unsigned char _heap[HEAPSIZE] __attribute__((aligned (4)));
-//__attribute__((section(".heap")));
-
-caddr_t sbrk( int incr )
-{
- static unsigned char *heap_end;
- unsigned char *prev_heap_end;
-
-/* initialize */
- if( heap_end == 0 )
- heap_end = _heap;
-
- prev_heap_end = heap_end;
-
- if( heap_end + incr - _heap > HEAPSIZE ) {
- /* heap overflow - announce on stderr */
- write( 2, "Heap overflow!\n", 15 );
- abort();
- }
-
- heap_end += incr;
-
- return (caddr_t) prev_heap_end;
-}
-#else
-void *sbrk(int inc )
-{
- /* We use our own malloc */
- return (void *)(-1);
-}
-#endif
-
-int stat( const char *file, struct stat *st ) {
-//int stat(char *file, struct stat *st) {
- (void)file;
- st->st_mode = S_IFCHR;
- return 0;
-}
-
-
-int getpid() {
- return 1;
-}
-
-#include <errno.h>
-#undef errno
-extern int errno;
-int kill(int pid, int sig){
- (void)pid;
- (void)sig;
- errno=EINVAL;
- return(-1);
-}
-
-
-/* Should not really be here, but .. */
-
-void _fini( void )
-{
-
-}
-
-
-void __init( void )
-{
-
-}
-#if defined(CFG_ARM)
-void _exit( int status ) {
- while(1);
-}
-#endif
-
+/* -------------------------------- Arctic Core ------------------------------\r
+ * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
+ *\r
+ * Copyright (C) 2009 ArcCore AB <contact@arccore.com>\r
+ *\r
+ * This source code is free software; you can redistribute it and/or modify it\r
+ * under the terms of the GNU General Public License version 2 as published by the\r
+ * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
+ *\r
+ * This program is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
+ * for more details.\r
+ * -------------------------------- Arctic Core ------------------------------*/\r
+\r
+\r
+#include <unistd.h>\r
+#include <sys/stat.h>\r
+#include <sys/types.h>\r
+#include <errno.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include <stddef.h>\r
+#include "Std_Types.h"\r
+#include "Ramlog.h"\r
+\r
+#if defined(CFG_ARM_CM3)\r
+#include "irq_types.h"\r
+#include "stm32f10x.h"\r
+#endif\r
+\r
+#ifdef USE_TTY_TCF_STREAMS\r
+#include "streams.h"\r
+#endif\r
+\r
+\r
+#if defined(CFG_ARM)\r
+#define open _open\r
+#define exit _exit\r
+#define fstat _fstat\r
+#define getpid _getpid\r
+#define kill _kill\r
+#define close _close\r
+#define isatty _isatty\r
+#define sbrk _sbrk\r
+#define read _read\r
+#define write _write\r
+#define lseek _lseek\r
+#endif\r
+\r
+// Operation on Winidea terminal buffer\r
+\r
+\r
+#define TWBUFF_SIZE 0x100\r
+#define TRBUFF_SIZE 0x100\r
+\r
+\r
+#define TBUFF_PTR 2\r
+\r
+#define TWBUFF_LEN (TWBUFF_SIZE+TBUFF_PTR)\r
+#define TRBUFF_LEN (TRBUFF_SIZE+TBUFF_PTR)\r
+#define TWBUFF_TPTR (g_TWBuffer[TWBUFF_SIZE+0])\r
+#define TWBUFF_CPTR (g_TWBuffer[TWBUFF_SIZE+1])\r
+#define TWBUFF_INC(n) ((n + 1)&(TWBUFF_SIZE-1))\r
+#define TWBUFF_FULL() (TWBUFF_TPTR==((TWBUFF_CPTR-1)&(TWBUFF_SIZE-1)))\r
+\r
+#ifdef USE_TTY_WINIDEA\r
+\r
+#if defined(MC912DG128A)\r
+static volatile unsigned char g_TWBuffer[TWBUFF_LEN];\r
+static volatile unsigned char g_TRBuffer[TRBUFF_LEN];\r
+volatile char g_TConn __attribute__ ((section (".winidea_port")));\r
+\r
+#else\r
+static volatile unsigned char g_TWBuffer[TWBUFF_LEN] __attribute__ ((aligned (0x100))); // Transmit to WinIDEA terminal\r
+static volatile unsigned char g_TRBuffer[TRBUFF_LEN] __attribute__ ((aligned (0x100)));\r
+volatile char g_TConn __attribute__ ((section (".winidea_port")));\r
+\r
+#endif\r
+\r
+#endif\r
+\r
+#ifdef USE_TTY_CODE_COMPOSER\r
+\r
+#define _DTOPEN (0xF0)\r
+#define _DTCLOSE (0xF1)\r
+#define _DTREAD (0xF2)\r
+#define _DTWRITE (0xF3)\r
+#define _DTLSEEK (0xF4)\r
+#define _DTUNLINK (0xF5)\r
+#define _DTGETENV (0xF6)\r
+#define _DTRENAME (0xF7)\r
+#define _DTGETTIME (0xF8)\r
+#define _DTGETCLK (0xF9)\r
+#define _DTSYNC (0xFF)\r
+\r
+#define LOADSHORT(x,y,z) { x[(z)] = (unsigned short) (y); \\r
+ x[(z)+1] = (unsigned short) (y) >> 8; }\r
+\r
+#define UNLOADSHORT(x,z) ((short) ( (short) x[(z)] + \\r
+ ((short) x[(z)+1] << 8)))\r
+\r
+#define PACKCHAR(val, base, byte) ( (base)[(byte)] = (val) )\r
+\r
+#define UNPACKCHAR(base, byte) ( (base)[byte] )\r
+\r
+\r
+static unsigned char parmbuf[8];\r
+#define CC_BUFSIZ 512\r
+#define CC_BUFFER_SIZE ((CC_BUFSIZ)+32)\r
+volatile unsigned int _CIOBUF_[CC_BUFFER_SIZE] __attribute__ ((section (".cio")));\r
+static unsigned char CIOTMPBUF[CC_BUFSIZ];\r
+static uint16 cio_tmp_buf_index = 0;\r
+\r
+/***************************************************************************/\r
+/* */\r
+/* WRITEMSG() - Sends the passed data and parameters on to the host. */\r
+/* */\r
+/***************************************************************************/\r
+void writemsg(unsigned char command,\r
+ register const unsigned char *parm,\r
+ register const char *data,\r
+ unsigned int length)\r
+{\r
+ volatile unsigned char *p = (volatile unsigned char *)(_CIOBUF_+1);\r
+ unsigned int i;\r
+\r
+ /***********************************************************************/\r
+ /* THE LENGTH IS WRITTEN AS A TARGET INT */\r
+ /***********************************************************************/\r
+ _CIOBUF_[0] = length;\r
+\r
+ /***********************************************************************/\r
+ /* THE COMMAND IS WRITTEN AS A TARGET BYTE */\r
+ /***********************************************************************/\r
+ *p++ = command;\r
+\r
+ /***********************************************************************/\r
+ /* PACK THE PARAMETERS AND DATA SO THE HOST READS IT AS BYTE STREAM */\r
+ /***********************************************************************/\r
+ for (i = 0; i < 8; i++) PACKCHAR(*parm++, p, i);\r
+ for (i = 0; i < length; i++) PACKCHAR(*data++, p, i+8);\r
+\r
+ /***********************************************************************/\r
+ /* THE BREAKPOINT THAT SIGNALS THE HOST TO DO DATA TRANSFER */\r
+ /***********************************************************************/\r
+ __asm(" .global C$$IO$$");\r
+ __asm("C$$IO$$: nop");\r
+}\r
+\r
+/***************************************************************************/\r
+/* */\r
+/* READMSG() - Reads the data and parameters passed from the host. */\r
+/* */\r
+/***************************************************************************/\r
+void readmsg(register unsigned char *parm,\r
+ register char *data)\r
+{\r
+ volatile unsigned char *p = (volatile unsigned char *)(_CIOBUF_+1);\r
+ unsigned int i;\r
+ unsigned int length;\r
+\r
+ /***********************************************************************/\r
+ /* THE LENGTH IS READ AS A TARGET INT */\r
+ /***********************************************************************/\r
+ length = _CIOBUF_[0];\r
+\r
+ /***********************************************************************/\r
+ /* UNPACK THE PARAMETERS AND DATA */\r
+ /***********************************************************************/\r
+ for (i = 0; i < 8; i++) *parm++ = UNPACKCHAR(p, i);\r
+ if (data != NULL)\r
+ for (i = 0; i < length; i++) *data++ = UNPACKCHAR(p, i+8);\r
+}\r
+\r
+/****************************************************************************/\r
+/* HOSTWRITE() - Pass the write command and its arguments to the host. */\r
+/****************************************************************************/\r
+int HOSTwrite(int dev_fd, const char *buf, unsigned count)\r
+{\r
+ int result;\r
+\r
+ // WARNING. Can only handle count == 1!\r
+ if (count != 1) _exit(1);\r
+\r
+ if (count > CC_BUFSIZ) count = CC_BUFSIZ;\r
+\r
+ if (cio_tmp_buf_index < CC_BUFSIZ) {\r
+ CIOTMPBUF[cio_tmp_buf_index++] = *buf;\r
+\r
+ if (*buf != 0xA) { // Only flush if newline\r
+ return 0;\r
+ }\r
+ }\r
+\r
+\r
+ LOADSHORT(parmbuf,dev_fd,0);\r
+ LOADSHORT(parmbuf,cio_tmp_buf_index,2);\r
+ writemsg(_DTWRITE,parmbuf,(char *)CIOTMPBUF,cio_tmp_buf_index);\r
+ readmsg(parmbuf,NULL);\r
+\r
+ result = UNLOADSHORT(parmbuf,0);\r
+\r
+ cio_tmp_buf_index = 0;\r
+\r
+ return result;\r
+}\r
+\r
+#endif\r
+\r
+#ifdef USE_TTY_TMS570_KEIL\r
+#include "GLCD.h"\r
+#endif\r
+\r
+#define FILE_RAMLOG 3\r
+\r
+/* Location MUST match NoICE configuration */\r
+#ifdef USE_TTY_NOICE\r
+static volatile char VUART_TX __attribute__ ((section (".noice_port")));\r
+static volatile char VUART_RX __attribute__ ((section (".noice_port")));\r
+volatile unsigned char START_VUART = 0;\r
+#endif\r
+\r
+/*\r
+ * T32 stuff\r
+ */\r
+\r
+// This must be in un-cached space....\r
+#ifdef USE_TTY_T32\r
+static volatile char t32_outport __attribute__ ((section (".t32_outport")));\r
+\r
+void t32_writebyte(char c)\r
+{\r
+ /* T32 can hang here for several reasons;\r
+ * - term.view e:address.offset(v.address(t32_outport)) e:0\r
+ */\r
+\r
+ while (t32_outport != 0 ) ; /* wait until port is free */\r
+ t32_outport = c; /* send character */\r
+}\r
+#endif\r
+/*\r
+ * clib support\r
+ */\r
+\r
+/* Do nothing */\r
+int close( int fd ) {\r
+ (void)fd;\r
+ return (-1);\r
+}\r
+\r
+char *__env[1] = { 0 };\r
+char **environ = __env;\r
+\r
+\r
+#include <errno.h>\r
+#undef errno\r
+extern int errno;\r
+\r
+\r
+int execve(const char *path, char * const argv[], char * const envp[] ) {\r
+//int execve(char *name, char **argv, char **env){\r
+ (void)path;\r
+ (void)argv;\r
+ (void)envp;\r
+ errno=ENOMEM;\r
+ return -1;\r
+}\r
+\r
+pid_t fork() {\r
+ errno=EAGAIN;\r
+ return -1;\r
+}\r
+\r
+#include <sys/stat.h>\r
+int fstat(int file, struct stat *st) {\r
+ (void)file;\r
+ st->st_mode = S_IFCHR;\r
+ return 0;\r
+}\r
+\r
+/* Returns 1 if connected to a terminal. T32 can be a terminal\r
+ */\r
+\r
+int isatty( int fd )\r
+{\r
+ (void)fd;\r
+ return 1;\r
+}\r
+\r
+/*\r
+int fstat( int fd, struct stat *buf )\r
+{\r
+ buf->st_mode = S_IFCHR;\r
+ buf->st_blksize = 0;\r
+\r
+ return (0);\r
+}\r
+*/\r
+\r
+/* reposition read/write file offset\r
+ * We can't seek, return error.*/\r
+off_t lseek( int fd, off_t offset,int whence)\r
+{\r
+ (void)fd;\r
+ (void)offset;\r
+ (void)whence;\r
+\r
+ errno = ESPIPE;\r
+ return ((off_t)-1);\r
+}\r
+\r
+int open(const char *name, int flags, int mode){\r
+ (void)name;\r
+ (void)flags;\r
+ (void)mode;\r
+\r
+#if defined(USE_RAMLOG)\r
+ if( strcmp(name,"ramlog") == 0 ) {\r
+ return FILE_RAMLOG;\r
+ }\r
+#endif\r
+\r
+ return -1;\r
+}\r
+\r
+int read( int fd, void *buf, size_t nbytes )\r
+{\r
+ (void)fd;\r
+ (void)buf;\r
+ (void)nbytes;\r
+#ifdef USE_TTY_WINIDEA\r
+ (void)g_TRBuffer[0];\r
+#endif\r
+\r
+#ifdef USE_TTY_NOICE\r
+ // Not tested at all\r
+ int retval;\r
+ while (VUART_RX != 0)\r
+ {\r
+ }\r
+\r
+ retval = VUART_RX;\r
+ VUART_RX = 0;\r
+#endif\r
+\r
+ /* Only support write for now, return 0 read */\r
+ return 0;\r
+}\r
+\r
+\r
+int write( int fd, const void *_buf, size_t nbytes)\r
+{\r
+ //(void)fd; // Normally 0- ?, 1-stdout, 2-stderr,\r
+ // Added 3-ramlog,\r
+\r
+\r
+ if( fd <= STDERR_FILENO ) {\r
+#ifdef USE_TTY_NOICE\r
+ char *buf1 = (char *)_buf;\r
+ if (START_VUART)\r
+ {\r
+ for (int i = 0; i < nbytes; i++) {\r
+ char c = buf1[i];\r
+ if (c == '\n')\r
+ {\r
+ while (VUART_TX != 0)\r
+ {\r
+ }\r
+\r
+ VUART_TX = '\r';\r
+ }\r
+\r
+ while (VUART_TX != 0)\r
+ {\r
+ }\r
+\r
+ VUART_TX = c;\r
+ }\r
+ }\r
+#endif\r
+\r
+#ifdef USE_TTY_WINIDEA\r
+ if (g_TConn)\r
+ {\r
+ char *buf = (char *)_buf;\r
+ unsigned char nCnt,nLen;\r
+ for(nCnt=0; nCnt<nbytes; nCnt++)\r
+ {\r
+ while(TWBUFF_FULL()) ;\r
+ nLen=TWBUFF_TPTR;\r
+ g_TWBuffer[nLen]=buf[nCnt];\r
+ nLen=TWBUFF_INC(nLen);\r
+ TWBUFF_TPTR=nLen;\r
+ }\r
+ }\r
+#endif\r
+\r
+#ifdef USE_TTY_T32\r
+ char *buf = (char *)_buf;\r
+ for (int i = 0; i < nbytes; i++) {\r
+ if (*(buf + i) == '\n') {\r
+ t32_writebyte ('\r');\r
+// t32_writebyte ('\n');\r
+ }\r
+ t32_writebyte (*(buf + i));\r
+ }\r
+#endif\r
+\r
+#ifdef USE_TTY_ARM_ITM\r
+ char *buf = (char *)_buf;\r
+ for (int i = 0; i < nbytes; i++) {\r
+ ITM_SendChar(*(buf + i));\r
+ }\r
+#endif\r
+\r
+#ifdef USE_TTY_TCF_STREAMS\r
+ char *buf = (char *)_buf;\r
+ for (int i = 0; i < nbytes; i++) {\r
+ TCF_TTY_SendChar(*(buf + i));\r
+ }\r
+#endif\r
+\r
+#ifdef USE_TTY_CODE_COMPOSER\r
+ HOSTwrite(fd, _buf, nbytes);\r
+#endif\r
+\r
+#ifdef USE_TTY_TMS570_KEIL\r
+ for (int i = 0; i < nbytes; i++) {\r
+ GLCD_PrintChar((char *)(_buf + i));\r
+ }\r
+#endif\r
+\r
+#if defined(USE_RAMLOG)\r
+ {\r
+ char *buf = (char *)_buf;\r
+ for (int i = 0; i < nbytes; i++) {\r
+ ramlog_chr (*(buf + i));\r
+ }\r
+ }\r
+#endif\r
+\r
+ }\r
+ else\r
+ {\r
+#if defined(USE_RAMLOG)\r
+ /* RAMLOG support */\r
+ if(fd == FILE_RAMLOG) {\r
+ char *buf = (char *)_buf;\r
+ for (int i = 0; i < nbytes; i++) {\r
+ ramlog_chr (*(buf + i));\r
+ }\r
+ }\r
+#endif\r
+ }\r
+\r
+ return (nbytes);\r
+}\r
+\r
+int arc_putchar(int fd, int c) {\r
+ char cc = c;\r
+ write( fd,&cc,1);\r
+\r
+ return 0;\r
+}\r
+\r
+/* If we use malloc and it runs out of memory it calls sbrk()\r
+ */\r
+\r
+#if defined(CFG_PPC)\r
+\r
+/* linker symbols */\r
+extern char _heap_start[]; // incomplete array to ensure not placed in small-data\r
+extern char _heap_end[];\r
+\r
+void * sbrk( ptrdiff_t incr )\r
+{\r
+ char *prevEnd;\r
+ static char *nextAvailMemPtr = _heap_start;\r
+\r
+ if( nextAvailMemPtr + incr > _heap_end) {\r
+ write( 2, "Heap overflow!\n", 15 );\r
+ abort();\r
+ }\r
+ prevEnd = nextAvailMemPtr;\r
+ nextAvailMemPtr += incr;\r
+ return prevEnd;\r
+}\r
+#else\r
+extern char _end[];\r
+\r
+//static char *curbrk = _end;\r
+\r
+#ifndef HEAPSIZE\r
+#define HEAPSIZE 16000\r
+#endif\r
+\r
+/*\r
+ * The heap sadly have alignment that depends on the pagesize that\r
+ * you compile malloc newlib with. From what I can tell from the\r
+ * code that is a pagesize of 4096.\r
+ */\r
+\r
+unsigned char _heap[HEAPSIZE] __attribute__((aligned (4)));\r
+//__attribute__((section(".heap")));\r
+\r
+void * sbrk( ptrdiff_t incr )\r
+{\r
+ static unsigned char *heap_end;\r
+ unsigned char *prev_heap_end;\r
+\r
+/* initialize */\r
+ if( heap_end == 0 ){\r
+ heap_end = _heap;\r
+ }\r
+ prev_heap_end = heap_end;\r
+\r
+ if( heap_end + incr - _heap > HEAPSIZE ) {\r
+ /* heap overflow - announce on stderr */\r
+ write( 2, "Heap overflow!\n", 15 );\r
+ abort();\r
+ }\r
+\r
+ heap_end += incr;\r
+\r
+ return (caddr_t) prev_heap_end;\r
+}\r
+#endif\r
+\r
+int stat( const char *file, struct stat *st ) {\r
+//int stat(char *file, struct stat *st) {\r
+ (void)file;\r
+ st->st_mode = S_IFCHR;\r
+ return 0;\r
+}\r
+\r
+\r
+pid_t getpid() {\r
+ return 1;\r
+}\r
+\r
+#include <errno.h>\r
+#undef errno\r
+extern int errno;\r
+int kill(int pid, int sig){\r
+ (void)pid;\r
+ (void)sig;\r
+ errno=EINVAL;\r
+ return(-1);\r
+}\r
+\r
+\r
+/* Should not really be here, but .. */\r
+\r
+void _fini( void )\r
+{\r
+\r
+}\r
+\r
+\r
+#if defined(__GNUC__)\r
+void __init( void )\r
+{\r
+}\r
+#endif\r
+\r
+#if defined(CFG_ARM)\r
+void _exit( int status ) {\r
+#ifdef USE_TTY_CODE_COMPOSER\r
+ __asm(" .global C$$EXIT");\r
+ __asm("C$$EXIT: nop");\r
+#endif\r
+ while(1) ;\r
+}\r
+#endif\r
+\r