From 70b141b3af85771f36119165e072c1c45d64de84 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Sun, 8 Jul 2018 01:44:13 +1000 Subject: 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. --- lib/stdio.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/stdio.c (limited to 'lib/stdio.c') 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 +#include +#include + +_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; +} -- cgit v1.3