-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
2931 lines (2808 loc) · 158 KB
/
Copy pathbuild.zig
File metadata and controls
2931 lines (2808 loc) · 158 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! VirelaiOS root build system (milestone zero).
//!
//! Written against Zig 0.16.0 (pinned in .zigversion). Notable 0.16
//! differences from older tutorials that this file accounts for:
//! * `b.addExecutable` takes `.root_module = b.createModule(...)`.
//! * `build.zig.zon` uses `.name = .virelaios`, `.fingerprint`,
//! `.minimum_zig_version` and a `.paths` allowlist.
//! * `Step.Run` exposes settable `has_side_effects` and `stdio` fields
//! (verified against the installed 0.16.0 std sources).
//! See docs/decisions/0001-arm64-uefi-zig.md and README.md.
const std = @import("std");
pub fn build(b: *std.Build) void {
// ------------------------------------------------------------------
// Guest: AArch64 UEFI application -- the loader (BOOTAA64.EFI).
// ------------------------------------------------------------------
const target = b.resolveTargetQuery(.{
.cpu_arch = .aarch64,
.os_tag = .uefi,
});
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseSmall });
const bad_handoff = b.option(bool, "bad-handoff", "Corrupt handoff v2 magic for the pre-exit failure-path test") orelse false;
const boot_options = b.addOptions();
boot_options.addOption(bool, "bad_handoff", bad_handoff);
const efi = b.addExecutable(.{
.name = "bootaa64",
.root_module = b.createModule(.{
.root_source_file = b.path("boot/src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
efi.root_module.addOptions("build_options", boot_options);
// Canonical removable-media ARM64 UEFI filename (EFI/BOOT/BOOTAA64.EFI).
// Set directly on the compile so the installed artifact is named exactly
// BOOTAA64.EFI. (On case-insensitive APFS a separate install step would
// collide with the default lowercase artifact name.)
efi.out_filename = "BOOTAA64.EFI";
b.installArtifact(efi);
// ------------------------------------------------------------------
// Guest: freestanding AArch64 kernel (linked ELF -> flat KERNEL.BIN).
// ------------------------------------------------------------------
const kernel_target = b.resolveTargetQuery(.{
.cpu_arch = .aarch64,
.os_tag = .freestanding,
});
// The kernel is always built ReleaseSmall regardless of the loader's
// mode: Debug's safety runtime (ubsan_rt etc.) bloats the flat blob and
// emits absolute-address movk chains, which would break the kernel's
// load-anywhere (PC-relative) contract. See ADR 0002.
// Claim 0015: `-Dnvram-console` diverts console TX through the NVRAM
// variable channel (post-exit access to the virtio transport hangs on
// VZ — claim 0013), so the kernel can produce host-observable console
// bytes after the MMU switch. Default off: the virtio TX path is
// unchanged.
const nvram_console = b.option(bool, "nvram-console", "Route kernel console TX through the NVRAM variable channel instead of the MMIO serial transport (claim 0015; for the VZ post-exit evidence gate)") orelse false;
// Claim 0017: `-Dpreexit-tx` transmits a fixed diagnostic line
// ("VIRELAIOS PREEXIT VIRTIO TX") through the virtio-pci console
// transport BEFORE ExitBootServices, while Boot Services and the
// firmware address space are still active — using the same device, BAR,
// rings and notify mechanism as the post-exit path. Default off: the
// post-exit TX path and every existing gate are byte-identical.
const preexit_tx = b.option(bool, "preexit-tx", "Transmit 'VIRELAIOS PREEXIT VIRTIO TX' through the virtio-pci transport before ExitBootServices (claim 0017 diagnostic)") orelse false;
// Claim 0018: `-Dtx-diag` replaces the flush's coarse TXST/TXNT/TXPL
// markers with ten ordered per-stage NVRAM markers around each
// potentially fatal operation of the first post-exit virtio TX, and
// removes the large post-exit probe-tail SetVariable + logging-only
// status dump from the flush. Default off: the default build's flush is
// byte-identical.
const tx_diag = b.option(bool, "tx-diag", "Bisect the post-exit virtio TX failure with per-stage NVRAM markers (claim 0018 diagnostic)") orelse false;
// Claim 0020: TX-transition matrix phases. Each is default off; a
// diagnostic build enables EXACTLY ONE phase, which runs a single
// controlled TX attempt at its named location (A pre-ExitBootServices,
// B immediately post-ExitBootServices on the firmware translation,
// C immediately after the identity-map install, D at the normal final
// location). Same payload + same transport + same flush in every phase.
// Default builds stay byte-identical.
const tx_transition_a = b.option(bool, "tx-transition-a", "Phase A: one virtio TX attempt before ExitBootServices (claim 0020 diagnostic)") orelse false;
const tx_transition_b = b.option(bool, "tx-transition-b", "Phase B: one virtio TX attempt immediately after ExitBootServices, before VirelaiOS page tables (claim 0020 diagnostic)") orelse false;
const tx_transition_c = b.option(bool, "tx-transition-c", "Phase C: one virtio TX attempt immediately after the identity-map install, before unrelated work (claim 0020 diagnostic)") orelse false;
const tx_transition_d = b.option(bool, "tx-transition-d", "Phase D: one virtio TX attempt at the normal final location (claim 0020 diagnostic)") orelse false;
// Claim 0021: firmware MMU-state capture. `-Dfw-mmu-capture` records the
// firmware's live SCTLR/TCR/MAIR/TTBR0/TTBR1 + a bounded walk of the
// firmware TTBR0 tables for the virtio BAR0 window and a RAM control
// address, plus the kernel's planned values, persisted pre-exit as the
// ASCII variable `VirelaiMmu` for a host-side firmware-vs-kernel diff.
// Default off: the default build is byte-identical.
const fw_mmu_capture = b.option(bool, "fw-mmu-capture", "Capture firmware MMU registers + a virtio BAR-window table walk pre-exit, persisted to NVRAM (claim 0021 diagnostic)") orelse false;
// Claim 3475: `-Dprobe-var` persists the claim-0013 probe dump (the raw
// declared-MMIO-window / config-table / ACPI evidence) as the chunked
// `VirelaiP0..N` variables. Default OFF: the serial log carries the
// probe records, and VZ's variable store is append-per-write, so the
// ~32 KiB persist per boot starved the store and left no room for the
// ESP file window's `write` (claim 3475; claim 0015 already gated the
// persist off in nvram-console builds for the same starvation).
const probe_var = b.option(bool, "probe-var", "Persist the claim-0013 probe dump as VirelaiP* NVRAM variables (diagnostic; default off — the serial log carries the probe records, and the persist starves the variable store)") orelse false;
// Claim 1517: production T0SZ is 16 (correct start level for the built
// L0-rooted hierarchy). `-Dt0sz25` selects the legacy 25 (W=39, walk
// starts at level 1 — the claim-6460/7896 start-level mismatch that
// made every fresh post-switch walk fault on VZ) for class-D A/B
// regression. ONLY T0SZ changes: same tables, same TTBR0 root, same
// MAIR/attributes/blanket/BAR window; the TLBI at the switch is
// unconditional production behavior (claim 1517). Default off: default
// builds are the production T0SZ=16 + TLBI kernel.
const t0sz25 = b.option(bool, "t0sz25", "Diagnostic: install_identity_map programs T0SZ=25 (legacy start level, W=39 — the claim-6460/7896 start-level mismatch) instead of production 16 (claim 1517; default off)") orelse false;
// Claim 7896: `-Dwalk-probe` runs a post-switch cold-address probe
// battery, each probe bracketed by an NVRAM marker, to test whether the
// installed tables resolve under the programmed T0SZ and to NAME the
// first address whose walk (or MMIO read) does not return. Runs after
// install_identity_map (which now always ends with the full TLBI,
// claim 1517) before the claim-0020 phase-C experiment. Default off: the
// module is linker-eliminated from default builds (byte-identical).
const walk_probe = b.option(bool, "walk-probe", "Diagnostic: post-switch walk-validity probe battery with per-probe NVRAM markers (claim 7896; default off)") orelse false;
const kernel_options = b.addOptions();
kernel_options.addOption(bool, "nvram_console", nvram_console);
kernel_options.addOption(bool, "probe_var", probe_var);
kernel_options.addOption(bool, "preexit_tx", preexit_tx);
kernel_options.addOption(bool, "tx_diag", tx_diag);
kernel_options.addOption(bool, "tx_transition_a", tx_transition_a);
kernel_options.addOption(bool, "tx_transition_b", tx_transition_b);
kernel_options.addOption(bool, "tx_transition_c", tx_transition_c);
kernel_options.addOption(bool, "tx_transition_d", tx_transition_d);
kernel_options.addOption(bool, "fw_mmu_capture", fw_mmu_capture);
kernel_options.addOption(bool, "t0sz25", t0sz25);
kernel_options.addOption(bool, "walk_probe", walk_probe);
const kernel = b.addExecutable(.{
.name = "virelai-kernel",
.root_module = b.createModule(.{
.root_source_file = b.path("kernel/src/main.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
kernel.root_module.addOptions("build_options", kernel_options);
// Dense layout from address 0 (kernel/linker.ld): without this, lld's
// 64 KiB max-page-size padding would inflate the flat image ~100x.
kernel.linker_script = b.path("kernel/linker.ld");
// Issue #1042: keep lld's relocation records in the linked ELF so
// elf2bin can emit the KRN2 absolute-relocation table the loader applies
// at any base. lld forbids --emit-relocs together with --strip-all, so
// the kernel ELF keeps its (non-PT_LOAD, image-irrelevant) symbols; every
// absolute relocation in loadable content must be representable or
// elf2bin fails the build — a pointer table can never silently ship.
kernel.link_emit_relocs = true;
kernel.root_module.strip = false;
// tools/elf2bin.py converts the linked ELF into the flat kernel image
// format (magic "KRN2", entry offset, size, absolute-reloc table; see
// docs/decisions/0019-kernel-absolute-relocation-table.md). The loader on
// the ESP reads KERNEL.BIN.
const kernel_step = b.step("kernel", "Extract the flat kernel image (zig-out/bin/KERNEL.BIN) from the freestanding ELF (class A tooling, no VM)");
// The kernel maps itself RW (its .data/.bss is live), so it is the one
// flat image exempt from elf2bin's writable-segment guard
// (--allow-writable); every exec'd user program must stay pure-code flat
// or go DSK3 segmented (user/linker-segmented.ld + --segments).
const elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--allow-writable", "--relocs" });
elf2bin.addFileArg(kernel.getEmittedBin());
const kernel_bin = elf2bin.addOutputFileArg("KERNEL.BIN");
elf2bin.has_side_effects = true;
elf2bin.stdio = .inherit;
kernel_step.dependOn(&elf2bin.step);
const install_kernel = b.addInstallFileWithDir(kernel_bin, .bin, "KERNEL.BIN");
b.getInstallStep().dependOn(&install_kernel.step);
// ------------------------------------------------------------------
// Guest: ESP user program (milestone-three card 6, claim 6783) — a
// small freestanding AArch64 flat image (USER.BIN, same DSK1 format as
// KERNEL.BIN) that the kernel's `exec` monitor command loads from the
// ESP and enters at EL0. Built into the same freestanding target and
// embedded on the ESP by the image builder.
// ------------------------------------------------------------------
const user = b.addExecutable(.{
.name = "user-hello",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/main.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
user.linker_script = b.path("user/linker.ld");
const user_step = b.step("user", "Build the ESP user program (zig-out/bin/USER.BIN; class A tooling, no VM)");
const user_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
user_elf2bin.addFileArg(user.getEmittedBin());
const user_bin = user_elf2bin.addOutputFileArg("USER.BIN");
user_elf2bin.has_side_effects = true;
user_elf2bin.stdio = .inherit;
user_step.dependOn(&user_elf2bin.step);
const install_user = b.addInstallFileWithDir(user_bin, .bin, "USER.BIN");
b.getInstallStep().dependOn(&install_user.step);
// ------------------------------------------------------------------
// Guest: second ESP user program (milestone-four follow-on 2, claim
// 4613) — the never-exiting COUNTER.BIN. Same freestanding target,
// linker script, elf2bin conversion, and ESP embedding as USER.BIN;
// the kernel's `exec COUNTER.BIN` monitor command loads it by name.
// It loops forever writing a DISTINCT marker (sys_write + sys_yield
// only, no sys_exit), so the live long-lived gate can tell the two
// programs apart in the serial log while one occupies its pool slot
// permanently.
// ------------------------------------------------------------------
const counter = b.addExecutable(.{
.name = "user-counter",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/counter.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
counter.linker_script = b.path("user/linker.ld");
const counter_step = b.step("counter", "Build the second ESP user program (zig-out/bin/COUNTER.BIN; class A tooling, no VM)");
const counter_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
counter_elf2bin.addFileArg(counter.getEmittedBin());
const counter_bin = counter_elf2bin.addOutputFileArg("COUNTER.BIN");
counter_elf2bin.has_side_effects = true;
counter_elf2bin.stdio = .inherit;
counter_step.dependOn(&counter_elf2bin.step);
const install_counter = b.addInstallFileWithDir(counter_bin, .bin, "COUNTER.BIN");
b.getInstallStep().dependOn(&install_counter.step);
// ------------------------------------------------------------------
// Guest: third ESP user program (milestone-four follow-on 3, card
// 3f — claim 5965) — the IPC peer PEER.BIN. Same freestanding target,
// linker script, elf2bin conversion, and ESP embedding as USER.BIN /
// COUNTER.BIN; the kernel's `exec PEER.BIN` monitor command loads it
// by name. It never exits: it recv-loops through sys_ipc_recv (slot
// 6) and echoes each received message verbatim ("peer: got N"), so
// the live IPC gate can show COUNTER.BIN's sends and PEER.BIN's
// echoes interleaving across the whole serial log — the strongest
// proof of two live processes communicating.
// ------------------------------------------------------------------
const peer = b.addExecutable(.{
.name = "user-peer",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/peer.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
peer.linker_script = b.path("user/linker.ld");
const peer_step = b.step("peer", "Build the third ESP user program (zig-out/bin/PEER.BIN; class A tooling, no VM)");
const peer_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
peer_elf2bin.addFileArg(peer.getEmittedBin());
const peer_bin = peer_elf2bin.addOutputFileArg("PEER.BIN");
peer_elf2bin.has_side_effects = true;
peer_elf2bin.stdio = .inherit;
peer_step.dependOn(&peer_elf2bin.step);
const install_peer = b.addInstallFileWithDir(peer_bin, .bin, "PEER.BIN");
b.getInstallStep().dependOn(&install_peer.step);
// ------------------------------------------------------------------
// Guest: fourth ESP user program (milestone-four follow-on 4, card
// 4c — claim 9946) — the short third program STATUS43.BIN. Same
// freestanding target, linker script, elf2bin conversion, and ESP
// embedding as USER.BIN / COUNTER.BIN / PEER.BIN; the kernel's
// `exec STATUS43.BIN` monitor command loads it by name. It prints its
// alive marker, sleeps `sleep_ticks` scheduler ticks (slot 4) so the
// observer deterministically blocks on it, then exits with status 43
// (slot 3) — the target in the exit-status-propagation live gate.
// ------------------------------------------------------------------
const status43 = b.addExecutable(.{
.name = "user-status43",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/status43.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
status43.linker_script = b.path("user/linker.ld");
const status43_step = b.step("status43", "Build the fourth ESP user program (zig-out/bin/STATUS43.BIN; class A tooling, no VM)");
const status43_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
status43_elf2bin.addFileArg(status43.getEmittedBin());
const status43_bin = status43_elf2bin.addOutputFileArg("STATUS43.BIN");
status43_elf2bin.has_side_effects = true;
status43_elf2bin.stdio = .inherit;
status43_step.dependOn(&status43_elf2bin.step);
const install_status43 = b.addInstallFileWithDir(status43_bin, .bin, "STATUS43.BIN");
b.getInstallStep().dependOn(&install_status43.step);
// ------------------------------------------------------------------
// Guest: the SMP user program (claim 2369) — SMP1.BIN, the FIRST user
// task that runs on a secondary core. Same freestanding target,
// linker script, elf2bin conversion, and ESP embedding as the others;
// the kernel's `exec -c1 SMP1.BIN` monitor command pins its task to
// core 1 (locked console TX makes a pinned program's sys_writes safe
// from there). It prints its hello marker, sleeps 2 ticks (the kernel
// parks core 1 on its WFE loop and resumes it after the wake), prints
// its exiting marker, and exits 0 — the live SMP gate's proof that a
// USER program ran on core 1 end to end.
// ------------------------------------------------------------------
const smp1 = b.addExecutable(.{
.name = "user-smp1",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/smp1.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
smp1.linker_script = b.path("user/linker.ld");
const smp1_step = b.step("smp1", "Build the SMP user program (zig-out/bin/SMP1.BIN; class A tooling, no VM)");
const smp1_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
smp1_elf2bin.addFileArg(smp1.getEmittedBin());
const smp1_bin = smp1_elf2bin.addOutputFileArg("SMP1.BIN");
smp1_elf2bin.has_side_effects = true;
smp1_elf2bin.stdio = .inherit;
smp1_step.dependOn(&smp1_elf2bin.step);
const install_smp1 = b.addInstallFileWithDir(smp1_bin, .bin, "SMP1.BIN");
b.getInstallStep().dependOn(&install_smp1.step);
// ------------------------------------------------------------------
// Guest: the sched-ring stress program (claim 881, #856 slice 4) —
// SCHEDRING.BIN, the per-core ready-ring proof. The live gate runs
// TWO copies: one pinned to core 1 (home ring 1) and one floating
// (home ring 0, stolen onto core 1 by the idle-branch steal view).
// Each runs 4 × sys_sleep(1) then 32 × sys_yield in a tight loop,
// writes exact-count markers (`slept=4` / `yielded=32` / `done`),
// and exits 0 — a lost wakeup, a duplicate staging, or a corrupt
// save/restore breaks the exact-count greps and fails the gate.
// ------------------------------------------------------------------
const schedring = b.addExecutable(.{
.name = "user-schedring",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/schedring.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
schedring.linker_script = b.path("user/linker.ld");
const schedring_step = b.step("schedring", "Build the sched-ring stress user program (zig-out/bin/SCHEDRING.BIN; class A tooling, no VM)");
const schedring_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
schedring_elf2bin.addFileArg(schedring.getEmittedBin());
const schedring_bin = schedring_elf2bin.addOutputFileArg("SCHEDRING.BIN");
schedring_elf2bin.has_side_effects = true;
schedring_elf2bin.stdio = .inherit;
schedring_step.dependOn(&schedring_elf2bin.step);
const install_schedring = b.addInstallFileWithDir(schedring_bin, .bin, "SCHEDRING.BIN");
b.getInstallStep().dependOn(&install_schedring.step);
// ------------------------------------------------------------------
// Guest: the four-core four-domain stress hammers (claim 907 / issue
// #858) — SMPFILE.BIN / SMPNET.BIN / SMPWIN.BIN / SMPEV.BIN, each a
// REAL Zig program (the calc/notepad shape, so they import the tiny
// lib/smpst.zig syscall shim and keep counters in Zig). The live
// gate boots 4 VCPUs and execs each pinned to its own core
// (`exec -c1 SMPFILE.BIN` / `-c2 SMPNET.BIN` / `-c3 SMPWIN.BIN` /
// `-c0 SMPEV.BIN`), each hammering a DIFFERENT service domain (FILE /
// NET / WIN / EV) concurrently — the no-cross-domain-contention
// payoff gate for the per-service-domain locks (claim 2792).
// ------------------------------------------------------------------
const smpst_hammers = [_]struct { src: []const u8, bin: []const u8, tag: []const u8 }{
.{ .src = "user/src/smpst_file.zig", .bin = "SMPFILE.BIN", .tag = "file" },
.{ .src = "user/src/smpst_net.zig", .bin = "SMPNET.BIN", .tag = "net" },
.{ .src = "user/src/smpst_win.zig", .bin = "SMPWIN.BIN", .tag = "win" },
.{ .src = "user/src/smpst_ev.zig", .bin = "SMPEV.BIN", .tag = "ev" },
};
for (smpst_hammers) |h| {
const hammer = b.addExecutable(.{
.name = b.fmt("user-smpst-{s}", .{h.tag}),
.root_module = b.createModule(.{
.root_source_file = b.path(h.src),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
hammer.linker_script = b.path("user/linker-segmented.ld");
const hammer_step = b.step(b.fmt("smpst-{s}", .{h.tag}), b.fmt("Build the four-core stress {s} hammer (zig-out/bin/{s}; class A tooling, no VM)", .{ h.tag, h.bin }));
const hammer_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--segments" });
hammer_elf2bin.addFileArg(hammer.getEmittedBin());
const hammer_bin = hammer_elf2bin.addOutputFileArg(h.bin);
hammer_elf2bin.has_side_effects = true;
hammer_elf2bin.stdio = .inherit;
hammer_step.dependOn(&hammer_elf2bin.step);
const install_hammer = b.addInstallFileWithDir(hammer_bin, .bin, h.bin);
b.getInstallStep().dependOn(&install_hammer.step);
}
// ------------------------------------------------------------------
// Guest: fifth ESP user program (milestone five, card N6 — claim
// 1384) — the UDP syscall proof UDP.BIN. Same freestanding target,
// linker script, elf2bin conversion, and ESP embedding as USER.BIN /
// COUNTER.BIN / PEER.BIN / STATUS43.BIN; the kernel's `exec UDP.BIN`
// monitor command loads it by name. It binds port 7000 through the
// new sys_udp_listen (slot 9), loopback-sends and round-trips to the
// host through sys_udp_send (slot 10) + sys_udp_recv (slot 11),
// prints its markers, and exits with status 17 — the live gate's
// first network-syscall proof from EL0.
// ------------------------------------------------------------------
const udp = b.addExecutable(.{
.name = "user-udp",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/udp.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
udp.linker_script = b.path("user/linker.ld");
const udp_step = b.step("udp", "Build the fifth ESP user program (zig-out/bin/UDP.BIN; class A tooling, no VM)");
const udp_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
udp_elf2bin.addFileArg(udp.getEmittedBin());
const udp_bin = udp_elf2bin.addOutputFileArg("UDP.BIN");
udp_elf2bin.has_side_effects = true;
udp_elf2bin.stdio = .inherit;
udp_step.dependOn(&udp_elf2bin.step);
const install_udp = b.addInstallFileWithDir(udp_bin, .bin, "UDP.BIN");
b.getInstallStep().dependOn(&install_udp.step);
// ------------------------------------------------------------------
// Guest: sixth ESP user program (milestone six, card G6 — claim 0487) —
// the draw/window syscall proof WIN.BIN. Same freestanding target,
// linker script, elf2bin conversion, and ESP embedding as the other
// user programs; the kernel's `exec WIN.BIN` monitor command loads it
// by name. It opens a user window through sys_win_open (slot 12),
// fills it through sys_win_fill (slot 13), presents it through
// sys_win_present (slot 14), and exits 87 — the first EL0 graphics
// proof.
// ------------------------------------------------------------------
const win = b.addExecutable(.{
.name = "user-win",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/win.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
win.linker_script = b.path("user/linker.ld");
const win_step = b.step("win", "Build the sixth ESP user program (zig-out/bin/WIN.BIN; class A tooling, no VM)");
const win_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
win_elf2bin.addFileArg(win.getEmittedBin());
const win_bin = win_elf2bin.addOutputFileArg("WIN.BIN");
win_elf2bin.has_side_effects = true;
win_elf2bin.stdio = .inherit;
win_step.dependOn(&win_elf2bin.step);
const install_win = b.addInstallFileWithDir(win_bin, .bin, "WIN.BIN");
b.getInstallStep().dependOn(&install_win.step);
// ------------------------------------------------------------------
// Guest: seventh ESP user program (milestone six, card G6 teardown
// follow-on — claim 0487) — the draw/window RELEASE proof WINCLOSE.BIN.
// Same freestanding target, linker script, elf2bin conversion, and ESP
// embedding as the other user programs; the kernel's
// `exec WINCLOSE.BIN` monitor command loads it by name. It opens a user
// window through sys_win_open (slot 12), fills it (slot 13), presents
// it (slot 14), then CLOSES it through sys_win_close (slot 15) and
// exits 88 — the EL0 release proof (the window does not persist; the
// freed id is re-openable).
// ------------------------------------------------------------------
const winclose = b.addExecutable(.{
.name = "user-winclose",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/winclose.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
winclose.linker_script = b.path("user/linker.ld");
const winclose_step = b.step("winclose", "Build the seventh ESP user program (zig-out/bin/WINCLOSE.BIN; class A tooling, no VM)");
const winclose_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
winclose_elf2bin.addFileArg(winclose.getEmittedBin());
const winclose_bin = winclose_elf2bin.addOutputFileArg("WINCLOSE.BIN");
winclose_elf2bin.has_side_effects = true;
winclose_elf2bin.stdio = .inherit;
winclose_step.dependOn(&winclose_elf2bin.step);
const install_winclose = b.addInstallFileWithDir(winclose_bin, .bin, "WINCLOSE.BIN");
b.getInstallStep().dependOn(&install_winclose.step);
// ------------------------------------------------------------------
// Guest: eighth ESP user program (milestone six, card G6 per-process-
// ownership follow-on — claim 0487) — the PERSISTENT window proof
// WINLOOP.BIN. Same freestanding target, linker script, elf2bin
// conversion, and ESP embedding as the other user programs; the kernel's
// `exec WINLOOP.BIN` monitor command loads it by name. It opens a user
// window (slot 12), fills it (slot 13), presents it (slot 14), then
// yield-loops FOREVER (slot 2) so the window stays on the scanout for
// the live gate's decoded-capture phase (WIN.BIN exits and its window
// auto-closes before a capture can see it).
// ------------------------------------------------------------------
const winloop = b.addExecutable(.{
.name = "user-winloop",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/winloop.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
winloop.linker_script = b.path("user/linker.ld");
const winloop_step = b.step("winloop", "Build the eighth ESP user program (zig-out/bin/WINLOOP.BIN; class A tooling, no VM)");
const winloop_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
winloop_elf2bin.addFileArg(winloop.getEmittedBin());
const winloop_bin = winloop_elf2bin.addOutputFileArg("WINLOOP.BIN");
winloop_elf2bin.has_side_effects = true;
winloop_elf2bin.stdio = .inherit;
winloop_step.dependOn(&winloop_elf2bin.step);
const install_winloop = b.addInstallFileWithDir(winloop_bin, .bin, "WINLOOP.BIN");
b.getInstallStep().dependOn(&install_winloop.step);
// ------------------------------------------------------------------
// Guest: ninth ESP user program (milestone six, card G6 move/raise
// follow-on — claim 0487) — the MOVE/RESTACK proof WINMOVE.BIN. Same
// freestanding target, linker script, elf2bin conversion, and ESP
// embedding as the other user programs; the kernel's
// `exec WINMOVE.BIN` monitor command loads it by name. It opens a user
// window (slot 12), fills it (slot 13), presents it (slot 14), moves it
// twice (slot 16 — the second move clamps to the scanout corner) and
// raises it (slot 17), then yield-loops FOREVER (slot 2) so the moved
// window stays on the scanout for the live gate's decoded-capture
// phase (the window's own colors at the NEW position).
// ------------------------------------------------------------------
const winmove = b.addExecutable(.{
.name = "user-winmove",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/winmove.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
winmove.linker_script = b.path("user/linker.ld");
const winmove_step = b.step("winmove", "Build the ninth ESP user program (zig-out/bin/WINMOVE.BIN; class A tooling, no VM)");
const winmove_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
winmove_elf2bin.addFileArg(winmove.getEmittedBin());
const winmove_bin = winmove_elf2bin.addOutputFileArg("WINMOVE.BIN");
winmove_elf2bin.has_side_effects = true;
winmove_elf2bin.stdio = .inherit;
winmove_step.dependOn(&winmove_elf2bin.step);
const install_winmove = b.addInstallFileWithDir(winmove_bin, .bin, "WINMOVE.BIN");
b.getInstallStep().dependOn(&install_winmove.step);
// ------------------------------------------------------------------
// Guest: tenth ESP user program (milestone nine, card E6 capstone gate —
// claim 9328) — the interactive event user application KEYTEST.BIN.
// Opens a window, waits for application events via sys_wait_event
// (slot 22), updates window contents in response to keyboard and pointer
// events, and exits with status 99.
// ------------------------------------------------------------------
const keytest = b.addExecutable(.{
.name = "user-keytest",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/keytest.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
keytest.linker_script = b.path("user/linker.ld");
const keytest_step = b.step("keytest", "Build the tenth ESP user program (zig-out/bin/KEYTEST.BIN; class A tooling, no VM)");
const keytest_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
keytest_elf2bin.addFileArg(keytest.getEmittedBin());
const keytest_bin = keytest_elf2bin.addOutputFileArg("KEYTEST.BIN");
keytest_elf2bin.has_side_effects = true;
keytest_elf2bin.stdio = .inherit;
keytest_step.dependOn(&keytest_elf2bin.step);
const install_keytest = b.addInstallFileWithDir(keytest_bin, .bin, "KEYTEST.BIN");
b.getInstallStep().dependOn(&install_keytest.step);
// ------------------------------------------------------------------
// Guest: eleventh ESP user program (milestone ten, card F4 — claim 0510)
// SAVETEXT.BIN. Writes data to /data/hello.txt via file syscalls.
// ------------------------------------------------------------------
const savetext = b.addExecutable(.{
.name = "user-savetext",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/savetext.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
savetext.linker_script = b.path("user/linker.ld");
const savetext_step = b.step("savetext", "Build the eleventh ESP user program (zig-out/bin/SAVETEXT.BIN)");
const savetext_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
savetext_elf2bin.addFileArg(savetext.getEmittedBin());
const savetext_bin = savetext_elf2bin.addOutputFileArg("SAVETEXT.BIN");
savetext_elf2bin.has_side_effects = true;
savetext_elf2bin.stdio = .inherit;
savetext_step.dependOn(&savetext_elf2bin.step);
const install_savetext = b.addInstallFileWithDir(savetext_bin, .bin, "SAVETEXT.BIN");
b.getInstallStep().dependOn(&install_savetext.step);
// ------------------------------------------------------------------
// Guest: twelfth ESP user program (milestone ten, card F4 — claim 0510)
// TYPE.BIN. Reads data from /data/hello.txt via file syscalls.
// ------------------------------------------------------------------
const type_prog = b.addExecutable(.{
.name = "user-type",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/type.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
type_prog.linker_script = b.path("user/linker.ld");
const type_step = b.step("type", "Build the twelfth ESP user program (zig-out/bin/TYPE.BIN)");
const type_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
type_elf2bin.addFileArg(type_prog.getEmittedBin());
const type_bin = type_elf2bin.addOutputFileArg("TYPE.BIN");
type_elf2bin.has_side_effects = true;
type_elf2bin.stdio = .inherit;
type_step.dependOn(&type_elf2bin.step);
const install_type = b.addInstallFileWithDir(type_bin, .bin, "TYPE.BIN");
b.getInstallStep().dependOn(&install_type.step);
// ------------------------------------------------------------------
// Guest: thirteenth ESP user program (milestone ten, card F4 — claim 0510)
// DIR.BIN. Enumerates directory entries via sys_dir_list.
// ------------------------------------------------------------------
const dir_prog = b.addExecutable(.{
.name = "user-dir",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/dir.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
dir_prog.linker_script = b.path("user/linker.ld");
const dir_step = b.step("dir", "Build the thirteenth ESP user program (zig-out/bin/DIR.BIN)");
const dir_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
dir_elf2bin.addFileArg(dir_prog.getEmittedBin());
const dir_bin = dir_elf2bin.addOutputFileArg("DIR.BIN");
dir_elf2bin.has_side_effects = true;
dir_elf2bin.stdio = .inherit;
dir_step.dependOn(&dir_elf2bin.step);
const install_dir = b.addInstallFileWithDir(dir_bin, .bin, "DIR.BIN");
b.getInstallStep().dependOn(&install_dir.step);
// ------------------------------------------------------------------
// Guest: M43 U3 EL0 consumer (issue #1034 — claim #1048) BLKD.BIN.
// Reads the raw USB mass-storage disk through the file-table `.usb`
// volume (slots 23/24/26) and prints the host-staged marker bytes.
// ------------------------------------------------------------------
const blkd_prog = b.addExecutable(.{
.name = "user-blkd",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/blkd.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
blkd_prog.linker_script = b.path("user/linker.ld");
const blkd_step = b.step("blkd", "Build the M43 U3 block-device consumer (zig-out/bin/BLKD.BIN)");
const blkd_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
blkd_elf2bin.addFileArg(blkd_prog.getEmittedBin());
const blkd_bin = blkd_elf2bin.addOutputFileArg("BLKD.BIN");
blkd_elf2bin.has_side_effects = true;
blkd_elf2bin.stdio = .inherit;
blkd_step.dependOn(&blkd_elf2bin.step);
const install_blkd = b.addInstallFileWithDir(blkd_bin, .bin, "BLKD.BIN");
b.getInstallStep().dependOn(&install_blkd.step);
// ------------------------------------------------------------------
// Guest: fourteenth ESP user program (milestone eleven, card A2 — claim 8401)
// CALC.BIN. Interactive graphical calculator with 64-bit engine.
// DSK3 segmented (writable .data/.bss — the WMS9 fill-batcher global needs
// the RW data+bss aperture; the EDIT/GLOBALS precedent).
// ------------------------------------------------------------------
const calc_prog = b.addExecutable(.{
.name = "user-calc",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/calc.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
calc_prog.linker_script = b.path("user/linker-segmented.ld");
const calc_step = b.step("calc", "Build the fourteenth ESP user program (zig-out/bin/CALC.BIN) — DSK3 segmented (writable .data/.bss)");
const calc_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--segments" });
calc_elf2bin.addFileArg(calc_prog.getEmittedBin());
const calc_bin = calc_elf2bin.addOutputFileArg("CALC.BIN");
calc_elf2bin.has_side_effects = true;
calc_elf2bin.stdio = .inherit;
calc_step.dependOn(&calc_elf2bin.step);
const install_calc = b.addInstallFileWithDir(calc_bin, .bin, "CALC.BIN");
b.getInstallStep().dependOn(&install_calc.step);
// ------------------------------------------------------------------
// Guest: fifteenth ESP user program (milestone eleven, card A3 — claim 3234)
// NOTEPAD.BIN. Interactive graphical text editor with /data persistence.
// DSK3 segmented (writable .data/.bss — the WMS9 fill-batcher global needs
// the RW data+bss aperture; observed live: NOTEPAD data-aborted on the flat
// DSK1 mapping at its .bss tail once draw primitives batched fills).
// ------------------------------------------------------------------
const notepad_prog = b.addExecutable(.{
.name = "user-notepad",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/notepad.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
notepad_prog.linker_script = b.path("user/linker-segmented.ld");
const notepad_step = b.step("notepad", "Build the fifteenth ESP user program (zig-out/bin/NOTEPAD.BIN) — DSK3 segmented (writable .data/.bss)");
const notepad_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--segments" });
notepad_elf2bin.addFileArg(notepad_prog.getEmittedBin());
const notepad_bin = notepad_elf2bin.addOutputFileArg("NOTEPAD.BIN");
notepad_elf2bin.has_side_effects = true;
notepad_elf2bin.stdio = .inherit;
notepad_step.dependOn(¬epad_elf2bin.step);
const install_notepad = b.addInstallFileWithDir(notepad_bin, .bin, "NOTEPAD.BIN");
b.getInstallStep().dependOn(&install_notepad.step);
// ------------------------------------------------------------------
// Guest: sixteenth ESP user program (milestone eleven, card A4 — claim 0680)
// TOP.BIN. Graphical task manager & process monitor.
// DSK3 segmented (writable .data/.bss — the WMS9 fill-batcher global).
// ------------------------------------------------------------------
const top_prog = b.addExecutable(.{
.name = "user-top",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/top.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
top_prog.linker_script = b.path("user/linker-segmented.ld");
const top_step = b.step("top", "Build the sixteenth ESP user program (zig-out/bin/TOP.BIN) — DSK3 segmented (writable .data/.bss)");
const top_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--segments" });
top_elf2bin.addFileArg(top_prog.getEmittedBin());
const top_bin = top_elf2bin.addOutputFileArg("TOP.BIN");
top_elf2bin.has_side_effects = true;
top_elf2bin.stdio = .inherit;
top_step.dependOn(&top_elf2bin.step);
const install_top = b.addInstallFileWithDir(top_bin, .bin, "TOP.BIN");
b.getInstallStep().dependOn(&install_top.step);
// ------------------------------------------------------------------
// Guest: seventeenth ESP user program (milestone eleven, card A5 — claim 2427)
// DESKTOP.BIN. Desktop launcher & environment panel.
// DSK3 segmented (writable .data/.bss — the WMS9 fill-batcher global).
// ------------------------------------------------------------------
const desktop_prog = b.addExecutable(.{
.name = "user-desktop",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/desktop.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
desktop_prog.linker_script = b.path("user/linker-segmented.ld");
const desktop_step = b.step("desktop", "Build the seventeenth ESP user program (zig-out/bin/DESKTOP.BIN) — DSK3 segmented (writable .data/.bss)");
const desktop_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--segments" });
desktop_elf2bin.addFileArg(desktop_prog.getEmittedBin());
const desktop_bin = desktop_elf2bin.addOutputFileArg("DESKTOP.BIN");
desktop_elf2bin.has_side_effects = true;
desktop_elf2bin.stdio = .inherit;
desktop_step.dependOn(&desktop_elf2bin.step);
const install_desktop = b.addInstallFileWithDir(desktop_bin, .bin, "DESKTOP.BIN");
b.getInstallStep().dependOn(&install_desktop.step);
// ------------------------------------------------------------------
// Guy: thirtieth ESP user program (M23 E1-E6 — EDIT.BIN, the text editor).
// Built as a SEGMENTED DSK3 image (like GLOBALS.BIN): the editor's ~140 KiB
// of state (4 × 32 KiB tab buffers + undo ring) lives in .data/.bss as a
// global, and the flat DSK1 format maps text read-only — a writable global
// needs the DSK3 loader's RW data+bss aperture (observed in the live gate).
// ------------------------------------------------------------------
const edit_prog = b.addExecutable(.{
.name = "user-edit",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/edit.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
edit_prog.linker_script = b.path("user/linker-segmented.ld");
const edit_step = b.step("edit", "Build the thirtieth user program (zig-out/bin/EDIT.BIN) — DSK3 segmented (writable .data/.bss)");
const edit_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--segments" });
edit_elf2bin.addFileArg(edit_prog.getEmittedBin());
const edit_bin = edit_elf2bin.addOutputFileArg("EDIT.BIN");
edit_elf2bin.has_side_effects = true;
edit_elf2bin.stdio = .inherit;
edit_step.dependOn(&edit_elf2bin.step);
const install_edit = b.addInstallFileWithDir(edit_bin, .bin, "EDIT.BIN");
b.getInstallStep().dependOn(&install_edit.step);
// ------------------------------------------------------------------
// Guest: eighteenth ESP user program (milestone twelve, card N1 — claim 7483)
// TCP.BIN. Userland TCP proof program.
// ------------------------------------------------------------------
const tcp_prog = b.addExecutable(.{
.name = "user-tcp",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/tcp_client.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
tcp_prog.linker_script = b.path("user/linker.ld");
const tcp_step = b.step("tcp", "Build the eighteenth ESP user program (zig-out/bin/TCP.BIN)");
const tcp_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
tcp_elf2bin.addFileArg(tcp_prog.getEmittedBin());
const tcp_bin = tcp_elf2bin.addOutputFileArg("TCP.BIN");
tcp_elf2bin.has_side_effects = true;
tcp_elf2bin.stdio = .inherit;
tcp_step.dependOn(&tcp_elf2bin.step);
const install_tcp = b.addInstallFileWithDir(tcp_bin, .bin, "TCP.BIN");
b.getInstallStep().dependOn(&install_tcp.step);
// ------------------------------------------------------------------
// Guest: nineteenth ESP user program (milestone twelve, card N3 — claim 5416)
// FETCH.BIN. Userland HTTP/1.0 client.
// ------------------------------------------------------------------
const fetch_prog = b.addExecutable(.{
.name = "user-fetch",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/fetch.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
fetch_prog.linker_script = b.path("user/linker.ld");
const fetch_step = b.step("fetch", "Build the nineteenth ESP user program (zig-out/bin/FETCH.BIN)");
const fetch_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py" });
fetch_elf2bin.addFileArg(fetch_prog.getEmittedBin());
const fetch_bin = fetch_elf2bin.addOutputFileArg("FETCH.BIN");
fetch_elf2bin.has_side_effects = true;
fetch_elf2bin.stdio = .inherit;
fetch_step.dependOn(&fetch_elf2bin.step);
const install_fetch = b.addInstallFileWithDir(fetch_bin, .bin, "FETCH.BIN");
b.getInstallStep().dependOn(&install_fetch.step);
// ------------------------------------------------------------------
// Guest: M51 SSH1 (#1168) class-B proof program — SSHPACKET.BIN. The
// guest half of the live-ssh-packet gate: it reassembles one SSH binary
// packet the host sends split across many paced TCP segments. DSK3
// segmented (the stream adapter's bounded buffer is a static .bss
// global, ADR 0025 D6).
// ------------------------------------------------------------------
const sshpacket_ui_mod = b.createModule(.{
.root_source_file = b.path("user/src/lib/ui.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
});
const sshpacket_mod = b.createModule(.{
.root_source_file = b.path("user/src/sshpacket.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
});
sshpacket_mod.addImport("ui", sshpacket_ui_mod);
const sshpacket_prog = b.addExecutable(.{
.name = "user-sshpacket",
.root_module = sshpacket_mod,
});
sshpacket_prog.linker_script = b.path("user/linker-segmented.ld");
const sshpacket_step = b.step("sshpacket", "Build the M51 SSH1 class-B proof program (zig-out/bin/SSHPACKET.BIN) — DSK3 segmented");
const sshpacket_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--segments" });
sshpacket_elf2bin.addFileArg(sshpacket_prog.getEmittedBin());
const sshpacket_bin = sshpacket_elf2bin.addOutputFileArg("SSHPACKET.BIN");
sshpacket_elf2bin.has_side_effects = true;
sshpacket_elf2bin.stdio = .inherit;
sshpacket_step.dependOn(&sshpacket_elf2bin.step);
const install_sshpacket = b.addInstallFileWithDir(sshpacket_bin, .bin, "SSHPACKET.BIN");
b.getInstallStep().dependOn(&install_sshpacket.step);
// ------------------------------------------------------------------
// Guest: SSH.BIN — M51 SSH4 (#1171, ADR 0025 D1/D2/D6/D7). The SSH-2
// client: KEX + userauth + the encrypted packet transport + a session
// channel, `exec`-one-shot or interactive `shell`. DSK3 segmented (the
// transport's bounded rx/tx/msg buffers are static .bss, ADR 0025 D6).
// No kernel change and no new syscall slot.
// ------------------------------------------------------------------
const ssh_ui_mod = b.createModule(.{
.root_source_file = b.path("user/src/lib/ui.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
});
const ssh_crypto_mod = b.createModule(.{
.root_source_file = b.path("user/src/lib/crypto.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
});
const ssh_rng_mod = b.createModule(.{
.root_source_file = b.path("user/src/lib/rng.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
});
ssh_rng_mod.addImport("ui", ssh_ui_mod);
const ssh_mod = b.createModule(.{
.root_source_file = b.path("user/src/ssh.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
});
ssh_mod.addImport("ui", ssh_ui_mod);
ssh_mod.addImport("crypto", ssh_crypto_mod);
ssh_mod.addImport("rng", ssh_rng_mod);
const ssh_prog = b.addExecutable(.{
.name = "user-ssh",
.root_module = ssh_mod,
});
ssh_prog.linker_script = b.path("user/linker-segmented.ld");
const ssh_step = b.step("ssh", "Build the M51 SSH4 client (zig-out/bin/SSH.BIN) — DSK3 segmented");
const ssh_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--segments" });
ssh_elf2bin.addFileArg(ssh_prog.getEmittedBin());
const ssh_bin = ssh_elf2bin.addOutputFileArg("SSH.BIN");
ssh_elf2bin.has_side_effects = true;
ssh_elf2bin.stdio = .inherit;
ssh_step.dependOn(&ssh_elf2bin.step);
const install_ssh = b.addInstallFileWithDir(ssh_bin, .bin, "SSH.BIN");
b.getInstallStep().dependOn(&install_ssh.step);
// ------------------------------------------------------------------
// Guest: FETCHS.BIN — the first HTTPS consumer of the in-tree TLS 1.3
// client (ADR 0029, cards TLS13-C7/C8). Connects to the host gateway on
// 443 over the kernel TCP seam, completes a 1-RTT handshake against the
// vendored root blob, and streams one HTTP/1.0 GET. DSK3 segmented: the
// trust store and the seam accumulator are static .bss.
// ------------------------------------------------------------------
const fetchs_ui_mod = b.createModule(.{
.root_source_file = b.path("user/src/lib/ui.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
});
const fetchs_crypto_mod = b.createModule(.{
.root_source_file = b.path("user/src/lib/crypto.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
});
const fetchs_rng_mod = b.createModule(.{
.root_source_file = b.path("user/src/lib/rng.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
});
fetchs_rng_mod.addImport("ui", fetchs_ui_mod);
const fetchs_mod = b.createModule(.{
.root_source_file = b.path("user/src/fetchs.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
});
fetchs_mod.addImport("ui", fetchs_ui_mod);
fetchs_mod.addImport("crypto", fetchs_crypto_mod);
fetchs_mod.addImport("rng", fetchs_rng_mod);
const fetchs_prog = b.addExecutable(.{
.name = "user-fetchs",
.root_module = fetchs_mod,
});
fetchs_prog.linker_script = b.path("user/linker-segmented.ld");
const fetchs_step = b.step("fetchs", "Build the HTTPS consumer (zig-out/bin/FETCHS.BIN), DSK3 segmented");
const fetchs_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--segments" });
fetchs_elf2bin.addFileArg(fetchs_prog.getEmittedBin());
const fetchs_bin = fetchs_elf2bin.addOutputFileArg("FETCHS.BIN");
fetchs_elf2bin.has_side_effects = true;
fetchs_elf2bin.stdio = .inherit;
fetchs_step.dependOn(&fetchs_elf2bin.step);
const install_fetchs = b.addInstallFileWithDir(fetchs_bin, .bin, "FETCHS.BIN");
b.getInstallStep().dependOn(&install_fetchs.step);
// ------------------------------------------------------------------
// Guest: twentieth ESP user program (milestone twelve, card N3 — claim 5416)
// CHAT.BIN. Userland graphical P2P chat application.
// DSK3 segmented (writable .data/.bss — the WMS9 fill-batcher global).
// ------------------------------------------------------------------
const chat_prog = b.addExecutable(.{
.name = "user-chat",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/chat.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
chat_prog.linker_script = b.path("user/linker-segmented.ld");
const chat_step = b.step("chat", "Build the twentieth ESP user program (zig-out/bin/CHAT.BIN) — DSK3 segmented (writable .data/.bss)");
const chat_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--segments" });
chat_elf2bin.addFileArg(chat_prog.getEmittedBin());
const chat_bin = chat_elf2bin.addOutputFileArg("CHAT.BIN");
chat_elf2bin.has_side_effects = true;
chat_elf2bin.stdio = .inherit;
chat_step.dependOn(&chat_elf2bin.step);
const install_chat = b.addInstallFileWithDir(chat_bin, .bin, "CHAT.BIN");
b.getInstallStep().dependOn(&install_chat.step);
// ------------------------------------------------------------------
// Guest: twenty-first ESP user program (milestone thirteen, card B3 — claim 4742)
// FILE.BIN. Graphical file browser for the DATA partition.
// ------------------------------------------------------------------
const file_prog = b.addExecutable(.{
.name = "user-file-browser",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/file_browser.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),
});
file_prog.linker_script = b.path("user/linker-segmented.ld");
const file_step = b.step("file", "Build the twenty-first ESP user program (zig-out/bin/FILE.BIN) — DSK3 segmented (writable .data/.bss)");
const file_elf2bin = b.addSystemCommand(&.{ "python3", "tools/elf2bin.py", "--segments" });
file_elf2bin.addFileArg(file_prog.getEmittedBin());
const file_bin = file_elf2bin.addOutputFileArg("FILE.BIN");
file_elf2bin.has_side_effects = true;
file_elf2bin.stdio = .inherit;
file_step.dependOn(&file_elf2bin.step);
const install_file = b.addInstallFileWithDir(file_bin, .bin, "FILE.BIN");
b.getInstallStep().dependOn(&install_file.step);
// ------------------------------------------------------------------
// Guest: twenty-third ESP user program (milestone fourteen, card S2 — claim 7323)
// TIMER.BIN. Headless per-process app-timer proof (arm/wait/fire/cancel).
// ------------------------------------------------------------------
const timertest_prog = b.addExecutable(.{
.name = "user-timertest",
.root_module = b.createModule(.{
.root_source_file = b.path("user/src/timertest.zig"),
.target = kernel_target,
.optimize = .ReleaseSmall,
}),