diff options
author | stefan <stefan@s00.xyz> | 2023-04-19 20:50:10 -0400 |
---|---|---|
committer | stefan <stefan@s00.xyz> | 2023-04-19 20:50:10 -0400 |
commit | 83e17e29456ec9b6d45f4d9f2634eb280c6f414f (patch) | |
tree | 004a9b2a7cd3f0c7bb4224b59204680bd5d79681 /sys/kern/printf.c | |
parent | af1ce4b2e637ceb418ea72d51c49a3eee276a938 (diff) | |
download | sv-83e17e29456ec9b6d45f4d9f2634eb280c6f414f.tar.gz |
ticket locks
Diffstat (limited to 'sys/kern/printf.c')
-rw-r--r-- | sys/kern/printf.c | 101 |
1 files changed, 0 insertions, 101 deletions
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 <printf.h> -#include <stdint.h> -#include <spinlock.h> -#include <sbi.h> -#include <stdarg.h> - -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; -} |