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
+1 -1
View File
@@ -174,7 +174,7 @@ kernel_api 已暴露能力:log, rsdp_address, fb_address/width/height/pitch/bp
下一阶段优先路线(活跃路线 = `docs/ROADMAP_INSANE.md` 五期填补计划,任务编号 F/U/D/R/E;状态唯一来源 = `docs/STATUS.md`):
1. **一期 F 系列收尾**: F2 统一控制台后端(fbcon.h 抽象已落,panic 已用)。(F1 莲花 panic / F3 跨平台 Makefile / F4 boot 分级自检 / F5 skip_firstinit 已完成)
2. **二期 U 系列**: ✅ 已完成(U1 UUID 表 / U2 Slow Path 真分支 / U3 @sealed 可选标记+linker .sealed section / U4 密文 dump / U5 RFC 8439 KAT)。chacha20 KAT 三方对拍通过(pycryptodome+官方向量+C),"间歇 FAIL" 确认为从未合并的幽灵缺陷。
3. **三期 D 系列**: DKM 热卸载(引用计数)、裸机器码加载器、按名 API 导出表、彩色日志。
3. **三期 D 系列**: DKM 热卸载(引用计数)、裸机器码加载器、按名 API 导出表。(~~彩色日志~~ D4 已完成:驱动名 hash → 8 色 ANSI,FUCK color_log 开关,BOOTLOG 保持纯文本)
4. **四期 R 系列收尾**: segment/system 级回滚验证、PCQ per-cpu 多核。(~~drr_emergency_pool_kb/drr_recovery_log_size 接线~~ R3b 已完成,运行期钳位验证 PASS)
5. **五期 E 系列**: 启动莲花动画、假想时光键彩蛋、提交信息规范、风味 ISO。
6. **工程债(Phase 存档遗留)**: vector allocator/MSI-X、NVMe 高位 BAR、virtio-net virtqueue、DKM 零 warning。
+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.
+2
View File
@@ -158,6 +158,8 @@ typedef struct dkm_builtin_driver {
} dkm_builtin_driver;
void dkm_init(void);
/* D4: 设置当前驱动日志颜色上下文(driver_init 前设置,返回后清 0) */
void dkm_log_set_driver(const char *name);
int dkm_load_builtin(const dkm_builtin_driver *driver);
void dkm_scan_boot_modules(void);
void dsm_load_by_manifest(void);
+7
View File
@@ -13,6 +13,13 @@ void log_error(const char *msg);
void log_hex64(const char *prefix, u64 value);
void panic(const char *msg);
/* D4: DKM 彩色日志——驱动 init 期间的颜色上下文。
* log_set_color 传 ANSI CSI(如 "\x1b[36m"),0/"" 恢复默认;
* 颜色只走串口,BOOTLOG 缓冲保持纯文本。log_color_enable 总开关
* (FUCK [debug] color_log)。 */
void log_set_color(const char *ansi);
void log_color_enable(int enable);
/* ---- 内存日志缓冲区(实机启动日志持久化) ----
* 由 disk_log_flush() 写入 FAT32 文件 SYSTEM/DESHAB64/DEV/BOOTLOG.TXT。 */
void log_capture_enable(int enable);
+54
View File
@@ -44,7 +44,57 @@ static void log_emit(const char *s) {
}
}
/* ---- D4: DKM 彩色日志 ----
* 驱动 init 期间由 dkm_log_set_driver() 设置 ANSI 颜色上下文;
* 颜色只走串口(QEMU stdio 可见),BOOTLOG 缓冲保持纯文本。 */
static const char *g_log_color = 0;
static int g_log_color_on = 1;
void log_set_color(const char *ansi) {
g_log_color = ansi;
}
void log_color_enable(int enable) {
g_log_color_on = enable;
if (!enable) g_log_color = 0;
}
/* 串口带色输出 + 缓冲纯文本(临界区内) */
static void log_emit_colored(const char *color, const char *a,
const char *b, const char *c) {
u64 flags;
__asm__ volatile("pushfq; popq %0; cli" : "=r"(flags) :: "memory");
serial_write(color);
serial_write(a);
if (b) serial_write(b);
if (c) serial_write(c);
serial_write("\x1b[0m\n");
if (g_log_capture_on) {
const char *parts[3] = { a, b, c };
for (int i = 0; i < 3; i++) {
const char *s = parts[i];
if (!s) continue;
while (*s) {
if (g_log_len < LOG_BUF_SIZE) {
g_log_buf[g_log_len++] = *s;
}
s++;
}
}
if (g_log_len < LOG_BUF_SIZE) {
g_log_buf[g_log_len++] = '\n';
}
}
if (flags & (1ULL << 9)) {
__asm__ volatile("sti" ::: "memory");
}
}
static void log_line(const char *level, const char *msg) {
if (g_log_color && g_log_color_on) {
log_emit_colored(g_log_color, level, " ", msg);
return;
}
log_emit(level);
log_emit(" ");
log_emit(msg);
@@ -72,6 +122,10 @@ void log_hex64(const char *prefix, u64 value) {
buf[2 + i] = hex[(value >> ((15 - i) * 4)) & 0xf];
}
buf[18] = 0;
if (g_log_color && g_log_color_on) {
log_emit_colored(g_log_color, prefix, buf, 0);
return;
}
log_emit(prefix);
log_emit(buf);
log_emit("\n");
Binary file not shown.
+4
View File
@@ -299,6 +299,10 @@ void kernel_main(void) {
g_boot_cfg_loaded = (utsm_load_fuck_config(&g_boot_cfg) == 0);
ini_config *cfg = g_boot_cfg_loaded ? &g_boot_cfg : NULL;
/* D4: DKM 彩色日志总开关(FUCK [debug] color_log,默认开;
* 颜色只走串口,BOOTLOG.TXT 保持纯文本) */
log_color_enable(ini_get_bool(cfg, "debug", "color_log", 1));
/* ---- 插桩: FUCK 配置加载完成 ---- */
INSTR_PROBE(BOOT, (u64)g_boot_cfg_loaded, 0, 0, 0);
Binary file not shown.
Binary file not shown.
+4 -2
View File
@@ -1,4 +1,4 @@
# Deshab Kernel Configuration — dev 变体(build/configs/dev/FUCK)
# Deshab Kernel Configuration — dev 变体(build/configs/dev/FUCK)
# build.ps1 -Variant dev 打包前注入 SYSTEM/system/deshab64/FUCK
# 开发者模式:selftest 开、dev_mode 自动跑 shell.elf 测试、日志持久化、跳过向导直达桌面
@@ -6,7 +6,7 @@
vmm=1
linux_guest=1
xj380_guest=0
# F4: 分级自检 0=关 1=快速 2=全量(含 UTSM selftest;注意 chacha20 KAT 间歇 FAIL 会挡启动)
# F4: 分级自检 0=关 1=快速 2=全量(含 UTSM selftest;RFC 8439 KAT 已确定性对拍通过)
selftest=1
# F1 验证钩子: 1=启动自检后触发莲花崩溃屏(演示/回归用,日常保持 0)
panic_test=0
@@ -83,6 +83,7 @@ dsk_trace=1
block_trace=1
net_trace=0
input_trace=1
color_log=1
[compat]
lib_path=lib
@@ -101,3 +102,4 @@ pe_dll_search=1
+4 -2
View File
@@ -1,4 +1,4 @@
# Deshab Kernel Configuration — dev 变体(build/configs/dev/FUCK)
# Deshab Kernel Configuration — dev 变体(build/configs/dev/FUCK)
# build.ps1 -Variant dev 打包前注入 SYSTEM/system/deshab64/FUCK
# 开发者模式:selftest 开、dev_mode 自动跑 shell.elf 测试、日志持久化、跳过向导直达桌面
@@ -6,7 +6,7 @@
vmm=1
linux_guest=1
xj380_guest=0
# F4: 分级自检 0=关 1=快速 2=全量(含 UTSM selftest;注意 chacha20 KAT 间歇 FAIL 会挡启动)
# F4: 分级自检 0=关 1=快速 2=全量(含 UTSM selftest;RFC 8439 KAT 已确定性对拍通过)
selftest=1
# F1 验证钩子: 1=启动自检后触发莲花崩溃屏(演示/回归用,日常保持 0)
panic_test=0
@@ -83,6 +83,7 @@ dsk_trace=1
block_trace=1
net_trace=0
input_trace=1
color_log=1
[compat]
lib_path=lib
@@ -101,3 +102,4 @@ pe_dll_search=1
+3 -1
View File
@@ -1,4 +1,4 @@
# Deshab Kernel Configuration — release 变体(build/configs/release/FUCK)
# Deshab Kernel Configuration — release 变体(build/configs/release/FUCK)
# build.ps1 -Variant release 打包前注入 SYSTEM/system/deshab64/FUCK
# 发布版:调试零开销、进登录+向导正常路径、真机安全选项
@@ -81,9 +81,11 @@ dsk_trace=0
block_trace=0
net_trace=0
input_trace=0
color_log=0
[compat]
lib_path=lib
linux_lib_guest_path=/usr/lib/deshab
linux_lib_sync=0
pe_dll_search=1
+1 -1
View File
@@ -61,7 +61,7 @@ Deshab 最标志性的疯点——给空气上锁。
| D1 | DKM 热卸载(基础) | 从"焊死"到"可拔" | ⬜ | 仅有 `DKM_F_NO_UNLOAD` 标志与状态机文档;需引用计数+资源回收,load/unload 循环 100 次不崩 |
| D2 | 裸机器码加载器 | 真·无限自由 | ⬜ | 任意 elf/裸码塞地址即执行;能打印、能崩内核 |
| D3 | 内核 API 导出表 | 自由也要有地图 | ⬜ | 当前为固定偏移 struct ABI(`CODE/sdk/include/deshab/kernel_api.h`);需按名导出表 kapi() |
| D4 | DKM 彩色日志前缀 | 每个驱动有自己的脾气 | ⬜ | 加载时自选颜色;日志一眼看出是谁在骂 |
| D4 | DKM 彩色日志前缀 | 每个驱动有自己的脾气 | ✅ | 驱动名 FNV hash → 8 色 ANSI(确定性可复现);init 期着色,仅串口;FUCK `color_log` 开关 |
| D5 | 最小 REPL/shell | 自由的交互面 | ✅ | shell.elf:ls/cat/cp/mv/rm/run/probe/test/pci 等 25+ 命令 |
三期做完:用户能真在系统里"为所欲为",疯得可上手。
+1 -1
View File
@@ -45,7 +45,7 @@
| virtio_net | 🔶 | PCI/capability 枚举,无 virtqueue | — |
| 热卸载(D1) | ⬜ | 仅有 NO_UNLOAD 标志与状态机文档 | — |
| 按名 API 导出表(D3) | ⬜ | 固定偏移 struct ABI | `CODE/sdk/include/deshab/kernel_api.h` |
| 彩色日志(D4) | ⬜ | 仅 info/warn/error/panic | — |
| 彩色日志(D4) | ✅ | `dkm_log_set_driver`(驱动名 FNV hash → 8 色调色板,确定可复现);init 期间驱动日志带 ANSI 色(仅串口,BOOTLOG 纯文本);FUCK `[debug] color_log` 总开关 | `.build_tmp/qemu_serial_d4color.log`(1150 彩色行) |
## DSK 主内核 / 用户态
+1 -1
View File
@@ -25,7 +25,7 @@
- [ ] D1 DKM 热卸载(引用计数 + 资源回收,循环 100 次不崩)
- [ ] D2 裸机器码加载器
- [ ] D3 内核 API 按名导出表(kapi())
- [ ] D4 DKM 彩色日志前缀
- [x] D4 DKM 彩色日志前缀(驱动名 hash → 8 色 ANSI,init 期着色,BOOTLOG 保持纯文本)
## ⏪ 四期:落款(DRR/PCQ)