重磅项目 · 从零构建 Flagship · Built From Scratch

Deshab-OS

一个从零编写的独立 64 位操作系统。双内核架构,单地址空间 Ring0,封缄内存,16 驱动 DKM 模块系统,内置 Linux/PE 双兼容层。 An independent 64-bit OS written from scratch. Dual-kernel architecture, single address space Ring0, sealed memory, 16-driver DKM module system, built-in Linux/PE compatibility layers.

x86_64 long mode · Limine · C11 + ASM · LLVM · SAS-R0 · UTSM · DRR · DKM

16/16 DKM 驱动16/16 DKM Drivers
桌面 / Shell / LoginDesktop / Shell / Login
网络栈 (DHCP/ARP/DNS)Network Stack
UTSM 加密原语UTSM Crypto

📑 目录Contents

📐

系统架构System Architecture

Deshab-OS 采用双内核架构:UTSM(首阶段内核)负责平台初始化和驱动加载,DSK(主内核)负责运行时调度与用户交互。两者通过版本化的 dsk_boot_context 结构体交接。 Deshab-OS uses a dual-kernel architecture: UTSM (first-stage kernel) handles platform init and driver loading, while DSK (main kernel) manages runtime scheduling and user interaction. They communicate via a versioned dsk_boot_context structure.

┌─────────────────────────────────────────────────────────┐ UEFI / BIOS Limine Bootloader ├──► utsm.elf (首阶段内核) │ │ │ ├── serial · IDT · arena · DMA │ ├── UTSM 封缄内存 初始化 │ ├── DKM 4-Stage 16 驱动 加载 │ │ │ │ Stage 0: timer · apic · acpi · pci │ │ Stage 1: console_fb · ahci · nvme · xhci · bootfs │ │ Stage 2: vfs · fat32 · devfs │ │ Stage 3: e1000 · virtio_net · ath9k · ps2kbd │ │ │ └── dsk_boot_context ──► deshab.elf (主内核) │ │ │ FirstInit → mouseInit → netman → desktop │ 或 login → desktop └─────────────────────────────────────────────────────────┘
🗂️

SAS-R0 单地址空间SAS-R0 Single Address Space

内核、驱动、用户程序共享同一地址空间,省去特权级切换与地址空间切换开销。配合 Per-CPU O(1) 位图调度器,调度热路径严格 O(1)。Kernel, drivers, and user programs share one address space, eliminating privilege-level and address-space switching overhead. Paired with a Per-CPU O(1) bitmap scheduler.

🔐

UTSM 封缄内存UTSM Sealed Memory

所有普通内存以密文存储,明文读写必须经过 UTRW。128-bit UUID 调谐加密,64B cache line 粒度,4KB 完整性校验。三级读写路径:Fast / Slow / Raw。All memory stored encrypted; plaintext access requires UTRW. 128-bit UUID-tuned, 64B cache-line granularity, 4KB integrity checks. Three access paths: Fast / Slow / Raw.

🛡️

DRR 专用恢复根DRR Recovery Root

独立 Emergency Pool,OOM 不阻断恢复。Checkpoint 只处理 dirty shard/page。A/B 双槽 + CRC 校验 + 原子切换。三级恢复:Page → Segment → System Rollback。Independent Emergency Pool, OOM-proof. Checkpoint only dirty shards/pages. A/B dual-slot + CRC + atomic swap. Three-tier recovery: Page → Segment → System Rollback.

🔌

DKM 驱动模块系统DKM Driver Module System

驱动以独立 ELF64 .drv 模块存在,通过统一 ABI 与内核解耦。4 阶段加载,失败策略分级(required → DRR/panic,optional → 标记跳过)。16 个真实驱动全部 ACTIVE。Drivers as independent ELF64 .drv modules, decoupled via unified ABI. 4-stage loading with tiered failure policies. All 16 real drivers ACTIVE.

五大核心架构支柱Five Core Architecture Pillars

SAS-R0-PCQ

单地址空间 Ring0 + Per-CPU O(1) 调度队列。切换只加载加密上下文指针,绝不扫描 capability、不计算 MAC、不重加密、不写 checkpoint。Single Address Space Ring0 + Per-CPU O(1) queues. Context switches only load encrypted pointers — no capability scans, MAC calculations, re-encryption, or checkpoint writes.

UTSM

UUID-Tuned Sealed Memory。内存默认密文形态。每 CPU 密钥缓存 (PCKC),capability O(1) 定位。epoch 过期 / MAC 失败 → Slow Path 异常恢复。Memory default-ciphertext. Per-CPU Key Cache (PCKC), O(1) capability lookup. Epoch expiry / MAC failure → Slow Path exception recovery.

UTRW

