Skip to content

KDAL - Kernel Device Abstraction Layer

A hardware-agnostic, pluggable abstraction framework inside the Linux kernel that lets developers write portable device drivers and accelerator backends once and run them on any embedded platform.

Master thesis project - Computer Engineering

  • Single control device (/dev/kdal) with per-fd device selection
  • 4 example drivers over the backends: UART, I2C, SPI, GPU (with accelerator ops)
  • Pluggable backends: QEMU ring-buffer, generic platform device, Device Tree
  • 6 ioctl commands defined: GET_VERSION, GET_INFO, SET_POWER, LIST_DEVICES, SELECT_DEV, and POLL_EVENT (defined, not yet dispatched by the character device)
  • debugfs interface: /sys/kernel/debug/kdal/ for introspection
  • Event system: circular buffer with waitqueue-based notification
  • Power management: per-device power state transitions
  • KUnit tests: 40 in-kernel test cases in 6 suites
  • Userspace tools: CLI tool, smoke test, integration suite, throughput benchmark
  • QEMU-first workflow: fully reproducible on Mac M4 Pro → aarch64 guest
  • KDAL DSL: .kdh device headers + .kdc driver implementations
  • Compiler (kdalc): hand-written lexer → parser → sema → codegen; produces kernel C + Kbuild
  • Standard library: 7 device headers (UART, I2C, SPI, GPIO, GPU, NPU, common)
  • Unified toolchain (kdality): compile, init, lint, simulate, dt-gen, test-gen
  • VS Code extension: syntax highlighting + snippets for .kdh/.kdc
  • CMake modules (7 installed): FindKDAL, Config, Targets, CompileKDC, Toolchain, Testing, Packaging
Terminal window
# Install dependencies (macOS or Linux)
./scripts/env/dependencies.sh
# Prepare QEMU workspace
./scripts/env/prepare.sh
# Build kernel with KDAL support
./scripts/env/kernel.sh
# Build everything (compiler + CLI + VS Code extension)
./scripts/dev/build.sh --variant release all
# Launch QEMU guest
./scripts/env/run.sh
# Inside guest: load module and test
insmod /mnt/shared/kdal.ko
/mnt/shared/kdality version
/mnt/shared/kdality list
flowchart TB US["User space<br/>kdality (CLI), testapp and benchmark (tests/userspace),<br/>kdaltest (tests/integration)<br/>(implemented)"] CP["Control plane: src/core/<br/>chardev.c: /dev/kdal, ioctl dispatch<br/>debugfs.c: introspection and the demand report"] CORE["Core runtime: src/core/<br/>registry, event, power, demand, kdal, module"] DRV["Example drivers: src/drivers/example/<br/>uart, i2c, spi, gpu (accelerator ops)"] BE["Backends: src/backends/<br/>generic: devicetree, platdev, socglue<br/>qemu: qemubackend, virtioio, virtioaccel, mmio"] HW["Devices: MMIO, platform devices,<br/>device tree nodes, virtio"] US -->|ioctl, read, write| CP CP --> CORE CORE --> DRV DRV --> BE BE --> HW classDef observed stroke:#0ca30c,stroke-width:2px classDef implemented stroke:#fab219,stroke-width:2px class CP,CORE,DRV,BE observed class US implemented

Green: built into kdal.ko, which CI loads and tests with its KUnit suites (and which loads inside HAVEN’s partition A on HAVEN’s pull requests). Amber: the user-space programs build, but CI does not run them against the module (it runs kdality only to compile the examples). Key: Reading the diagrams.

See the architecture page for full details.

KDAL is one of three components of the HAVEN Master’s thesis. Its role is the device-access driver inside HAVEN’s Linux partition: the kernel module (src/, include/) and the kdality runtime CLI are active. The KDAL language, the kdalc compiler (compiler/, lang/) and the editor plugins (editor/) are frozen as of 2026-11-01: kept, still built and checked by CI, but not developed further unless the thesis needs them.

