From c5394b8b223cf48abec0ac227f24846a4d154411 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sun, 1 Mar 2009 17:48:25 +0000 Subject: [PATCH] - minor changes Committed on the Free edition of March Hare Software CVSNT Server. Upgrade to CVS Suite for more features and support: http://march-hare.com/cvsnt/ git-svn-id: http://moon:8086/svn/vhdl/trunk@367 cc03376c-175c-47c8-b038-4cd826a8556b --- lib/CPUs/MIPS/bsp/examples/libsys.c | 56 +++++++++++++++++------------ lib/CPUs/MIPS/bsp/examples/libsys.h | 4 +++ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/lib/CPUs/MIPS/bsp/examples/libsys.c b/lib/CPUs/MIPS/bsp/examples/libsys.c index a6d706e..209e79a 100644 --- a/lib/CPUs/MIPS/bsp/examples/libsys.c +++ b/lib/CPUs/MIPS/bsp/examples/libsys.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "libsys.h" @@ -150,9 +151,8 @@ void _cg_putchar(char c) void _exit (int exitcode) { - sputs("_exit("); - print_word(exitcode); - sputs(")\n"); + fflush(stdout); + fflush(stderr); while(1); } @@ -239,29 +239,31 @@ int settimeofday(const struct timeval *tp, const struct timezone *tzp) caddr_t sbrk(int incr) { extern char end; + extern char stack_ptr; static char *heap_end; char *prev_heap_end; if (heap_end == 0) + { heap_end = &end; + } prev_heap_end = heap_end; -// if (heap_end + incr > stack_ptr) -// { -// sputs("Heap and stack collision\r\n"); -// abort(); -// } - -// sputs("\n"); -// print_word((int)prev_heap_end); -// sputs("\n"); + if (heap_end + incr > &stack_ptr) + { +// sputs("Heap and stack collision\n"); +// sputs("Stack Ptr = ");print_word(&stack_ptr);sputs("\n"); +// sputs("Heap end = ");print_word(heap_end);sputs("\n"); +// sputs("Increment = ");print_word(incr);sputs("\n"); + exit(1); + } heap_end += incr; return (caddr_t) prev_heap_end; } int fstat(int file, struct stat *st) { -// sputs("Fstat()\n"); +// sputs("fstat\n"); st->st_mode = S_IFCHR; st->st_blksize = 0; return 0; @@ -269,41 +271,49 @@ int fstat(int file, struct stat *st) int lseek(int file, int ptr, int dir) { - sputs("Lseek()\n"); - +// sputs("lseek\n"); errno = ESPIPE; return -1; } int open(const char *name, int flags, int mode) { - sputs("Open()\n"); +// sputs("open\n"); errno = EIO; return -1; } int close(int file) { - sputs("Close()\n"); +// sputs("close\n"); return 0; } int read(int file, char *ptr, int len) { int i; + char c; -// sputs("Read()\n"); - for (i = 0; i < len; i++) +// sputs("read\n"); + i = 0; + while (i < len) { - ptr[i] = readchar(); - if ((ptr[i] == '\n') || (ptr[i] == '\r')) + c = readchar(); + if ((c == 0x0D) || (c == 0x0A)) { - i++; writechar(0x0D); writechar(0x0A); + if (i==0) + continue; + + ptr[i++] = c; break; } - writechar(ptr[i]); + else + { + ptr[i++] = c; + writechar(c); + } } return i; } diff --git a/lib/CPUs/MIPS/bsp/examples/libsys.h b/lib/CPUs/MIPS/bsp/examples/libsys.h index d73b602..c155cc5 100644 --- a/lib/CPUs/MIPS/bsp/examples/libsys.h +++ b/lib/CPUs/MIPS/bsp/examples/libsys.h @@ -51,8 +51,12 @@ //#define STDOUT_FUNCTION _cg_putchar // Video character //#define STDERR_FUNCTION _putchar // Serial output +#ifndef STDOUT_FUNCTION #define STDOUT_FUNCTION _putchar // Serial output +#endif +#ifndef STDERR_FUNCTION #define STDERR_FUNCTION _putchar // Serial output +#endif UINT32 CP0_SR_read(void); void CP0_SR_write(UINT32 val);