带标记读写器。所有明文内存访问必须经过 UTRW。读写分 Fast Path (PCKC 命中) / Slow Path (密钥缺失) / Raw Path (直接读密文)。Tagged Read/Write mediator. All plaintext memory access must go through UTRW. Three paths: Fast (PCKC hit) / Slow (key miss) / Raw (direct ciphertext).

DRR

Dedicated Recovery Root。独立 Emergency Pool,仅处理 dirty 数据。A/B 双槽 + CRC + active slot 原子切换,杜绝半写 checkpoint。Independent Emergency Pool, dirty-only processing. A/B dual-slot + CRC + atomic active-slot swap — no half-written checkpoints.

DKM

驱动 ELF64 .drv,通过 driver_desc / driver_init / driver_exit ABI 与内核解耦。通过 dkm_kernel_api 调用内核服务,不直接依赖内核符号。ELF64 .drv modules decoupled via driver_desc / driver_init / driver_exit ABI. Kernel services via dkm_kernel_api, no direct symbol dependency.

🖥️

FUCK 配置

启动配置文件 SYSTEM/system/deshab64/FUCK 采用 INI 格式。控制启动行为、驱动开关、UTSM 参数、桌面行为。UTSM 阶段经 Limine boot module 读取,DSK 阶段经 FAT32 读取。Boot config FUCK in INI format. Controls boot behavior, driver toggles, UTSM params, desktop behavior. Read via Limine module (UTSM) or FAT32 (DSK).

🚀

DBS 五阶段启动序列DBS Five-Stage Boot Sequence

Deshab Boot Sequence (DBS) 每阶段有明确的 Entry / Exit / Fail 承诺与可验证串口锚点。 Each stage has clear Entry / Exit / Fail contracts and verifiable serial anchors.

阶段Stage 代号Codename 含义Meaning 锚点Anchor
B0 Ignis 火种 固件 → Limine → utsm.elf 入内存Firmware → Limine → utsm.elf loaded [UTSM] boot
B1 Sigillum 封缄解封 UTSM 建立封缄内存 + 16 驱动 ACTIVEUTSM sealed memory + 16 drivers ACTIVE [UTSM] SELFTEST PASS
B2 Transitus 交接 UTSM → DSK 版本化 context 传递UTSM → DSK versioned context handoff [UTSM] jumping to DSK
B3 Origo 溯源 DSK 判定首次 / 正常启动DSK determines first/normal boot [DSK] context ok
B4 Excitas 唤醒 FirstInit 向导或登录 → 桌面FirstInit wizard or login → desktop [DSK] loading desktop
🔌

驱动矩阵 (16 DKM 驱动)Driver Matrix (16 DKM Drivers)

Stage 类别Class 驱动Driver 能力Capability 失败策略Fail Policy
0platform timer PIT 校准 + 精确延时PIT calibration + precise delay required → DRR
0platform apic CPUID / MADT / LAPIC MMIO / IOAPIC 路由接管CPUID / MADT / LAPIC MMIO / IOAPIC routing
0platform acpi RSDP → XSDT,ACPI 表枚举RSDP → XSDT, ACPI table enumeration
0bus pci PCI config space 扫描,设备枚举PCI config space scan, device enumeration
1console console_fb Limine framebuffer,图形清屏Limine framebuffer, graphical clear required → DRR
1block ahci PCI AHCI + IDENTIFY/READ/WRITE DMA + ahci0 providerPCI AHCI + IDENTIFY/READ/WRITE DMA + ahci0 provider
1block nvme PCI NVMe 探测(BAR0>4G 待高位 MMIO)PCI NVMe discovery (high MMIO pending)
1block xhci USB xHCI + MSC (BOT/SCSI) + usb0 providerUSB xHCI + MSC (BOT/SCSI) + usb0 provider
1fs bootfs Limine boot module 内存文件系统Limine boot module in-memory filesystem
2fs vfs 挂载 bootfs,文件查找 / 读取Mount bootfs, file lookup / read fallback bootfs
2fs fat32 只读 FAT32(优先 block provider,回退 boot module)Read-only FAT32 (block provider first, fallback boot module)
2fs devfs /dev/version /dev/platform /dev/fb0 /dev/modules /dev/boot/Virtual device filesystem
3net e1000 PCI + MAC + RX/TX ring + DHCP/ARP/UDP/DNSPCI + MAC + full RX/TX ring + DHCP/ARP/UDP/DNS 标记 FAILED 继续
3net virtio_net PCI + modern virtio capability 枚举PCI + modern virtio capability enumeration
3net ath9k Atheros AR928x WiFi,被动扫描 / 802.11 beaconAtheros AR928x WiFi, passive scan / 802.11 beacon
3input ps2kbd IRQ1,scancode set 1 → ASCIIIRQ1, scancode set 1 → ASCII