Where to work:

  • Maintained: the kernel module (src/, include/, tests/ with kunit, integration and userspace tests, scripts/ci/) and the kdality runtime CLI (tools/). New work, fixes and reviews go here.
  • Frozen since 2026-11-01: lang/, compiler/ and editor/ (the KDAL language, the kdalc compiler and the editor plugins). They are kept and still built by CI, but take no new work unless the thesis needs them. Known limit, parked with the freeze: kdality compile writes C that does not build as a module yet (it includes <linux/kdal.h> and calls a register API KDAL does not provide; docs/open-findings-20261121.md, F1 and F4). The language, simulate, lint, test-gen and dt-gen work. Three more limits, found on 2026-12-03 and parked with the freeze: the compiler checks ro/wo only for registers declared in the file it compiles, so for a driver and its imported header the check is kdality lint (W003, W004); a .kdh with semantic errors (for example a bitfield range written high to low) prints them but still lints “OK” with exit 0, because kdal_sema returns 0 for a header; and kdality compile does not parse the imported headers, so it exits 0 when one is broken. Read the messages, not only the exit status.
include/kdal/ Public API headers (types, ioctl, driver, accel, backend)
src/core/ Core runtime (lifecycle, registry, events, chardev, debugfs)
src/drivers/ Device drivers (UART, I2C, SPI, GPU)
src/backends/ Hardware backends (QEMU, generic)
compiler/ KDAL compiler (kdalc): lexer, parser, sema, codegen
lang/grammar/ EBNF grammars for .kdh and .kdc
lang/stdlib/ Standard device headers (7 .kdh files)
lang/ Language specification + design docs
tools/kdality/ Unified CLI + compiler frontend (kdality)
editor/vscode/ VS Code extension for .kdh/.kdc
editor/vim/ Vim/Neovim plugin for .kdh/.kdc
cmake/ CMake modules for build integration
tests/kunit/ In-kernel tests (40 test cases, 6 suites)
tests/userspace/ Userspace smoke test + benchmark
tests/integration/ Multi-device integration suite
scripts/dev/ Development scripts (build, run, test)
scripts/e2e/ End-to-end test suites
scripts/ci/ CI/CD helper scripts
scripts/installer/ SDK installer (kdalup)
docs/ release workflow, open findings, CI SDK, evidence (the guides are on the documentation site)
examples/ Driver examples (.kdc, plain C, accel demos)
build/ Variant-specific build trees and generated outputs

The project uses CMake 3.20+ as its build system, wrapped by convenience scripts under scripts/dev/.

Terminal window
./scripts/dev/build.sh --variant <name> <target> # Build targets
./scripts/dev/run.sh --variant <name> <target> # Run targets (auto-builds if needed)
./scripts/dev/test.sh --variant <name> <target> # Test targets with PASS/FAIL reporting
  • release: optimized local SDK build in build/release/; use for packaging, install checks, and normal local use.
  • debug: symbols + assertions in build/debug/; use for compiler or CLI debugging.
  • asan: AddressSanitizer-enabled build in build/asan/; use for memory-safety investigations.

Use --variant for normal local development. Use --preset only for automation-oriented trees such as ci-release, nightly, and release-matrix.

