diff options
| author | Jake Mannens <jake72360@gmail.com> | 2018-07-08 01:44:13 +1000 |
|---|---|---|
| committer | Jake Mannens <jake72360@gmail.com> | 2018-07-08 01:44:13 +1000 |
| commit | 70b141b3af85771f36119165e072c1c45d64de84 (patch) | |
| tree | 8c67026fc02c86ffc7328e13354adede5f0ea9ed /lib/stdio.c | |
| parent | ec4f58e8e362e371718f656923c2d234f8ac215c (diff) | |
Added a printf() function to the library under stdio.c which uses the
vsprintf() function to render formatted strings and then the puts system
call to output them.
Moved the vsprintf() function from the kernel to the library.
Furthermore, the prototype for the function has been moved from the
kernel's headers, to the new header file stdio.h.
Renamed the kernel's internal printf() function to printk() in order to
avoid confusion with the library provided function.
Renamed the sys_print system call to the more appropriate name,
sys_puts.
Added a new system call sys_time, which returns the system's uptime in
seconds. This is mainly for testing the userspace binary and will not be
permanent.
Added the file time.c to the library which contains the caller for
sys_time and a helper routine sleep() which delays execution for the
specified number of seconds. The new header file time.h contains
prototypes for both these functions as well as the definition for the
type time_t.
Fixed a bug in which the value of EAX was not properly passed to the
system call handler, resulting in the wrong system call being executed.
This was caused by the code in the SAVE macro not properly preserving
the value.
Fixed a bug in which the value of EAX was not preserved during a return
from system call, but rather restored with the original EAX value prior
to the call. As a result, system call return codes were not properly
passed. This has been corrected by introducing a new macro RESTORE_SYS
which carries out the same restore operations, but maintains EAX prior
to the return.
Diffstat (limited to 'lib/stdio.c')
| -rw-r--r-- | lib/stdio.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/stdio.c b/lib/stdio.c new file mode 100644 index 0000000..912fd17 --- /dev/null +++ b/lib/stdio.c @@ -0,0 +1,18 @@ +#include <stdarg.h> +#include <stdio.h> +#include <unistd.h> + +_syscall1(int, puts, char*, s); + +int printf(char *fmt, ...) { + int ret; + char buf[1024]; + va_list ap; + + va_start(ap, fmt); + ret = vsprintf(buf, fmt, ap); + va_end(ap); + + puts(buf); + return ret; +} |