驱动状态机:DISCOVERED → QUEUED → DEP_WAIT → LOADING → ELF_CHECKED → MEMORY_ALLOCATED → RELOCATED → ABI_CHECKED → INITING → ACTIVE Driver FSM: DISCOVERED → QUEUED → DEP_WAIT → LOADING → ELF_CHECKED → MEMORY_ALLOCATED → RELOCATED → ABI_CHECKED → INITING → ACTIVE

🌐

网络栈Network Stack

📡

e1000 完整收发链路Full TX/RX Path

DHCP 四步握手获取 IP → ARP 解析网关 MAC → DNS A 记录查询外部域名。netman 网络管理器由 DSK 调度,完成早期联网闭环。DHCP 4-step handshake → ARP gateway MAC resolution → DNS A record query. netman network manager scheduled by DSK for early networking.

📶

ath9k WiFi 支持WiFi Support

Atheros AR928x 芯片组。EEPROM 解析、被动扫描、802.11 beacon 帧解析。需真实硬件测试(QEMU 不支持 WiFi 模拟)。Atheros AR928x chipset. EEPROM parsing, passive scanning, 802.11 beacon frame parsing. Requires real hardware (QEMU cannot emulate WiFi).

🔀

virtio_net

PCI + modern virtio capability 枚举。支持 QEMU virtio-net-pci 设备 (1af4:1001)。PCI + modern virtio capability enumeration. Supports QEMU virtio-net-pci device (1af4:1001).

🖥️

桌面环境Desktop Environment

desktop.elf — 全屏独占 framebuffer,复刻 Winux-Kate 布局,提供完整桌面体验。 desktop.elf — Full-screen exclusive framebuffer, Winux-Kate-inspired layout, complete desktop experience.

📄

多页面Multi-Page

DASHBOARD(四面板)/ IDE(多标签)/ DESKTOP(图标网格 + 浮动窗口)/ CUSTOM(外部 ELF 宿主)DASHBOARD (4-panel) / IDE (multi-tab) / DESKTOP (icon grid + floating windows) / CUSTOM (external ELF host)

🪟

窗口管理Window Management

最多 8 个窗口,支持拖拽 / 聚焦 / 最小化 / 关闭,6 个工作区。Up to 8 windows, drag / focus / minimize / close, 6 workspaces.

📱

内置应用Built-in Apps

shell(Linux 风格)/ cmd(Windows 风格)/ editor / fileman / calc / browsershell (Linux-style) / cmd (Windows-style) / editor / fileman / calc / browser

🎨

渲染引擎Rendering Engine

双缓冲 + 脏矩形合并(仅 flip 包围盒)+ 行级脏标记增量渲染 + 亮度延迟应用。"Sealed Arc" 设计语言(Arc 弧 / Seal 封 / Flow 流),暗色主题。Double-buffered + dirty rect merging + line-level dirty incremental rendering + deferred brightness. "Sealed Arc" design language, dark theme.

🔤

字体系统Font System

DBF 格式 8bpp 灰度位图字体。GB2312 6763 汉字 + ASCII 全覆盖,16/24/32px 三档字号。索引按 codepoint 升序二分查找。DBF format 8bpp grayscale bitmap. GB2312 6763 Hanzi + ASCII full coverage, 16/24/32px sizes. Binary search by codepoint.

FirstInit 首次启动向导Wizard

圆角卡片 UI,PS/2 键盘 + 鼠标输入。引导用户设置计算机名 / 用户名 / 密码 → 网络配置(WiFi)。SHA256 + XOR 加密写入 USER.CONF。Rounded card UI, PS/2 keyboard + mouse. Guides through computer name / username / password → network setup (WiFi). SHA256 + XOR → USER.CONF.

🔗

双兼容层Dual Compatibility Layers

🐧

Linux 兼容层Linux Compat Layer

Park-and-Resume 双内核(类 WSL)。UTSM 充当 VMM (VMX root),Linux 6.6 LTS 作为 guest (VMX non-root) 常驻内存。IPC 委托执行:共享内存 ring + VMCALL hypercall + IPI。Shell 提供 dsl 命令。代码全链路就绪,VMX 实机验证待嵌套虚拟化环境。Park-and-Resume dual-kernel (WSL-like). UTSM as VMM (VMX root), Linux 6.6 LTS guest (VMX non-root) parked in memory. IPC delegation: shared memory ring + VMCALL hypercall + IPI. dsl shell commands. Full code path ready; VMX hw verification pending nested virt env.

🪟

PE/EXE 兼容层PE/EXE Compat Layer

