]> rtime.felk.cvut.cz Git - arc.git/blobdiff - common/newlib_port.c
Fixed warning in Code Composer terminal code.
[arc.git] / common / newlib_port.c
index ece0313baa0afe2f10504729ba2b4b9421025097..0a9ca794057f8ee7c5921bf5824e8bed11f3862e 100644 (file)
@@ -21,6 +21,7 @@
 #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
@@ -106,9 +107,11 @@ volatile char g_TConn __attribute__ ((section (".winidea_port")));
 \r
 \r
 static unsigned char parmbuf[8];\r
-#define BUFSIZ 512\r
-#define CC_BUFFER_SIZE ((BUFSIZ)+32)\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
@@ -178,15 +181,29 @@ int HOSTwrite(int dev_fd, const char *buf, unsigned count)
 {\r
    int result;\r
 \r
-   if (count > BUFSIZ) count = BUFSIZ;\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,count,2);\r
-   writemsg(_DTWRITE,parmbuf,(char *)buf,count);\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
@@ -251,7 +268,7 @@ int execve(const char *path, char * const argv[], char * const envp[] ) {
        return -1;\r
 }\r
 \r
-int fork() {\r
+pid_t fork() {\r
   errno=EAGAIN;\r
   return -1;\r
 }\r
@@ -371,7 +388,7 @@ int write(  int fd, const void *_buf, size_t nbytes)
                  unsigned char nCnt,nLen;\r
                  for(nCnt=0; nCnt<nbytes; nCnt++)\r
                        {\r
-                       while(TWBUFF_FULL());\r
+                       while(TWBUFF_FULL()) ;\r
                        nLen=TWBUFF_TPTR;\r
                        g_TWBuffer[nLen]=buf[nCnt];\r
                        nLen=TWBUFF_INC(nLen);\r
@@ -411,7 +428,7 @@ int write(  int fd, const void *_buf, size_t nbytes)
 \r
 #ifdef USE_TTY_TMS570_KEIL\r
        for (int i = 0; i < nbytes; i++) {\r
-               GLCD_PrintChar((_buf + i));\r
+               GLCD_PrintChar((char *)(_buf + i));\r
        }\r
 #endif\r
 \r
@@ -450,8 +467,27 @@ int arc_putchar(int fd, int c) {
 \r
 /* If we use malloc and it runs out of memory it calls sbrk()\r
  */\r
-#if 1\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
@@ -490,12 +526,6 @@ void * sbrk( ptrdiff_t incr )
 \r
    return (caddr_t) prev_heap_end;\r
 }\r
-#else\r
-void *sbrk(int inc )\r
-{\r
-       /* We use our own malloc */\r
-       return (void *)(-1);\r
-}\r
 #endif\r
 \r
 int stat( const char *file, struct stat *st ) {\r
@@ -506,7 +536,7 @@ int stat( const char *file, struct stat *st ) {
 }\r
 \r
 \r
-int getpid() {\r
+pid_t getpid() {\r
   return 1;\r
 }\r
 \r
@@ -529,17 +559,19 @@ void _fini( void )
 }\r
 \r
 \r
+#if defined(__GNUC__)\r
 void __init( void )\r
 {\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
+       while(1) ;\r
 }\r
 #endif\r
 \r