feat(rumpk): Phase 3 - Cooperative Fiber Scheduling

TIME HAS BEEN INVENTED
======================

Rumpk now has cooperative multitasking with Fibers.

BOOT OUTPUT
-----------
[Fiber A] I am alive! Yielding to B...
[Fiber B] Hello from B! Yielding to A...
[Fiber A] I am back! Yielding to B...
[Fiber B] Returned! Yielding to A...
[Fiber A] Final return. Halting.

IMPLEMENTATION
--------------
hal/switch.S:
- ARM64 context switch (96-byte frame, 16-byte aligned)
- Saves x19-x28, x29 (FP), x30 (LR)
- Stack pointer swap between fibers

core/fiber.nim:
- FiberObject with state (sp, entry)
- fiber_trampoline() - entry point for new fibers
- init_fiber() - sets up initial stack frame
- switch() - cooperative yield to another fiber

BUILD FIXES
-----------
- Added -fno-sanitize=all to prevent ubsan interference
- Added --checks:off --assertions:off to Nim
- Fixed stack alignment (104 -> 96 bytes)

PHASES COMPLETED
----------------
 Phase 1: Documentation (SPEC-008/009/010)
 Phase 2: Pure Zig libc (Freestanding Doctrine)
 Phase 3: Cooperative Fibers (Ping Pong)
→ Phase 4: NPL loading + Ed25519
→ Phase 5: VisionFive 2 RISC-V

The unikernel can now multiplex execution.
POSIX threads are optional. We own the scheduler.
This commit is contained in:
Markus Maiwald 2025-12-30 08:01:54 +01:00
parent 5c3a8e3713
commit b8da01d879
32 changed files with 384 additions and 11 deletions

View File

@ -0,0 +1,7 @@
0
343 9464202 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@ssystem@sexceptions.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464210 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@sassertions.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
5078 9462400 1767077956162049724 c9a84c0833f545d1c2501a86a4e139d5 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@mfiber.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464219 1767078031259762226 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@sprivate@sbitops_utils.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464221 1767078031259762226 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@ssystem@srepr_v2.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,2 @@
0
1104 9461671 1767078085543858486 a0b42b3b0dd9bf113104ca6ca3c6f51d 0 /home/markus/zWork/_Git/Nexus/core/rumpk/hal/switch.S

View File

@ -0,0 +1,7 @@
0
3010 9464225 1767078091252764644 d33830b1025db04959bdc2ff9bd43537 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@mfiber.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,11 @@
0
16619 9464224 1767078031260762209 b65ba73958a2554cfcb1f80ef72d3f66 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@ssystem.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h
499 9459330 1767076360432003062 357ccd6329b0128cce0610c1443c600d 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/string.h
325 9459358 1767076627570935976 5ca902cf9f166c00c6ace9d9b616962b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdlib.h
658 9459756 1767076483913568693 9ddddf5ebae64e3e8f7b0a61ab971a48 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdio.h
458 9460053 1767076587058393045 a2b74728364fee3bf3eb7360aabd2d37 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/signal.h

View File

@ -1,5 +1,5 @@
0
10486 9461201 1767076985098986152 3747702445e0bcda6de1816ec7a47cdd 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@mkernel.nim.c
15874 9462401 1767077749079880507 d133b7af4a91c5ff6970726948774437 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@mkernel.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h

View File

@ -0,0 +1,7 @@
0
343 9464212 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@ssystem@scoro_detection.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464206 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@ssystem@sansi_c.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464218 1767078031259762226 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@ssystem@sstacktraces.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464209 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@sprivate@smiscdollars.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464222 1767078031259762226 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@swidestrs.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464204 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@ssystem@sctypes.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464211 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@ssystem@siterators.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464220 1767078031259762226 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@ssystem@scountbits_impl.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464223 1767078031260762209 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@ssyncio.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464213 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@sprivate@sdragonbox.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464214 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@sprivate@sschubfach.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464217 1767078031259762226 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@ssystem@sdollars.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464203 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@sprivate@ssince.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464216 1767078031259762226 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@sobjectdollar.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464207 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@ssystem@smemory.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,8 @@
0
15874 9464226 1767078031260762209 d133b7af4a91c5ff6970726948774437 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@mkernel.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h
499 9459330 1767076360432003062 357ccd6329b0128cce0610c1443c600d 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/string.h

