feat: D4 DKM colored log prefixes - every driver has its own temper

- log.c: color context (log_set_color / log_color_enable); ANSI only goes to serial, BOOTLOG.TXT buffer stays clean plain text
- kernel_api.c: dkm_log_set_driver() — driver-name FNV-1a hash into an 8-color bright ANSI palette, deterministic per driver
- load sites (dkm_core builtin + boot_modules external) set color around driver_init and clear after
- FUCK [debug] color_log gate (dev=1, release=0)
- QEMU verified: 1150 colored lines, per-driver stable colors (.build_tmp/qemu_serial_d4color.log)
This commit is contained in:
Linehu
2026-10-02 19:48:54 +08:00
parent 068e0e37c3
commit 3aa15e7b21
22 changed files with 130 additions and 9 deletions
+2
View File
@@ -390,7 +390,9 @@ int dkm_load_elf_rel(const void *address, u64 size, const struct dkm_symbol_scan
handle.load_stage = desc->stage;
handle.flags = desc->flags;
dkm_log_set_driver(desc->name); /* D4: 驱动自己的颜色 */
int result = init(dkm_get_kernel_api(), &handle);
dkm_log_set_driver(0);
handle.init_status = result;
if (result != 0) {
handle.state = DKM_STATE_FAILED;
+13
View File
@@ -0,0 +1,13 @@
dkm/boot_modules.o: dkm\boot_modules.c include\utsm\dkm.h \
include\utsm\types.h include\utsm\dma.h include\utsm\block.h \
include\utsm\net.h include\utsm\paging.h include\utsm\log.h \
include\utsm\arena.h dkm\..\arch\x86_64\limine.h
include\utsm\dkm.h:
include\utsm\types.h:
include\utsm\dma.h:
include\utsm\block.h:
include\utsm\net.h:
include\utsm\paging.h:
include\utsm\log.h:
include\utsm\arena.h:
dkm\..\arch\x86_64\limine.h:
Binary file not shown.
+2
View File
@@ -51,8 +51,10 @@ int dkm_load_builtin(const dkm_builtin_driver *driver) {
log_info("[DKM] builtin driver init begin");
log_info(driver->desc->name);
dkm_log_set_driver(driver->desc->name); /* D4: 驱动自己的颜色 */
handle.state = DKM_STATE_INITING;
status = driver->init(dkm_get_kernel_api(), &handle);
dkm_log_set_driver(0);
handle.init_status = status;
if (status != 0) {
+10
View File
@@ -0,0 +1,10 @@
dkm/dkm_core.o: dkm\dkm_core.c include\utsm\dkm.h include\utsm\types.h \
include\utsm\dma.h include\utsm\block.h include\utsm\net.h \
include\utsm\paging.h include\utsm\log.h
include\utsm\dkm.h:
include\utsm\types.h:
include\utsm\dma.h:
include\utsm\block.h:
include\utsm\net.h:
include\utsm\paging.h:
include\utsm\log.h:
Binary file not shown.
+21
View File
@@ -32,6 +32,27 @@ static const dkm_log_api g_log_api = {
.panic = dkm_api_panic
};
/* ---- D4: DKM 彩色日志——每个驱动有自己的脾气 ----
* 加载器在 driver_init 前调用 dkm_log_set_driver(desc->name):
* 驱动名 FNV-1a hash → 8 色调色板(明亮色系,串口可读),
* 同名驱动颜色确定性可复现。init 返回后由调用方清上下文。 */
void dkm_log_set_driver(const char *name) {
static const char *palette[8] = {
"\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[35m",
"\x1b[96m", "\x1b[92m", "\x1b[93m", "\x1b[95m"
};
if (!name || !*name) {
log_set_color(0);
return;
}
u32 h = 2166136261u;
while (*name) {
h ^= (u8)*name++;
h *= 16777619u;
}
log_set_color(palette[h & 7]);
}
static dkm_kernel_api g_kernel_api = {
.version = DKM_KERNEL_API_VERSION,
.size = sizeof(dkm_kernel_api),
Binary file not shown.