From 83e17e29456ec9b6d45f4d9f2634eb280c6f414f Mon Sep 17 00:00:00 2001 From: stefan Date: Wed, 19 Apr 2023 20:50:10 -0400 Subject: ticket locks --- sys/kern/printf.c | 101 ------------------------------------------------------ 1 file changed, 101 deletions(-) delete mode 100644 sys/kern/printf.c (limited to 'sys/kern/printf.c') diff --git a/sys/kern/printf.c b/sys/kern/printf.c deleted file mode 100644 index 89add9e..0000000 --- a/sys/kern/printf.c +++ /dev/null @@ -1,101 +0,0 @@ -#include -#include -#include -#include -#include - -static char digits[] = "0123456789abcdef"; - -struct spinlock mutex; -int locked = 0; - -int -puts(const char *str) -{ - do { - sbi_console_putchar(*str); - } while (*(str++) != '\0'); -} - -#define PUTCHAR(c) sbi_console_putchar(c) - -static void -printint(int xx, int base, int sign) -{ - char buf[16]; - int i; - unsigned int x; - - if (sign && (sign = xx < 0)) - x = -xx; - else - x = xx; - - i = 0; - do { - buf[i++] = digits[x % base]; - } while ((x /= base) != 0); - - if (sign) - buf[i++] = '-'; - while (--i >= 0) - PUTCHAR(buf[i]); - -} - -static void -printptr(uint64_t x) -{ - int i; - puts("0x"); - for (i = 0; i < (sizeof(uint64_t) * 2); i++, x <<= 4) - PUTCHAR(digits[x >> (sizeof(int64_t) * 8 - 4)]); -} - -void -printf(const char *fmt, ...) -{ - va_list ap; - int i, c, _locked; - char *s; - - _locked = locked; - if (_locked) - acquire(&mutex); - - va_start(ap, fmt); - - for (i = 0; (c = fmt[i] & 0xff) != 0; i++) { - if (c != '%') { - PUTCHAR(c); - continue; - } - c = fmt[++i] & 0xff; - if (!c) - break; - - switch (c) { - case 'd': - case 'i': - printint(va_arg(ap, int), 10, 1); - break; - case 'x': - printint(va_arg(ap, int), 16, 1); - break; - case 'p': - printptr(va_arg(ap, uint64_t)); - break; - case '%': - PUTCHAR('%'); - break; - } - } - if (_locked) - release(&mutex); -} - -void printf_init(void) -{ - initlock(&mutex); - locked = 1; -} -- cgit v1.2.3