Skip to main content
Createyourownprogramming
Createyourownprogramming
languageandOSusingOCaml,
languageandOSusingOCaml,
LLVM,andGenerativeAI--
LLVM,andGenerativeAI--
accessibletoeveryone
accessibletoeveryone
Kiwamu Okabe
github.com/takibi-lang/takibi
Welovebuildingoperatingsystems
But the traditional implementation language is a problem:
C language gives the kernel complete control
+
C language gives the kernel almost no proof
=
one bad access can corrupt the entire system
We wanted a language designed for the place where a crash is least recoverable.
Could more kernel failures become compile-time errors?
2 / 15
OCaml Meeting 2026 in Tokyo
2
WhyOCaml+LLVM+GenerativeAI?
Ingredient Role
OCaml Make syntax and static semantics explicit and changeable
LLVM Produce real native code without writing machine backends
Generative AI Implement enough compiler and kernel code to test ideas end-to-end
The LLVM project officially maintains OCaml bindings.
LLVM IR is still hard. AI made it easy.
3 / 15
OCaml Meeting 2026 in Tokyo
3
Thesetup,keepsthehumanontheloop
Linux Desktop
devcontainer
Takibi toolchain
Raspberry Pi 5
USB storage (ext2)
Memory
Takibi kernel
AI Agents Internet
AI coding CLIs
Claude Code · Codex · Copilot
Ethernet
validate httpd
TCP/IP stack
UART
monitor logs
UART monitor
SWD
memory + debug
OpenOCD + GDB
SWD debug interface
hardware memory access
Takibi compiler
OCaml + LLVM
kernel image
BusyBox (httpd)
UART driver
4 / 15
OCaml Meeting 2026 in Tokyo
4
Demo
0:00 / 0:55
5 / 15
OCaml Meeting 2026 in Tokyo
5
Thekernelisthelanguage-designworkload
1
AI implements
a real kernel path
2 Repeated
Takibi code patterns
expose missing guarantees
3 The OCaml
compiler learns
a checked abstraction
4
The next
kernel path
becomes safer and simpler
6 / 15
OCaml Meeting 2026 in Tokyo
6
Ctechnique:describeNICstatewithbooleans
frame->valid = true;
frame->tx_in_flight = true;
frame->released = false;
The representation also permits contradictions:
frame->valid && frame->released
frame->tx_in_flight && frame->available
Every caller must remember which combinations are legal.
The compiler sees only fields and integers.
7 / 15
OCaml Meeting 2026 in Tokyo
7
Takibitechnique1:theNICisacapabilitystate
machine
NetRxCanAcquire
-> NetRxValidated[desc]
-> NetRxReplyReady[desc]
-> NetTxInFlight[desc]
-> NetRxCanAcquire
fn net_transmit(reply: sink NetRxReplyReady[desc])
-> NetTxInFlight[desc];
fn net_tx_complete(in_flight: sink NetTxInFlight[desc])
-> NetRxCanAcquire !{may_block};
Each transition consumes the previous state with sink .
8 / 15
OCaml Meeting 2026 in Tokyo
8
MakeinvalidNICstatesunrepresentable
The type checker prevents:
releasing the same RX frame twice;
transmitting before validation;
reacquiring a descriptor before TX completes;
forgetting to return an active descriptor to DMA.
detect an invalid state later C flags
make the invalid state impossible Takibi types
The capability types add no new descriptor identity at runtime.
9 / 15
OCaml Meeting 2026 in Tokyo
9
Ctechnique:returnapointerintoanRXbuffer
uint8_t *packet = net_rx_frame(frame);
net_rx_release(frame); /* DMA owns it again */
parse(packet); /* use after release */
The pointer still looks valid.
Its type does not remember:
the available length;
the descriptor it came from;
when ownership returned to DMA.
10 / 15
OCaml Meeting 2026 in Tokyo
10
Takibitechnique2:tietheslicetodescriptor
authority
fn net_rx_frame(frame: borrow NetRxValidated[desc])
-> [u8; 1514..] @ desc;
The result carries two proofs:
at least 1514 bytes are available
+
the slice is derived from descriptor desc
let packet = net_rx_frame(frame);
let ready = net_rx_release(frame);
parse(packet); // compile error
11 / 15
OCaml Meeting 2026 in Tokyo
11
AproblemeventheAIcouldnotsolve:STM32
UART
AI: "Serial output is lost while using the SD card."
It kept investigating symptoms.
Human:
Our UART is polling, while the SD card uses DMA. ChibiOS/RT normally uses
DMA and interrupts for both. What happens if we change UART to DMA + IRQ?
AI: Implemented it, tested it on the board -- problem solved.
12 / 15
OCaml Meeting 2026 in Tokyo
12
Anotherblindway:kernelprintfdebugging
AI: Added more and more kernel-side prints to infer userspace behavior.
Human:
If we need to know what BusyBox does, why not read the BusyBox source?
AI: Read the actual userspace implementation -- problem solved.
more observability is not always more understanding
The human changed the source of evidence, not the amount of logging.
13 / 15
OCaml Meeting 2026 in Tokyo
13
TheoneOCaml-sideroughedge:DWARF
Takibi emits DWARF and supports source debugging through GDB.
LLVM's OCaml bindings still lack convenient APIs for:
dbg.value locations for SSA and entry parameter values;
DISubrange construction for natural fixed-array display.
Takibi currently works around those gaps with debug-only allocas,
volatile preservation stores, and GDB artificial arrays.
We would like to contribute these capabilities upstream.
Details: Takibi's open DWARF issues
14 / 15
OCaml Meeting 2026 in Tokyo
14
OCaml+LLVM+GenerativeAI
OCaml+LLVM+GenerativeAI
makesthestackaccessible
makesthestackaccessible
I tried the experiment: github.com/takibi-lang/takibi
Question today's architectural assumptions.
Design your language and your OS with OCaml.
Perhaps design the CPU too, with Hardcaml.
OCamlmakesambitioussystemsexperiments
ordinary.