diff options
Diffstat (limited to 'src/user/lib')
-rw-r--r-- | src/user/lib/fwik/Makefile | 11 | ||||
-rw-r--r-- | src/user/lib/fwik/String.cpp | 1 | ||||
-rw-r--r-- | src/user/lib/fwik/include/IO/IOStream.h | 33 | ||||
-rw-r--r-- | src/user/lib/fwik/include/IO/Node.h | 25 | ||||
-rw-r--r-- | src/user/lib/fwik/include/IO/Term.h | 32 | ||||
-rw-r--r-- | src/user/lib/fwik/include/String.h | 5 | ||||
-rw-r--r-- | src/user/lib/fwik/include/cpp.h | 16 | ||||
-rw-r--r-- | src/user/lib/fwik/io/IOStream.cpp | 19 | ||||
-rw-r--r-- | src/user/lib/fwik/io/Node.cpp | 23 | ||||
-rw-r--r-- | src/user/lib/fwik/io/Term.cpp | 51 | ||||
-rw-r--r-- | src/user/lib/fwik/main.cpp | 30 | ||||
-rw-r--r-- | src/user/lib/libc/Makefile (renamed from src/user/lib/Makefile) | 4 | ||||
-rw-r--r-- | src/user/lib/libc/include/_dlmalloc.h (renamed from src/user/lib/include/_dlmalloc.h) | 0 | ||||
-rw-r--r-- | src/user/lib/libc/include/readline.h (renamed from src/user/lib/include/readline.h) | 11 | ||||
-rw-r--r-- | src/user/lib/libc/include/sched.h (renamed from src/user/lib/include/sched.h) | 4 | ||||
-rw-r--r-- | src/user/lib/libc/include/stdarg.h (renamed from src/user/lib/include/stdarg.h) | 0 | ||||
-rw-r--r-- | src/user/lib/libc/include/stdio.h (renamed from src/user/lib/include/stdio.h) | 8 | ||||
-rw-r--r-- | src/user/lib/libc/include/stdlib.h (renamed from src/user/lib/include/stdlib.h) | 7 | ||||
-rw-r--r-- | src/user/lib/libc/include/string.h (renamed from src/user/lib/include/string.h) | 4 | ||||
-rw-r--r-- | src/user/lib/libc/include/tce/syscall.h (renamed from src/user/lib/include/tce/syscall.h) | 10 | ||||
-rw-r--r-- | src/user/lib/libc/start.c (renamed from src/user/lib/start.c) | 0 | ||||
-rw-r--r-- | src/user/lib/libc/std/_dlmalloc.c (renamed from src/user/lib/std/_dlmalloc.c) | 0 | ||||
-rw-r--r-- | src/user/lib/libc/std/readline.c (renamed from src/user/lib/std/readline.c) | 2 | ||||
-rw-r--r-- | src/user/lib/libc/std/sched.c (renamed from src/user/lib/std/sched.c) | 1 | ||||
-rw-r--r-- | src/user/lib/libc/std/stdio.c (renamed from src/user/lib/std/stdio.c) | 1 | ||||
-rw-r--r-- | src/user/lib/libc/std/stdlib.c (renamed from src/user/lib/std/stdlib.c) | 0 | ||||
-rw-r--r-- | src/user/lib/libc/std/string.c (renamed from src/user/lib/std/string.c) | 1 | ||||
-rw-r--r-- | src/user/lib/libc/tce/syscall.c (renamed from src/user/lib/tce/syscall.c) | 4 |
28 files changed, 291 insertions, 12 deletions
diff --git a/src/user/lib/fwik/Makefile b/src/user/lib/fwik/Makefile new file mode 100644 index 0000000..cf8896a --- /dev/null +++ b/src/user/lib/fwik/Makefile @@ -0,0 +1,11 @@ +Out = _fwik.o +Obj = String.o io/Node.o io/Term.o io/IOStream.o main.o + +ExtObj = $(SrcPath)/user/lib/libc/_libc.o + +include $(SrcPath)/common.make + +CFLAGS += -I$(SrcPath)/include -I$(SrcPath)/user/lib/libc/include -I$(SrcPath)/user/lib/fwik/include + +LDFLAGS += -r + diff --git a/src/user/lib/fwik/String.cpp b/src/user/lib/fwik/String.cpp new file mode 100644 index 0000000..75114c2 --- /dev/null +++ b/src/user/lib/fwik/String.cpp @@ -0,0 +1 @@ +#include <String.h> diff --git a/src/user/lib/fwik/include/IO/IOStream.h b/src/user/lib/fwik/include/IO/IOStream.h new file mode 100644 index 0000000..e9ae246 --- /dev/null +++ b/src/user/lib/fwik/include/IO/IOStream.h @@ -0,0 +1,33 @@ +#ifndef DEF_FWIK_IO_IOSTREAM_H +#define DEF_FWIK_IO_IOSTREAM_H + +#include "Term.h" + +class IOStream { + public: + Term *term; + + IOStream() : term(0) {} + IOStream(Term *t) : term(t) {} + + void print(char* str); + void printf(char* fmt, ...); + char* readln(); + + IOStream &operator<<(char* s) { + print(s); + return *this; + } + IOStream &operator<<(int i) { + printf("%d", i); + return *this; + } + IOStream &operator<<(void* p) { + printf("%p", p); + return *this; + } +}; + +extern IOStream stdio; + +#endif diff --git a/src/user/lib/fwik/include/IO/Node.h b/src/user/lib/fwik/include/IO/Node.h new file mode 100644 index 0000000..6100fc9 --- /dev/null +++ b/src/user/lib/fwik/include/IO/Node.h @@ -0,0 +1,25 @@ +#ifndef DEF_FWIK_IO_NODE_H +#define DEF_FWIK_IO_NODE_H + +#include <tce/syscall.h> +#include <tce/vfs.h> +#include <stdio.h> +#include <cpp.h> + +class Term; +class Node { + public: + FILE fd; + file_info info; + bool valid; + + Node(FILE f); + Node(char* filename, int mode); + virtual ~Node() {} + + void close(); + + virtual Term* as_term() { return 0; } +}; + +#endif diff --git a/src/user/lib/fwik/include/IO/Term.h b/src/user/lib/fwik/include/IO/Term.h new file mode 100644 index 0000000..cf90789 --- /dev/null +++ b/src/user/lib/fwik/include/IO/Term.h @@ -0,0 +1,32 @@ +#ifndef DEF_FWIK_IO_TERM_H +#define DEF_FWIK_IO_TERM_H + +#include <stdio.h> +#include "Node.h" + +#include <readline.h> + +class Term : public Node { + int w, h; + + readline_history hist; + + void _init(); + + public: + Term(FILE f); + Term(char* filename, int mode); + Term(const Node &n); + virtual ~Term(); + + virtual void print(char *s); + virtual void printf(char* fmt, ...); + virtual void vprintf(char* fmt, va_list ap); + virtual char* readln(); + char* readline(); + + virtual Term* as_term() { return this; } +}; + +#endif + diff --git a/src/user/lib/fwik/include/String.h b/src/user/lib/fwik/include/String.h new file mode 100644 index 0000000..2a44046 --- /dev/null +++ b/src/user/lib/fwik/include/String.h @@ -0,0 +1,5 @@ +#ifndef DEF_FWIK_STRING_H +#define DEF_FWIK_STRING_H + + +#endif diff --git a/src/user/lib/fwik/include/cpp.h b/src/user/lib/fwik/include/cpp.h new file mode 100644 index 0000000..5b66ba1 --- /dev/null +++ b/src/user/lib/fwik/include/cpp.h @@ -0,0 +1,16 @@ +#ifndef DEF_FWIK_CPPSUPPORT_H +#define DEF_FWIK_CPPSUPPORT_H + +#include <stdlib.h> + +inline void* operator new(size_t, void* p) throw() { return p; } +inline void* operator new[](size_t, void* p) throw() { return p; } +inline void operator delete (void*, void*) throw() { }; +inline void operator delete[](void*, void*) throw() { }; + +inline void* operator new (size_t size) { return malloc(size); } +inline void* operator new[] (size_t size) { return malloc(size); } +inline void operator delete (void* ptr) { return free(ptr); } +inline void operator delete[] (void* ptr) { return free(ptr); } + +#endif diff --git a/src/user/lib/fwik/io/IOStream.cpp b/src/user/lib/fwik/io/IOStream.cpp new file mode 100644 index 0000000..bcaa581 --- /dev/null +++ b/src/user/lib/fwik/io/IOStream.cpp @@ -0,0 +1,19 @@ +#include <IO/IOStream.h> + +void IOStream::print(char* str) { + if (term == 0) return; + term->print(str); +} + +void IOStream::printf(char* fmt, ...) { + if (term == 0) return; + va_list ap; + va_start(ap, fmt); + term->vprintf(fmt, ap); + va_end(ap); +} + +char* IOStream::readln() { + if (term == 0) return 0; + return term->readln(); +} diff --git a/src/user/lib/fwik/io/Node.cpp b/src/user/lib/fwik/io/Node.cpp new file mode 100644 index 0000000..1d8b7f5 --- /dev/null +++ b/src/user/lib/fwik/io/Node.cpp @@ -0,0 +1,23 @@ +#include <IO/Node.h> + +Node::Node(FILE f) { + fd = f; + int i = libc::statf(f, &info); + valid = (i == 0); +} + +Node::Node(char* filename, int mode) { + fd = libc::open(filename, mode); + if (fd < 0) { + valid = false; + } else { + int i = libc::statf(fd, &info); + valid = (i == 0); + if (!valid) libc::close(fd); + } +} + +void Node::close() { + if (valid) libc::close(fd); + valid = false; +} diff --git a/src/user/lib/fwik/io/Term.cpp b/src/user/lib/fwik/io/Term.cpp new file mode 100644 index 0000000..1c6db66 --- /dev/null +++ b/src/user/lib/fwik/io/Term.cpp @@ -0,0 +1,51 @@ +#include <IO/Term.h> + +Term::Term(const Node &n) : Node(n) { + _init(); +} + +Term::Term(FILE f) : Node(f) { + _init(); +} + +Term::Term(char* filename, int mode) : Node(filename, mode) { + _init(); +} + +void Term::_init() { + if (info.type & FT_TERMINAL) { + w = info.size >> 16; + h = info.size & 0xFFFF; + } else { + valid = false; + } + hist.str = 0; + hist.max = 12; +} + +Term::~Term() { + //TODO : free readline history +} + +void Term::print(char *s) { + libc::fprint(fd, s); +} + +void Term::printf(char* fmt, ...) { + va_list ap; + va_start(ap, fmt); + libc::vfprintf(fd, fmt, ap); + va_end(ap); +} + +void Term::vprintf(char* fmt, va_list ap) { + libc::vfprintf(fd, fmt, ap); +} + +char* Term::readln() { + return libc::freadln(fd); +} + +char *Term::readline() { + return libc::freadline(fd, &hist); +} diff --git a/src/user/lib/fwik/main.cpp b/src/user/lib/fwik/main.cpp new file mode 100644 index 0000000..8e2e289 --- /dev/null +++ b/src/user/lib/fwik/main.cpp @@ -0,0 +1,30 @@ +#include <IO/IOStream.h> +#include <stdio.h> +#include <cpp.h> + +IOStream stdio; + +int Main(char **args); // FWIK app main + +extern "C" int main(char **args) { + stdio.term = 0; + + Node zero(libc::term); + if (zero.info.type & FT_TERMINAL) { + stdio.term = new Term(zero); + } + Main(args); +} + + +// C++ support + +//Enables pure virtual functions +extern "C" void __cxa_pure_virtual() { + //do nothing +} +//Enables global objects +void *__dso_handle; +extern "C" int __cxa_atexit(void (*f)(void*), void *p, void *d) { return 0; } + + diff --git a/src/user/lib/Makefile b/src/user/lib/libc/Makefile index c2630c4..14a5421 100644 --- a/src/user/lib/Makefile +++ b/src/user/lib/libc/Makefile @@ -1,11 +1,11 @@ -Out = _user.o +Out = _libc.o Obj = tce/syscall.o std/_dlmalloc.o \ std/stdio.o std/stdlib.o std/string.o std/sched.o std/readline.o \ start.o include $(SrcPath)/common.make -CFLAGS += -I$(SrcPath)/include -I$(SrcPath)/user/lib/include +CFLAGS += -I$(SrcPath)/include -I$(SrcPath)/user/lib/libc/include -Wno-error=unused-variable LDFLAGS += -r diff --git a/src/user/lib/include/_dlmalloc.h b/src/user/lib/libc/include/_dlmalloc.h index d896e22..d896e22 100644 --- a/src/user/lib/include/_dlmalloc.h +++ b/src/user/lib/libc/include/_dlmalloc.h diff --git a/src/user/lib/include/readline.h b/src/user/lib/libc/include/readline.h index 53193d7..910ad9a 100644 --- a/src/user/lib/include/readline.h +++ b/src/user/lib/libc/include/readline.h @@ -3,14 +3,21 @@ #include <stdio.h> -char* freadln(FILE f); // minimal line-reading function. user must free the returned value. typedef struct _rdln_hist { int max; int n; char **str; } readline_history; -char* readline(FILE f, readline_history *h); + +#ifdef __cplusplus +extern "C" { namespace libc { +#endif +char* freadln(FILE f); // minimal line-reading function. user must free the returned value. +char* freadline(FILE f, readline_history *h); +#ifdef __cplusplus +} } +#endif #endif diff --git a/src/user/lib/include/sched.h b/src/user/lib/libc/include/sched.h index 1fe148d..451a114 100644 --- a/src/user/lib/include/sched.h +++ b/src/user/lib/libc/include/sched.h @@ -10,7 +10,7 @@ typedef uint32_t mutex_t; #ifdef __cplusplus -extern "C" { +extern "C" { namespace libc { #endif int mutex_lock(mutex_t* mutex); //wait for mutex to be free @@ -18,7 +18,7 @@ int mutex_lockE(mutex_t* mutex); //lock mutex only if free, returns !0 if locked void mutex_unlock(mutex_t* mutex); #ifdef __cplusplus -} +} } #endif #endif diff --git a/src/user/lib/include/stdarg.h b/src/user/lib/libc/include/stdarg.h index 5cd74ff..5cd74ff 100644 --- a/src/user/lib/include/stdarg.h +++ b/src/user/lib/libc/include/stdarg.h diff --git a/src/user/lib/include/stdio.h b/src/user/lib/libc/include/stdio.h index 099746e..d93ebf0 100644 --- a/src/user/lib/include/stdio.h +++ b/src/user/lib/libc/include/stdio.h @@ -4,6 +4,10 @@ #include <stdarg.h> #include <tce/syscall.h> +#ifdef __cplusplus +extern "C" { namespace libc { +#endif + extern FILE term; void print(char *s); @@ -17,5 +21,9 @@ void fprintf(FILE f, char *s, ...); void vfprintf(FILE f, char *s, va_list arg); +#ifdef __cplusplus +} } +#endif + #endif diff --git a/src/user/lib/include/stdlib.h b/src/user/lib/libc/include/stdlib.h index 594f5c5..1cc5d16 100644 --- a/src/user/lib/include/stdlib.h +++ b/src/user/lib/libc/include/stdlib.h @@ -4,8 +4,15 @@ #include <types.h> #include <tce/syscall.h> +#ifdef __cplusplus +extern "C" { namespace libc { +#endif + void abort(); extern volatile int errno; +#ifdef __cplusplus +} } +#endif #include <_dlmalloc.h> diff --git a/src/user/lib/include/string.h b/src/user/lib/libc/include/string.h index 87d8da2..fbe3ade 100644 --- a/src/user/lib/include/string.h +++ b/src/user/lib/libc/include/string.h @@ -4,7 +4,7 @@ #include <types.h> #ifdef __cplusplus -extern "C" { +extern "C" { namespace libc { #endif void *memcpy(void *dest, const void *src, int count); @@ -19,7 +19,7 @@ char *strcat(char *dest, const char *src); int strcmp(const char *s1, const char *s2); #ifdef __cplusplus -} +} } #endif diff --git a/src/user/lib/include/tce/syscall.h b/src/user/lib/libc/include/tce/syscall.h index c182f40..6ad37f1 100644 --- a/src/user/lib/include/tce/syscall.h +++ b/src/user/lib/libc/include/tce/syscall.h @@ -7,6 +7,10 @@ #define NEW_STACK_SIZE 0x8000 +#ifdef __cplusplus +extern "C" { namespace libc { +#endif + void thread_exit(); void schedule(); void thread_sleep(int time); @@ -16,7 +20,7 @@ void thread_new(void (*entry)(void*), void *data); void irq_wait(int number); int proc_priv(); -void* sbrk(size_t size); +void* sbrk(ptrdiff_t size); void brk(void* ptr); int run(char* file, char** args, FILE zero_fd); @@ -32,4 +36,8 @@ int read(FILE file, size_t offset, size_t len, char *buffer); int write(FILE file, size_t offset, size_t len, char *buffer); int link(char* from, char* to, int mode); +#ifdef __cplusplus +} } +#endif + #endif diff --git a/src/user/lib/start.c b/src/user/lib/libc/start.c index 2521f97..2521f97 100644 --- a/src/user/lib/start.c +++ b/src/user/lib/libc/start.c diff --git a/src/user/lib/std/_dlmalloc.c b/src/user/lib/libc/std/_dlmalloc.c index aae76f8..aae76f8 100644 --- a/src/user/lib/std/_dlmalloc.c +++ b/src/user/lib/libc/std/_dlmalloc.c diff --git a/src/user/lib/std/readline.c b/src/user/lib/libc/std/readline.c index a3beefa..c2237b6 100644 --- a/src/user/lib/std/readline.c +++ b/src/user/lib/libc/std/readline.c @@ -38,7 +38,7 @@ char* freadln(FILE f) { // ** READLINE -char *readline(FILE f, readline_history *h) { +char *freadline(FILE f, readline_history *h) { int i; fprint(f, "\x1b[h"); // disable keyboard echo diff --git a/src/user/lib/std/sched.c b/src/user/lib/libc/std/sched.c index 29ea8a8..84e9c3a 100644 --- a/src/user/lib/std/sched.c +++ b/src/user/lib/libc/std/sched.c @@ -1,4 +1,5 @@ #include <sched.h> +#include <tce/syscall.h> /* Internal use only. This function is atomic, meaning it cannot be interrupted by a system task switch. */ static uint32_t atomic_exchange(uint32_t* ptr, uint32_t newval) { diff --git a/src/user/lib/std/stdio.c b/src/user/lib/libc/std/stdio.c index b1778d6..3595622 100644 --- a/src/user/lib/std/stdio.c +++ b/src/user/lib/libc/std/stdio.c @@ -1,6 +1,7 @@ #include <stdlib.h> #include <stdio.h> #include <tce/syscall.h> +#include <readline.h> FILE term = 0; void print(char *s) { fprint(term, s); } diff --git a/src/user/lib/std/stdlib.c b/src/user/lib/libc/std/stdlib.c index 9d46b5c..9d46b5c 100644 --- a/src/user/lib/std/stdlib.c +++ b/src/user/lib/libc/std/stdlib.c diff --git a/src/user/lib/std/string.c b/src/user/lib/libc/std/string.c index 21dbd03..5a41b7e 100644 --- a/src/user/lib/std/string.c +++ b/src/user/lib/libc/std/string.c @@ -1,4 +1,5 @@ #include <string.h> +#include <stdlib.h> int strlen(const char *str) { int i = 0; diff --git a/src/user/lib/tce/syscall.c b/src/user/lib/libc/tce/syscall.c index 4304840..80e0e0e 100644 --- a/src/user/lib/tce/syscall.c +++ b/src/user/lib/libc/tce/syscall.c @@ -65,12 +65,12 @@ int proc_priv() { // ******** memory -void* sbrk(size_t s) { +void* sbrk(ptrdiff_t s) { return (void*)call(SC_SBRK, s, 0, 0, 0, 0); } void brk(void* ptr) { - return call (SC_BRK, ptr, 0, 0, 0, 0); + call (SC_BRK, (size_t)ptr, 0, 0, 0, 0); } // ********** proc |