Language Specification
Version: 0.1 | Status: Draft | Applies to: kdalc ≥ 0.1, kdality ≥ 0.1
1. Overview
Section titled “1. Overview”KDAL defines two file formats that together describe a hardware device and its Linux kernel driver:
| Extension | Role | Analogous to |
|---|---|---|
.kdh |
Device header - register map, signals, capabilities | C .h header + device tree binding |
.kdc |
Driver implementation - event handlers compiled to .ko |
C .c source + Kbuild Makefile |
The compiler translates a .kdc file (and its imported .kdh files) into:
- a C translation unit (
.c) containing akdal_driver_opsstruct and all handler functions - a Kbuild fragment (
Makefile.kbuild) formake -C $KERNEL_DIR M=$PWD modules
At 5eff1ff: that module build fails (open finding O7 in KDAL’s
docs/open-findings-20261121.md).
2. Design Goals
Section titled “2. Design Goals”- Auditable surface - not Turing-complete. No recursion, no heap, no pointers. Every program terminates.
- Kernel-space first - all output targets the Linux kernel ABI. No libc, no syscalls.
- Type safety at register level - access direction verified before the module is built (ro/wo/rw/rc).
At 5eff1ff: kdalc checks ro/wo only for registers declared in
the file it compiles; for a driver and its imported header the check is
kdality lint (W003, W004). Not every program is shown to terminate: a
loop bound the compiler cannot show to be constant is a warning.
4. Backend agnostic - same .kdc targets MMIO, platform_device, devicetree, virtio, or QEMU.
5. Self-describing - .kdh + .kdc fully describe device and driver.
3. Lexical Rules
Section titled “3. Lexical Rules”Comments
Section titled “Comments”// single-line comment/* multi-line comment */Keywords
Section titled “Keywords”kdal_version import as device class registers signalscapabilities power config backend driver for proberemove on read write signal timeout power emitwait arm cancel let return log if elif else intrue false ro wo rw rc rising falling anyhigh low edge level completion allowed forbiddendefault on off suspend forThe type names (u8 to u64, i8 to i64, bool, str, buf,
bitfield) are keywords too. use and while are not: use is reserved
for a later version (section 12), and there is no while.
Primitive Types
Section titled “Primitive Types”| Type | Width | Signed |
|---|---|---|
u8 |
8-bit | no |
u16 |
16-bit | no |
u32 |
32-bit | no |
u64 |
64-bit | no |
i8 |
8-bit | yes |
i16 |
16-bit | yes |
i32 |
32-bit | yes |
i64 |
64-bit | yes |
bool |
1-bit | - |
str |
NUL-terminated, read-only | - |
timeout |
opaque timer handle | - |
buf[T] |
contiguous array of T |
- |
Integer Literals
Section titled “Integer Literals”42 // decimal0xFF // hexadecimal (case-insensitive)0b1010 // binary4. Device Header Format (.kdh)
Section titled “4. Device Header Format (.kdh)”See Device Headers for detailed examples.
kdal_version: "0.1";import "...";device class <Name> { compatible "..."; class <device_class>; registers { … } signals { … } capabilities { … } power { … } config { … }}5. Driver Implementation Format (.kdc)
Section titled “5. Driver Implementation Format (.kdc)”See Driver Code for detailed examples.
kdal_version: "0.1";import "device.kdh" as DEV;backend <type> { … }driver <Name> for DEV.<Device> { config { … } probe { … } remove { … } on read(DEV.<REG>) { … } on write(DEV.<REG>, val) { … } on signal(DEV.<signal>) { … } on power(<A> -> <B>) { … } on timeout(DEV.<timer>) { … }}6. Backend Annotations
Section titled “6. Backend Annotations”| Backend | Description |
|---|---|
mmio |
Direct MMIO register access via ioremap |
platdev |
Linux platform_device / platform_driver |
devicetree |
DT-compatible (generates OF match table) |
virtio |
VirtIO transport (QEMU) |
soc |
SoC vendor glue layer |
qemu |
QEMU ring-buffer emulation |
At 5eff1ff: the backend declaration and its options are parsed, but
the code generator emits the same platform_driver module whatever the
backend.
7. Event Handlers
Section titled “7. Event Handlers”| Handler | Trigger |
|---|---|
on read(reg) |
Userspace reads reg via /dev/kdal |
on write(reg, val) |
Userspace writes val to reg |
on signal(sig) |
IRQ or GPIO edge/level event |
on power(A -> B) |
Power state transition |
on timeout(t) |
Armed timer fires |
8. Built-in Operations
Section titled “8. Built-in Operations”| Operation | Description |
|---|---|
read(reg_path) |
Returns register value as typed integer |
write(reg_path, val) |
Writes typed value to register |
emit(signal [, val]) |
Triggers an output signal |
wait(signal, ms) |
Waits for signal with timeout |
arm(timer, ms) |
Starts a one-shot or periodic timer |
cancel(timer) |
Cancels armed timer |
log(fmt, ...) |
Kernel pr_debug/dev_dbg print |
9. Control Flow
Section titled “9. Control Flow”if (condition) { … } elif (condition) { … } else { … }for i in 0..8 { … } // bounded range - always terminatesNo while, no goto, no break, no continue.
10. Type Rules
Section titled “10. Type Rules”- Register reads return the declared type (
u8,u16,u32,u64, or bitfield width) - Write values are implicitly narrowed; out-of-range is a compile error
boolis not implicitly promoted to integersstrvalues are read-only, only aslogformat arguments
At 5eff1ff: none of these four rules is checked: the semantic
analysis checks register access (see above), duplicate names, register
overlap, bitfield ranges, loop bounds and wait() in on write.
11. Error Messages
Section titled “11. Error Messages”my_driver.kdc:12:5: error: register 'DATA' is declared 'ro' - cannot writemy_driver.kdc:18:3: warning: wait() inside on_write handler may block IRQ contextmy_device.kdh:7:1: note: DATA declared hereSeverity levels: error (abort), warning (continue), note (context), hint (suggestion).
At 5eff1ff: the compiler has error, warning and note
(kdal_error, kdal_warn, kdal_note); no hint.
12. Reserved Future Keywords
Section titled “12. Reserved Future Keywords”sync async atomic pub priv use module pkgtest bench mock sim trace profile