diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-07-10 11:24:56 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-07-10 11:24:56 +0800 |
| commit | 1767d390fbf3d0c65389de46caf0b6d43ef3b6ad (patch) | |
| tree | 0f5e01cd7c7a05abb6b1c7472d7f00f49caf02cc /na/lib/kprintf.cc | |
| parent | 63dc025705f6533b91fb1a7d26e6ed864efd9900 (diff) | |
| download | lume-1767d390fbf3d0c65389de46caf0b6d43ef3b6ad.tar.gz lume-1767d390fbf3d0c65389de46caf0b6d43ef3b6ad.tar.xz | |
feat: establish bootable new architecture checkpoint
Replace the compressed boot path with a relocatable higher-half RISC-V entry, expand memory and SMP support, and add the driver, TTY, VFS, exec, signal, syscall, initramfs, and self-test infrastructure needed for a bootable kernel checkpoint.
Diffstat (limited to 'na/lib/kprintf.cc')
| -rw-r--r-- | na/lib/kprintf.cc | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/na/lib/kprintf.cc b/na/lib/kprintf.cc index ddd2e59..a98de71 100644 --- a/na/lib/kprintf.cc +++ b/na/lib/kprintf.cc @@ -5,21 +5,44 @@ * kprintf.cc — Kernel formatted output * * Uses mpaland/printf's vsnprintf_ as the core formatting engine. - * All kernel output ultimately goes through this module. * * Architecture: * vsnprintf_() ← pure formatting, writes to buffer * ↓ - * kprintf() ← format + emit to UART via early_putc + * kprintf() ← format + emit via console_write_all() * kvprintf() ← va_list variant * ksnprintf() ← format into caller's buffer + * + * Output path: + * Pre-registration: console_write_all() → early_putc() fallback + * Post-registration: console_write_all() → struct console chain */ #include <lume/kprintf.h> #include <lume/console.h> +#include <lume/atomic.h> +#include <arch/cpu.h> #include "printf.h" /* ------------------------------------------------------------------ */ +/* Console spinlock (raw, no scheduler dependency — safe in panic) */ +/* ------------------------------------------------------------------ */ + +static lume::atomic<uint32> g_console_lock{0}; + +static inline void console_lock_acquire() +{ + while (g_console_lock.exchange(1, __ATOMIC_ACQUIRE) != 0) { + /* spin */ + } +} + +static inline void console_lock_release() +{ + g_console_lock.store(0, __ATOMIC_RELEASE); +} + +/* ------------------------------------------------------------------ */ /* _putchar: required by mpaland/printf for printf_() / vprintf_() */ /* ------------------------------------------------------------------ */ @@ -40,10 +63,10 @@ extern "C" int kprintf(const char* fmt, ...) int len = vsnprintf_(buf, sizeof(buf), fmt, va); va_end(va); - /* Emit to console */ - for (int i = 0; i < len && buf[i] != '\0'; ++i) { - early_putc(buf[i]); - } + /* Emit to console under lock */ + console_lock_acquire(); + console_write_all(buf, len); + console_lock_release(); return len; } @@ -52,9 +75,9 @@ extern "C" int kvprintf(const char* fmt, va_list va) char buf[256]; int len = vsnprintf_(buf, sizeof(buf), fmt, va); - for (int i = 0; i < len && buf[i] != '\0'; ++i) { - early_putc(buf[i]); - } + console_lock_acquire(); + console_write_all(buf, len); + console_lock_release(); return len; } |