Terminal window
./scripts/dev/build.sh --variant release kdalc # Compiler (kdalc + libkdalc.a)
./scripts/dev/build.sh --variant release kdality # CLI toolchain
./scripts/dev/build.sh --variant release vscode # VS Code extension → build/release/editor/vscode/
./scripts/dev/build.sh --variant debug module # Kernel module iteration build
./scripts/dev/build.sh --variant release all # Everything above
./scripts/dev/build.sh --variant asan clean # Remove the asan build tree
./scripts/dev/build.sh --variant release install # Install to system (cmake --install)
Terminal window
export KDAL_KERNEL_DIR=/path/to/linux-6.6
export CROSS_COMPILE=aarch64-linux-gnu-
export ARCH=arm64
./scripts/dev/build.sh --variant debug module
Terminal window
# Run all tests (mirrors CI stages locally)
./scripts/dev/test.sh --variant release all
# Test specific targets
./scripts/dev/test.sh --variant release kdalc # Compiler binary + sample compilation
./scripts/dev/test.sh --variant release kdality # CLI subcommands
./scripts/dev/test.sh --variant release vscode # VS Code extension packaging
./scripts/dev/test.sh --variant release cppcheck # C static analysis (mirrors CI)
./scripts/dev/test.sh --variant release shellcheck # Shell script linting (mirrors CI)
./scripts/dev/test.sh --variant release structure # Project structure validation
./scripts/dev/test.sh --variant release e2e # End-to-end test suites
./scripts/dev/test.sh help # List all testable targets

Test reports are saved under the selected variant tree, for example build/debug/test/<target>_<date>.log.

build/
├── release/ Optimized local build and install validation
│ ├── compiler/ kdalc, libkdalc.a
│ ├── editor/vscode/ .vsix package
│ └── test/ Test reports
├── debug/ Debuggable local build with symbols
├── asan/ AddressSanitizer build
├── ci/release/ CI-only verification build
└── nightly/<os-arch>/ Nightly matrix builds per target host/arch

The KDAL documentation site is part of the ecosystem’s site, docs-haven.vercel.app/kdal (its pages are in the haven-docs repository). The repository’s own documents:

Document Description
Architecture 6-layer design, data flow, init cascade
API Reference All functions, ioctl commands, types
Language Overview Tutorial: .kdh/.kdc from scratch
Language Spec Formal language specification
Language Design Design rationale and comparison table
Installation Setup guide for macOS and Linux
Porting Guide How to add a new backend
Performance Benchmarking methodology and metrics
FAQ Common questions answered
Upstreaming Path to Linux kernel mainline
Thesis Chapter mapping to repository artifacts
Platform Status Backend
QEMU aarch64 virt Implemented qemu (ring buffer)
CIX P1: Orange Pi 6 Plus Planned (thesis board, end of 2026) generic (MMIO + DT)
CIX P1: Radxa Orion O6 / O6N, Orange Pi 6 Reference variants generic (MMIO + DT)

The HAVEN thesis targets the CIX P1 SoC only. In QEMU, KDAL’s module runs in Linux inside HAVEN’s partition A: HAVEN’s CI job “Linux in partition A” builds kdal.ko at the KDAL commit HAVEN pins and checks the device demand it prints.

KDAL v0.2.0 is QEMU-validated only - no real hardware is required.

Terminal window
./scripts/env/dependencies.sh # Install host tools
./scripts/env/prepare.sh # Download Ubuntu cloud image + create QEMU workspace
./scripts/env/kernel.sh # Cross-compile Linux 6.6 with KUnit + virtio
./scripts/env/run.sh # Boot QEMU aarch64 virt machine
# Inside guest: insmod /mnt/shared/kdal.ko
Terminal window
docker build -t kdal-dev -f Dockerfile.dev .
docker run -it -v $(pwd):/workspace kdal-dev
# Inside container: cmake --preset ci-release && cmake --build --preset ci-release

The container includes cmake, gcc, aarch64 cross-compiler, QEMU, cppcheck, shellcheck, and Node.js.

GPL-2.0-only - see LICENSE. Every C source carries its SPDX line; the userspace ABI header include/kdal/ioctl.h is GPL-2.0-only WITH Linux-syscall-note, as the kernel’s own UAPI headers are, so programs that include it are not bound by the GPL. Until 2026-12-03 the repository said GPLv3 while the module declared MODULE_LICENSE("GPL") (GPL version 2) and the compiler’s files said GPL-2.0-only; a GPLv3 module cannot be loaded into the GPLv2 kernel consistently, so KDAL is GPL-2.0-only throughout.

See CONTRIBUTING.md for guidelines.