FAQ
Architecture
Section titled “Architecture”Why QEMU first instead of real hardware?
Section titled “Why QEMU first instead of real hardware?”QEMU provides a deterministic, reproducible environment that eliminates
hardware variance during architecture validation. Every developer gets the
exact same execution environment regardless of whether they have physical
hardware. The QEMU aarch64 virt machine matches the target ISA (ARM64).
Moving a driver to real hardware by swapping only the backend is the design
goal; today the example drivers call the QEMU backend themselves, so they
would change.
Why not support every device class immediately?
Section titled “Why not support every device class immediately?”The first milestone validates the abstraction boundary, not device coverage. Starting with four classes (UART, I2C, SPI, GPU) proves the framework handles both simple serial peripherals and complex accelerators. Adding GPIO, NPU, or others later exercises only the porting guide - the core remains unchanged.
Why a thin core?
Section titled “Why a thin core?”Portability depends on stable interfaces, not on absorbing device details into a monolithic framework. The core is about 1,000 lines managing lifecycle, registry, and events. All hardware logic lives in drivers and backends. This keeps the trusted surface small and auditable.
Why out-of-tree instead of in-tree?
Section titled “Why out-of-tree instead of in-tree?”- Faster iteration without kernel patch review cycles
- A licence of KDAL’s own choosing (in-tree code must be GPLv2-compatible; KDAL’s files do not yet carry one consistent licence)
- Easy deployment via
insmodwithout kernel rebuilds - Clear separation for thesis evaluation
The architecture is designed for future upstreaming - see Upstreaming.
Implementation
Section titled “Implementation”How does device selection work for userspace?
Section titled “How does device selection work for userspace?”KDAL exposes a single /dev/kdal character device. Userspace selects a
device via the KDAL_IOCTL_SELECT_DEV ioctl, which stores the selection
in per-fd state (file->private_data). Subsequent read()/write() calls
route to the selected device’s driver. Multiple processes can open /dev/kdal
independently, each with their own device selection.
Why misc_register instead of a custom major number?
Section titled “Why misc_register instead of a custom major number?”Automatic minor number allocation avoids conflicts with other drivers and simplifies deployment.
How is the ring buffer sized?
Section titled “How is the ring buffer sized?”The QEMU backend allocates a 4096-byte ring buffer per device, balancing memory usage with throughput for emulated I/O. Real hardware backends use DMA buffers or MMIO regions instead.
Why are KUnit tests separate from integration tests?
Section titled “Why are KUnit tests separate from integration tests?”KUnit tests run inside the kernel and test internal APIs without userspace. Integration tests run from userspace and exercise the full ioctl path. Both are needed: KUnit catches internal regressions, integration tests validate the end-to-end contract.
Development
Section titled “Development”How do I build the userspace tool without kernel headers?
Section titled “How do I build the userspace tool without kernel headers?”The tool mirrors ioctl ABI definitions locally and does not depend on kernel headers:
./scripts/dev/build.sh --variant release kdalityHow do I add a new device class?
Section titled “How do I add a new device class?”- Add the class enum to
include/kdal/types.h - Create a driver under
src/drivers/example/ - Wire init/exit into
src/core/kdal.c - Add KUnit tests
- Update
kdality(kdalctl.c) to display the new class name
What kernel versions are supported?
Section titled “What kernel versions are supported?”CI builds and tests the module on Linux 6.18; the local scripts use
6.6.80. The API surface (misc_register, debugfs,
copy_to_user/copy_from_user, mutex, list_head) has been stable since
Linux 4.x, so backporting is straightforward.
Language Ecosystem
Section titled “Language Ecosystem”What are .kdh and .kdc files?
Section titled “What are .kdh and .kdc files?”.kdh (KDAL Device Header) files are declarative descriptions of a
hardware device - register maps, signal definitions, capabilities, and power
states. .kdc (KDAL Driver Code) files contain imperative event handlers
that implement driver logic. Together they separate what a device is from
how it behaves.
How does the KDAL compiler work?
Section titled “How does the KDAL compiler work?”The compiler (kdalc) reads a .kdc file plus its .kdh header, then runs
four pipeline stages:
- Lexer - tokenises source into 80+ token types
- Parser - builds an arena-allocated AST via recursive descent
- Semantic analysis - resolves symbols (register access modes are
checked by
kdality lint, as warnings, not here) - Code generation - emits kernel C +
Makefile.kbuild; the generated module does not build yet (open finding O7)
Why not just write C directly?
Section titled “Why not just write C directly?”The aim is a driver of a few dozen lines of intent instead of the kernel
boilerplate around it (no measurement yet). The compiler emits the
platform_driver registration, OF match table and devm_* resource calls;
the generated module does not build yet (O7). New
programmers can focus on driver logic rather than kernel API minutiae.
Can I write a driver without knowing C?
Section titled “Can I write a driver without knowing C?”Not yet: that is the goal. A .kdc file uses high-level constructs like
probe { ... }, on read(DEV.DATA) { ... } and write(DEV.CTRL, 0x01),
and the compiler generates the module’s C, but until open finding O7 is
fixed that C does not build without changes by hand.
How do I create a custom device header?
Section titled “How do I create a custom device header?”Create a .kdh file anywhere the compiler can find it (or in
lang/stdlib/), following the format in the
Language Specification. A minimal .kdh file declares a
device name and a register map (capabilities are optional). Then import it
from your .kdc with an alias, import "mydevice.kdh" as DEV;, and name its
registers as DEV.<register>: without the alias, accesses are not checked.