diff options
Diffstat (limited to 'kernel/src/print')
| -rw-r--r-- | kernel/src/print/panic.c | 27 | ||||
| -rw-r--r-- | kernel/src/print/print.c | 128 | ||||
| -rw-r--r-- | kernel/src/print/time.c | 146 |
3 files changed, 0 insertions, 301 deletions
diff --git a/kernel/src/print/panic.c b/kernel/src/print/panic.c deleted file mode 100644 index 58ffe40..0000000 --- a/kernel/src/print/panic.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <sys.h> -#include <stdarg.h> -#include <stdlib.h> -#include <panic.h> -#include <print.h> - -#include "tty/color.h" -#include "tty/term.h" - -__attribute__((noreturn)) -void _panic_impl(char* msg, int line, char* file, ...) { - int_disable(); - va_list args; - va_start(args, file); - term_clear(); - term_setpos(0, 0); - term_setfg(VGA_LIGHT_RED); - puts("!!!PANIC!!!\n"); - term_setfg(VGA_WHITE); - vprintk(msg, args); - if (!term_newline()) putchar('\n'); - printk("\nin %s at line %d\n", file, line); - term_flush(); - while(1) { - halt(); - } -} diff --git a/kernel/src/print/print.c b/kernel/src/print/print.c deleted file mode 100644 index 46ec047..0000000 --- a/kernel/src/print/print.c +++ /dev/null @@ -1,128 +0,0 @@ -#include "tty/color.h" -#include "tty/term.h" -#include <stdbool.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <print.h> - -void printk(const char *restrict format, ...) { - va_list args; - va_start(args, format); - vprintk(format, args); - va_end(args); -} - -void vprintk(const char *restrict format, va_list args) { - char buf[80]; - for (; *format; format++) { - if (*format == '%') { - bool l = false; - char c = *++format; - if (c == 'l') { - l = true; - c = *++format; - } - switch(c) { - case '%': - putchar('%'); - break; - case 's': - puts(va_arg(args, char*)); - break; - case 'c': - putchar(va_arg(args, int)); - break; - case 'd': - if (l) ltoa(va_arg(args, long long), buf, 10); - else itoa(va_arg(args, int), buf, 10); - puts(buf); - break; - case 'u': - if (l) ultoa(va_arg(args, unsigned long long), buf, 10); - else utoa(va_arg(args, unsigned int), buf, 10); - puts(buf); - break; - case 'f': - case 'F': - ftoa(va_arg(args, double), buf); - puts(buf); - break; - case 'x': - case 'X': - utoa(va_arg(args, unsigned int), buf, 16); - puts(buf); - break; - case 'b': - va_arg(args, int) ? puts("true") : puts("false"); - break; - case 'k': { - static char disp[] = {'B', 'K', 'M', 'G'}; - uint32_t size = va_arg(args, unsigned int); - size_t i = 0; - while (size / 1024 > 0) { - size /= 1024; - i++; - } - utoa(size, buf, 10); - puts(buf); - putchar(disp[i]); - if (i > 0) putchar('B'); - break; - } - default: - break; - } - } else { - putchar(*format); - } - } -} - -void puts(const char *s) { - for(; *s; s++) putchar(*s); -} - -void printl(enum VGAColor color, const char* msg) { - term_setbg(VGA_BLACK); - term_setfg(VGA_WHITE); - putchar('['); - term_setfg(color); - printk("%s", msg); - term_setfg(VGA_WHITE); - putchar(']'); - putchar(' '); -} - -void _debugk_impl(char *format, ...) { - uint16_t color = term_save_col(); - printl(VGA_LIGHT_CYAN, "LOG"); - va_list args; - va_start(args, format); - vprintk(format, args); - va_end(args); - if (!term_newline()) putchar('\n'); - term_load_col(color); -} - -void _succek_impl(char *format, ...) { - uint16_t color = term_save_col(); - printl(VGA_LIGHT_GREEN, "OK"); - va_list args; - va_start(args, format); - vprintk(format, args); - va_end(args); - if (!term_newline()) putchar('\n'); - term_load_col(color); -} - -void _errork_impl(char *format, ...) { - uint16_t color = term_save_col(); - printl(VGA_LIGHT_RED, "ERR"); - va_list args; - va_start(args, format); - vprintk(format, args); - va_end(args); - if (!term_newline()) putchar('\n'); - term_load_col(color); -} diff --git a/kernel/src/print/time.c b/kernel/src/print/time.c deleted file mode 100644 index 7f52a98..0000000 --- a/kernel/src/print/time.c +++ /dev/null @@ -1,146 +0,0 @@ -#include <stdbool.h> -#include <string.h> -#include <time.h> -#include <stddef.h> - -static char* ABB_WEEKDAY[7] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" -}; - -static char* FULL_WEEKDAY[7] = { - "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturady" -}; - -static char* ABB_MONTH[12] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" -}; - -static char* FULL_MONTH[12] = { - "January", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" -}; - -static char *write_num(unsigned int num, unsigned int pad, char *buf, size_t n) { - size_t digits = 1; - unsigned int x = num; - - while (x /= 10, x > 0) digits++; - if (pad == 0) pad = digits; - - for (size_t i = 0; i < pad; i++) { - - size_t digit; - if (i >= digits) { - digit = 0; - } else { - digit = num % 10; - num /= 10; - } - - if (pad - i - 1 >= n) continue; - buf[pad - i - 1] = '0' + digit; - - } - - if (pad > n) pad = n; - - return buf + pad; -} - -void timetostr(struct Time *time, char *format, char *buf, size_t n) { - char *index = buf; - char c; - int space; - - while ( - c = *format++, - space = (buf + n) - index, - c != '\0' && space > 0 - ) { - if (c != '%') { - *index++ = c; - continue; - } else { - c = *format++; - } - - switch (c) { - case '%': - *index++ = '%'; - break; - case 'a': - index = strncpy(index, ABB_WEEKDAY[time->wday], space); - break; - case 'A': - index = strncpy(index, FULL_WEEKDAY[time->wday], space); - break; - case 'b': - case 'h': - index = strncpy(index, ABB_MONTH[time->mon], space); - break; - case 'B': - index = strncpy(index, FULL_MONTH[time->mon], space); - break; - case 'C': - index = write_num(time->cen, 0, index, space); - break; - case 'd': - index = write_num(time->mday, 2, index, space); - break; - case 'H': - index = write_num(time->hour, 2, index, space); - break; - case 'I': - index = write_num((time->hour + 12) % 12 + 1, 2, index, space); - break; - case 'j': - index = write_num(time->yday, 3, index, space); - break; - case 'm': - index = write_num(time->mon + 1, 2, index, space); - break; - case 'M': - index = write_num(time->min, 2, index, space); - break; - case 'n': - *index++ = '\n'; - break; - case 'p': - index = strncpy(index, time->hour > 11 ? "PM" : "AM", space); - break; - case 'P': - index = strncpy(index, time->hour > 11 ? "pm" : "am", space); - break; - case 'q': - index = write_num((time->mon + 3) / 3, 0, index, space); - break; - case 'S': - index = write_num(time->sec, 2, index, space); - break; - case 't': - *index++ = '\t'; - break; - case 'u': - index = write_num(((time->wday + 1 )% 7) + 1, 0, index, space); - break; - case 'w': - index = write_num(time->wday, 0, index, space); - break; - case 'y': - index = write_num(time->yn, 2, index, space); - break; - case 'Y': - index = write_num(time->year + 1900, 0, index, space); - break; - default: { - char b[3] = {'%', c, '\0'}; - index = strncpy(index, b, space); - break; - } - } - } - - if (space < 1) - buf[n - 1] = '\0'; - else - *index = '\0'; -} |