极简 Wine。UTSM 内置 PE 加载器 + Windows API shim + x86-32 解释器。PE32+ (64 位) 重定位加载 → IAT 填 ms_abi shim → Ring0 原生执行。PE32 (32 位) 加载 → 合成 IAT → x86emu32 解释执行。Minimal Wine. UTSM built-in PE loader + Windows API shim + x86-32 interpreter. PE32+ (64-bit): relocate → IAT ms_abi shim → Ring0 native. PE32 (32-bit): load → synthetic IAT → x86emu32 interpreted.

🔧

构建与运行Build & Run

系统要求System Requirements

工具Tool 版本Version 用途Purpose
LLVM Clang14+C11 / 汇编编译C11 / ASM compilation
ld.lld14+链接器Linker
make任意Any各模块构建Module builds
Python 3 + Pillow3.8+字体生成Font generation
QEMU7+UEFI 启动验证UEFI boot verification
PowerShell5.1+构建脚本Build script

build.ps1 会自动扫描 C:\Program Files\LLVM\bin 等常见目录发现 clang / ld.lld,即使不在 PATH 也可用。 build.ps1 auto-scans common directories for clang/ld.lld, so they work even when not in PATH.

构建Build

# 在项目根目录执行Run from project root .\build.bat

build.bat 调用 build.ps1,完整产出:utsm.elf + deshab.elf + 16 个 .drv 驱动 + GPT/FAT32 ESP 磁盘镜像 ISO/deshab.img build.bat calls build.ps1, producing: utsm.elf + deshab.elf + 16 .drv drivers + GPT/FAT32 ESP disk image ISO/deshab.img.

运行 (QEMU UEFI)Run (QEMU UEFI)

.\ISO\run_qemu.bat

预期启动锚点: Expected boot anchors:

[UTSM] boot [UTSM] SELFTEST PASS [UTSM] jumping to DSK [DSK] boot [DSK] context ok [DSK] FUCK config loaded [DSK] loading desktop

设备测试场景Device Test Scenarios

驱动Driver QEMU 参数Flags 验证Verification
ahci临时 SATA 测试盘Temp SATA test diskahci0 block provider, FAT32 读取read
nvme-device nvme探测Probe 1b36:0010
e1000-device e1000eRX/TX ring, DHCP 联网online
virtio_net-netdev user -device virtio-net-pci探测Probe 1af4:1001
ath9k真实硬件Real hardwareQEMU 不支持 WiFi 模拟No QEMU WiFi emulation
📊

开发状态Development Status

子系统Subsystem 状态Status 备注Notes
早期启动 / IDT / PIC / IOAPIC-LAPIC 路由Early boot / IDT / PIC / IOAPIC-LAPIC routing✅ 完成
DKM 驱动加载 (16/16)DKM driver loading (16/16)✅ 完成
DMA 物理页分配器DMA physical page allocator✅ 完成
AHCI 块设备 (读/写)AHCI block device (R/W)✅ 完成
FAT32 (读 + DSK 侧写)FAT32 (read + DSK-side write)✅ 完成
e1000 网络 (DHCP/ARP/DNS)e1000 network (DHCP/ARP/DNS)✅ 完成
字体系统 (GB2312 全覆盖)Font system (GB2312 full coverage)✅ 完成
桌面 / shell / cmd / loginDesktop / shell / cmd / login✅ 完成
PE/EXE 兼容层PE/EXE compatibility layer✅ 完成
Linux 兼容层Linux compatibility layer✅ 完成代码全链路;VMX 实机验证待嵌套虚拟化环境Code complete; VMX hw verification pending nested virt
FirstInit 首次启动向导FirstInit wizard✅ 完成
配置持久化 (USER.CONF 写盘)Config persistence (USER.CONF)✅ 完成
UTSM 封缄内存UTSM sealed memory🔶 selftest 闭环占位加密,真实加密原语待落地Placeholder crypto; real primitives pending
NVMe🔶 PCI discovery待高位 MMIO 映射High MMIO mapping pending
SAS-R0-PCQ 调度器Scheduler⬜ 设计完成
DRR 恢复系统Recovery System⬜ stub 占位
📚

设计文档Design Documents

文档Document 内容Content
📐 架构设计Architecture 五大核心子系统、内存模型、驱动系统Five core subsystems, memory model, driver system
🚀 启动路线设计Boot Sequence DBS 五阶段启动序列、启动契约、回退链DBS 5-stage boot, contracts, fallback chain
🗺️ 开发路线图Roadmap 分阶段路线、里程碑、验收标准Phased roadmap, milestones, acceptance criteria
🖥️ 桌面设计Desktop Design 桌面页面、应用、视觉与渲染Desktop pages, apps, visuals & rendering
🔗 兼容层设计Compat Layer Design Linux park-and-resume 与 PE/EXE 兼容层Linux park-and-resume & PE/EXE compat layers