From d718561a9c47ba6d4f8ecf61bb6a93876c91940f Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Mon, 18 Mar 2019 14:21:00 +0100 Subject: [PATCH] Terminal stuff --- kaleid/include/base/crtlib.h | 24 ++++++++++++++++++++++++ kaleid/include/kernel/term.h | 5 +++++ kaleid/kernel/io/term.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/kaleid/include/base/crtlib.h b/kaleid/include/base/crtlib.h index 04654af..c74dd3a 100644 --- a/kaleid/include/base/crtlib.h +++ b/kaleid/include/base/crtlib.h @@ -239,6 +239,30 @@ DEC_CTYPE_FUNC(isalnum, (_AL|_DG)); //------------------------------------------// +#ifndef __min_defined +#define __min_defined +static inline int min(int __x, int __y) +{ return __x < __y ? __x : __y; } +#endif + +#ifndef __lmin_defined +#define __lmin_defined +static inline int lmin(long __x, long __y) +{ return __x < __y ? __x : __y; } +#endif + +#ifndef __max_defined +#define __max_defined +static inline int max(int __x, int __y) +{ return __x > __y ? __x : __y; } +#endif + +#ifndef __lmax_defined +#define __lmax_defined +static inline int lmax(long __x, long __y) +{ return __x > __y ? __x : __y; } +#endif + #ifndef __abs_defined #define __abs_defined static inline int abs(int __x) diff --git a/kaleid/include/kernel/term.h b/kaleid/include/kernel/term.h index 29477ee..fcc000b 100644 --- a/kaleid/include/kernel/term.h +++ b/kaleid/include/kernel/term.h @@ -37,6 +37,11 @@ // enum { KTABSIZE = 4 }; +// +// Upper bound on what a single KernLog() can write +// +enum { KLOG_MAX_BUFSIZE = 4096 }; + // // The VGA colors // diff --git a/kaleid/kernel/io/term.c b/kaleid/kernel/io/term.c index 5392b23..618919b 100644 --- a/kaleid/kernel/io/term.c +++ b/kaleid/kernel/io/term.c @@ -116,3 +116,39 @@ error_t PrintOnTerm(Terminal_t *term, const char *str) return retcode; } +// +// Print formatted string on standard output +// Prints at most KLOG_MAX_BUFSIZE characters +// +error_t KernLog(const char *fmt, ...) +{ + va_list ap; + + char logbuf[KLOG_MAX_BUFSIZE]; + + va_start(ap, fmt); + vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap); + va_end(ap); + + return PrintOnTerm(stdOut, logbuf); +} + +#ifndef _NO_DEBUG +// +// Print formatted string on debug output +// Prints at most KLOG_MAX_BUFSIZE characters +// +error_t DebugLog(const char *fmt, ...) +{ + va_list ap; + + char logbuf[KLOG_MAX_BUFSIZE]; + + va_start(ap, fmt); + vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap); + va_end(ap); + + return PrintOnTerm(stdDbg, logbuf); +} +#endif +