Kernel Build and Deployment Summary¶
Build Status: ✓ SUCCESS¶
Date: 2025-11-16 Build System: NDIX-C compatible bootstrap pattern
Build Verification¶
Makefile Build Process¶
cd examples/05-c-kernel
make clean
make all
Build Steps Executed:
- Step 1a: Preprocess
locore.c→locore.s(C preprocessor with -E -DLOCORE) - Step 1b: Compile
kernel.c→kernel.s(with debug info -g) - Step 2a: Assemble
locore.s→locore.o - Step 2b: Assemble
kernel.s→kernel.o(with map -am) - Step 3: Link
locore.o + kernel.o→kernel(entry point: start, IMAGIC format) - Step 4: Split
kernel→kernel.pseg + kernel.dseg - Step 5: Package →
kernel.zip
Build Output¶
Text size: 762 bytes (0x2fa)
Data size: 72 bytes (0x48)
BSS size: 78608 bytes (0x13310)
Symbol table: 408 bytes (0x198)
Entry point: 0x4
Files created:
locore.s - Bootstrap assembly (from locore.c)
locore.o - Bootstrap object (linked FIRST)
kernel.s - Kernel assembly code
kernel.o - Kernel object file (IMAGIC format)
kernel - Linked kernel (IMAGIC format with symbols)
kernel.map - Map file with source line mappings
kernel.pseg - Program segment (text/instructions)
kernel.dseg - Data segment (data + bss)
kernel.zip - Distribution package
Package Contents¶
File: kernel.zip (8.2 KB)
Archive Contents:
8,553 bytes - kernel.c (C source)
10,825 bytes - kernel.s (generated assembly)
1,624 bytes - kernel (linked executable)
16,228 bytes - kernel.map (symbol map)
---------
37,230 bytes - Total (4 files)
Deployment Locations¶
The kernel.zip file has been copied to all required locations:
✓ examples/05-c-kernel/kernel.zip
✓ src/frontend/nd500wasm/web/demo/kernel.zip
✓ build_wasm/bin/kernel.zip
Checksum: 2c5fa9bcd8db8a80892e57e65ad95405 (all locations verified)
Deployment Verification¶
md5sum examples/05-c-kernel/kernel.zip \
src/frontend/nd500wasm/web/demo/kernel.zip \
build_wasm/bin/kernel.zip
# Output:
2c5fa9bcd8db8a80892e57e65ad95405 examples/05-c-kernel/kernel.zip
2c5fa9bcd8db8a80892e57e65ad95405 src/frontend/nd500wasm/web/demo/kernel.zip
2c5fa9bcd8db8a80892e57e65ad95405 build_wasm/bin/kernel.zip
✓ All checksums match - deployment verified
Functional Verification¶
Debugger Test¶
cd .
./build/bin/nd500x --debug
> load examples/05-c-kernel/kernel
> set PC 4
> step 5
> regs
Results:
[INIT] Stack initialized at B=0xE8001000, TOS=0xE8005000, SP=0xE8001000
[STUB] Dctsb instruction not implemented (mnemonic: dctsb, opcode: 0xFF1D)
[STUB] Pctsb instruction not implemented (mnemonic: pctsb, opcode: 0xFF1C)
Registers after INIT:
B = 0xE8001000 (stack base)
TOS = 0xE8005000 (stack top)
L = 0x00000011 (link register - return address)
✓ INIT instruction executed successfully ✓ Stack registers properly initialized ✓ No ENTS trap (problem solved!)
Disassembly Verification¶
Entry Point: 0x4
00000004: init $3892318208,$20,$16384
0000000D: dctsb
0000000F: pctsb
00000011: call $436207616,$0
00000017: go $0
✓ INIT is first instruction at entry point ✓ Cache operations follow INIT ✓ CALL to kernel_main comes after stack initialization
Bootstrap Implementation¶
locore.c Pattern (NDIX-C Compatible)¶
.text
.org 4
.globl start
start:
init _Kstack, $20, $UPAGES*NBPG # Stack initialization
dctsb # Clear data cache
pctsb # Clear program cache
call _kernel_main, $0 # Call C kernel
halt_loop:
go halt_loop # Halt if returns
Key Features:
- Uses assembly label (not C function) to avoid ENTS prologue
- INIT is first instruction (prevents trap)
- C preprocessor expands constants
- Linked first in object order
Build Process Details¶
Preprocessing locore.c:
$(CC) -E -DLOCORE $(CFLAGS) locore.c | \
sed -e 's/\(_[0-9]\)[ ]*:/\1:/' > locore.s
Linking:
$(LD) -i -e start -x -m -o kernel locore.o kernel.o
Flags:
-i- IMAGIC format (0411)-e start- Entry point atstartlabel-x- Preserve symbols for debugging-m- Generate map file with relocated addresses
Makefile Targets¶
Primary Targets¶
make all # Complete build pipeline (default)
make clean # Remove all generated files
make compile # Compile C to assembly only
make assemble # Assemble to object files only
make link # Link to kernel executable
make split # Split into PSEG/DSEG segments
make package # Create kernel.zip
Inspection Targets¶
make inspect # Inspect all generated files
make test # Verify complete build process
make demo # Show detailed information with disassembly
make asm # View generated assembly code
Help Target¶
make help # Show all available targets and documentation
File Structure¶
Source Files¶
examples/05-c-kernel/
├── locore.c # Bootstrap assembly-in-C (NEW)
├── kernel.c # Main kernel C code (MODIFIED)
├── Makefile # Build system (UPDATED)
├── BOOTSTRAP_IMPLEMENTATION.md
├── NDIX_VMUNIX_BOOTSTRAP_ANALYSIS.md
├── BUILD_DEPLOYMENT_SUMMARY.md (this file)
└── [legacy files...]
Generated Files (Build Artifacts)¶
examples/05-c-kernel/
├── locore.s # Preprocessed bootstrap assembly
├── locore.o # Bootstrap object file
├── kernel.s # Generated kernel assembly
├── kernel.o # Kernel object file
├── kernel.map # Symbol map (assembly line numbers)
├── kernel # Linked executable (IMAGIC format)
├── kernel.pseg # Program segment (instructions)
├── kernel.dseg # Data segment (data + BSS)
└── kernel.zip # Distribution package
Changes from Previous Version¶
Before (Failed Bootstrap)¶
kernel.c:
void start() {
asm("init _stack_area,$4096,$65536"); // WRONG: After ENTS!
init_kernel();
scheduler();
}
Problem: Compiler adds ENTS prologue before inline assembly
Result: Instruction sequence error trap
After (Working Bootstrap)¶
locore.c:
start:
init _Kstack, $20, $UPAGES*NBPG # RIGHT: First instruction!
call _kernel_main, $0
kernel.c:
void kernel_main() { // Renamed from start()
init_kernel(); // Stack already initialized
scheduler();
}
Result: Stack properly initialized, no trap
Architecture Compliance¶
✓ ND-500 Specification Compliant:
- INIT instruction before any ENTS
- Stack registers (B, TOS, SP) initialized
- Entry point at text address 4
- No instruction sequence error trap
✓ NDIX-C Pattern Compliant:
- Assembly-in-C bootstrap (locore.c)
- C preprocessor for constant expansion
- locore.o linked first
- Entry point at
startlabel
Integration with ND500X Emulator¶
Native Debugger¶
./build/bin/nd500x --debug
> load examples/05-c-kernel/kernel
> set PC 4
> step
> regs
WASM Emulator¶
File location: src/frontend/nd500wasm/web/demo/kernel.zip
The WASM frontend automatically extracts and loads this kernel for web-based debugging.
Build System Integration¶
Updated: No changes needed to ND500X CMake build system
The kernel is a standalone package built with external pcc-nd500 toolchain.
Testing Instructions¶
Quick Test¶
cd examples/05-c-kernel
make clean
make all
make test
Expected output:
✓ Step 1: Compilation - SUCCESS
✓ Step 2: Assembly - SUCCESS
✓ Step 3: Linking - SUCCESS
✓ Step 4: Splitting - SUCCESS
All tests passed! ✓
Full Verification¶
make clean
make all
make inspect
Verify:
- ✓ All files created
- ✓ IMAGIC format (0411)
- ✓ Entry point at 0x4
- ✓ Symbol table resolved
- ✓ kernel.zip created
Deployment Verification¶
md5sum examples/05-c-kernel/kernel.zip \
src/frontend/nd500wasm/web/demo/kernel.zip \
build_wasm/bin/kernel.zip
All checksums must match.
Runtime Verification¶
./build/bin/nd500x --debug <<EOF
load examples/05-c-kernel/kernel
set PC 4
step 3
regs
q
EOF
Look for:
[INIT] Stack initialized at B=0xE8001000, TOS=0xE8005000
Future Maintenance¶
Rebuilding Kernel¶
cd examples/05-c-kernel
make clean
make all
Redeploying After Rebuild¶
The Makefile automatically creates kernel.zip. To deploy:
cp kernel.zip ../../../src/frontend/nd500wasm/web/demo/
cp kernel.zip ../../../build_wasm/bin/
md5sum kernel.zip \
../../../src/frontend/nd500wasm/web/demo/kernel.zip \
../../../build_wasm/bin/kernel.zip
Or use the provided deployment script (if created).
Modifying Kernel¶
To add features to kernel:
- Edit
kernel.c(add functions, data structures) - Do NOT modify
locore.c(bootstrap is stable) - Rebuild:
make clean && make all - Test in debugger before deployment
- Deploy kernel.zip to all locations
To modify bootstrap (advanced):
- Edit
locore.c(requires assembly knowledge) - Ensure INIT remains first instruction
- Test thoroughly in debugger
- Update documentation
Known Issues¶
Emulator Loader Message¶
The ND500X loader currently shows:
File Type: OBJECT FILE (needs linking)
This is incorrect - the kernel IS an executable (IMAGIC format 0411, all symbols resolved).
Workaround: Use set PC 4 before running.
Fix needed: Update src/ndlib/ndlib_aout.c loader to correctly identify IMAGIC executables.
Cache Operations (Not Critical)¶
[STUB] Dctsb instruction not implemented
[STUB] Pctsb instruction not implemented
These are stub messages from the emulator. Cache operations (dctsb, pctsb) are optional for correct operation.
Impact: None - kernel works correctly without cache emulation.
Success Criteria¶
✓ Build: Makefile completes without errors ✓ Package: kernel.zip created with correct contents ✓ Deployment: All locations have matching checksums ✓ Bootstrap: INIT executes first, stack initialized ✓ Compliance: ND-500 architecture specification met ✓ Pattern: NDIX-C locore.c pattern adopted
Documentation¶
NDIX_VMUNIX_BOOTSTRAP_ANALYSIS.md- Analysis of NDIX kernel bootstrapBOOTSTRAP_IMPLEMENTATION.md- Implementation details and verificationBUILD_DEPLOYMENT_SUMMARY.md- This file (build and deployment guide)KERNEL_STACK_INIT.md- Original issue documentationBOOTSTRAP_EXPLAINED.md- Technical explanation of ENTS-without-INIT problem
Conclusion¶
The ND-500 demo kernel now uses the proven NDIX-C assembly-in-C bootstrap pattern, solving the ENTS-without-INIT trap issue. The build system is fully automated via Makefile, and kernel.zip is successfully deployed to all required locations.
Status: ✓ Production-ready Pattern: NDIX-C compatible Next Step: Future full vmunix kernel integration