Skip to content

Commit

Permalink
Syscall handling actually works now. Also implemented printf as syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
sprakes committed May 3, 2015
1 parent 50feccc commit effbf73
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
5 changes: 3 additions & 2 deletions user/hello/hello.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>

int main() {
while(1);
}
printf("Hello world... from hello.c\n");
while(1);
}
1 change: 1 addition & 0 deletions user/include/fs_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions user/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ extern "C" {

#include <features.h>

#define SYSCALL_PRINTF 16


#define __NEED_FILE
#define __NEED___isoc_va_list
#define __NEED_size_t
Expand Down
1 change: 0 additions & 1 deletion user/libc/stdio/__towrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions user/libc/stdio/fwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 10 additions & 7 deletions user/libc/stdio/printf.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include <stdio.h>
#include <stdarg.h>
#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;
}
1 change: 1 addition & 0 deletions user/libc/stdio/vfprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit effbf73

Please sign in to comment.