From effbf73ed4226c109065e491bb5e907370eebd2a Mon Sep 17 00:00:00 2001 From: Prakash Date: Sun, 3 May 2015 01:08:34 -0500 Subject: [PATCH] Syscall handling actually works now. Also implemented printf as syscall #16 --- user/hello/hello.c | 5 +++-- user/include/fs_syscalls.h | 1 + user/include/stdio.h | 3 +++ user/libc/stdio/__towrite.c | 1 - user/libc/stdio/fwrite.c | 2 -- user/libc/stdio/printf.c | 17 ++++++++++------- user/libc/stdio/vfprintf.c | 1 + 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/user/hello/hello.c b/user/hello/hello.c index 0621e5ea..0f7c6138 100644 --- a/user/hello/hello.c +++ b/user/hello/hello.c @@ -1,5 +1,6 @@ #include int main() { - while(1); -} + printf("Hello world... from hello.c\n"); + while(1); +} \ No newline at end of file diff --git a/user/include/fs_syscalls.h b/user/include/fs_syscalls.h index 36896c53..70765f02 100644 --- a/user/include/fs_syscalls.h +++ b/user/include/fs_syscalls.h @@ -16,6 +16,7 @@ #define SYSCALL_LS 12 // show contents of a directory + //FUNCTIONS THE USER CAN CALL TO INTERACT WITH FILESYSTEM: int open(char* filepath, char mode); diff --git a/user/include/stdio.h b/user/include/stdio.h index 884d2e6a..513b12df 100644 --- a/user/include/stdio.h +++ b/user/include/stdio.h @@ -7,6 +7,9 @@ extern "C" { #include +#define SYSCALL_PRINTF 16 + + #define __NEED_FILE #define __NEED___isoc_va_list #define __NEED_size_t diff --git a/user/libc/stdio/__towrite.c b/user/libc/stdio/__towrite.c index 380ea396..23658e4c 100644 --- a/user/libc/stdio/__towrite.c +++ b/user/libc/stdio/__towrite.c @@ -9,7 +9,6 @@ int __towrite(FILE *f) } /* Clear read buffer (easier than summoning nasal demons) */ f->rpos = f->rend = 0; - /* Activate write through the buffer. */ f->wpos = f->wbase = f->buf; f->wend = f->buf + f->buf_size; diff --git a/user/libc/stdio/fwrite.c b/user/libc/stdio/fwrite.c index d5f6542d..1956af2e 100644 --- a/user/libc/stdio/fwrite.c +++ b/user/libc/stdio/fwrite.c @@ -4,9 +4,7 @@ size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f) { size_t i=0; - if (!f->wend && __towrite(f)) return 0; - if (l > f->wend - f->wpos) return f->write(f, s, l); if (f->lbf >= 0) { diff --git a/user/libc/stdio/printf.c b/user/libc/stdio/printf.c index cebfe404..db0699c8 100644 --- a/user/libc/stdio/printf.c +++ b/user/libc/stdio/printf.c @@ -1,12 +1,15 @@ #include #include +#include "../arch/arm/syscall_arch.h" int printf(const char *restrict fmt, ...) { - int ret; - va_list ap; - va_start(ap, fmt); - ret = vfprintf(stdout, fmt, ap); - va_end(ap); - return ret; -} + //int ret; + //va_list ap; + //va_start(ap, fmt); + //ret = vfprintf(stdout, fmt, ap); + //va_end(ap); + //return ret; + long error = __syscall1(SYSCALL_PRINTF, (long)fmt); + return error; +} \ No newline at end of file diff --git a/user/libc/stdio/vfprintf.c b/user/libc/stdio/vfprintf.c index 31c3d5dd..ce0bf7b3 100644 --- a/user/libc/stdio/vfprintf.c +++ b/user/libc/stdio/vfprintf.c @@ -160,6 +160,7 @@ static void pop_arg(union arg *arg, int type, va_list *ap) static void out(FILE *f, const char *s, size_t l) { + while(1); __fwritex((void *)s, l, f); }