Skip to content

Architecture Overview

MerlionOS is a hybrid kernel with 330 modules across 121,000+ lines of Rust, supporting four CPU architectures. It runs primarily as a monolithic kernel in ring 0, with an optional microkernel mode (v45) for service isolation and hot-restart.

┌───────────────────────────────────────────────┐
│ User Space (Ring 3) │
│ ELF binaries, libc, /bin programs │
│ Dynamic linker, WASI runtime │
├───────────────────────────────────────────────┤
│ Kernel Shell (450+ cmds) │
│ NL interface, AI agents, scripting engine │
├───────────────────────────────────────────────┤
│ Kernel Subsystems │
│ ┌───────────┐ ┌───────────┐ ┌─────────────┐ │
│ │ Scheduler │ │ VFS │ │ Security │ │
│ │ preempt + │ │ ext4/tmp/ │ │ caps/seccomp│ │
│ │ RT (EDF) │ │ proc/sys │ │ ACLs/audit │ │
│ └───────────┘ └───────────┘ └─────────────┘ │
│ ┌───────────┐ ┌───────────┐ ┌─────────────┐ │
│ │ Memory │ │ Drivers │ │ Network │ │
│ │ slab/page │ │PCI/ACPI/ │ │IPv4/v6/TCP/ │ │
│ │ demand pg │ │virtio/GPU │ │UDP/HTTPS/TLS│ │
│ └───────────┘ └───────────┘ └─────────────┘ │
│ ┌───────────┐ ┌───────────┐ ┌─────────────┐ │
│ │ AI │ │ Audio │ │ GUI │ │
│ │ inference │ │ mixer/WAV │ │ widgets/ │ │
│ │ ML/vector │ │ synth/MIDI│ │ themes │ │
│ └───────────┘ └───────────┘ └─────────────┘ │
├───────────────────────────────────────────────┤
│ Hardware Abstraction │
│ x86_64: GDT, IDT, APIC, PIT, VGA, FB │
│ aarch64: GIC, Generic Timer, PL011 UART │
│ riscv64: PLIC, CLINT Timer, SBI console │
│ loongarch64: EIOINTC, Stable Timer, UART │
│ SMP: up to 16 CPUs, per-CPU state │
│ Power: P/C-states, thermal, battery │
└───────────────────────────────────────────────┘

MerlionOS runs on four CPU architectures with a shared kernel core and per-architecture HAL (Hardware Abstraction Layer):

ArchitectureTarget TripleBoot MethodInterrupt ControllerTimerUART
x86_64x86_64-unknown-noneBIOS (bootloader 0.9) / UEFI (Limine)PIC / APICPIT / HPET16550 COM1
aarch64aarch64-unknown-noneRaspberry Pi firmwareGIC (Generic Interrupt Controller)ARM Generic TimerPL011
riscv64riscv64gc-unknown-none-elfOpenSBIPLICCLINTSBI console
loongarch64loongarch64-unknown-noneUEFIEIOINTCStable Counter16550-compatible

The architecture-independent kernel subsystems (scheduler, VFS, networking, AI, etc.) are shared across all targets. Each architecture provides its own arch_* module implementing the HAL traits for interrupts, memory management, timer, and console I/O.

User programs communicate with the kernel via int 0x80. The kernel provides 15 syscalls:

#NameArgsDescription
0writerdi=buf, rsi=lenWrite to file descriptor
1exitrdi=codeTerminate process
2yieldYield to scheduler
3getpidGet current PID
4sleeprdi=ticksSleep for N ticks
5sendrdi=chan, rsi=byteSend to IPC channel
6recvrdi=chanReceive from IPC channel
7openrdi=path, rsi=flagsOpen a file descriptor
8readrdi=fd, rsi=buf, rdx=lenRead from file descriptor
9closerdi=fdClose a file descriptor
10forkFork current process (COW)
11execrdi=pathExecute ELF binary
12mmaprdi=addr, rsi=lenMap memory pages
13ioctlrdi=fd, rsi=cmdDevice control
14socketrdi=domain, rsi=typeCreate network socket

The VFS layer supports six filesystem backends:

/
├── bin/ # user-space programs (ELF)
├── dev/
│ ├── null # discard sink
│ ├── serial # COM1 serial port
│ ├── fb0 # framebuffer device
│ └── audio # audio mixer
├── proc/ # procfs — 28 entries
│ ├── uptime # system uptime
│ ├── meminfo # heap statistics
│ ├── tasks # running task list
│ ├── cpuinfo # CPU topology & features
│ ├── net/ # network statistics
│ └── ... # mounts, modules, interrupts, etc.
├── sys/ # sysfs — device model
│ ├── devices/ # device hierarchy
│ ├── bus/ # bus types (PCI, virtio)
│ └── power/ # power management
├── mnt/ # ext4 / MF16 block devices
└── tmp/ # tmpfs — writable in-memory files

Supported filesystems: MF16 (FAT16-like), ext4 (extents, journaling, htree), tmpfs, procfs, sysfs, devfs.

MerlionOS implements defense in depth:

  • Capabilities — fine-grained privilege control per process
  • Seccomp — syscall filtering policies
  • POSIX ACLs — per-user/group access control on filesystem objects
  • Audit log — structured security event logging with remote syslog
  • Container isolation — namespaces, veth networking, resource limits

The kernel includes a built-in AI platform:

  • Neural network inference — INT32 arithmetic, no floating point required
  • ML training — linear regression, decision trees, KNN
  • Vector store — semantic search with cosine similarity
  • Workflow engine — task orchestration and scheduling
  • Self-evolution — code analysis, patch generation, self-healing

Optional microkernel mode (v45) provides:

  • Service isolation in separate address spaces
  • Message-passing IPC between services
  • Hot-restart of failed services without full reboot
  • Fault containment boundaries

Full network stack with:

  • IPv4 + IPv6 dual stack with ARP, ICMP, NDP
  • TCP with congestion control (Reno, Cubic, BBR)
  • UDP, DNS client/server with zone management
  • Application protocols — HTTP/HTTPS, SSH, SCP, MQTT (QoS), WebSocket
  • TLS — certificate validation, reverse proxy
  • Container networking — veth pairs, bridge, network namespaces