Self-hosting assembler for UBerryNix β reads .basm source and produces native Berry binaries that exactly match the kernel binary grammar (kernel/include/{bdl,befb,bex,rtcf,bsp,bpp}_format.h).
All formats follow the kernel binary grammar with consistent section tables (16 bytes/entry) and export entries (12 bytes/entry).
| Format | Magic | Header Size | Purpose |
|---|---|---|---|
.befb |
BEFB164\0 |
36 B | Berry Executable β Ring-0 isolated applications (LBRT) |
.bex |
BEXI64\0\0 |
16 B | Berry Executable β Nano Kernel / Recovery |
.bdl |
BDLI64\0\0 |
36 B | Berry Dynamic Library |
.lbrct / .hbrct |
RTCFI64\0 |
12 B | Runtime Component (bundle) |
.bsp |
BSP164\0\0 |
24 B | Berry System Package (Scheduler) |
.bpp |
BPP164\0\0 |
24 B | Berry Panel Program β GUI App (DE/WM/DS) |
.bo |
BOBJ\0\0\0\0 |
16 B | Berry Object (intermediate format) |
All formats share:
- Section table: 16 B/entry
{ type u32, offset u32, size u32, vaddr u32 } .exportstable: 12 B/entry{ fn_hash u32, entry_off u32, flags u16, rsv u16 }entry_off= RVA from.textbase (NOT patched by CherryReva)- Terminator:
{0, 0, 0, 0}
- CherryReva entries: 8 B/entry
{ offset u32, type u8, width u8, rsv u16 }offset= patch position relative to.textbase
# Requires libc for file I/O
gcc -O2 -o build/beasm distro/base/runtime/beasm/beasm.c# Once beasm is running inside the OS
beasm beasm.c -o beasm.befb# Build BEX (nano kernel executable)
beasm examples/hello.basm -o hello.bex --format bex --entry _start
# Build BEFB (LBRT application)
beasm examples/hello.basm -o hello.befb --format befb --entry _start --token BEFB_00001
# Build BDL (dynamic library)
beasm examples/mathlib.basm -o mathlib.bdl --format bdl --token BDL_00000
# Build BPP (GUI application)
beasm examples/hello_bpp.basm -o hello_bpp.bpp --format bpp --win-w 320 --win-h 200# Compute FNV-1a hash (synchronized with kernel bdl_fnv1a)
beasm --hash bsnd_dsp_polish # 0x4c3e463c (NOT 0xdac00005!)
beasm --hash bdl_hello # 0x6b7a5c86| Option | Description |
|---|---|
-o <file> |
Output file name |
--format <type> |
`befb |
--token <BTP> |
Berry Token Protocol ID |
--entry <sym> |
Entry point symbol |
--version <1|2> |
Format version |
--win-w <px> |
Window width (BPP only) |
--win-h <px> |
Window height (BPP only) |
--hash <name> |
Compute FNV-1a hash of name |
# Validate binary against kernel grammar
node tools/beasm_check.js hello.bex
node tools/beasm_check.js mathlib.bdlChecks performed:
- 8-byte magic
- Header size
- BTP token format
- Section table (16 B/entry)
.exportstable (12 B/entry) with terminator- CherryReva entries (8 B/entry)
mov(reg/imm/mem, movabs, cr/dr)lea,push/pop,call/jmp/jcc(rel32)ret,int/int3/syscall/sysret/sysenter/sysexithlt/nop/ud2/cli/sti/cld/stdadd/adc/sbb/or/and/sub/xor/cmp/testinc/dec/neg/not,imulshl/shr/sar/rol/ror,shld/shrdmovzx/movsx,xchg,setcccdq/cqo/cwde/cdqe,leave,pushfq/popfq
| Category | Instructions |
|---|---|
| I/O Port | in/out (al/ax/eax β dx/imm8) |
| MSR & TSC | rdmsr/wrmsr, rdpmc, rdtsc/rdtscp, cpuid |
| System Control | xgetbv/xsetbv, clac/stac, swapgs, wbinvd/invd, invlpg |
| Interrupt | iretq, int/int3, syscall/sysret |
| String Ops | movsb/w/d/q, stosb/w/d/q, lodsb/w/d/q, cmpsb/w/d/q, scasb/w/d/q, insb/w/d, outsb/w/d (with rep/repe/repne) |
| Descriptor Tables | lgdt/lidt/sgdt/sidt, lldt/ltr/sldt/str |
| Cache Control | clflush/clflushopt, prefetcht0/t1/t2/nta |
| Atomic (lock) | cmpxchg, cmpxchg8b/cmpxchg16b, xadd |
| Bit Manipulation | bt/bts/btr/btc, bsf/bsr, bswap |
| Control/Debug Regs | mov cr0..cr15, r64 / mov r64, cr0..cr15, mov dr0..dr15, r64 / mov r64, dr0..dr15 |
| Loop | loop/loope/loopne, jrcxz/jecxz (rel8) |
- Registers: 8/16/32/64-bit (including UBerry aliases
r0..r22) - Control/debug registers:
cr0..cr15,dr0..dr15 - Immediate values
- Memory addressing:
[reg],[reg+disp],[reg+idx*scale+disp],[rip+disp]/[rel sym],[disp32] - Directives:
section,db/dw/dd/dq,equ/=,align,resb/resw/resd/resq - Labels:
name:and implicitname db ... lockprefix- Automatic relocation: references to labels generate CherryReva entries (ABS 4/8 B)
- RIP-relative references do NOT generate relocations
Complete ring-0 example: examples/sys_ring0.basm
beasm/
βββ beasm.c # Main assembler (two-pass x86_64, kernel grammar)
βββ examples/
β βββ hello.basm # .bex + .befb (syscall SOW/WITHER)
β βββ mathlib.basm # .bdl (exports + CherryReva relocation)
β βββ demo_api.basm # 3 API pillars (nano_call / lbrt_invoke / gui_send)
β βββ hello_bpp.basm # .bpp GUI app (hook table + service table)
β βββ sys_ring0.basm # Full ring-0 instruction verification
βββ packages/berry/ # FASM/G macros (for host fasmg users)
βββ berry_core.inc # Core macros (FNV-1a, BERRY_EXPORT 12 B, section)
βββ format/ # bdl/befb/bex/lbrct/bsp/bpp/bo β kernel grammar
βββ api/ # nano_abi / lbrt_api / gui_api / berryio (modular)
βββ arch/ # x86_16, i386, x86_64, arm32, arm64, rv32, rv64
packages/berry/api/berryio.inc wraps the ENTIRE BerryCall contract (kernel/include/berrycall.h) into a single berryio_* namespace β self-contained (includes lbrt_api.inc internally).
| Category | Functions |
|---|---|
| I/O | berryio_io_write/read/open/close/stat/ctl/exec |
| Filesystem | berryio_fs_read/perm/sync |
| Process | berryio_proc_getpid/list |
| Time | berryio_time_tick/sleep |
| Memory | berryio_mem_alloc/free |
| Components | berryio_comp_reg/call/sym, berryio_bpp_load/mint |
| Display | berryio_dsp_query/modes/set/text/canvas/canvas_free/flip/session |
| Window | berryio_win_create/destroy/move/resize/focus/frame/input/list/workspace |
| Activity | berryio_act_reg/unreg/query/bump/drop/list |
| Storage | berryio_stor_persist/bdl_load/lbrct_load |
| Panic | berryio_panic_trigger/version |
All constants and numbers are 100% synchronized with berrycall.h (verified by tools/audit_sync.js).
- FASM/G (
packages/berry/):berryio_*macros +bc_*/gui_*(legacy) - C/C3:
libnullberry(ubosix.h/c) +develop/c3/berryio+develop/c3/ubosix
Standalone C assembler that runs inside UBerryNix. Source .basm is plain without include 'berry_core.inc' β syscall constants defined via equ in source. Examples in examples/ use this path.
For fasmg (Flat Assembler G) users on host:
include 'berry_core.inc'
BERRY_EXPORT my_func, BERRY_SHARED
nano_call SYS_MEM_ALLOC
lbrt_invoke 'bsnd_dsp_polish'
gui_send GUI_DRAW_TEXTMacros compute FNV-1a hashes at compile time. The grammar is IDENTICAL to beasm.c (synchronized with kernel).
FNV-1a Hash:
0x811c9dc5/0x01000193β identical across kernel (bdl_fnv1a),berryhashlay.c,bdl_packer.js,beasm.c, and FASM/G macros. The0xdac0xxxxvalues in older docs were placeholders β actual hash ofbsnd_dsp_polish=0x4c3e463c.
A native C scanner that auto-generates export tables from C source code.
cc -o build/berryhashlay tools/berryhashlay.c# Scan directory and generate export table
build/berryhashlay -o build/libberrysound_exports.gen.h \
--scan-dir distro/base/component/lowlevel/libberrysound/srcAutomatically integrated into the Makefile as a pre-build step for components.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Source (.basm) β
β - section / db..dq / equ / label β
β - BERRY_EXPORT sym, BERRY_SHARED β
β - mov/call/jcc/syscall (x86_64) β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β beasm.c (Assembler) β
β - FNV-1a hash compile-time β
β - Two-pass: size β vaddr β emit β
β - CherryReva relocation (ABS 4/8 B) β
β - Format header + section table (kernel grammar) β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Binary Output (.befb/.bex/.bdl/.lbrct/.bsp/.bpp/.bo) β
β magic 8-byte + header + sect 16 B + exports + CherryReva β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Add instruction support: Extend the parser in
beasm.c - Add format: Add a new format handler in
packages/berry/format/ - Sync with kernel: Run
tools/audit_sync.jsto verify grammar alignment - Test: Use
tools/beasm_check.jsto validate output
Part of UBerryNix Core Systems β see root LICENSE.
Made with π by Berry Chan β "Null Berry Chan"
Everything is a token. Nothing is copied twice.