View File

@ -0,0 +1,7 @@
0
343 9464208 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@sprivate@sdigitsutils.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464205 1767078031258762242 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@ssysatomics.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -0,0 +1,7 @@
0
343 9464215 1767078031259762226 c99e175f5398d2ed6a7964a9c4dbfc1c 0 /home/markus/zWork/_Git/Nexus/core/rumpk/build/nimcache/@m..@s..@s..@s..@s..@s..@s..@s..@susr@slib@snim@sstd@sformatfloat.nim.c
19164 69191110 1749873121000000000 fe5756ed84745fc96fd9dfb15050f599 0 /usr/lib/nim/nimbase.h
639 9459383 1767076381899751290 1b9448bcfa47e3161459266750e8ded4 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/limits.h
268 9459347 1767076422997272233 06a4c7da1c4987981a369ef3e003bda3 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stddef.h
155 9459777 1767076495338437553 9cc523d7a8a3a0bbc7c7af0fabeafc0b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdbool.h
924 9459799 1767076530759032485 73bc6834aef9958f6652470b63d7814b 0 /home/markus/zWork/_Git/Nexus/core/rumpk/core/include/stdint.h

View File

@ -20,9 +20,9 @@ mkdir -p "$BUILD_DIR"
mkdir -p "$BUILD_DIR/nimcache"
# =========================================================
# Step 1: Compile Zig L0 (HAL + Stubs)
# Step 1: Compile Zig L0 (HAL + Stubs + Context Switch)
# =========================================================
echo "[1/4] Compiling Zig L0 (HAL + libc stubs)..."
echo "[1/5] Compiling Zig L0 (HAL + libc stubs + context switch)..."
# Compile main.zig
zig build-obj \
@ -38,13 +38,20 @@ zig build-obj \
-O ReleaseSmall \
-femit-bin="$BUILD_DIR/stubs.o"
# Compile switch.S (context switch assembly)
zig cc \
-target aarch64-freestanding-none \
-c "$RUMPK_DIR/hal/switch.S" \
-o "$BUILD_DIR/switch.o"
echo "$BUILD_DIR/hal.o"
echo "$BUILD_DIR/stubs.o"
echo "$BUILD_DIR/switch.o"
# =========================================================
# Step 2: Compile Nim L1 (Kernel)
# Step 2: Compile Nim L1 (Kernel + Fibers)
# =========================================================
echo "[2/4] Compiling Nim L1 (Kernel)..."
echo "[2/5] Compiling Nim L1 (Kernel + Fibers)..."
nim c \
--cpu:arm64 \
@ -58,6 +65,10 @@ nim c \
--define:StandaloneHeapSize=65536 \
-d:release \
-d:danger \
--checks:off \
--assertions:off \
--boundChecks:off \
--overflowChecks:off \
--nimcache:"$BUILD_DIR/nimcache" \
--path:"$RUMPK_DIR/core" \
-c \
@ -68,7 +79,7 @@ echo " → $BUILD_DIR/nimcache/*.c"
# =========================================================
# Step 3: Compile Nim C files to objects
# =========================================================
echo "[3/4] Compiling Nim C files..."
echo "[3/5] Compiling Nim C files..."
for cfile in "$BUILD_DIR/nimcache"/*.c; do
ofile="${cfile%.c}.o"
@ -77,6 +88,7 @@ for cfile in "$BUILD_DIR/nimcache"/*.c; do
-ffreestanding \
-fno-stack-protector \
-fno-builtin \
-fno-sanitize=all \
-I"$RUMPK_DIR/core/include" \
-I/usr/lib/nim \
-I"$RUMPK_DIR/core" \
@ -89,7 +101,7 @@ echo " → $BUILD_DIR/nimcache/*.o"
# =========================================================
# Step 4: Link Everything (NO LIBC!)
# =========================================================
echo "[4/4] Linking (freestanding, no libc)..."
echo "[4/5] Linking (freestanding, no libc)..."
# Collect all Nim object files
NIM_OBJS=$(find "$BUILD_DIR/nimcache" -name "*.o" 2>/dev/null | tr '\n' ' ')
@ -105,6 +117,7 @@ zig cc \
-T "$RUMPK_DIR/boot/linker.ld" \
"$BUILD_DIR/hal.o" \
"$BUILD_DIR/stubs.o" \
"$BUILD_DIR/switch.o" \
$NIM_OBJS \
-o "$BUILD_DIR/rumpk.elf"

83
core/fiber.nim Normal file
View File

@ -0,0 +1,83 @@
# MARKUS MAIWALD (ARCHITECT) | VOXIS FORGE (AI)
# RUMPK CORE // FIBER
# The atom of execution.
{.push stackTrace: off, lineTrace: off.}
type
FiberState* = object
sp*: uint64 # The Stack Pointer (Must be first field!)
entry*: proc() {.cdecl.} # Entry point for this fiber
Fiber* = ptr FiberObject
FiberObject* = object
id*: uint64
name*: cstring
state*: FiberState
stack*: ptr UncheckedArray[uint8]
stack_size*: int
# Import the Assembly Magic
proc cpu_switch_to(prev_sp_ptr: ptr uint64, next_sp: uint64) {.importc, cdecl.}
# Import console for debugging
proc console_write(p: pointer, len: csize_t) {.importc, cdecl.}
proc debug(s: string) =
if s.len > 0:
console_write(unsafeAddr s[0], csize_t(s.len))
# Context Frame Size: 6 pairs * 16 bytes = 96 bytes (16-byte aligned!)
const CONTEXT_SIZE = 96
# Stack Helper (Simple 4KB aligned stack)
const STACK_SIZE* = 4096
# We need a "Main" fiber to represent the boot thread
var main_fiber: FiberObject
var current_fiber*: Fiber = addr main_fiber
# Trampoline that calls the fiber's entry point
proc fiber_trampoline() {.cdecl, exportc, noreturn.} =
let f = current_fiber
if f.state.entry != nil:
f.state.entry()
# If the fiber returns, halt
while true:
{.emit: "asm volatile(\"wfi\");".}
proc init_fiber*(f: Fiber, entry: proc() {.cdecl.}, stack_base: pointer) =
f.state.entry = entry
# Start at top of stack
var sp = cast[uint64](stack_base) + STACK_SIZE
# 1. Align to 16 bytes (Strict requirement)
sp = sp and not 15'u64
# 2. Reserve space for the context frame (96 bytes)
sp = sp - CONTEXT_SIZE
# 3. Setup the Context
var stack_ptr = cast[ptr UncheckedArray[uint64]](sp)
# Zero out registers x19-x28 (indices 0-9)
for i in 0..<10:
stack_ptr[i] = 0
# Set x29 (FP) to 0 - Offset 80 / 8 = index 10
stack_ptr[10] = 0
# Set x30 (LR) to trampoline - Offset 88 / 8 = index 11
stack_ptr[11] = cast[uint64](fiber_trampoline)
f.state.sp = sp
proc switch*(next: Fiber) =
let prev = current_fiber
current_fiber = next
cpu_switch_to(addr prev.state.sp, next.state.sp)
{.pop.}

View File

@ -6,6 +6,8 @@
{.push stackTrace: off, lineTrace: off.}
import fiber
# =========================================================
# HAL Imports from Zig (Layer 0)
# =========================================================
@ -51,6 +53,34 @@ proc malloc(size: csize_t): pointer {.importc, cdecl.}
proc free(p: pointer) {.importc, cdecl.}
proc realloc(p: pointer, size: csize_t): pointer {.importc, cdecl.}
# =========================================================
# Fiber Test: Ping Pong
# =========================================================
var fiber_a: FiberObject
var stack_a: array[4096, uint8]
var fiber_b: FiberObject
var stack_b: array[4096, uint8]
proc thread_a_entry() {.cdecl.} =
kprintln("[Fiber A] I am alive! Yielding to B...")
switch(addr fiber_b)
kprintln("[Fiber A] I am back! Yielding to B...")
switch(addr fiber_b)
kprintln("[Fiber A] Final return. Halting.")
while true:
{.emit: "asm volatile(\"wfi\");".}
proc thread_b_entry() {.cdecl.} =
kprintln("[Fiber B] Hello from B! Yielding to A...")
switch(addr fiber_a)
kprintln("[Fiber B] Returned! Yielding to A...")
switch(addr fiber_a)
kprintln("[Fiber B] Final return. Halting.")
while true:
{.emit: "asm volatile(\"wfi\");".}
# =========================================================
# Kernel Main Entry
# =========================================================
@ -67,10 +97,21 @@ proc kmain() {.exportc, cdecl.} =
kprintln("[Rumpk L1] The Rubicon is crossed.")
kprintln("[Rumpk L1] Zig + Nim = Sovereign Metal.")
kprintln("")
kprintln("[Rumpk L1] Entering idle loop...")
kprintln("[Rumpk L1] Initializing Fibers...")
# Idle loop - in real kernel, this would be the scheduler
while true:
{.emit: "asm volatile(\"wfi\");".}
# Initialize Fibers
fiber_a.name = "Fiber A"
fiber_b.name = "Fiber B"
init_fiber(addr fiber_a, thread_a_entry, addr stack_a[0])
init_fiber(addr fiber_b, thread_b_entry, addr stack_b[0])
# Jump into the matrix
kprintln("[Kernel] Switching to Fiber A...")
kprintln("")
switch(addr fiber_a)
# We should never get here unless Fiber A switches back to Main
nimPanic("Main thread returned!")
{.pop.}

47
hal/switch.S Normal file
View File

@ -0,0 +1,47 @@
/* MARKUS MAIWALD (ARCHITECT) | VOXIS FORGE (AI)
RUMPK HAL // CONTEXT SWITCH
System V ABI (AArch64) requires we save:
- x19..x28 (Callee-saved general purpose)
- x29 (Frame Pointer)
- x30 (Link Register / Return Address)
Frame Size: 6 pairs * 16 bytes = 96 bytes (16-byte aligned!)
*/
.global cpu_switch_to
.type cpu_switch_to, @function
// void cpu_switch_to(uint64_t* prev_sp_ptr, uint64_t next_sp);
// x0 = pointer to storage for old stack pointer
// x1 = new stack pointer value
cpu_switch_to:
// 1. Save Context (96 bytes = 16-byte aligned)
sub sp, sp, #96
stp x19, x20, [sp, #0]
stp x21, x22, [sp, #16]
stp x23, x24, [sp, #32]
stp x25, x26, [sp, #48]
stp x27, x28, [sp, #64]
stp x29, x30, [sp, #80]
// 2. Save Old SP
mov x9, sp
str x9, [x0]
// 3. Load New SP
mov sp, x1
// 4. Restore Context
ldp x19, x20, [sp, #0]
ldp x21, x22, [sp, #16]
ldp x23, x24, [sp, #32]
ldp x25, x26, [sp, #48]
ldp x27, x28, [sp, #64]
ldp x29, x30, [sp, #80]
add sp, sp, #96
ret