interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / omc / omc.om

26051 lines · 602173 bytes Raw Blame History
1note omc: the Omega compiler written in Omega (the om4 subset). Reads Omegese on stdin, writes a runnable
2note AArch64 Linux program (or bare function words) on stdout. Built first by om4; its codegen matches om4
3note byte for byte on the original subset (seed chain rung 5, ledger L408). Native host operations
4note extend that subset; om4 still builds this compiler, and the compiler rebuilds itself identically.
5note All compiler state lives in global pools (decision 24: no heap). Every working value is a ulong
6note (raw 64 bits) so the language's checked conversions never fire on om4's untyped-register logic.
7
8note ---- the arena (decision 23 as amended 2026-11-11, OMEGESE 9.6; grown at run time since landing 2 of the
9note run-time pools, decision 3 of 2026-11-11, docs/RUNTIME-POOLS.md s6). Every table whose size grows with the
10note unit (the input, the output, names, long names, functions and their parameters, call sites, trap sites,
11note blocks, breaks, value nesting, the x86 fixups, the om2 diag sites) is a region of the one pool a_ar.
12note A region starts small and doubles when an index reaches its capacity (a_need), so no table fills.
13note a_ar is a run-time pool (global a_ar ulong *, OMEGESE 9.15): its length is 0 when omc starts, and a_need
14note enlarges it (a_grow) whenever a group's growth would not fit in the words left: to twice its length, or
15note to what the tables need when that is more. So omc has no arena size of its own: the host is the bound.
16note When the host refuses (enlarge's negative result, for example under prlimit --as), the arena is compacted
17note and the group grows in place to the largest size that fits; when not even one more entry fits, the unit
18note is error 14 with an omc-use record on stderr (full=1: the host refused) naming every group and the words
19note it held (a_full, a_rec). The static 128 MiB arena this replaces was sized by omc's image under the
20note smallest RLIMIT_AS omc runs under (the interplane-forge salvage compile, 268435456) and by the 16777216
21note elements of a sized pool (OMEGESE 9.4); a run-time pool is bounded by neither, and the image no longer
22note holds the arena.
23note a_rb / a_rw: a region's first word and the words it holds; a_rg its group; a_rm its elements per group
24note index (0: a byte region, 8 bytes to a word); a_gc / a_gp a group's capacity and the highest index it
25note was asked for, plus 1; a_top the words handed out; a_wst the words left behind by moves; a_fl 1 while
26note error 14 is the arena's; a_nr the region count; a_wb the staging bytes of read and write.
27global a_ar ulong *
28note a_cel: the caller-stated memory ceiling C in bytes (OMC_MEMORY_MAX, a_env; 0: none). The arena's bytes A, the
29note output's bytes O (written to stdout they are page cache of the same cgroup) and the margin 16 MiB + A / 128
30note stay within C (docs/RUNTIME-POOLS.md s6, "The memory ceiling"): a_capw at every growth, a_ceilo before the write
31global a_cel ulong 1
32note a_rdy: 1 once a_init has given every region its first room (a_need compacts only then, or while region 0 is alone)
33global a_rdy ulong 1
34note a_hw: the most words a_top ever held (a_hwset); a compaction lowers a_top, not the pages it touched
35global a_hw ulong 1
36text a_envk "OMC_MEMORY_MAX="
37note a_eb: one environment entry (Linux keeps each below 131072 bytes, MAX_ARG_STRLEN)
38global a_eb uchar 131072
39global a_rb ulong 96
40global a_rw ulong 96
41global a_rg ulong 96
42global a_rm ulong 96
43global a_gc ulong 32
44global a_gp ulong 32
45global a_top ulong 1
46global a_wst ulong 1
47global a_fl ulong 1
48global a_nr ulong 1
49note a_ord / a_np: the regions in order of base and their new places, for a_relayout
50global a_ord ulong 96
51global a_np ulong 96
52global a_wb uchar 65536
53note nh_b / lh_b / fh_b: the bucket bits of the name, long-name and function hash tables (chained: the
54note bucket holds index + 1 of the newest entry, nm_nx / ln_x / fn_nx the one before it in the chain)
55global nh_b ulong 1
56global lh_b ulong 1
57global fh_b ulong 1
58note tpend: the first trap site of the function being compiled that no stub was patched to yet (island)
59global tpend ulong 1
60
61note ---- input, output, token ----
62global inlen ulong 1
63global irmode ulong 1
64global cur ulong 1
65global line ulong 1
66global tk ulong 1
67global tw ulong 1
68global tl ulong 1
69global ts ulong 1
70global tbig ulong 1
71global oc ulong 1
72
73note ---- OM-2 profile (spec/omegese-om2.md, OMEGESE.md 9.13). om2 is 1 in an OM-2 unit (its first line
74note that is not a note or blank is exactly om2, om2 diag or om2 fmt); om2m 0 compile, 1 diag, 2 fmt;
75note om2ln/om2pos the line number and offset of that line; fmtm 1 while a unit is formatted; lbase and
76note sbase shift reported lines and bytes back to the original input in fmt mode; tka/tkb the byte span of
77note the last token; dexp what was being read (0 word 1 value 2 type 3 name 4 number 5 end 6 newline);
78note dsev 0 derived, 2 unknown (an undeclared function or struct), 3 error ----
79global om2 ulong 1
80global om2m ulong 1
81global om2ln ulong 1
82global om2pos ulong 1
83global fmtm ulong 1
84global chkmode ulong 1
85global objmode ulong 1
86global objmeta ulong 1
87global chkln ulong 1
88global lbase ulong 1
89global sbase ulong 1
90global tka ulong 1
91global tkb ulong 1
92global dexp ulong 1
93global dsev ulong 1
94
95note ---- executable contracts: OM-2 debug by default, release erases only validated pure predicates.
96note Function prefixes are replayed at returns with their declaration scope, including inline frames.
97global crel ulong 1
98global cpure ulong 1
99global cvalid ulong 1
100global clim ulong 1
101global crkind ulong 1
102global crval ulong 1
103global crtype ulong 1
104global cfpos ulong 8
105global cfline ulong 8
106global cflim ulong 8
107global cfhas ulong 8
108global csnap ulong 8
109global ckind ulong 1
110
111note ---- OM-2 section 4 (unroll, inline, folding, bounds, sites). fn_inl/fn_body/fn_bln/fn_pn: a function's
112note inline mark, its body offset and line, its parameter names. fstart: where the function being compiled
113note starts (no longer a bound: OM-2 functions have no emitted-word budget). nmlo: names below it and at or above nglob are hidden while an
114note inlined body is compiled (0 otherwise). fzone: open unrolled bodies and inline frames (folding is
115note done only when it is above 0). inl and il_*: the inline frames (at most 4). ilp/nilp: the B words of
116note an inlined ret, patched at its end. lastb/tgoc: the word after the last inlined ret's B and the last
117note place a branch was patched to. u_*: the unrolled loop of each block. fok/fval/fty: a fold result.
118note sitebuf/nsite: the omc-site records of om2 diag.
119global fstart ulong 1
120global nmlo ulong 1
121global fzone ulong 1
122global inl ulong 1
123global il_cur ulong 8
124global il_line ulong 8
125global il_ret ulong 8
126global il_nn ulong 8
127global il_lo ulong 8
128global il_held ulong 8
129global il_ns ulong 8
130global il_res ulong 8
131global il_fn ulong 8
132global il_p0 ulong 8
133global nilp ulong 1
134global lastb ulong 1
135global tgoc ulong 1
136note fuel (E14, E16): the expansion fuel used by the function being compiled: an unrolled loop costs K when
137note it starts, an inline expansion 1, at most 65536 in all (error 14)
138global fuel ulong 1
139global fok ulong 1
140global fval ulong 1
141global fty ulong 1
142global nsite ulong 1
143global nie ulong 1
144
145note ---- name table (arena group 3; names in scope bounded by the arena only): packed name, register, type,
146note length, kind, address. Lookup is by the chained hash nm_h (group 4) with nm_nx; every change of nn goes
147note through nm_set, so a chain holds exactly the names below nn, newest first ----
148global nn ulong 1
149note ---- long names: tok2 interns each word of 9..63 bytes that is not a number as the packed word
150note 1 + 256 * index. Its low byte, 1, is below every byte a word can hold (33..255), so it never equals
151note a name of 8 bytes or fewer or a keyword, and two words get the same packed word exactly when they
152note are spelled the same: every table that compares packed words takes long names unchanged.
153note ln_o: where the spelling starts in the input (it is read there, never copied); ln_l: its length; ln_h
154note (group 6) the chained hash, bucket -> index + 1 of the newest, ln_x the one before it; ln_n: the
155note count (arena group 5). tw8: the word's first 8 bytes before interning (cp_kind reads
156note invariant there). Abstract, layout and layout-field names and IR-mode names stay at 8.
157global ln_n ulong 1
158global tw8 ulong 1
159note ---- OM-2 pinned registers (AArch64 program mode only): X18..X26, which nothing else in a program names,
160note hold for the whole run the base address of the first globals and the length of a global whose length
161note is no CMP immediate. nm_pb / nm_pl: the base / length register of a global name (0: none); pinv the
162note value of pin p (register 18 + p), npin how many are taken. eof_prog sets them before main; scrub sets
163note them again after it clears X18..X26. pinshut: 1 once the body pass has begun a function; a global
164note declared after that gets no pin, because a scrub compiled before it would clear its register and
165note restore only the pins taken so far. ----
166global pinv ulong 9
167global npin ulong 1
168global pinshut ulong 1
169note ---- floats in v registers: kind 9 is a float held in v(16 + pool index of x register rv), the twin of
170note pool register rv; vsl marks each pool slot whose value lives in its twin (an f32/f64 local name, a
171note kind 9 value), saved and loaded as D around a call. fpw asks the next value read for kind 9 (1: a new
172note twin, 2 + r: the twin of r); fpo hands that request to the part that makes the value. A float local
173note name (nm_fv 1) lives in its twin; its x register holds a copy only while a reader needs one. ----
174global vsl uchar 16
175global fpw ulong 1
176global fpo ulong 1
177note fwv: rdval's fpw request at each nesting depth (kept here, not in a register of rdval)
178
179note ---- function table (arena group 7; chained hash fn_h, group 8, with fn_nx): name, address (byte offset
180note in out), return type, parameter count, per-parameter type/length/kind (6 each), name length, name offset
181note in the input ----
182note x86 Linux retains the parser's sixteen logical slots in each native frame.
183note No A64 instruction may pass emit once the explicit target is selected (error 25).
184global xtarget ulong 1
185note xefa: 1 under the first line `target a64efi` (docs/A64-EFI.md): the default AArch64 code generator,
186note a PE32+ UEFI image, base-relative addresses (mataddr) and the efi and fw words; xtarget stays 0.
187global xefa ulong 1
188global xnaddr ulong 1
189note x86efi (xtarget 2): exit-site jumps patched to the shared firmware return, the PE bss address,
190note and the error/done branch lists of one efi operation (closed by xe 2).
191global xnexit ulong 1
192global xbss ulong 1
193global xenerr ulong 1
194global xerrpos ulong 256
195global xerrcode ulong 256
196global xenend ulong 1
197global xendpos ulong 256
198global nf ulong 1
199global lastfn ulong 1
200global scanning ulong 1
201global ncalls ulong 1
202
203
204note ---- compiler state ----
205global npar ulong 1
206global held ulong 1
207global nslot ulong 1
208global curret ulong 1
209global progmode ulong 1
210global nglob ulong 1
211global hostargs ulong 1
212global maptab ulong 1
213global fdtab ulong 1
214global stkbytes ulong 1
215global osp ulong 1
216global osmax ulong 1
217global osbad ulong 1
218global dead ulong 1
219global poolb ulong 1
220note run-time pools (docs/RUNTIME-POOLS.md, OMEGESE 9.15): enl_at is the code offset of the unit's omc_enlarge
221note helper plus 1, 0 until the unit's first enlarge.
222global enl_at ulong 1
223
224note ---- structs (16) and fields (256). R6. nm_type 16+index, kind 6 own, 7 edit, 8 view ----
225global st_name ulong 16
226global st_nf uchar 16
227global st_cells uchar 16
228global st_foff uchar 16
229global nst ulong 1
230global sf_name ulong 256
231global sf_type uchar 256
232global sf_len uchar 256
233global sf_off uchar 256
234global nsf ulong 1
235global svk ulong 16
236global svv ulong 16
237global svt ulong 16
238
239note ---- OM-2 section 5 external layouts (16) and their fields (256): name, SIZE, first field, field count,
240note the cursor and line after the block's end (the body pass jumps there). Field: name, type, COUNT (0 a
241note scalar), byte offset, 1 big-endian. lymap marks the bytes taken while a layout is read. nm_lay /
242note fn_play: the layout (index + 1) of a layout parameter name / parameter slot, else 0 ----
243global ly_name ulong 16
244global ly_size ulong 16
245global ly_fo ulong 16
246global ly_nf ulong 16
247global ly_ec ulong 16
248global ly_el ulong 16
249global nly ulong 1
250global lf_name ulong 256
251global lf_type uchar 256
252global lf_cnt ulong 256
253global lf_off ulong 256
254global lf_big uchar 256
255global nlf ulong 1
256global lymap uchar 4096
257
258note ---- OM-2 section 5 fresh scratch (erratum E8). fn_pfr: 1 for a `fresh` parameter slot. nm_fr: the
259note written-set slot (index + 1) a name's elements are tracked in, else 0. fz_n slots in use by the
260note function being compiled (16), fz_len their N, fz_cur the elements definitely written on the path
261note being compiled (bit i for element i); fz_ent / fz_thn (16 per block): the sets when the block opened
262note and at its else. il_fz: fz_n when an inline frame opened. dobx 1: error 14 reports obligation=init ----
263global fz_n ulong 1
264global fz_len ulong 16
265global fz_cur ulong 16
266global il_fz ulong 8
267global dobx ulong 1
268
269note ---- OM-2 section 5 abstract types (16; type 64 + index): name, its length, representation type (4 uint,
270note 5 ulong), the preserving operations listed (1 rotr, 2 rotl, 4 and, 8 or, 16 xor), 1 when `holds NAME
271note dup32` is declared. aw_*: the word reader of the exact-constructor test (place, packed word, length,
272note newlines crossed before it) ----
273global ab_name ulong 16
274global ab_len ulong 16
275global ab_base uchar 16
276global ab_ops ulong 16
277global ab_holds uchar 16
278global nab ulong 1
279global aw_p ulong 1
280global aw_w ulong 1
281global aw_l ulong 1
282global aw_nl ulong 1
283
284note ---- OM-2 section 6 unsized views (spec 4 slots, 6, erratum E2). An unsized `view T *` / `edit T *`
285note name has length 0 in nm_len and its run-time element count in register nm_lr. Parameters take the
286note registers x0..x5 by slots: an unsized array two (pointer, then count), every other parameter one
287note (pwid, pslot); psl counts the slots of the fn line being read (6 at most, error 9). ul_k / ul_v: the
288note count (kind 1 register / 3 number) of argument i of the call at value depth d, at d * 6 + i ----
289global psl ulong 1
290note ---- OM-2 section 6 multi-entry units: nexp `export fn` lines (32 at most, function mode only), fn_exp 1
291note for an exported function, expf 1 while an `export fn` line is read. With any export, words 0 .. E-1
292note of the code are B to each export in source order and the code starts at byte 176 + 4E ----
293global nexp ulong 1
294global expf ulong 1
295
296note ======== leaf helpers ========
297
298note poolc: the i-th register of the pool x0..x6, x8..x15, x17 (x7 is the runtime, x16 scratch)
299fn poolc i ulong to ulong
300if lt i 7
301ret i
302end
303if lt i 15
304ret add i 1
305end
306ret 17
307end
308
309note pwid: the parameter slots of fn table entry p: 2 for an unsized array (pointer, count), else 1
310fn pwid p ulong to ulong
311k = ulong uchar get a_ar add get a_rb 37 p
312if and or eq k 2 eq k 3 eq get a_ar add get a_rb 36 p 0
313ret 2
314end
315ret 1
316end
317
318note unsz: 1 when name entry i is an unsized array (nm_len 0, its count in register nm_lr), else 0. A text
319note (kind 5) of length 0 (`text e ""`) is sized: its count is the number 0 and it has no count register.
320fn unsz i ulong to ulong
321if and eq a_g 6 i 0 ne a_gu 7 i 5
322if ne a_gu 7 i 10
323ret 1
324end
325end
326ret 0
327end
328
329note pslot: the first slot (register) of parameter i of function f (index)
330fn pslot f ulong i ulong to ulong
331s = ulong 0
332j = ulong 0
333while lt j i
334s = add s pwid add mul f 6 j
335j = add j 1
336end
337ret s
338end
339
340note ---- error reporting ----
341global msg uchar 65536
342global mc ulong 1
343note ======== the arena (notes at a_ar). Groups: 0 inp, 1 out, 2 site, 3 names, 4 name hash, 5 long names,
344note 6 long-name hash, 7 functions, 8 function hash, 9 calls, 10 trap sites, 11 x86 addresses, 12 x86 exits,
345note 13 blocks, 14 breaks, 15 continues, 16 inline rets, 17 inline edges, 18 value depth, 19 and 20 the
346note settle order (ksettle). The regions of each group are listed at a_defs. ========
347
348note a_def: region r is in group g with m elements per group index (0: a byte region)
349fn a_def r ulong g ulong m ulong to void
350put a_rg r g
351put a_rm r m
352end
353
354note a_words: the words region r takes at group capacity c
355fn a_words r ulong c ulong to ulong
356m = get a_rm r
357if eq m 0
358ret shr add c 7 3
359end
360ret mul c m
361end
362
363note a_move: room in region r for group capacity c. The last region handed out grows in place; any other
364note moves to the top with its words copied, and the words it leaves behind are counted in a_wst. Words
365note past a_top were never handed out and are 0, so new elements start at 0 as a fresh pool's do. No
366note room: error 14 (a_full).
367fn a_move r ulong c ulong to void
368w = a_words r c
369o = get a_rw r
370if le w o
371ret
372end
373b = get a_rb r
374t = get a_top 0
375if eq add b o t
376if gt sub w o sub len a_ar t
377a_full
378end
379put a_top 0 add b w
380put a_rw r w
381ret
382end
383if gt w sub len a_ar t
384a_full
385end
386a_copy t b o
387put a_wst 0 add get a_wst 0 o
388put a_rb r t
389put a_rw r w
390put a_top 0 add t w
391end
392
393note a_copy: words s .. s + n - 1 of the arena to d .. d + n - 1, in ascending order: d above s + n (no
394note overlap, a move to the top) or d below s (a slide down, a_compact)
395fn a_copy d ulong s ulong n ulong to void
396i = ulong 0
397go = true
398while go
399m = ulong 0
400while and go lt m 999999
401if ge i n
402go = false
403else
404put a_ar add d i get a_ar add s i
405i = add i 1
406end
407m = add m 1
408end
409end
410end
411
412note a_need: group g is about to use index n. Call sites outside this module test `if ge n get a_gp g`
413note first: below the highest index asked so far the capacity already holds n, so no call is made. Below its capacity nothing happens; at or above it every
414note region of the group grows to twice the capacity (at least n + 1, at least 64), moving to the top when
415note it is not there already. When the moved copies do not fit in the free words, the arena is compacted
416note (a_compact: the words moved regions left behind are reclaimed) and the group grows in place
417note (a_relayout: everything above its first region slides up), to twice when that fits, else to the
418note largest capacity that does (a_gfit). Before that the arena itself grows (a_grow); the compaction runs
419note only when the host refused. So a table is refused (error 14) only when the host refuses the arena's
420note growth and the live tables with its group grown by one entry no longer fit in the arena as it is.
421note a_gp keeps the highest index asked for, plus 1, for the omc-use record.
422fn a_need g ulong n ulong to void
423if ge n get a_gp g
424put a_gp g add n 1
425end
426c = get a_gc g
427if lt n c
428ret
429end
430c = shl c 1
431if le c n
432c = add n 1
433end
434if lt c 64
435c = ulong 64
436end
437if gt a_gneed g c sub len a_ar get a_top 0
438a_grow a_gneed g c
439end
440cm = ulong 0
441if gt a_gneed g c sub len a_ar get a_top 0
442cm = ulong 1
443end
444if eq a_ok g c add get a_top 0 a_gneed g c 0
445cm = ulong 1
446end
447note under a ceiling a move to the top never raises the high-water (the group grows in place after a compaction),
448note and a group never grows to less than its doubling: then the words handed out follow the same course for
449note every ceiling, and a unit refused at a ceiling is refused at every lower one
450if ne get a_cel 0 0
451if ne get a_rdy 0 0
452if gt add get a_top 0 a_gneed g c get a_hw 0
453cm = ulong 1
454end
455end
456end
457if ne cm 0
458if eq get a_rdy 0 0
459if ne get a_nr 0 1
460a_full
461end
462end
463a_compact
464if ne get a_cel 0 0
465if gt a_gextra g c sub len a_ar get a_top 0
466a_grow a_gextra g c
467end
468if ne get a_rdy 0 0
469if ne a_bad g c 0
470a_full
471end
472end
473end
474if ne a_bad g c 0
475c = a_gfit g n c
476end
477a_relayout g c
478put a_gc g c
479a_hwset
480ret
481end
482r = ulong 0
483while lt r get a_nr 0
484if eq get a_rg r g
485a_move r c
486end
487r = add r 1
488end
489put a_gc g c
490a_hwset
491end
492
493note a_hwset: a_hw follows a_top up. While a_rdin reads the input, region 0 is the only region (a_nr 1): it grows
494note in place, words past the input are handed out but never touched, and how far depends on how the reads were
495note cut (a pipe or a file), so a_hw is not followed then; a_rdin sets it to the words the input holds
496fn a_hwset to void
497if eq get a_nr 0 1
498ret
499end
500if gt get a_top 0 get a_hw 0
501put a_hw 0 get a_top 0
502end
503end
504
505note a_grow: the arena a_ar grows so that w more words are free above a_top: to twice its length, or to a_top
506note + w when that is more (doubling, so the copies a_need makes are linear in the arena's final size). A
507note refusal by the host (enlarge's negative result: -12 when mmap or mremap fails, -22 past 2^63 bytes)
508note leaves a_ar as it was, and a_need goes on to compact. Words past the old length are 0 (a fresh pool's
509note pages), as a_move expects of words above a_top.
510fn a_grow w ulong to void
511t = add get a_top 0 w
512n = shl len a_ar 1
513if lt n t
514n = t
515end
516note under a memory ceiling the arena grows at most to a_capw words; when that is less than the tables need,
517note a_need goes on as after a host refusal (compaction, then error 14 full=1)
518if ne get a_cel 0 0
519c = a_capw 0
520if gt n c
521n = c
522end
523end
524r = enlarge a_ar n
525end
526
527note a_capw: the arena's largest length in words under the ceiling with the output so far: A + A / 128 + 16 MiB + O
528note <= C, A = 8 words, so words <= (C - 16 MiB - O) / 129 * 16 (0 when C does not cover 16 MiB and O)
529fn a_capw z ulong to ulong
530f = add 16777216 a_resv 0 0
531if le get a_cel 0 f
532ret 0
533end
534ret mul div sub get a_cel 0 f 129 16
535end
536
537note a_marg: the margin added to b bytes of arena: b / 128 for the kernel's page tables, 16 MiB for omc's image
538note (docs/RUNTIME-POOLS.md s6, "The margin")
539fn a_marg b ulong to ulong
540ret add add b shr b 7 16777216
541end
542
543note a_resv: the output reserve in bytes: the capacities of group 1 (the artifact) and group 2 (the om2 diag site
544note records written after it), with group g at capacity c. Everything omc writes beyond them is small and
545note inside the margin (diagnostics, the omc-use record)
546fn a_resv g ulong c ulong to ulong
547r = get a_gc 1
548if eq g 1
549r = c
550end
551t = get a_gc 2
552if eq g 2
553t = c
554end
555ret add r t
556end
557
558note a_ok: 1 when group g at capacity c with the words handed out at t keeps the budget under the ceiling: the most
559note words ever handed out (a_hw, or t when higher) in bytes, their margin and the output reserve within C; 1
560note without a ceiling. Every growth keeps it, so the artifact and the site records always fit when written
561fn a_ok g ulong c ulong t ulong to ulong
562if eq get a_cel 0 0
563ret 1
564end
565h = get a_hw 0
566if gt t h
567h = t
568end
569if gt add a_marg shl h 3 a_resv g c get a_cel 0
570ret 0
571end
572ret 1
573end
574
575note a_bad: 1 when group g cannot grow in place to capacity c after a compaction: no room in the arena, or past
576note the budget (a_ok)
577fn a_bad g ulong c ulong to ulong
578x = a_gextra g c
579if gt x sub len a_ar get a_top 0
580ret 1
581end
582if eq a_ok g c add get a_top 0 x 0
583ret 1
584end
585ret 0
586end
587
588note a_ceilo: before the artifact (o bytes) is written: under a ceiling, the most arena words ever handed out
589note (a_hw: the words above it were never handed out and their pages never touched), the margin and o must fit in
590note it (the output grows inside its region without a growth to check), else error 14 full=1 and nothing is written
591fn a_ceilo o ulong to void
592if eq get a_cel 0 0
593ret
594end
595if gt add a_marg shl get a_hw 0 3 o get a_cel 0
596a_full
597end
598end
599
600note a_env: the memory ceiling from the environment (docs/RUNTIME-POOLS.md s6): the first entry named
601note OMC_MEMORY_MAX, read with envcnt / envread into a_eb before the input; an entry that does not fit is error 26
602note D2-GENERATED-BEGIN
603text d2pin "7c3278640c250cb51f0948440c03d4e4ae978311586b38f8c7966168de91eb7b"
604text d2means "1|the compiler's standard input could not be read\n2|the compiler's standard output could not be written\n3|unknown name or field, or a word this mode does not provide\n4|the line ends where a word or value is needed\n5|extra words after a complete statement\n6|malformed number or token\n7|type mismatch\n8|number out of range for its type or place\n9|word or declaration in a place that does not allow it\n10|duplicate name\n11|bare number without a type from its context\n12|register pool exhausted\n13|name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode)\n14|capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound)\n15|missing end\n16|syntax: unknown or misplaced word\n17|line after ret, break, continue, trap or exit in the same block\n18|a function with a result can reach its end\n19|global passed as an argument, or one array twice in a call\n20|write to a view or a text\n21|constant index outside the array\n22|malformed text literal\n23|size capacity\n24|AArch64 branch displacement out of range\n25|unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14)\n26|the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole\n27|fresh element read before it is definitely written, or fresh array passed on\n28|abstract type: seal outside its constructor, or an unsupported holds\n29|external layout out of bounds or misplaced\n30|contract syntax misplaced or not supported here (IR mode included)\n"
605text d2sites "1|a_env: the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole; condition if lt kl 0\n2|a_envv: the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole; condition if gt sub k 15 19\n3|a_envv: the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole; condition if or lt c 48 gt c 57\n4|a_envv: the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole; condition if gt v 922337203685477580\n5|a_envv: the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole; condition if ge v 9223372036854775808\n6|a_full: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound)\n7|a_rdin: the compiler's standard input could not be read; condition if lt n 0\n623|mflush: standard output refused a diagnostic or query chunk\n8|emit: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xtarget 0 0\n9|a_ogrow: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge o lim\n10|tok_num: malformed number or token; condition if eq ndig 0\n11|tok_num: malformed number or token; condition if gt ndig 20\n12|tok_num: malformed number or token; condition if gt d 9\n13|tok_num: number out of range for its type or place; condition if gt v lim\n14|tok_num: number out of range for its type or place; condition if and eq v lim gt d 5\n15|tok_num: number out of range for its type or place; condition if gt v half\n16|tok_text: malformed text literal; condition if ge get cur 0 get inlen 0\n17|tok_text: malformed text literal; condition if eq b 10\n18|tok_text: malformed text literal; condition if ge get cur 0 get inlen 0\n19|tok_text: malformed text literal; condition if eq a_ib get cur 0 10\n20|tok_text: malformed text literal; condition if gt a_ib get cur 0 32\n21|tok: syntax: unknown or misplaced word; condition if lt c 32\n22|fmttail: malformed number or token; condition if bad\n23|fmtprep: syntax: unknown or misplaced word; condition if ne get om2pos 0 0\n24|fmtprep: malformed number or token; condition if eq b 13\n25|fmtprep: syntax: unknown or misplaced word; condition if eq get om2m 0 2\n26|tok_hex: malformed number or token; condition if or eq c 120 eq c 88\n27|tok_hex: malformed number or token; condition if eq c 88\n28|tok_hex: malformed number or token; condition if eq n 0\n29|tok_hex: malformed number or token; condition if gt n 16\n30|tok_hex: malformed number or token; condition otherwise: if and ge d 97 le d 102\n31|fparse: number out of range for its type or place; condition if gt get fnd 0 922337203685477580\n32|fparse: number out of range for its type or place; condition if gt d 7\n33|fparse: malformed number or token; condition if and ne get fg_seen 0 0 eq get fg_fl 0 0\n34|fparse: malformed number or token; condition if ne p e\n35|fexp: number out of range for its type or place; condition if gt get fg_ex 0 999\n36|fexp: malformed number or token; condition if eq get fg_ed 0 0\n37|fsufx: malformed number or token; condition if ne r 3\n38|fsufx: malformed number or token; condition if ne uchar and shr get a_ar shr p 3 shl and p 7 3 255 102\n39|fsufx: malformed number or token; condition otherwise: if and eq a_ib add p 1 54 eq a_ib add p 2 52\n40|fpack: number out of range for its type or place; condition if ge E maxe\n41|fbits: number out of range for its type or place; condition if gt p 308\n42|fsizeof: type mismatch; condition if ge t 64\n43|foffset: syntax: unknown or misplaced word; condition if ne get tk 0 1\n44|foffset: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n45|foffset: unknown name or field, or a word this mode does not provide; condition if eq sid 0\n46|foffset: syntax: unknown or misplaced word; condition if ne get tk 0 1\n47|foffset: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n48|foffset: unknown name or field, or a word this mode does not provide; condition if eq f 0\n49|newname: syntax: unknown or misplaced word; condition if ne kwx w 0\n50|newname: duplicate name; condition if ne findstruct w 0\n51|newname: duplicate name; condition if ne findname w 0\n52|newname: duplicate name; condition if ne findlay w 0\n53|newname: duplicate name; condition if ne findab w 0\n54|newname: duplicate name; condition if ne findfn w l s 0\n55|addname: syntax: unknown or misplaced word; condition if ne kwx w 0\n56|alloc: register pool exhausted; condition if ge i 16\n57|bdisp: AArch64 branch displacement out of range; condition if ne and diff 3 0\n58|bdisp: AArch64 branch displacement out of range; condition if and gt diff sub span 4 lt diff sub ulong 0 span\n59|range: number out of range for its type or place; condition if ne big 0\n60|range: number out of range for its type or place; condition if ne shr v 63 0\n61|range: number out of range for its type or place; condition if ne big 0\n62|range: number out of range for its type or place; condition if ge v lim\n63|range: number out of range for its type or place; condition if ge add v half lim\n64|force: bare number without a type from its context\n65|elemtype: word or declaration in a place that does not allow it; condition if lt t 2\n66|elemtype: type mismatch; condition if ge t 64\n67|arrlen: size capacity; condition if ne get tbig 0 0\n68|arrlen: number out of range for its type or place; condition if or eq v 0 ne shr v 63 0\n69|arrlen: size capacity; condition if gt v 16777216\n70|lenval: line ended before the required array expression; condition if eq k 0\n71|lenval: syntax: unknown or misplaced word; condition if ge t 10\n72|lenval: syntax: unknown or misplaced word\n73|typeword: the line ends where a word or value is needed; condition if eq k 0\n74|typeword: syntax: unknown or misplaced word; condition if ne k 1\n75|typeword: syntax: unknown or misplaced word; condition if gt get tl 0 8\n76|typeword: syntax: unknown or misplaced word; condition if eq c 0\n77|typeword: word or declaration in a place that does not allow it; condition if eq c 76\n78|typeword: word or declaration in a place that does not allow it; condition if ne get irmode 0 0\n79|typeword: syntax: unknown or misplaced word; condition if gt sub c 1 8\n80|eol: extra words after a complete statement; condition if and ne k 0 ne k 3\n81|arrname: the line ends where a word or value is needed; condition if eq k 0\n82|arrname: the line ends where a word or value is needed; condition if eq k 3\n83|arrname: syntax: unknown or misplaced word; condition if ne k 1\n84|arrname: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n85|arrname: word or declaration in a place that does not allow it; condition if eq kw get tw 0 193\n86|arrname: unknown name or field, or a word this mode does not provide; condition if eq e 0\n87|arrname: type mismatch; condition if eq k 0\n88|arrname: type mismatch; condition if eq pk 0\n89|topname: syntax: unknown or misplaced word; condition if ne get tk 0 1\n90|topname: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n91|topname: syntax: unknown or misplaced word; condition if ne kw w 0\n92|xfconv: word or declaration in a place that does not allow it; condition if or eq ft 1 eq tt 1\n93|xfconv: type mismatch; condition if or eq ft 13 eq tt 13\n94|xfbinop: type mismatch; condition if or or lt op 33 gt op 36 ge op 41\n95|fintr: word or declaration in a place that does not allow it; condition if ne get irmode 0 0\n96|fintr: type mismatch; condition if eq get rk 0 2\n97|fintr: bare number without a type from its context; condition if eq get rk 0 6\n98|fintr: type mismatch; condition if eq isfloat t 0\n99|fminmax: word or declaration in a place that does not allow it; condition if ne get irmode 0 0\n100|fminmax: bare number without a type from its context; condition if or eq get rk 0 2 eq get rk 0 6\n101|fminmax: bare number without a type from its context; condition if or eq get rk 0 2 eq get rk 0 6\n102|fminmax: type mismatch; condition if or eq isfloat at 0 eq isfloat get rt 0 0\n103|fminmax: type mismatch; condition if ne at get rt 0\n104|ffma: bare number without a type from its context; condition if eq get rk 0 6\n105|ffma: type mismatch; condition if eq isfloat at 0\n106|ffma: bare number without a type from its context; condition if eq get rk 0 6\n107|ffma: type mismatch; condition if ne get rt 0 at\n108|ffma: bare number without a type from its context; condition if eq get rk 0 6\n109|ffma: type mismatch; condition if ne get rt 0 at\n110|ffma: word or declaration in a place that does not allow it; condition if or ne get irmode 0 0 ne get xtarget 0 0\n111|fp_conv: word or declaration in a place that does not allow it; condition if eq ft 1\n112|fp_conv: word or declaration in a place that does not allow it; condition if eq tt 1\n113|binrot: type mismatch; condition if or lt ty 2 gt ty 5\n114|binop: type mismatch; condition if or or lt op 33 gt op 36 ge op 41\n115|binop: type mismatch; condition if and ge op 38 le op 42\n116|binop: type mismatch; condition if gt sub op 38 2\n117|elemaddr: type mismatch; condition if or or eq t 1 eq t 10 eq t 11\n118|elemaddr: constant index outside the array; condition if ge v ln\n119|aa_word: the line ends where a word or value is needed; condition if eq k 0\n120|aa_word: syntax: unknown or misplaced word; condition if ne k 1\n121|aa_word: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n122|arrarg: syntax: unknown or misplaced word; condition if or lt c 57 gt c 58\n123|arrarg: unknown name or field, or a word this mode does not provide; condition if eq e 0\n124|arrarg: type mismatch; condition if eq k 0\n125|arrarg: global passed as an argument, or one array twice in a call; condition if eq k 10\n126|arrarg: type mismatch; condition if ge k 6\n127|arrarg: global passed as an argument, or one array twice in a call; condition if eq k 4\n128|arrarg: write to a view or a text; condition if eq md 57\n129|arrarg: write to a view or a text; condition if and ne k 1 ne k 3\n130|arrarg: type mismatch; condition if eq md 58\n131|arrarg: type mismatch; condition if ne a_gu 5 i a_gu 35 p\n132|arrarg: type mismatch; condition if ne a_g 6 i a_g 36 p\n133|arrpart: global passed as an argument, or one array twice in a call; condition if eq k 10\n134|arrpart: type mismatch; condition if ge k 6\n135|arrpart: global passed as an argument, or one array twice in a call; condition if eq k 4\n136|arrpart: write to a view or a text; condition if eq md 57\n137|arrpart: write to a view or a text; condition if and ne k 1 ne k 3\n138|arrpart: type mismatch; condition if eq md 58\n139|arrpart: type mismatch; condition if ne ulong a_gu 5 i ulong a_gu 35 p\n140|arrpart: type mismatch; condition if ne get a_ar add get a_rb 36 p 0\n141|arrpart: type mismatch; condition if and ne k 5 ne k 13\n142|arrpart: type mismatch; condition if and ne k 5 ne k 13\n143|vdec: contract syntax misplaced or not supported here (IR mode included); condition if and ne get cpure 0 0 ge get rt 0 10\n144|vt_un: type mismatch; condition if eq c 50\n145|vt_un: type mismatch; condition if eq ty 13\n146|vt_un: type mismatch; condition if or eq ty 1 eq ty 13\n147|vt_conv: type mismatch; condition if or eq ft 13 eq tt 13\n148|vt_conv: word or declaration in a place that does not allow it; condition if eq ft 1\n149|vt_conv: word or declaration in a place that does not allow it; condition if eq tt 1\n150|vt_conv: word or declaration in a place that does not allow it; condition if eq ft 1\n151|vt_conv: word or declaration in a place that does not allow it; condition if eq tt 1\n152|vs_chk: type mismatch; condition if ne uchar get a_ar add get a_rb 5 sub e 1 2\n153|vs_chk: type mismatch; condition if ne uchar get a_ar add get a_rb 5 sub e 1 2\n154|vs_call: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xefa 0 0\n155|ca_scal: type mismatch; condition if ne get rt 0 ulong uchar get a_ar add get a_rb 35 p\n156|ca_arr: global passed as an argument, or one array twice in a call; condition if eq a_g 77 add add cb mul j 3 2 get rt 0\n157|vs_fd: type mismatch; condition if ne get rt 0 8\n158|vs_arr: type mismatch; condition if ne uchar get a_ar add get a_rb 7 sub e 1 10\n159|vs_arr: write to a view or a text; condition if or eq k 2 eq k 5\n160|vs_off: type mismatch; condition if ne get rt 0 5\n161|vs_end: type mismatch; condition if ne get rt 0 5\n162|harg: type mismatch; condition if ne get rt 0 ty\n163|hscalar: size capacity; condition if gt fdpool 1073739776\n164|harray: type mismatch; condition if ne uchar get a_ar add get a_rb 5 sub e 1 2\n165|mtinit: size capacity; condition if gt p 1073737728\n166|mnew: word or declaration in a place that does not allow it; condition if or ne a_g 77 add x 14 3 ne a_g 77 add x 16 3\n167|mnew: word or declaration in a place that does not allow it; condition if and ne acc 1 ne acc 3\n168|mnew: word or declaration in a place that does not allow it; condition if and and and ne mode 1 ne mode 2 ne mode 33 ne mode 34\n169|mbind: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 14 3\n170|mbind: word or declaration in a place that does not allow it; condition if and ne acc 1 ne acc 3\n171|hdevcall: global passed as an argument, or one array twice in a call; condition if eq e f\n172|mmapio: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 12 3\n173|mmapio: word or declaration in a place that does not allow it; condition if and ne w 4 ne w 8\n624|ksize: KFD request is not in the checked request allowlist\n625|kctl: KFD request must be a literal\n626|kctl: literal KFD header length differs from the request ABI size\n627|kctl: KFD header and pointed-to span must be distinct arrays\n174|hostval: word or declaration in a place that does not allow it; condition if and ne get objmode 0 0 and ge c 166 le c 177\n175|hostval: word or declaration in a place that does not allow it; condition if eq get progmode 0 0\n176|hostval: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if and ge c 228 le c 232\n177|hostval: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xtarget 0 0\n178|hostval: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xefa 0 0\n179|hostval: word or declaration in a place that does not allow it; condition if eq get om2 0 0\n180|hostval: word or declaration in a place that does not allow it; condition if eq ok 0\n181|hostval: size capacity; condition if gt fdpool 1073739776\n182|hostval: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 12 3\n183|hostval: word or declaration in a place that does not allow it; condition if eq n 99\n184|hostval: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 12 3\n185|hostval: word or declaration in a place that does not allow it; condition if and ne q 15213 ne q 15214\n186|rdval: contract syntax misplaced or not supported here (IR mode included); condition if ne get cpure 0 0\n187|rdval: word or declaration in a place that does not allow it; condition if eq get curfn 0 fe\n188|rdval: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if gt get depth 0 32768\n189|rdval: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3\n190|rdval: syntax: unknown or misplaced word; condition if eq get tk 0 4\n191|rdval: word or declaration in a place that does not allow it; condition if ne get irmode 0 0\n192|rdval: type mismatch; condition if ge exp 64\n193|rdval: type mismatch; condition if eq isfloat exp 0\n194|rdval: type mismatch; condition if and ne exp 0 ne exp t\n195|rdval: type mismatch; condition if or ge exp 64 ne isfloat exp 0\n196|rdval: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n197|rdval: type mismatch; condition if eq uchar get a_ar add get a_rb 23 sub f 1 12\n198|rdval: contract syntax misplaced or not supported here (IR mode included); condition if eq get crkind 0 0\n199|rdval: type mismatch; condition if ne uchar get a_ar add get a_rb 7 sub e 1 0\n200|rdval: contract syntax misplaced or not supported here (IR mode included); condition if ge get rt 0 10\n201|rdval: unknown name or field, or a word this mode does not provide; condition if eq f 0\n202|rdval: type mismatch; condition if eq uchar get a_ar add get a_rb 23 sub f 1 12\n203|rdval: type mismatch; condition if ge get rt 0 64\n204|rdval: type mismatch; condition if eq get rt 0 1\n205|rdval: word or declaration in a place that does not allow it; condition if ne get irmode 0 0\n206|rdval: bare number without a type from its context; condition if or eq get rk 0 6 eq get rk 0 2\n207|rdval: type mismatch; condition if eq ft 1\n208|rdval: type mismatch; condition if or ge ft 64 ge tt 64\n209|rdval: type mismatch; condition if ne twid ft twid tt\n210|rdval: type mismatch; condition if ge get rt 0 64\n211|rdval: bare number without a type from its context; condition if eq get rk 0 2\n212|rdval: type mismatch; condition if eq get rk 0 6\n213|rdval: type mismatch; condition if ge get rt 0 64\n214|rdval: bare number without a type from its context; condition if eq get rk 0 2\n215|rdval: syntax: unknown or misplaced word; condition if ne get tk 0 1\n216|rdval: syntax: unknown or misplaced word; condition if gt get tl 0 8\n217|rdval: syntax: unknown or misplaced word; condition if ne kw get tw 0 75\n218|rdval: word or declaration in a place that does not allow it; condition if or eq c 77 eq c 193\n219|rdval: word or declaration in a place that does not allow it; condition if or eq get progmode 0 0 ne get irmode 0 0\n220|rdval: type mismatch; condition if ge uchar get a_ar add get a_rb 7 sub e 1 6\n222|rdval: word or declaration in a place that does not allow it; condition if eq c 244\n223|rdval: syntax: unknown or misplaced word; condition if and gt sub c 33 17 gt sub c 59 1\n224|rdval: type mismatch; condition if ge get rt 0 64\n225|rdval: bare number without a type from its context; condition if eq get rk 0 2\n226|rdval: bare number without a type from its context; condition if and eq ak 6 eq bk 6\n227|rdval: bare number without a type from its context; condition if eq bt 0\n228|rdval: type mismatch; condition if eq isfloat bt 0\n229|rdval: bare number without a type from its context; condition if eq at 0\n230|rdval: type mismatch; condition if eq isfloat at 0\n231|rdval: type mismatch; condition if or eq ak 2 eq ak 3\n232|rdval: type mismatch; condition if or eq bk 2 eq bk 3\n233|rdval: type mismatch; condition if or eq ak 6 eq bk 6\n234|rdval: bare number without a type from its context; condition if eq bk 2\n235|rdval: type mismatch; condition if ne at bt\n236|cond: type mismatch; condition if ne get rt 0 1\n237|cond: type mismatch; condition if ne get rt 0 1\n238|sa_arr: word or declaration in a place that does not allow it; condition if ne get nb 0 0\n239|sa_arr: size capacity; condition if gt s 4194304\n240|sa_arr: type mismatch; condition if ne get rt 0 t\n241|s_assign: type mismatch; condition if ne uchar get a_ar add get a_rb 7 i 0\n242|s_assign: type mismatch; condition if ne get rt 0 t\n243|s_assign: type mismatch; condition if ne get rt 0 t\n244|s_assign: duplicate name; condition if ne findfn w 0 0 0\n245|s_assign: bare number without a type from its context; condition if eq get rk 0 2\n246|s_enlarge: type mismatch; condition if ne uchar get a_ar add get a_rb 7 i 0\n247|s_enlarge: type mismatch; condition if ne uchar get a_ar add get a_rb 5 i 9\n248|s_enlarge: duplicate name; condition if ne findfn w 0 0 0\n249|s_enlarge: type mismatch; condition if ne uchar get a_ar add get a_rb 7 sub p 1 10\n250|s_enlarge: bare number without a type from its context; condition if eq get rk 0 2\n251|s_enlarge: type mismatch; condition if ne get rt 0 5\n252|s_name: type mismatch; condition if ne uchar get a_ar add get a_rb 23 sub f 1 12\n253|fn_p: syntax: unknown or misplaced word; condition if ne get tk 0 1\n254|fn_p: syntax: unknown or misplaced word; condition if gt get tl 0 8\n255|fn_to: the line ends where a word or value is needed; condition if eq get tk 0 0\n256|fn_to: syntax: unknown or misplaced word; condition if ne get tk 0 1\n257|fn_to: syntax: unknown or misplaced word; condition if gt get tl 0 8\n258|s_fn: missing end; condition if ne get curret 0 0\n259|s_fn: syntax: unknown or misplaced word; condition if ne get tk 0 1\n260|s_fn: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n261|s_fn: syntax: unknown or misplaced word; condition if eq get tl 0 6\n262|s_fn: syntax: unknown or misplaced word; condition if ne kw w 0\n263|s_fn: the line ends where a word or value is needed; condition if eq get tk 0 0\n264|s_fn: syntax: unknown or misplaced word; condition if ne get tk 0 1\n265|s_fn: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n266|s_fn: syntax: unknown or misplaced word; condition if ne c 0\n267|s_fn: word or declaration in a place that does not allow it; condition if ge get psl 0 6\n268|s_fn: word or declaration in a place that does not allow it; condition if gt get psl 0 6\n269|s_ret: type mismatch; condition if ne get rt 0 r\n270|s_break: word or declaration in a place that does not allow it; condition if eq found 0\n271|s_break: word or declaration in a place that does not allow it; condition if ge get a_ar add get a_rb 49 bi 5\n272|s_cont: word or declaration in a place that does not allow it; condition if eq found 0\n273|s_cont: word or declaration in a place that does not allow it; condition if ge get a_ar add get a_rb 49 bi 5\n274|s_put: write to a view or a text; condition if or eq k 2 eq k 5\n275|s_put: type mismatch; condition if ne get rt 0 t\n276|s_const: syntax: unknown or misplaced word; condition if ne get tk 0 1\n277|s_const: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n278|s_const: syntax: unknown or misplaced word; condition if ne kw w 0\n279|s_const: type mismatch; condition if ge t 64\n280|s_const: syntax: unknown or misplaced word; condition if ne get rk 0 6\n281|s_const: the line ends where a word or value is needed; condition if eq get tk 0 0\n282|s_const: type mismatch; condition if eq get tk 0 5\n283|s_const: syntax: unknown or misplaced word; condition if ne get tk 0 2\n284|s_global: size capacity; condition if gt s 1073741824\n285|sg_pool: word or declaration in a place that does not allow it; condition if eq get progmode 0 0\n286|sg_pool: word or declaration in a place that does not allow it; condition if ne get irmode 0 0\n287|sg_pool: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if gt get xtarget 0 1\n288|sg_pool: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xefa 0 0\n289|sg_pool: size capacity; condition if gt s 1073741824\n290|s_text: syntax: unknown or misplaced word; condition if ne get tk 0 4\n291|s_text: malformed text literal; condition if and ne b 92 ne b 34\n292|s_else: missing end; condition if eq n 0\n293|s_else: missing end; condition if ne get a_ar add get a_rb 49 i 1\n294|s_while: extra words after a complete statement; condition if ne k 1\n295|s_while: extra words after a complete statement; condition if gt get tl 0 8\n296|s_while: extra words after a complete statement; condition if ne kw get tw 0 70\n297|s_while: number out of range for its type or place; condition if ge sub v 1 9223372036854775807\n298|sf_num: number out of range for its type or place; condition if ge sub bn 1 9223372036854775807\n299|sf_val: number out of range for its type or place; condition if ge sub n 1 9223372036854775807\n300|s_for: the line ends where a word or value is needed; condition if eq get tk 0 0\n301|s_for: syntax: unknown or misplaced word; condition if ne get tk 0 1\n302|s_for: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n303|s_for: syntax: unknown or misplaced word; condition if ne kw w 0\n304|s_for: type mismatch; condition if or eq t 1 ge t 10\n305|s_for: the line ends where a word or value is needed; condition if eq get tk 0 0\n306|s_for: type mismatch; condition if ne get rt 0 t\n307|s_for: syntax: unknown or misplaced word; condition if eq peekw 181\n308|s_unroll: number out of range for its type or place; condition if or eq kk 0 gt kk 64\n309|fuelc: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if gt add get fuel 0 n 65536\n310|fn_tail: extra words after a complete statement; condition if and ne k 0 ne k 3\n311|inl_body: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge lv 4\n312|inl_body: word or declaration in a place that does not allow it; condition if eq get curfn 0 fe\n313|inl_body: word or declaration in a place that does not allow it; condition if eq get il_fn j fe\n314|inl_run: missing end; condition if ne stmt 0\n315|s_iret: type mismatch; condition if ne get rt 0 r\n316|s_iret: type mismatch; condition if ne get rt 0 r\n317|s_inlx: a function with a result can reach its end; condition if ne uchar get a_ar add get a_rb 23 sub fe 1 12\n318|finish: a function with a result can reach its end; condition if ne get curret 0 12\n628|finish: word or declaration in a place that does not allow it; condition if or ne get osbad 0 0 ne get osp 0 0\n319|writeout: the compiler's standard output could not be written; condition if eq a_out 1 1 st get oc 0 0\n320|eof_prog: syntax: unknown or misplaced word; condition if eq f 0\n321|eof_prog: word or declaration in a place that does not allow it; condition if ne uchar get a_ar add get a_rb 24 sub f 1 0\n322|kunset: word or declaration in a place that does not allow it; condition if eq uchar get a_ar add get a_rb 30 f 0\n323|s_eof: missing end; condition if ne get curret 0 0\n324|s_eof: syntax: unknown or misplaced word; condition if eq get nf 0 0\n325|s_eof: word or declaration in a place that does not allow it; condition if ne reachself f 0\n326|s_eof: word or declaration in a place that does not allow it; condition if ne uchar get a_ar add get a_rb 7 i 9\n327|stmt: syntax: unknown or misplaced word; condition if ne k 1\n328|stmt: contract syntax misplaced or not supported here (IR mode included); condition if ne cp_kind 0\n329|stmt: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if eq get curret 0 0\n330|stmt: line after ret, break, continue, trap or exit in the same block; condition if ne get dead 0 0\n331|stmt: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n332|stmt: type mismatch; condition if ne uchar get a_ar add get a_rb 23 sub f 1 12\n333|stmt: syntax: unknown or misplaced word; condition if eq get curret 0 0\n334|stmt: line after ret, break, continue, trap or exit in the same block; condition if ne get dead 0 0\n336|stmt: type mismatch; condition if ne get rt 0 8\n337|stmt: number out of range for its type or place; condition if or lt v 1 gt v 14\n338|stmt: word or declaration in a place that does not allow it; condition if ne get objmode 0 0\n339|stmt: word or declaration in a place that does not allow it; condition if ne get objmode 0 0\n340|stmt: word or declaration in a place that does not allow it; condition if or or or eq c 77 eq c 78 eq c 79 eq c 81\n341|stmt: word or declaration in a place that does not allow it; condition if or eq c 85 eq c 193\n342|stmt: syntax: unknown or misplaced word\n343|s_field: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n344|s_field: syntax: unknown or misplaced word; condition if ne kw get tw 0 0\n345|s_field: duplicate name; condition if eq fw w\n346|s_field: duplicate name; condition if ne findstruct fw 0\n347|s_field: duplicate name; condition if ne field_dup fo fw 0\n348|s_field: type mismatch; condition if ge t 64\n349|s_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ne get tbig 0 0\n350|s_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if or eq ln 0 gt ln 64\n351|s_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge ct 10\n352|s_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if or eq ln 0 gt ln 64\n353|s_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if gt add cells addc 64\n354|s_struct: word or declaration in a place that does not allow it; condition if ne get nf 0 0\n355|s_struct: syntax: unknown or misplaced word; condition if ne get tk 0 1\n356|s_struct: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n357|s_struct: syntax: unknown or misplaced word; condition if ne kw get tw 0 0\n358|s_struct: duplicate name; condition if ne findstruct w 0\n359|s_struct: duplicate name; condition if ne findfn w get tl 0 get ts 0 0\n360|s_struct: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge get nst 0 16\n361|s_struct: the line ends where a word or value is needed; condition if eq get tk 0 0\n362|s_struct: syntax: unknown or misplaced word; condition if ne get tk 0 1\n363|s_struct: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge nfld 16\n364|s_struct: syntax: unknown or misplaced word; condition if eq nfld 0\n365|sa_new: word or declaration in a place that does not allow it; condition if ne get inl 0 0\n366|sa_new: word or declaration in a place that does not allow it; condition if ne uchar get a_ar add get a_rb 27 sub get curfn 0 1 0\n367|st_read: type mismatch; condition if ne get rt 0 ft\n368|sa_st: word or declaration in a place that does not allow it; condition if ne get nb 0 0\n369|sa_st: size capacity; condition if gt s 4194304\n370|abty: syntax: unknown or misplaced word; condition if eq a 0\n371|s_abstract: word or declaration in a place that does not allow it; condition if ne get nf 0 0\n372|s_abstract: syntax: unknown or misplaced word; condition if ne get tk 0 1\n373|s_abstract: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 8\n374|s_abstract: syntax: unknown or misplaced word; condition if ne kw w 0\n375|s_abstract: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 16\n376|s_abstract: type mismatch; condition if and ne t 4 ne t 5\n377|s_abstract: extra words after a complete statement; condition if or gt get tl 0 8 ne kw get tw 0 196\n378|s_abstract: syntax: unknown or misplaced word; condition if or ne k 1 gt get tl 0 8\n379|s_abstract: syntax: unknown or misplaced word; condition if eq b 0\n380|s_abstract: extra words after a complete statement; condition if and ne get tk 0 0 ne get tk 0 3\n381|ab_entry: type mismatch; condition if ge uchar get a_ar add get a_rb 23 f 64\n382|ab_entry: type mismatch; condition if ge uchar get a_ar add get a_rb 35 add mul f 6 i 64\n383|ab_open: type mismatch; condition if lt t 64\n384|ab_seal: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3\n385|ab_seal: syntax: unknown or misplaced word; condition if eq a 0\n386|ab_seal: abstract type: seal outside its constructor, or an unsupported holds; condition if eq ab_ctor fe a 0\n387|ab_seal: type mismatch; condition if ne get rt 0 t\n388|ab_bin: type mismatch; condition if lt at 64\n389|ab_bin: type mismatch; condition if eq b 0\n390|ab_bin: type mismatch; condition if eq and get ab_ops a b 0\n391|ab_bin: type mismatch; condition if ne bt t\n392|ab_bin: type mismatch; condition if ne bt at\n393|fz_par: syntax: unknown or misplaced word; condition if ne k 3\n394|fz_par: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if gt ln 64\n395|fz_new: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge s 16\n396|fz_get: fresh element read before it is definitely written, or fresh array passed on; condition if eq and shr get fz_cur s v 1 0\n397|fz_get: fresh element read before it is definitely written, or fresh array passed on; condition if ne get fz_cur s fmask n\n398|fz_arg: fresh element read before it is definitely written, or fresh array passed on; condition if ne uchar get a_ar add get a_rb 13 sub e 1 0\n399|ns_om2: word or declaration in a place that does not allow it; condition if ne get nf 0 0\n400|ns_om2: syntax: unknown or misplaced word; condition if ne get tk 0 1\n401|ns_om2: syntax: unknown or misplaced word; condition if eq a 0\n402|ns_om2: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3\n403|ns_om2: abstract type: seal outside its constructor, or an unsupported holds; condition if ne get tk 0 1\n404|ns_om2: abstract type: seal outside its constructor, or an unsupported holds; condition if or ne get tl 0 5 ne get tw 0 215611372900\n405|ns_om2: abstract type: seal outside its constructor, or an unsupported holds; condition if ne get ab_base a 5\n406|ns_om2: duplicate name; condition if ne get ab_holds a 0\n407|s_export: syntax: unknown or misplaced word; condition if or ne get tk 0 1 ne get tw 0 28262\n408|s_export: word or declaration in a place that does not allow it; condition if ne get progmode 0 0\n409|s_export: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge get nexp 0 32\n410|ly_num: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3\n411|ly_num: syntax: unknown or misplaced word; condition if ne get tk 0 2\n412|ly_num: external layout out of bounds or misplaced; condition if ne get tbig 0 0\n413|s_layout: external layout out of bounds or misplaced; condition if ne get nf 0 0\n414|s_layout: syntax: unknown or misplaced word; condition if ne get tk 0 1\n415|s_layout: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 8\n416|s_layout: syntax: unknown or misplaced word; condition if ne kw w 0\n417|s_layout: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge get nly 0 16\n418|s_layout: external layout out of bounds or misplaced; condition if or eq sz 0 gt sz 4096\n419|s_layout: the line ends where a word or value is needed; condition if eq k 3\n420|s_layout: syntax: unknown or misplaced word; condition if ne c 189\n421|s_layout: syntax: unknown or misplaced word; condition if ne k 0\n422|ly_field: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3\n423|ly_field: syntax: unknown or misplaced word; condition if ne get tk 0 1\n424|ly_field: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 8\n425|ly_field: syntax: unknown or misplaced word; condition if ne kw fw 0\n426|ly_field: duplicate name; condition if eq get lf_name i fw\n427|ly_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 256\n428|ly_field: type mismatch; condition if or lt t 2 gt t 9\n429|ly_field: external layout out of bounds or misplaced; condition if ne get tbig 0 0\n430|ly_field: external layout out of bounds or misplaced; condition if or eq cnt 0 gt cnt 4096\n431|ly_field: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3\n432|ly_field: syntax: unknown or misplaced word; condition if ne get tk 0 1\n433|ly_field: syntax: unknown or misplaced word; condition if ne kw get tw 0 190\n434|ly_end: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3\n435|ly_end: syntax: unknown or misplaced word; condition if ne get tk 0 1\n436|ly_end: syntax: unknown or misplaced word\n437|ly_mark: external layout out of bounds or misplaced; condition if gt off sz\n438|ly_mark: external layout out of bounds or misplaced; condition if gt e sz\n439|ly_mark: external layout out of bounds or misplaced; condition if ne get lymap i 0\n440|ly_ix: type mismatch; condition if or eq t 1 ge t 10\n441|ly_ix: constant index outside the array; condition if ge v cnt\n442|ly_st: type mismatch; condition if ne get rt 0 ft\n443|vt_fget_go: type mismatch; condition if eq get rt 0 1\n444|vt_fget_go: constant index outside the array; condition if ge get rv 0 fl\n445|vt_fget_go: type mismatch; condition if ne get rk 0 1\n446|vt_fget: syntax: unknown or misplaced word; condition if ne get tk 0 1\n447|vt_fget: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n448|vt_fget: unknown name or field, or a word this mode does not provide; condition if eq fid 0\n449|s_putf_go: type mismatch; condition if eq get rt 0 1\n450|s_putf_go: type mismatch; condition if ne get rt 0 ft\n451|s_putf: write to a view or a text; condition if eq ulong uchar get a_ar add get a_rb 7 i 8\n452|s_putf: syntax: unknown or misplaced word; condition if ne get tk 0 1\n453|s_putf: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n454|s_putf: unknown name or field, or a word this mode does not provide; condition if eq fid 0\n455|s_putf_ix: type mismatch; condition if eq get svt 0 1\n456|s_putf_ix: constant index outside the array; condition if ge iv fl\n457|s_putf_ix: type mismatch; condition if ne ik 1\n458|ca_st_ok: syntax: unknown or misplaced word; condition if or lt c 57 gt c 58\n459|ca_st_ok: unknown name or field, or a word this mode does not provide; condition if eq e 0\n460|ca_st_ok: type mismatch; condition if eq k 10\n461|ca_st_ok: type mismatch; condition if lt k 6\n462|ca_st_ok: write to a view or a text; condition if eq md 57\n463|ca_st_ok: write to a view or a text; condition if eq k 8\n464|ca_st_ok: type mismatch; condition if eq md 58\n465|ca_st_ok: type mismatch; condition if ne ulong a_gu 5 ni ulong a_gu 35 p\n466|ca_st: global passed as an argument, or one array twice in a call; condition if eq a_g 77 add add cb mul j 3 2 e\n467|ir_newreg: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge r 64\n468|ir_block: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge b 32\n469|ir_op: line after ret, break, continue, trap or exit in the same block; condition if ne get ir_dead 0 0\n470|ir_op: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 256\n471|ir_lit: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 32\n472|ir_bind: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 32\n473|ir_newname: syntax: unknown or misplaced word; condition if ne kw w 0\n474|ir_newname: duplicate name; condition if ne findname w 0\n475|ir_newname: duplicate name; condition if ne ir_find w l 0\n476|ir_newname: duplicate name; condition if ne ir_nameeq j 0\n477|ir_newloc: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt l 8\n478|ir_type: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3\n479|ir_type: syntax: unknown or misplaced word; condition if ne get tk 0 1\n480|ir_type: word or declaration in a place that does not allow it; condition if or or eq c 76 eq c 88 eq c 89\n481|ir_type: word or declaration in a place that does not allow it; condition if or eq c 57 eq c 58\n482|ir_type: syntax: unknown or misplaced word\n483|ir_push: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 8\n484|ir_emit_record: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge get irnf 0 32\n485|ir_callop: line after ret, break, continue, trap or exit in the same block; condition if ne get ir_dead 0 0\n486|ir_callop: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 256\n487|ir_name: word or declaration in a place that does not allow it; condition if ge t 10\n488|ir_un: bare number without a type from its context; condition if ne get ir_isb 0 0\n489|ir_un: type mismatch; condition if and eq c 49 eq ty 1\n490|ir_bin_done: type mismatch; condition if or ge lty 10 eq lty 1\n491|ir_bin_done: type mismatch; condition if or ge ty2 10 eq ty2 1\n492|ir_bin_done: type mismatch; condition if ge lty 10\n493|ir_bin_done: type mismatch; condition if and eq isb2 0 ne ty2 lty\n494|ir_bin_done: type mismatch; condition if and and ge c 33 le c 37 eq lty 1\n495|ir_bin: bare number without a type from its context; condition if ne get ir_isb 0 0\n496|ir_cast: word or declaration in a place that does not allow it; condition if xor eq sty 1 eq c 1\n497|ir_val: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if gt get irdep 0 32768\n498|ir_valb: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3\n499|ir_valb: word or declaration in a place that does not allow it; condition if or eq get tk 0 4 eq get tk 0 5\n500|ir_valb: type mismatch; condition if and ne exp 0 ne get ir_vt 0 exp\n501|ir_valb: type mismatch; condition if and ne exp 0 ne get ir_vt 0 exp\n502|ir_valb: type mismatch; condition if and ne exp 0 ne exp 1\n503|ir_valb: type mismatch; condition if and ne exp 0 ne exp 1\n504|ir_valb: unknown name or field, or a word this mode does not provide; condition if eq f 0\n505|ir_valb: type mismatch; condition if eq rtv 76\n506|ir_valb: type mismatch; condition if ne get ir_vt 0 ty\n507|ir_end: a function with a result can reach its end; condition if ne get ir_ret 0 76\n508|ir_bound: extra words after a complete statement; condition if or ne get tk 0 1 ne ir_kwt 70\n509|ir_bound: number out of range for its type or place; condition if ge sub bnd 1 1000000\n510|ir_while: type mismatch; condition if ne get ir_vt 0 1\n511|ir_for: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3\n512|ir_for: syntax: unknown or misplaced word; condition if ne get tk 0 1\n513|ir_for: type mismatch; condition if eq ty 1\n514|ir_for: number out of range for its type or place; condition if eq a_ib get ts 0 45\n515|ir_for: number out of range for its type or place; condition if gt get tw 0 1000000\n516|ir_for: number out of range for its type or place; condition if gt a_g 8 sub e 1 1000000\n517|ir_for: type mismatch; condition if ne get ir_vt 0 ty\n518|ir_stmtcall: type mismatch; condition if ne get irf_ret j 76\n519|ir_stmtcall: type mismatch; condition if ne get ir_vt 0 ty\n520|ir_assign: type mismatch; condition if ne get ir_vt 0 ulong get ir_rty r\n521|ir_assign: type mismatch; condition if eqs\n522|ir_assign: type mismatch; condition if ne findname w 0\n523|ir_assign: bare number without a type from its context; condition if ne get ir_isb 0 0\n524|ir_stmt: missing end; condition if eq get tk 0 3\n525|ir_stmt: syntax: unknown or misplaced word; condition if ne get tk 0 1\n526|ir_stmt: line after ret, break, continue, trap or exit in the same block; condition if ne get ir_dead 0 0\n527|ir_stmt: word or declaration in a place that does not allow it; condition if eq c 77\n528|ir_stmt: number out of range for its type or place; condition if or lt code 1 gt code 14\n529|ir_stmt: the line ends where a word or value is needed; condition if not or eq get tk 0 0 eq get tk 0 3\n530|ir_stmt: word or declaration in a place that does not allow it; condition if eq ex 0\n531|ir_stmt: missing end; condition if or ne get ir_fk n 1 ne get ir_fc n 0\n532|ir_stmt: type mismatch; condition if ne get ir_vt 0 1\n533|ir_stmt: the line ends where a word or value is needed; condition if ne get ir_ret 0 76\n534|ir_stmt: extra words after a complete statement; condition if eq get ir_ret 0 76\n535|ir_stmt: type mismatch; condition if ne get ir_vt 0 get ir_ret 0\n536|ir_stmt: missing end; condition if eq c 64\n537|ir_stmt: unknown name or field, or a word this mode does not provide; condition if eq c 97\n538|ir_stmt: word or declaration in a place that does not allow it; condition if or eq c 80 eq c 82\n539|ir_stmt: word or declaration in a place that does not allow it; condition if or or or eq c 78 eq c 79 eq c 81 eq c 85\n540|ir_stmt: word or declaration in a place that does not allow it; condition if eq c 193\n541|ir_stmt: syntax: unknown or misplaced word; condition if ne c 0\n542|ir_stmt: contract syntax misplaced or not supported here (IR mode included); condition if not eqs\n543|ir_param: word or declaration in a place that does not allow it; condition if ge np 6\n544|ir_fn: syntax: unknown or misplaced word; condition if ne get tk 0 1\n545|ir_fn: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63\n546|ir_fn: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge fcur 32\n547|ir_fn: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3\n548|ir_fn: syntax: unknown or misplaced word; condition if ne get tk 0 1\n549|ir_run: syntax: unknown or misplaced word; condition if ne k 1\n550|ir_run: word or declaration in a place that does not allow it; condition if or or eq c 85 eq c 78 eq c 79\n551|ir_run: syntax: unknown or misplaced word; condition otherwise: if eq c 152\n552|cp_token: contract syntax misplaced or not supported here (IR mode included); condition if ne get tk 0 1\n553|cp_token: contract syntax misplaced or not supported here (IR mode included); condition if gt get tl 0 63\n554|cp_token: contract syntax misplaced or not supported here (IR mode included)\n555|cp_eval: type mismatch; condition if ne get rt 0 1\n556|cp_entry: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 64\n557|cp_entry: contract syntax misplaced or not supported here (IR mode included); condition if eq k 3\n558|cp_head: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 64\n559|main: syntax: unknown or misplaced word; condition if or eq get om2 0 0 ne get om2m 0 0\n560|main: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if or ne get xtarget 0 0 ne get xefa 0 0\n561|main: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if eq get progmode 0 0\n562|main: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if eq get progmode 0 0\n563|xhmnew: word or declaration in a place that does not allow it; condition if or ne a_g 77 add x 14 3 ne a_g 77 add x 16 3\n564|xhmnew: word or declaration in a place that does not allow it; condition if and ne acc 1 ne acc 3\n565|xhmnew: word or declaration in a place that does not allow it; condition if and and and ne mode 1 ne mode 2 ne mode 33 ne mode 34\n566|xhmbind: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 14 3\n567|xhmbind: word or declaration in a place that does not allow it; condition if and ne acc 1 ne acc 3\n568|xhmmio: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 12 3\n569|xhmmio: word or declaration in a place that does not allow it; condition if and ne w 4 ne w 8\n570|xhreq: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 12 3\n571|xhreq: word or declaration in a place that does not allow it; condition if not ok\n572|xhreq: word or declaration in a place that does not allow it; condition if eq n 0\n573|xhreq: word or declaration in a place that does not allow it; condition if eq n 0\n574|xhreq: word or declaration in a place that does not allow it; condition if and ne q 3223340586 ne q 3223340587\n575|xhdev: global passed as an argument, or one array twice in a call; condition if eq e f\n576|xhost: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xtarget 0 1\n577|xhost: word or declaration in a place that does not allow it; condition if eq 0 get om2 0\n578|xhost: word or declaration in a place that does not allow it; condition if eq ok 0\n579|xhost: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if eq c 198\n580|xcc: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14)\n581|xarith: type mismatch; condition if or lt op 33 gt op 35\n582|xdiv: type mismatch; condition if ne op 36\n583|xunary: type mismatch; condition if eq ty 13\n584|xunary: type mismatch; condition if eq op 50\n585|xunary: type mismatch; condition if eq ty 1\n586|xconv: type mismatch; condition if or eq ft 13 eq tt 13\n587|xconv: word or declaration in a place that does not allow it; condition if or eq ft 1 eq tt 1\n588|xconv: word or declaration in a place that does not allow it; condition if or eq ft 1 eq tt 1\n589|xelem: type mismatch; condition if or or eq t 1 eq t 10 eq t 11\n590|xelem: constant index outside the array; condition if le ln v\n591|xio: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xtarget 0 1\n592|xarray: word or declaration in a place that does not allow it; condition if ne get nb 0 0\n593|xarray: size capacity; condition if gt add get stkbytes 0 by 4194304\n594|xarray: type mismatch; condition if ne get rt 0 t\n595|xfinish: a function with a result can reach its end; condition if ne get curret 0 12\n596|xlead: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition otherwise: if and eq get tw 0 115888505501281 eq get tl 0 6\n597|xeof: syntax: unknown or misplaced word; condition if eq f 0\n598|xeof: word or declaration in a place that does not allow it; condition if ne uchar get a_ar add get a_rb 24 sub f 1 0\n599|xer: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 256\n600|xer: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge m 256\n601|xefival: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xtarget 0 2\n602|xefival: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if gt op 14\n603|xdev: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne op 13\n604|aeof: syntax: unknown or misplaced word; condition if eq f 0\n605|aeof: word or declaration in a place that does not allow it; condition if ne uchar get a_ar add get a_rb 24 sub f 1 0\n606|aeof: word or declaration in a place that does not allow it; condition if ne ulong get a_ar add get a_rb 24 sub h 1 0\n607|aeof: word or declaration in a place that does not allow it; condition if ne ulong get a_ar add get a_rb 23 sub h 1 12\n608|aefival: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if gt op 14\n609|aefival: syntax: unknown or misplaced word; condition if eq f 0\n610|aefival: word or declaration in a place that does not allow it; condition if ne ulong get a_ar add get a_rb 24 sub f 1 4\n611|aefival: word or declaration in a place that does not allow it; condition if ne ulong get a_ar add get a_rb 23 sub f 1 5\n612|aefival: word or declaration in a place that does not allow it; condition if ne a_gu 37 pe 0\n613|aefival: word or declaration in a place that does not allow it; condition if ne ulong a_gu 35 pe 5\n614|s_extern: missing end; condition if ne get curret 0 0\n615|s_extern: syntax: unknown or misplaced word; condition if or ne get tk 0 1 ne get tw 0 28262\n616|obj_import: word or declaration in a place that does not allow it; condition if ne a_gu 27 f 0\n617|obj_signature: type mismatch; condition if gt a_gu 23 f 13\n618|obj_signature: type mismatch; condition if gt a_gu 35 p 13\n619|obj_signature: type mismatch; condition if and ne k 0 and ne k 2 ne k 3\n620|obj_signature: type mismatch; condition if ne a_gu 38 p 0\n621|obj_signature: fresh element read before it is definitely written, or fresh array passed on; condition if and eq a_gu 32 f 2 ne a_gu 39 p 0\n622|obj_write: the compiler's standard output could not be written; condition if eq a_out 1 1 0 get oc 0 0\n"
606note Native diagnostic v2 + canonical program-identity & effect receipts. SHA core below is generated from seed/trace/sha256.om.
607global d2mode ulong 1
608global d2site ulong 1
609global d2size ulong 1
610global d2full ulong 1
611global d2done ulong 1
612global d2hash uchar 32
613global rcmode ulong 1
614global rc_sz ulong 1
615global rc_cnt ulong 1
616global rc_cat ulong 1
617global rc_ccnt ulong 1
618global rc_w ulong 4
619global rc_tmp uchar 32
620global rc_body uchar 32
621global rc_sig uchar 32
622global rc_con uchar 32
623global rc_pid uchar 32
624global rc_out uchar 32
625global rc_rid uchar 32
626text d2flag "OMC_DIAGNOSTICS=2"
627text rcflag "OMC_RECEIPT=1"
628text rcdom_p "omega.program.v2"
629text rcdom_c "omega.contract.v1"
630text rcdom_r "omega.effect.receipt.v1"
631text rct_hdr "omc-receipt 1 program_id="
632text rct_bid " body_id="
633text rct_sid " sig_id="
634text rct_cid " contract_id="
635text rct_ish " input_sha256="
636text rct_ib " input_bytes="
637text rct_osh " output_sha256="
638text rct_ob " output_bytes="
639text rct_cs " compiler_source_sha256="
640text rct_om2 " om2="
641text rct_obj " obj="
642text rct_ir " ir="
643text rct_tgt " target="
644text rct_efa " efa="
645text rct_eff " effects="
646text rct_es " effect_sites="
647text rct_ew " effect_words="
648text rct_rid " receipt_id="
649
650note SPDX-License-Identifier: AGPL-3.0-only
651note SHA-256, one-shot over a byte slice, in seeded .om.
652note The digest is the standard FIPS 180-4 construction with 32-bit words held in ulong and
653note masked after every addition. It has no host crypto dependency and no network path.
654global ds_h ulong 8
655global ds_w ulong 64
656global ds_k ulong 64
657global ds_blk uchar 64
658global ds_kset ulong 1
659
660fn ds_mask x ulong to ulong
661ret and x 4294967295
662end
663
664fn ds_ror x ulong n ulong to ulong
665ret ds_mask or shr x n shl x sub 32 n
666end
667
668fn ds_ch e ulong f ulong g ulong to ulong
669ret xor and e f and xor e 4294967295 g
670end
671
672fn ds_maj a ulong b ulong c ulong to ulong
673ret xor and a b xor and a c and b c
674end
675
676fn ds_bs0 x ulong to ulong
677ret xor ds_ror x 2 xor ds_ror x 13 ds_ror x 22
678end
679
680fn ds_bs1 x ulong to ulong
681ret xor ds_ror x 6 xor ds_ror x 11 ds_ror x 25
682end
683
684fn ds_ss0 x ulong to ulong
685ret xor ds_ror x 7 xor ds_ror x 18 shr x 3
686end
687
688fn ds_ss1 x ulong to ulong
689ret xor ds_ror x 17 xor ds_ror x 19 shr x 10
690end
691
692fn ds_kinit to void
693if ne get ds_kset 0 0
694ret
695end
696put ds_k 0 ulong 1116352408
697put ds_k 1 ulong 1899447441
698put ds_k 2 ulong 3049323471
699put ds_k 3 ulong 3921009573
700put ds_k 4 ulong 961987163
701put ds_k 5 ulong 1508970993
702put ds_k 6 ulong 2453635748
703put ds_k 7 ulong 2870763221
704put ds_k 8 ulong 3624381080
705put ds_k 9 ulong 310598401
706put ds_k 10 ulong 607225278
707put ds_k 11 ulong 1426881987
708put ds_k 12 ulong 1925078388
709put ds_k 13 ulong 2162078206
710put ds_k 14 ulong 2614888103
711put ds_k 15 ulong 3248222580
712put ds_k 16 ulong 3835390401
713put ds_k 17 ulong 4022224774
714put ds_k 18 ulong 264347078
715put ds_k 19 ulong 604807628
716put ds_k 20 ulong 770255983
717put ds_k 21 ulong 1249150122
718put ds_k 22 ulong 1555081692
719put ds_k 23 ulong 1996064986
720put ds_k 24 ulong 2554220882
721put ds_k 25 ulong 2821834349
722put ds_k 26 ulong 2952996808
723put ds_k 27 ulong 3210313671
724put ds_k 28 ulong 3336571891
725put ds_k 29 ulong 3584528711
726put ds_k 30 ulong 113926993
727put ds_k 31 ulong 338241895
728put ds_k 32 ulong 666307205
729put ds_k 33 ulong 773529912
730put ds_k 34 ulong 1294757372
731put ds_k 35 ulong 1396182291
732put ds_k 36 ulong 1695183700
733put ds_k 37 ulong 1986661051
734put ds_k 38 ulong 2177026350
735put ds_k 39 ulong 2456956037
736put ds_k 40 ulong 2730485921
737put ds_k 41 ulong 2820302411
738put ds_k 42 ulong 3259730800
739put ds_k 43 ulong 3345764771
740put ds_k 44 ulong 3516065817
741put ds_k 45 ulong 3600352804
742put ds_k 46 ulong 4094571909
743put ds_k 47 ulong 275423344
744put ds_k 48 ulong 430227734
745put ds_k 49 ulong 506948616
746put ds_k 50 ulong 659060556
747put ds_k 51 ulong 883997877
748put ds_k 52 ulong 958139571
749put ds_k 53 ulong 1322822218
750put ds_k 54 ulong 1537002063
751put ds_k 55 ulong 1747873779
752put ds_k 56 ulong 1955562222
753put ds_k 57 ulong 2024104815
754put ds_k 58 ulong 2227730452
755put ds_k 59 ulong 2361852424
756put ds_k 60 ulong 2428436474
757put ds_k 61 ulong 2756734187
758put ds_k 62 ulong 3204031479
759put ds_k 63 ulong 3329325298
760put ds_kset 0 1
761end
762
763fn ds_hinit to void
764put ds_h 0 ulong 1779033703
765put ds_h 1 ulong 3144134277
766put ds_h 2 ulong 1013904242
767put ds_h 3 ulong 2773480762
768put ds_h 4 ulong 1359893119
769put ds_h 5 ulong 2600822924
770put ds_h 6 ulong 528734635
771put ds_h 7 ulong 1541459225
772end
773
774fn ds_compress to void
775ds_kinit
776for i ulong 16
777v = ulong 0
778for j ulong 4
779v = or shl v 8 ulong get ds_blk add mul i 4 j
780end
781put ds_w i v
782end
783for i ulong 48
784j = add i 16
785v = add ds_ss1 get ds_w sub j 2 add ds_ss0 get ds_w sub j 15 add get ds_w sub j 7 get ds_w sub j 16
786put ds_w j ds_mask v
787end
788a = ulong get ds_h 0
789b = ulong get ds_h 1
790c = ulong get ds_h 2
791d = ulong get ds_h 3
792e = ulong get ds_h 4
793f = ulong get ds_h 5
794g = ulong get ds_h 6
795hh = ulong get ds_h 7
796for i ulong 64
797x = ds_ch e f g
798x = add x get ds_k i
799x = add x get ds_w i
800x = add x ds_bs1 e
801x = add x hh
802t1 = ds_mask x
803x = ds_maj a b c
804x = add ds_bs0 a x
805hh = g
806g = f
807f = e
808e = ds_mask add d t1
809d = c
810c = b
811b = a
812a = ds_mask add t1 x
813end
814put ds_h 0 ds_mask add get ds_h 0 a
815put ds_h 1 ds_mask add get ds_h 1 b
816put ds_h 2 ds_mask add get ds_h 2 c
817put ds_h 3 ds_mask add get ds_h 3 d
818put ds_h 4 ds_mask add get ds_h 4 e
819put ds_h 5 ds_mask add get ds_h 5 f
820put ds_h 6 ds_mask add get ds_h 6 g
821put ds_h 7 ds_mask add get ds_h 7 hh
822end
823
824fn d2env to void
825n = envcnt
826i = ulong 0
827while lt i ulong n
828k = envread i a_eb 0 131072
829if eq k long len d2flag
830ok = true
831for j ulong len d2flag
832if ne get a_eb j get d2flag j
833ok = false
834end
835end
836if ok
837put d2mode 0 1
838end
839end
840if eq k long len rcflag
841ok = true
842for j ulong len rcflag
843if ne get a_eb j get rcflag j
844ok = false
845end
846end
847if ok
848put rcmode 0 1
849end
850end
851i = add i 1
852end
853if or ne get d2mode 0 0 ne get rcmode 0 0
854ds_hinit
855end
856end
857
858note Hash bytes as read, before a memory refusal or formatter can change the input arena.
859fn d2feed n ulong to void
860for i ulong n
861j = rem get d2size 0 64
862put ds_blk j get a_wb i
863put d2size 0 add get d2size 0 1
864if eq j 63
865ds_compress
866end
867end
868end
869
870fn d2finish to void
871if ne get d2done 0 0
872ret
873end
874j = rem get d2size 0 64
875put ds_blk j 128
876j = add j 1
877while lt j 64
878put ds_blk j 0
879j = add j 1
880end
881if ge rem get d2size 0 64 56
882ds_compress
883for i ulong 64
884put ds_blk i 0
885end
886end
887bits = mul get d2size 0 8
888for i ulong 8
889put ds_blk add 56 i uchar and shr bits mul sub 7 i 8 255
890end
891ds_compress
892for i ulong 32
893v = get ds_h div i 4
894shift = mul sub 3 rem i 4 8
895put d2hash i uchar and shr v shift 255
896end
897put d2done 0 1
898end
899
900fn d2record code ulong to void
901d2finish
902put mc 0 0
903mputw 7449351137626647919 8
904mputw 4424052638528582176 8
905mputn code
906mputw 19207804370383648 7
907mputn get d2site 0
908mputw 67505853393952 6
909mputn add get line 0 get lbase 0
910mputw 263812244256 5
911mputn dcol get tka 0
912mputw 67544290456352 6
913mputn add get tka 0 get sbase 0
914mputb 45
915mputn add get tkb 0 get sbase 0
916mputw 7088512386250729760 8
917mputw 263929033849 5
918mputn get d2size 0
919mputw 7160569980288657696 8
920mputw 4424070187921206639 8
921mputn get d2full 0
922mputw 8313491484895504672 8
923mputw 67303030022504 6
924for i ulong 32
925mputh ulong get d2hash i
926end
927mputw 7308332226908742432 8
928mputw 7305808869231648626 8
929mputw 4410771375554851679 8
930for i ulong len d2pin
931mputb get d2pin i
932end
933mputw 262839037728 5
934mputn get om2 0
935mputw 67505686015264 6
936mputn get chkmode 0
937mputw 1030908192 4
938mputn get irmode 0
939mputw 4428275828587066400 8
940mputn get xtarget 0
941mputw 7237123381843029792 8
942mputw 15717 2
943mputn get om2m 0
944mputb 10
945w = write 2 msg 0 get mc 0
946end
947
948fn d2mean code ulong to void
949i = ulong 0
950while lt i len d2means
951id = ulong 0
952more = true
953while and more lt i len d2means
954c = get d2means i
955i = add i 1
956if eq c 124
957more = false
958else
959id = add mul id 10 sub ulong c 48
960end
961end
962more = true
963while and more lt i len d2means
964c = get d2means i
965i = add i 1
966if eq c 10
967more = false
968else
969if eq id code
970mputb c
971end
972end
973end
974if eq id code
975ret
976end
977end
978end
979
980fn d2reason to void
981i = ulong 0
982while lt i len d2sites
983id = ulong 0
984more = true
985while and more lt i len d2sites
986c = get d2sites i
987i = add i 1
988if eq c 124
989more = false
990else
991id = add mul id 10 sub ulong c 48
992end
993end
994more = true
995while and more lt i len d2sites
996c = get d2sites i
997i = add i 1
998if eq c 10
999more = false
1000else
1001if eq id get d2site 0
1002mputb c
1003end
1004end
1005end
1006if eq id get d2site 0
1007ret
1008end
1009end
1010end
1011
1012fn eff_cat1 c ulong to ulong
1013if or eq c 53 eq c 54
1014ret 1
1015end
1016if or eq c 108 eq c 128
1017ret 1
1018end
1019if or eq c 161 eq c 162
1020ret 1
1021end
1022if eq c 221
1023ret 1
1024end
1025if or and ge c 100 le c 103 and ge c 110 le c 113
1026ret 2
1027end
1028if or eq c 117 and ge c 125 le c 126
1029ret 2
1030end
1031if or and ge c 132 le c 133 and ge c 138 le c 144
1032ret 2
1033end
1034if or and ge c 149 le c 151 eq c 153
1035ret 2
1036end
1037if or and ge c 155 le c 157 or eq c 164 eq c 197
1038ret 2
1039end
1040ret 0
1041end
1042
1043fn eff_cat2 c ulong to ulong
1044if or eq c 82 eq c 107
1045ret 4
1046end
1047if or eq c 116 eq c 124
1048ret 4
1049end
1050if or eq c 127 eq c 129
1051ret 4
1052end
1053if or eq c 154 and ge c 158 le c 160
1054ret 4
1055end
1056if or eq c 163 eq c 198
1057ret 4
1058end
1059if or eq c 233 eq c 235
1060ret 4
1061end
1062if or and ge c 104 le c 106 and ge c 114 le c 115
1063ret 8
1064end
1065if or and ge c 118 le c 119 eq c 123
1066ret 8
1067end
1068if or eq c 131 eq c 134
1069ret 8
1070end
1071if or eq c 165 eq c 220
1072ret 8
1073end
1074if or eq c 222 eq c 224
1075ret 8
1076end
1077ret 0
1078end
1079
1080fn eff_cat3 c ulong to ulong
1081if or eq c 109 eq c 120
1082ret 16
1083end
1084if or eq c 130 eq c 135
1085ret 16
1086end
1087if or and ge c 166 le c 177 and ge c 228 le c 232
1088ret 32
1089end
1090if and ge c 241 le c 243
1091ret 32
1092end
1093if eq c 244
1094ret 64
1095end
1096if or eq c 178 ge c 251
1097ret 128
1098end
1099if or and ge c 121 le c 122 and ge c 136 le c 137
1100ret 256
1101end
1102if and ge c 145 le c 148
1103ret 256
1104end
1105if or eq c 199 eq c 200
1106ret 512
1107end
1108if and ge c 236 le c 240
1109ret 512
1110end
1111ret 0
1112end
1113
1114fn eff_rec c ulong to void
1115put rc_cnt 0 add get rc_cnt 0 1
1116if lt c 256
1117wi = shr c 6
1118wb = shl ulong 1 and c 63
1119put rc_w wi or get rc_w wi wb
1120end
1121cat = or or eff_cat1 c eff_cat2 c eff_cat3 c
1122put rc_cat 0 or get rc_cat 0 cat
1123end
1124
1125fn rc_sha_init to void
1126ds_hinit
1127put rc_sz 0 0
1128end
1129
1130fn rc_sha_b b uchar to void
1131j = rem get rc_sz 0 64
1132put ds_blk j b
1133put rc_sz 0 add get rc_sz 0 1
1134if eq j 63
1135ds_compress
1136end
1137end
1138
1139fn rc_sha_u64 v ulong to void
1140for i ulong 8
1141rc_sha_b uchar and shr v mul sub 7 i 8 255
1142end
1143end
1144
1145fn rc_sha_fin to void
1146sz = get rc_sz 0
1147j = rem sz 64
1148put ds_blk j 128
1149j = add j 1
1150while lt j 64
1151put ds_blk j 0
1152j = add j 1
1153end
1154if ge rem sz 64 56
1155ds_compress
1156for i ulong 64
1157put ds_blk i 0
1158end
1159end
1160bits = mul sz 8
1161for i ulong 8
1162put ds_blk add 56 i uchar and shr bits mul sub 7 i 8 255
1163end
1164ds_compress
1165for i ulong 32
1166v = get ds_h div i 4
1167shift = mul sub 3 rem i 4 8
1168put rc_tmp i uchar and shr v shift 255
1169end
1170end
1171
1172fn rc_body_str p ulong e ulong to ulong
1173rc_sha_b 34
1174q = add p 1
1175sgo = true
1176while and sgo lt q e
1177sb = a_ib q
1178rc_sha_b sb
1179q = add q 1
1180if eq sb 92
1181if lt q e
1182rc_sha_b a_ib q
1183q = add q 1
1184end
1185else
1186if or eq sb 34 eq sb 10
1187sgo = false
1188end
1189end
1190end
1191ret q
1192end
1193
1194fn rc_body_tok p ulong e ulong to ulong
1195q = p
1196tgo = true
1197while and tgo lt q e
1198tb = a_ib q
1199st = ulong 0
1200if le ulong tb 32
1201st = 1
1202end
1203if or eq ulong tb 40 eq ulong tb 41
1204st = 1
1205end
1206if eq ulong tb 34
1207st = 1
1208end
1209if ne st 0
1210tgo = false
1211else
1212rc_sha_b tb
1213q = add q 1
1214end
1215end
1216ret q
1217end
1218
1219fn rc_body_hash to void
1220rc_sha_init
1221e = get inlen 0
1222p = ulong 0
1223ht = ulong 0
1224go = true
1225while go
1226m = ulong 0
1227while and go lt m 999999
1228if ge p e
1229go = false
1230else
1231b = a_ib p
1232if or or eq b 32 eq b 9 eq b 13
1233p = add p 1
1234else
1235if eq b 10
1236if ne ht 0
1237rc_sha_b 10
1238ht = ulong 0
1239end
1240p = add p 1
1241else
1242if and eq ht 0 ne isnote p 0
1243p = skipln p
1244else
1245if ne ht 0
1246rc_sha_b 32
1247end
1248if eq b 34
1249p = rc_body_str p e
1250else
1251if or eq b 40 eq b 41
1252rc_sha_b b
1253p = add p 1
1254else
1255p = rc_body_tok p e
1256end
1257end
1258ht = ulong 1
1259end
1260end
1261end
1262end
1263m = add m 1
1264end
1265end
1266if ne ht 0
1267rc_sha_b 10
1268end
1269rc_sha_fin
1270for i ulong 32
1271put rc_body i get rc_tmp i
1272end
1273end
1274
1275fn rc_sig_hash to void
1276rc_sha_init
1277nfv = get nf 0
1278rc_sha_u64 nfv
1279f = ulong 0
1280go = true
1281while go
1282m = ulong 0
1283while and go lt m 999999
1284if ge f nfv
1285go = false
1286else
1287rc_sha_b a_gu 32 f
1288rc_sha_b a_gu 23 f
1289np = ulong a_gu 24 f
1290rc_sha_b uchar np
1291j = ulong 0
1292while lt j np
1293px = add mul f 6 j
1294rc_sha_b a_gu 35 px
1295rc_sha_b a_gu 37 px
1296rc_sha_u64 a_g 36 px
1297j = add j 1
1298end
1299f = add f 1
1300end
1301m = add m 1
1302end
1303end
1304rc_sha_fin
1305for i ulong 32
1306put rc_sig i get rc_tmp i
1307end
1308end
1309
1310fn rc_con_hash to void
1311if and eq get rc_ccnt 0 0 eq get crel 0 0
1312for i ulong 32
1313put rc_con i 0
1314end
1315ret
1316end
1317rc_sha_init
1318for i ulong len rcdom_c
1319rc_sha_b get rcdom_c i
1320end
1321rc_sha_b 0
1322rc_sha_u64 get crel 0
1323rc_sha_u64 get rc_ccnt 0
1324rc_sha_fin
1325for i ulong 32
1326put rc_con i get rc_tmp i
1327end
1328end
1329
1330fn rc_pid_hash to void
1331rc_sha_init
1332for i ulong len rcdom_p
1333rc_sha_b get rcdom_p i
1334end
1335rc_sha_b 0
1336for i ulong 32
1337rc_sha_b get rc_body i
1338end
1339for i ulong 32
1340rc_sha_b get rc_sig i
1341end
1342for i ulong 32
1343rc_sha_b get rc_con i
1344end
1345rc_sha_fin
1346for i ulong 32
1347put rc_pid i get rc_tmp i
1348end
1349end
1350
1351fn rc_out_hash st ulong to void
1352rc_sha_init
1353i = st
1354e = get oc 0
1355go = true
1356while go
1357m = ulong 0
1358while and go lt m 999999
1359if ge i e
1360go = false
1361else
1362rc_sha_b a_ob i
1363i = add i 1
1364end
1365m = add m 1
1366end
1367end
1368rc_sha_fin
1369for j ulong 32
1370put rc_out j get rc_tmp j
1371end
1372end
1373
1374fn rc_putw64 v ulong to void
1375for i ulong 8
1376mputh and shr v mul sub 7 i 8 255
1377end
1378end
1379
1380fn rc_emit st ulong to void
1381if eq get rcmode 0 0
1382ret
1383end
1384d2finish
1385rc_body_hash
1386rc_sig_hash
1387rc_con_hash
1388rc_pid_hash
1389rc_out_hash st
1390put mc 0 0
1391for i ulong len rct_hdr
1392mputb get rct_hdr i
1393end
1394for i ulong 32
1395mputh ulong get rc_pid i
1396end
1397for i ulong len rct_bid
1398mputb get rct_bid i
1399end
1400for i ulong 32
1401mputh ulong get rc_body i
1402end
1403for i ulong len rct_sid
1404mputb get rct_sid i
1405end
1406for i ulong 32
1407mputh ulong get rc_sig i
1408end
1409for i ulong len rct_cid
1410mputb get rct_cid i
1411end
1412for i ulong 32
1413mputh ulong get rc_con i
1414end
1415for i ulong len rct_ish
1416mputb get rct_ish i
1417end
1418for i ulong 32
1419mputh ulong get d2hash i
1420end
1421for i ulong len rct_ib
1422mputb get rct_ib i
1423end
1424mputn get d2size 0
1425for i ulong len rct_osh
1426mputb get rct_osh i
1427end
1428for i ulong 32
1429mputh ulong get rc_out i
1430end
1431for i ulong len rct_ob
1432mputb get rct_ob i
1433end
1434mputn sub get oc 0 st
1435for i ulong len rct_cs
1436mputb get rct_cs i
1437end
1438for i ulong len d2pin
1439mputb get d2pin i
1440end
1441for i ulong len rct_om2
1442mputb get rct_om2 i
1443end
1444mputn get om2 0
1445for i ulong len rct_obj
1446mputb get rct_obj i
1447end
1448mputn get objmode 0
1449for i ulong len rct_ir
1450mputb get rct_ir i
1451end
1452mputn get irmode 0
1453for i ulong len rct_tgt
1454mputb get rct_tgt i
1455end
1456mputn get xtarget 0
1457for i ulong len rct_efa
1458mputb get rct_efa i
1459end
1460mputn get xefa 0
1461for i ulong len rct_eff
1462mputb get rct_eff i
1463end
1464mputn get rc_cat 0
1465for i ulong len rct_es
1466mputb get rct_es i
1467end
1468mputn get rc_cnt 0
1469for i ulong len rct_ew
1470mputb get rct_ew i
1471end
1472rc_putw64 get rc_w 3
1473rc_putw64 get rc_w 2
1474rc_putw64 get rc_w 1
1475rc_putw64 get rc_w 0
1476plen = get mc 0
1477rc_sha_init
1478for i ulong len rcdom_r
1479rc_sha_b get rcdom_r i
1480end
1481rc_sha_b 0
1482for i ulong plen
1483rc_sha_b get msg i
1484end
1485rc_sha_fin
1486for i ulong 32
1487put rc_rid i get rc_tmp i
1488end
1489for i ulong len rct_rid
1490mputb get rct_rid i
1491end
1492for i ulong 32
1493mputh ulong get rc_rid i
1494end
1495mputb 10
1496w = write 2 msg 0 get mc 0
1497end
1498
1499
1500note D2-GENERATED-END
1501
1502fn a_env to void
1503nl = envcnt
1504n = ulong nl
1505i = ulong 0
1506while lt i n
1507kl = envread i a_eb 0 131072
1508if lt kl 0
1509note d2site 1|a_env: the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole; condition if lt kl 0
1510put d2site 0 1
1511fail 26
1512end
1513if ge kl 15
1514k = ulong kl
1515if eq a_envp 0 1
1516a_envv k
1517ret
1518end
1519end
1520i = add i 1
1521end
1522end
1523
1524note a_envp: 1 when a_eb starts with OMC_MEMORY_MAX=
1525fn a_envp z ulong to ulong
1526j = ulong 0
1527while lt j 15
1528if ne get a_eb j get a_envk j
1529ret 0
1530end
1531j = add j 1
1532end
1533ret 1
1534end
1535
1536note a_envv: the value of OMC_MEMORY_MAX=, bytes 15 .. k - 1 of a_eb: empty or 0 is no ceiling; 1 to 19 decimal
1537note digits below 2^63 a ceiling; anything else is a caller's mistake: error 26 on line 0, before any input is read
1538fn a_envv k ulong to void
1539if eq k 15
1540ret
1541end
1542if gt sub k 15 19
1543note d2site 2|a_envv: the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole; condition if gt sub k 15 19
1544put d2site 0 2
1545fail 26
1546end
1547v = ulong 0
1548j = ulong 15
1549while lt j k
1550c = ulong get a_eb j
1551if or lt c 48 gt c 57
1552note d2site 3|a_envv: the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole; condition if or lt c 48 gt c 57
1553put d2site 0 3
1554fail 26
1555end
1556if gt v 922337203685477580
1557note d2site 4|a_envv: the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole; condition if gt v 922337203685477580
1558put d2site 0 4
1559fail 26
1560end
1561v = add mul v 10 sub c 48
1562j = add j 1
1563end
1564if ge v 9223372036854775808
1565note d2site 5|a_envv: the compiler's environment entry OMC_MEMORY_MAX is not empty, 0 or 1 to 19 decimal digits below 2^63, or an entry is too long to read whole; condition if ge v 9223372036854775808
1566put d2site 0 5
1567fail 26
1568end
1569if eq v 0
1570ret
1571end
1572note CEILMUT
1573put a_cel 0 v
1574end
1575
1576note a_gextra: the words group g's regions need beyond the words they hold, at capacity c
1577fn a_gextra g ulong c ulong to ulong
1578s = ulong 0
1579r = ulong 0
1580while lt r get a_nr 0
1581if eq get a_rg r g
1582w = a_words r c
1583if gt w get a_rw r
1584s = add s sub w get a_rw r
1585end
1586end
1587r = add r 1
1588end
1589ret s
1590end
1591
1592note a_gfit: the largest capacity in n + 1 .. hi whose growth in place fits in the free words and the budget (a_bad)
1593note (binary search; it grows with the capacity), or error 14 (a_full) when not even n + 1 does
1594fn a_gfit g ulong n ulong hi ulong to ulong
1595f = sub len a_ar get a_top 0
1596lo = add n 1
1597if ne a_bad g lo 0
1598a_full
1599end
1600go = true
1601while go
1602m = ulong 0
1603while and go lt m 999999
1604if le sub hi lo 1
1605go = false
1606else
1607mid = add lo shr sub hi lo 1
1608if ne a_bad g mid 0
1609hi = mid
1610else
1611lo = mid
1612end
1613end
1614m = add m 1
1615end
1616end
1617ret lo
1618end
1619
1620note a_relayout: after a_compact (regions contiguous from word 0 in order of base), give group g's
1621note regions their words at capacity c in place: new places are laid out in the same order, every region
1622note at or above its old place, and the regions are moved from the top down (a_copyd), each new tail
1623note zeroed. Region 0, the input, is the first and never moves.
1624fn a_relayout g ulong c ulong to void
1625k = ulong 0
1626lb = ulong 0
1627any = false
1628go = true
1629while go
1630best = a_lowest any lb
1631if eq best 0
1632go = false
1633else
1634r = sub best 1
1635put a_ord k r
1636k = add k 1
1637lb = get a_rb r
1638any = true
1639end
1640end
1641pos = ulong 0
1642i = ulong 0
1643while lt i k
1644r = get a_ord i
1645put a_np i pos
1646w = get a_rw r
1647if eq get a_rg r g
1648w = a_words r c
1649end
1650pos = add pos w
1651i = add i 1
1652end
1653i = k
1654while gt i 0
1655i = sub i 1
1656r = get a_ord i
1657np = get a_np i
1658b = get a_rb r
1659w = get a_rw r
1660if ne np b
1661a_copyd np b w
1662put a_rb r np
1663end
1664if eq get a_rg r g
1665nw = a_words r c
1666if gt nw w
1667a_clear add np w add np nw
1668put a_rw r nw
1669end
1670end
1671end
1672put a_top 0 pos
1673end
1674
1675note a_copyd: words s .. s + n - 1 of the arena to d .. d + n - 1 in descending order (d above s: a slide up)
1676fn a_copyd d ulong s ulong n ulong to void
1677i = n
1678go = true
1679while go
1680m = ulong 0
1681while and go lt m 999999
1682if eq i 0
1683go = false
1684else
1685i = sub i 1
1686put a_ar add d i get a_ar add s i
1687end
1688m = add m 1
1689end
1690end
1691end
1692
1693note a_compact: slide every region down over the words moved regions left behind, in order of base, so
1694note the free words are one run at the top again; the words above the new top become 0 (a_move hands out
1695note words past a_top as zero). Region 0, the input, has base 0 and stays there (a_ib reads it at 0).
1696fn a_compact to void
1697t = get a_top 0
1698pos = ulong 0
1699lb = ulong 0
1700any = false
1701go = true
1702while go
1703best = a_lowest any lb
1704if eq best 0
1705go = false
1706else
1707r = sub best 1
1708b = get a_rb r
1709w = get a_rw r
1710if ne b pos
1711a_copy pos b w
1712put a_rb r pos
1713end
1714pos = add pos w
1715lb = b
1716any = true
1717end
1718end
1719a_clear pos t
1720put a_top 0 pos
1721put a_wst 0 0
1722end
1723
1724note a_lowest: index + 1 of the region holding words with the lowest base above lb (any base when any is
1725note false), or 0 when none is left; regions slid already have bases at or below lb
1726fn a_lowest any bool lb ulong to ulong
1727best = ulong 0
1728bb = ulong 0
1729r = ulong 0
1730while lt r get a_nr 0
1731if ne get a_rw r 0
1732b = get a_rb r
1733if or not any gt b lb
1734if or eq best 0 lt b bb
1735best = add r 1
1736bb = b
1737end
1738end
1739end
1740r = add r 1
1741end
1742ret best
1743end
1744
1745note a_clear: words a .. b - 1 of the arena become 0
1746fn a_clear a ulong b ulong to void
1747i = a
1748go = true
1749while go
1750m = ulong 0
1751while and go lt m 999999
1752if ge i b
1753go = false
1754else
1755put a_ar i 0
1756i = add i 1
1757end
1758m = add m 1
1759end
1760end
1761end
1762
1763note a_gneed: the words group g's regions take at capacity c, counted as if every one of them moved
1764fn a_gneed g ulong c ulong to ulong
1765s = ulong 0
1766r = ulong 0
1767while lt r get a_nr 0
1768if eq get a_rg r g
1769s = add s a_words r c
1770end
1771r = add r 1
1772end
1773ret s
1774end
1775
1776note a_full: the arena has no room left and the host refused to grow it: error 14 (full=1), and fail writes the
1777note omc-use record after its line
1778fn a_full to void
1779put a_fl 0 1
1780note d2site 6|a_full: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound)
1781put d2site 0 6
1782fail 14
1783end
1784
1785note a_zero: the first k words of region r become 0
1786fn a_zero r ulong k ulong to void
1787b = get a_rb r
1788i = ulong 0
1789go = true
1790while go
1791m = ulong 0
1792while and go lt m 999999
1793if ge i k
1794go = false
1795else
1796put a_ar add b i 0
1797i = add i 1
1798end
1799m = add m 1
1800end
1801end
1802end
1803
1804note a_gzero: every word of every region of group g becomes 0 (a hash table about to be rebuilt)
1805fn a_gzero g ulong to void
1806r = ulong 0
1807while lt r get a_nr 0
1808if eq get a_rg r g
1809a_zero r get a_rw r
1810end
1811r = add r 1
1812end
1813end
1814
1815note a_ib: input byte i. The input is region 0, the first region handed out, so it starts at word 0. Past
1816note its words the byte is 0, as the zero pool past the input was.
1817fn a_ib i ulong to uchar
1818x = shr i 3
1819if ge x get a_rw 0
1820ret 0
1821end
1822y = get a_ar x
1823ret uchar and shr y shl and i 7 3 255
1824end
1825
1826note a_ob: output byte i (0 past the output's words)
1827fn a_ob i ulong to uchar
1828x = shr i 3
1829if ge x get a_rw 1
1830ret 0
1831end
1832y = get a_ar add get a_rb 1 x
1833ret uchar and shr y shl and i 7 3 255
1834end
1835
1836note a_oob: an index past its region is a fault of omc itself, never an input's: trap 3, exactly as an
1837note index past a fixed pool trapped (the runtime check on a_rb at index 96 + i, always past its 96)
1838fn a_oob i ulong to void
1839z = get a_rb add 96 i
1840end
1841
1842note a_bput: byte i of byte region r becomes v (a_oob past the region's words)
1843fn a_bput r ulong i ulong v uchar to void
1844x = shr i 3
1845if ge x get a_rw r
1846a_oob x
1847end
1848x = add get a_rb r x
1849s = shl and i 7 3
1850y = get a_ar x
1851y = and y not shl ulong 255 s
1852y = or y shl ulong v s
1853put a_ar x y
1854end
1855
1856note a_pc: element i of a uchar table held one to a word (region r) becomes v (a_oob past the region)
1857fn a_pc r ulong i ulong v uchar to void
1858if ge i get a_rw r
1859a_oob i
1860end
1861put a_ar add get a_rb r i ulong v
1862end
1863
1864note a_stage: bytes p .. p + c - 1 of the byte region at word b into a_wb from 0 (c at most 65536)
1865fn a_stage b ulong p ulong c ulong to void
1866i = ulong 0
1867while and lt i c ne and add p i 7 0
1868x = add p i
1869y = get a_ar add b shr x 3
1870put a_wb i uchar and shr y shl and x 7 3 255
1871i = add i 1
1872end
1873note whole words: one load, eight bytes
1874while le add i 8 c
1875y = get a_ar add b shr add p i 3
1876for k ulong 8
1877put a_wb add i k uchar and shr y shl k 3 255
1878end
1879i = add i 8
1880end
1881while lt i c
1882x = add p i
1883y = get a_ar add b shr x 3
1884put a_wb i uchar and shr y shl and x 7 3 255
1885i = add i 1
1886end
1887end
1888
1889note a_out: write bytes p .. e - 1 of byte region r to fd, 65536 at a time through a_wb: 1 when every
1890note byte was written, 0 when a write returned 0 or less
1891fn a_out fd ulong r ulong p ulong e ulong to ulong
1892b = get a_rb r
1893go = true
1894while go
1895m = ulong 0
1896while and go lt m 999999
1897if ge p e
1898go = false
1899else
1900c = sub e p
1901if gt c 65536
1902c = ulong 65536
1903end
1904a_stage b p c
1905q = ulong 0
1906while lt q c
1907n = write int fd a_wb q sub c q
1908if le n 0
1909ret 0
1910end
1911q = add q ulong n
1912end
1913p = add p c
1914end
1915m = add m 1
1916end
1917end
1918ret 1
1919end
1920
1921note a_rdin: all of stdin into region 0, eight bytes to a word from word 0 (error 1 on a read error,
1922note error 14 when the arena has no room); then the region keeps the words the input fills and 8 more, all
1923note zero, so the next region starts after them. inlen: the input's bytes. Input bytes are read inline
1924note from word 0 (the codemod's a_ib form) without a region check; the 64 zero bytes past the input are
1925note what a lookahead past the end reads, as the zero pool past the input did.
1926fn a_rdin to void
1927off = ulong 0
1928go = true
1929while go
1930m = ulong 0
1931while and go lt m 999999
1932n = read 0 a_wb 0 65536
1933if eq n 0
1934if or ne get d2mode 0 0 ne get rcmode 0 0
1935d2finish
1936put d2full 0 1
1937end
1938go = false
1939else
1940if lt n 0
1941note d2site 7|a_rdin: the compiler's standard input could not be read; condition if lt n 0
1942put d2site 0 7
1943fail 1
1944end
1945c = ulong n
1946if or ne get d2mode 0 0 ne get rcmode 0 0
1947d2feed c
1948end
1949note inlen counts what was read so far, so an arena-full record shows it
1950put inlen 0 add off c
1951a_need 0 add off c
1952a_pack off c
1953off = add off c
1954end
1955m = add m 1
1956end
1957end
1958put inlen 0 off
1959w = add shr off 3 9
1960a_need 0 shl w 3
1961put a_rw 0 w
1962put a_top 0 w
1963put a_hw 0 w
1964put a_gc 0 shl w 3
1965end
1966
1967note a_pack: the c bytes of a_wb become input bytes off .. off + c - 1 (their words are 0 until now)
1968fn a_pack off ulong c ulong to void
1969i = ulong 0
1970while and lt i c ne and add off i 7 0
1971a_pack1 add off i ulong get a_wb i
1972i = add i 1
1973end
1974note whole words: eight bytes, one store (the word was 0)
1975while le add i 8 c
1976w = ulong 0
1977for k ulong 8
1978w = or w shl ulong get a_wb add i k shl k 3
1979end
1980put a_ar shr add off i 3 w
1981i = add i 8
1982end
1983while lt i c
1984a_pack1 add off i ulong get a_wb i
1985i = add i 1
1986end
1987end
1988
1989note a_pack1: input byte x becomes b (its word holds 0 at that byte until now)
1990fn a_pack1 x ulong b ulong to void
1991s = shl and x 7 3
1992y = get a_ar shr x 3
1993put a_ar shr x 3 or y shl b s
1994end
1995
1996note a_init: every other region gets its first room after the input: the hash tables 1024 buckets, the
1997note output last (it grows most, and the last region grows in place), the rest 64 entries each, except
1998note the groups that grow with the input (names, long names, functions, calls, trap sites), which get
1999note room for the entries an input of this size usually holds (a_isize). The arena is zero .bss: room
2000note never written costs no page, while a region that outgrows its room moves and leaves touched pages
2001note behind, so a first room that fits saves those pages (measured: 145 fewer page faults on omega-mcp).
2002fn a_init to void
2003a_defs
2004g = ulong 2
2005while lt g 21
2006if or or eq g 4 eq g 6 eq g 8
2007a_need g 1023
2008else
2009a_need g sub a_isize g 1
2010end
2011g = add g 1
2012end
2013put nh_b 0 10
2014put lh_b 0 10
2015put fh_b 0 10
2016a_need 1 65535
2017note the first room is not use: a_gp counts only what the unit asks for (the omc-use record)
2018g = ulong 0
2019while lt g 21
2020put a_gp g 0
2021g = add g 1
2022end
2023put a_rdy 0 1
2024end
2025
2026note a_isize: the first room of group g, in entries: the input's bytes over k for the groups that grow
2027note with it (names k 16, long names 64, functions 64, calls 8, trap sites 8), between 64 and 8192;
2028note 64 for the rest. A guess, never a bound: past it the group doubles as always.
2029fn a_isize g ulong to ulong
2030k = ulong 0
2031if or eq g 3 eq g 9
2032k = ulong 16
2033end
2034if or eq g 5 eq g 7
2035k = ulong 64
2036end
2037if eq g 10
2038k = ulong 8
2039end
2040if eq g 9
2041k = ulong 8
2042end
2043if eq k 0
2044ret 64
2045end
2046c = div get inlen 0 k
2047if lt c 64
2048ret 64
2049end
2050if gt c 8192
2051ret 8192
2052end
2053ret c
2054end
2055
2056note a_hash: the b-bit multiplicative hash of w (2^64 divided by the golden ratio, odd)
2057fn a_hash w ulong b ulong to ulong
2058ret shr mul w 11400714819323198485 sub 64 b
2059end
2060
2061note a_gcount: what group g was asked to hold: the bytes of the input, the output and the om2 diag sites,
2062note else the highest index asked for, plus 1
2063fn a_gcount g ulong to ulong
2064if eq g 0
2065ret get inlen 0
2066end
2067if eq g 1
2068ret get oc 0
2069end
2070if eq g 2
2071ret get nsite 0
2072end
2073ret get a_gp g
2074end
2075
2076note a_gwords: the words the regions of group g hold
2077fn a_gwords g ulong to ulong
2078s = ulong 0
2079r = ulong 0
2080while lt r get a_nr 0
2081if eq get a_rg r g
2082s = add s get a_rw r
2083end
2084r = add r 1
2085end
2086ret s
2087end
2088
2089note a_rec: the omc-use record, one line to fd: omc-use 1 arena=A top=T waste=W full=F, then for each
2090note group LABEL=N/H, N what it was asked to hold (a_gcount) and H the words it holds. A, T, W and H are
2091note 8-byte words of the arena; F is 1 when the compile stopped because the arena was full.
2092fn a_rec fd ulong to void
2093put mc 0 0
2094mputw 2334398928971328879 8
2095mputw 4422937691044257841 8
2096mputn len a_ar
2097mputw 263879357472 5
2098mputn get a_top 0
2099mputw 17281524405729056 7
2100mputn get a_wst 0
2101mputw 67535885395488 6
2102mputn get a_fl 0
2103g = ulong 0
2104limit = ulong 21
2105if ne get objmode 0 0
2106limit = ulong 23
2107end
2108while lt g limit
2109mputb 32
2110a_gname g
2111mputb 61
2112mputn a_gcount g
2113mputb 47
2114mputn a_gwords g
2115g = add g 1
2116end
2117mputb 32
2118mputw 4424626557984269667 8
2119mputn get a_cel 0
2120mputb 10
2121w = write int fd msg 0 get mc 0
2122end
2123
2124note ---- arena regions (generated by the one-off codemod; region: name, group, kind) ----
2125note 0 inp group 0 (INP) bytes
2126note 1 out group 1 (OUT) bytes
2127note 2 sitebuf group 2 (SITE) bytes
2128note 3 nm_name group 3 (NM) ulong x1
2129note 4 nm_reg group 3 (NM) uchar in a word x1
2130note 5 nm_type group 3 (NM) uchar in a word x1
2131note 6 nm_len group 3 (NM) ulong x1
2132note 7 nm_kind group 3 (NM) uchar in a word x1
2133note 8 nm_addr group 3 (NM) ulong x1
2134note 9 nm_fv group 3 (NM) uchar in a word x1
2135note 10 nm_pb group 3 (NM) uchar in a word x1
2136note 11 nm_pl group 3 (NM) uchar in a word x1
2137note 12 nm_lay group 3 (NM) uchar in a word x1
2138note 13 nm_fr group 3 (NM) uchar in a word x1
2139note 14 nm_lr group 3 (NM) uchar in a word x1
2140note 15 nm_nx group 3 (NM) ulong x1
2141note 16 nm_h group 4 (NMH) ulong x1
2142note 17 ln_o group 5 (LN) ulong x1
2143note 18 ln_l group 5 (LN) uchar in a word x1
2144note 19 ln_x group 5 (LN) ulong x1
2145note 20 ln_h group 6 (LNH) ulong x1
2146note 21 fn_name group 7 (FN) ulong x1
2147note 22 fn_addr group 7 (FN) ulong x1
2148note 23 fn_ret group 7 (FN) uchar in a word x1
2149note 24 fn_np group 7 (FN) uchar in a word x1
2150note 25 fn_nmlen group 7 (FN) ulong x1
2151note 26 fn_off group 7 (FN) ulong x1
2152note 27 fn_inl group 7 (FN) uchar in a word x1
2153note 28 fn_body group 7 (FN) ulong x1
2154note 29 fn_bln group 7 (FN) ulong x1
2155note 30 settled group 7 (FN) uchar in a word x1
2156note 31 reach group 7 (FN) uchar in a word x1
2157note 32 fn_exp group 7 (FN) uchar in a word x1
2158note 33 fn_nx group 7 (FN) ulong x1
2159note 34 fn_pn group 7 (FN) ulong x6
2160note 35 fn_pt group 7 (FN) uchar in a word x6
2161note 36 fn_pl group 7 (FN) ulong x6
2162note 37 fn_pk group 7 (FN) uchar in a word x6
2163note 38 fn_play group 7 (FN) uchar in a word x6
2164note 39 fn_pfr group 7 (FN) uchar in a word x6
2165note 40 fn_h group 8 (FNH) ulong x1
2166note 41 callsite group 9 (CALL) ulong x1
2167note 42 callfrom group 9 (CALL) ulong x1
2168note 43 callto group 9 (CALL) ulong x1
2169note 44 tsite group 10 (TRAP) ulong x1
2170note 45 tcode group 10 (TRAP) ulong x1
2171note 46 xasite group 11 (XA) ulong x1
2172note 47 xavalue group 11 (XA) ulong x1
2173note 48 xexsite group 12 (XE) ulong x1
2174note 49 bkind group 13 (BLK) ulong x1
2175note 50 bbr group 13 (BLK) ulong x1
2176note 51 bhead group 13 (BLK) ulong x1
2177note 52 breg group 13 (BLK) ulong x1
2178note 53 btyp group 13 (BLK) ulong x1
2179note 54 bnames group 13 (BLK) ulong x1
2180note 55 bheld group 13 (BLK) ulong x1
2181note 56 bdead group 13 (BLK) ulong x1
2182note 57 brot group 13 (BLK) ulong x1
2183note 58 bkk group 13 (BLK) ulong x1
2184note 59 bkr group 13 (BLK) ulong x1
2185note 60 bk0 group 13 (BLK) ulong x1
2186note 61 bc0 group 13 (BLK) ulong x1
2187note 62 u_cur group 13 (BLK) ulong x1
2188note 63 u_line group 13 (BLK) ulong x1
2189note 64 u_it group 13 (BLK) ulong x1
2190note 65 u_k group 13 (BLK) ulong x1
2191note 66 u_nn group 13 (BLK) ulong x1
2192note 67 u_held group 13 (BLK) ulong x1
2193note 68 fz_ent group 13 (BLK) ulong x16
2194note 69 fz_thn group 13 (BLK) ulong x16
2195note 70 brkpos group 14 (BRK) ulong x1
2196note 71 brkblk group 14 (BRK) ulong x1
2197note 72 cpos group 15 (CONT) ulong x1
2198note 73 cblk group 15 (CONT) ulong x1
2199note 74 ilp group 16 (ILP) ulong x1
2200note 75 ie_from group 17 (IE) ulong x1
2201note 76 ie_to group 17 (IE) ulong x1
2202note 77 fr group 18 (DEP) ulong x32
2203note 78 fwv group 18 (DEP) ulong x1
2204note 79 ul_k group 18 (DEP) ulong x6
2205note 80 ul_v group 18 (DEP) ulong x6
2206note 81 k_deg group 19 (KF) ulong x1
2207note 82 k_st group 19 (KF) ulong x1
2208note 83 k_cu group 19 (KF) ulong x1
2209note 84 k_q group 19 (KF) ulong x1
2210note 85 k_ed group 20 (KC) ulong x1
2211fn a_defs to void
2212a_def 0 0 0
2213a_def 1 1 0
2214a_def 2 2 0
2215a_def 3 3 1
2216a_def 4 3 1
2217a_def 5 3 1
2218a_def 6 3 1
2219a_def 7 3 1
2220a_def 8 3 1
2221a_def 9 3 1
2222a_def 10 3 1
2223a_def 11 3 1
2224a_def 12 3 1
2225a_def 13 3 1
2226a_def 14 3 1
2227a_def 15 3 1
2228a_def 16 4 1
2229a_def 17 5 1
2230a_def 18 5 1
2231a_def 19 5 1
2232a_def 20 6 1
2233a_def 21 7 1
2234a_def 22 7 1
2235a_def 23 7 1
2236a_def 24 7 1
2237a_def 25 7 1
2238a_def 26 7 1
2239a_def 27 7 1
2240a_def 28 7 1
2241a_def 29 7 1
2242a_def 30 7 1
2243a_def 31 7 1
2244a_def 32 7 1
2245a_def 33 7 1
2246a_def 34 7 6
2247a_def 35 7 6
2248a_def 36 7 6
2249a_def 37 7 6
2250a_def 38 7 6
2251a_def 39 7 6
2252a_def 40 8 1
2253a_def 41 9 1
2254a_def 42 9 1
2255a_def 43 9 1
2256a_def 44 10 1
2257a_def 45 10 1
2258a_def 46 11 1
2259a_def 47 11 1
2260a_def 48 12 1
2261a_def 49 13 1
2262a_def 50 13 1
2263a_def 51 13 1
2264a_def 52 13 1
2265a_def 53 13 1
2266a_def 54 13 1
2267a_def 55 13 1
2268a_def 56 13 1
2269a_def 57 13 1
2270a_def 58 13 1
2271a_def 59 13 1
2272a_def 60 13 1
2273a_def 61 13 1
2274a_def 62 13 1
2275a_def 63 13 1
2276a_def 64 13 1
2277a_def 65 13 1
2278a_def 66 13 1
2279a_def 67 13 1
2280a_def 68 13 16
2281a_def 69 13 16
2282a_def 70 14 1
2283a_def 71 14 1
2284a_def 72 15 1
2285a_def 73 15 1
2286a_def 74 16 1
2287a_def 75 17 1
2288a_def 76 17 1
2289a_def 77 18 32
2290a_def 78 18 1
2291a_def 79 18 6
2292a_def 80 18 6
2293a_def 81 19 1
2294a_def 82 19 1
2295a_def 83 19 1
2296a_def 84 19 1
2297a_def 85 20 1
2298note Object-only local stack and call-stack cost: lazy, charged arena groups.
2299a_def 86 21 1
2300a_def 87 22 1
2301put a_nr 0 88
2302end
2303
2304note a_gname: the usage-record label of group g
2305fn a_gname g ulong to void
2306if eq g 21
2307mputw 474164650607 5
2308ret
2309end
2310if eq g 22
2311mputw 30518463020294767 7
2312ret
2313end
2314if eq g 0
2315mputw 7368297 3
2316ret
2317end
2318if eq g 1
2319mputw 7632239 3
2320ret
2321end
2322if eq g 2
2323mputw 1702127987 4
2324ret
2325end
2326if eq g 3
2327mputw 495622906222 5
2328ret
2329end
2330if eq g 4
2331mputw 7526466503272391022 8
2332ret
2333end
2334if eq g 5
2335mputw 1735290732 4
2336ret
2337end
2338if eq g 6
2339mputw 7526466503306014572 8
2340ret
2341end
2342if eq g 7
2343mputw 7564902 3
2344ret
2345end
2346if eq g 8
2347mputw 114844764761702 6
2348ret
2349end
2350if eq g 9
2351mputw 495740281187 5
2352ret
2353end
2354if eq g 10
2355mputw 495806673524 5
2356ret
2357end
2358if eq g 11
2359mputw 32198529635465336 7
2360ret
2361end
2362if eq g 12
2363mputw 32767063113480312 7
2364ret
2365end
2366if eq g 13
2367mputw 126905066941538 6
2368ret
2369end
2370if eq g 14
2371mputw 126905032733282 6
2372ret
2373end
2374if eq g 15
2375mputw 495874633571 5
2376ret
2377end
2378if eq g 16
2379mputw 127979060227689 6
2380ret
2381end
2382if eq g 17
2383mputw 28542653543771753 7
2384ret
2385end
2386if eq g 18
2387mputw 448630121828 5
2388ret
2389end
2390if eq g 19
2391mputw 121386218053995 6
2392ret
2393end
2394if eq g 20
2395mputw 7812726533262958955 8
2396ret
2397end
2398end
2399
2400note Table accesses are written inline, `get a_ar add get a_rb R i` / `put a_ar add get a_rb R i v`,
2401note checked only by a_ar's own length: every index is in its region by construction. A count
2402note grows only after a_need has given its group room for it, reads use indices below a count, links
2403note omc stored (each below a count) or hash buckets below the bucket count, and input bytes are read
2404note from region 0 at word 0, padded with 64 zero bytes (a_rdin). The lines whose registers did not
2405note fit inline use the calls below; a_g / a_gu / a_p check the region (a_oob, trap 3), as a_pc,
2406note a_bput and a_ib do. gate-nocaps, gate12 and gate-usage drive every group far past its first room.
2407note The argument holds only when the count that bounds an index is the count of the region's own group:
2408note rscan once read the calls (group 9) at an inline edge's index (group 17), past them once the edges
2409note outnumbered the calls' room (trap 3, omc c52e986e and 1e628c80). gate-nocaps step 4 compiles a unit
2410note past every group's first room with a checked twin of this file (each inline access the checked call).
2411fn a_g r ulong i ulong to ulong
2412if ge i get a_rw r
2413a_oob i
2414end
2415ret get a_ar add get a_rb r i
2416end
2417
2418fn a_gu r ulong i ulong to uchar
2419if ge i get a_rw r
2420a_oob i
2421end
2422ret uchar get a_ar add get a_rb r i
2423end
2424
2425fn a_p r ulong i ulong v ulong to void
2426if ge i get a_rw r
2427a_oob i
2428end
2429put a_ar add get a_rb r i v
2430end
2431
2432
2433note mflush: complete a diagnostic/query stdout chunk or report compiler output error 2.
2434fn mflush to void
2435off = ulong 0
2436n = get mc 0
2437while lt off n
2438w = write 1 msg off sub n off
2439if le w 0
2440if ne get d2mode 0 0
2441note d2site 623|mflush: standard output refused a diagnostic or query chunk
2442put d2site 0 623
2443fail 2
2444end
2445exit int 2
2446end
2447off = add off ulong w
2448end
2449put mc 0 0
2450end
2451
2452fn mputb b uchar to void
2453m = get mc 0
2454put msg m b
2455put mc 0 add m 1
2456end
2457
2458fn mputn v ulong to void
2459d = new uchar 20 0
2460i = ulong 0
2461x = v
2462put d 0 uchar add rem x 10 48
2463x = div x 10
2464i = add i 1
2465while gt x 0
2466put d i uchar add rem x 10 48
2467x = div x 10
2468i = add i 1
2469end
2470j = i
2471while gt j 0
2472j = sub j 1
2473mputb get d j
2474end
2475end
2476
2477note fail: write "omc: line N: error E" to stderr (fd 2) and exit with the code
2478fn fail code ulong to void
2479put mc 0 0
2480mputb 111
2481mputb 109
2482mputb 99
2483mputb 58
2484mputb 32
2485mputb 108
2486mputb 105
2487mputb 110
2488mputb 101
2489mputb 32
2490mputn add get line 0 get lbase 0
2491mputb 58
2492mputb 32
2493mputb 101
2494mputb 114
2495mputb 114
2496mputb 111
2497mputb 114
2498mputb 32
2499mputn code
2500if ne get d2mode 0 0
2501mputb 58
2502mputb 32
2503d2mean code
2504mputb 59
2505mputb 32
2506d2reason
2507end
2508mputb 10
2509w = write 2 msg 0 get mc 0
2510if ne get om2 0 0
2511if eq get om2m 0 1
2512drec code
2513end
2514end
2515if and ge get chkmode 0 1 le get chkmode 0 2
2516note A stdout failure cannot report another record to stdout.
2517if ne code 2
2518diagrec code
2519end
2520end
2521if ne get d2mode 0 0
2522d2record code
2523end
2524note An arena-full error 14, and any error of a usage unit, ends with the omc-use record (a_rec).
2525if or ne get a_fl 0 0 eq get chkmode 0 3
2526a_rec 2
2527end
2528exit int code
2529end
2530
2531note mputw: the first n bytes (at most 8) of the little-endian packed word w
2532fn mputw w ulong n ulong to void
2533i = ulong 0
2534x = w
2535while lt i n
2536mputb uchar and x 255
2537x = shr x 8
2538i = add i 1
2539end
2540end
2541
2542note dcol: the 1-based column of byte a in its line
2543fn dcol a ulong to ulong
2544j = a
2545go = true
2546while go
2547m = ulong 0
2548while and go lt m 999999
2549if eq j 0
2550go = false
2551else
2552if eq a_ib sub j 1 10
2553go = false
2554else
2555j = sub j 1
2556end
2557end
2558m = add m 1
2559end
2560end
2561ret add sub a j 1
2562end
2563
2564note dsev_w: sev= incomplete when the failure is on the end-of-input token (or inside a text literal cut by
2565note the end), unknown for an undeclared function or struct, else error
2566fn dsev_w code ulong to void
2567s = get dsev 0
2568if eq s 0
2569if eq get tk 0 3
2570s = ulong 1
2571end
2572if and eq code 22 ge get cur 0 get inlen 0
2573s = ulong 1
2574end
2575end
2576if eq s 1
2577mputw 7308339910638005865 8
2578mputw 25972 2
2579ret
2580end
2581if eq s 2
2582mputw 31093567915781749 7
2583ret
2584end
2585mputw 491496043109 5
2586end
2587
2588note dexp_w: expect= the class of token being read (end for an open function at the end of the input)
2589fn dexp_w code ulong to void
2590e = get dexp 0
2591if eq code 15
2592e = ulong 5
2593end
2594if or eq code 6 eq code 8
2595e = ulong 4
2596end
2597if eq e 1
2598mputw 435761734006 5
2599ret
2600end
2601if eq e 2
2602mputw 1701869940 4
2603ret
2604end
2605if eq e 3
2606mputw 1701667182 4
2607ret
2608end
2609if eq e 4
2610mputw 125779768604014 6
2611ret
2612end
2613if eq e 5
2614mputw 6581861 3
2615ret
2616end
2617if eq e 6
2618mputw 28550371718161774 7
2619ret
2620end
2621mputw 1685221239 4
2622end
2623
2624note dobl_w: obligation= from the code: 27 init, 28 ctor, 29 layout, 21 bounds, 14 growth, 12 regs, else -
2625fn dobl_w code ulong to void
2626if eq code 30
2627mputw 8386654075301556067 8
2628ret
2629end
2630if eq code 27
2631mputw 1953066601 4
2632ret
2633end
2634if eq code 28
2635mputw 1919906915 4
2636ret
2637end
2638if eq code 29
2639mputw 128047730221420 6
2640ret
2641end
2642if eq code 21
2643mputw 126875187113826 6
2644ret
2645end
2646if and eq code 14 ne get dobx 0 0
2647mputw 1953066601 4
2648ret
2649end
2650if eq code 14
2651mputw 114849429287527 6
2652ret
2653end
2654if eq code 12
2655mputw 1936156018 4
2656ret
2657end
2658mputb 45
2659end
2660
2661note mputh: one byte as two lowercase hex digits
2662fn mputh b ulong to void
2663hi = shr b 4
2664lo = and b 15
2665if lt hi 10
2666mputb uchar add hi 48
2667else
2668mputb uchar add hi 87
2669end
2670if lt lo 10
2671mputb uchar add lo 48
2672else
2673mputb uchar add lo 87
2674end
2675end
2676
2677note drec: the om2 diag machine record after the human line (spec 1): code, sev, line (the human line),
2678note col, the half-open byte span of the token being read, expect, found (at most 32 bytes, hex),
2679note obligation, profile
2680fn drec code ulong to void
2681put mc 0 0
2682mputw 7449351137626647919 8
2683mputw 4424052638528581920 8
2684mputn code
2685mputw 263979365152 5
2686dsev_w code
2687mputw 67505853393952 6
2688mputn add get line 0 get lbase 0
2689a = get tka 0
2690b = get tkb 0
2691if le b a
2692b = a
2693if gt get cur 0 a
2694b = get cur 0
2695end
2696end
2697if gt b get inlen 0
2698b = get inlen 0
2699end
2700mputw 263812244256 5
2701mputn dcol a
2702mputw 67544290456352 6
2703mputn add a get sbase 0
2704mputb 45
2705mputn add b get sbase 0
2706mputw 4428273620941825312 8
2707dexp_w code
2708mputw 17280399158765088 7
2709if eq a b
2710mputb 45
2711end
2712i = a
2713while and lt i b lt sub i a 32
2714mputh ulong uchar and shr get a_ar shr i 3 shl and i 7 3 255
2715i = add i 1
2716end
2717mputw 8386097683628191520 8
2718mputw 1030647657 4
2719dobl_w code
2720mputw 7308332183992823840 8
2721mputw 11210624683837 6
2722w = write 2 msg 0 get mc 0
2723end
2724
2725note emitb / emit: one byte / one 32-bit word (little-endian) to the output (region 1, eight bytes to a
2726note word). The output grows with the arena (a_ogrow); there is no per-function budget: the OM-2 65536-word
2727note bound is gone, and a long function keeps its trap branches in reach through stub islands (island).
2728fn emitb b uchar to void
2729o = get oc 0
2730if ge o get a_gc 1
2731a_ogrow o
2732end
2733x = add get a_rb 1 shr o 3
2734s = shl and o 7 3
2735y = get a_ar x
2736y = and y not shl ulong 255 s
2737y = or y shl ulong b s
2738put a_ar x y
2739put oc 0 add o 1
2740end
2741
2742fn emit w ulong to void
2743if ne get xtarget 0 0
2744note d2site 8|emit: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xtarget 0 0
2745put d2site 0 8
2746fail 25
2747end
2748o = get oc 0
2749if ne and o 3 0
2750emitb uchar and w 255
2751emitb uchar and shr w 8 255
2752emitb uchar and shr w 16 255
2753emitb uchar and shr w 24 255
2754ret
2755end
2756if ge add o 3 get a_gc 1
2757a_ogrow add o 3
2758end
2759x = add get a_rb 1 shr o 3
2760s = shl and o 4 3
2761y = get a_ar x
2762y = and y not shl ulong 4294967295 s
2763y = or y shl and w 4294967295 s
2764put a_ar x y
2765put oc 0 add o 4
2766end
2767
2768note a_ogrow: the output will hold byte o. Two machine boundaries, each error 14 at its first byte, never a
2769note table's: AArch64 output stops at 134217728 bytes, the reach of B and BL (imm26, 2^27 bytes), so every
2770note call and jump of a unit stays encodable and bdisp's error 24 for them stays a defence (security673
2771note gate669 probes 16 and 17); x86 code is mapped from 0x400000 below the pools at 0x10000000, so its
2772note output ends at byte 264241152.
2773fn a_ogrow o ulong to void
2774lim = ulong 264241152
2775if eq get xtarget 0 0
2776lim = ulong 134217728
2777end
2778note Non-executable object metadata has no instruction-displacement bound; allocation is checked.
2779if ne get objmeta 0 0
2780lim = ulong 9223372036854775807
2781end
2782if ge o lim
2783note d2site 9|a_ogrow: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge o lim
2784put d2site 0 9
2785fail 14
2786end
2787if ge o get a_gp 1
2788a_need 1 o
2789end
2790end
2791
2792note tok_num: the word at [ts,cur) is [-]decimal, at most 20 digits, from -2^63 to 2^64 - 1 (error 6
2793note bad number, 8 out of range). tw = its raw 64 bits (a negative one as two's complement); tbig = 1
2794note when it is 2^63 or more (only a ulong holds it), else 0. As om4's TK_NUM.
2795note The float-marker scan walks the word in chunks of at most 999999 bytes: a single loop's hidden
2796note 1000000-pass guard trapped 4 on a decimal word of 1000001 digits, which must refuse with error 6 (#671).
2797fn tok_num to void
2798if ne get om2 0 0
2799if ne tok_hex 0
2800ret
2801end
2802end
2803p = get ts 0
2804e = get cur 0
2805fl = false
2806i = p
2807while lt i e
2808c = sub e i
2809if gt c 999999
2810c = ulong 999999
2811end
2812for k ulong c
2813b = a_ib add i k
2814if or or or eq b 46 eq b 101 eq b 69 eq b 102
2815fl = true
2816end
2817end
2818i = add i c
2819end
2820if fl
2821put tk 0 5
2822ret
2823end
2824minus = false
2825if eq uchar and shr get a_ar shr p 3 shl and p 7 3 255 45
2826minus = true
2827p = add p 1
2828end
2829ndig = sub e p
2830if eq ndig 0
2831note d2site 10|tok_num: malformed number or token; condition if eq ndig 0
2832put d2site 0 10
2833nfail 6
2834end
2835if gt ndig 20
2836note d2site 11|tok_num: malformed number or token; condition if gt ndig 20
2837put d2site 0 11
2838nfail 6
2839end
2840v = ulong 0
2841lim = ulong 1844674407370955161
2842i = p
2843while lt i e
2844d = sub ulong a_ib i 48
2845if gt d 9
2846note d2site 12|tok_num: malformed number or token; condition if gt d 9
2847put d2site 0 12
2848nfail 6
2849end
2850if gt v lim
2851note d2site 13|tok_num: number out of range for its type or place; condition if gt v lim
2852put d2site 0 13
2853nfail 8
2854end
2855if and eq v lim gt d 5
2856note d2site 14|tok_num: number out of range for its type or place; condition if and eq v lim gt d 5
2857put d2site 0 14
2858nfail 8
2859end
2860v = add mul v 10 d
2861i = add i 1
2862end
2863half = shl ulong 1 63
2864put tbig 0 0
2865if minus
2866if gt v half
2867note d2site 15|tok_num: number out of range for its type or place; condition if gt v half
2868put d2site 0 15
2869nfail 8
2870end
2871put tw 0 sub ulong 0 v
2872else
2873if ge v half
2874put tbig 0 1
2875end
2876put tw 0 v
2877end
2878put tk 0 2
2879end
2880
2881note tok_text: a text literal starting at the opening quote. tw = first byte offset, tl = source length
2882note (escapes not yet decoded). Ends at an unescaped '"' on the same line, followed by a blank/end. Err 22.
2883note (Loops over the input are two loops, the inner under 1000000 passes: om4 has no pass limit.)
2884fn tok_text to void
2885put cur 0 add get cur 0 1
2886put tw 0 get cur 0
2887go = true
2888while go
2889n = ulong 0
2890while and go lt n 999999
2891if ge get cur 0 get inlen 0
2892note d2site 16|tok_text: malformed text literal; condition if ge get cur 0 get inlen 0
2893put d2site 0 16
2894fail 22
2895end
2896b = a_ib get cur 0
2897if eq b 10
2898note d2site 17|tok_text: malformed text literal; condition if eq b 10
2899put d2site 0 17
2900fail 22
2901end
2902if eq b 34
2903go = false
2904else
2905put cur 0 add get cur 0 1
2906if eq b 92
2907if ge get cur 0 get inlen 0
2908note d2site 18|tok_text: malformed text literal; condition if ge get cur 0 get inlen 0
2909put d2site 0 18
2910fail 22
2911end
2912if eq a_ib get cur 0 10
2913note d2site 19|tok_text: malformed text literal; condition if eq a_ib get cur 0 10
2914put d2site 0 19
2915fail 22
2916end
2917put cur 0 add get cur 0 1
2918end
2919end
2920n = add n 1
2921end
2922end
2923put tl 0 sub get cur 0 get tw 0
2924put cur 0 add get cur 0 1
2925put tk 0 4
2926if lt get cur 0 get inlen 0
2927if gt a_ib get cur 0 32
2928note d2site 20|tok_text: malformed text literal; condition if gt a_ib get cur 0 32
2929put d2site 0 20
2930fail 22
2931end
2932end
2933end
2934
2935note tok2: a word at cur with first byte c; packs 8 bytes into tw, sets tl and ts. A '"' is a text; a
2936note first byte '-' or a digit is a number.
2937fn tok2 c uchar to void
2938if eq c 34
2939tok_text
2940ret
2941end
2942put ts 0 get cur 0
2943if or eq c 40 eq c 41
2944put tw 0 ulong c
2945put tl 0 1
2946put cur 0 add get cur 0 1
2947put tk 0 1
2948ret
2949end
2950w = ulong 0
2951sh = ulong 0
2952n = ulong 0
2953go = true
2954while go
2955m = ulong 0
2956while and go lt m 999999
2957if ge get cur 0 get inlen 0
2958go = false
2959else
2960b = a_ib get cur 0
2961if le b 32
2962go = false
2963else
2964if or eq b 40 eq b 41
2965go = false
2966else
2967if lt n 8
2968w = or w shl ulong b sh
2969sh = add sh 8
2970end
2971n = add n 1
2972put cur 0 add get cur 0 1
2973end
2974end
2975end
2976m = add m 1
2977end
2978end
2979put tw 0 w
2980put tl 0 n
2981put tw8 0 w
2982if and gt n 8 le n 63
2983if ne c 45
2984if or lt c 48 gt c 57
2985note intern the long name (the long-names notes above the name table): its index from ln_intern
2986put tw 0 add 1 shl ln_intern get ts 0 n 8
2987end
2988end
2989end
2990f = a_ib get ts 0
2991isnum = false
2992if eq f 45
2993isnum = true
2994end
2995if and ge f 48 le f 57
2996isnum = true
2997end
2998if isnum
2999tok_num
3000else
3001put tk 0 1
3002end
3003end
3004
3005note tok: next word, skipping blanks (space, tab, carriage return); newline is end of line (kind 0) and
3006note bumps the line number; another byte below 32 is error 16; the end of the input is kind 3. om4 TOK.
3007fn tok to void
3008go = true
3009while go
3010n = ulong 0
3011while and go lt n 999999
3012if ge get cur 0 get inlen 0
3013go = false
3014else
3015c = a_ib get cur 0
3016if or or eq c 32 eq c 9 eq c 13
3017put cur 0 add get cur 0 1
3018else
3019if eq c 10
3020put tka 0 get cur 0
3021put tkb 0 add get cur 0 1
3022put cur 0 add get cur 0 1
3023put line 0 add get line 0 1
3024put tk 0 0
3025ret
3026end
3027put tka 0 get cur 0
3028put tkb 0 add get cur 0 1
3029if lt c 32
3030note d2site 21|tok: syntax: unknown or misplaced word; condition if lt c 32
3031put d2site 0 21
3032fail 16
3033end
3034put tka 0 get cur 0
3035put tkb 0 get cur 0
3036tok2 c
3037put tkb 0 get cur 0
3038ret
3039end
3040end
3041n = add n 1
3042end
3043end
3044put tka 0 get inlen 0
3045put tkb 0 get inlen 0
3046put tk 0 3
3047end
3048
3049note ======== keyword lookup (original om4 KWTAB plus native host words 100..177, flock 197, execpure 198, execenv 233, prlimit 235 and cpuset..getprio 236..240) ========
3050note genkw.awk describes the original om4 table only; retain the native host extension on regeneration.
3051note efi (178) is a keyword only under `target x86efi`; gate18 checks that scoped entry separately.
3052note kwa: the words of target a64efi, 0 for any other word: efi (178) and the firmware words fwcall 250,
3053note fwld 251, fwst 252, fwsys 253, fwadr 254. They are not in fn kw (the chain gate18 compares with
3054note genkw.awk), so under every other target these stay ordinary names. Read where a value starts.
3055fn kwa w ulong to ulong
3056if eq w 6907493
3057ret 178
3058end
3059if eq w 119212746176358
3060ret 250
3061end
3062if eq w 1684830054
3063ret 251
3064end
3065if eq w 1953724262
3066ret 252
3067end
3068if eq w 495958849382
3069ret 253
3070end
3071if eq w 491310380902
3072ret 254
3073end
3074if eq w 1886353254
3075ret 255
3076end
3077ret 0
3078end
3079
3080note kwx: w is reserved under the current target beyond fn kw's chain: under target a64efi the words of
3081note fn kwa. A program may not define a variable, a global, a constant, a text or a function with such
3082note a name (error 16, as for a keyword; checked where every name is entered, newname and addname): where
3083note a value starts the word would win and the name be ignored.
3084fn kwx w ulong to ulong
3085if eq get xefa 0 0
3086ret 0
3087end
3088ret kwa w
3089end
3090
3091fn kw w ulong to ulong
3092if and eq w 6907493 eq get xtarget 0 2
3093ret 178
3094end
3095if eq w 7310034270740117605
3096ret 198
3097end
3098if eq w 6584163
3099ret 132
3100end
3101packed = or ulong 114 shl ulong 101 8
3102packed = or packed shl ulong 97 16
3103packed = or packed shl ulong 100 24
3104packed = or packed shl ulong 108 32
3105packed = or packed shl ulong 110 40
3106packed = or packed shl ulong 107 48
3107if eq w packed
3108ret 133
3109end
3110packed = or ulong 115 shl ulong 111 8
3111packed = or packed shl ulong 99 16
3112packed = or packed shl ulong 107 24
3113packed = or packed shl ulong 111 32
3114packed = or packed shl ulong 112 40
3115packed = or packed shl ulong 116 48
3116if eq w packed
3117ret 134
3118end
3119if eq w 120325193752946
3120ret 135
3121end
3122if eq w 128017463930469
3123ret 136
3124end
3125if eq w 28254586011020901
3126ret 137
3127end
3128if eq w 491394459747
3129ret 138
3130end
3131if eq w 109326067987558
3132ret 139
3133end
3134if eq w 1952543859
3135ret 140
3136end
3137if eq w 1802398060
3138ret 141
3139end
3140if eq w 118122009688435
3141ret 142
3142end
3143if eq w 431366170723
3144ret 143
3145end
3146if eq w 32496501618073958
3147ret 144
3148end
3149if eq w 110404104906087
3150ret 145
3151end
3152if eq w 28263450605282663
3153ret 146
3154end
3155if eq w 110403870025063
3156ret 147
3157end
3158if eq w 28263390475740519
3159ret 148
3160end
3161if eq w 499851228012
3162ret 149
3163end
3164if eq w 7310575174812004980
3165ret 150
3166end
3167if eq w 474450192483
3168ret 151
3169end
3170if eq w 500152823651
3171ret 152
3172end
3173if eq w 125796981695334
3174ret 153
3175end
3176if eq w 28263429314995559
3177ret 154
3178end
3179if eq w 461497265525
3180ret 155
3181end
3182if eq w 109326135157862
3183ret 156
3184end
3185if eq w 431215175021
3186ret 157
3187end
3188if eq w 110404071351667
3189ret 158
3190end
3191if eq w 28263390660289895
3192ret 159
3193end
3194if eq w 28263390660289907
3195ret 160
3196end
3197if eq w 431130767984
3198ret 161
3199end
3200if eq w 111550659721072
3201ret 162
3202end
3203if eq w 110404071351655
3204ret 163
3205end
3206if eq w 126883592042867
3207ret 164
3208end
3209if eq w 7959953343641905267
3210ret 165
3211end
3212if eq w 119247140709732
3213ret 166
3214end
3215if eq w 131277528260973
3216ret 167
3217end
3218if eq w 31647734493634925
3219ret 168
3220end
3221if eq w 28254586010624365
3222ret 169
3223end
3224if eq w 7310584035480199533
3225ret 170
3226end
3227if eq w 30518463021081956
3228ret 171
3229end
3230if eq w 119247140124277
3231ret 172
3232end
3233if eq w 32198529639276909
3234ret 173
3235end
3236if eq w 127978875937133
3237ret 174
3238end
3239if eq w 127979077263725
3240ret 175
3241end
3242if eq w 28266723420430701
3243ret 176
3244end
3245if eq w 28268896573219181
3246ret 177
3247end
3248if eq w 30527267904513654
3249ret 228
3250end
3251if eq w 31632320040101494
3252ret 229
3253end
3254if eq w 8606486010553525878
3255ret 230
3256end
3257if eq w 28260147925448293
3258ret 231
3259end
3260if eq w 31932469534615158
3261ret 232
3262end
3263if eq w 32767015939502704
3264ret 235
3265end
3266if eq w 127979077595235
3267ret 236
3268end
3269if eq w 127978876268643
3270ret 237
3271end
3272if eq w 131320478265443
3273ret 238
3274end
3275if eq w 31359662648747379
3276ret 239
3277end
3278if eq w 31359662648747367
3279ret 240
3280end
3281if eq w 119247139530347
3282ret 241
3283end
3284if eq w 123563749434987
3285ret 242
3286end
3287if eq w 126879548073579
3288ret 243
3289end
3290if eq w 461229747302
3291ret 197
3292end
3293if eq w 1819242338
3294ret 1
3295end
3296if eq w 491260502901
3297ret 2
3298end
3299if eq w 14453
3300ret 2
3301end
3302if eq w 128034844210037
3303ret 3
3304end
3305if eq w 3551605
3306ret 3
3307end
3308if eq w 1953393013
3309ret 4
3310end
3311if eq w 3289973
3312ret 4
3313end
3314if eq w 444234427509
3315ret 5
3316end
3317if eq w 3421813
3318ret 5
3319end
3320if eq w 1702132066
3321ret 6
3322end
3323if eq w 14441
3324ret 6
3325end
3326if eq w 500136110195
3327ret 7
3328end
3329if eq w 3551593
3330ret 7
3331end
3332if eq w 7630441
3333ret 8
3334end
3335if eq w 3289961
3336ret 8
3337end
3338if eq w 1735290732
3339ret 9
3340end
3341if eq w 3421801
3342ret 9
3343end
3344if eq w 6579297
3345ret 33
3346end
3347if eq w 6452595
3348ret 34
3349end
3350if eq w 7107949
3351ret 35
3352end
3353if eq w 7760228
3354ret 36
3355end
3356if eq w 7169394
3357ret 37
3358end
3359if eq w 6581857
3360ret 38
3361end
3362if eq w 29295
3363ret 39
3364end
3365if eq w 7499640
3366ret 40
3367end
3368if eq w 7104627
3369ret 41
3370end
3371if eq w 7497843
3372ret 42
3373end
3374if eq w 29029
3375ret 43
3376end
3377if eq w 25966
3378ret 44
3379end
3380if eq w 29804
3381ret 45
3382end
3383if eq w 25964
3384ret 46
3385end
3386if eq w 29799
3387ret 47
3388end
3389if eq w 25959
3390ret 48
3391end
3392if eq w 6776174
3393ret 49
3394end
3395if eq w 7630702
3396ret 50
3397end
3398if eq w 7628135
3399ret 51
3400end
3401if eq w 7234924
3402ret 52
3403end
3404if eq w 1684104562
3405ret 53
3406end
3407if eq w 435744764535
3408ret 54
3409end
3410if eq w 1702195828
3411ret 55
3412end
3413if eq w 435728179558
3414ret 56
3415end
3416if eq w 2003134838
3417ret 57
3418end
3419if eq w 1953064037
3420ret 58
3421end
3422if eq w 28262
3423ret 64
3424end
3425if eq w 28532
3426ret 65
3427end
3428if eq w 6581861
3429ret 66
3430end
3431if eq w 26217
3432ret 67
3433end
3434if eq w 1702063205
3435ret 68
3436end
3437if eq w 435610544247
3438ret 69
3439end
3440if eq w 431349919586
3441ret 70
3442end
3443if eq w 7499622
3444ret 71
3445end
3446if eq w 7628146
3447ret 72
3448end
3449if eq w 61
3450ret 73
3451end
3452if eq w 40
3453ret 74
3454end
3455if eq w 41
3456ret 75
3457end
3458if eq w 1684631414
3459ret 76
3460end
3461if eq w 119165519096935
3462ret 78
3463end
3464if eq w 1954047348
3465ret 79
3466end
3467if eq w 7632240
3468ret 80
3469end
3470if eq w 1701147238
3471ret 81
3472end
3473if eq w 1953069157
3474ret 82
3475end
3476if eq w 1702129518
3477ret 83
3478end
3479if eq w 7824750
3480ret 84
3481end
3482if eq w 461195539042
3483ret 86
3484end
3485if eq w 1885434484
3486ret 87
3487end
3488if eq w 7239535
3489ret 77
3490end
3491if eq w 7308604897168158579
3492ret 131
3493end
3494if eq w 126918101919090
3495ret 130
3496end
3497if eq w 7453301735350958181
3498ret 124
3499end
3500if eq w 32481142782190962
3501ret 125
3502end
3503if eq w 491394461042
3504ret 126
3505end
3506if eq w 28263429247363435
3507ret 127
3508end
3509if eq w 32480013273033072
3510ret 128
3511end
3512if eq w 110404021020007
3513ret 129
3514end
3515if eq w 122498715312503
3516ret 123
3517end
3518if eq w 32497639802299751
3519ret 113
3520end
3521if eq w 32760384594014051
3522ret 114
3523end
3524if eq w 1684957538
3525ret 115
3526end
3527if eq w 28263429381382519
3528ret 116
3529end
3530if eq w 499851228006
3531ret 117
3532end
3533if eq w 1986225522
3534ret 118
3535end
3536if eq w 1684956531
3537ret 119
3538end
3539if eq w 32491051338263667
3540ret 120
3541end
3542if eq w 128017462948449
3543ret 121
3544end
3545if eq w 28254586010038881
3546ret 122
3547end
3548if eq w 111546465018726
3549ret 100
3550end
3551if eq w 427055215462
3552ret 101
3553end
3554if eq w 110429739705190
3555ret 102
3556end
3557if eq w 461262648166
3558ret 103
3559end
3560if eq w 33607047151054707
3561ret 104
3562end
3563if eq w 121382024472940
3564ret 105
3565end
3566if eq w 128026086171489
3567ret 106
3568end
3569if eq w 1802661734
3570ret 107
3571end
3572if eq w 431215375716
3573ret 108
3574end
3575if eq w 126918153105261
3576ret 109
3577end
3578if eq w 474148269926
3579ret 110
3580end
3581if eq w 118121959288437
3582ret 111
3583end
3584if eq w 32204027264196973
3585ret 112
3586end
3587if eq w 127970521019507
3588ret 85
3589end
3590if eq w 3289958
3591ret 88
3592end
3593if eq w 3421798
3594ret 89
3595end
3596if eq w 32777959416031586
3597ret 90
3598end
3599if eq w 500136244070
3600ret 91
3601end
3602if eq w 1935827302
3603ret 92
3604end
3605if eq w 1852403046
3606ret 93
3607end
3608if eq w 2019650918
3609ret 94
3610end
3611if eq w 112628629924211
3612ret 95
3613end
3614if eq w 7381246293360141935
3615ret 96
3616end
3617if eq w 7310870969309884259
3618ret 97
3619end
3620if eq w 7234314147887146352
3621ret 220
3622end
3623if eq w 32480013390212976
3624ret 221
3625end
3626if eq w 29118836274783603
3627ret 222
3628end
3629if eq w 7959665
3630ret 223
3631end
3632if eq w 7305804402314801251
3633ret 199
3634end
3635if eq w 8674333540260081763
3636ret 200
3637end
3638if eq w 7308604897285727600
3639ret 224
3640end
3641if eq w 6384998
3642ret 227
3643end
3644if eq w 33335428990204005
3645ret 233
3646end
3647if eq w 28542713606205029
3648ret 244
3649end
3650if eq get om2 0 0
3651ret 0
3652end
3653ret kw2 w
3654end
3655
3656note ======== OM-2 words (spec/omegese-om2.md): reserved only in an OM-2 unit. rotr 59, rotl 60 are
3657note binary operators; dit 225 and scrub 226 are program-mode value words (OMEGESE 9.13.1); the rest are
3658note statement and declaration words of later sections. ========
3659fn kw2 w ulong to ulong
3660if eq w 1920233330
3661ret 59
3662end
3663if eq w 1819570034
3664ret 60
3665end
3666if eq w 119212982038133
3667ret 181
3668end
3669if eq w 111524889521769
3670ret 182
3671end
3672if eq w 448612627046
3673ret 183
3674end
3675if eq w 8386654075301880417
3676ret 184
3677end
3678if eq w 1818322291
3679ret 185
3680end
3681if eq w 1852141679
3682ret 186
3683end
3684if eq w 495606067048
3685ret 187
3686end
3687if eq w 128047730221420
3688ret 188
3689end
3690if eq w 431315315046
3691ret 189
3692end
3693if eq w 29793
3694ret 190
3695end
3696if eq w 111516484659564
3697ret 191
3698end
3699if eq w 6777186
3700ret 192
3701end
3702if eq w 1953653104
3703ret 193
3704end
3705if eq w 7632239
3706ret 194
3707end
3708if eq w 128034844735589
3709ret 195
3710end
3711if eq w 7565423
3712ret 196
3713end
3714if eq w 7629156
3715ret 225
3716end
3717if eq w 422877225843
3718ret 226
3719end
3720ret 0
3721end
3722
3723note nfail: a bad number (diag expect=number); unkfail: an undeclared function or struct (sev=unknown)
3724fn nfail code ulong to void
3725put dexp 0 4
3726fail code
3727end
3728
3729fn unkfail code ulong to void
3730put dsev 0 2
3731put dexp 0 3
3732fail code
3733end
3734
3735note lineis: the n bytes at q are the packed word w and the line ends right after them
3736fn lineis q ulong w ulong n ulong to ulong
3737e = get inlen 0
3738if gt add q n e
3739ret 0
3740end
3741i = ulong 0
3742x = w
3743while lt i n
3744if ne ulong a_ib add q i and x 255
3745ret 0
3746end
3747x = shr x 8
3748i = add i 1
3749end
3750r = add q n
3751if lt r e
3752if ne a_ib r 10
3753ret 0
3754end
3755end
3756ret 1
3757end
3758
3759note isnote: the word at p is note (the lexer ends a word at a blank, a parenthesis or the end)
3760fn isnote p ulong to ulong
3761e = get inlen 0
3762if gt add p 4 e
3763ret 0
3764end
3765i = ulong 0
3766x = ulong 1702129518
3767while lt i 4
3768if ne ulong a_ib add p i and x 255
3769ret 0
3770end
3771x = shr x 8
3772i = add i 1
3773end
3774r = add p 4
3775if lt r e
3776b = a_ib r
3777if and gt b 32 and ne b 40 ne b 41
3778ret 0
3779end
3780end
3781ret 1
3782end
3783
3784note chk_mode: the lead line check (1), next (2) or usage (3). usage compiles the unit as usual and, in
3785note place of the artifact, writes the omc-use record (a_rec) to stdout and exits 0; an error writes the
3786note human line and then the record to stderr. It is how the usage gate reads what a unit asked of the
3787note arena without changing the unit's profile.
3788fn chk_mode q ulong to ulong
3789if ne lineis q 127970252055151 6 0
3790ret 4
3791end
3792if ne lineis q 461229090915 5 0
3793ret 1
3794end
3795if ne lineis q 1954047342 4 0
3796ret 2
3797end
3798if ne lineis q 435526136693 5 0
3799ret 3
3800end
3801ret 0
3802end
3803
3804fn chk_lead to void
3805e = get inlen 0
3806p = ulong 0
3807ln = ulong 1
3808go = true
3809while go
3810m = ulong 0
3811while and go lt m 999999
3812q = skipbl p
3813if ge q e
3814go = false
3815else
3816if eq a_ib q 10
3817p = add q 1
3818ln = add ln 1
3819else
3820if ne isnote q 0
3821p = skipln q
3822ln = add ln 1
3823else
3824k = chk_mode q
3825if ne k 0
3826put chkmode 0 k
3827put chkln 0 ln
3828put sbase 0 skipln q
3829end
3830go = false
3831end
3832end
3833end
3834m = add m 1
3835end
3836end
3837end
3838
3839note om2lead: skip blank lines and note lines; when the next line is exactly om2 (1), om2 diag (2) or
3840note om2 fmt (3) the unit is OM-2: om2, om2m, om2ln, om2pos. Anything else leaves the unit OM-1.
3841fn om2lead to void
3842e = get inlen 0
3843p = ulong 0
3844ln = ulong 1
3845if ne get chkmode 0 0
3846p = get sbase 0
3847ln = add get chkln 0 1
3848end
3849go = true
3850while go
3851m = ulong 0
3852while and go lt m 999999
3853q = skipbl p
3854if ge q e
3855go = false
3856else
3857if eq a_ib q 10
3858p = add q 1
3859ln = add ln 1
3860else
3861if ne isnote q 0
3862p = skipln q
3863ln = add ln 1
3864else
3865r = ulong 0
3866if eq q p
3867if ne lineis q 3304815 3 0
3868r = ulong 1
3869end
3870if ne lineis q 7449351137405332847 8 0
3871r = ulong 2
3872end
3873if ne lineis q 32771382692703599 7 0
3874r = ulong 3
3875end
3876if eq r 0
3877r = cp_mode q
3878end
3879end
3880if ne r 0
3881put om2 0 1
3882put om2m 0 sub r 1
3883put om2ln 0 ln
3884put om2pos 0 q
3885end
3886go = false
3887end
3888end
3889end
3890m = add m 1
3891end
3892end
3893end
3894
3895note ---- om2 fmt (spec 2, errata E4, E6): only when the input's first line, at byte 0, is om2 fmt (an om2
3896note fmt line elsewhere is error 16). The rest (the bytes after the first LF) is compiled as a unit of
3897note its own (OM-1 or OM-2 by its own first line) and, when it is accepted, its canonical text is written
3898note instead of the artifact. A CR anywhere and blank lines at the end are error 6. Lines and spans are
3899note reported against the whole input.
3900global fst ulong 1
3901global fpend ulong 1
3902global fbo ulong 1
3903global fprp ulong 1
3904global flso ulong 1
3905
3906note fmttail: blank lines at the end of the rest (n bytes) are error 6, at the first such line
3907fn fmttail n ulong to void
3908lnb = ulong 0
3909lnl = ulong 1
3910ln = ulong 1
3911i = ulong 0
3912go = true
3913while go
3914m = ulong 0
3915while and go lt m 999999
3916if ge i n
3917go = false
3918else
3919b = a_ib i
3920if eq b 10
3921ln = add ln 1
3922else
3923if and ne b 32 ne b 9
3924lnb = add i 1
3925lnl = ln
3926end
3927end
3928i = add i 1
3929end
3930m = add m 1
3931end
3932end
3933bad = false
3934if eq lnb 0
3935if gt n 0
3936bad = true
3937lnl = ulong 0
3938end
3939end
3940k = lnb
3941fl = n
3942go = true
3943while go
3944m = ulong 0
3945while and go lt m 999999
3946if ge k n
3947go = false
3948else
3949if eq a_ib k 10
3950fl = k
3951go = false
3952end
3953k = add k 1
3954end
3955m = add m 1
3956end
3957end
3958if lt add fl 1 n
3959bad = true
3960end
3961if bad
3962put line 0 add lnl 1
3963put tka 0 lnb
3964put tkb 0 lnb
3965note d2site 22|fmttail: malformed number or token; condition if bad
3966put d2site 0 22
3967fail 6
3968end
3969end
3970
3971fn fmtprep to void
3972if ne get om2pos 0 0
3973put line 0 get om2ln 0
3974put tka 0 get om2pos 0
3975put tkb 0 get om2pos 0
3976note d2site 23|fmtprep: syntax: unknown or misplaced word; condition if ne get om2pos 0 0
3977put d2site 0 23
3978fail 16
3979end
3980e = get inlen 0
3981ln = ulong 1
3982i = ulong 0
3983go = true
3984while go
3985m = ulong 0
3986while and go lt m 999999
3987if ge i e
3988go = false
3989else
3990b = a_ib i
3991if eq b 13
3992put line 0 ln
3993put tka 0 i
3994put tkb 0 add i 1
3995note d2site 24|fmtprep: malformed number or token; condition if eq b 13
3996put d2site 0 24
3997fail 6
3998end
3999if eq b 10
4000ln = add ln 1
4001end
4002i = add i 1
4003end
4004m = add m 1
4005end
4006end
4007r = skipln get om2pos 0
4008put lbase 0 get om2ln 0
4009put sbase 0 r
4010n = sub e r
4011j = ulong 0
4012go = true
4013while go
4014m = ulong 0
4015while and go lt m 999999
4016if ge j n
4017go = false
4018else
4019a_bput 0 j a_ib add r j
4020j = add j 1
4021end
4022m = add m 1
4023end
4024end
4025put inlen 0 n
4026fmttail n
4027put om2 0 0
4028put om2m 0 0
4029put om2ln 0 0
4030put fmtm 0 1
4031om2lead
4032if eq get om2m 0 2
4033put line 0 get om2ln 0
4034put tka 0 get om2pos 0
4035put tkb 0 get om2pos 0
4036note d2site 25|fmtprep: syntax: unknown or misplaced word; condition if eq get om2m 0 2
4037put d2site 0 25
4038fail 16
4039end
4040end
4041
4042note fmtbyte: one input byte of the canonical text. fst: 0 line start, 1 indentation (kept, dropped
4043note again on a blank line), 2 note line (copied), 3 between words, 4 in a word, 5 in a text literal, 6
4044note after a backslash in a text literal. A run of blanks between words (fpend, starting at output byte
4045note fbo) is written as it comes, then becomes one space unless a parenthesis is next to it (fprp: the
4046note word before it was one); at the end of the line it is dropped.
4047fn fmtbyte p ulong to void
4048b = uchar and shr get a_ar shr p 3 shl and p 7 3 255
4049s = get fst 0
4050if eq b 10
4051if lt s 2
4052put oc 0 get flso 0
4053else
4054if ne get fpend 0 0
4055put oc 0 get fbo 0
4056end
4057end
4058emitb 10
4059put fst 0 0
4060put fpend 0 0
4061put fprp 0 0
4062put flso 0 get oc 0
4063ret
4064end
4065if eq s 2
4066emitb b
4067ret
4068end
4069if eq s 5
4070emitb b
4071if eq b 92
4072put fst 0 6
4073end
4074if eq b 34
4075put fst 0 3
4076put fprp 0 0
4077end
4078ret
4079end
4080if eq s 6
4081emitb b
4082put fst 0 5
4083ret
4084end
4085blank = or eq b 32 eq b 9
4086if lt s 2
4087if blank
4088emitb b
4089put fst 0 1
4090ret
4091end
4092if ne isnote p 0
4093emitb b
4094put fst 0 2
4095ret
4096end
4097put fst 0 3
4098put fpend 0 0
4099end
4100if blank
4101if eq get fpend 0 0
4102put fbo 0 get oc 0
4103put fpend 0 1
4104end
4105emitb b
4106put fst 0 3
4107ret
4108end
4109paren = or eq b 40 eq b 41
4110if and eq get fst 0 4 not paren
4111emitb b
4112ret
4113end
4114if ne get fpend 0 0
4115if and eq get fprp 0 0 not paren
4116put oc 0 get fbo 0
4117emitb 32
4118end
4119end
4120put fpend 0 0
4121emitb b
4122if eq b 34
4123put fst 0 5
4124put fprp 0 0
4125ret
4126end
4127if paren
4128put fst 0 3
4129put fprp 0 1
4130else
4131put fst 0 4
4132put fprp 0 0
4133end
4134end
4135
4136fn fmtout to void
4137put oc 0 0
4138put fst 0 0
4139put fpend 0 0
4140put fprp 0 0
4141put flso 0 0
4142e = get inlen 0
4143p = ulong 0
4144go = true
4145while go
4146m = ulong 0
4147while and go lt m 999999
4148if ge p e
4149go = false
4150else
4151fmtbyte p
4152p = add p 1
4153end
4154m = add m 1
4155end
4156end
4157if ge get fst 0 2
4158if ne get fpend 0 0
4159put oc 0 get fbo 0
4160end
4161emitb 10
4162end
4163put fmtm 0 0
4164put om2m 0 0
4165writeout 0
4166end
4167
4168note tok_hex (OM-2): 0x and 1..16 digits 0-9 a-f is the unsigned value (tk 2, tbig as tok_num). A - before
4169note 0x, 0X, no digits, more than 16 digits, an uppercase or any other character is error 6. 0 when the
4170note word is not a hex literal.
4171fn tok_hex to ulong
4172p = get ts 0
4173e = get cur 0
4174if eq uchar and shr get a_ar shr p 3 shl and p 7 3 255 45
4175q = add p 1
4176if lt add q 1 e
4177if eq uchar and shr get a_ar shr q 3 shl and q 7 3 255 48
4178c = a_ib add q 1
4179if or eq c 120 eq c 88
4180note d2site 26|tok_hex: malformed number or token; condition if or eq c 120 eq c 88
4181put d2site 0 26
4182nfail 6
4183end
4184end
4185end
4186ret 0
4187end
4188if ge add p 1 e
4189ret 0
4190end
4191if ne uchar and shr get a_ar shr p 3 shl and p 7 3 255 48
4192ret 0
4193end
4194c = uchar and shr get a_ar shr add p 1 3 shl and add p 1 7 3 255
4195if eq c 88
4196note d2site 27|tok_hex: malformed number or token; condition if eq c 88
4197put d2site 0 27
4198nfail 6
4199end
4200if ne c 120
4201ret 0
4202end
4203n = sub e add p 2
4204if eq n 0
4205note d2site 28|tok_hex: malformed number or token; condition if eq n 0
4206put d2site 0 28
4207nfail 6
4208end
4209if gt n 16
4210note d2site 29|tok_hex: malformed number or token; condition if gt n 16
4211put d2site 0 29
4212nfail 6
4213end
4214v = ulong 0
4215i = add p 2
4216while lt i e
4217d = ulong a_ib i
4218if and ge d 48 le d 57
4219v = or shl v 4 sub d 48
4220else
4221if and ge d 97 le d 102
4222v = or shl v 4 sub d 87
4223else
4224note d2site 30|tok_hex: malformed number or token; condition otherwise: if and ge d 97 le d 102
4225put d2site 0 30
4226nfail 6
4227end
4228end
4229i = add i 1
4230end
4231put tbig 0 shr v 63
4232put tw 0 v
4233put tk 0 2
4234ret 1
4235end
4236
4237note ---- float literals: a token is the decimal value fsgn * fnd * 10^fp10, fsuf 0 none / 1 f32 / 2 f64.
4238note fg_* hold the working state of the one literal being converted (see fparse/fbits/fnorm/fgen).
4239global fsgn ulong 1
4240global fnd ulong 1
4241global fp10 long 1
4242global fsuf ulong 1
4243global fg_fl ulong 1
4244global fg_seen ulong 1
4245global fg_ex long 1
4246global fg_esign long 1
4247global fg_ed ulong 1
4248global fg_ty ulong 1
4249global fg_e long 1
4250global fg_q ulong 1
4251global fg_m ulong 1
4252global fg_stk ulong 1
4253global fbn ulong 80
4254
4255note ======== float literals: decimal text to IEEE-754 binary32/binary64 ========
4256note The literal is fnd * 10^fp10 = A / D with A = fnd * 10^max(fp10,0) and D = 10^max(-fp10,0), both
4257note held exactly as 40 32-bit limbs in fbn (A at 0, D at 40). The smaller of the two is shifted to the
4258note other's bit length, then restoring division yields the first 64 quotient bits (fg_m, leading bit
4259note set) and a remainder whose nonzero-ness is the sticky flag (fg_stk); froundsh rounds that exact
4260note truncation once to nearest even and fpack packs it, subnormals included (#1024: the old converter
4261note scaled one factor of ten at a time and dropped bits at every step). fp10 < -343 means a value
4262note below (2^63-1)*10^-344 < 2^-1075, signed zero; fp10 > 308 means at least 10^309, above the
4263note binary64 maximum (error 8). So A and D never exceed 1141 bits.
4264
4265note blen: bits needed for x (0 for zero)
4266fn blen x ulong to ulong
4267n = ulong 0
4268while ne x 0
4269x = shr x 1
4270n = add n 1
4271end
4272ret n
4273end
4274
4275note fparse: read the literal text inp[pos, pos+len) into fsgn, fnd, fp10, fsuf (0 none, 1 f32, 2 f64).
4276note Grammar: [-]digits[.digits][(e|E)[+|-]digits][f32|f64]. At most 2^63-1 significant digits
4277note (error 8), a dot with no digit after it is error 6, |exponent| <= 999 (error 8).
4278note The digit scans here and in fexp run as nested 999999-pass loops: a literal of more than 1000000
4279note zero digits trapped 4 in a single loop's hidden 1000000-pass guard (#965).
4280fn fparse pos ulong ln ulong to void
4281p = pos
4282e = add pos ln
4283put fsgn 0 0
4284put fsuf 0 0
4285put fnd 0 0
4286put fg_fl 0 0
4287put fg_seen 0 0
4288if eq uchar and shr get a_ar shr p 3 shl and p 7 3 255 45
4289put fsgn 0 1
4290p = add p 1
4291end
4292go = true
4293while go
4294pos = ulong 0
4295while and go lt pos 999999
4296if ge p e
4297go = false
4298else
4299d = sub ulong a_ib p 48
4300if le d 9
4301if gt get fnd 0 922337203685477580
4302note d2site 31|fparse: number out of range for its type or place; condition if gt get fnd 0 922337203685477580
4303put d2site 0 31
4304fail 8
4305end
4306if eq get fnd 0 922337203685477580
4307if gt d 7
4308note d2site 32|fparse: number out of range for its type or place; condition if gt d 7
4309put d2site 0 32
4310fail 8
4311end
4312end
4313put fnd 0 add mul get fnd 0 10 d
4314if ne get fg_seen 0 0
4315put fg_fl 0 add get fg_fl 0 1
4316end
4317p = add p 1
4318else
4319go = false
4320if eq a_ib p 46
4321if eq get fg_seen 0 0
4322put fg_seen 0 1
4323p = add p 1
4324go = true
4325end
4326end
4327end
4328end
4329pos = add pos 1
4330end
4331end
4332if and ne get fg_seen 0 0 eq get fg_fl 0 0
4333note d2site 33|fparse: malformed number or token; condition if and ne get fg_seen 0 0 eq get fg_fl 0 0
4334put d2site 0 33
4335fail 6
4336end
4337p = fexp p e
4338p = fsufx p e
4339if ne p e
4340note d2site 34|fparse: malformed number or token; condition if ne p e
4341put d2site 0 34
4342fail 6
4343end
4344x = mul get fg_esign 0 get fg_ex 0
4345put fp10 0 sub x long get fg_fl 0
4346end
4347
4348note fexp: the exponent of the literal, if present: fg_ex, fg_esign, fg_ed. Returns the new position.
4349fn fexp p ulong e ulong to ulong
4350put fg_ex 0 0
4351put fg_esign 0 1
4352if and lt p e or eq a_ib p 101 eq a_ib p 69
4353p = add p 1
4354if lt p e
4355if or eq a_ib p 43 eq a_ib p 45
4356if eq uchar and shr get a_ar shr p 3 shl and p 7 3 255 45
4357put fg_esign 0 -1
4358end
4359p = add p 1
4360end
4361end
4362put fg_ed 0 0
4363go = true
4364while go
4365m = ulong 0
4366while and go lt m 999999
4367if ge p e
4368go = false
4369else
4370d = sub ulong a_ib p 48
4371if gt d 9
4372go = false
4373else
4374put fg_ex 0 mul get fg_ex 0 10
4375put fg_ex 0 add get fg_ex 0 long d
4376if gt get fg_ex 0 999
4377note d2site 35|fexp: number out of range for its type or place; condition if gt get fg_ex 0 999
4378put d2site 0 35
4379fail 8
4380end
4381put fg_ed 0 add get fg_ed 0 1
4382p = add p 1
4383end
4384end
4385m = add m 1
4386end
4387end
4388if eq get fg_ed 0 0
4389note d2site 36|fexp: malformed number or token; condition if eq get fg_ed 0 0
4390put d2site 0 36
4391fail 6
4392end
4393end
4394ret p
4395end
4396
4397note fsufx: the optional f32/f64 suffix: fsuf 1 or 2. Returns the new position.
4398fn fsufx p ulong e ulong to ulong
4399if lt p e
4400r = sub e p
4401if ne r 3
4402note d2site 37|fsufx: malformed number or token; condition if ne r 3
4403put d2site 0 37
4404fail 6
4405end
4406if ne uchar and shr get a_ar shr p 3 shl and p 7 3 255 102
4407note d2site 38|fsufx: malformed number or token; condition if ne uchar and shr get a_ar shr p 3 shl and p 7 3 255 102
4408put d2site 0 38
4409fail 6
4410end
4411if and eq a_ib add p 1 51 eq a_ib add p 2 50
4412put fsuf 0 1
4413else
4414if and eq a_ib add p 1 54 eq a_ib add p 2 52
4415put fsuf 0 2
4416else
4417note d2site 39|fsufx: malformed number or token; condition otherwise: if and eq a_ib add p 1 54 eq a_ib add p 2 52
4418put d2site 0 39
4419fail 6
4420end
4421end
4422p = add p 3
4423end
4424ret p
4425end
4426
4427note fbmul: limbs fbn[o, o+40) times k (k < 2^32, so each limb step fits 64 bits); the product must fit
4428note in 40 limbs. Returns its bit length, so fbmul o 1 only measures.
4429fn fbmul o ulong k ulong to ulong
4430c = ulong 0
4431t = ulong 0
4432i = ulong 0
4433while lt i 40
4434j = add o i
4435v = add mul get fbn j k c
4436put fbn j and v 4294967295
4437c = shr v 32
4438if ne and v 4294967295 0
4439t = add mul i 32 blen and v 4294967295
4440end
4441i = add i 1
4442end
4443ret t
4444end
4445
4446note fbpow: fbn[o, o+40) times b^n (b 2 or 10), in factors that stay below 2^32.
4447fn fbpow o ulong b ulong n ulong to void
4448while gt n 0
4449m = ulong 1
4450c = ulong 0
4451while and lt c n le mul m b 4294967295
4452m = mul m b
4453c = add c 1
4454end
4455t = fbmul o m
4456n = sub n c
4457end
4458end
4459
4460note fbsub: one restoring-division step. If A >= D then A = A - D and 1, else A is kept and 0.
4461fn fbsub to ulong
4462r = ulong 2
4463i = ulong 40
4464while and gt i 0 eq r 2
4465i = sub i 1
4466a = get fbn i
4467d = get fbn add i 40
4468if lt a d
4469r = ulong 0
4470end
4471if gt a d
4472r = ulong 1
4473end
4474end
4475if eq r 0
4476ret 0
4477end
4478b = ulong 0
4479i = ulong 0
4480while lt i 40
4481v = sub sub get fbn i get fbn add i 40 b
4482put fbn i and v 4294967295
4483b = shr v 63
4484i = add i 1
4485end
4486ret 1
4487end
4488
4489note froundsh: round fg_m right by sh bits to fg_q, nearest even; the guard and every lower bit
4490note (plus fg_stk) decide. sh may be 64 (then q is zero and bit 63 is the guard).
4491fn froundsh sh ulong to void
4492m = get fg_m 0
4493q = ulong 0
4494guard = ulong 0
4495lost = ulong 0
4496if eq sh 0
4497q = m
4498else
4499if ge sh 64
4500guard = shr m 63
4501lost = and m 9223372036854775807
4502else
4503q = shr m sh
4504guard = and shr m sub sh 1 1
4505if gt sub sh 1 0
4506lost = and m sub shl 1 sub sh 1 1
4507end
4508end
4509end
4510sticky = or get fg_stk 0 lost
4511if ne guard 0
4512if or ne sticky 0 eq and q 1 1
4513q = add q 1
4514end
4515end
4516put fg_q 0 q
4517end
4518
4519note fpack: fg_m/fg_e to IEEE bits of fg_ty, including subnormals; a literal that rounds to infinity
4520note is refused (error 8).
4521fn fpack to ulong
4522p = ulong 53
4523bias = long 1023
4524maxe = long 2047
4525emin = long -1022
4526mb = ulong 52
4527w = ulong 64
4528if eq get fg_ty 0 10
4529p = ulong 24
4530bias = long 127
4531maxe = long 255
4532emin = long -126
4533mb = ulong 23
4534w = ulong 32
4535end
4536e = add get fg_e 0 63
4537if ge e emin
4538sh = sub 64 p
4539froundsh sh
4540q = get fg_q 0
4541if eq q shl 1 p
4542q = shr q 1
4543e = add e 1
4544end
4545E = add e bias
4546if ge E maxe
4547note d2site 40|fpack: number out of range for its type or place; condition if ge E maxe
4548put d2site 0 40
4549fail 8
4550end
4551q = and q sub shl 1 sub p 1 1
4552q = or q shl ulong E mb
4553q = or q shl get fsgn 0 sub w 1
4554ret q
4555end
4556k = ulong sub emin e
4557sh = add sub 64 p k
4558if gt sh 64
4559ret shl get fsgn 0 sub w 1
4560end
4561froundsh sh
4562q = get fg_q 0
4563q = or q shl get fsgn 0 sub w 1
4564ret q
4565end
4566
4567note fbits: the parsed literal as IEEE bits of type ty (10 f32, 11 f64). Zero keeps the sign (-0.0).
4568fn fbits ty ulong to ulong
4569put fg_ty 0 ty
4570p = get fp10 0
4571if or eq get fnd 0 0 lt p -343
4572w = ulong 64
4573if eq ty 10
4574w = ulong 32
4575end
4576b = ulong 0
4577if ne get fsgn 0 0
4578b = shl ulong 1 sub w 1
4579end
4580ret b
4581end
4582if gt p 308
4583note d2site 41|fbits: number out of range for its type or place; condition if gt p 308
4584put d2site 0 41
4585fail 8
4586end
4587i = ulong 0
4588while lt i 80
4589put fbn i 0
4590i = add i 1
4591end
4592put fbn 0 and get fnd 0 4294967295
4593put fbn 1 shr get fnd 0 32
4594put fbn 40 1
4595if gt p 0
4596fbpow 0 10 ulong p
4597else
4598fbpow 40 10 ulong sub 0 p
4599end
4600a = fbmul 0 1
4601d = fbmul 40 1
4602e = long 0
4603if lt a d
4604fbpow 0 2 sub d a
4605e = sub 0 long sub d a
4606else
4607fbpow 40 2 sub a d
4608e = long sub a d
4609end
4610q = ulong 0
4611while lt q 9223372036854775808
4612q = or shl q 1 fbsub
4613a = fbmul 0 2
4614e = sub e 1
4615end
4616put fg_m 0 q
4617put fg_e 0 add e 1
4618put fg_stk 0 fbmul 0 1
4619ret fpack
4620end
4621
4622note fsizeof: sizeof T, or sizeof S for a struct: bytes. foffset: offsetof S f: the field's byte offset
4623note in the struct's 8-byte-cell layout. Both are compile-time constants of type ulong.
4624fn fsizeof dst ulong to void
4625sid = peek_struct
4626if ne sid 0
4627si = sub sid 1
4628n = ulong get st_cells si
4629vdone 3 mul n 8 5
4630ret
4631end
4632t = typeword
4633if ge t 64
4634note d2site 42|fsizeof: type mismatch; condition if ge t 64
4635put d2site 0 42
4636fail 7
4637end
4638v = shl 1 tlog t
4639vdone 3 v 5
4640end
4641
4642fn foffset dst ulong to void
4643tok
4644if ne get tk 0 1
4645note d2site 43|foffset: syntax: unknown or misplaced word; condition if ne get tk 0 1
4646put d2site 0 43
4647fail 16
4648end
4649if gt get tl 0 63
4650note d2site 44|foffset: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
4651put d2site 0 44
4652fail 13
4653end
4654sid = findstruct get tw 0
4655if eq sid 0
4656note d2site 45|foffset: unknown name or field, or a word this mode does not provide; condition if eq sid 0
4657put d2site 0 45
4658unkfail 3
4659end
4660tok
4661if ne get tk 0 1
4662note d2site 46|foffset: syntax: unknown or misplaced word; condition if ne get tk 0 1
4663put d2site 0 46
4664fail 16
4665end
4666if gt get tl 0 63
4667note d2site 47|foffset: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
4668put d2site 0 47
4669fail 13
4670end
4671f = findfield sub sid 1 get tw 0
4672if eq f 0
4673note d2site 48|foffset: unknown name or field, or a word this mode does not provide; condition if eq f 0
4674put d2site 0 48
4675fail 3
4676end
4677off = ulong get sf_off sub f 1
4678vdone 3 mul off 8 5
4679end
4680
4681note fspan: a deferred literal stored as pos*4294967296+len. The input lives in the arena (2^27 bytes at
4682note most), so pos fits the high 32 bits and len the low 32; the old pos*64+len read a literal of 64 or more
4683note characters from the wrong span (#965), and pos*16777216+len assumed an input below 2^23 bytes.
4684fn fspan ty ulong packed ulong to ulong
4685fparse div packed 4294967296 rem packed 4294967296
4686ret fbits ty
4687end
4688
4689fn isfloat t ulong to ulong
4690if or eq t 10 eq t 11
4691ret 1
4692end
4693ret 0
4694end
4695
4696note ======== om4's small tables, as functions ========
4697note twid: width in bits by type 0..9 (bool 1; uchar ushort uint ulong; byte short int long)
4698fn twid t ulong to ulong
4699if eq t 13
4700ret 64
4701end
4702if eq t 10
4703ret 32
4704end
4705if eq t 11
4706ret 64
4707end
4708if eq t 1
4709ret 1
4710end
4711if or eq t 2 eq t 6
4712ret 8
4713end
4714if or eq t 3 eq t 7
4715ret 16
4716end
4717if or eq t 4 eq t 8
4718ret 32
4719end
4720if or eq t 5 eq t 9
4721ret 64
4722end
4723ret 0
4724end
4725
4726note tlog: log2 of the element size by type
4727fn tlog t ulong to ulong
4728if eq t 13
4729ret 3
4730end
4731if eq t 10
4732ret 2
4733end
4734if eq t 11
4735ret 3
4736end
4737if or eq t 3 eq t 7
4738ret 1
4739end
4740if or eq t 4 eq t 8
4741ret 2
4742end
4743if or eq t 5 eq t 9
4744ret 3
4745end
4746ret 0
4747end
4748
4749note regidx: the pool index of register r (the inverse of poolc; 255 for x7 and x16)
4750fn regidx r ulong to ulong
4751if lt r 7
4752ret r
4753end
4754if eq r 7
4755ret 255
4756end
4757if lt r 16
4758ret sub r 1
4759end
4760if eq r 16
4761ret 255
4762end
4763ret 15
4764end
4765
4766note conds: the condition for eq ne lt le gt ge (i = 2 (op - 43) + 1 when signed): EQ 0, NE 1, LO 3 / LT 11,
4767note LS 9 / LE 13, HI 8 / GT 12, HS 2 / GE 10 (Arm ARM Table C1-1). The opposite condition is cond xor 1.
4768fn conds i ulong to ulong
4769if lt i 2
4770ret 0
4771end
4772if lt i 4
4773ret 1
4774end
4775if eq i 4
4776ret 3
4777end
4778if eq i 5
4779ret 11
4780end
4781if eq i 6
4782ret 9
4783end
4784if eq i 7
4785ret 13
4786end
4787if eq i 8
4788ret 8
4789end
4790if eq i 9
4791ret 12
4792end
4793if eq i 10
4794ret 2
4795end
4796ret 10
4797end
4798
4799note ldop / stop: register-offset load / store by element type (om4 LDOP, STOP tables)
4800fn ldop t ulong to ulong
4801note LDRB 0x38606800, LDRH 0x78607800, LDR w 0xb8607800, LDR x 0xf8607800, LDRSB 0x38a06800,
4802note LDRSH 0x78a07800, LDRSW 0xb8a07800
4803note Bool struct fields use a byte load/store, as their canonical values are zero or one.
4804if or eq t 1 eq t 2
4805ret 945842176
4806end
4807if eq t 3
4808ret 2019588096
4809end
4810if eq t 4
4811ret 3093329920
4812end
4813if or or eq t 5 eq t 9 eq t 13
4814ret 4167071744
4815end
4816if eq t 10
4817ret 3093329920
4818end
4819if eq t 11
4820ret 4167071744
4821end
4822if eq t 6
4823ret 950036480
4824end
4825if eq t 7
4826ret 2023782400
4827end
4828if eq t 8
4829ret 3097524224
4830end
4831ret 0
4832end
4833
4834fn stop t ulong to ulong
4835note STRB 0x38206800, STRH 0x78207800, STR w 0xb8207800, STR x 0xf8207800
4836if or or eq t 1 eq t 2 eq t 6
4837ret 941647872
4838end
4839if or eq t 3 eq t 7
4840ret 2015393792
4841end
4842if or eq t 4 eq t 8
4843ret 3089135616
4844end
4845if or or eq t 5 eq t 9 eq t 13
4846ret 4162877440
4847end
4848if eq t 10
4849ret 3089135616
4850end
4851if eq t 11
4852ret 4162877440
4853end
4854ret 0
4855end
4856
4857note ---- trap list (arena group 10; no count of its own): output offset of the branch, trap code ----
4858global nt ulong 1
4859note ---- block stack (arena group 13; no depth of its own): kind (1 if, 2 else, 3 while, 4 for), branch to patch, loop head, loop
4860note register, its type, names and held pool slots to restore at end, then-part ended (for else) ----
4861note brot / bkk / bkr: a for whose test moved to its latch (OM-2, lpmark / lpback): the place the latch
4862note branches back to (0: not moved), its number K, and its K register + 1 (0 when K is the number).
4863note cphn: the head clauses the last cp_head emitted (OM-2).
4864global cphn ulong 1
4865global nb ulong 1
4866global curfn ulong 1
4867note ---- break and continue fixups (arena groups 14, 15; no count of their own): output offset of the branch, block index of the loop it leaves ----
4868global nbrk ulong 1
4869global ncont ulong 1
4870fn dcat_w code ulong to void
4871if or or eq code 4 eq code 6 eq code 16
4872mputw 9104236865280339 7
4873ret
4874end
4875if or or eq code 7 eq code 11 eq code 19
4876mputw 138601847124 5
4877ret
4878end
4879if or eq code 17 eq code 18
4880mputw 138903768134 5
4881ret
4882end
4883if or or eq code 3 eq code 10 eq code 13
4884mputw 138601644366 5
4885ret
4886end
4887if or or or eq code 12 eq code 14 eq code 23 eq code 24
4888mputw 6436850320626696515 8
4889mputb 32
4890ret
4891end
4892if or eq code 8 eq code 21
4893mputw 35481921143122 6
4894ret
4895end
4896if or or or eq code 27 eq code 28 eq code 29 eq code 30
4897mputw 6071768544483102531 8
4898mputb 32
4899ret
4900end
4901mputw 9104236865280339 7
4902end
4903
4904fn dty_w t ulong to void
4905if eq t 1
4906mputw 1819242338 4
4907ret
4908end
4909if eq t 2
4910mputw 491260502901 5
4911ret
4912end
4913if eq t 3
4914mputw 128034844210037 6
4915ret
4916end
4917if eq t 4
4918mputw 1953393013 4
4919ret
4920end
4921if eq t 5
4922mputw 444234427509 5
4923ret
4924end
4925if eq t 6
4926mputw 1702132066 4
4927ret
4928end
4929if eq t 7
4930mputw 500136110195 5
4931ret
4932end
4933if eq t 8
4934mputw 7630441 3
4935ret
4936end
4937if eq t 9
4938mputw 1735290732 4
4939ret
4940end
4941if eq t 10
4942mputw 3289958 3
4943ret
4944end
4945if eq t 11
4946mputw 3421798 3
4947ret
4948end
4949if eq t 12
4950mputw 1684631414 4
4951ret
4952end
4953if eq t 13
4954mputb 113
4955mputb 116
4956mputb 121
4957ret
4958end
4959mputw 2003134838 4
4960end
4961
4962fn dname_kind i ulong to void
4963k = ulong uchar get a_ar add get a_rb 7 i
4964if eq k 4
4965mputw 119165519096935 6
4966ret
4967end
4968if eq k 5
4969mputw 1954047348 4
4970ret
4971end
4972if eq k 10
4973mputw 1819242352 4
4974ret
4975end
4976if eq k 9
4977mputw 500152823651 5
4978ret
4979end
4980if or eq k 2 eq k 8
4981mputw 2003134838 4
4982ret
4983end
4984if or eq k 3 eq k 7
4985mputw 1953064037 4
4986ret
4987end
4988if ne get curfn 0 0
4989f = sub get curfn 0 1
4990np = ulong uchar get a_ar add get a_rb 24 f
4991endp = add get nglob 0 np
4992if and ge i get nglob 0 lt i endp
4993mputw 469786321264 5
4994ret
4995end
4996end
4997mputw 465490374508 5
4998end
4999
5000fn mput_name w ulong to void
5001if eq and w 255 1
5002k = shr w 8
5003o = get a_ar add get a_rb 17 k
5004i = ulong 0
5005while lt i ulong uchar get a_ar add get a_rb 18 k
5006mputb a_ib add o i
5007i = add i 1
5008end
5009ret
5010end
5011x = w
5012go = true
5013while go
5014if eq x 0
5015go = false
5016else
5017b = and x 255
5018if eq b 0
5019go = false
5020else
5021mputb uchar b
5022x = shr x 8
5023end
5024end
5025end
5026end
5027
5028
5029fn mput_tok a ulong b ulong to void
5030if eq a b
5031if eq get tk 0 3
5032mputw 6713189 3
5033ret
5034end
5035mputb 45
5036ret
5037end
5038i = a
5039while and lt i b lt sub i a 16
5040c = ulong uchar and shr get a_ar shr i 3 shl and i 7 3 255
5041if and gt c 32 lt c 127
5042mputb uchar c
5043else
5044mputh c
5045end
5046i = add i 1
5047end
5048end
5049
5050fn diagrec code ulong to void
5051put mc 0 0
5052mputw 7594244768023276911 8
5053mputw 11207551510369 6
5054if eq get om2 0 0
5055mputw 3239279 3
5056mputb 32
5057else
5058mputw 3304815 3
5059mputb 32
5060end
5061dcat_w code
5062a = get tka 0
5063b = get tkb 0
5064if le b a
5065b = a
5066if gt get cur 0 a
5067b = get cur 0
5068end
5069end
5070if gt b get inlen 0
5071b = get inlen 0
5072end
5073sa = a
5074sb = b
5075if ge sa get sbase 0
5076sa = sub sa get sbase 0
5077else
5078sa = ulong 0
5079end
5080if ge sb get sbase 0
5081sb = sub sb get sbase 0
5082else
5083sb = ulong 0
5084end
5085mputw 263844884595 5
5086mputn sa
5087mputb 45
5088mputn sb
5089mputb 32
5090s = get dsev 0
5091if eq s 0
5092if eq get tk 0 3
5093s = ulong 1
5094end
5095if and eq code 22 ge get cur 0 get inlen 0
5096s = ulong 1
5097end
5098end
5099if eq s 1
5100mputw 4993454379819552329 8
5101mputw 2114900 3
5102else
5103if eq s 2
5104mputw 2327894055524716117 8
5105else
5106mputw 35511885252934 6
5107end
5108end
5109note Repairability is independent of prefix finality; only capacity failures are unrepairable.
5110if or or or eq code 12 eq code 14 eq code 23 eq code 24
5111mputw 5929342197426179669 8
5112mputw 138601579073 4
5113else
5114mputw 4774187554571306322 8
5115mputw 2114892 2
5116end
5117mputw 67505686012704 6
5118mputn code
5119mputw 67505853393952 6
5120hl = get line 0
5121if ne get chkmode 0 0
5122if gt hl get chkln 0
5123hl = sub hl get chkln 0
5124else
5125hl = ulong 1
5126end
5127end
5128mputn hl
5129mputw 4428273620941825312 8
5130dexp_w code
5131mputw 17280399158765088 7
5132mput_tok a b
5133mputb 10
5134mflush
5135end
5136
5137fn emit_query to void
5138put mc 0 0
5139mputw 8462595071175650671 8
5140mputw 2869133187838565 7
5141mputw 9071406607197043 7
5142if eq get curfn 0 0
5143mputw 7810779306727075700 8
5144mputb 10
5145mputw 7166760226508402531 8
5146mputw 7142830393916027764 8
5147mputw 8028905624785088111 8
5148mputw 8392569455039504738 8
5149mputw 2338603462594687776 8
5150mputw 44651802478 5
5151else
5152mputw 7957695015192261990 8
5153mputb 10
5154mputw 7166760226508402531 8
5155mputw 2338605647353508724 8
5156mputw 7308332192711599721 8
5157mputw 7021802451731703328 8
5158mputw 8079585727842951280 8
5159mputw 9117624560546933 7
5160mputw 1702129518 4
5161in_loop = ulong 0
5162j = get nb 0
5163while and eq in_loop 0 gt j 0
5164j = sub j 1
5165if and ge a_g 49 j 3 le a_g 49 j 4
5166in_loop = ulong 1
5167end
5168end
5169if ne in_loop 0
5170mputw 7142827075067601440 8
5171mputw 749134030103146095 8
5172else
5173mputb 10
5174end
5175end
5176mputw 2879017064423790 7
5177mflush
5178i = ulong 0
5179go = true
5180while go
5181m = ulong 0
5182while and go lt m 999999
5183if ge i get nn 0
5184go = false
5185else
5186if ne get a_ar add get a_rb 3 i 0
5187mput_name get a_ar add get a_rb 3 i
5188mputb 32
5189dty_w ulong uchar get a_ar add get a_rb 5 i
5190mputb 32
5191dname_kind i
5192mputb 10
5193mflush
5194end
5195i = add i 1
5196end
5197m = add m 1
5198end
5199end
5200mputw 7957695015192261990 8
5201mputw 670323 3
5202mflush
5203f = ulong 0
5204while lt f get nf 0
5205mputw 2125414 3
5206note Single caller: spell the function name here rather than spend a bootstrap function slot.
5207o = get a_ar add get a_rb 26 f
5208l = get a_ar add get a_rb 25 f
5209if and ne o 0 gt l 0
5210i = ulong 0
5211while lt i l
5212mputb a_ib add o i
5213i = add i 1
5214end
5215else
5216mput_name get a_ar add get a_rb 21 f
5217end
5218mputw 544175136 4
5219dty_w ulong uchar get a_ar add get a_rb 23 f
5220np = ulong uchar get a_ar add get a_rb 24 f
5221p = ulong 0
5222while lt p np
5223mputb 32
5224dty_w ulong a_gu 35 add mul f 6 p
5225p = add p 1
5226end
5227mputb 10
5228mflush
5229f = add f 1
5230end
5231mflush
5232exit int 0
5233end
5234note ======== names and functions ========
5235note findname: packed name -> its index + 1 among the names in scope (0 none). om4 FINDNAME. The names in
5236note scope are 0 .. nn - 1 (clim while a pure contract is read), without nglob .. nmlo - 1 while an inlined
5237note body hides its caller's locals. The lowest such index whose packed name is w is the answer, as the
5238note old front-to-back scan gave; the chain of w's bucket holds every name below nn, newest first.
5239fn findname w ulong to ulong
5240n = get nn 0
5241if ne get cpure 0 0
5242n = get clim 0
5243end
5244g = get nglob 0
5245lo = get nmlo 0
5246k = get a_ar add get a_rb 16 a_hash w get nh_b 0
5247best = ulong 0
5248go = true
5249while go
5250m = ulong 0
5251while and go lt m 999999
5252if eq k 0
5253go = false
5254else
5255i = sub k 1
5256if and lt i n eq a_g 3 i w
5257if or lt i g ge i lo
5258best = k
5259end
5260end
5261k = a_g 15 i
5262end
5263m = add m 1
5264end
5265end
5266ret best
5267end
5268
5269note nm_link: name i becomes the newest of its bucket's chain
5270fn nm_link i ulong to void
5271h = a_hash get a_ar add get a_rb 3 i get nh_b 0
5272put a_ar add get a_rb 15 i get a_ar add get a_rb 16 h
5273put a_ar add get a_rb 16 h add i 1
5274end
5275
5276note nm_unlk: name i, the newest name of its chain (every name above it has left), leaves it. Should a
5277note chain ever not start with i, the buckets are rebuilt from names 0 .. i - 1 instead.
5278fn nm_unlk i ulong to void
5279h = a_hash get a_ar add get a_rb 3 i get nh_b 0
5280if eq get a_ar add get a_rb 16 h add i 1
5281put a_ar add get a_rb 16 h get a_ar add get a_rb 15 i
5282else
5283nm_build i
5284end
5285end
5286
5287note nm_build: empty buckets, then names 0 .. n - 1 linked in order
5288fn nm_build n ulong to void
5289a_gzero 4
5290i = ulong 0
5291go = true
5292while go
5293m = ulong 0
5294while and go lt m 999999
5295if ge i n
5296go = false
5297else
5298nm_link i
5299i = add i 1
5300end
5301m = add m 1
5302end
5303end
5304end
5305
5306note nm_set: the names in scope become 0 .. v - 1 (every write of nn but addname's): names above v leave
5307note their chains newest first; names between nn and v (a scope given back) join them again in order
5308fn nm_set v ulong to void
5309n = get nn 0
5310if gt v 0
5311if ge sub v 1 get a_gp 3
5312a_need 3 sub v 1
5313end
5314end
5315go = true
5316while go
5317m = ulong 0
5318while and go lt m 999999
5319if gt n v
5320n = sub n 1
5321nm_unlk n
5322else
5323if lt n v
5324nm_link n
5325n = add n 1
5326else
5327go = false
5328end
5329end
5330m = add m 1
5331end
5332end
5333put nn 0 v
5334end
5335
5336note fn_same: function j is the name w of length l starting at input byte s (the test of the old scan)
5337fn fn_same j ulong w ulong l ulong s ulong to ulong
5338if ne get a_ar add get a_rb 21 j w
5339ret 0
5340end
5341if eq and w 255 1
5342ret 1
5343end
5344fl = get a_ar add get a_rb 25 j
5345if le l 8
5346if le fl 8
5347ret 1
5348end
5349ret 0
5350end
5351if ne fl l
5352ret 0
5353end
5354o = get a_ar add get a_rb 26 j
5355k = ulong 8
5356while lt k l
5357if ne a_ib add o k a_ib add s k
5358ret 0
5359end
5360k = add k 1
5361end
5362ret 1
5363end
5364
5365note findfn: packed name w (first 8 bytes, or an interned long name), length l (any value up to 8 for a
5366note short name), start s in the input (read only for a name over 8 bytes that is not interned) ->
5367note function index + 1 (0 none), the lowest that matches, as the old scan gave. om4 FINDFN.
5368fn findfn w ulong l ulong s ulong to ulong
5369k = get a_ar add get a_rb 40 a_hash w get fh_b 0
5370best = ulong 0
5371go = true
5372while go
5373m = ulong 0
5374while and go lt m 999999
5375if eq k 0
5376go = false
5377else
5378j = sub k 1
5379if ne fn_same j w l s 0
5380best = k
5381end
5382k = get a_ar add get a_rb 33 j
5383end
5384m = add m 1
5385end
5386end
5387ret best
5388end
5389
5390note fn_link: function f becomes the newest of its bucket's chain; at twice as many functions as buckets
5391note the buckets double and every function is linked again in order
5392fn fn_link f ulong to void
5393h = a_hash get a_ar add get a_rb 21 f get fh_b 0
5394put a_ar add get a_rb 33 f get a_ar add get a_rb 40 h
5395put a_ar add get a_rb 40 h add f 1
5396if ge add f 1 shl ulong 2 get fh_b 0
5397b = add get fh_b 0 1
5398put fh_b 0 b
5399if ge sub shl ulong 1 b 1 get a_gp 8
5400a_need 8 sub shl ulong 1 b 1
5401end
5402a_gzero 8
5403j = ulong 0
5404go = true
5405while go
5406m = ulong 0
5407while and go lt m 999999
5408if gt j f
5409go = false
5410else
5411h = a_hash get a_ar add get a_rb 21 j b
5412a_p 33 j a_g 40 h
5413put a_ar add get a_rb 40 h add j 1
5414j = add j 1
5415end
5416m = add m 1
5417end
5418end
5419end
5420end
5421
5422note ln_hw: the hash word of the n input bytes at s
5423fn ln_hw s ulong n ulong to ulong
5424w = ulong 0
5425i = ulong 0
5426while lt i n
5427w = add mul w 31 ulong a_ib add s i
5428i = add i 1
5429end
5430ret w
5431end
5432
5433note ln_same: long name j is spelled as the n input bytes at s
5434fn ln_same j ulong s ulong n ulong to ulong
5435if ne ulong uchar get a_ar add get a_rb 18 j n
5436ret 0
5437end
5438o = get a_ar add get a_rb 17 j
5439i = ulong 0
5440while lt i n
5441if ne a_ib add o i a_ib add s i
5442ret 0
5443end
5444i = add i 1
5445end
5446ret 1
5447end
5448
5449note ln_intern: the index of the long name spelled by the n input bytes at s. A spelling met for the first
5450note time is appended (indices in order of first appearance, as before) and linked into its chain; at
5451note twice as many long names as buckets the buckets double and every name is linked again.
5452fn ln_intern s ulong n ulong to ulong
5453h = a_hash ln_hw s n get lh_b 0
5454k = get a_ar add get a_rb 20 h
5455go = true
5456while go
5457m = ulong 0
5458while and go lt m 999999
5459if eq k 0
5460go = false
5461else
5462j = sub k 1
5463if ne ln_same j s n 0
5464ret j
5465end
5466k = get a_ar add get a_rb 19 j
5467end
5468m = add m 1
5469end
5470end
5471k = get ln_n 0
5472if ge k get a_gp 5
5473a_need 5 k
5474end
5475put a_ar add get a_rb 17 k s
5476a_pc 18 k uchar n
5477a_p 19 k a_g 20 h
5478put a_ar add get a_rb 20 h add k 1
5479put ln_n 0 add k 1
5480if ge add k 1 shl ulong 2 get lh_b 0
5481ln_rehash add k 1
5482end
5483ret k
5484end
5485
5486note ln_rehash: double the long-name buckets and link long names 0 .. c - 1 again in order
5487fn ln_rehash c ulong to void
5488b = add get lh_b 0 1
5489put lh_b 0 b
5490if ge sub shl ulong 1 b 1 get a_gp 6
5491a_need 6 sub shl ulong 1 b 1
5492end
5493a_gzero 6
5494j = ulong 0
5495go = true
5496while go
5497m = ulong 0
5498while and go lt m 999999
5499if ge j c
5500go = false
5501else
5502h = a_hash ln_hw a_g 17 j ulong a_gu 18 j b
5503a_p 19 j a_g 20 h
5504put a_ar add get a_rb 20 h add j 1
5505j = add j 1
5506end
5507m = add m 1
5508end
5509end
5510end
5511
5512note newname: the name must not be in use (a name in scope, a struct, layout, abstract or function): error 10
5513fn newname w ulong l ulong s ulong to void
5514if le l 8
5515if ne kwx w 0
5516note d2site 49|newname: syntax: unknown or misplaced word; condition if ne kwx w 0
5517put d2site 0 49
5518fail 16
5519end
5520end
5521if ne findstruct w 0
5522note d2site 50|newname: duplicate name; condition if ne findstruct w 0
5523put d2site 0 50
5524fail 10
5525end
5526if ne findname w 0
5527note d2site 51|newname: duplicate name; condition if ne findname w 0
5528put d2site 0 51
5529fail 10
5530end
5531if ne findlay w 0
5532note d2site 52|newname: duplicate name; condition if ne findlay w 0
5533put d2site 0 52
5534fail 10
5535end
5536if ne findab w 0
5537note d2site 53|newname: duplicate name; condition if ne findab w 0
5538put d2site 0 53
5539fail 10
5540end
5541if ne findfn w l s 0
5542note d2site 54|newname: duplicate name; condition if ne findfn w l s 0
5543put d2site 0 54
5544fail 10
5545end
5546end
5547
5548note addname: packed name, register, type, length, kind, address. om4 ADDNAME. The table grows with the
5549note arena (group 3); at twice as many names as buckets the buckets double (nm_build).
5550fn addname w ulong r ulong t ulong ln ulong k ulong a ulong to void
5551if ne kwx w 0
5552note d2site 55|addname: syntax: unknown or misplaced word; condition if ne kwx w 0
5553put d2site 0 55
5554fail 16
5555end
5556n = get nn 0
5557if ge n get a_gp 3
5558a_need 3 n
5559end
5560put a_ar add get a_rb 3 n w
5561a_pc 4 n uchar r
5562a_pc 5 n uchar t
5563put a_ar add get a_rb 6 n ln
5564a_pc 7 n uchar k
5565put a_ar add get a_rb 8 n a
5566a_pc 9 n 0
5567a_pc 12 n 0
5568a_pc 13 n 0
5569a_pc 14 n 0
5570a_pc 10 n 0
5571a_pc 11 n 0
5572nm_link n
5573put nn 0 add n 1
5574if ge add n 1 shl ulong 2 get nh_b 0
5575put nh_b 0 add get nh_b 0 1
5576if ge sub shl ulong 1 get nh_b 0 1 get a_gp 4
5577a_need 4 sub shl ulong 1 get nh_b 0 1
5578end
5579nm_build add n 1
5580end
5581end
5582
5583note ======== registers and words ========
5584note alloc: the next free register of the pool (after the parameters); error 12 when none is left
5585fn alloc to ulong
5586i = add get npar 0 get nslot 0
5587if ge i 16
5588note d2site 56|alloc: register pool exhausted; condition if ge i 16
5589put d2site 0 56
5590fail 12
5591end
5592put vsl i 0
5593put nslot 0 add get nslot 0 1
5594ret poolc i
5595end
5596
5597note destreg: d, or a new temporary when d is 255
5598fn destreg d ulong to ulong
5599if eq d 255
5600ret alloc
5601end
5602ret d
5603end
5604
5605note e3: emit op | d | n << 5 | m << 16
5606fn e3 op ulong d ulong n ulong m ulong to void
5607emit or or or op d shl n 5 shl m 16
5608end
5609
5610note trapsite: note the place and code of a branch to the trap stub, then emit it. trapc: B.cond, as om4.
5611note The trap list grows with the arena (group 10); island keeps every such branch within its reach.
5612fn trapsite w ulong code ulong to void
5613n = get nt 0
5614if ge n get a_gp 10
5615a_need 10 n
5616end
5617put a_ar add get a_rb 44 n get oc 0
5618put a_ar add get a_rb 45 n code
5619put nt 0 add n 1
5620emit w
5621if eq get om2m 0 1
5622siterec
5623end
5624end
5625
5626fn trapc cc ulong code ulong to void
5627if ne get xtarget 0 0
5628xtrap cc code
5629ret
5630end
5631trapsite or 1409286144 cc code
5632end
5633
5634fn rdword at ulong to ulong
5635a = ulong a_ob at
5636b = shl ulong a_ob add at 1 8
5637c = shl ulong a_ob add at 2 16
5638d = shl ulong a_ob add at 3 24
5639ret or or or a b c d
5640end
5641
5642fn wrword at ulong w ulong to void
5643a_bput 1 at uchar and w 255
5644a_bput 1 add at 1 uchar and shr w 8 255
5645a_bput 1 add at 2 uchar and shr w 16 255
5646a_bput 1 add at 3 uchar and shr w 24 255
5647end
5648
5649note bdisp: the checked word distance from a branch at `at` to `target` for its signed w-bit word field:
5650note w 19 for B.cond / CBZ / CBNZ (C6.2.34, C6.2.78, C6.2.77), w 26 for B (C6.2.35) and BL. The
5651note target must be word aligned and at most 2^(w-1) - 1 words forward or 2^(w-1) words back (w 19: 1048572
5652note bytes forward, 1048576 back; w 26: 134217724 forward, 134217728 back), else error 24 before any
5653note artifact is accepted. Returns the distance masked to w bits.
5654fn bdisp at ulong target ulong w ulong to ulong
5655diff = sub target at
5656if ne and diff 3 0
5657note d2site 57|bdisp: AArch64 branch displacement out of range; condition if ne and diff 3 0
5658put d2site 0 57
5659fail 24
5660end
5661span = shl ulong 1 add w 1
5662if and gt diff sub span 4 lt diff sub ulong 0 span
5663note d2site 58|bdisp: AArch64 branch displacement out of range; condition if and gt diff sub span 4 lt diff sub ulong 0 span
5664put d2site 0 58
5665fail 24
5666end
5667ret and shr diff 2 sub shl ulong 1 w 1
5668end
5669
5670note patch19: the word distance from a B.cond / CBZ / CBNZ at `at` to `target`, into bits 5..23
5671fn patch19 at ulong target ulong to void
5672if ne get xtarget 0 0
5673xpatch at target
5674if eq target get oc 0
5675put tgoc 0 target
5676end
5677ret
5678end
5679d = bdisp at target 19
5680wrword at or rdword at shl d 5
5681if eq target get oc 0
5682put tgoc 0 target
5683end
5684end
5685
5686note patch26: the word distance from a B at `at` to `target`, into bits 0..25, checked by bdisp. The output
5687note grows with the arena, whose 2^27 bytes equal the reach of B and BL, so a legal unit stays in reach; the
5688note check keeps a wrong B from ever being written (error 24, the ISA's boundary) if the arena grows.
5689fn patch26 at ulong target ulong to void
5690if ne get xtarget 0 0
5691xpatch at target
5692if eq target get oc 0
5693put tgoc 0 target
5694end
5695ret
5696end
5697d = bdisp at target 26
5698wrword at or rdword at d
5699if eq target get oc 0
5700put tgoc 0 target
5701end
5702end
5703
5704note back: emit B to an earlier place (C6.2.35)
5705fn back addr ulong to void
5706if ne get xtarget 0 0
5707p = xbranch 14
5708xpatch p addr
5709ret
5710end
5711emit or 335544320 bdisp get oc 0 addr 26
5712end
5713
5714note matconst: put a 64-bit value in register r: MOVZ (C6.2.285) or, for a value with the top bit set,
5715note MOVN (C6.2.284) with the first halfword that differs from the fill, then MOVK (C6.2.283) for each
5716note other such halfword. om4 MATCONST.
5717fn matconst r ulong v ulong to void
5718if ne get xtarget 0 0
5719ximm 0 v
5720xstore 0 r
5721ret
5722end
5723fill = ulong 0
5724mop = ulong 3531603968
5725if ne shr v 63 0
5726fill = ulong 65535
5727mop = ulong 2457862144
5728end
5729started = false
5730hw = ulong 0
5731while lt hw 4
5732h = and shr v shl hw 4 65535
5733if ne h fill
5734if started
5735emit or or or 4068474880 shl h 5 shl hw 21 r
5736else
5737emit or or or mop shl xor h fill 5 shl hw 21 r
5738started = true
5739end
5740end
5741hw = add hw 1
5742end
5743if not started
5744emit or mop r
5745end
5746end
5747
5748note canon: u8/u16/u32 UBFM Xr, Xr, #0, #w-1 (C6.2.487); i8/i16/i32 SBFM (C6.2.355); else nothing
5749fn canon r ulong t ulong to void
5750canonto r r t
5751end
5752
5753note canonto: canon of Xn written to Xd (the same UBFM / SBFM with Rd = d, Rn = n)
5754fn canonto d ulong n ulong t ulong to void
5755if ne get xtarget 0 0
5756xload 0 n
5757xcanrax t
5758xstore 0 d
5759ret
5760end
5761if lt t 2
5762ret
5763end
5764if eq t 5
5765ret
5766end
5767if eq t 9
5768ret
5769end
5770base = ulong 3544186880
5771if gt t 5
5772base = ulong 2470445056
5773end
5774emit or or or base shl sub twid t 1 10 d shl n 5
5775end
5776
5777note chkext: CMP Xr, Wr, SXTB/SXTH/SXTW (SUBS extended, C6.2.463), then B.NE trap code
5778fn chkext r ulong t ulong code ulong to void
5779if ne get xtarget 0 0
5780xext r t code
5781ret
5782end
5783emit or or or 3944742943 shl sub t 2 13 shl r 16 shl r 5
5784trapc 1 code
5785end
5786
5787note range: error 8 unless v is a value of type t; big = the number was written as 2^63 or more
5788fn range v ulong t ulong big ulong to void
5789w = twid t
5790if eq w 64
5791if eq t 9
5792if ne big 0
5793note d2site 59|range: number out of range for its type or place; condition if ne big 0
5794put d2site 0 59
5795fail 8
5796end
5797ret
5798end
5799if ne big 0
5800ret
5801end
5802if ne shr v 63 0
5803note d2site 60|range: number out of range for its type or place; condition if ne shr v 63 0
5804put d2site 0 60
5805fail 8
5806end
5807ret
5808end
5809if ne big 0
5810note d2site 61|range: number out of range for its type or place; condition if ne big 0
5811put d2site 0 61
5812fail 8
5813end
5814lim = shl ulong 1 w
5815if lt t 6
5816if ge v lim
5817note d2site 62|range: number out of range for its type or place; condition if ge v lim
5818put d2site 0 62
5819fail 8
5820end
5821ret
5822end
5823half = shr lim 1
5824if ge add v half lim
5825note d2site 63|range: number out of range for its type or place; condition if ge add v half lim
5826put d2site 0 63
5827fail 8
5828end
5829end
5830
5831note cset: CSET Xr, cond = CSINC Xr, XZR, XZR, opposite cond (C6.2.141)
5832fn cset r ulong cc ulong to void
5833if ne get xtarget 0 0
5834xb 15 add 144 xcc cc 192
5835xb 72 15 182
5836emitb 192
5837xstore 0 r
5838ret
5839end
5840emit or or 2594113504 r shl xor cc 1 12
5841end
5842
5843note force: put a value (kind 1 register, 3 number, 4 flags, 9 float in a twin: FMOV Xr, Dn) in register
5844note r; a bare number is error 11
5845fn force k ulong v ulong t ulong r ulong to void
5846if ne get xtarget 0 0
5847if eq k 1
5848xload 0 v
5849xstore 0 r
5850ret
5851end
5852end
5853if eq k 1
5854if ne v r
5855emit or or 2852127712 r shl v 16
5856end
5857ret
5858end
5859if or eq k 3 eq k 7
5860matconst r v
5861ret
5862end
5863if eq k 4
5864cset r v
5865ret
5866end
5867if eq k 9
5868fv2x t vtw v r
5869ret
5870end
5871note d2site 64|force: bare number without a type from its context
5872put d2site 0 64
5873fail 11
5874end
5875
5876note matreg: a register holding the value
5877fn matreg k ulong v ulong t ulong to ulong
5878if eq k 1
5879ret v
5880end
5881if eq k 9
5882fv2x t vtw v v
5883ret v
5884end
5885r = alloc
5886force k v t r
5887ret r
5888end
5889
5890note spop: ADD (C6.2.5) / SUB (C6.2.457) SP, SP by a multiple of 16 below 2^24: low 12 bits, then the
5891note high 12 bits LSL 12; nothing for a zero part
5892fn spop base ulong bytes ulong to void
5893lo = and bytes 4095
5894if ne lo 0
5895emit or or base 1023 shl lo 10
5896end
5897hi = and shr bytes 12 4095
5898if ne hi 0
5899emit or or base 4195327 shl hi 10
5900end
5901end
5902
5903note spadd and spsub move SP for a transient push (a save area, a host word's private buffer) and keep
5904note osp, the bytes of transient push live at this point of the emitted code, and osmax, its largest value
5905note in the function. A native object records stkbytes + osmax as the function's own stack, so the
5906note module linker's whole-program stack proof covers every push. A pop larger than osp sets osbad;
5907note an object function with osbad set, or osp not 0 at its end, is refused (fnend), never under-reported.
5908fn spadd bytes ulong to void
5909if lt get osp 0 bytes
5910put osbad 0 1
5911put osp 0 0
5912else
5913put osp 0 sub get osp 0 bytes
5914end
5915if ne get xtarget 0 0
5916xsp 0 bytes
5917ret
5918end
5919spop 2432696320 bytes
5920end
5921
5922fn spsub bytes ulong to void
5923put osp 0 add get osp 0 bytes
5924if gt get osp 0 get osmax 0
5925put osmax 0 get osp 0
5926end
5927if ne get xtarget 0 0
5928xsp 1 bytes
5929ret
5930end
5931spop 3506438144 bytes
5932end
5933
5934note spaddk and spsubk move SP for the frame (local arrays and structs), which stkbytes counts and epi
5935note gives back; they leave osp alone.
5936fn spaddk bytes ulong to void
5937if ne get xtarget 0 0
5938xsp 0 bytes
5939ret
5940end
5941spop 2432696320 bytes
5942end
5943
5944fn spsubk bytes ulong to void
5945if ne get xtarget 0 0
5946xsp 1 bytes
5947ret
5948end
5949spop 3506438144 bytes
5950end
5951
5952note stkchk: program mode only: CMP SP, X28 (C6.2.463); B.LO trap 6
5953fn stkchk to void
5954if ne get xtarget 0 0
5955ret
5956end
5957if ne get progmode 0 0
5958emit 3946603519
5959trapc 3 6
5960end
5961end
5962
5963note epi: give back the stack of the local arrays, then RET (C6.2.338)
5964fn epi to void
5965if ne get xtarget 0 0
5966xload 0 0
5967emitb 201
5968emitb 195
5969ret
5970end
5971spaddk get stkbytes 0
5972emit 3596551104
5973end
5974
5975fn dead1 to void
5976put dead 0 1
5977end
5978
5979note pushb / pushnh: open a block (om4 PUSHB, split in two because a call takes at most 6 values). The
5980note block stack grows with the arena (group 13). bk0 / bc0: the break and continue counts when it opened,
5981note so a loop's end patches only its own (s_end) and gives their entries back.
5982fn pushb br ulong k ulong head ulong reg ulong ty ulong to void
5983n = get nb 0
5984if ge n get a_gp 13
5985a_need 13 n
5986end
5987put a_ar add get a_rb 60 n get nbrk 0
5988put a_ar add get a_rb 61 n get ncont 0
5989put a_ar add get a_rb 49 n k
5990put a_ar add get a_rb 50 n br
5991put a_ar add get a_rb 51 n head
5992put a_ar add get a_rb 52 n reg
5993put a_ar add get a_rb 53 n ty
5994put a_ar add get a_rb 56 n 0
5995put a_ar add get a_rb 57 n 0
5996put nb 0 add n 1
5997note fz_push / fz_else / fz_join: the sets when block n opens; at its else (the then sets kept, the
5998note opening sets back); at its end (kind k: 1 if, 2 else, 3 while, 4 for)
5999j = ulong 0
6000while lt j get fz_n 0
6001a_p 68 add mul n 16 j get fz_cur j
6002j = add j 1
6003end
6004end
6005
6006fn pushnh names ulong hd ulong to void
6007n = sub get nb 0 1
6008put a_ar add get a_rb 54 n names
6009put a_ar add get a_rb 55 n hd
6010end
6011
6012note ======== small readers ========
6013fn elemtype t ulong to void
6014if lt t 2
6015note d2site 65|elemtype: word or declaration in a place that does not allow it; condition if lt t 2
6016put d2site 0 65
6017fail 9
6018end
6019if ge t 64
6020note d2site 66|elemtype: type mismatch; condition if ge t 64
6021put d2site 0 66
6022fail 7
6023end
6024end
6025
6026note arrlen: an array length 1 .. 16777216 (error 8 below, 23 above, 23 when written as 2^63 or more)
6027fn arrlen v ulong to void
6028if ne get tbig 0 0
6029note d2site 67|arrlen: size capacity; condition if ne get tbig 0 0
6030put d2site 0 67
6031fail 23
6032end
6033if or eq v 0 ne shr v 63 0
6034note d2site 68|arrlen: number out of range for its type or place; condition if or eq v 0 ne shr v 63 0
6035put d2site 0 68
6036fail 8
6037end
6038if gt v 16777216
6039note d2site 69|arrlen: size capacity; condition if gt v 16777216
6040put d2site 0 69
6041fail 23
6042end
6043end
6044
6045note lenval: an array length, loop bound or trap code token: a number, or an integer constant name (kind 9).
6046note A name that is not an integer constant is error 16. When the line ends it is error eolc: 16 for a pool,
6047note a new array or a parameter written without its length (OMEGESE s.7, as om4), 4 for trap and bound.
6048fn lenval eolc ulong to ulong
6049tok
6050k = get tk 0
6051if eq k 0
6052note d2site 70|lenval: line ended before the required array expression; condition if eq k 0
6053put d2site 0 70
6054fail eolc
6055end
6056if eq k 2
6057ret get tw 0
6058end
6059if eq k 1
6060if le get tl 0 63
6061e = findname get tw 0
6062if ne e 0
6063if eq uchar get a_ar add get a_rb 7 sub e 1 9
6064t = ulong uchar get a_ar add get a_rb 5 sub e 1
6065if ge t 10
6066note d2site 71|lenval: syntax: unknown or misplaced word; condition if ge t 10
6067put d2site 0 71
6068fail 16
6069end
6070put tbig 0 0
6071ret get a_ar add get a_rb 8 sub e 1
6072end
6073end
6074end
6075end
6076note d2site 72|lenval: syntax: unknown or misplaced word
6077put d2site 0 72
6078fail 16
6079ret 0
6080end
6081
6082note typeword: read a type name -> 1..9
6083fn typeword to ulong
6084put dexp 0 2
6085tok
6086k = get tk 0
6087if eq k 0
6088note d2site 73|typeword: the line ends where a word or value is needed; condition if eq k 0
6089put d2site 0 73
6090fail 4
6091end
6092if ne k 1
6093note d2site 74|typeword: syntax: unknown or misplaced word; condition if ne k 1
6094put d2site 0 74
6095fail 16
6096end
6097if gt get tl 0 8
6098note d2site 75|typeword: syntax: unknown or misplaced word; condition if gt get tl 0 8
6099put d2site 0 75
6100fail 16
6101end
6102c = kw get tw 0
6103if eq c 0
6104a = findab get tw 0
6105if ne a 0
6106ret add a 63
6107end
6108note d2site 76|typeword: syntax: unknown or misplaced word; condition if eq c 0
6109put d2site 0 76
6110unkfail 16
6111end
6112if eq c 76
6113note d2site 77|typeword: word or declaration in a place that does not allow it; condition if eq c 76
6114put d2site 0 77
6115fail 9
6116end
6117if or eq c 88 eq c 89
6118if ne get irmode 0 0
6119note d2site 78|typeword: word or declaration in a place that does not allow it; condition if ne get irmode 0 0
6120put d2site 0 78
6121fail 9
6122end
6123end
6124if eq c 88
6125ret 10
6126end
6127if eq c 89
6128ret 11
6129end
6130if eq c 223
6131ret 13
6132end
6133if gt sub c 1 8
6134note d2site 79|typeword: syntax: unknown or misplaced word; condition if gt sub c 1 8
6135put d2site 0 79
6136fail 16
6137end
6138ret c
6139end
6140
6141note eol: the line must end here
6142fn eol to void
6143put dexp 0 6
6144tok
6145k = get tk 0
6146if and ne k 0 ne k 3
6147note d2site 80|eol: extra words after a complete statement; condition if and ne k 0 ne k 3
6148put d2site 0 80
6149fail 5
6150end
6151end
6152
6153note arrname: read an array name -> its index + 1. pk 1 where a run-time pool may be named (get, put, len,
6154note read, write, part (then error 19), enlarge); with pk 0 a pool is error 7 (every host word, mcopy, ...)
6155fn arrname pk ulong to ulong
6156put dexp 0 3
6157tok
6158k = get tk 0
6159if eq k 0
6160note d2site 81|arrname: the line ends where a word or value is needed; condition if eq k 0
6161put d2site 0 81
6162fail 4
6163end
6164if eq k 3
6165note d2site 82|arrname: the line ends where a word or value is needed; condition if eq k 3
6166put d2site 0 82
6167fail 4
6168end
6169if ne k 1
6170note d2site 83|arrname: syntax: unknown or misplaced word; condition if ne k 1
6171put d2site 0 83
6172fail 16
6173end
6174if gt get tl 0 63
6175note d2site 84|arrname: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
6176put d2site 0 84
6177fail 13
6178end
6179if eq kw get tw 0 193
6180note d2site 85|arrname: word or declaration in a place that does not allow it; condition if eq kw get tw 0 193
6181put d2site 0 85
6182fail 9
6183end
6184e = findname get tw 0
6185if eq e 0
6186note d2site 86|arrname: unknown name or field, or a word this mode does not provide; condition if eq e 0
6187put d2site 0 86
6188fail 3
6189end
6190k = ulong uchar get a_ar add get a_rb 7 sub e 1
6191if eq k 0
6192note d2site 87|arrname: type mismatch; condition if eq k 0
6193put d2site 0 87
6194fail 7
6195end
6196if eq k 10
6197if eq pk 0
6198note d2site 88|arrname: type mismatch; condition if eq pk 0
6199put d2site 0 88
6200fail 7
6201end
6202end
6203ret e
6204end
6205
6206note topname: read a new name for a global or a text -> its packed word
6207fn topname to ulong
6208tok
6209if ne get tk 0 1
6210note d2site 89|topname: syntax: unknown or misplaced word; condition if ne get tk 0 1
6211put d2site 0 89
6212fail 16
6213end
6214if gt get tl 0 63
6215note d2site 90|topname: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
6216put d2site 0 90
6217fail 13
6218end
6219w = get tw 0
6220if ne kw w 0
6221note d2site 91|topname: syntax: unknown or misplaced word; condition if ne kw w 0
6222put d2site 0 91
6223fail 16
6224end
6225newname w get tl 0 get ts 0
6226ret w
6227end
6228
6229note ---- value results (om4 x0 kind 1 register / 2 bare number / 3 typed number / 4 flags, x1 register,
6230note number or condition, x2 type). fr: 32 cells per value nesting depth (arena group 18, 0..32768): 0..5 the two operands of
6231note a binary op (kind, value, type each), 8..25 a call's arguments (kind, value, array name each) ----
6232global rk ulong 1
6233global rv ulong 1
6234global rt ulong 1
6235global depth ulong 1
6236
6237note ======== BINOP (om4 BINOP and its BO_* parts): two values already read, types settled ========
6238note bo_w3: emit fx | rd | ra << 5 | (imm12 << 10, or rb << 16)
6239fn bo_w3 fx ulong rd ulong ra ulong rb ulong imm ulong to void
6240if ne imm 0
6241emit or or or fx rd shl ra 5 shl rb 10
6242else
6243emit or or or fx rd shl ra 5 shl rb 16
6244end
6245end
6246
6247note bo_fix: after a 64-bit op on rd: u8/u16/u32 wrap (canon), i8/i16/i32 overflow check (trap 1)
6248fn bo_fix rd ulong ty ulong to void
6249if lt ty 6
6250canon rd ty
6251ret
6252end
6253if eq ty 9
6254ret
6255end
6256chkext rd ty 1
6257end
6258
6259note bo_schk: a shift amount in a register must be below the width: CMP Xb, #w; B.HS trap 7
6260fn bo_schk ty ulong rb ulong to void
6261if ne get xtarget 0 0
6262xload 0 rb
6263ximm 1 twid ty
6264xrr 57 0 1
6265xtrap 2 7
6266ret
6267end
6268emit or or 4043309087 shl twid ty 10 shl rb 5
6269trapc 2 7
6270end
6271
6272note add, sub: u32 the 32-bit form; i64 ADDS/SUBS + B.VS trap 1; others 64-bit then bo_fix (om4 BO_ADD)
6273fn bo_add op ulong ty ulong ra ulong rb ulong imm ulong rd ulong to void
6274if ne get xtarget 0 0
6275xarith op ty ra rb imm rd
6276ret
6277end
6278fx = ulong 2332033024
6279if eq op 34
6280fx = ulong 3405774848
6281end
6282if ne imm 0
6283fx = ulong 2432696320
6284if eq op 34
6285fx = ulong 3506438144
6286end
6287end
6288if eq ty 4
6289bo_w3 xor fx 2147483648 rd ra rb imm
6290ret
6291end
6292if eq ty 9
6293bo_w3 or fx 536870912 rd ra rb imm
6294trapc 6 1
6295ret
6296end
6297if eq ty 13
6298bo_w3 or fx 536870912 rd ra rb imm
6299if eq op 34
6300trapc 3 1
6301else
6302trapc 2 1
6303end
6304ret
6305end
6306bo_w3 fx rd ra rb imm
6307bo_fix rd ty
6308end
6309
6310note mul: i64 SMULH t, MUL, CMP t, rd, ASR #63, B.NE trap 1 (om4 BO_MUL)
6311fn bo_mul ty ulong ra ulong rb ulong rd ulong to void
6312if ne get xtarget 0 0
6313xarith 35 ty ra rb 0 rd
6314ret
6315end
6316if eq ty 9
6317t = alloc
6318e3 2604694528 t ra rb
6319bo_w3 2600500224 rd ra rb 0
6320e3 3951098911 0 t rd
6321trapc 1 1
6322ret
6323end
6324if eq ty 13
6325t = alloc
6326e3 2613083136 t ra rb
6327bo_w3 2600500224 rd ra rb 0
6328emit or 4043309087 shl t 5
6329trapc 1 1
6330ret
6331end
6332if eq ty 4
6333bo_w3 453016576 rd ra rb 0
6334ret
6335end
6336bo_w3 2600500224 rd ra rb 0
6337bo_fix rd ty
6338end
6339
6340note div, rem (om4 BO_DIV, BO_SDIV): CBZ Xb trap 2 unless fl bit 1 (b a number other than 0); UDIV or
6341note SDIV; rem: t = a / b, rd = a - t * b (MSUB); i64 div: CMN Xb, #1; B.NE +3; NEGS XZR, Xa; B.VS trap 1,
6342note unless fl bit 2 (b a number other than -1)
6343fn bo_div op ulong ty ulong ra ulong rb ulong rd ulong fl ulong to void
6344if ne get xtarget 0 0
6345xdiv op ty ra rb rd fl
6346ret
6347end
6348if eq and fl 1 0
6349trapsite or 3019898880 rb 2
6350end
6351if eq op 37
6352t = alloc
6353if and ge ty 6 le ty 9
6354e3 2596277248 t ra rb
6355else
6356e3 2596276224 t ra rb
6357end
6358e3 or 2600501248 shl ra 10 rd t rb
6359ret
6360end
6361if or lt ty 6 eq ty 13
6362bo_w3 2596276224 rd ra rb 0
6363ret
6364end
6365if eq ty 9
6366if eq and fl 2 0
6367emit or 2969568287 shl rb 5
6368emit 1409286241
6369emit or 3942646783 shl ra 16
6370trapc 6 1
6371end
6372end
6373bo_w3 2596277248 rd ra rb 0
6374if ne ty 9
6375bo_fix rd ty
6376end
6377end
6378
6379note and, or, xor (om4 BO_LOG)
6380fn bo_log op ulong ra ulong rb ulong rd ulong to void
6381if ne get xtarget 0 0
6382xarith op 5 ra rb 0 rd
6383ret
6384end
6385fx = ulong 2315255808
6386if eq op 39
6387fx = ulong 2852126720
6388end
6389if eq op 40
6390fx = ulong 3388997632
6391end
6392bo_w3 fx rd ra rb 0
6393end
6394
6395note bo_lsl: LSL Xd, Xn, #s as UBFM Xd, Xn, #(64-s) mod 64, #63-s
6396fn bo_lsl ra ulong s ulong rd ulong to void
6397if ne get xtarget 0 0
6398xshift 41 5 ra s 1 rd
6399ret
6400end
6401r = shl and sub 64 s 63 16
6402r = or r shl sub 63 s 10
6403r = or r shl ra 5
6404emit or or 3544186880 r rd
6405end
6406
6407note shl (om4 BO_SHL, BS_64): by a number s: UBFM Xd, Xn, #(64-s) mod 64, #63-s; by a register: the amount
6408note check, LSLV; i64: t = a << s, X16 = t >> s arithmetic, CMP X16, Xa, B.NE trap 1, MOV Xd, Xt
6409fn bo_shl ty ulong ra ulong rb ulong imm ulong rd ulong to void
6410if ne get xtarget 0 0
6411xshift 41 ty ra rb imm rd
6412ret
6413end
6414if eq ty 9
6415t = alloc
6416if ne imm 0
6417bo_lsl ra rb t
6418emit or or 2470509584 shl rb 16 shl t 5
6419else
6420bo_schk ty rb
6421e3 2596282368 t ra rb
6422e3 2596284432 0 t rb
6423end
6424emit or 3942646303 shl ra 16
6425trapc 1 1
6426emit or or 2852127712 rd shl t 16
6427ret
6428end
6429if ne imm 0
6430bo_lsl ra rb rd
6431bo_fix rd ty
6432ret
6433end
6434bo_schk ty rb
6435if eq ty 4
6436bo_w3 448798720 rd ra rb 0
6437ret
6438end
6439bo_w3 2596282368 rd ra rb 0
6440bo_fix rd ty
6441end
6442
6443note shr: unsigned LSR, signed ASR; by a number UBFM / SBFM Xd, Xn, #s, #63; by a register the amount check
6444note then LSRV / ASRV (om4 BO_SHR)
6445fn bo_shr ty ulong ra ulong rb ulong imm ulong rd ulong to void
6446if ne get xtarget 0 0
6447xshift 42 ty ra rb imm rd
6448ret
6449end
6450if ne imm 0
6451fi = ulong 3544251392
6452if ge ty 6
6453fi = ulong 2470509568
6454end
6455emit or or or fi shl rb 16 shl ra 5 rd
6456ret
6457end
6458bo_schk ty rb
6459fx = ulong 2596283392
6460if ge ty 6
6461fx = ulong 2596284416
6462end
6463bo_w3 fx rd ra rb 0
6464end
6465
6466note comparisons: CMP Xa, #imm or CMP Xa, Xb; the result is the flags and a condition (om4 BO_CMP)
6467fn bo_cmp op ulong ty ulong ra ulong rb ulong imm ulong to void
6468if ne get xtarget 0 0
6469xcmp ra rb imm
6470else
6471if ne imm 0
6472emit or or 4043309087 shl rb 10 shl ra 5
6473else
6474emit or or 3942645791 shl rb 16 shl ra 5
6475end
6476end
6477i = mul sub op 43 2
6478if and ge ty 6 le ty 9
6479i = add i 1
6480end
6481put rk 0 4
6482put rv 0 conds i
6483put rt 0 1
6484end
6485
6486note Baseline SSE2, Intel SDM MOVD/MOVQ, scalar SS/SD, UCOMIS, CVTSI and CVTT instructions.
6487note WolframLanguageEvaluator: {2^31,2^63,2^22,2^51} -> {2147483648,9223372036854775808,4194304,2251799813685248}.
6488note WolframLanguageEvaluator: FromDigits[#,16]& /@ {"7F800000","7FF0000000000000","7FC00000","7FF8000000000000"}
6489note -> {2139095040,9218868437227405312,2143289344,9221120237041090560}.
6490fn xfmask ty ulong kind ulong to ulong
6491if eq ty 10
6492if eq kind 0
6493ret 2147483648
6494end
6495if eq kind 1
6496ret 2147483647
6497end
6498if eq kind 2
6499ret 4194304
6500end
6501if eq kind 3
6502ret 2139095040
6503end
6504ret 2143289344
6505end
6506if eq kind 0
6507ret 9223372036854775808
6508end
6509if eq kind 1
6510ret 9223372036854775807
6511end
6512if eq kind 2
6513ret 2251799813685248
6514end
6515if eq kind 3
6516ret 9218868437227405312
6517end
6518ret 9221120237041090560
6519end
6520
6521note MOVD clears EAX's upper bits on extraction; no float sign extension.
6522fn xfmov ty ulong op ulong vr ulong to void
6523emitb 102
6524if eq ty 11
6525emitb 72
6526end
6527xb 15 op add 192 shl vr 3
6528end
6529
6530fn xfsse ty ulong op ulong mr ulong to void
6531if eq ty 10
6532emitb 243
6533else
6534emitb 242
6535end
6536xb 15 op mr
6537end
6538
6539fn xfucom ty ulong mr ulong to void
6540if eq ty 11
6541emitb 102
6542end
6543xb 15 46 mr
6544end
6545
6546note Raw Intel condition for parity: existing xbranch takes the A64 condition vocabulary.
6547fn xfbranch cc ulong to ulong
6548p = get oc 0
6549emitb 15
6550emitb uchar add 128 cc
6551xword 0
6552ret p
6553end
6554
6555note Leaves the raw value in RAX, magnitude in RCX, and unsigned magnitude-versus-infinity flags.
6556fn xfclass ty ulong r ulong to void
6557xload 0 r
6558ximm 1 xfmask ty 1
6559xrr 33 1 0
6560ximm 2 xfmask ty 3
6561xrr 57 1 2
6562end
6563
6564note Arm FPProcessNaNs priority: first signaling NaN, second signaling NaN, then first quiet NaN.
6565note minNum/maxNum additionally return the numeric argument when paired with one quiet NaN.
6566note Return the selected-result jump for the caller to patch past its normal arithmetic.
6567fn xfnans ty ulong a ulong b ulong num ulong d ulong to ulong
6568note Emit shared result stubs first so each case patches immediately instead of retaining its own fixup.
6569skip = xbranch 14
6570quiet = get oc 0
6571ximm 1 xfmask ty 2
6572xrr 9 0 1
6573store = get oc 0
6574xstore 0 d
6575d = xbranch 14
6576xpatch skip get oc 0
6577xfclass ty a
6578skip = xbranch 8
6579xfclass ty b
6580bn = xbranch 8
6581none = xbranch 14
6582xpatch skip get oc 0
6583ximm 1 xfmask ty 2
6584xrr 133 0 1
6585p = xbranch 0
6586xpatch p quiet
6587xfclass ty b
6588skip = xbranch 9
6589ximm 1 xfmask ty 2
6590xrr 133 0 1
6591p = xbranch 0
6592xpatch p quiet
6593xload 0 a
6594p = xbranch 14
6595xpatch p store
6596xpatch skip get oc 0
6597if ne num 0
6598xload 0 b
6599else
6600xload 0 a
6601end
6602p = xbranch 14
6603xpatch p store
6604xpatch bn get oc 0
6605if ne num 0
6606ximm 1 xfmask ty 2
6607xrr 133 0 1
6608p = xbranch 0
6609xpatch p quiet
6610xload 0 a
6611p = xbranch 14
6612xpatch p store
6613else
6614p = xbranch 14
6615xpatch p quiet
6616end
6617xpatch none get oc 0
6618ret d
6619end
6620
6621note SSE invalid arithmetic produces a negative indefinite NaN; Arm's default NaN is positive.
6622note Operand NaNs have already bypassed arithmetic, retaining their sign and payload.
6623fn xfdefnan ty ulong d ulong to void
6624xfclass ty d
6625ok = xbranch 9
6626ximm 0 xfmask ty 4
6627xstore 0 d
6628xpatch ok get oc 0
6629end
6630
6631fn xfbin op ulong ty ulong a ulong b ulong d ulong to void
6632nanend = xfnans ty a b 0 d
6633f2v ty a 0
6634f2v ty b 1
6635code = ulong 89
6636if eq op 33
6637code = ulong 88
6638end
6639if eq op 34
6640code = ulong 92
6641end
6642if eq op 36
6643code = ulong 94
6644end
6645xfsse ty code 193
6646fv2x ty 0 d
6647xfdefnan ty d
6648xpatch nanend get oc 0
6649end
6650
6651fn xfminmax c ulong ty ulong a ulong b ulong d ulong to void
6652nanend = xfnans ty a b 1 d
6653f2v ty a 0
6654f2v ty b 1
6655xfucom ty 193
6656cc = ulong 3
6657if eq c 94
6658cc = ulong 8
6659end
6660takea = xbranch cc
6661if eq c 94
6662cc = ulong 3
6663else
6664cc = ulong 8
6665end
6666takeb = xbranch cc
6667note Equal finite operands have equal bits except signed zero: OR chooses -0, AND chooses +0.
6668xload 0 a
6669xload 1 b
6670if eq c 94
6671xrr 33 0 1
6672else
6673xrr 9 0 1
6674end
6675xstore 0 d
6676equalend = xbranch 14
6677xpatch takea get oc 0
6678xload 0 a
6679xstore 0 d
6680aend = xbranch 14
6681xpatch takeb get oc 0
6682xload 0 b
6683xstore 0 d
6684xpatch equalend get oc 0
6685xpatch aend get oc 0
6686xpatch nanend get oc 0
6687end
6688
6689note Normalize the predicate to TEST flags; callers retain the existing rk=4, rv=NE contract.
6690fn xfcmp op ulong ty ulong a ulong b ulong to void
6691f2v ty a 0
6692f2v ty b 1
6693xfucom ty 193
6694unord = xfbranch 10
6695cc = ulong 4
6696if eq op 44
6697cc = ulong 5
6698end
6699if eq op 45
6700cc = ulong 2
6701end
6702if eq op 46
6703cc = ulong 6
6704end
6705if eq op 47
6706cc = ulong 7
6707end
6708if eq op 48
6709cc = ulong 3
6710end
6711xb 15 add 144 cc 192
6712done = xbranch 14
6713xpatch unord get oc 0
6714if eq op 44
6715ximm 0 1
6716else
6717ximm 0 0
6718end
6719xpatch done get oc 0
6720xb 72 15 182
6721emitb 192
6722xrr 133 0 0
6723put rk 0 4
6724put rv 0 1
6725put rt 0 1
6726end
6727
6728fn xfsito ty ulong to void
6729if eq ty 10
6730emitb 243
6731else
6732emitb 242
6733end
6734emitb 72
6735xb 15 42 192
6736end
6737
6738fn xfint ft ulong tt ulong a ulong d ulong to void
6739xload 0 a
6740if eq ft 5
6741xrr 133 0 0
6742small = xbranch 10
6743note Sticky halve before signed conversion preserves nearest-even rounding for the unsigned high half.
6744xrr 137 2 0
6745xb 72 209 234
6746ximm 1 1
6747xrr 33 0 1
6748xrr 9 0 2
6749xfsito tt
6750xfsse tt 88 192
6751done = xbranch 14
6752xpatch small get oc 0
6753xfsito tt
6754xpatch done get oc 0
6755else
6756xfsito tt
6757end
6758fv2x tt 0 d
6759end
6760
6761fn xfconst bits ulong to void
6762ximm 0 bits
6763xfmov 11 110 1
6764end
6765
6766fn xfcvtt to void
6767emitb 242
6768emitb 72
6769xb 15 44 192
6770end
6771
6772
6773note Widen f32 exactly, guard NaN and the destination's own bounds, then CVTT toward zero.
6774note WolframLanguageEvaluator: Table[BitShiftLeft[1023+k,52],{k,{7,8,15,16,31,32,63,64}}]
6775note -> {4638707616191610880,4643211215818981376,4674736413210574848,4679240012837945344,4746794007248502784,4751297606875873280,4890909195324358656,4895412794951729152}.
6776fn xftoint ft ulong tt ulong d ulong to void
6777n = twid tt
6778sg = and ge tt 6 le tt 9
6779if eq ft 10
6780xfsse 10 90 192
6781end
6782xfucom 11 192
6783nan = xfbranch 10
6784if sg
6785n = sub n 1
6786end
6787xfconst shl add ulong 1023 n 52
6788xfucom 11 193
6789above = xbranch 2
6790if sg
6791xfconst or 9223372036854775808 shl add ulong 1023 n 52
6792else
6793xfconst 0
6794end
6795xfucom 11 193
6796below = xbranch 9
6797if and not sg eq n 64
6798xfconst 4890909195324358656
6799xfucom 11 193
6800small = xbranch 3
6801xfsse 11 92 193
6802xfcvtt
6803ximm 1 9223372036854775808
6804xrr 9 0 1
6805done = xbranch 14
6806xpatch small get oc 0
6807xfcvtt
6808xpatch done get oc 0
6809else
6810xfcvtt
6811end
6812done = xbranch 14
6813xpatch nan get oc 0
6814ximm 0 0
6815nan = xbranch 14
6816xpatch above get oc 0
6817maxv = ulong 18446744073709551615
6818if sg
6819maxv = sub shl ulong 1 n 1
6820else
6821if lt n 64
6822maxv = sub shl ulong 1 n 1
6823end
6824end
6825ximm 0 maxv
6826above = xbranch 14
6827xpatch below get oc 0
6828if sg
6829ximm 0 sub ulong 0 shl ulong 1 n
6830else
6831ximm 0 0
6832end
6833xpatch done get oc 0
6834xpatch nan get oc 0
6835xpatch above get oc 0
6836xstore 0 d
6837end
6838
6839fn xfconv ft ulong tt ulong a ulong to ulong
6840if or eq ft 1 eq tt 1
6841note d2site 92|xfconv: word or declaration in a place that does not allow it; condition if or eq ft 1 eq tt 1
6842put d2site 0 92
6843fail 9
6844end
6845if or eq ft 13 eq tt 13
6846note d2site 93|xfconv: type mismatch; condition if or eq ft 13 eq tt 13
6847put d2site 0 93
6848fail 7
6849end
6850if eq ft tt
6851ret a
6852end
6853d = alloc
6854if ge ft 10
6855f2v ft a 0
6856if ge tt 10
6857xfsse ft 90 192
6858fv2x tt 0 d
6859else
6860xftoint ft tt d
6861end
6862else
6863xfint ft tt a d
6864end
6865ret d
6866end
6867
6868note xfbinop: binop's float arm on x86: both operands in x registers, a compare or one SSE operation.
6869fn xfbinop op ulong dst ulong ix ulong ty ulong to void
6870ra = matreg a_g 77 ix a_g 77 add ix 1 ty
6871rb = matreg a_g 77 add ix 3 a_g 77 add ix 4 ty
6872if ge op 43
6873xfcmp op ty ra rb
6874ret
6875end
6876if or or lt op 33 gt op 36 ge op 41
6877note d2site 94|xfbinop: type mismatch; condition if or or lt op 33 gt op 36 ge op 41
6878put d2site 0 94
6879fail 7
6880end
6881rd = destreg dst
6882xfbin op ty ra rb rd
6883put rk 0 1
6884put rv 0 rd
6885put rt 0 ty
6886end
6887
6888note xfun1 / xfmm: fintr's and fminmax's x86 arms; the operand is in rk/rv (fminmax: the first in ak/av).
6889fn xfun1 c ulong t ulong dst ulong to void
6890ra = matreg get rk 0 get rv 0 t
6891rd = destreg dst
6892if eq c 91
6893nanend = xfnans t ra ra 0 rd
6894f2v t ra 0
6895xfsse t 81 192
6896fv2x t 0 rd
6897xfdefnan t rd
6898xpatch nanend get oc 0
6899else
6900xload 0 ra
6901ximm 1 xfmask t 1
6902xrr 33 0 1
6903xstore 0 rd
6904end
6905put rk 0 1
6906put rv 0 rd
6907put rt 0 t
6908end
6909
6910fn xfmm c ulong at ulong ak ulong av ulong dst ulong to void
6911ra = matreg ak av at
6912rb = matreg get rk 0 get rv 0 at
6913rd = destreg dst
6914xfminmax c at ra rb rd
6915put rk 0 1
6916put rv 0 rd
6917put rt 0 at
6918end
6919
6920note ---- floating point. A float value is its IEEE bit pattern: in an x register (kind 1, 7 a constant),
6921note or in a v register (kind 9, the twin of a pool register; float local names live there). Arithmetic
6922note runs one scalar FP instruction (round to nearest even, no fused op) on v registers: an x operand moves
6923note to v0/v1 first; a result wanted in x moves back from v1/v2, one wanted as kind 9 stays in its twin.
6924note f32 uses the S form (low 32 bits), f64 the D form.
6925fn f2v ty ulong xr ulong vr ulong to void
6926if ne get xtarget 0 0
6927xload 0 xr
6928xfmov ty 110 vr
6929ret
6930end
6931if eq ty 10
6932emit or or 505872384 shl xr 5 vr
6933else
6934emit or or 2657550336 shl xr 5 vr
6935end
6936end
6937
6938fn fv2x ty ulong vr ulong xr ulong to void
6939if ne get xtarget 0 0
6940xfmov ty 126 vr
6941xstore 0 xr
6942ret
6943end
6944if eq ty 10
6945emit or or 505806848 shl vr 5 xr
6946else
6947emit or or 2657484800 shl vr 5 xr
6948end
6949end
6950
6951note vtw: the twin of pool register r, v(16 + its pool index): v16..v31, caller-saved in AAPCS64
6952fn vtw r ulong to ulong
6953ret add 16 regidx r
6954end
6955
6956note fv8d / fv8s: the FMOV (scalar, immediate) imm8 of f64 / f32 bits b, or 256 when there is none. imm8 is
6957note the sign, then bits 54..48 (f64) / 25..19 (f32). Encodable only when the fraction bits below those are
6958note zero and exponent bits 61..54 (f64) / 29..25 (f32) all equal NOT bit 62 / 30 (VFPExpandImm).
6959fn fv8d b ulong to ulong
6960if ne and b 281474976710655 0
6961ret 256
6962end
6963e = and shr b 54 255
6964if and ne e 0 ne e 255
6965ret 256
6966end
6967if eq and shr b 62 1 and e 1
6968ret 256
6969end
6970s = shl shr b 63 7
6971s = or s shl and e 1 6
6972ret or s and shr b 48 63
6973end
6974
6975fn fv8s b ulong to ulong
6976if ne and b 524287 0
6977ret 256
6978end
6979e = and shr b 25 31
6980if and ne e 0 ne e 31
6981ret 256
6982end
6983if eq and shr b 30 1 and e 1
6984ret 256
6985end
6986s = shl and shr b 31 1 7
6987s = or s shl and e 1 6
6988ret or s and shr b 19 63
6989end
6990
6991note fvk: float bits b of type ty into v register vr: 0 FMOV from XZR (C7.2.131); a value with an 8-bit
6992note form FMOV (scalar, immediate, C7.2.132); any other MOVZ/MOVK into X16, then FMOV from X16.
6993fn fvk ty ulong b ulong vr ulong to void
6994if eq b 0
6995f2v ty 31 vr
6996ret
6997end
6998if eq ty 10
6999im = fv8s b
7000if lt im 256
7001emit or or 505417728 shl im 13 vr
7002ret
7003end
7004else
7005im = fv8d b
7006if lt im 256
7007emit or or 509612032 shl im 13 vr
7008ret
7009end
7010end
7011matconst 16 b
7012f2v ty 16 vr
7013end
7014
7015note fvop: the v register holding float operand (kind k, value v, type t): its twin for kind 9, else v
7016note register s, filled from the constant or from the operand's x register.
7017fn fvop k ulong v ulong t ulong s ulong to ulong
7018if eq k 9
7019ret vtw v
7020end
7021if eq k 7
7022fvk t v s
7023ret s
7024end
7025r = matreg k v t
7026f2v t r s
7027ret s
7028end
7029
7030note fvdst: the pool register whose twin takes a kind 9 result for request o (fpw): 1 a new one, its slot
7031note marked as living in v; 2 + r the twin of r (a float local name).
7032fn fvdst o ulong to ulong
7033if eq o 1
7034r = alloc
7035put vsl regidx r uchar 1
7036ret r
7037end
7038ret sub o 2
7039end
7040
7041note fvset: float value (kind k, value v, type t) into the twin of r: FMOV Dd, Dn (C7.2.130), the constant,
7042note or FMOV from its x register. Nothing when it is already there.
7043fn fvset k ulong v ulong t ulong r ulong to void
7044d = vtw r
7045if eq k 9
7046if ne v r
7047if eq t 10
7048emit or or 505430016 shl vtw v 5 d
7049else
7050emit or or 509624320 shl vtw v 5 d
7051end
7052end
7053ret
7054end
7055if eq k 7
7056fvk t v d
7057ret
7058end
7059x = matreg k v t
7060f2v t x d
7061end
7062
7063note fp_binop: one FP add / sub / mul / div of v registers va, vb into vd
7064fn fp_binop op ulong ty ulong va ulong vb ulong vd ulong to void
7065base = ulong 509609984
7066if eq ty 10
7067base = ulong 505415680
7068end
7069if eq op 33
7070if eq ty 10
7071base = ulong 505423872
7072else
7073base = ulong 509618176
7074end
7075else
7076if eq op 34
7077if eq ty 10
7078base = ulong 505427968
7079else
7080base = ulong 509622272
7081end
7082else
7083if eq op 36
7084if eq ty 10
7085base = ulong 505419776
7086else
7087base = ulong 509614080
7088end
7089end
7090end
7091end
7092emit or or or base shl vb 16 shl va 5 vd
7093end
7094
7095fn fp_neg ty ulong va ulong vd ulong to void
7096if eq ty 10
7097emit or or ulong 505495552 shl va 5 vd
7098else
7099emit or or ulong 509689856 shl va 5 vd
7100end
7101end
7102
7103note fp_un1: sqrt (c 91) or abs of v register va into vd
7104fn fp_un1 c ulong ty ulong va ulong vd ulong to void
7105if eq c 91
7106if eq ty 10
7107emit or or ulong 505528320 shl va 5 vd
7108else
7109emit or or ulong 509722624 shl va 5 vd
7110end
7111else
7112if eq ty 10
7113emit or or ulong 505462784 shl va 5 vd
7114else
7115emit or or ulong 509657088 shl va 5 vd
7116end
7117end
7118end
7119
7120note fp_minmax: FMINNM/FMAXNM, the IEEE minNum/maxNum rule: one quiet NaN returns the other operand,
7121note and -0.0 orders below +0.0.
7122fn fp_minmax c ulong ty ulong va ulong vb ulong vd ulong to void
7123base = ulong 509638656
7124if eq c 94
7125base = ulong 509634560
7126end
7127if eq ty 10
7128base = ulong 505444352
7129if eq c 94
7130base = ulong 505440256
7131end
7132end
7133emit or or or base shl vb 16 shl va 5 vd
7134end
7135
7136note fintr: sqrt or abs of one float value; fminmax: min or max of two values of one float type.
7137note Both refuse a bare integer operand and an unresolved literal, as everywhere else. A request o (fpo)
7138note makes the result in a twin (kind 9); otherwise it moves to x register destreg dst (kind 1).
7139fn fintr c ulong dst ulong to void
7140o = get fpo 0
7141put fpo 0 0
7142if ne get irmode 0 0
7143note d2site 95|fintr: word or declaration in a place that does not allow it; condition if ne get irmode 0 0
7144put d2site 0 95
7145fail 9
7146end
7147put fpw 0 1
7148rdval 0 0 255 0
7149if eq get rk 0 2
7150note d2site 96|fintr: type mismatch; condition if eq get rk 0 2
7151put d2site 0 96
7152fail 7
7153end
7154if eq get rk 0 6
7155note d2site 97|fintr: bare number without a type from its context; condition if eq get rk 0 6
7156put d2site 0 97
7157fail 11
7158end
7159t = get rt 0
7160if eq isfloat t 0
7161note d2site 98|fintr: type mismatch; condition if eq isfloat t 0
7162put d2site 0 98
7163fail 7
7164end
7165if ne get xtarget 0 0
7166xfun1 c t dst
7167vdec
7168ret
7169end
7170va = fvop get rk 0 get rv 0 t 0
7171if eq o 0
7172rd = destreg dst
7173fp_un1 c t va 1
7174fv2x t 1 rd
7175put rk 0 1
7176put rv 0 rd
7177else
7178r = fvdst o
7179fp_un1 c t va vtw r
7180put rk 0 9
7181put rv 0 r
7182end
7183put rt 0 t
7184vdec
7185end
7186
7187fn fminmax c ulong dst ulong to void
7188o = get fpo 0
7189put fpo 0 0
7190if ne get irmode 0 0
7191note d2site 99|fminmax: word or declaration in a place that does not allow it; condition if ne get irmode 0 0
7192put d2site 0 99
7193fail 9
7194end
7195put fpw 0 1
7196rdval 0 0 255 0
7197if or eq get rk 0 2 eq get rk 0 6
7198note d2site 100|fminmax: bare number without a type from its context; condition if or eq get rk 0 2 eq get rk 0 6
7199put d2site 0 100
7200fail 11
7201end
7202at = get rt 0
7203ak = get rk 0
7204av = get rv 0
7205put fpw 0 1
7206rdval 0 0 255 0
7207if or eq get rk 0 2 eq get rk 0 6
7208note d2site 101|fminmax: bare number without a type from its context; condition if or eq get rk 0 2 eq get rk 0 6
7209put d2site 0 101
7210fail 11
7211end
7212if or eq isfloat at 0 eq isfloat get rt 0 0
7213note d2site 102|fminmax: type mismatch; condition if or eq isfloat at 0 eq isfloat get rt 0 0
7214put d2site 0 102
7215fail 7
7216end
7217if ne at get rt 0
7218note d2site 103|fminmax: type mismatch; condition if ne at get rt 0
7219put d2site 0 103
7220fail 7
7221end
7222if ne get xtarget 0 0
7223xfmm c at ak av dst
7224vdec
7225ret
7226end
7227va = fvop ak av at 0
7228vb = fvop get rk 0 get rv 0 at 1
7229if eq o 0
7230rd = destreg dst
7231fp_minmax c at va vb 2
7232fv2x at 2 rd
7233put rk 0 1
7234put rv 0 rd
7235else
7236r = fvdst o
7237fp_minmax c at va vb vtw r
7238put rk 0 9
7239put rv 0 r
7240end
7241put rt 0 at
7242vdec
7243end
7244
7245note FMADD (scalar), ARM C7: one rounded multiply-add, not FMUL followed by FADD.
7246note The addend is Ra, bits 14..10; multiplicands Rn, Rm are bits 9..5, 20..16.
7247fn ffma dst ulong to void
7248o = get fpo 0
7249put fpo 0 0
7250put fpw 0 1
7251rdval 0 0 255 0
7252if eq get rk 0 6
7253note d2site 104|ffma: bare number without a type from its context; condition if eq get rk 0 6
7254put d2site 0 104
7255fail 11
7256end
7257at = get rt 0
7258if eq isfloat at 0
7259note d2site 105|ffma: type mismatch; condition if eq isfloat at 0
7260put d2site 0 105
7261fail 7
7262end
7263ak = get rk 0
7264av = get rv 0
7265put fpw 0 1
7266rdval 0 0 255 0
7267if eq get rk 0 6
7268note d2site 106|ffma: bare number without a type from its context; condition if eq get rk 0 6
7269put d2site 0 106
7270fail 11
7271end
7272if ne get rt 0 at
7273note d2site 107|ffma: type mismatch; condition if ne get rt 0 at
7274put d2site 0 107
7275fail 7
7276end
7277bk = get rk 0
7278bv = get rv 0
7279put fpw 0 1
7280rdval 0 0 255 0
7281if eq get rk 0 6
7282note d2site 108|ffma: bare number without a type from its context; condition if eq get rk 0 6
7283put d2site 0 108
7284fail 11
7285end
7286if ne get rt 0 at
7287note d2site 109|ffma: type mismatch; condition if ne get rt 0 at
7288put d2site 0 109
7289fail 7
7290end
7291note x86's baseline is SSE2, not FMA3. No unfused fallback is permitted. The operands are typed
7292note first, so an ill-typed fma gets the same error 7 or 11 on every target; only a well-typed one
7293note is refused here.
7294if or ne get irmode 0 0 ne get xtarget 0 0
7295note d2site 110|ffma: word or declaration in a place that does not allow it; condition if or ne get irmode 0 0 ne get xtarget 0 0
7296put d2site 0 110
7297fail 9
7298end
7299va = fvop ak av at 0
7300vb = fvop bk bv at 1
7301vc = fvop get rk 0 get rv 0 at 2
7302r = ulong 0
7303vd = ulong 3
7304if eq o 0
7305r = destreg dst
7306else
7307r = fvdst o
7308vd = vtw r
7309end
7310b = ulong 520093696
7311if eq at 11
7312b = 524288000
7313end
7314b = or b shl vb 16
7315b = or b shl vc 10
7316b = or b shl va 5
7317emit or b vd
7318if eq o 0
7319fv2x at vd r
7320put rk 0 1
7321else
7322put rk 0 9
7323end
7324put rv 0 r
7325put rt 0 at
7326vdec
7327end
7328
7329note fcond: the condition for a float compare op: EQ, NE, MI (lt), LS (le), GT, GE. MI/LS/GT/GE are
7330note false for NaN, so unordered comparisons come out as the IEEE rules require.
7331fn fcond op ulong to ulong
7332i = sub op 43
7333if eq i 0
7334ret 0
7335end
7336if eq i 1
7337ret 1
7338end
7339if eq i 2
7340ret 4
7341end
7342if eq i 3
7343ret 9
7344end
7345if eq i 4
7346ret 12
7347end
7348ret 10
7349end
7350
7351note fp_cmp: FCMP Sn, Sm / Dn, Dm (scalar) of v registers va, vb: 0x1E202000 / 0x1E602000 with Rm and Rn
7352note zero, so both fields come from va and vb alone (#861: the S word had Rm bit 0 set, and an even vb
7353note read the next twin).
7354fn fp_cmp op ulong ty ulong va ulong vb ulong to void
7355if eq ty 10
7356emit or or 505421824 shl vb 16 shl va 5
7357else
7358emit or or 509616128 shl vb 16 shl va 5
7359end
7360put rk 0 4
7361put rv 0 fcond op
7362put rt 0 1
7363end
7364
7365note fp_conv: one scalar conversion (int<->float, f32<->f64) into a new x register. Same type is a copy.
7366note Returns the register. A float result is made in v(rd), or in v0 when rd is x17 (v17 is a twin).
7367fn fp_conv ft ulong tt ulong ra ulong to ulong
7368if ne get xtarget 0 0
7369ret xfconv ft tt ra
7370end
7371if eq ft tt
7372ret ra
7373end
7374if eq ft 1
7375note d2site 111|fp_conv: word or declaration in a place that does not allow it; condition if eq ft 1
7376put d2site 0 111
7377fail 9
7378end
7379if eq tt 1
7380note d2site 112|fp_conv: word or declaration in a place that does not allow it; condition if eq tt 1
7381put d2site 0 112
7382fail 9
7383end
7384rd = alloc
7385if eq isfloat tt 0
7386f2v ft ra 0
7387fp_toint ft tt rd
7388ret rd
7389end
7390vs = rd
7391if ge rd 16
7392vs = ulong 0
7393end
7394fp_tov ft tt ra vs
7395fv2x tt vs rd
7396ret rd
7397end
7398
7399note fp_tov: x register ra of type ft (an integer, or the other float type, moved to v0 first) converted
7400note to float type tt in v register vd: SCVTF/UCVTF (C7.2.236/C7.2.355) by signedness, FCVT (C7.2.69).
7401fn fp_tov ft ulong tt ulong ra ulong vd ulong to void
7402if ne isfloat ft 0
7403f2v ft ra 0
7404if eq ft 10
7405emit or 505593856 vd
7406else
7407emit or 509755392 vd
7408end
7409ret
7410end
7411sgn = false
7412if ge ft 6
7413sgn = true
7414end
7415if eq tt 10
7416if eq twid ft 32
7417if sgn
7418emit or or 505544704 shl ra 5 vd
7419else
7420emit or or 505610240 shl ra 5 vd
7421end
7422else
7423if sgn
7424emit or or 2653028352 shl ra 5 vd
7425else
7426emit or or 2653093888 shl ra 5 vd
7427end
7428end
7429else
7430if eq twid ft 32
7431if sgn
7432emit or or 509739008 shl ra 5 vd
7433else
7434emit or or 509804544 shl ra 5 vd
7435end
7436else
7437if sgn
7438emit or or 2657222656 shl ra 5 vd
7439else
7440emit or or 2657288192 shl ra 5 vd
7441end
7442end
7443end
7444end
7445
7446
7447note fp_toint: float (v0) to integer rd: truncate toward zero, saturate to the destination's own range, NaN
7448note to 0 (OMEGESE 9.9; spec/one-layer-format.md 10.3). 32/64-bit: FCVTZS/FCVTZU (C7.2.90/C7.2.94) by
7449note signedness, int sign-extended (SXTW). 8/16-bit: the scalar SIMD FCVTZ[SU] in v0, then saturating
7450note narrows (SQXTN/UQXTN, C7.2.311/C7.2.374) to the width, FMOV W (C7.2.130), then SXTB/SXTH for signed.
7451fn fp_toint ft ulong tt ulong rd ulong to void
7452if ne get xtarget 0 0
7453xftoint ft tt rd
7454ret
7455end
7456w = twid tt
7457sg = ge tt 6
7458if eq w 64
7459if sg
7460if eq ft 10
7461emit or 2654470144 rd
7462else
7463emit or 2658664448 rd
7464end
7465else
7466if eq ft 10
7467emit or 2654535680 rd
7468else
7469emit or 2658729984 rd
7470end
7471end
7472ret
7473end
7474if eq w 32
7475if sg
7476if eq ft 10
7477emit or 506986496 rd
7478else
7479emit or 511180800 rd
7480end
7481emit or or 2470476800 rd shl rd 5
7482else
7483if eq ft 10
7484emit or 507052032 rd
7485else
7486emit or 511246336 rd
7487end
7488end
7489ret
7490end
7491fp_narrow ft sg w
7492emit or 505806848 rd
7493if sg
7494if eq w 8
7495emit or or 2470452224 rd shl rd 5
7496else
7497emit or or 2470460416 rd shl rd 5
7498end
7499end
7500end
7501
7502note fp_narrow: convert v0 in place to a saturated integer of width w (8 or 16) in its low bits.
7503fn fp_narrow ft ulong sg bool w ulong to void
7504if eq ft 10
7505if sg
7506emit 1587656704
7507emit 1583433728
7508else
7509emit 2124527616
7510emit 2120304640
7511end
7512else
7513if sg
7514emit 1591851008
7515emit 1587628032
7516emit 1583433728
7517else
7518emit 2128721920
7519emit 2124498944
7520emit 2120304640
7521end
7522end
7523if eq w 8
7524if sg
7525emit 1579239424
7526else
7527emit 2116110336
7528end
7529end
7530end
7531
7532note ---- rotate (OM-2, spec 3): rotr 59 / rotl 60 of an unsigned uchar..ulong by the same type. uint and
7533note ulong with a number below the width: ROR (immediate) = EXTR Rd, Rn, Rn, #s (C6.2.347, C6.2.160);
7534note otherwise the shift amount check (trap 7) then RORV (C6.2.349); rotl by n is ror by w - n (a number)
7535note or by NEG n (C6.2.295) since RORV takes the amount modulo the width. uchar/ushort first replicate the
7536note value through W16 with ORR (shifted register, LSL, C6.2.302), rotate the 32-bit pattern, then canon.
7537fn rotrep ty ulong ra ulong to void
7538if eq ty 3
7539emit or or 704659472 shl ra 16 shl ra 5
7540ret
7541end
7542emit or or 704651280 shl ra 16 shl ra 5
7543emit 705708560
7544end
7545
7546fn rotimm ty ulong ra ulong s ulong rd ulong to void
7547if ne get xtarget 0 0
7548xrot ty ra s 1 rd
7549ret
7550end
7551if eq ty 5
7552emit or or or 2478833664 shl ra 16 shl s 10 or shl ra 5 rd
7553ret
7554end
7555if eq ty 4
7556emit or or or 327155712 shl ra 16 shl s 10 or shl ra 5 rd
7557ret
7558end
7559rotrep ty ra
7560emit or or 328204800 shl s 10 rd
7561canon rd ty
7562end
7563
7564fn rotreg ty ulong ra ulong rr ulong rd ulong to void
7565if ne get xtarget 0 0
7566xrot ty ra rr 0 rd
7567ret
7568end
7569if eq ty 5
7570emit or or 2596285440 shl rr 16 or shl ra 5 rd
7571ret
7572end
7573if eq ty 4
7574emit or or 448801792 shl rr 16 or shl ra 5 rd
7575ret
7576end
7577rotrep ty ra
7578emit or or 448802304 shl rr 16 rd
7579canon rd ty
7580end
7581
7582fn binrot op ulong dst ulong ix ulong to void
7583ty = get a_ar add get a_rb 77 add ix 2
7584if or lt ty 2 gt ty 5
7585note d2site 113|binrot: type mismatch; condition if or lt ty 2 gt ty 5
7586put d2site 0 113
7587fail 7
7588end
7589ra = matreg a_g 77 ix a_g 77 add ix 1 ty
7590bk = get a_ar add get a_rb 77 add ix 3
7591bn = get a_ar add get a_rb 77 add ix 4
7592w = twid ty
7593rb = ulong 0
7594useimm = false
7595if and eq bk 3 lt bn w
7596useimm = true
7597rb = bn
7598else
7599rb = matreg bk bn a_g 77 add ix 5
7600bo_schk ty rb
7601end
7602rd = destreg dst
7603if useimm
7604s = rb
7605if and eq op 60 ne s 0
7606s = sub w s
7607end
7608rotimm ty ra s rd
7609else
7610rr = rb
7611if eq op 60
7612rr = alloc
7613if ne get xtarget 0 0
7614xload 0 rb
7615xb 72 247 216
7616xstore 0 rr
7617else
7618emit or or 3405775840 shl rb 16 rr
7619end
7620end
7621rotreg ty ra rr rd
7622end
7623put rk 0 1
7624put rv 0 rd
7625put rt 0 ty
7626end
7627
7628note binop: op 33..48, destination (255 none), ix the fr slot of a (kind, number/register, type) then b.
7629note Result in rk/rv/rt. om4 BINOP. A float op reads its operands as v registers; with a request (fpo)
7630note the result stays in a twin (kind 9), else it moves to x (kind 1).
7631fn binop op ulong dst ulong ix ulong to void
7632if ne get fzone 0 0
7633if and eq a_g 77 ix 3 eq a_g 77 add ix 3 3
7634foldbin op a_g 77 add ix 2 a_g 77 add ix 1 a_g 77 add ix 4
7635if ne get fok 0 0
7636put rk 0 3
7637put rv 0 get fval 0
7638put rt 0 get fty 0
7639ret
7640end
7641end
7642end
7643if or eq op 59 eq op 60
7644binrot op dst ix
7645ret
7646end
7647ty = get a_ar add get a_rb 77 add ix 2
7648if ne isfloat ty 0
7649if ne get xtarget 0 0
7650xfbinop op dst ix ty
7651ret
7652end
7653o = get fpo 0
7654put fpo 0 0
7655va = fvop a_g 77 ix a_g 77 add ix 1 ty 0
7656vb = fvop a_g 77 add ix 3 a_g 77 add ix 4 ty 1
7657if ge op 43
7658fp_cmp op ty va vb
7659ret
7660end
7661if or or lt op 33 gt op 36 ge op 41
7662note d2site 114|binop: type mismatch; condition if or or lt op 33 gt op 36 ge op 41
7663put d2site 0 114
7664fail 7
7665end
7666if eq o 0
7667rd = destreg dst
7668fp_binop op ty va vb 2
7669fv2x ty 2 rd
7670put rk 0 1
7671put rv 0 rd
7672else
7673r = fvdst o
7674fp_binop op ty va vb vtw r
7675put rk 0 9
7676put rv 0 r
7677end
7678put rt 0 ty
7679ret
7680end
7681ra = matreg a_g 77 ix a_g 77 add ix 1 ty
7682if eq ty 13
7683if and ge op 38 le op 42
7684note d2site 115|binop: type mismatch; condition if and ge op 38 le op 42
7685put d2site 0 115
7686fail 7
7687end
7688end
7689imm = ulong 0
7690bk = get a_ar add get a_rb 77 add ix 3
7691bn = get a_ar add get a_rb 77 add ix 4
7692rb = ulong 0
7693useimm = false
7694if eq bk 3
7695if or eq op 41 eq op 42
7696if lt bn twid ty
7697useimm = true
7698end
7699else
7700if or lt op 35 ge op 43
7701if le bn 4095
7702useimm = true
7703end
7704end
7705end
7706end
7707if useimm
7708rb = bn
7709imm = ulong 1
7710else
7711rb = matreg bk bn a_g 77 add ix 5
7712end
7713if ge op 43
7714bo_cmp op ty ra rb imm
7715ret
7716end
7717if eq ty 1
7718if gt sub op 38 2
7719note d2site 116|binop: type mismatch; condition if gt sub op 38 2
7720put d2site 0 116
7721fail 7
7722end
7723end
7724rd = destreg dst
7725if lt op 35
7726bo_add op ty ra rb imm rd
7727else
7728if eq op 35
7729bo_mul ty ra rb rd
7730else
7731if lt op 38
7732fl = ulong 0
7733if and eq bk 3 ne bn 0
7734fl = or fl 1
7735end
7736if and eq bk 3 ne bn 18446744073709551615
7737fl = or fl 2
7738end
7739bo_div op ty ra rb rd fl
7740else
7741if lt op 41
7742bo_log op ra rb rd
7743else
7744if eq op 41
7745bo_shl ty ra rb imm rd
7746else
7747bo_shr ty ra rb imm rd
7748end
7749end
7750end
7751end
7752end
7753put rk 0 1
7754put rv 0 rd
7755put rt 0 ty
7756end
7757
7758note ======== calls: registers saved around a call and loaded back ========
7759global svn ulong 1
7760global sva ulong 1
7761note save: n = registers in use (parameters + pool slots), A = 8 (n + 1) rounded up to 16: SUB SP, SP, #A
7762note (C6.2.457); the stack check; STR Xr, [SP, #8j] for each (C6.2.415), or STR Dj+16 (SIMD&FP, C7.2.331)
7763note for a slot living in its twin (vsl); STR X30, [SP, #8n]. Out: svn n, sva A. om4 SAVE.
7764fn save to void
7765if ne get xtarget 0 0
7766put svn 0 add get npar 0 get nslot 0
7767put sva 0 256
7768xsp 1 256
7769j = ulong 0
7770while lt j 18
7771xload 0 j
7772xmem 137 0 4 mul j 8
7773j = add j 1
7774end
7775note Reserve the callee's return address, frame pointer and slot area before CALL.
7776xcheck 272
7777ret
7778end
7779n = add get npar 0 get nslot 0
7780a = shl shr add n 2 1 4
7781put svn 0 n
7782put sva 0 a
7783spsub a
7784stkchk
7785j = ulong 0
7786while lt j n
7787if ne get vsl j 0
7788emit or or 4244636640 add j 16 shl j 10
7789else
7790emit or or 4177527776 poolc j shl j 10
7791end
7792j = add j 1
7793end
7794emit or 4177527806 shl n 10
7795end
7796
7797note loadarg: register t from an argument: kind 1, 5 or 9 a register v, read back from its save slot (LDR
7798note Xt, [SP, #8 slot], C6.2.216; a kind 9 slot holds the twin's D bits, the same bit pattern); kind 3, 6
7799note or 7 the number, address or float bits v. om4 LOADARG.
7800fn loadarg t ulong k ulong v ulong to void
7801if ne get xtarget 0 0
7802xarg t k v
7803ret
7804end
7805if eq k 6
7806mataddr t v
7807ret
7808end
7809if or eq k 3 eq k 7
7810matconst t v
7811ret
7812end
7813emit or or 4181722080 t shl regidx v 10
7814end
7815
7816note basearg: register t = the base of array name e (index + 1): its register from the save area, or its
7817note address. om4 BASEARG.
7818fn basearg t ulong e ulong to void
7819i = sub e 1
7820if eq uchar get a_ar add get a_rb 7 i 10
7821mataddr t get a_ar add get a_rb 8 i
7822emit or or 4181721088 shl t 5 t
7823ret
7824end
7825if ge uchar get a_ar add get a_rb 7 i 4
7826mataddr t get a_ar add get a_rb 8 i
7827ret
7828end
7829loadarg t 1 ulong uchar get a_ar add get a_rb 4 i
7830end
7831
7832note restore: d destination (255: a new temporary at pool slot `slot`), slot the pool slot before the
7833note arguments, n saved count, a save bytes, res 1 if there is a result in X0. MOV Xd, X0 (C6.2.282); LDR
7834note each register in use before the arguments except Xd (C6.2.216), or LDR Dj+16 (C7.2.191) instead for a
7835note slot living in its twin; LDR X30; ADD SP, SP, #A (C6.2.5). Returns Xd (255 when no result). om4
7836note RESTORE.
7837fn restore d ulong slot ulong n ulong a ulong res ulong to ulong
7838if ne get xtarget 0 0
7839ret xrestore d slot res
7840end
7841put nslot 0 slot
7842rd = ulong 255
7843if ne res 0
7844rd = d
7845if eq d 255
7846rd = alloc
7847end
7848if ne rd 0
7849emit or 2852127712 rd
7850end
7851end
7852m = add get npar 0 slot
7853j = ulong 0
7854while lt j m
7855r = poolc j
7856if ne get vsl j 0
7857emit or or 4248830944 add j 16 shl j 10
7858else
7859if ne r rd
7860emit or or 4181722080 r shl j 10
7861end
7862end
7863j = add j 1
7864end
7865emit or 4181722110 shl n 10
7866spadd a
7867ret rd
7868end
7869
7870note ca_bl: BL to function f (index + 1), C6.2.43. The call records grow with the arena (group 9).
7871fn ca_bl f ulong to void
7872n = get ncalls 0
7873if ge n get a_gp 9
7874a_need 9 n
7875end
7876put a_ar add get a_rb 41 n get oc 0
7877put a_ar add get a_rb 42 n get curfn 0
7878put a_ar add get a_rb 43 n f
7879if ne get objmode 0 0
7880a_need 22 n
7881note At the BL, SP is stkbytes + osp below the frame base; osp holds this call's save area too.
7882t = get osp 0
7883if lt t get sva 0
7884t = get sva 0
7885end
7886a_p 87 n add get stkbytes 0 t
7887end
7888put ncalls 0 add n 1
7889
7890if ne get xtarget 0 0
7891emitb 232
7892xword 0
7893else
7894if and ne get objmode 0 0 eq a_gu 32 sub f 1 2
7895emit 2483027968
7896else
7897emit or 2483027968 bdisp get oc 0 get a_ar add get a_rb 22 sub f 1 26
7898end
7899end
7900end
7901
7902note ======== element addresses and array arguments ========
7903global ea_b ulong 1
7904global ea_i ulong 1
7905global ea_k ulong 1
7906note xea_g: on x86 targets, the address of the global whose element access is pending (ea_b 254, xbase)
7907global xea_g ulong 1
7908
7909note eaem: the load or store word base (LDOP / STOP register-offset form) of register rt at ea_b / ea_i.
7910note ea_i 255 (OM-2, a number index k = ea_k up to 4095): the unsigned-offset form instead, same size, V
7911note (bit 26, the SIMD&FP forms) and opc bits, imm12 = k scaled by the element size (LDR/STR (immediate),
7912note C6.2.216 and its family; C7.2.191/C7.2.331).
7913fn eaem wd ulong rg ulong to void
7914b = get ea_b 0
7915if eq get ea_i 0 255
7916emit or or or or and wd 3300917248 956301312 shl get ea_k 0 10 shl b 5 rg
7917ret
7918end
7919emit or or or wd rg shl b 5 shl get ea_i 0 16
7920end
7921note elemaddr: array name e (index + 1), index value (kind, number or register, type). A number index must
7922note be inside the array (error 21) and needs no check; a register index: CMP Xi, #len (C6.2.96) or CMP Xi,
7923note Xt (C6.2.97), B.HS trap 3 (unsigned, so a negative signed index traps too). Out: ea_b base register
7924note (the array's register, or a new one holding its address), ea_i index register. om4 ELEMADDR.
7925note OM-2 unsized array (unsz): every index, a number too, is checked against its count register nm_lr
7926note (CMP Xi, Xn; B.HS trap 3); none is eliminated (spec 4, 6).
7927note OM-2 global with a pinned register (pinset): the base is that register and a long length is compared
7928note with its pinned register (CMP Xi, Xp), so neither is rebuilt with MOVZ/MOVK at each access.
7929fn elemaddr e ulong k ulong v ulong t ulong to void
7930if ne get xtarget 0 0
7931xelem e k v t
7932ret
7933end
7934if or or eq t 1 eq t 10 eq t 11
7935note d2site 117|elemaddr: type mismatch; condition if or or eq t 1 eq t 10 eq t 11
7936put d2site 0 117
7937fail 7
7938end
7939i = sub e 1
7940ln = get a_ar add get a_rb 6 i
7941if eq ln 0
7942if eq uchar get a_ar add get a_rb 7 i 10
7943ea_pool i k v t
7944ret
7945end
7946end
7947x = v
7948if ne unsz i 0
7949x = matreg k v t
7950emit or or 3942645791 shl ulong a_gu 14 i 16 shl x 5
7951trapc 2 3
7952else
7953if eq k 3
7954if ge v ln
7955note d2site 118|elemaddr: constant index outside the array; condition if ge v ln
7956put d2site 0 118
7957fail 21
7958end
7959if and ne get om2 0 0 le v 4095
7960x = ulong 255
7961put ea_k 0 v
7962else
7963x = alloc
7964matconst x v
7965end
7966else
7967if le ln 4095
7968emit or or 4043309087 shl ln 10 shl v 5
7969else
7970if ne uchar get a_ar add get a_rb 11 i 0
7971emit or or 3942645791 shl ulong a_gu 11 i 16 shl v 5
7972else
7973y = alloc
7974matconst y ln
7975emit or or 3942645791 shl y 16 shl v 5
7976end
7977end
7978trapc 2 3
7979end
7980end
7981put ea_i 0 x
7982if ge uchar get a_ar add get a_rb 7 i 4
7983if ne uchar get a_ar add get a_rb 10 i 0
7984put ea_b 0 ulong a_gu 10 i
7985else
7986b = alloc
7987mataddr b get a_ar add get a_rb 8 i
7988put ea_b 0 b
7989end
7990else
7991put ea_b 0 ulong a_gu 4 i
7992end
7993end
7994
7995note ea_pool: the element address of run-time pool i (docs/RUNTIME-POOLS.md s4) for index (k, v, t): the index
7996note in a register, the slot's base and length in two more (LDP, C6.2.163), CMP index, length (C6.2.97), B.HS
7997note trap 3. The slot is loaded here, after every operand of the access has been read (the soundness rule
7998note B1: an enlarge inside an operand may move the pool). A number index is checked at run time like any
7999note other: no error 21 and no check elimination, since the length is known only at run time.
8000fn ea_pool i ulong k ulong v ulong t ulong to void
8001x = matreg k v t
8002b = alloc
8003l = alloc
8004mataddr b get a_ar add get a_rb 8 i
8005emit or or or 2839543808 shl l 10 shl b 5 b
8006emit or or 3942645791 shl l 16 shl x 5
8007note POOLMUT-ALT cmpdrop note removed
8008note POOLMUT cmpdrop
8009trapc 2 3
8010put ea_i 0 x
8011put ea_b 0 b
8012end
8013
8014note aa_word: the next word of an array argument must be a name of at most 63 bytes
8015fn aa_word to void
8016tok
8017k = get tk 0
8018if eq k 0
8019note d2site 119|aa_word: the line ends where a word or value is needed; condition if eq k 0
8020put d2site 0 119
8021fail 4
8022end
8023if ne k 1
8024note d2site 120|aa_word: syntax: unknown or misplaced word; condition if ne k 1
8025put d2site 0 120
8026fail 16
8027end
8028if gt get tl 0 63
8029note d2site 121|aa_word: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
8030put d2site 0 121
8031fail 13
8032end
8033end
8034
8035note arrarg: an array argument for parameter pi of function f (index + 1): [view | edit] NAME. Its type and
8036note length must equal the parameter's; an edit parameter needs a writable array (local or edit, error 20;
8037note a view passed to it is error 20, OMEGESE.md 9.4); a global is never passed (error 19). Out: rk 5
8038note (register rv) or 6 (address rv, a text), rt the name entry. om4 ARRARG.
8039note OM-2: an unsized parameter (length 0) takes an array of any length (erratum E2), whose count goes to
8040note ul_k / ul_v at depth * 6 + pi: its count register, or its length as a number. `part` is read by arrpart.
8041fn arrarg f ulong pi ulong to void
8042md = ulong 0
8043aa_word
8044w = get tw 0
8045c = kw w
8046if ne c 0
8047if eq c 193
8048arrpart f pi 0
8049ret
8050end
8051if or lt c 57 gt c 58
8052note d2site 122|arrarg: syntax: unknown or misplaced word; condition if or lt c 57 gt c 58
8053put d2site 0 122
8054fail 16
8055end
8056md = c
8057aa_word
8058w = get tw 0
8059if eq kw w 193
8060arrpart f pi md
8061ret
8062end
8063end
8064e = findname w
8065if eq e 0
8066note d2site 123|arrarg: unknown name or field, or a word this mode does not provide; condition if eq e 0
8067put d2site 0 123
8068fail 3
8069end
8070i = sub e 1
8071k = ulong uchar get a_ar add get a_rb 7 i
8072if eq k 0
8073note d2site 124|arrarg: type mismatch; condition if eq k 0
8074put d2site 0 124
8075fail 7
8076end
8077if eq k 10
8078note d2site 125|arrarg: global passed as an argument, or one array twice in a call; condition if eq k 10
8079put d2site 0 125
8080fail 19
8081end
8082if ge k 6
8083note d2site 126|arrarg: type mismatch; condition if ge k 6
8084put d2site 0 126
8085fail 7
8086end
8087if eq k 4
8088note d2site 127|arrarg: global passed as an argument, or one array twice in a call; condition if eq k 4
8089put d2site 0 127
8090fail 19
8091end
8092p = add mul sub f 1 6 pi
8093if eq a_gu 37 p 3
8094if eq md 57
8095note d2site 128|arrarg: write to a view or a text; condition if eq md 57
8096put d2site 0 128
8097fail 20
8098end
8099if and ne k 1 ne k 3
8100note d2site 129|arrarg: write to a view or a text; condition if and ne k 1 ne k 3
8101put d2site 0 129
8102fail 20
8103end
8104else
8105if eq md 58
8106note d2site 130|arrarg: type mismatch; condition if eq md 58
8107put d2site 0 130
8108fail 7
8109end
8110end
8111if ne a_gu 5 i a_gu 35 p
8112note d2site 131|arrarg: type mismatch; condition if ne a_gu 5 i a_gu 35 p
8113put d2site 0 131
8114fail 7
8115end
8116ux = add mul get depth 0 6 pi
8117if eq a_g 36 p 0
8118if ne unsz i 0
8119a_p 79 ux 1
8120a_p 80 ux ulong a_gu 14 i
8121else
8122a_p 79 ux 3
8123a_p 80 ux a_g 6 i
8124end
8125else
8126if ne a_g 6 i a_g 36 p
8127note d2site 132|arrarg: type mismatch; condition if ne a_g 6 i a_g 36 p
8128put d2site 0 132
8129fail 7
8130end
8131end
8132put rt 0 e
8133if eq k 5
8134put rk 0 6
8135put rv 0 a_g 8 i
8136else
8137put rk 0 5
8138put rv 0 ulong a_gu 4 i
8139end
8140end
8141
8142note arrpart (OM-2, spec 6): `part A o k` as argument pi of function f (index + 1); md 57 / 58 when `view` /
8143note `edit` was written before it. A is a name (a global is error 19, a fresh array 27); o, then k, are
8144note ulong values. Checks, in this order: o <= len A (CMP Xo, Xlen; B.HI trap 3), then k <= len A - o (SUB,
8145note CMP, B.HI trap 3); the wrapped o + k is never formed. The part is a view of A + o * size with count k:
8146note an edit when A is writable (local or edit) and no `view` was written, else a view. It goes only to an
8147note unsized parameter (error 7). Out as arrarg; rt is A, so for error 19 the part counts as its base.
8148fn arrpart f ulong pi ulong md ulong to void
8149p = add mul sub f 1 6 pi
8150e = arrname 1
8151i = sub e 1
8152k = ulong uchar get a_ar add get a_rb 7 i
8153if eq k 10
8154note d2site 133|arrpart: global passed as an argument, or one array twice in a call; condition if eq k 10
8155put d2site 0 133
8156fail 19
8157end
8158if ge k 6
8159note d2site 134|arrpart: type mismatch; condition if ge k 6
8160put d2site 0 134
8161fail 7
8162end
8163if eq k 4
8164note d2site 135|arrpart: global passed as an argument, or one array twice in a call; condition if eq k 4
8165put d2site 0 135
8166fail 19
8167end
8168fz_arg e
8169if eq uchar get a_ar add get a_rb 37 p 3
8170if eq md 57
8171note d2site 136|arrpart: write to a view or a text; condition if eq md 57
8172put d2site 0 136
8173fail 20
8174end
8175if and ne k 1 ne k 3
8176note d2site 137|arrpart: write to a view or a text; condition if and ne k 1 ne k 3
8177put d2site 0 137
8178fail 20
8179end
8180else
8181if eq md 58
8182note d2site 138|arrpart: type mismatch; condition if eq md 58
8183put d2site 0 138
8184fail 7
8185end
8186end
8187if ne ulong a_gu 5 i ulong a_gu 35 p
8188note d2site 139|arrpart: type mismatch; condition if ne ulong a_gu 5 i ulong a_gu 35 p
8189put d2site 0 139
8190fail 7
8191end
8192if ne get a_ar add get a_rb 36 p 0
8193note d2site 140|arrpart: type mismatch; condition if ne get a_ar add get a_rb 36 p 0
8194put d2site 0 140
8195fail 7
8196end
8197rdval 0 5 255 0
8198k = get rt 0
8199if and ne k 5 ne k 13
8200note d2site 141|arrpart: type mismatch; condition if and ne k 5 ne k 13
8201put d2site 0 141
8202fail 7
8203end
8204ro = matreg get rk 0 get rv 0 k
8205rdval 0 5 255 0
8206k = get rt 0
8207if and ne k 5 ne k 13
8208note d2site 142|arrpart: type mismatch; condition if and ne k 5 ne k 13
8209put d2site 0 142
8210fail 7
8211end
8212rn = matreg get rk 0 get rv 0 k
8213d = partck i ro rn
8214ux = add mul get depth 0 6 pi
8215a_p 79 ux 1
8216a_p 80 ux rn
8217put rt 0 e
8218put rk 0 5
8219put rv 0 d
8220end
8221
8222note partck: the two checks of part (name index i, o in ro, k in rn), then the part's base register
8223fn partck i ulong ro ulong rn ulong to ulong
8224rl = ulong uchar get a_ar add get a_rb 14 i
8225if eq unsz i 0
8226rl = alloc
8227matconst rl get a_ar add get a_rb 6 i
8228end
8229if ne get xtarget 0 0
8230xcmp ro rl 0
8231xtrap 8 3
8232d = alloc
8233xarith 34 5 rl ro 0 d
8234xcmp rn d 0
8235xtrap 8 3
8236b = ulong uchar get a_ar add get a_rb 4 i
8237if eq uchar get a_ar add get a_rb 7 i 5
8238b = alloc
8239mataddr b get a_ar add get a_rb 8 i
8240end
8241xload 0 ro
8242xb 72 193 224
8243emitb uchar tlog ulong uchar get a_ar add get a_rb 5 i
8244xload 1 b
8245xrr 1 0 1
8246xstore 0 d
8247ret d
8248end
8249emit or or 3942645791 shl rl 16 shl ro 5
8250trapc 8 3
8251d = alloc
8252e3 3405774848 d rl ro
8253emit or or 3942645791 shl d 16 shl rn 5
8254trapc 8 3
8255b = ulong uchar get a_ar add get a_rb 4 i
8256if eq uchar get a_ar add get a_rb 7 i 5
8257b = alloc
8258mataddr b get a_ar add get a_rb 8 i
8259end
8260emit or or or or 2332033024 shl ro 16 shl tlog ulong a_gu 5 i 10 shl b 5 d
8261ret d
8262end
8263
8264note ======== the parts of the value reader that read no further value ========
8265fn vdec to void
8266if and ne get cpure 0 0 ge get rt 0 10
8267note d2site 143|vdec: contract syntax misplaced or not supported here (IR mode included); condition if and ne get cpure 0 0 ge get rt 0 10
8268put d2site 0 143
8269fail 30
8270end
8271put depth 0 sub get depth 0 1
8272end
8273
8274note vdone: a value's result, and one nesting level less (om4 VT_RET)
8275fn vdone k ulong v ulong t ulong to void
8276put rk 0 k
8277put rv 0 v
8278put rt 0 t
8279vdec
8280end
8281
8282note fwreq: hand this depth's fpw request to the part that makes the value (fpo)
8283fn fwreq to void
8284put fpo 0 get a_ar add get a_rb 78 get depth 0
8285end
8286
8287note vt_un: neg / not of the value in rk/rv/rt (a bare number already refused). neg: NEG Xd, Xm (SUB from
8288note XZR, C6.2.458; the 32-bit form for u32), i64 NEGS + B.VS trap 1 (C6.2.465), then the wrap or the
8289note sign check; not: bool EOR Xd, Xn, #1 (C6.2.155), else MVN (ORN from XZR, C6.2.300), then the wrap.
8290note om4 VU1 .. VU_E. Float neg: FNEG (C7.2.144) of the operand's v register; with a request (fpo) the
8291note result stays in a twin (kind 9).
8292fn vt_un c ulong dst ulong to void
8293o = get fpo 0
8294put fpo 0 0
8295if ne get fzone 0 0
8296if eq get rk 0 3
8297foldun c get rt 0 get rv 0
8298if ne get fok 0 0
8299put rv 0 get fval 0
8300ret
8301end
8302end
8303end
8304if ne get xtarget 0 0
8305xunary c dst
8306ret
8307end
8308ty = get rt 0
8309if or eq ty 10 eq ty 11
8310if eq c 50
8311note d2site 144|vt_un: type mismatch; condition if eq c 50
8312put d2site 0 144
8313fail 7
8314end
8315va = fvop get rk 0 get rv 0 ty 0
8316if eq o 0
8317rd = destreg dst
8318fp_neg ty va 1
8319fv2x ty 1 rd
8320put rk 0 1
8321put rv 0 rd
8322else
8323r = fvdst o
8324fp_neg ty va vtw r
8325put rk 0 9
8326put rv 0 r
8327end
8328put rt 0 ty
8329ret
8330end
8331ra = matreg get rk 0 get rv 0 ty
8332rd = destreg dst
8333if eq c 50
8334if eq ty 13
8335note d2site 145|vt_un: type mismatch; condition if eq ty 13
8336put d2site 0 145
8337fail 7
8338end
8339if eq ty 1
8340e3 3527409664 rd ra 0
8341else
8342if eq ty 4
8343e3 706741216 rd 0 ra
8344else
8345e3 2854224864 rd 0 ra
8346if lt ty 6
8347canon rd ty
8348end
8349end
8350end
8351else
8352if or eq ty 1 eq ty 13
8353note d2site 146|vt_un: type mismatch; condition if or eq ty 1 eq ty 13
8354put d2site 0 146
8355fail 7
8356end
8357if eq ty 9
8358e3 3942646752 rd 0 ra
8359trapc 6 1
8360else
8361if eq ty 4
8362e3 1258292192 rd 0 ra
8363else
8364e3 3405775840 rd 0 ra
8365if lt ty 6
8366canon rd ty
8367else
8368chkext rd ty 1
8369end
8370end
8371end
8372end
8373put rk 0 1
8374put rv 0 rd
8375put rt 0 ty
8376end
8377
8378note vt_conv: the value in rk/rv/rt converted to type tt (neither bool, error 9). Out of range when any bit
8379note at or above s is set: LSR Xt, Xa, #s (UBFM, C6.2.487); CBNZ Xt trap 5 (C6.2.77); signed to a narrower
8380note signed type: the sign-extension check, trap 5. om4 VTT1 .. VC_OK. To a float with a request (fpo): the
8381note conversion is made in a twin (kind 9); the same float type is left as it is.
8382fn vt_conv tt ulong to void
8383if ne get xtarget 0 0
8384xconv tt
8385ret
8386end
8387o = get fpo 0
8388put fpo 0 0
8389ft = get rt 0
8390if or or or eq ft 10 eq ft 11 eq tt 10 eq tt 11
8391if or eq ft 13 eq tt 13
8392note d2site 147|vt_conv: type mismatch; condition if or eq ft 13 eq tt 13
8393put d2site 0 147
8394fail 7
8395end
8396if eq ft 1
8397note d2site 148|vt_conv: word or declaration in a place that does not allow it; condition if eq ft 1
8398put d2site 0 148
8399fail 9
8400end
8401if eq tt 1
8402note d2site 149|vt_conv: word or declaration in a place that does not allow it; condition if eq tt 1
8403put d2site 0 149
8404fail 9
8405end
8406if and ne o 0 ne isfloat tt 0
8407if eq ft tt
8408ret
8409end
8410ra = matreg get rk 0 get rv 0 ft
8411r = fvdst o
8412fp_tov ft tt ra vtw r
8413put rk 0 9
8414put rv 0 r
8415put rt 0 tt
8416ret
8417end
8418ra = matreg get rk 0 get rv 0 ft
8419rd = fp_conv ft tt ra
8420put rk 0 1
8421put rv 0 rd
8422put rt 0 tt
8423ret
8424end
8425ra = matreg get rk 0 get rv 0 ft
8426if eq ft 1
8427note d2site 150|vt_conv: word or declaration in a place that does not allow it; condition if eq ft 1
8428put d2site 0 150
8429fail 9
8430end
8431if eq tt 1
8432note d2site 151|vt_conv: word or declaration in a place that does not allow it; condition if eq tt 1
8433put d2site 0 151
8434fail 9
8435end
8436wf = twid ft
8437wt = twid tt
8438s = ulong 99
8439sgf = and ge ft 6 le ft 9
8440sgt = and ge tt 6 le tt 9
8441if eq sgf 0
8442if ne sgt 0
8443if ge wf wt
8444s = sub wt 1
8445end
8446else
8447if gt wf wt
8448s = wt
8449end
8450end
8451else
8452if eq sgt 0
8453s = wt
8454if gt s 63
8455s = ulong 63
8456end
8457else
8458if gt wf wt
8459chkext ra tt 5
8460end
8461end
8462end
8463if ne s 99
8464t = alloc
8465emit or or or 3544251392 t shl s 16 shl ra 5
8466trapsite or 3036676096 t 5
8467end
8468put rk 0 1
8469put rv 0 ra
8470put rt 0 tt
8471end
8472
8473note vt_get: get A i with the index value in rk/rv/rt: the element address, then the load of the element
8474note type, register offset (LDOP table). om4 VT_GET. A float element with a request (fpo) loads straight
8475note into a twin: the same word with V (bit 26), LDR St/Dt (C7.2.192) (kind 9).
8476fn vt_get e ulong dst ulong to void
8477if ne get xtarget 0 0
8478elemaddr e get rk 0 get rv 0 get rt 0
8479st_ld get ea_b 0 get ea_i 0 ulong a_gu 5 sub e 1 dst
8480ret
8481end
8482o = get fpo 0
8483put fpo 0 0
8484elemaddr e get rk 0 get rv 0 get rt 0
8485ty = ulong uchar get a_ar add get a_rb 5 sub e 1
8486if and ne o 0 ne isfloat ty 0
8487r = fvdst o
8488eaem or ldop ty 67108864 vtw r
8489put rk 0 9
8490put rv 0 r
8491put rt 0 ty
8492ret
8493end
8494rd = destreg dst
8495eaem ldop ty rd
8496put rk 0 1
8497put rv 0 rd
8498put rt 0 ty
8499end
8500
8501note pl_len: len P of run-time pool e (index + 1): a run-time load of the slot's length (LDR, C6.2.214), never
8502note a constant, so a contract on it is checked at run time (docs/RUNTIME-POOLS.md s5). x86linux: LEA RAX,
8503note [RIP + slot] (SDM vol 2 LEA), MOV RAX, [RAX + 8] (MOV 8B /r), stored to the destination slot.
8504fn pl_len e ulong dst ulong to void
8505rd = destreg dst
8506if ne get xtarget 0 0
8507xaddr 0 get a_ar add get a_rb 8 sub e 1
8508xmem 139 0 0 8
8509xstore 0 rd
8510vdone 1 rd 5
8511ret
8512end
8513mataddr rd get a_ar add get a_rb 8 sub e 1
8514emit or or 4181722112 shl rd 5 rd
8515vdone 1 rd 5
8516end
8517
8518note vs_chk: read / write bounds: n <= len A and off <= len A - n, else trap 3 (CMP C6.2.97, B.HI C6.2.34,
8519note SUB C6.2.458). om4 VT_SYS.
8520fn vs_chk e ulong ro ulong rn ulong to void
8521if ne get xtarget 0 0
8522if ne uchar get a_ar add get a_rb 5 sub e 1 2
8523note d2site 152|vs_chk: type mismatch; condition if ne uchar get a_ar add get a_rb 5 sub e 1 2
8524put d2site 0 152
8525fail 7
8526end
8527xload 1 rn
8528if eq uchar get a_ar add get a_rb 7 sub e 1 10
8529note x86linux pool: the length is loaded from the slot after every operand (soundness rule B1)
8530xaddr 0 get a_ar add get a_rb 8 sub e 1
8531xmem 139 0 0 8
8532else
8533if ne unsz sub e 1 0
8534xload 0 ulong uchar get a_ar add get a_rb 14 sub e 1
8535else
8536ximm 0 get a_ar add get a_rb 6 sub e 1
8537end
8538end
8539xrr 57 1 0
8540xtrap 8 3
8541xrr 41 0 1
8542xload 1 ro
8543xrr 57 1 0
8544xtrap 8 3
8545ret
8546end
8547if ne uchar get a_ar add get a_rb 5 sub e 1 2
8548note d2site 153|vs_chk: type mismatch; condition if ne uchar get a_ar add get a_rb 5 sub e 1 2
8549put d2site 0 153
8550fail 7
8551end
8552t = alloc
8553l = ulong uchar get a_ar add get a_rb 14 sub e 1
8554if eq uchar get a_ar add get a_rb 7 sub e 1 10
8555l = alloc
8556mataddr l get a_ar add get a_rb 8 sub e 1
8557emit or or 4181722112 shl l 5 l
8558else
8559if eq unsz sub e 1 0
8560l = t
8561matconst t get a_ar add get a_rb 6 sub e 1
8562end
8563end
8564emit or or 3942645791 shl rn 5 shl l 16
8565trapc 8 3
8566e3 3405774848 t l rn
8567emit or or 3942645791 shl ro 5 shl t 16
8568trapc 8 3
8569end
8570
8571note vs_call: save the registers in use, X0 = fd, X1 = A + off (ADD through X16, C6.2.6), X2 = n, X8 = 63
8572note (read) or 64 (write) (MOVZ C6.2.285), SVC #0 (C6.2.466). om4 VT_SYS.
8573fn vs_call c ulong fk ulong fv ulong e ulong ro ulong rn ulong to void
8574if ne get xtarget 0 0
8575xio c fk fv e ro rn
8576ret
8577end
8578note target a64efi: read and write are Linux system calls; there is no Linux beneath the image
8579if ne get xefa 0 0
8580note d2site 154|vs_call: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xefa 0 0
8581put d2site 0 154
8582fail 25
8583end
8584save
8585loadarg 0 fk fv
8586basearg 1 e
8587loadarg 16 1 ro
8588emit 2333081633
8589loadarg 2 1 rn
8590emit or 3531603976 shl add c 10 5
8591emit 3556769793
8592end
8593
8594note ca_scal: a scalar argument just read (rk/rv/rt) for parameter p: flags into a register; its type
8595note must be the parameter's; stored at fr[q..q+2]. om4 CA1 .. CA_PUT.
8596fn ca_scal p ulong q ulong to void
8597if eq get rk 0 4
8598put rv 0 matreg 4 get rv 0 get rt 0
8599put rk 0 1
8600put rt 0 1
8601end
8602if ne get rt 0 ulong uchar get a_ar add get a_rb 35 p
8603note d2site 155|ca_scal: type mismatch; condition if ne get rt 0 ulong uchar get a_ar add get a_rb 35 p
8604put d2site 0 155
8605fail 7
8606end
8607put a_ar add get a_rb 77 q get rk 0
8608put a_ar add get a_rb 77 add q 1 get rv 0
8609put a_ar add get a_rb 77 add q 2 0
8610end
8611
8612note ca_arr: an array argument i of function f, call frame cb: one array passed twice is error 19.
8613note om4 CA_ARR .. CA_PUT.
8614fn ca_arr f ulong i ulong cb ulong to void
8615arrarg f i
8616j = ulong 0
8617while lt j i
8618if eq a_g 77 add add cb mul j 3 2 get rt 0
8619note d2site 156|ca_arr: global passed as an argument, or one array twice in a call; condition if eq a_g 77 add add cb mul j 3 2 get rt 0
8620put d2site 0 156
8621fail 19
8622end
8623j = add j 1
8624end
8625q = add cb mul i 3
8626put a_ar add get a_rb 77 q get rk 0
8627put a_ar add get a_rb 77 add q 1 get rv 0
8628put a_ar add get a_rb 77 add q 2 get rt 0
8629end
8630
8631note ca_end: all arguments read: save, the arguments into X0.., BL, restore. Frame cb: 3 per argument,
8632note then cb+18 the parameter count, cb+19 the pool slot before the arguments. om4 CA_DONE .. CA5.
8633fn ca_end f ulong dst ulong cb ulong to void
8634save
8635np = get a_ar add get a_rb 77 add cb 18
8636i = ulong 0
8637while lt i np
8638q = add cb mul i 3
8639s = pslot sub f 1 i
8640loadarg s a_g 77 q a_g 77 add q 1
8641if eq pwid add mul sub f 1 6 i 2
8642ux = add mul div cb 32 6 i
8643loadarg add s 1 a_g 79 ux a_g 80 ux
8644end
8645i = add i 1
8646end
8647ca_bl f
8648hr = ulong 1
8649if eq uchar get a_ar add get a_rb 23 sub f 1 12
8650hr = ulong 0
8651end
8652n = get svn 0
8653a = get sva 0
8654sl = get a_ar add get a_rb 77 add cb 19
8655r = restore dst sl n a hr
8656put rk 0 1
8657put rv 0 r
8658put rt 0 ulong a_gu 23 sub f 1
8659end
8660
8661note vs_fd, vs_arr, vs_off, vs_end: the steps of read / write between the values it reads, with the fd
8662note (kind, value), the offset register and the pool slot before kept in fr[x+8..x+11] (om4's VT_SYS
8663note frame slots 4, 5, 7 and 14)
8664fn vs_fd x ulong to void
8665if ne get rt 0 8
8666note d2site 157|vs_fd: type mismatch; condition if ne get rt 0 8
8667put d2site 0 157
8668fail 7
8669end
8670put a_ar add get a_rb 77 add x 9 get rk 0
8671put a_ar add get a_rb 77 add x 10 get rv 0
8672end
8673
8674fn vs_arr c ulong e ulong to void
8675fz_arg e
8676if ge uchar get a_ar add get a_rb 7 sub e 1 6
8677if ne uchar get a_ar add get a_rb 7 sub e 1 10
8678note d2site 158|vs_arr: type mismatch; condition if ne uchar get a_ar add get a_rb 7 sub e 1 10
8679put d2site 0 158
8680fail 7
8681end
8682end
8683if eq c 53
8684k = uchar get a_ar add get a_rb 7 sub e 1
8685if or eq k 2 eq k 5
8686note d2site 159|vs_arr: write to a view or a text; condition if or eq k 2 eq k 5
8687put d2site 0 159
8688fail 20
8689end
8690end
8691end
8692
8693fn vs_off x ulong to void
8694if ne get rt 0 5
8695note d2site 160|vs_off: type mismatch; condition if ne get rt 0 5
8696put d2site 0 160
8697fail 7
8698end
8699put a_ar add get a_rb 77 add x 11 matreg get rk 0 get rv 0 get rt 0
8700end
8701
8702fn vs_end c ulong e ulong dst ulong x ulong to void
8703if ne get rt 0 5
8704note d2site 161|vs_end: type mismatch; condition if ne get rt 0 5
8705put d2site 0 161
8706fail 7
8707end
8708rn = matreg get rk 0 get rv 0 get rt 0
8709ro = get a_ar add get a_rb 77 add x 11
8710vs_chk e ro rn
8711fk = get a_ar add get a_rb 77 add x 9
8712fv = get a_ar add get a_rb 77 add x 10
8713vs_call c fk fv e ro rn
8714sl = get a_ar add get a_rb 77 add x 8
8715n = get svn 0
8716a = get sva 0
8717r = restore dst sl n a 1
8718vdone 1 r 9
8719end
8720
8721note Native Linux ARM64 host operations. Encoding forms are those in seed/rung2/table.s2.
8722note Syscall numbers and layouts: Linux asm-generic/unistd.h, fcntl.h and time.h.
8723note No raw address or arbitrary syscall is exposed to an Omega program.
8724fn hargc c ulong to ulong
8725if eq c 107
8726ret 0
8727end
8728if eq c 109
8729ret 0
8730end
8731if eq c 129
8732ret 0
8733end
8734if eq c 145
8735ret 0
8736end
8737if eq c 146
8738ret 0
8739end
8740if eq c 147
8741ret 0
8742end
8743if eq c 148
8744ret 0
8745end
8746if eq c 154
8747ret 0
8748end
8749if eq c 158
8750ret 0
8751end
8752if eq c 100
8753ret 1
8754end
8755if eq c 101
8756ret 1
8757end
8758if eq c 153
8759ret 1
8760end
8761if eq c 155
8762ret 1
8763end
8764if eq c 156
8765ret 1
8766end
8767if eq c 159
8768ret 1
8769end
8770if eq c 163
8771ret 1
8772end
8773if eq c 164
8774ret 1
8775end
8776if eq c 102
8777ret 2
8778end
8779if eq c 105
8780ret 2
8781end
8782if eq c 106
8783ret 2
8784end
8785if eq c 127
8786ret 2
8787end
8788if eq c 139
8789ret 2
8790end
8791if eq c 160
8792ret 2
8793end
8794if eq c 165
8795ret 2
8796end
8797if eq c 197
8798ret 2
8799end
8800if eq c 240
8801ret 2
8802end
8803ret 3
8804end
8805fn hsysno c ulong to ulong
8806if eq c 127
8807ret 129
8808end
8809if eq c 129
8810ret 172
8811end
8812if eq c 100
8813ret 57
8814end
8815if eq c 101
8816ret 82
8817end
8818if eq c 102
8819ret 52
8820end
8821if eq c 103
8822ret 62
8823end
8824if eq c 104
8825ret 198
8826end
8827if eq c 139
8828ret 46
8829end
8830if eq c 145
8831ret 174
8832end
8833if eq c 146
8834ret 175
8835end
8836if eq c 147
8837ret 176
8838end
8839if eq c 148
8840ret 177
8841end
8842if eq c 144
8843ret 48
8844end
8845if eq c 153
8846ret 50
8847end
8848if eq c 154
8849ret 173
8850end
8851if eq c 155
8852ret 166
8853end
8854if eq c 156
8855ret 83
8856end
8857if eq c 157
8858ret 279
8859end
8860if eq c 158
8861ret 157
8862end
8863if eq c 159
8864ret 155
8865end
8866if eq c 160
8867ret 154
8868end
8869if eq c 163
8870ret 156
8871end
8872if eq c 164
8873ret 267
8874end
8875if eq c 165
8876ret 210
8877end
8878if eq c 197
8879ret 32
8880end
8881if eq c 105
8882ret 201
8883end
8884if eq c 106
8885ret 242
8886end
8887if eq c 107
8888ret 220
8889end
8890if eq c 239
8891ret 140
8892end
8893if eq c 240
8894ret 141
8895end
8896ret 24
8897end
8898fn harg x ulong i ulong ty ulong to void
8899rdval 0 ty 255 0
8900if ne get rt 0 ty
8901note d2site 162|harg: type mismatch; condition if ne get rt 0 ty
8902put d2site 0 162
8903fail 7
8904end
8905q = add add x 8 mul i 2
8906put a_ar add get a_rb 77 q get rk 0
8907put a_ar add get a_rb 77 add q 1 get rv 0
8908end
8909fn hload x ulong i ulong reg ulong to void
8910q = add add x 8 mul i 2
8911loadarg reg a_g 77 q a_g 77 add q 1
8912end
8913fn hsys n ulong to void
8914matconst 8 n
8915emit 3556769793
8916end
8917fn hreturn dst ulong x ulong to void
8918sl = get a_ar add get a_rb 77 add x 7
8919n = get svn 0
8920a = get sva 0
8921r = restore dst sl n a 1
8922vdone 1 r 9
8923end
8924fn hscalar c ulong dst ulong x ulong to void
8925np = hargc c
8926for i ulong np
8927ty = ulong 8
8928if or and eq c 103 eq i 1 and eq c 139 eq i 1
8929ty = ulong 9
8930end
8931harg x i ty
8932end
8933note VFIO descriptor-kind state exists only in standalone programs, never in OM-2 unit contexts.
8934if and ne get progmode 0 0 or eq c 100 eq c 108
8935if eq get fdtab 0 0
8936fdpool = get poolb 0
8937if gt fdpool 1073739776
8938note d2site 163|hscalar: size capacity; condition if gt fdpool 1073739776
8939put d2site 0 163
8940fail 23
8941end
8942put fdtab 0 add 276824064 fdpool
8943put poolb 0 add fdpool 2048
8944end
8945end
8946save
8947if and ne get progmode 0 0 eq c 100
8948hload x 0 10
8949fdforget
8950end
8951for i ulong np
8952hload x i i
8953end
8954if eq c 106
8955hload x 1 3
8956matconst 1 0
8957matconst 2 0
8958end
8959if eq c 107
8960matconst 0 17
8961for i ulong 5
8962matconst add i 1 0
8963end
8964end
8965hsys hsysno c
8966if and ne get progmode 0 0 eq c 108
8967mimmed 4043309056 31 0 0
8968baddup = mbranch 11
8969hload x 1 10
8970fdforget
8971patch19 baddup get oc 0
8972end
8973hreturn dst x
8974end
8975fn hclock c ulong dst ulong x ulong to void
8976save
8977spsub 16
8978stkchk
8979matconst 0 1
8980if eq c 130
8981matconst 0 0
8982end
8983emit 2432697313
8984hsys 113
8985emit 4043309087
8986bad = get oc 0
8987emit 1409286155
8988emit 4181722081
8989emit 4181723106
8990note Reject overflow before seconds are multiplied; clock result is a signed nanosecond count.
8991matconst 3 9223372036
8992e3 3942645760 31 1 3
8993trapc 8 1
8994matconst 3 1000000000
8995e3 2600500224 1 1 3
8996e3 2868903936 0 1 2
8997trapc 6 1
8998patch19 bad get oc 0
8999spadd 16
9000hreturn dst x
9001end
9002fn harray x ulong writable ulong to ulong
9003e = arrname 0
9004if ne uchar get a_ar add get a_rb 5 sub e 1 2
9005note d2site 164|harray: type mismatch; condition if ne uchar get a_ar add get a_rb 5 sub e 1 2
9006put d2site 0 164
9007fail 7
9008end
9009if ne writable 0
9010vs_arr 53 e
9011end
9012fz_arg e
9013put a_ar add get a_rb 77 add x 20 e
9014harg x 0 5
9015harg x 1 5
9016ro = matreg a_g 77 add x 8 a_g 77 add x 9 5
9017rn = matreg a_g 77 add x 10 a_g 77 add x 11 5
9018put a_ar add get a_rb 77 add x 21 ro
9019put a_ar add get a_rb 77 add x 22 rn
9020vs_chk e ro rn
9021ret e
9022end
9023note Copy a checked path to a private 4096-byte stack buffer. Reject embedded zero bytes.
9024note Public paths remain length-delimited; only the kernel-facing private copy has a terminator.
9025fn hpathcp x ulong to void
9026e = get a_ar add get a_rb 77 add x 20
9027save
9028basearg 4 e
9029loadarg 16 1 get a_ar add get a_rb 77 add x 21
9030e3 2332033024 4 4 16
9031loadarg 5 1 get a_ar add get a_rb 77 add x 22
9032matconst 6 4095
9033e3 3942645760 31 5 6
9034trapc 8 3
9035end
9036fn hcopy to void
9037spsub 4096
9038stkchk
9039emit 2432697313
9040head = get oc 0
9041emit 4043309247
9042done = get oc 0
9043emit 1409286144
9044emit 960495750
9045emit 4043309279
9046trapc 0 3
9047emit 956301350
9048emit 2432697476
9049emit 2432697377
9050emit 3506439333
9051back head
9052patch19 done get oc 0
9053emit 956301375
9054emit 2432697313
9055matconst 0 18446744073709551516
9056end
9057fn hpath c ulong dst ulong x ulong to void
9058e = harray x 0
9059if or eq c 110 eq c 151
9060harg x 2 8
9061harg x 3 8
9062end
9063if or or or eq c 112 eq c 143 eq c 144 eq c 157
9064harg x 2 8
9065end
9066if eq c 150
9067harg x 2 9
9068end
9069hpathcp x
9070if or eq c 110 eq c 151
9071hload x 2 2
9072hload x 3 3
9073end
9074if eq c 111
9075matconst 2 0
9076end
9077if eq c 126
9078matconst 2 512
9079end
9080if eq c 112
9081hload x 2 2
9082end
9083if or eq c 143 eq c 144
9084hload x 2 2
9085matconst 3 0
9086end
9087if eq c 157
9088hload x 2 2
9089end
9090if eq c 150
9091hload x 2 2
9092end
9093hcopy
9094nr = ulong 56
9095if or eq c 111 eq c 126
9096nr = ulong 35
9097end
9098if eq c 112
9099nr = ulong 34
9100end
9101if eq c 143
9102nr = ulong 53
9103end
9104if eq c 144
9105nr = ulong 48
9106end
9107if eq c 157
9108nr = ulong 279
9109end
9110if eq c 150
9111nr = ulong 45
9112end
9113if eq c 151
9114nr = ulong 54
9115end
9116if eq c 138
9117nr = ulong 49
9118note hcopy leaves AT_FDCWD in X0 and the path in X1; chdir takes the path in X0.
9119e3 2852126720 0 31 1
9120end
9121if eq c 150
9122note truncate takes the path in X0 and the length in X1.
9123e3 2852126720 0 31 1
9124e3 2852126720 1 31 2
9125end
9126if eq c 151
9127note fchownat(dirfd, path, uid, gid, 0): X2/X3 are the ids, X4 is set after the copy.
9128matconst 4 0
9129end
9130if eq c 157
9131note memfd_create(name, flags): X0 = name, X1 = flags.
9132e3 2852126720 0 31 1
9133e3 2852126720 1 31 2
9134end
9135hsys nr
9136spadd 4096
9137hreturn dst x
9138end
9139fn hbuffer c ulong dst ulong x ulong to void
9140harg x 4 8
9141wr = ulong 0
9142if or or or or or eq c 113 eq c 116 eq c 117 eq c 118 eq c 131 eq c 224
9143wr = ulong 1
9144end
9145e = harray x wr
9146if or or eq c 116 eq c 118 eq c 119
9147harg x 2 8
9148end
9149if or eq c 116 eq c 117
9150need = ulong 4
9151if eq c 117
9152need = ulong 128
9153end
9154tmp = alloc
9155matconst tmp need
9156e3 3942645760 31 get a_ar add get a_rb 77 add x 22 tmp
9157trapc 3 3
9158end
9159save
9160hload x 4 0
9161basearg 1 e
9162loadarg 16 1 get a_ar add get a_rb 77 add x 21
9163e3 2332033024 1 1 16
9164loadarg 2 1 get a_ar add get a_rb 77 add x 22
9165nr = ulong 61
9166if eq c 114
9167nr = ulong 203
9168end
9169if eq c 115
9170nr = ulong 200
9171end
9172if eq c 116
9173nr = ulong 260
9174hload x 2 2
9175matconst 3 0
9176end
9177if eq c 117
9178nr = ulong 80
9179end
9180if or eq c 118 eq c 119
9181nr = ulong 207
9182hload x 2 3
9183matconst 4 0
9184matconst 5 0
9185if eq c 119
9186nr = ulong 206
9187matconst 16 16384
9188e3 2852126720 3 3 16
9189end
9190end
9191
9192if or eq c 131 eq c 224
9193note Socket-name queries use a private 32-bit socklen and return the full length.
9194spsub 16
9195stkchk
9196emit 3103785954
9197emit 2432697314
9198if eq c 224
9199hsys 205
9200else
9201hsys 204
9202end
9203emit 4043309087
9204failed = get oc 0
9205emit 1409286155
9206emit 3107980256
9207patch19 failed get oc 0
9208spadd 16
9209else
9210hsys nr
9211end
9212hreturn dst x
9213end
9214fn hargs c ulong dst ulong x ulong to void
9215if eq c 121
9216save
9217emit 4181721952
9218hreturn dst x
9219ret
9220end
9221if eq c 136
9222note envcnt: walk the environment vector X27 + 8*(argc+2) (after argv's own null word) until the
9223note terminating null.
9224save
9225emit 4181721953
9226emit 2432698401
9227bo_lsl 1 3 1
9228e3 2332033024 0 27 1
9229matconst 2 0
9230lb = get oc 0
9231emit 4181721091
9232brend = get oc 0
9233emit 3019898883
9234emit 2432697410
9235emit 2432704512
9236back lb
9237patch19 brend get oc 0
9238emit 2852258784
9239hreturn dst x
9240ret
9241end
9242harg x 4 5
9243e = harray x 1
9244save
9245hload x 4 0
9246if eq c 137
9247note envread: envp[index] lives at X27 + 8*(argc+2+index); scan the entries before it so an
9248note index at or past the count traps 3 even when the vector is sparse or empty.
9249emit 2852127714
9250emit 4181721953
9251emit 2432698401
9252e3 2852126720 0 31 1
9253matconst 16 8
9254emit 2601548800
9255e3 2332033024 3 27 0
9256lb = get oc 0
9257brend = get oc 0
9258emit 3019898882
9259emit 4181721188
9260emit 4043309215
9261trapc 0 3
9262emit 2432704611
9263emit 3506439234
9264back lb
9265patch19 brend get oc 0
9266emit 4181721187
9267emit 4043309183
9268trapc 0 3
9269else
9270emit 4181721953
9271e3 3942645760 31 0 1
9272trapc 2 3
9273emit 2432697344
9274matconst 16 8
9275e3 2600500224 0 0 16
9276e3 2332033024 3 27 0
9277emit 4181721187
9278end
9279e3 2852126720 4 31 3
9280matconst 5 0
9281scan = get oc 0
9282emit 960495750
9283emit 4043309279
9284done = get oc 0
9285emit 1409286144
9286emit 2432697476
9287emit 2432697509
9288matconst 16 1048576
9289e3 3942645760 31 5 16
9290trapc 2 3
9291back scan
9292patch19 done get oc 0
9293loadarg 2 1 get a_ar add get a_rb 77 add x 22
9294e3 3942645760 31 5 2
9295small = get oc 0
9296emit 1409286152
9297basearg 0 e
9298loadarg 16 1 get a_ar add get a_rb 77 add x 21
9299e3 2332033024 0 0 16
9300e3 2852126720 2 31 5
9301copy = get oc 0
9302emit 4043309247
9303endcp = get oc 0
9304emit 1409286144
9305emit 960495718
9306emit 956301318
9307emit 2432697443
9308emit 2432697344
9309emit 3506439333
9310back copy
9311patch19 endcp get oc 0
9312e3 2852126720 0 31 2
9313endbr = get oc 0
9314emit 335544320
9315patch19 small get oc 0
9316matconst 0 18446744073709551511
9317patch26 endbr get oc 0
9318hreturn dst x
9319end
9320
9321note waitio(fd int, events int, timeout_ns long): revents, 0 timeout, or negative errno.
9322note ppoll uses one private pollfd and one private timespec. Negative timeout is infinite.
9323fn hwaitio dst ulong x ulong to void
9324harg x 0 8
9325harg x 1 8
9326harg x 2 9
9327save
9328hload x 0 0
9329hload x 1 1
9330hload x 2 2
9331note pollfd.events is 16 bits; refuse truncation of the public int argument.
9332emit 4043309119
9333trapc 11 3
9334matconst 16 65535
9335e3 3942645760 31 1 16
9336trapc 8 3
9337spsub 32
9338stkchk
9339emit 4177527807
9340emit 3103785952
9341emit 2030046177
9342matconst 3 1000000000
9343emit 4043309151
9344forever = get oc 0
9345emit 1409286155
9346e3 2596276224 4 2 3
9347emit 2600700037
9348emit 4177528804
9349emit 4177529829
9350emit 2432705506
9351jump = get oc 0
9352emit 335544320
9353patch19 forever get oc 0
9354matconst 2 0
9355patch26 jump get oc 0
9356emit 2432697312
9357matconst 1 1
9358matconst 3 0
9359matconst 4 8
9360hsys 73
9361emit 4043309087
9362failed = get oc 0
9363emit 1409286157
9364emit 2034241504
9365patch19 failed get oc 0
9366spadd 32
9367hreturn dst x
9368end
9369
9370note hexw: 1 for the exec words (execprog 124, execpure 198, execenv 233), whose argv packet may hold
9371note 65536 bytes and 1024 records; 0 for renames, link and symlnk.
9372fn hexw c ulong to ulong
9373if or or eq c 124 eq c 198 eq c 233
9374ret 1
9375end
9376ret 0
9377end
9378note hnpass: packet passes of hpack/xhpack: 2 for execenv (argv, then environment), else 1.
9379fn hnpass c ulong to ulong
9380if eq c 233
9381ret 2
9382end
9383ret 1
9384end
9385note hplim: the record-count limit of packet pass p: 1024 for an exec argv packet, else 64.
9386fn hplim c ulong p ulong to ulong
9387if eq p 0
9388if ne hexw c 0
9389ret 1024
9390end
9391end
9392ret 64
9393end
9394
9395note A packed argument list is u16 count followed by count (u16 length, bytes) records.
9396note Byte order is little-endian. An exec argv packet (execprog, execpure, execenv) is at most 65536
9397note bytes and 1024 records; renames, link and symlnk packets and the execenv environment packet are
9398note at most 4096 bytes and 64 records. The decoder constructs kernel pointers only in private stack memory.
9399note execenv 233 (execenv A off n B off m) decodes a second packet, the environment, with the same
9400note rules except that every record must be nonempty. Its base and length are loaded into x14/x15
9401note before SPSUB (save-area reads are SP-relative) and both packets are checked before any fd closes.
9402note Stack, exec words: argv strings SP, argv pointers SP+65536 (at most 1025 words), and for execenv
9403note env strings SP+81920, env pointers SP+86016 (at most 65 words). Other words: strings SP,
9404note pointers SP+4096, 8192 bytes.
9405fn hpack c ulong dst ulong x ulong to void
9406errs = new ulong 16 0
9407tbl = new ulong 27 0
9408e = harray x 0
9409if eq c 125
9410harg x 2 8
9411end
9412if eq c 233
9413put a_ar add get a_rb 77 add x 23 e
9414a_p 77 add x 24 a_g 77 add x 21
9415a_p 77 add x 25 a_g 77 add x 22
9416e = harray x 0
9417put a_ar add get a_rb 77 add x 26 e
9418a_p 77 add x 27 a_g 77 add x 21
9419a_p 77 add x 28 a_g 77 add x 22
9420a_p 77 add x 20 a_g 77 add x 23
9421a_p 77 add x 21 a_g 77 add x 24
9422a_p 77 add x 22 a_g 77 add x 25
9423e = get a_ar add get a_rb 77 add x 23
9424end
9425save
9426basearg 4 e
9427loadarg 16 1 get a_ar add get a_rb 77 add x 21
9428e3 2332033024 4 4 16
9429loadarg 5 1 get a_ar add get a_rb 77 add x 22
9430if ne hexw c 0
9431matconst 16 65536
9432else
9433matconst 16 4096
9434end
9435e3 3942645760 31 5 16
9436trapc 8 3
9437emit 4043311295
9438trapc 3 3
9439if eq c 125
9440hload x 2 14
9441end
9442note stack: 8192 bytes for renames, link and symlnk; 81920 for execprog and execpure; 90112 for
9443note execenv, whose second pass decodes the environment packet.
9444stack = ulong 8192
9445if ne hexw c 0
9446stack = ulong 81920
9447end
9448if eq c 233
9449note x14 = env base + off (ADD), x15 = env length; length 2..4096 (CMP x15,x16 B.HI; CMP x15,#2 B.LO).
9450basearg 14 get a_ar add get a_rb 77 add x 26
9451loadarg 16 1 get a_ar add get a_rb 77 add x 27
9452e3 2332033024 14 14 16
9453loadarg 15 1 get a_ar add get a_rb 77 add x 28
9454matconst 16 4096
9455e3 3942645760 31 15 16
9456trapc 8 3
9457emit 4043311615
9458trapc 3 3
9459stack = ulong 90112
9460end
9461spsub stack
9462stkchk
9463pass = ulong 0
9464while lt pass hnpass c
9465if eq pass 1
9466note MOV x4,x14; MOV x5,x15 (ORR with XZR): the environment packet.
9467e3 2852126720 4 31 14
9468e3 2852126720 5 31 15
9469end
9470emit 2034237574
9471emit 2432698500
9472emit 3506440357
9473emit 4043309279
9474trapc 0 3
9475matconst 16 hplim c pass
9476e3 3942645760 31 6 16
9477trapc 8 3
9478if or or eq c 125 eq c 141 eq c 142
9479emit 4043311327
9480trapc 1 3
9481end
9482matconst 9 0
9483if eq pass 0
9484emit 2432697322
9485if ne hexw c 0
9486emit 2436908011
9487else
9488emit 2436892651
9489end
9490else
9491note ADD x10,SP,#20,LSL12; ADD x11,SP,#21,LSL12: env strings and env pointers.
9492emit 2436912106
9493emit 2436913131
9494end
9495outer = get oc 0
9496e3 3942645760 31 9 6
9497done = get oc 0
9498emit 1409286146
9499emit 4043311295
9500trapc 3 3
9501emit 2034237580
9502emit 2432698500
9503emit 3506440357
9504e3 3942645760 31 12 5
9505trapc 8 3
9506note A program path and both rename paths must be nonempty; every environment record is nonempty.
9507note (Nested conditions keep om4 within its 16 live registers.)
9508if eq pass 0
9509if or or eq c 124 eq c 198 eq c 233
9510emit 4043309375
9511notfirst = get oc 0
9512emit 1409286145
9513emit 4043309471
9514trapc 0 3
9515patch19 notfirst get oc 0
9516else
9517emit 4043309471
9518trapc 0 3
9519end
9520else
9521emit 4043309471
9522trapc 0 3
9523end
9524emit 4177527146
9525emit 2432704875
9526inner = get oc 0
9527emit 4043309471
9528endstr = get oc 0
9529emit 1409286144
9530emit 960495757
9531emit 4043309503
9532trapc 0 3
9533emit 956301645
9534emit 2432697476
9535emit 2432697674
9536emit 3506439333
9537emit 3506439564
9538back inner
9539patch19 endstr get oc 0
9540emit 956301663
9541emit 2432697674
9542emit 2432697641
9543back outer
9544patch19 done get oc 0
9545emit 4043309247
9546trapc 1 3
9547emit 4177527167
9548pass = add pass 1
9549end
9550if or or eq c 124 eq c 198 eq c 233
9551note Exec admits only the caller-assigned standard streams. Linux close_range with UNSHARE
9552note closes every descriptor >=3 in a private table. Failure returns without executing a child;
9553note no guessed descriptor ceiling or permissive fallback. This is not filesystem isolation.
9554matconst 0 3
9555matconst 1 4294967295
9556matconst 2 2
9557hsys 436
9558emit 4043309087
9559note outer and done are dead after the packet scan; they are reused for the two branch sites here.
9560done = get oc 0
9561emit 1409286145
9562if eq c 198
9563note execpure strict stdio profile: Linux UAPI layouts in 640 private guest stack bytes, never an
9564note exposed native pointer. sock_filter is u16 code,u8 jt,u8 jf,u32 k; sock_fprog has its length at
9565note 0 and its pointer at 8 on AArch64. A Landlock path rule is a packed u64 allowed_access plus an
9566note s32 parent_fd; prlimit64 takes two u64s. Each step that returns a negative value branches (B.LT)
9567note to the common restore with the kernel error in x0. ADD x16,SP,#k then STR x0,[x16] stores a word.
9568n = ulong 0
9569spsub 640
9570stkchk
9571mimmed 2432697312 16 0 632
9572e3 4177526784 11 16 0
9573note Extra descriptors are already closed in a private table. Pin the executable as descriptor 3.
9574matconst 0 18446744073709551516
9575mimmed 2432697312 1 0 640
9576matconst 2 2621440
9577matconst 3 0
9578hsys 56
9579emit 4043309087
9580put errs n get oc 0
9581emit 1409286155
9582n = add n 1
9583note ABI3 rights through TRUNCATE are all handled, with only read/execute of that one inode allowed.
9584matconst 0 32767
9585mimmed 2432697312 16 0 0
9586e3 4177526784 0 16 0
9587mimmed 2432697312 0 0 0
9588matconst 1 8
9589matconst 2 0
9590hsys 444
9591emit 4043309087
9592put errs n get oc 0
9593emit 1409286155
9594n = add n 1
9595matconst 0 5
9596mimmed 2432697312 16 0 16
9597e3 4177526784 0 16 0
9598matconst 0 3
9599mimmed 2432697312 16 0 24
9600e3 4177526784 0 16 0
9601matconst 0 4
9602matconst 1 1
9603mimmed 2432697312 2 0 16
9604matconst 3 0
9605hsys 445
9606emit 4043309087
9607put errs n get oc 0
9608emit 1409286155
9609n = add n 1
9610matconst 0 38
9611matconst 1 1
9612matconst 2 0
9613matconst 3 0
9614matconst 4 0
9615hsys 167
9616emit 4043309087
9617put errs n get oc 0
9618emit 1409286155
9619n = add n 1
9620matconst 0 4
9621matconst 1 0
9622hsys 446
9623emit 4043309087
9624put errs n get oc 0
9625emit 1409286155
9626n = add n 1
9627matconst 0 4
9628hsys 57
9629emit 4043309087
9630put errs n get oc 0
9631emit 1409286155
9632n = add n 1
9633note Per-process ceilings as (resource, soft, hard): CPU, FSIZE, STACK, CORE, NPROC, NOFILE, AS.
9634note Pipe-output and wall budgets additionally require the trusted supervisor.
9635put tbl 1 1
9636put tbl 2 2
9637put tbl 3 1
9638put tbl 4 1048576
9639put tbl 5 1048576
9640put tbl 6 3
9641put tbl 7 8388608
9642put tbl 8 8388608
9643put tbl 9 4
9644put tbl 12 6
9645put tbl 15 7
9646put tbl 16 4
9647put tbl 17 4
9648put tbl 18 9
9649put tbl 19 134217728
9650put tbl 20 134217728
9651for i ulong 7
9652matconst 0 get tbl add mul i 3 1
9653mimmed 2432697312 16 0 48
9654e3 4177526784 0 16 0
9655matconst 0 get tbl add mul i 3 2
9656mimmed 2432697312 16 0 56
9657e3 4177526784 0 16 0
9658matconst 0 0
9659matconst 1 get tbl mul i 3
9660mimmed 2432697312 2 0 48
9661matconst 3 0
9662hsys 261
9663emit 4043309087
9664put errs n get oc 0
9665emit 1409286155
9666n = add n 1
9667end
9668note Validate architecture, then read only 0, write only 1/2, exit/exit_group. Everything else is EPERM.
9669note execveat is restricted to descriptor 3 and AT_EMPTY_PATH; Landlock also binds execution to inode 3.
9670note The inode rule is essential: an absolute execveat path otherwise ignores its dirfd argument.
9671note Entry i = code | jt<<16 | jf<<24 | k<<32, stored at SP+128+8i. (code jt jf k) rows in order:
9672note (32 0 0 4) (21 1 0 3221225655) (6 0 0 2147483648) (32 0 0 0) (21 0 3 63) (32 0 0 16) (21 0 1 0) (6 0 0 2147418112) (32 0 0 0)
9673note (21 0 4 64) (32 0 0 16) (21 1 0 1) (21 0 1 2) (6 0 0 2147418112) (32 0 0 0) (21 0 1 93) (6 0 0 2147418112) (21 0 1 94)
9674note (6 0 0 2147418112) (32 0 0 0) (21 0 5 281) (32 0 0 16) (21 0 3 3) (32 0 0 48) (21 0 1 4096) (6 0 0 2147418112) (6 0 0 327681)
9675put tbl 0 ulong 17179869216
9676put tbl 1 ulong 13835058841261244437
9677put tbl 2 ulong 9223372036854775814
9678put tbl 3 ulong 32
9679put tbl 4 ulong 270633271317
9680put tbl 5 ulong 68719476768
9681put tbl 6 ulong 16777237
9682put tbl 7 ulong 9223090561878065158
9683put tbl 8 ulong 32
9684put tbl 9 ulong 274945015829
9685put tbl 10 ulong 68719476768
9686put tbl 11 ulong 4295032853
9687put tbl 12 ulong 8606711829
9688put tbl 13 ulong 9223090561878065158
9689put tbl 14 ulong 32
9690put tbl 15 ulong 399448735765
9691put tbl 16 ulong 9223090561878065158
9692put tbl 17 ulong 403743703061
9693put tbl 18 ulong 9223090561878065158
9694put tbl 19 ulong 32
9695put tbl 20 ulong 1206969696277
9696put tbl 21 ulong 68719476768
9697put tbl 22 ulong 12935233557
9698put tbl 23 ulong 206158430240
9699put tbl 24 ulong 17592202821653
9700put tbl 25 ulong 9223090561878065158
9701put tbl 26 ulong 1407379178520582
9702for i ulong 27
9703matconst 0 get tbl i
9704mimmed 2432697312 16 0 add 128 mul i 8
9705e3 4177526784 0 16 0
9706end
9707matconst 0 27
9708mimmed 2432697312 16 0 80
9709e3 4177526784 0 16 0
9710mimmed 2432697312 0 0 128
9711mimmed 2432697312 16 0 88
9712e3 4177526784 0 16 0
9713matconst 0 1
9714matconst 1 0
9715mimmed 2432697312 2 0 80
9716hsys 277
9717emit 4043309087
9718put errs n get oc 0
9719emit 1409286155
9720n = add n 1
9721note Restore the original packet stack before entering the pinned executable. Descriptor 3 is CLOEXEC.
9722mimmed 2432697312 16 0 632
9723e3 4181721088 11 16 0
9724spadd 640
9725matconst 0 3
9726e3 2852126720 1 31 11
9727emit 2436908002
9728e3 2852126720 3 31 11
9729matconst 4 4096
9730hsys 281
9731outer = get oc 0
9732emit 335544320
9733while gt n 0
9734n = sub n 1
9735patch19 get errs n get oc 0
9736end
9737mimmed 2432697312 16 0 632
9738e3 4181721088 11 16 0
9739spadd 640
9740patch26 outer get oc 0
9741else
9742emit 2432697312
9743emit 2436908001
9744if eq c 233
9745note ADD x2,SP,#21,LSL12: envp is the private environment pointer list.
9746emit 2436913122
9747else
9748note MOV x2,x11: envp is the argv list's NULL terminator, an empty environment.
9749e3 2852126720 2 31 11
9750end
9751hsys 221
9752end
9753patch19 done get oc 0
9754else
9755if eq c 125
9756emit 2436892656
9757emit 4181721601
9758emit 4181722627
9759matconst 0 18446744073709551516
9760matconst 2 18446744073709551516
9761e3 2852126720 4 31 14
9762hsys 276
9763else
9764note linkat/symlnk: the packed list's two records are pointer-list entries 0 and 1.
9765emit 2436892656
9766emit 4181721601
9767emit 4181722627
9768if eq c 141
9769matconst 0 18446744073709551516
9770matconst 2 18446744073709551516
9771matconst 4 0
9772hsys 37
9773else
9774e3 2852126720 2 31 3
9775e3 2852126720 0 31 1
9776matconst 1 18446744073709551516
9777hsys 36
9778end
9779end
9780end
9781spadd stack
9782hreturn dst x
9783end
9784
9785fn hreadlnk dst ulong x ulong to void
9786e = harray x 0
9787put a_ar add get a_rb 77 add x 23 e
9788a_p 77 add x 24 a_g 77 add x 21
9789a_p 77 add x 25 a_g 77 add x 22
9790e = harray x 1
9791put a_ar add get a_rb 77 add x 26 e
9792a_p 77 add x 27 a_g 77 add x 21
9793a_p 77 add x 28 a_g 77 add x 22
9794a_p 77 add x 20 a_g 77 add x 23
9795a_p 77 add x 21 a_g 77 add x 24
9796a_p 77 add x 22 a_g 77 add x 25
9797hpathcp x
9798note readlnk refuses an empty path before the kernel call.
9799emit 4043309247
9800trapc 0 3
9801basearg 2 get a_ar add get a_rb 77 add x 26
9802loadarg 16 1 get a_ar add get a_rb 77 add x 27
9803e3 2332033024 2 2 16
9804loadarg 3 1 get a_ar add get a_rb 77 add x 28
9805hcopy
9806hsys 78
9807spadd 4096
9808hreturn dst x
9809end
9810note stat: path slice (readonly) + output slice, at least 128 bytes for the ARM64 stat structure.
9811note Linux newfstatat(AT_FDCWD, path, out, 0); returns 0 or -errno. A short output traps 3.
9812note pread/pwrite: fd, byte slice (off, n), position long. The file offset is not moved.
9813note pread (161) writes A, so A must be writable (error 20); pwrite (162) only reads A, so a text is allowed.
9814fn hpread c ulong dst ulong x ulong to void
9815harg x 4 8
9816wr = ulong 0
9817if eq c 161
9818wr = ulong 1
9819end
9820e = harray x wr
9821harg x 3 9
9822save
9823hload x 4 0
9824basearg 1 e
9825loadarg 16 1 get a_ar add get a_rb 77 add x 21
9826e3 2332033024 1 1 16
9827loadarg 2 1 get a_ar add get a_rb 77 add x 22
9828hload x 3 3
9829nr = ulong 67
9830if eq c 162
9831nr = ulong 68
9832end
9833hsys nr
9834hreturn dst x
9835end
9836
9837fn hstat c ulong dst ulong x ulong to void
9838e = harray x 0
9839put a_ar add get a_rb 77 add x 23 e
9840a_p 77 add x 24 a_g 77 add x 21
9841a_p 77 add x 25 a_g 77 add x 22
9842e = harray x 1
9843put a_ar add get a_rb 77 add x 26 e
9844a_p 77 add x 27 a_g 77 add x 21
9845a_p 77 add x 28 a_g 77 add x 22
9846a_p 77 add x 20 a_g 77 add x 23
9847a_p 77 add x 21 a_g 77 add x 24
9848a_p 77 add x 22 a_g 77 add x 25
9849hpathcp x
9850note stat refuses an empty path before the kernel call.
9851emit 4043309247
9852trapc 0 3
9853basearg 2 get a_ar add get a_rb 77 add x 26
9854loadarg 16 1 get a_ar add get a_rb 77 add x 27
9855e3 2332033024 2 2 16
9856loadarg 3 1 get a_ar add get a_rb 77 add x 28
9857matconst 6 128
9858e3 3942645760 31 3 6
9859trapc 3 3
9860matconst 3 0
9861if eq c 149
9862matconst 3 256
9863end
9864hcopy
9865hsys 79
9866spadd 4096
9867hreturn dst x
9868end
9869fn hsockopt dst ulong x ulong to void
9870harg x 2 8
9871harg x 3 8
9872harg x 4 8
9873e = harray x 0
9874save
9875hload x 2 0
9876hload x 3 1
9877hload x 4 2
9878basearg 3 e
9879loadarg 16 1 get a_ar add get a_rb 77 add x 21
9880e3 2332033024 3 3 16
9881loadarg 4 1 get a_ar add get a_rb 77 add x 22
9882note Only scalar transport options; no filters, devices, credentials or pointer-bearing options.
9883hoptgate
9884hreturn dst x
9885end
9886
9887note Socket option allowlist. Linux asm-generic/socket.h and linux/tcp.h own these IDs.
9888note Unknown options retain ENOPROTOOPT (-92); malformed scalar sizes return EINVAL (-22).
9889fn hoptgate to void
9890ok = new ulong 6 0
9891mimmed 4043309056 31 1 1
9892tcp = get oc 0
9893emit 1409286145
9894for j ulong 5
9895v = add j 5
9896if eq j 0
9897v = ulong 2
9898end
9899if eq j 1
9900v = ulong 15
9901end
9902mimmed 4043309056 31 2 v
9903put ok j get oc 0
9904emit 1409286144
9905end
9906badso = get oc 0
9907emit 335544320
9908patch19 tcp get oc 0
9909mimmed 4043309056 31 1 6
9910badtcp = get oc 0
9911emit 1409286145
9912mimmed 4043309056 31 2 1
9913put ok 5 get oc 0
9914emit 1409286144
9915patch26 badso get oc 0
9916patch19 badtcp get oc 0
9917matconst 0 sub ulong 0 92
9918done = get oc 0
9919emit 335544320
9920for j ulong 6
9921patch19 get ok j get oc 0
9922end
9923mimmed 4043309056 31 4 4
9924sizeok = get oc 0
9925emit 1409286144
9926matconst 0 sub ulong 0 22
9927badsize = get oc 0
9928emit 335544320
9929patch19 sizeok get oc 0
9930hsys 208
9931patch26 done get oc 0
9932patch26 badsize get oc 0
9933end
9934
9935note prlimit pid res A off n (keyword 235): Linux prlimit64, ARM64 261. pid and res are int; A is a writable
9936note byte slice checked like every host slice (trap 3). n 16 reads: new NULL, old {rlim_cur, rlim_max} as
9937note little-endian u64 at A[off..off+16). n 32 sets from A[off..off+16) and writes the old pair to
9938note A[off+16..off+32). Any other n returns -22 (EINVAL) without a kernel call. x4 = &A[off], x5 = n.
9939fn hprlim dst ulong x ulong to void
9940harg x 2 8
9941harg x 3 8
9942e = harray x 1
9943save
9944hload x 2 0
9945hload x 3 1
9946basearg 4 e
9947loadarg 16 1 get a_ar add get a_rb 77 add x 21
9948e3 2332033024 4 4 16
9949loadarg 5 1 get a_ar add get a_rb 77 add x 22
9950matconst 2 0
9951e3 2852126720 3 31 4
9952mimmed 4043309056 31 5 16
9953rd = mbranch 0
9954mimmed 4043309056 31 5 32
9955setp = mbranch 0
9956matconst 0 sub ulong 0 22
9957bad = get oc 0
9958emit 335544320
9959patch19 setp get oc 0
9960e3 2852126720 2 31 4
9961mimmed 2432696320 3 4 16
9962patch19 rd get oc 0
9963hsys 261
9964patch26 bad get oc 0
9965hreturn dst x
9966end
9967
9968note cpuset 236 / cpuget 237 pid A off n: Linux sched_setaffinity 122 / sched_getaffinity 123 (ARM64),
9969note X0 pid (int; 0 is the calling thread), X1 n, X2 &A[off]. The byte slice is checked like every host
9970note slice (trap 3); cpuset only reads it, cpuget writes it (a text is error 20). cpuset gives 0 or minus
9971note errno (a mask with no online permitted CPU is -22); cpuget gives the bytes the kernel wrote (its
9972note cpumask size) or minus errno (n below that size or not a multiple of 8 is -22). cpunow 238, no
9973note operands: getcpu 168 into a 16-byte stack slot, node NULL; the CPU the calling thread ran on at the
9974note call (LDR W0 from the slot only when X0 is not negative), or minus errno.
9975fn hsched c ulong dst ulong x ulong to void
9976if eq c 238
9977save
9978spsub 16
9979stkchk
9980emit 2432697312
9981matconst 1 0
9982matconst 2 0
9983hsys 168
9984emit 4043309087
9985bad = get oc 0
9986emit 1409286155
9987mimmed 3107979264 0 31 0
9988patch19 bad get oc 0
9989spadd 16
9990hreturn dst x
9991ret
9992end
9993harg x 2 8
9994w = ulong 0
9995if eq c 237
9996w = ulong 1
9997end
9998e = harray x w
9999save
10000hload x 2 0
10001basearg 2 e
10002loadarg 16 1 get a_ar add get a_rb 77 add x 21
10003e3 2332033024 2 2 16
10004loadarg 1 1 get a_ar add get a_rb 77 add x 22
10005hsys add 122 w
10006hreturn dst x
10007end
10008
10009note SO_PEERCRED: fixed 12-byte ucred result, never a caller-chosen getsockopt operation.
10010fn hpeercr dst ulong x ulong to void
10011harg x 4 8
10012e = harray x 1
10013save
10014hload x 4 0
10015basearg 3 e
10016loadarg 16 1 get a_ar add get a_rb 77 add x 21
10017e3 2332033024 3 3 16
10018loadarg 4 1 get a_ar add get a_rb 77 add x 22
10019matconst 16 12
10020e3 3942645760 31 4 16
10021trapc 3 3
10022matconst 1 1
10023matconst 2 17
10024spsub 16
10025stkchk
10026matconst 4 12
10027emit or ulong 3103785952 4
10028emit or ulong 2432697312 4
10029hsys 209
10030spadd 16
10031hreturn dst x
10032end
10033
10034note pollfds uses packed Linux pollfd records; length is bytes, each record is 8 bytes.
10035note Maximum 1024 records, checked before ppoll. Kernel writes only revents in the checked slice.
10036fn hpollfds dst ulong x ulong to void
10037e = harray x 1
10038harg x 2 9
10039save
10040basearg 0 e
10041loadarg 16 1 get a_ar add get a_rb 77 add x 21
10042e3 2332033024 0 0 16
10043loadarg 1 1 get a_ar add get a_rb 77 add x 22
10044matconst 16 7
10045e3 2315255808 17 1 16
10046mimmed 4043309056 31 17 0
10047trapc 1 3
10048matconst 16 8192
10049e3 3942645760 31 1 16
10050trapc 8 3
10051matconst 16 8
10052e3 2596276224 1 1 16
10053hload x 2 2
10054spsub 16
10055stkchk
10056matconst 3 1000000000
10057emit 4043309151
10058forever = get oc 0
10059emit 1409286155
10060e3 2596276224 4 2 3
10061emit 2600700037
10062emit 4177527780
10063emit 4177528805
10064emit or ulong 2432697312 2
10065jump = get oc 0
10066emit 335544320
10067patch19 forever get oc 0
10068matconst 2 0
10069patch26 jump get oc 0
10070matconst 3 0
10071matconst 4 8
10072hsys 73
10073spadd 16
10074hreturn dst x
10075end
10076
10077note sendmsg has one checked iovec and no ancillary data or exposed kernel pointers.
10078note Arm ARM STR unsigned offset: imm12 scaled by 8, Rn=SP; private msghdr then iovec.
10079fn hsendmsg dst ulong x ulong to void
10080harg x 4 8
10081e = harray x 0
10082harg x 2 8
10083save
10084hload x 4 0
10085hload x 2 2
10086matconst 16 16384
10087e3 2852126720 2 2 16
10088basearg 3 e
10089loadarg 16 1 get a_ar add get a_rb 77 add x 21
10090e3 2332033024 3 3 16
10091loadarg 4 1 get a_ar add get a_rb 77 add x 22
10092spsub 80
10093stkchk
10094for j ulong 10
10095emit or or ulong 4177527776 31 shl j 10
10096end
10097emit or or ulong 4177527776 3 shl ulong 8 10
10098emit or or ulong 4177527776 4 shl ulong 9 10
10099emit or or ulong 2432697312 3 shl ulong 64 10
10100emit or or ulong 4177527776 3 shl ulong 2 10
10101matconst 3 1
10102emit or or ulong 4177527776 3 shl ulong 3 10
10103emit or ulong 2432697312 1
10104hsys 211
10105spadd 80
10106hreturn dst x
10107end
10108
10109note Bounded mapping table belongs to the emitted program, not the compiler process.
10110note 128 slots of address, byte length, generation, access. Only owned spans are accessible.
10111note Function mode has no program image: the caller's runtime table supplies the zero-initialised
10112note 4096-byte table at entry 31 (mcheck and mnew load it from [x7, #248]); nothing is reserved here.
10113fn mtinit to void
10114if eq get progmode 0 0
10115ret
10116end
10117if eq get maptab 0 0
10118p = get poolb 0
10119if gt p 1073737728
10120note d2site 165|mtinit: size capacity; condition if gt p 1073737728
10121put d2site 0 165
10122fail 23
10123end
10124put maptab 0 add 276824064 p
10125put poolb 0 add p 4096
10126end
10127end
10128note Instruction forms in seed/rung2/table.s2. ldr/str offsets count eight-byte cells.
10129fn mload d ulong n ulong off ulong to void
10130emit or or or 4181721088 d shl n 5 shl off 10
10131end
10132fn mstore d ulong n ulong off ulong to void
10133emit or or or 4177526784 d shl n 5 shl off 10
10134end
10135fn mimmed op ulong d ulong n ulong k ulong to void
10136emit or or or op d shl n 5 shl k 10
10137end
10138fn mbranch cc ulong to ulong
10139p = get oc 0
10140emit or 1409286144 cc
10141ret p
10142end
10143
10144note Descriptor-kind table is process local, not a sandbox. Full fd keys avoid high-fd cleanup resets.
10145note Tags certify the current descriptor, not a generation-bearing stale integer reference.
10146note X10 fd, X11 entry or end, X12 remaining. X0..X8 and X15..X17 preserved.
10147fn fdscan kind ulong to void
10148matconst 11 get fdtab 0
10149matconst 12 128
10150head = get oc 0
10151mload 14 11 1
10152mimmed 4043309056 31 14 kind
10153next = mbranch 1
10154found = ulong 0
10155if ne kind 0
10156mload 13 11 0
10157e3 3942645760 31 13 10
10158found = mbranch 0
10159else
10160found = mbranch 0
10161end
10162patch19 next get oc 0
10163mimmed 2432696320 11 11 16
10164mimmed 3506438144 12 12 1
10165mimmed 4043309056 31 12 0
10166again = mbranch 1
10167patch19 again head
10168patch19 found get oc 0
10169end
10170fn fdcheck kind ulong to void
10171fdscan kind
10172mimmed 4043309056 31 12 0
10173trapc 0 3
10174end
10175fn fdforget to void
10176note Match either kind, clearing every matching key. No propagation through dupfd.
10177for kind ulong 2
10178fdscan add kind 1
10179mimmed 4043309056 31 12 0
10180none = mbranch 0
10181mstore 31 11 1
10182patch19 none get oc 0
10183end
10184end
10185fn fdrecord kind ulong to void
10186mimmed 4043309056 31 0 0
10187bad = mbranch 11
10188mstore 0 11 0
10189matconst 12 kind
10190mstore 12 11 1
10191patch19 bad get oc 0
10192end
10193
10194
10195
10196note Validate a long handle in X10; produce entry X11, base X13, length X12.
10197note The slot's generation defeats a stale handle after close and slot reuse.
10198fn mcheck to void
10199if eq get progmode 0 0
10200matconst 15 8191
10201else
10202matconst 15 255
10203end
10204e3 2315255808 11 10 15
10205mimmed 4043309056 31 11 1
10206trapc 3 3
10207if eq get progmode 0 0
10208mload 14 7 31
10209mload 14 14 0
10210mimmed 4043309056 31 14 1
10211trapc 3 3
10212matconst 15 4098
10213e3 3942645760 31 14 15
10214trapc 8 3
10215e3 3942645760 31 11 14
10216trapc 8 3
10217else
10218mimmed 4043309056 31 11 128
10219trapc 8 3
10220end
10221mimmed 3506438144 11 11 1
10222matconst 15 32
10223e3 2600500224 11 11 15
10224if eq get progmode 0 0
10225mload 15 7 31
10226mimmed 2432696320 15 15 32
10227else
10228matconst 15 get maptab 0
10229end
10230e3 2332033024 11 11 15
10231mload 14 11 2
10232mimmed 4043309056 31 14 0
10233trapc 0 3
10234if eq get progmode 0 0
10235matconst 15 13
10236else
10237matconst 15 8
10238end
10239e3 2596283392 10 10 15
10240e3 3942645760 31 10 14
10241trapc 1 3
10242mload 13 11 0
10243mimmed 4043309056 31 13 0
10244trapc 0 3
10245mload 12 11 1
10246end
10247
10248note mapnew fd:int offset:ulong bytes:ulong access:int mode:int -> long handle/errno.
10249note Access 1 or 3 and modes 1/2/33/34 must be literal. No fixed address or executable map.
10250note vfiomap fd:int A off n -> long handle/errno: n must be 32, a struct vfio_region_info the kernel
10251note filled. Its flags need READ|MMAP (1|4); size and offset come from the span. Always read-only shared.
10252note vfiomapw is the same with flags READ|WRITE|MMAP (7) and a read/write shared map, so mapset can store
10253note to device registers (BAR0 MMIO). Only a span the kernel reported writable maps writable.
10254fn mnew c ulong dst ulong x ulong to void
10255acc = ulong 0
10256mode = ulong 1048610
10257if eq c 242
10258harg x 0 8
10259harg x 1 5
10260harg x 2 5
10261acc = ulong 3
10262mode = ulong 1
10263end
10264if eq c 243
10265harg x 2 5
10266mode = ulong 34
10267end
10268if or eq c 229 eq c 230
10269harg x 4 8
10270put a_ar add get a_rb 77 add x 20 harray x 0
10271put a_ar add get a_rb 77 add x 23 alloc
10272matconst get a_ar add get a_rb 77 add x 23 32
10273e3 3942645760 31 a_g 77 add x 22 a_g 77 add x 23
10274trapc 1 3
10275acc = ulong 1
10276if eq c 230
10277acc = ulong 3
10278end
10279mode = ulong 1
10280end
10281if eq c 167
10282harg x 0 8
10283harg x 1 5
10284harg x 2 5
10285harg x 3 8
10286harg x 4 8
10287if or ne a_g 77 add x 14 3 ne a_g 77 add x 16 3
10288note d2site 166|mnew: word or declaration in a place that does not allow it; condition if or ne a_g 77 add x 14 3 ne a_g 77 add x 16 3
10289put d2site 0 166
10290fail 9
10291end
10292acc = get a_ar add get a_rb 77 add x 15
10293mode = get a_ar add get a_rb 77 add x 17
10294if and ne acc 1 ne acc 3
10295note d2site 167|mnew: word or declaration in a place that does not allow it; condition if and ne acc 1 ne acc 3
10296put d2site 0 167
10297fail 9
10298end
10299if and and and ne mode 1 ne mode 2 ne mode 33 ne mode 34
10300note d2site 168|mnew: word or declaration in a place that does not allow it; condition if and and and ne mode 1 ne mode 2 ne mode 33 ne mode 34
10301put d2site 0 168
10302fail 9
10303end
10304end
10305if eq c 176
10306harg x 1 5
10307harg x 2 5
10308end
10309save
10310if eq c 242
10311hload x 0 0
10312kmapfd
10313end
10314if or eq c 229 eq c 230
10315basearg 6 get a_ar add get a_rb 77 add x 20
10316loadarg 16 1 get a_ar add get a_rb 77 add x 21
10317e3 2332033024 6 6 16
10318mimmed 3107979264 15 6 1
10319matconst 14 or 5 sub acc 1
10320e3 2315255808 15 15 14
10321mimmed 4043309056 31 15 or 5 sub acc 1
10322trapc 1 3
10323mload 1 6 2
10324hload x 4 4
10325mload 5 6 3
10326else
10327hload x 2 1
10328end
10329mimmed 4043309056 31 1 0
10330trapc 0 3
10331if lt c 242
10332matconst 15 68719476736
10333e3 3942645760 31 1 15
10334trapc 8 3
10335end
10336if eq c 242
10337hload x 0 4
10338hload x 1 5
10339end
10340if eq c 243
10341matconst 4 18446744073709551615
10342matconst 5 0
10343note Keep the exact requested length; over-reserve only to align the owned base to 2 MiB.
10344matconst 15 4095
10345e3 2315255808 14 1 15
10346mimmed 4043309056 31 14 0
10347trapc 1 3
10348matconst 15 2097152
10349e3 2868903936 1 1 15
10350trapc 2 3
10351end
10352if eq c 167
10353hload x 0 4
10354hload x 1 5
10355if ge mode 32
10356matconst 15 18446744073709551615
10357e3 3942645760 31 4 15
10358trapc 1 3
10359mimmed 4043309056 31 5 0
10360trapc 1 3
10361end
10362end
10363if eq c 176
10364hload x 1 0
10365note Reservations are page aligned and bounded below the 40-bit GPU command limit.
10366matconst 15 65536
10367e3 3942645760 31 0 15
10368trapc 3 3
10369matconst 15 1099511627776
10370e3 3405774848 15 15 1
10371e3 3942645760 31 0 15
10372trapc 8 3
10373matconst 15 4095
10374e3 2315255808 14 0 15
10375mimmed 4043309056 31 14 0
10376trapc 1 3
10377e3 2315255808 14 1 15
10378mimmed 4043309056 31 14 0
10379trapc 1 3
10380matconst 4 18446744073709551615
10381matconst 5 0
10382end
10383if eq get progmode 0 0
10384mload 9 7 31
10385mload 12 9 0
10386mimmed 4043309056 31 12 1
10387trapc 3 3
10388matconst 15 4098
10389e3 3942645760 31 12 15
10390trapc 8 3
10391mload 14 9 2
10392mimmed 4043309056 31 14 1
10393trapc 3 3
10394matconst 15 1125899906842623
10395e3 3942645760 31 14 15
10396trapc 8 3
10397mimmed 2432696320 9 9 32
10398else
10399matconst 9 get maptab 0
10400end
10401matconst 10 1
10402head = get oc 0
10403mload 11 9 0
10404mimmed 4043309056 31 11 0
10405used = mbranch 1
10406mload 11 9 2
10407if eq get progmode 0 0
10408e3 3942645760 31 11 14
10409else
10410matconst 15 36028797018963967
10411e3 3942645760 31 11 15
10412end
10413vacant = mbranch 3
10414patch19 used get oc 0
10415mimmed 2432696320 9 9 32
10416mimmed 2432696320 10 10 1
10417if eq get progmode 0 0
10418e3 3942645760 31 10 12
10419else
10420mimmed 4043309056 31 10 128
10421end
10422again = mbranch 9
10423patch19 again head
10424matconst 0 18446744073709551592
10425full = get oc 0
10426emit 335544320
10427patch19 vacant get oc 0
10428if eq c 176
10429hload x 1 0
10430else
10431matconst 0 0
10432end
10433matconst 2 acc
10434matconst 3 mode
10435hsys 222
10436mimmed 4043309056 31 0 0
10437failed = mbranch 11
10438if eq c 243
10439note Trim only the prefix and suffix of this fresh anonymous mapping.
10440matconst 15 2097152
10441e3 3405774848 1 1 15
10442matconst 15 2097151
10443e3 2332033024 2 0 15
10444matconst 15 18446744073707454464
10445e3 2315255808 2 2 15
10446e3 3405774848 3 2 0
10447spsub 32
10448mstore 1 31 0
10449mstore 2 31 1
10450mstore 3 31 2
10451mimmed 4043309056 31 3 0
10452aligned = mbranch 0
10453e3 2852126720 1 31 3
10454hsys 215
10455mimmed 4043309056 31 0 0
10456trapc 1 3
10457patch19 aligned get oc 0
10458mload 0 31 1
10459mload 1 31 0
10460e3 2332033024 0 0 1
10461mload 2 31 2
10462matconst 1 2097152
10463e3 3405774848 1 1 2
10464hsys 215
10465mimmed 4043309056 31 0 0
10466trapc 1 3
10467mload 0 31 1
10468mload 1 31 0
10469spadd 32
10470end
10471if eq c 176
10472hload x 1 14
10473e3 3942645760 31 0 14
10474exact = mbranch 0
10475note Old kernels may ignore NOREPLACE; reject and unmap any displaced result.
10476hsys 215
10477mimmed 4043309056 31 0 0
10478trapc 1 3
10479matconst 0 18446744073709551521
10480wrong = get oc 0
10481emit 335544320
10482patch19 exact get oc 0
10483a_p 77 add x 23 wrong
10484end
10485mstore 0 9 0
10486mstore 1 9 1
10487mimmed 2432696320 11 11 1
10488mstore 11 9 2
10489matconst 15 acc
10490mstore 15 9 3
10491if eq get progmode 0 0
10492matconst 15 13
10493else
10494matconst 15 8
10495end
10496e3 2596282368 0 11 15
10497e3 2852126720 0 0 10
10498patch19 failed get oc 0
10499patch26 full get oc 0
10500if eq c 176
10501head = a_g 77 add x 23
10502patch26 head get oc 0
10503end
10504hreturn dst x
10505end
10506
10507note Replace only an entire owned PROT_NONE reservation. Failed binds retire the handle.
10508fn mbind dst ulong x ulong to void
10509harg x 0 9
10510harg x 1 8
10511harg x 2 5
10512harg x 3 8
10513if ne get a_ar add get a_rb 77 add x 14 3
10514note d2site 169|mbind: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 14 3
10515put d2site 0 169
10516fail 9
10517end
10518acc = get a_ar add get a_rb 77 add x 15
10519if and ne acc 1 ne acc 3
10520note d2site 170|mbind: word or declaration in a place that does not allow it; condition if and ne acc 1 ne acc 3
10521put d2site 0 170
10522fail 9
10523end
10524save
10525hload x 0 10
10526mcheck
10527mload 15 11 3
10528mimmed 4043309056 31 15 0
10529trapc 1 3
10530e3 2852126720 0 31 13
10531e3 2852126720 1 31 12
10532matconst 2 acc
10533matconst 3 17
10534hload x 1 4
10535hload x 2 5
10536hsys 222
10537mimmed 4043309056 31 0 0
10538failed = mbranch 11
10539e3 3942645760 31 0 13
10540trapc 1 3
10541matconst 15 acc
10542mstore 15 11 3
10543matconst 0 0
10544done = get oc 0
10545emit 335544320
10546patch19 failed get oc 0
10547e3 2852126720 10 31 0
10548e3 2852126720 0 31 13
10549e3 2852126720 1 31 12
10550note Preserve a droppable owner but forbid a second bind if cleanup also fails.
10551if eq get progmode 0 0
10552matconst 15 4
10553mstore 15 11 3
10554end
10555hsys 215
10556mimmed 4043309056 31 0 0
10557trapc 1 3
10558mstore 31 11 0
10559mstore 31 11 1
10560mstore 31 11 3
10561e3 2852126720 0 31 10
10562patch26 done get oc 0
10563hreturn dst x
10564end
10565
10566note Copies traverse only checked live mapped spans and normal bounded byte arrays.
10567note mapread writes A; mapwrite reads A. Both return the count, with no pointer decay.
10568fn mcopy c ulong dst ulong x ulong to void
10569harg x 4 9
10570harg x 3 5
10571wr = ulong 0
10572if eq c 169
10573wr = ulong 1
10574end
10575e = harray x wr
10576save
10577hload x 4 10
10578mcheck
10579mload 15 11 3
10580mimmed 4043309056 31 15 0
10581trapc 0 3
10582if eq get progmode 0 0
10583mimmed 4043309056 31 15 3
10584trapc 8 3
10585end
10586hload x 3 0
10587e3 3942645760 31 0 12
10588trapc 8 3
10589e3 3405774848 12 12 0
10590loadarg 2 1 get a_ar add get a_rb 77 add x 22
10591e3 3942645760 31 2 12
10592trapc 8 3
10593e3 2332033024 0 13 0
10594basearg 1 e
10595loadarg 16 1 get a_ar add get a_rb 77 add x 21
10596e3 2332033024 1 1 16
10597if eq c 170
10598mload 15 11 3
10599mimmed 4043309056 31 15 3
10600trapc 1 3
10601e3 2852126720 15 31 0
10602e3 2852126720 0 31 1
10603e3 2852126720 1 31 15
10604end
10605e3 2852126720 4 31 2
10606head = get oc 0
10607mimmed 4043309056 31 2 0
10608done = mbranch 0
10609emit 960495619
10610emit 956301347
10611mimmed 2432696320 0 0 1
10612mimmed 2432696320 1 1 1
10613mimmed 3506438144 2 2 1
10614back head
10615patch19 done get oc 0
10616e3 2852126720 0 31 4
10617hreturn dst x
10618end
10619
10620note NVRM NVOS21/NVOS54 parameter binding. The kernel sees one private header.
10621note Pointer and length are derived from a checked byte span, never from user bytes.
10622note Request is exactly the 32-byte RM_ALLOC or RM_CONTROL encoding.
10623fn hdevcall dst ulong x ulong to void
10624n = xhreq 171 x
10625e = harray x 1
10626put a_ar add get a_rb 77 add x 23 e
10627a_p 77 add x 24 a_g 77 add x 21
10628t = alloc
10629matconst t 32
10630e3 3942645760 31 get a_ar add get a_rb 77 add x 22 t
10631trapc 1 3
10632f = harray x 1
10633if eq e f
10634note d2site 171|hdevcall: global passed as an argument, or one array twice in a call; condition if eq e f
10635put d2site 0 171
10636fail 19
10637end
10638t = alloc
10639matconst t 1048576
10640e3 3942645760 31 get a_ar add get a_rb 77 add x 22 t
10641trapc 8 3
10642save
10643hload x 4 0
10644hload x 2 1
10645basearg 10 get a_ar add get a_rb 77 add x 23
10646loadarg 16 1 get a_ar add get a_rb 77 add x 24
10647e3 2332033024 10 10 16
10648basearg 11 f
10649loadarg 16 1 get a_ar add get a_rb 77 add x 21
10650e3 2332033024 11 11 16
10651loadarg 12 1 get a_ar add get a_rb 77 add x 22
10652note Refuse overlapping parameter/header spans even through distinct edit parameters.
10653mimmed 4043309056 31 12 0
10654empty = mbranch 0
10655e3 2332033024 14 11 12
10656e3 3942645760 31 14 10
10657before = mbranch 9
10658mimmed 2432696320 14 10 32
10659e3 3942645760 31 11 14
10660trapc 3 3
10661patch19 before get oc 0
10662patch19 empty get oc 0
10663mload 13 10 2
10664mimmed 4043309056 31 13 0
10665trapc 1 3
10666mimmed 4043309056 31 12 0
10667nonzero = mbranch 1
10668matconst 11 0
10669patch19 nonzero get oc 0
10670spsub 32
10671stkchk
10672for i ulong 4
10673mload 13 10 i
10674mstore 13 31 i
10675end
10676mstore 11 31 2
10677emit 3103792108
10678emit 2432697314
10679hsys 29
10680for i ulong 4
10681if ne i 2
10682mload 13 31 i
10683mstore 13 10 i
10684end
10685end
10686spadd 32
10687hreturn dst x
10688end
10689
10690
10691note Mapped-address export for driver GPU VA serialization; no arbitrary-address access.
10692note Aligned word access uses exactly one 32/64-bit load/store bracketed by DSB SY.
10693fn mmapio c ulong dst ulong x ulong to void
10694harg x 0 9
10695if eq c 173
10696save
10697hload x 0 10
10698mcheck
10699e3 2852126720 0 31 13
10700hreturn dst x
10701put rt 0 5
10702ret
10703end
10704harg x 1 5
10705harg x 2 8
10706if ne get a_ar add get a_rb 77 add x 12 3
10707note d2site 172|mmapio: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 12 3
10708put d2site 0 172
10709fail 9
10710end
10711w = get a_ar add get a_rb 77 add x 13
10712if and ne w 4 ne w 8
10713note d2site 173|mmapio: word or declaration in a place that does not allow it; condition if and ne w 4 ne w 8
10714put d2site 0 173
10715fail 9
10716end
10717if eq c 175
10718harg x 3 5
10719end
10720save
10721hload x 0 10
10722mcheck
10723hload x 1 0
10724mload 15 11 3
10725mimmed 4043309056 31 15 0
10726trapc 0 3
10727if eq get progmode 0 0
10728mimmed 4043309056 31 15 3
10729trapc 8 3
10730end
10731e3 3942645760 31 0 12
10732trapc 8 3
10733e3 3405774848 12 12 0
10734mimmed 4043309056 31 12 w
10735trapc 3 3
10736matconst 15 sub w 1
10737e3 2315255808 14 0 15
10738mimmed 4043309056 31 14 0
10739trapc 1 3
10740e3 2332033024 13 13 0
10741if eq c 175
10742mload 15 11 3
10743mimmed 4043309056 31 15 3
10744trapc 1 3
10745hload x 3 2
10746if eq w 4
10747matconst 15 4294967295
10748e3 3942645760 31 2 15
10749trapc 8 3
10750end
10751emit 3573759903
10752if eq w 4
10753mimmed 3103784960 2 13 0
10754else
10755mstore 2 13 0
10756end
10757emit 3573759903
10758matconst 0 0
10759hreturn dst x
10760else
10761emit 3573759903
10762if eq w 4
10763mimmed 3107979264 0 13 0
10764else
10765mload 0 13 0
10766end
10767emit 3573759903
10768hreturn dst x
10769put rt 0 5
10770end
10771end
10772
10773note KFD private records: logical scratch 0..3 and 4 (SP), no language slot registers.
10774fn kfdreg r ulong to ulong
10775if eq get xtarget 0 0
10776if eq r 4
10777ret 31
10778end
10779ret r
10780end
10781if eq r 1
10782ret 2
10783end
10784if eq r 2
10785ret 6
10786end
10787if eq r 3
10788ret 7
10789end
10790ret r
10791end
10792fn kfdimm r ulong v ulong to void
10793if eq get xtarget 0 0
10794matconst kfdreg r v
10795else
10796ximm kfdreg r v
10797end
10798end
10799fn kfdload r ulong b ulong off ulong size ulong to void
10800if eq get xtarget 0 0
10801op = ulong 4181721088
10802if eq size 4
10803op = ulong 3107979264
10804end
10805mimmed op kfdreg r kfdreg b div off size
10806else
10807if eq size 8
10808xmem 139 kfdreg r kfdreg b off
10809else
10810xhraw kfdreg r kfdreg b off size
10811end
10812end
10813end
10814fn kfdstore r ulong b ulong off ulong to void
10815if eq get xtarget 0 0
10816mstore kfdreg r kfdreg b div off 8
10817else
10818xmem 137 kfdreg r kfdreg b off
10819end
10820end
10821fn kfdcmp r ulong s ulong to void
10822if eq get xtarget 0 0
10823e3 3942645760 31 kfdreg r kfdreg s
10824else
10825xrr 57 kfdreg r kfdreg s
10826end
10827end
10828fn kfdcmpv r ulong v ulong to void
10829if eq get xtarget 0 0
10830matconst 16 v
10831e3 3942645760 31 kfdreg r 16
10832else
10833xhcmp kfdreg r v
10834end
10835end
10836fn kfdtrap c ulong to void
10837if eq get xtarget 0 0
10838trapc c 3
10839else
10840xtrap c 3
10841end
10842end
10843fn kfdjump c ulong to ulong
10844if eq get xtarget 0 0
10845ret mbranch c
10846end
10847ret xbranch c
10848end
10849fn kfdpatch p ulong to void
10850if eq get xtarget 0 0
10851patch19 p get oc 0
10852else
10853xpatch p get oc 0
10854end
10855end
10856fn kfdadd r ulong v ulong to void
10857if eq get xtarget 0 0
10858matconst 16 v
10859e3 2332033024 kfdreg r kfdreg r 16
10860else
10861xhadd kfdreg r v
10862end
10863end
10864fn kfdzero off ulong to void
10865kfdload 0 4 off 8
10866kfdcmpv 0 0
10867kfdtrap 1
10868end
10869fn ksize q ulong to ulong
10870if or or eq q 2148027137 eq q 1074285333 or eq q 3221768963 eq q 1074285335
10871ret 8
10872end
10873if or eq q 1074285321 eq q 1074291721
10874ret 8
10875end
10876if or eq q 3222293268 eq q 3222293265
10877ret 16
10878end
10879if or or eq q 3222817560 eq q 3222817561 eq q 3222817548
10880ret 24
10881end
10882if or eq q 1075340356 eq q 1075340359
10883ret 24
10884end
10885if or eq q 3223341832 eq q 3223348291
10886ret 32
10887end
10888if or or eq q 3223866134 eq q 3223872576 eq q 3223872578
10889ret 40
10890end
10891if eq q 3224396870
10892ret 48
10893end
10894if or eq q 3224921153 eq q 1077437513
10895ret 56
10896end
10897if eq q 3225969738
10898ret 72
10899end
10900if eq q 3227011842
10901ret 88
10902end
10903if eq q 1082680389
10904ret 136
10905end
10906note d2site 624|ksize: KFD request is not in the checked request allowlist
10907put d2site 0 624
10908fail 9
10909ret 0
10910end
10911fn kptr q ulong off ulong to bool
10912if eq q 3227011842
10913ret or or le off 16 eq off 56 eq off 72
10914end
10915if or eq q 3222817560 eq q 3222817561
10916ret eq off 8
10917end
10918if or or eq q 3222293268 eq q 3222817548 or eq q 3223866134 eq q 3222293265
10919ret eq off 0
10920end
10921if eq q 3223872576
10922ret eq off 16
10923end
10924if eq q 3224396870
10925ret eq off 24
10926end
10927ret false
10928end
10929note X6 anchors the original AArch64 save area while the private KFD record is on SP.
10930fn karg x ulong i ulong r ulong to void
10931j = add add x 8 mul i 2
10932k = a_g 77 j
10933v = a_g 77 add j 1
10934if or or eq k 3 eq k 7 eq k 6
10935loadarg r k v
10936else
10937mload r 6 regidx v
10938end
10939end
10940fn kbase e ulong to void
10941if ge uchar get a_ar add get a_rb 7 sub e 1 4
10942basearg 3 e
10943else
10944mload 3 6 regidx ulong uchar get a_ar add get a_rb 4 sub e 1
10945end
10946end
10947note kind 0 reservation, kind 3 writable map. need is size-field offset or 255 for minimum sz.
10948note Fixed-layout fields (shape bit 24) bind base plus a compiler constant (shape bits 32 to 47), never caller bytes;
10949note their required remaining bytes are shape bits 48 to 63 (wider than the 8-bit literal size of other fields).
10950fn kbind x ulong i ulong off ulong kind ulong shape ulong z ulong to void
10951need = and shape 255
10952sz = and shr shape 8 255
10953optional = and shr shape 16 255
10954relative = ne and shape 16777216 0
10955kfdzero off
10956if relative
10957kfdimm 0 shr shape 48
10958else
10959if eq need 255
10960kfdimm 0 sz
10961else
10962kfdload 0 4 need sz
10963end
10964end
10965kfdstore 0 4 add z 8
10966if eq get xtarget 0 0
10967karg x i 10
10968mimmed 4043309056 31 10 0
10969else
10970xha x i 10
10971xhcmp 10 0
10972end
10973skip = ulong 0
10974if ne optional 0
10975skip = kfdjump 0
10976end
10977if eq get xtarget 0 0
10978mcheck
10979mload 0 11 3
10980else
10981xhmcheck
10982xmem 139 0 13 24
10983end
10984kfdcmpv 0 kind
10985kfdtrap 1
10986if relative
10987note The offset is the compiler's ABI constant, never a caller-supplied byte.
10988kfdimm 0 and shr shape 32 65535
10989if eq get xtarget 0 0
10990e3 3942645760 31 0 12
10991else
10992xrr 57 0 9
10993end
10994kfdtrap 8
10995note Subtract only after offset <= length; the existing extent check sees remaining bytes.
10996if eq get xtarget 0 0
10997e3 3405774848 12 12 0
10998e3 2332033024 13 13 0
10999e3 3942645760 31 13 0
11000else
11001xrr 41 9 0
11002xrr 1 8 0
11003xrr 57 8 0
11004end
11005kfdtrap 3
11006end
11007kfdload 0 4 add z 8 8
11008if eq get xtarget 0 0
11009e3 3942645760 31 0 12
11010else
11011xrr 57 0 9
11012end
11013kfdtrap 8
11014if eq get xtarget 0 0
11015mstore 13 31 div off 8
11016else
11017xmem 137 8 4 off
11018end
11019if ne optional 0
11020kfdpatch skip
11021if ne optional 2
11022kfdload 0 4 off 8
11023kfdcmpv 0 0
11024live = kfdjump 1
11025kfdload 0 4 add z 8 8
11026kfdcmpv 0 0
11027kfdtrap 1
11028kfdpatch live
11029end
11030end
11031end
11032note Aperture payload dispatch looks ahead without consuming the array or scalar expression.
11033fn kapmap to bool
11034c0 = get cur 0
11035l0 = get line 0
11036a0 = get tka 0
11037b0 = get tkb 0
11038tok
11039e = findname get tw 0
11040r = true
11041if ne e 0
11042k = ulong uchar get a_ar add get a_rb 7 sub e 1
11043r = or eq k 0 eq k 9
11044end
11045put cur 0 c0
11046put line 0 l0
11047put tka 0 a0
11048put tkb 0 b0
11049ret r
11050end
11051note Checked mapping payload: logical 3 receives base+offset, logical 2 receives span length.
11052fn kmspan x ulong to void
11053if eq get xtarget 0 0
11054karg x 0 10
11055mcheck
11056mload 0 11 3
11057else
11058xha x 0 10
11059xhmcheck
11060xmem 139 0 13 24
11061end
11062kfdcmpv 0 3
11063kfdtrap 1
11064if eq get xtarget 0 0
11065karg x 1 0
11066karg x 3 2
11067e3 2332033024 3 0 2
11068else
11069xha x 1 0
11070xha x 3 6
11071xrr 137 7 0
11072xrr 1 7 6
11073end
11074note Reject wrapped offset+length before comparing the mapping extent.
11075kfdcmp 3 0
11076kfdtrap 3
11077if eq get xtarget 0 0
11078e3 3942645760 31 3 12
11079else
11080xrr 57 7 9
11081end
11082kfdtrap 8
11083if eq get xtarget 0 0
11084e3 2332033024 3 13 0
11085else
11086xrr 137 7 8
11087xrr 1 7 0
11088end
11089end
11090fn kspan q ulong x ulong e ulong n ulong z ulong to void
11091off = ulong 0
11092co = ulong 8
11093stride = ulong 56
11094if or eq q 3222817560 eq q 3222817561
11095off = ulong 8
11096co = ulong 16
11097stride = ulong 4
11098end
11099if eq q 3222817548
11100stride = ulong 48
11101end
11102if eq q 3223872576
11103off = ulong 16
11104co = ulong 12
11105stride = ulong 1
11106end
11107if eq q 3224396870
11108off = ulong 24
11109co = ulong 8
11110stride = ulong 8
11111end
11112kfdzero off
11113if eq e 0
11114kmspan x
11115else
11116if eq get xtarget 0 0
11117kbase e
11118mload 16 6 regidx a_g 77 add x 21
11119e3 2332033024 3 3 16
11120mload 2 6 regidx a_g 77 add x 22
11121else
11122xhb 7 e a_g 77 add x 21
11123xhs 6 a_g 77 add x 22
11124end
11125end
11126if eq q 3224396870
11127note XE_EXEC_QUEUE_CREATE: require width=1 and num_placements=1 (8-byte engine_class_instance).
11128kfdload 0 4 8 4
11129kfdcmpv 0 65537
11130kfdtrap 1
11131kfdimm 0 8
11132else
11133kfdload 0 4 co 4
11134if eq get xtarget 0 0
11135matconst 16 stride
11136e3 2600500224 0 0 16
11137else
11138ximm 11 stride
11139xb 73 15 175
11140emitb 195
11141end
11142end
11143note A u32 count times a wire stride fits u64.
11144kfdcmp 0 2
11145kfdtrap 8
11146kfdload 1 4 z 8
11147if eq get xtarget 0 0
11148e3 2332033024 2 3 2
11149else
11150xrr 1 6 7
11151end
11152kfdcmp 2 1
11153before = kfdjump 9
11154kfdadd 1 n
11155kfdcmp 3 1
11156kfdtrap 3
11157kfdpatch before
11158if eq q 3223872576
11159note XE_DEVICE_QUERY with size=0 queries required byte length and requires data=NULL.
11160kfdcmpv 0 0
11161qzero = kfdjump 0
11162kfdstore 3 4 off
11163kfdpatch qzero
11164else
11165kfdstore 3 4 off
11166end
11167if eq q 3222817548
11168note event_data.ext is an unsupported pointer extension and must remain NULL.
11169kfdload 2 4 co 4
11170loop = get oc 0
11171kfdcmpv 2 0
11172done = kfdjump 0
11173kfdload 0 3 32 8
11174kfdcmpv 0 0
11175kfdtrap 1
11176kfdadd 3 48
11177if eq get xtarget 0 0
11178mimmed 3506438144 2 2 1
11179back loop
11180else
11181xhsub 6 1
11182p = xbranch 14
11183xpatch p loop
11184end
11185kfdpatch done
11186end
11187end
11188note ACQUIRE_VM accepts only a DRM render character descriptor. Linux stat layouts
11189note are asm-generic (AArch64) and arch/x86 UAPI; fstat never follows a supplied path.
11190fn kdrm z ulong to void
11191if eq get xtarget 0 0
11192kfdload 0 4 0 4
11193mimmed 2432696320 1 31 add z 32
11194hsys 80
11195else
11196xhraw 7 4 0 4
11197xmem 141 6 4 add z 32
11198xhcall 5
11199end
11200kfdcmpv 0 0
11201kfdtrap 1
11202mo = ulong 16
11203ro = ulong 32
11204if ne get xtarget 0 0
11205mo = ulong 24
11206ro = ulong 40
11207end
11208kfdload 0 4 add add z 32 mo 4
11209if eq get xtarget 0 0
11210matconst 16 61440
11211e3 2315255808 0 0 16
11212else
11213ximm 11 61440
11214xrr 33 0 11
11215end
11216kfdcmpv 0 8192
11217kfdtrap 1
11218kfdload 0 4 add add z 32 ro 8
11219note Linux dev_t encodes minor bits 0..7 and 20..31; every other bit is major.
11220if eq get xtarget 0 0
11221matconst 16 18446744069415632640
11222e3 2315255808 1 0 16
11223else
11224xrr 137 2 0
11225ximm 11 18446744069415632640
11226xrr 33 2 11
11227end
11228kfdcmpv 1 57856
11229kfdtrap 1
11230if eq get xtarget 0 0
11231matconst 16 4293918975
11232e3 2315255808 0 0 16
11233else
11234ximm 11 4293918975
11235xrr 33 0 11
11236end
11237kfdcmpv 0 128
11238kfdtrap 3
11239end
11240
11241note kfdmap admits DRM render character descriptors or the device named /dev/kfd.
11242note The fd is already evaluated and saved. Compare st_rdev, not a caller path.
11243note Python oracle int.from_bytes(b'/dev/kfd','little') = 7234587703011271727.
11244fn kmapfd to void
11245if eq get xtarget 0 0
11246spsub 352
11247stkchk
11248mimmed 2432696320 1 31 0
11249hsys 80
11250else
11251xsp 1 352
11252xrr 137 6 4
11253xhcall 5
11254end
11255kfdcmpv 0 0
11256kfdtrap 1
11257mo = ulong 16
11258ro = ulong 32
11259if ne get xtarget 0 0
11260mo = ulong 24
11261ro = ulong 40
11262end
11263kchar mo
11264kfdload 0 4 ro 8
11265kfdstore 0 4 304
11266if eq get xtarget 0 0
11267matconst 16 18446744069415632640
11268e3 2315255808 1 0 16
11269else
11270xrr 137 2 0
11271ximm 11 18446744069415632640
11272xrr 33 2 11
11273end
11274kfdcmpv 1 57856
11275other = kfdjump 1
11276if eq get xtarget 0 0
11277matconst 16 4293918975
11278e3 2315255808 0 0 16
11279else
11280ximm 11 4293918975
11281xrr 33 0 11
11282end
11283kfdcmpv 0 128
11284render = kfdjump 2
11285kfdpatch other
11286kfdimm 0 7234587703011271727
11287kfdstore 0 4 320
11288kfdimm 0 0
11289kfdstore 0 4 328
11290if eq get xtarget 0 0
11291matconst 0 18446744073709551516
11292mimmed 2432696320 1 31 320
11293mimmed 2432696320 2 31 144
11294matconst 3 0
11295hsys 79
11296else
11297ximm 7 18446744073709551516
11298xmem 141 6 4 320
11299xmem 141 2 4 144
11300ximm 10 0
11301xhcall 262
11302end
11303kfdcmpv 0 0
11304kfdtrap 1
11305kchar add 144 mo
11306kfdload 0 4 add 144 ro 8
11307kfdload 1 4 304 8
11308kfdcmp 0 1
11309kfdtrap 1
11310kfdpatch render
11311if eq get xtarget 0 0
11312spadd 352
11313else
11314xsp 0 352
11315end
11316end
11317fn kchar off ulong to void
11318kfdload 0 4 off 4
11319if eq get xtarget 0 0
11320matconst 16 61440
11321e3 2315255808 0 0 16
11322else
11323ximm 11 61440
11324xrr 33 0 11
11325end
11326kfdcmpv 0 8192
11327kfdtrap 1
11328end
11329
11330fn kring to void
11331kfdload 0 4 32 4
11332kfdcmpv 0 1024
11333kfdtrap 3
11334if eq get xtarget 0 0
11335mimmed 3506438144 1 0 1
11336e3 2315255808 0 0 1
11337else
11338xrr 137 2 0
11339xhsub 2 1
11340xrr 33 0 2
11341end
11342kfdcmpv 0 0
11343kfdtrap 1
11344end
11345fn kshape need ulong sz ulong optional ulong to ulong
11346ret or or need shl sz 8 shl optional 16
11347end
11348fn kxezero q ulong to void
11349if or eq q 3223872576 eq q 3224396870
11350kfdzero 0
11351end
11352if eq q 1082680389
11353kfdzero 0
11354kfdzero 24
11355kfdzero 112
11356end
11357if eq q 1077437513
11358kfdzero 0
11359kfdzero 16
11360end
11361end
11362
11363fn kctl dst ulong x ulong to void
11364harg x 4 8
11365harg x 2 4
11366if ne a_g 77 add x 12 3
11367note d2site 625|kctl: KFD request must be a literal
11368put d2site 0 625
11369fail 9
11370end
11371q = a_g 77 add x 13
11372n = ksize q
11373z = mul div add n 15 16 16
11374e = harray x 1
11375if eq a_g 77 add x 10 3
11376if ne a_g 77 add x 11 n
11377note d2site 626|kctl: literal KFD header length differs from the request ABI size
11378put d2site 0 626
11379fail 9
11380end
11381end
11382a_p 77 add x 23 e
11383a_p 77 add x 24 a_g 77 add x 21
11384a_p 77 add x 25 a_g 77 add x 22
11385a_p 77 add x 26 a_g 77 add x 16
11386a_p 77 add x 27 a_g 77 add x 17
11387span = false
11388if or eq q 3222293268 eq q 3222817548
11389span = true
11390end
11391if or eq q 3222817560 eq q 3222817561
11392span = true
11393end
11394if or eq q 3223872576 eq q 3224396870
11395span = true
11396end
11397f = ulong 0
11398if span
11399if and eq q 3222293268 kapmap
11400harg x 0 9
11401harg x 1 5
11402harg x 3 5
11403else
11404f = harray x 1
11405if eq e f
11406note d2site 627|kctl: KFD header and pointed-to span must be distinct arrays
11407put d2site 0 627
11408fail 19
11409end
11410end
11411end
11412if eq q 3227011842
11413for i ulong 5
11414harg x i 9
11415end
11416end
11417if or eq q 3223866134 eq q 3222293265
11418harg x 0 9
11419end
11420if eq get xtarget 0 0
11421save
11422loadarg 0 1 a_g 77 add x 25
11423else
11424xhbegin
11425xhs 0 a_g 77 add x 25
11426end
11427kfdcmpv 0 n
11428kfdtrap 1
11429if eq get xtarget 0 0
11430basearg 3 e
11431loadarg 16 1 a_g 77 add x 24
11432e3 2332033024 3 3 16
11433mimmed 2432696320 6 31 0
11434spsub add z 176
11435stkchk
11436else
11437xhb 7 e a_g 77 add x 24
11438xsp 1 add z 176
11439end
11440kfdstore 3 4 z
11441for i ulong div n 8
11442kfdload 0 3 mul i 8 8
11443kfdstore 0 4 mul i 8
11444end
11445if span
11446kspan q x f n z
11447end
11448if eq q 1074285333
11449kdrm z
11450end
11451kxezero q
11452if eq q 3227011842
11453kring
11454kbind x 0 0 3 kshape 32 4 0 z
11455note One writable handle named as both write and read pointer selects the AMD AQL queue object:
11456note the compiler binds write_dispatch_id at 56 and read_dispatch_id at 128 and requires all
11457note 2304 bytes of amd_queue_v2_t inside the mapping (CP firmware reads past the 256-byte v1 object
11458note when the caller-owned caps word sets SW_ASYNC_RECLAIM; ROCm amd_hsa_queue.h, MAX_NUM_XCC 128).
11459note Distinct handles keep base-only binding. Both address fields stay zero in the caller's header.
11460if eq get xtarget 0 0
11461karg x 1 0
11462karg x 2 1
11463e3 3942645760 31 0 1
11464else
11465xha x 1 0
11466xha x 2 2
11467xrr 57 0 2
11468end
11469sep = kfdjump 1
11470kfdload 0 4 40 4
11471kfdcmpv 0 2
11472kfdtrap 1
11473wshape = or shl ulong 56 32 shl ulong 2248 48
11474kbind x 1 8 3 or kshape 255 0 0 or 16777216 wshape z
11475rshape = or shl ulong 128 32 shl ulong 2176 48
11476kbind x 2 16 3 or kshape 255 0 0 or 16777216 rshape z
11477kfdpatch sep
11478if eq get xtarget 0 0
11479karg x 1 0
11480karg x 2 1
11481e3 3942645760 31 0 1
11482else
11483xha x 1 0
11484xha x 2 2
11485xrr 57 0 2
11486end
11487obj = kfdjump 0
11488kbind x 1 8 3 kshape 255 8 0 z
11489kbind x 2 16 3 kshape 255 8 0 z
11490kfdpatch obj
11491kbind x 3 56 3 kshape 64 8 1 z
11492kbind x 4 72 3 kshape 80 4 1 z
11493end
11494if eq q 3223866134
11495note USERPTR would smuggle an address through mmap_offset; never admit it.
11496kfdload 0 4 36 4
11497if eq get xtarget 0 0
11498matconst 16 4
11499e3 2315255808 0 0 16
11500else
11501ximm 11 4
11502xrr 33 0 11
11503end
11504kfdcmpv 0 0
11505kfdtrap 1
11506kbind x 0 0 0 kshape 8 8 0 z
11507end
11508if eq q 3222293265
11509kbind x 0 0 0 kshape 255 1 0 z
11510end
11511if eq get xtarget 0 0
11512karg x 9 0
11513matconst 1 q
11514mimmed 2432696320 2 31 0
11515hsys 29
11516else
11517xha x 9 7
11518ximm 6 q
11519xrr 137 2 4
11520xhcall 16
11521end
11522kfdload 3 4 z 8
11523for i ulong div n 8
11524if not kptr q mul i 8
11525kfdload 1 4 mul i 8 8
11526kfdstore 1 3 mul i 8
11527end
11528end
11529if eq get xtarget 0 0
11530spadd add z 176
11531hreturn dst x
11532else
11533xhdone dst x add z 176
11534end
11535end
11536
11537fn hostval c ulong dst ulong to void
11538note A native object takes the OM-2 function-mode host subset below (files, identity, clocks), save,
11539note inline svc, restore, its pushes charged to the object's stack record (spsub). The device words
11540note 166..177 keep error 9: their table lives in the caller's runtime context, which the module linker's
11541note program wrapper does not set up.
11542if and ne get objmode 0 0 and ge c 166 le c 177
11543note d2site 174|hostval: word or declaration in a place that does not allow it; condition if and ne get objmode 0 0 and ge c 166 le c 177
11544put d2site 0 174
11545fail 9
11546end
11547if eq get xtarget 0 1
11548if and ge c 228 le c 232
11549if eq get progmode 0 0
11550note d2site 175|hostval: word or declaration in a place that does not allow it; condition if eq get progmode 0 0
11551put d2site 0 175
11552fail 9
11553end
11554note d2site 176|hostval: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if and ge c 228 le c 232
11555put d2site 0 176
11556fail 25
11557end
11558xhost c dst
11559ret
11560end
11561if ne get xtarget 0 0
11562note d2site 177|hostval: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xtarget 0 0
11563put d2site 0 177
11564fail 25
11565end
11566note target a64efi has no Linux beneath it: every host word is error 25 (the fw words are not host words).
11567if ne get xefa 0 0
11568note d2site 178|hostval: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xefa 0 0
11569put d2site 0 178
11570fail 25
11571end
11572note Function mode (no program image: no argv in x27, no x28 stack floor, no globals) refuses host
11573note words with error 9, except in an OM-2 unit the file and identity subset that needs none of the
11574note image: fclose 100, fopen 110, fstat 117, stat 140, getuid 145, geteuid 146, getgid 147, getegid 148,
11575note lstat 149 (OMEGESE.md 10, spec/omegese-om2.md); the clocks monons 109, realns 130 and sleepns 120;
11576note and the device subset devctl 166, mapnew 167, mapdrop 168, mapread 169, mapwrite 170, devcall 171,
11577note uvmctl 172, mapaddr 173, mapget 174, mapset 175, maphold 176 and mapbind 177. Fixed replacement
11578note is only over a whole live PROT_NONE reservation owned by this table. Each is save, inline svc,
11579note restore; x7 and x19..x28 are never written. Function-mode table entry31 points at a 32-byte
11580note header (capacity1..4098, generation base, generation limit, reserved) then capacity32-byte slots.
11581note Handles use13slot bits; program mode retains its raw128slots and8slot-bit handles.
11582if eq get progmode 0 0
11583if eq get om2 0 0
11584note d2site 179|hostval: word or declaration in a place that does not allow it; condition if eq get om2 0 0
11585put d2site 0 179
11586fail 9
11587end
11588ok = ulong 0
11589if or or eq c 100 eq c 110 or eq c 117 eq c 140
11590ok = ulong 1
11591end
11592if and ge c 145 le c 149
11593ok = ulong 1
11594end
11595if or or eq c 109 eq c 120 eq c 130
11596ok = ulong 1
11597end
11598if and ge c 166 le c 177
11599ok = ulong 1
11600end
11601if eq ok 0
11602note d2site 180|hostval: word or declaration in a place that does not allow it; condition if eq ok 0
11603put d2site 0 180
11604fail 9
11605end
11606end
11607eff_rec c
11608x = mul get depth 0 32
11609put a_ar add get a_rb 77 add x 7 get nslot 0
11610if and ge c 241 le c 243
11611mtinit
11612if eq c 241
11613kctl dst x
11614else
11615mnew c dst x
11616end
11617ret
11618end
11619note VFIO words are program-only. These IDs are disjoint from efi178, qty223 and peername224.
11620if and ge c 228 le c 232
11621if eq get fdtab 0 0
11622fdpool = get poolb 0
11623if gt fdpool 1073739776
11624note d2site 181|hostval: size capacity; condition if gt fdpool 1073739776
11625put d2site 0 181
11626fail 23
11627end
11628put fdtab 0 add 276824064 fdpool
11629put poolb 0 add fdpool 2048
11630end
11631if eq c 228
11632note VFIO container, group and device requests: _IO(';', 100 + k) from linux/vfio.h, exact allowlist and
11633note shapes. GET_API_VERSION 15204 takes no argument (n 0). DEVICE_RESET 15215 is not allowed: W0 never
11634note resets the device from Omega (Drake: W0a only, no FLR). CHECK_EXTENSION 15205 and
11635note SET_IOMMU 15206 pass the 4-byte little-endian value in the span; SET_IOMMU accepts only TYPE1v2 (3).
11636note GROUP_SET_CONTAINER 15208 points at a 4-byte fd. GROUP_GET_STATUS 15207 (8), DEVICE_GET_INFO 15211
11637note (24) and DEVICE_GET_REGION_INFO 15212 (32) point at the span after the compiler itself stores
11638note argsz = n, so the kernel copies at most n bytes. GROUP_GET_DEVICE_FD 15210 passes a private zero-
11639note terminated copy of a non-empty span (at most 4095 bytes, no embedded zero).
11640note IOMMU_MAP_DMA 15217 (32) takes an Omega mapping handle in the vaddr field (bytes 8..15), never an
11641note address: the compiler checks the handle like mapget, requires a read/write mapping and flags exactly
11642note READ|WRITE (3), then stores the mapping's own base address and whole length into vaddr and size.
11643note The caller chooses only the IOVA (bytes 16..23). IOMMU_UNMAP_DMA 15218 (24) requires flags 0 (no
11644note dirty bitmap, no ALL, no VADDR) and unmaps only the caller's IOVA range in its own container.
11645mtinit
11646harg x 4 8
11647harg x 2 4
11648if ne get a_ar add get a_rb 77 add x 12 3
11649note d2site 182|hostval: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 12 3
11650put d2site 0 182
11651fail 9
11652end
11653q = get a_ar add get a_rb 77 add x 13
11654if eq q 15210
11655e = harray x 0
11656hpathcp x
11657emit 4043309247
11658trapc 0 3
11659fdscan 0
11660mimmed 4043309056 31 12 0
11661fdfound = mbranch 1
11662matconst 0 18446744073709551592
11663full = get oc 0
11664emit 335544320
11665patch19 fdfound get oc 0
11666hload x 4 3
11667hcopy
11668e3 2852126720 0 31 3
11669e3 2852126720 2 31 1
11670matconst 1 15210
11671hsys 29
11672fdrecord 1
11673spadd 4096
11674patch26 full get oc 0
11675hreturn dst x
11676ret
11677end
11678n = ulong 99
11679if eq q 15204
11680n = ulong 0
11681end
11682if or or eq q 15205 eq q 15206 eq q 15208
11683n = ulong 4
11684end
11685if eq q 15207
11686n = ulong 8
11687end
11688if eq q 15211
11689n = ulong 24
11690end
11691if eq q 15212
11692n = ulong 32
11693end
11694if eq q 15217
11695n = ulong 32
11696end
11697if eq q 15218
11698n = ulong 24
11699end
11700if eq n 99
11701note d2site 183|hostval: word or declaration in a place that does not allow it; condition if eq n 99
11702put d2site 0 183
11703fail 9
11704end
11705put a_ar add get a_rb 77 add x 23 n
11706e = harray x 1
11707t = alloc
11708matconst t get a_ar add get a_rb 77 add x 23
11709e3 3942645760 31 get a_ar add get a_rb 77 add x 22 t
11710trapc 1 3
11711save
11712hload x 4 0
11713matconst 1 q
11714basearg 2 e
11715loadarg 16 1 get a_ar add get a_rb 77 add x 21
11716e3 2332033024 2 2 16
11717if ge n 8
11718matconst 16 n
11719mimmed 3103784960 16 2 0
11720end
11721if eq q 15217
11722mimmed 3107979264 15 2 1
11723mimmed 4043309056 31 15 3
11724trapc 1 3
11725mload 10 2 1
11726mcheck
11727mload 15 11 3
11728mimmed 4043309056 31 15 3
11729trapc 1 3
11730mstore 13 2 1
11731mstore 12 2 3
11732end
11733if eq q 15218
11734mimmed 3107979264 15 2 1
11735mimmed 4043309056 31 15 0
11736trapc 1 3
11737end
11738if or eq q 15205 eq q 15206
11739mimmed 3107979264 2 2 0
11740end
11741if eq q 15206
11742mimmed 4043309056 31 2 3
11743trapc 1 3
11744end
11745if eq n 0
11746matconst 2 0
11747end
11748hsys 29
11749hreturn dst x
11750end
11751if or eq c 229 eq c 230
11752mtinit
11753mnew c dst x
11754end
11755if eq c 231
11756note Fixed eventfd flags: CLOEXEC prevents exec leakage; NONBLOCK makes drained reads safe.
11757harg x 0 4
11758save
11759fdscan 0
11760mimmed 4043309056 31 12 0
11761fdfound = mbranch 1
11762matconst 0 18446744073709551592
11763full = get oc 0
11764emit 335544320
11765patch19 fdfound get oc 0
11766hload x 0 0
11767matconst 1 526336
11768hsys 19
11769fdrecord 2
11770patch26 full get oc 0
11771hreturn dst x
11772end
11773if eq c 232
11774note GET_IRQ_INFO and SET_IRQS only; caller bytes cannot introduce pointers or arbitrary ioctls.
11775harg x 4 8
11776harg x 2 4
11777if ne get a_ar add get a_rb 77 add x 12 3
11778note d2site 184|hostval: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 12 3
11779put d2site 0 184
11780fail 9
11781end
11782q = get a_ar add get a_rb 77 add x 13
11783if and ne q 15213 ne q 15214
11784note d2site 185|hostval: word or declaration in a place that does not allow it; condition if and ne q 15213 ne q 15214
11785put d2site 0 185
11786fail 9
11787end
11788e = harray x 1
11789save
11790hload x 4 10
11791fdcheck 1
11792basearg 2 e
11793loadarg 16 1 get a_ar add get a_rb 77 add x 21
11794e3 2332033024 2 2 16
11795loadarg 3 1 get a_ar add get a_rb 77 add x 22
11796if eq q 15213
11797mimmed 4043309056 31 3 16
11798trapc 1 3
11799else
11800mimmed 4043309056 31 3 20
11801trapc 3 3
11802mimmed 4043309056 31 3 276
11803trapc 8 3
11804end
11805mimmed 3107979264 4 2 0
11806e3 3942645760 31 4 3
11807trapc 1 3
11808if eq q 15214
11809mimmed 3107979264 5 2 4
11810mimmed 4043309056 31 5 64
11811trapc 8 3
11812mimmed 3107979264 6 2 3
11813matconst 7 4294967295
11814e3 3405774848 7 7 5
11815e3 3942645760 31 6 7
11816trapc 8 3
11817mimmed 3107979264 4 2 1
11818mimmed 4043309056 31 4 36
11819event = mbranch 0
11820mimmed 4043309056 31 3 20
11821trapc 1 3
11822mimmed 4043309056 31 4 33
11823disable = mbranch 0
11824note DATA_NONE MASK or UNMASK. Linux checks the device's MASKABLE capability.
11825mimmed 4043309056 31 4 9
11826mask = mbranch 0
11827mimmed 4043309056 31 4 17
11828trapc 1 3
11829patch19 mask get oc 0
11830mimmed 4043309056 31 5 0
11831trapc 0 3
11832done = get oc 0
11833emit 335544320
11834patch19 disable get oc 0
11835mimmed 4043309056 31 5 0
11836trapc 1 3
11837mimmed 4043309056 31 6 0
11838trapc 1 3
11839disdone = get oc 0
11840emit 335544320
11841patch19 event get oc 0
11842mimmed 4043309056 31 5 0
11843trapc 0 3
11844matconst 7 4
11845e3 2600500224 7 5 7
11846mimmed 2432696320 7 7 20
11847e3 3942645760 31 7 3
11848trapc 1 3
11849mimmed 2432696320 6 2 20
11850head = get oc 0
11851mimmed 3107979264 10 6 0
11852matconst 7 4294967295
11853e3 3942645760 31 10 7
11854skip = mbranch 0
11855fdcheck 2
11856patch19 skip get oc 0
11857mimmed 2432696320 6 6 4
11858mimmed 3506438144 5 5 1
11859mimmed 4043309056 31 5 0
11860again = mbranch 1
11861patch19 again head
11862patch26 done get oc 0
11863patch26 disdone get oc 0
11864end
11865hload x 4 0
11866matconst 1 q
11867hsys 29
11868hreturn dst x
11869end
11870ret
11871end
11872if eq c 197
11873hscalar c dst x
11874ret
11875end
11876note execpure 198 and execenv 233 are dispatched here, before the ge c 173 mapped-memory range below
11877note would claim them.
11878if or eq c 198 eq c 233
11879hpack c dst x
11880ret
11881end
11882if eq c 220
11883hpeercr dst x
11884ret
11885end
11886if eq c 235
11887hprlim dst x
11888ret
11889end
11890if and ge c 236 le c 238
11891hsched c dst x
11892ret
11893end
11894if or eq c 239 eq c 240
11895hscalar c dst x
11896ret
11897end
11898if eq c 221
11899hpollfds dst x
11900ret
11901end
11902if eq c 222
11903hsendmsg dst x
11904ret
11905end
11906if eq c 224
11907hbuffer c dst x
11908ret
11909end
11910if eq c 176
11911mtinit
11912mnew c dst x
11913ret
11914end
11915if eq c 177
11916mtinit
11917mbind dst x
11918ret
11919end
11920if ge c 173
11921mtinit
11922mmapio c dst x
11923ret
11924end
11925if eq c 172
11926note Linux UVM has unencoded commands. Exact allowlist and ABI580.173.02 byte sizes.
11927put a_ar add get a_rb 77 add x 23 xhreq 172 x
11928e = harray x 1
11929t = alloc
11930matconst t get a_ar add get a_rb 77 add x 23
11931e3 3942645760 31 get a_ar add get a_rb 77 add x 22 t
11932trapc 1 3
11933save
11934hload x 4 0
11935hload x 2 1
11936basearg 2 e
11937loadarg 16 1 get a_ar add get a_rb 77 add x 21
11938e3 2332033024 2 2 16
11939hsys 29
11940hreturn dst x
11941ret
11942end
11943if eq c 171
11944hdevcall dst x
11945ret
11946end
11947if ge c 167
11948mtinit
11949if eq c 167
11950mnew c dst x
11951ret
11952end
11953if eq c 168
11954harg x 0 9
11955save
11956hload x 0 10
11957mcheck
11958e3 2852126720 0 31 13
11959e3 2852126720 1 31 12
11960hsys 215
11961mimmed 4043309056 31 0 0
11962failed = mbranch 1
11963mstore 31 11 0
11964mstore 31 11 1
11965mstore 31 11 3
11966patch19 failed get oc 0
11967hreturn dst x
11968ret
11969end
11970mcopy c dst x
11971ret
11972end
11973if eq c 166
11974note Same bounded ioctl contract as L605 src/device/omc.om at 0dee699.
11975note Compose with native host words instead of maintaining a second compiler.
11976note Only literal FIONREAD, encoded read/write NVRM F, or five exact aien-gpu ABI1 A requests.
11977put a_ar add get a_rb 77 add x 23 xhreq 166 x
11978e = harray x 1
11979t = alloc
11980matconst t get a_ar add get a_rb 77 add x 23
11981e3 3942645760 31 get a_ar add get a_rb 77 add x 22 t
11982trapc 1 3
11983save
11984hload x 4 0
11985hload x 2 1
11986basearg 2 e
11987loadarg 16 1 get a_ar add get a_rb 77 add x 21
11988e3 2332033024 2 2 16
11989hsys 29
11990hreturn dst x
11991ret
11992end
11993if eq c 132
11994e = harray x 1
11995save
11996basearg 0 e
11997loadarg 16 1 get a_ar add get a_rb 77 add x 21
11998e3 2332033024 0 0 16
11999loadarg 1 1 get a_ar add get a_rb 77 add x 22
12000hsys 17
12001hreturn dst x
12002ret
12003end
12004if eq c 133
12005hreadlnk dst x
12006ret
12007end
12008if eq c 134
12009hsockopt dst x
12010ret
12011end
12012if eq c 135
12013note random A off n flags: Linux getrandom into a writable byte slice. Returns the bytes written or
12014note minus the Linux error number. flags follows getrandom(2): 0 blocks until the pool is ready,
12015note 1 (GRND_NONBLOCK) returns -EAGAIN instead, 2 (GRND_INSECURE) may return non-cryptographic bytes.
12016e = harray x 1
12017harg x 2 8
12018save
12019basearg 0 e
12020loadarg 16 1 get a_ar add get a_rb 77 add x 21
12021e3 2332033024 0 0 16
12022loadarg 1 1 get a_ar add get a_rb 77 add x 22
12023hload x 2 2
12024hsys 278
12025hreturn dst x
12026ret
12027end
12028if or eq c 109 eq c 130
12029hclock c dst x
12030ret
12031end
12032if or and ge c 113 le c 119 eq c 131
12033hbuffer c dst x
12034ret
12035end
12036if eq c 120
12037harg x 0 9
12038save
12039hload x 0 2
12040emit 4043309151
12041trapc 11 3
12042spsub 16
12043stkchk
12044matconst 3 1000000000
12045e3 2596276224 4 2 3
12046note MSUB x5,x4,x3,x2 gives the subsecond remainder.
12047emit 2600700037
12048emit 4177527780
12049emit 4177528805
12050emit 2432697312
12051matconst 1 0
12052hsys 101
12053spadd 16
12054hreturn dst x
12055ret
12056end
12057if eq c 123
12058hwaitio dst x
12059ret
12060end
12061if or or or eq c 124 eq c 125 eq c 141 eq c 142
12062hpack c dst x
12063ret
12064end
12065if or or or or or or eq c 126 eq c 138 eq c 143 eq c 144 eq c 150 eq c 151 eq c 157
12066hpath c dst x
12067ret
12068end
12069if eq c 140
12070hstat 140 dst x
12071ret
12072end
12073if eq c 149
12074hstat 149 dst x
12075ret
12076end
12077if and ge c 145 le c 148
12078hscalar c dst x
12079ret
12080end
12081if or or or eq c 153 eq c 154 eq c 155 eq c 156
12082hscalar c dst x
12083ret
12084end
12085if and ge c 158 le c 160
12086hscalar c dst x
12087ret
12088end
12089if or eq c 161 eq c 162
12090hpread c dst x
12091ret
12092end
12093if and ge c 163 le c 165
12094hscalar c dst x
12095ret
12096end
12097if or or eq c 127 eq c 129 eq c 139
12098hscalar c dst x
12099ret
12100end
12101if eq c 128
12102e = harray x 1
12103harg x 2 8
12104tmp = alloc
12105matconst tmp 8
12106e3 3942645760 31 get a_ar add get a_rb 77 add x 22 tmp
12107trapc 3 3
12108save
12109basearg 0 e
12110loadarg 16 1 get a_ar add get a_rb 77 add x 21
12111e3 2332033024 0 0 16
12112hload x 2 1
12113hsys 59
12114hreturn dst x
12115ret
12116end
12117if ge c 121
12118put hostargs 0 1
12119hargs c dst x
12120ret
12121end
12122if ge c 110
12123hpath c dst x
12124ret
12125end
12126hscalar c dst x
12127end
12128
12129note ======== rdval: read one value (om4 VAL, VALTOK, CALL and the VT_ parts, one self-recursive
12130note function because a function calls only earlier functions or itself) ========
12131note mode 0: read the first word; 1: the first word is the current token; 2: a call of function fe (index
12132note + 1), its arguments still to read. exp the expected type (0 none), dst the destination register (255
12133note none). Out: rk kind (1 register, 2 bare number, 3 typed number, 4 flags, 9 a float in a twin, only when
12134note asked for by fpw), rv register / number / condition, rt type (for a bare number: 1 when written as 2^63
12135note or more). Only the outermost op writes the destination. Every value nests one level deeper (at most
12136note 32768, bounded by omc's own stack, error 14); a call does not.
12137fn rdval mode ulong exp ulong dst ulong fe ulong to void
12138note fwtake: rdval's entry: keep the caller's fpw request for this depth (none on x86, which has no twins)
12139if eq get xtarget 0 0
12140a_p 78 add get depth 0 1 get fpw 0
12141else
12142put a_ar add get a_rb 78 add get depth 0 1 0
12143end
12144put fpw 0 0
12145put dexp 0 1
12146if eq mode 2
12147if ne get cpure 0 0
12148note d2site 186|rdval: contract syntax misplaced or not supported here (IR mode included); condition if ne get cpure 0 0
12149put d2site 0 186
12150fail 30
12151end
12152if ne get om2 0 0
12153if ne uchar get a_ar add get a_rb 27 sub fe 1 0
12154inl_call fe dst
12155ret
12156end
12157end
12158cb = add mul get depth 0 32 8
12159a_p 77 add cb 18 ulong a_gu 24 sub fe 1
12160put a_ar add get a_rb 77 add cb 19 get nslot 0
12161if eq get progmode 0 0
12162if eq get curfn 0 fe
12163note d2site 187|rdval: word or declaration in a place that does not allow it; condition if eq get curfn 0 fe
12164put d2site 0 187
12165fail 9
12166end
12167end
12168i = ulong 0
12169while lt i get a_ar add get a_rb 77 add cb 18
12170p = add mul sub fe 1 6 i
12171if eq uchar get a_ar add get a_rb 37 p 0
12172if ne isfloat ulong uchar get a_ar add get a_rb 35 p 0
12173put fpw 0 1
12174end
12175rdval 0 ulong uchar get a_ar add get a_rb 35 p 255 0
12176ca_scal p add cb mul i 3
12177else
12178if ge uchar get a_ar add get a_rb 37 p 6
12179ca_st fe i cb
12180else
12181ca_arr fe i cb
12182fz_arg get rt 0
12183end
12184end
12185i = add i 1
12186end
12187ca_end fe dst cb
12188ret
12189end
12190if eq mode 0
12191tok
12192end
12193if ne get cpure 0 0
12194cp_token
12195end
12196put depth 0 add get depth 0 1
12197note value nesting: the per-depth cells (fr, fwv, ul_k, ul_v) are arena group 18 and grow. What bounds the
12198note depth is omc's own stack: rdval recurses once per level, and omc, a program, has the fixed 8 MiB stack
12199note pool of program mode (OMEGESE 9.6); past it omc would trap 6 with no line. Measured 2026-11-11 (omc
12200note b985535d): the deepest frame per level is 144 bytes (nested calls; 64 for get, 80 for and, 96 in IR
12201note mode), trap 6 from 58252 nested calls. Allowing 256 bytes per level, 8388608 / 256 = 32768 levels is
12202note the deepest value omc reads; deeper is error 14 on its line, a clean refusal before the stack ends.
12203note seed/omc/gate-nocaps.sh compiles every measured shape at 32768 deep, so a frame that grows is noticed.
12204if gt get depth 0 32768
12205note d2site 188|rdval: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if gt get depth 0 32768
12206put d2site 0 188
12207fail 14
12208end
12209if ge add get depth 0 1 get a_gp 18
12210a_need 18 add get depth 0 1
12211end
12212if or eq get tk 0 0 eq get tk 0 3
12213note d2site 189|rdval: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3
12214put d2site 0 189
12215fail 4
12216end
12217if eq get tk 0 4
12218note d2site 190|rdval: syntax: unknown or misplaced word; condition if eq get tk 0 4
12219put d2site 0 190
12220fail 16
12221end
12222if eq get tk 0 5
12223if ne get irmode 0 0
12224note d2site 191|rdval: word or declaration in a place that does not allow it; condition if ne get irmode 0 0
12225put d2site 0 191
12226fail 9
12227end
12228if ge exp 64
12229note d2site 192|rdval: type mismatch; condition if ge exp 64
12230put d2site 0 192
12231fail 7
12232end
12233fparse get ts 0 get tl 0
12234t = ulong 0
12235if eq get fsuf 0 0
12236if eq exp 0
12237vdone 6 add mul get ts 0 4294967296 get tl 0 ulong 0
12238ret
12239end
12240if eq isfloat exp 0
12241note d2site 193|rdval: type mismatch; condition if eq isfloat exp 0
12242put d2site 0 193
12243fail 7
12244end
12245t = exp
12246else
12247t = ulong 10
12248if eq get fsuf 0 2
12249t = ulong 11
12250end
12251if and ne exp 0 ne exp t
12252note d2site 194|rdval: type mismatch; condition if and ne exp 0 ne exp t
12253put d2site 0 194
12254fail 7
12255end
12256end
12257v = fbits t
12258vdone 7 v t
12259ret
12260end
12261if eq get tk 0 2
12262if eq exp 0
12263vdone 2 get tw 0 get tbig 0
12264ret
12265end
12266note an integer literal where a float is expected is the mixing OMEGESE 9.9 refuses (error 7); before
12267note this it was stored as raw bits (f64 x = 1 held 0x1). The conversion f64 1 reads it with exp 0.
12268if or ge exp 64 ne isfloat exp 0
12269note d2site 195|rdval: type mismatch; condition if or ge exp 64 ne isfloat exp 0
12270put d2site 0 195
12271fail 7
12272end
12273range get tw 0 exp get tbig 0
12274vdone 3 get tw 0 exp
12275ret
12276end
12277if gt get tl 0 8
12278f = findfn get tw 0 get tl 0 get ts 0
12279if eq f 0
12280if gt get tl 0 63
12281note d2site 196|rdval: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
12282put d2site 0 196
12283unkfail 13
12284end
12285else
12286if eq uchar get a_ar add get a_rb 23 sub f 1 12
12287note d2site 197|rdval: type mismatch; condition if eq uchar get a_ar add get a_rb 23 sub f 1 12
12288put d2site 0 197
12289fail 7
12290end
12291rdval 2 0 dst f
12292vdec
12293ret
12294end
12295end
12296c = kw get tw 0
12297if ne get xefa 0 0
12298ca = kwa get tw 0
12299if eq ca 178
12300eff_rec 178
12301aefival dst
12302ret
12303end
12304if ne ca 0
12305eff_rec ca
12306afw ca dst
12307ret
12308end
12309end
12310if eq c 178
12311eff_rec 178
12312xefival dst
12313ret
12314end
12315if eq c 0
12316if ne get cpure 0 0
12317if eq get tw 0 128009175786866
12318if eq get crkind 0 0
12319note d2site 198|rdval: contract syntax misplaced or not supported here (IR mode included); condition if eq get crkind 0 0
12320put d2site 0 198
12321fail 30
12322end
12323vdone get crkind 0 get crval 0 get crtype 0
12324ret
12325end
12326end
12327e = findname get tw 0
12328if ne e 0
12329if eq uchar get a_ar add get a_rb 7 sub e 1 9
12330ct = ulong uchar get a_ar add get a_rb 5 sub e 1
12331cv = get a_ar add get a_rb 8 sub e 1
12332if ne isfloat ct 0
12333vdone 7 cv ct
12334else
12335vdone 3 cv ct
12336end
12337ret
12338end
12339if ne uchar get a_ar add get a_rb 7 sub e 1 0
12340note d2site 199|rdval: type mismatch; condition if ne uchar get a_ar add get a_rb 7 sub e 1 0
12341put d2site 0 199
12342fail 7
12343end
12344e1 = sub e 1
12345if ne uchar get a_ar add get a_rb 9 e1 0
12346nr = ulong uchar get a_ar add get a_rb 4 e1
12347if ne a_g 78 get depth 0 0
12348vdone 9 nr ulong uchar get a_ar add get a_rb 5 e1
12349else
12350fv2x ulong a_gu 5 e1 vtw nr nr
12351vdone 1 nr ulong uchar get a_ar add get a_rb 5 e1
12352end
12353else
12354vdone 1 ulong a_gu 4 e1 ulong a_gu 5 e1
12355end
12356if ne get cpure 0 0
12357if ge get rt 0 10
12358note d2site 200|rdval: contract syntax misplaced or not supported here (IR mode included); condition if ge get rt 0 10
12359put d2site 0 200
12360fail 30
12361end
12362end
12363ret
12364end
12365f = findfn get tw 0 0 0
12366if eq f 0
12367note d2site 201|rdval: unknown name or field, or a word this mode does not provide; condition if eq f 0
12368put d2site 0 201
12369unkfail 3
12370end
12371if eq uchar get a_ar add get a_rb 23 sub f 1 12
12372note d2site 202|rdval: type mismatch; condition if eq uchar get a_ar add get a_rb 23 sub f 1 12
12373put d2site 0 202
12374fail 7
12375end
12376rdval 2 0 dst f
12377vdec
12378ret
12379end
12380if or eq c 88 eq c 89
12381t = ulong 10
12382if eq c 89
12383t = ulong 11
12384end
12385rdval 0 0 255 0
12386if ge get rt 0 64
12387note d2site 203|rdval: type mismatch; condition if ge get rt 0 64
12388put d2site 0 203
12389fail 7
12390end
12391if eq get rk 0 6
12392v = fspan t get rv 0
12393put rk 0 7
12394put rv 0 v
12395put rt 0 t
12396end
12397if eq get rk 0 2
12398range get rv 0 9 get tbig 0
12399put rk 0 3
12400put rt 0 9
12401end
12402if eq get rt 0 1
12403note d2site 204|rdval: type mismatch; condition if eq get rt 0 1
12404put d2site 0 204
12405fail 7
12406end
12407fwreq
12408vt_conv t
12409vdec
12410ret
12411end
12412if eq c 90
12413if ne get irmode 0 0
12414note d2site 205|rdval: word or declaration in a place that does not allow it; condition if ne get irmode 0 0
12415put d2site 0 205
12416fail 9
12417end
12418tt = typeword
12419rdval 0 0 255 0
12420if or eq get rk 0 6 eq get rk 0 2
12421note d2site 206|rdval: bare number without a type from its context; condition if or eq get rk 0 6 eq get rk 0 2
12422put d2site 0 206
12423fail 11
12424end
12425ft = get rt 0
12426if eq ft 1
12427note d2site 207|rdval: type mismatch; condition if eq ft 1
12428put d2site 0 207
12429fail 7
12430end
12431if or ge ft 64 ge tt 64
12432note d2site 208|rdval: type mismatch; condition if or ge ft 64 ge tt 64
12433put d2site 0 208
12434fail 7
12435end
12436if ne twid ft twid tt
12437note d2site 209|rdval: type mismatch; condition if ne twid ft twid tt
12438put d2site 0 209
12439fail 7
12440end
12441r = matreg get rk 0 get rv 0 ft
12442note A register holds an 8/16/32-bit unsigned value and an f32 zero-extended (canon, FMOV W) and a signed
12443note one sign-extended, so a bitcast that changes the extension extends the bits again for tt, into a new
12444note register (a name's register keeps its value). f32 takes the uint form.
12445if ne twid tt 64
12446if ne and ge ft 6 le ft 8 and ge tt 6 le tt 8
12447ct = tt
12448if eq tt 10
12449ct = ulong 4
12450end
12451rd = destreg dst
12452canonto rd r ct
12453r = rd
12454end
12455end
12456put rk 0 1
12457put rv 0 r
12458put rt 0 tt
12459vdec
12460ret
12461end
12462if or or or eq c 91 eq c 92 eq c 93 eq c 94
12463fwreq
12464if or eq c 91 eq c 92
12465fintr c dst
12466else
12467fminmax c dst
12468end
12469ret
12470end
12471if eq c 227
12472fwreq
12473ffma dst
12474ret
12475end
12476if eq c 95
12477fsizeof dst
12478ret
12479end
12480if eq c 96
12481foffset dst
12482ret
12483end
12484if le sub c 1 8
12485tok
12486if eq get tk 0 2
12487range get tw 0 c get tbig 0
12488vdone 3 get tw 0 c
12489ret
12490end
12491rdval 1 0 255 0
12492if ge get rt 0 64
12493note d2site 210|rdval: type mismatch; condition if ge get rt 0 64
12494put d2site 0 210
12495fail 7
12496end
12497if eq get rk 0 2
12498note d2site 211|rdval: bare number without a type from its context; condition if eq get rk 0 2
12499put d2site 0 211
12500fail 11
12501end
12502vt_conv c
12503vdec
12504ret
12505end
12506if eq c 223
12507tok
12508if eq get tk 0 2
12509range get tw 0 13 get tbig 0
12510vdone 3 get tw 0 13
12511ret
12512end
12513rdval 1 0 255 0
12514if eq get rk 0 6
12515note d2site 212|rdval: type mismatch; condition if eq get rk 0 6
12516put d2site 0 212
12517fail 7
12518end
12519if ge get rt 0 64
12520note d2site 213|rdval: type mismatch; condition if ge get rt 0 64
12521put d2site 0 213
12522fail 7
12523end
12524if eq get rk 0 2
12525note d2site 214|rdval: bare number without a type from its context; condition if eq get rk 0 2
12526put d2site 0 214
12527fail 11
12528end
12529vt_conv 13
12530vdec
12531ret
12532end
12533if eq c 74
12534put fpw 0 a_g 78 get depth 0
12535rdval 0 exp dst 0
12536tok
12537if ne get tk 0 1
12538note d2site 215|rdval: syntax: unknown or misplaced word; condition if ne get tk 0 1
12539put d2site 0 215
12540fail 16
12541end
12542if gt get tl 0 8
12543note d2site 216|rdval: syntax: unknown or misplaced word; condition if gt get tl 0 8
12544put d2site 0 216
12545fail 16
12546end
12547if ne kw get tw 0 75
12548note d2site 217|rdval: syntax: unknown or misplaced word; condition if ne kw get tw 0 75
12549put d2site 0 217
12550fail 16
12551end
12552vdec
12553ret
12554end
12555if or eq c 77 eq c 193
12556note d2site 218|rdval: word or declaration in a place that does not allow it; condition if or eq c 77 eq c 193
12557put d2site 0 218
12558fail 9
12559end
12560if or eq c 225 eq c 226
12561if or eq get progmode 0 0 ne get irmode 0 0
12562note d2site 219|rdval: word or declaration in a place that does not allow it; condition if or eq get progmode 0 0 ne get irmode 0 0
12563put d2site 0 219
12564fail 9
12565end
12566x = mul get depth 0 32
12567sl = get nslot 0
12568note dit and scrub are emitted inline here, not in helper functions: om4 holds 512 functions and omc.om
12569note uses 511 of them (seed/omc/size-history.tsv).
12570if eq c 225
12571note dit: OM-2 `dit v` (program mode): v is int, 0 or 1, else trap 3. Sets PSTATE.DIT (Arm ARM
12572note C5.2.4: DIT is bit 24 of the special-purpose register; MRS/MSR <Xt>, DIT have op0 3, op1 3, CRn 4,
12573note CRm 2, op2 5) and gives the previous bit as a long 0 or 1. CMP Xv, #1 = SUBS XZR (C6.2.464); B.HI
12574note trap 3; LSL X16, Xv, #24 = UBFM X16, Xv, #40, #39 (C6.2.487), taken before the destination is
12575note written because the destination may be v's own register; MRS Xd, DIT (C6.2.287); MSR DIT, X16
12576note (C6.2.289); UBFX Xd, Xd, #24, #1 = UBFM Xd, Xd, #24, #24. Writes to PSTATE are in program order
12577note without further synchronization (C5.1), so the next instruction already runs under the new bit.
12578harg x 0 8
12579r = matreg a_g 77 add x 8 a_g 77 add x 9 8
12580emit or 4043310111 shl r 5
12581trapc 8 3
12582emit or 3546848272 shl r 5
12583put nslot 0 sl
12584d = destreg dst
12585emit or 3577430688 d
12586emit 3575333552
12587emit or or 3545784320 shl d 5 d
12588vdone 1 d 9
12589ret
12590end
12591note scrub: OM-2 `scrub n` (program mode): n is ulong, a multiple of 16 and at most 1048576, else trap 3.
12592note TST Xn, #15 = ANDS XZR (C6.2.16, N 1 immr 0 imms 3); B.NE trap 3; X16 = 1048576; CMP Xn, X16 =
12593note SUBS XZR (C6.2.465); B.HI trap 3. X16 = SP - n: SUB X16, SP, Xn, UXTX (C6.2.456); CMP X16, X28
12594note (C6.2.465); B.LO trap 6, before any store. Loop: CMP SP, X16 = SUBS XZR, SP, X16, UXTX (C6.2.463);
12595note B.LS out; STP XZR, XZR, [X16], #16 (C6.2.414, post-index); B back (C6.2.35). Then MOVZ Xr, #0
12596note (C6.2.319) for every pool register at index npar + nslot or above (no live value: parameters,
12597note locals and the held parts of the expression sit below), X16, and X7, X18-X26, X29, which program
12598note mode never names; then MOVI Vd.2D, #0 (C7.2.247) for V0-V15 and for every twin V16+j except those
12599note of a live slot j (below npar + nslot) whose value lives in its twin (vsl: an f32/f64 local name or a
12600note held kind 9 float, as save stores it); a twin of a free slot or of a slot whose value is in its x
12601note register holds nothing live. V0-V15 carry a float only inside one operation. Never touched: SP, X27
12602note (the Linux initial stack under args), X28 (the stack floor), X30 (the return address), the live pool
12603note registers and live twins, NZCV, FPCR, FPSR, and the SVE P registers and FFR. Gives long 0. Pinned
12604note registers (OM-2 global bases and lengths among X18..X26, pinset) are cleared with the rest, then set
12605note back to their public constant values (pinlo), since later element accesses read them.
12606harg x 0 5
12607r = matreg a_g 77 add x 8 a_g 77 add x 9 5
12608emit or 4064283679 shl r 5
12609trapc 1 3
12610matconst 16 1048576
12611emit or 3943694367 shl r 5
12612trapc 8 3
12613emit or 3407897584 shl r 16
12614emit 3944481311
12615trapc 3 6
12616top = get oc 0
12617emit 3945817087
12618at = get oc 0
12619emit 1409286153
12620emit 2827058719
12621back top
12622patch19 at get oc 0
12623i = add get npar 0 sl
12624while lt i 16
12625emit or 3531603968 poolc i
12626i = add i 1
12627end
12628emit 3531603984
12629emit 3531603975
12630note under target a64efi X18 is the platform's (UEFI 2.10 2.3.6): scrub leaves it and clears X19..X26
12631i = add 18 get xefa 0
12632while le i 26
12633emit or 3531603968 i
12634i = add i 1
12635end
12636emit 3531603997
12637at = add get npar 0 sl
12638i = ulong 0
12639while lt i 32
12640top = and i 15
12641r = ulong get vsl top
12642if or lt i 16 ge top at
12643r = ulong 0
12644end
12645if eq r 0
12646emit or 1862329344 i
12647end
12648i = add i 1
12649end
12650pinlo
12651put nslot 0 sl
12652d = destreg dst
12653matconst d 0
12654vdone 1 d 9
12655ret
12656end
12657if or or and ge c 100 le c 177 and ge c 197 le c 198 and ge c 220 le c 222
12658hostval c dst
12659ret
12660end
12661if eq c 224
12662hostval c dst
12663ret
12664end
12665if or or and ge c 228 le c 232 or eq c 233 eq c 235 and ge c 236 le c 243
12666hostval c dst
12667ret
12668end
12669if eq c 186
12670rdval 0 0 255 0
12671ab_open
12672vdec
12673ret
12674end
12675if eq c 185
12676ab_seal
12677vdec
12678ret
12679end
12680if eq c 51
12681e = arrname 1
12682if ge uchar get a_ar add get a_rb 7 sub e 1 6
12683if ne uchar get a_ar add get a_rb 7 sub e 1 10
12684vt_fget e dst
12685vdec
12686ret
12687end
12688end
12689if ne ly_get e dst 0
12690vdec
12691ret
12692end
12693rdval 0 5 255 0
12694fz_get e
12695fwreq
12696vt_get e dst
12697vdec
12698ret
12699end
12700if eq c 52
12701e = arrname 1
12702if eq uchar get a_ar add get a_rb 7 sub e 1 10
12703pl_len e dst
12704ret
12705end
12706if ge uchar get a_ar add get a_rb 7 sub e 1 6
12707note d2site 220|rdval: type mismatch; condition if ge uchar get a_ar add get a_rb 7 sub e 1 6
12708put d2site 0 220
12709fail 7
12710end
12711if ne unsz sub e 1 0
12712vdone 1 ulong uchar get a_ar add get a_rb 14 sub e 1 5
12713ret
12714end
12715vdone 3 get a_ar add get a_rb 6 sub e 1 5
12716ret
12717end
12718if or eq c 53 eq c 54
12719eff_rec c
12720note read and write compile the same in a native object as in function mode (no image state).
12721x = mul get depth 0 32
12722put a_ar add get a_rb 77 add x 8 get nslot 0
12723rdval 0 8 255 0
12724vs_fd x
12725e = arrname 1
12726vs_arr c e
12727rdval 0 5 255 0
12728vs_off x
12729rdval 0 5 255 0
12730vs_end c e dst x
12731ret
12732end
12733if eq c 55
12734vdone 3 1 1
12735ret
12736end
12737if eq c 56
12738vdone 3 0 1
12739ret
12740end
12741if and gt sub c 33 17 gt sub c 59 1
12742if eq c 244
12743note d2site 222|rdval: word or declaration in a place that does not allow it; condition if eq c 244
12744put d2site 0 222
12745fail 9
12746end
12747note d2site 223|rdval: syntax: unknown or misplaced word; condition if and gt sub c 33 17 gt sub c 59 1
12748put d2site 0 223
12749fail 16
12750end
12751if and ge c 49 le c 50
12752put fpw 0 1
12753rdval 0 exp 255 0
12754if ge get rt 0 64
12755note d2site 224|rdval: type mismatch; condition if ge get rt 0 64
12756put d2site 0 224
12757fail 7
12758end
12759if and eq c 50 eq get rk 0 4
12760put rv 0 xor get rv 0 1
12761vdec
12762ret
12763end
12764if eq get rk 0 2
12765note d2site 225|rdval: bare number without a type from its context; condition if eq get rk 0 2
12766put d2site 0 225
12767fail 11
12768end
12769fwreq
12770vt_un c dst
12771vdec
12772ret
12773end
12774put fpw 0 1
12775rdval 0 0 255 0
12776ak = get rk 0
12777av = get rv 0
12778at = get rt 0
12779if eq ak 4
12780av = matreg 4 av at
12781ak = ulong 1
12782at = ulong 1
12783end
12784put fpw 0 1
12785rdval 0 0 255 0
12786bk = get rk 0
12787bv = get rv 0
12788bt = get rt 0
12789if eq bk 4
12790bv = matreg 4 bv bt
12791bk = ulong 1
12792bt = ulong 1
12793end
12794if or ge at 64 ge bt 64
12795x = mul get depth 0 32
12796a_p 77 x ak
12797a_p 77 add x 1 av
12798a_p 77 add x 2 at
12799a_p 77 add x 3 bk
12800a_p 77 add x 4 bv
12801a_p 77 add x 5 bt
12802ab_bin c dst x
12803vdec
12804ret
12805end
12806if and eq ak 6 eq bk 6
12807note d2site 226|rdval: bare number without a type from its context; condition if and eq ak 6 eq bk 6
12808put d2site 0 226
12809fail 11
12810end
12811if or ne isfloat at 0 ne isfloat bt 0
12812if eq ak 6
12813if eq bt 0
12814note d2site 227|rdval: bare number without a type from its context; condition if eq bt 0
12815put d2site 0 227
12816fail 11
12817end
12818if eq isfloat bt 0
12819note d2site 228|rdval: type mismatch; condition if eq isfloat bt 0
12820put d2site 0 228
12821fail 7
12822end
12823av = fspan bt av
12824ak = ulong 7
12825at = bt
12826end
12827if eq bk 6
12828if eq at 0
12829note d2site 229|rdval: bare number without a type from its context; condition if eq at 0
12830put d2site 0 229
12831fail 11
12832end
12833if eq isfloat at 0
12834note d2site 230|rdval: type mismatch; condition if eq isfloat at 0
12835put d2site 0 230
12836fail 7
12837end
12838bv = fspan at bv
12839bk = ulong 7
12840bt = at
12841end
12842if or eq ak 2 eq ak 3
12843note d2site 231|rdval: type mismatch; condition if or eq ak 2 eq ak 3
12844put d2site 0 231
12845fail 7
12846end
12847if or eq bk 2 eq bk 3
12848note d2site 232|rdval: type mismatch; condition if or eq bk 2 eq bk 3
12849put d2site 0 232
12850fail 7
12851end
12852end
12853if or eq ak 6 eq bk 6
12854note d2site 233|rdval: type mismatch; condition if or eq ak 6 eq bk 6
12855put d2site 0 233
12856fail 7
12857end
12858if eq ak 2
12859if eq bk 2
12860note d2site 234|rdval: bare number without a type from its context; condition if eq bk 2
12861put d2site 0 234
12862fail 11
12863end
12864range av bt at
12865at = bt
12866ak = ulong 3
12867end
12868if eq bk 2
12869range bv at bt
12870bt = at
12871bk = ulong 3
12872end
12873if and ne c 41 ne c 42
12874if ne at bt
12875note d2site 235|rdval: type mismatch; condition if ne at bt
12876put d2site 0 235
12877fail 7
12878end
12879end
12880x = mul get depth 0 32
12881a_p 77 x ak
12882a_p 77 add x 1 av
12883a_p 77 add x 2 at
12884a_p 77 add x 3 bk
12885a_p 77 add x 4 bv
12886a_p 77 add x 5 bt
12887if ne isfloat at 0
12888fwreq
12889end
12890binop c dst x
12891vdec
12892end
12893
12894note cond: read a condition (a bool value); emit a branch taken when it is false: B.cond with the opposite
12895note condition (C6.2.34), or CBZ Xr (C6.2.78). Returns that branch's place. om4 COND.
12896fn cond to ulong
12897if ne get xtarget 0 0
12898rdval 0 1 255 0
12899if ne get rt 0 1
12900note d2site 236|cond: type mismatch; condition if ne get rt 0 1
12901put d2site 0 236
12902fail 7
12903end
12904if eq get rk 0 4
12905ret xbranch xor get rv 0 1
12906end
12907r = matreg get rk 0 get rv 0 get rt 0
12908xcmp r 0 1
12909ret xbranch 0
12910end
12911rdval 0 1 255 0
12912if ne get rt 0 1
12913note d2site 237|cond: type mismatch; condition if ne get rt 0 1
12914put d2site 0 237
12915fail 7
12916end
12917if eq get rk 0 4
12918at = get oc 0
12919emit or 1409286144 xor get rv 0 1
12920ret at
12921end
12922r = matreg get rk 0 get rv 0 get rt 0
12923at = get oc 0
12924emit or 3019898880 r
12925ret at
12926end
12927
12928note ======== statements, one per line (om4 STMT and the S_ parts) ========
12929note skipnl: note ...: the rest of the line is not read (up to the newline, which tok reads). om4 S_NOTE.
12930fn skipnl to void
12931go = true
12932while go
12933n = ulong 0
12934while and go lt n 999999
12935if ge get cur 0 get inlen 0
12936go = false
12937else
12938if eq a_ib get cur 0 10
12939go = false
12940else
12941put cur 0 add get cur 0 1
12942end
12943end
12944n = add n 1
12945end
12946end
12947end
12948
12949note blo: B.LO back to an earlier place (C6.2.34)
12950fn blo at ulong to void
12951if ne get xtarget 0 0
12952p = xbranch 3
12953xpatch p at
12954ret
12955end
12956d = bdisp get oc 0 at 19
12957emit or 1409286147 shl d 5
12958end
12959
12960note sa_arr: x = new T N v: N elements of type T on the stack, each set to v; only in the function's
12961note outermost block, so the stack held by local arrays is known at every ret. SUB SP (C6.2.457); program
12962note mode: the stack check; MOV Xb, SP (ADD immediate, C6.2.5); then the fill loop: STR v, [Xb, Xi, LSL];
12963note ADD Xi, Xi, #1; CMP Xi, #N or Xn; B.LO back (C6.2.34). om4 SA_ARR.
12964fn sa_arr w ulong to void
12965if ne get xtarget 0 0
12966xarray w
12967ret
12968end
12969if ne get nb 0 0
12970note d2site 238|sa_arr: word or declaration in a place that does not allow it; condition if ne get nb 0 0
12971put d2site 0 238
12972fail 9
12973end
12974t = typeword
12975elemtype t
12976n = lenval 16
12977arrlen n
12978by = shl shr add shl n tlog t 15 4 4
12979s = add get stkbytes 0 by
12980if gt s 4194304
12981note d2site 239|sa_arr: size capacity; condition if gt s 4194304
12982put d2site 0 239
12983fail 23
12984end
12985put stkbytes 0 s
12986r = alloc
12987put held 0 get nslot 0
12988rdval 0 t 255 0
12989if ne get rt 0 t
12990note d2site 240|sa_arr: type mismatch; condition if ne get rt 0 t
12991put d2site 0 240
12992fail 7
12993end
12994v = matreg get rk 0 get rv 0 get rt 0
12995spsubk by
12996stkchk
12997emit or 2432697312 r
12998i = alloc
12999emit or 3531603968 i
13000m = ulong 0
13001if gt n 4095
13002m = alloc
13003matconst m n
13004end
13005lp = get oc 0
13006emit or or or stop t v shl r 5 shl i 16
13007emit or or 2432697344 i shl i 5
13008if le n 4095
13009emit or or 4043309087 shl n 10 shl i 5
13010else
13011emit or or 3942645791 shl m 16 shl i 5
13012end
13013blo lp
13014addname w r t n 1 0
13015end
13016
13017note s_assign: name [=] value (an existing scalar, or a new one), or name = new T N v. om4 S_ASSIGN. A new
13018note f32/f64 name lives in the twin of its register (nm_fv, vsl): the value is made there when it can be.
13019fn s_assign w ulong to void
13020tok
13021if eq get tk 0 1
13022if le get tl 0 8
13023if eq kw get tw 0 73
13024tok
13025end
13026end
13027end
13028if eq get tk 0 1
13029if eq get tl 0 7
13030if eq get tw 0 28542713606205029
13031s_enlarge w
13032ret
13033end
13034end
13035end
13036e = findname w
13037if ne e 0
13038i = sub e 1
13039if ne uchar get a_ar add get a_rb 7 i 0
13040note d2site 241|s_assign: type mismatch; condition if ne uchar get a_ar add get a_rb 7 i 0
13041put d2site 0 241
13042fail 7
13043end
13044r = ulong uchar get a_ar add get a_rb 4 i
13045t = ulong uchar get a_ar add get a_rb 5 i
13046if ne uchar get a_ar add get a_rb 9 i 0
13047put fpw 0 add r 2
13048rdval 1 t 255 0
13049if ne get rt 0 t
13050note d2site 242|s_assign: type mismatch; condition if ne get rt 0 t
13051put d2site 0 242
13052fail 7
13053end
13054fvset get rk 0 get rv 0 t r
13055eol
13056ret
13057end
13058rdval 1 t r 0
13059if ne get rt 0 t
13060note d2site 243|s_assign: type mismatch; condition if ne get rt 0 t
13061put d2site 0 243
13062fail 7
13063end
13064force get rk 0 get rv 0 get rt 0 r
13065eol
13066ret
13067end
13068if ne findfn w 0 0 0
13069note d2site 244|s_assign: duplicate name; condition if ne findfn w 0 0 0
13070put d2site 0 244
13071fail 10
13072end
13073if eq get tk 0 1
13074if le get tl 0 8
13075if eq kw get tw 0 84
13076sa_new w
13077eol
13078ret
13079end
13080end
13081end
13082r = alloc
13083put held 0 get nslot 0
13084put fpw 0 add r 2
13085rdval 1 0 r 0
13086if eq get rk 0 2
13087note d2site 245|s_assign: bare number without a type from its context; condition if eq get rk 0 2
13088put d2site 0 245
13089fail 11
13090end
13091t = get rt 0
13092if and ne isfloat t 0 eq get xtarget 0 0
13093fvset get rk 0 get rv 0 t r
13094put vsl regidx r uchar 1
13095addname w r t 0 0 0
13096a_pc 9 sub get nn 0 1 uchar 1
13097else
13098force get rk 0 get rv 0 t r
13099addname w r t 0 0 0
13100end
13101eol
13102end
13103
13104note s_enlarge: NAME = enlarge P n (docs/RUNTIME-POOLS.md s3), only as the whole of an assignment (anywhere
13105note else error 9). NAME is a long local or a new one (error 7 for any other type), P a run-time pool (error
13106note 7 for any other name), n a ulong (error 7). n is read first; then the registers in use are saved, X0 = P's
13107note slot, X1 = n, X2 = log2 of the element size, BL omc_enlarge (en_help), and the result moves to NAME's
13108note register as the registers come back: 0, -22 when n times the element size reaches 2^63, or the host's
13109note -errno (-12) when mmap or mremap refuses; on a refusal the pool is unchanged.
13110fn s_enlarge w ulong to void
13111eff_rec 244
13112e = findname w
13113r = ulong 0
13114if ne e 0
13115i = sub e 1
13116if ne uchar get a_ar add get a_rb 7 i 0
13117note d2site 246|s_enlarge: type mismatch; condition if ne uchar get a_ar add get a_rb 7 i 0
13118put d2site 0 246
13119fail 7
13120end
13121if ne uchar get a_ar add get a_rb 5 i 9
13122note d2site 247|s_enlarge: type mismatch; condition if ne uchar get a_ar add get a_rb 5 i 9
13123put d2site 0 247
13124fail 7
13125end
13126r = ulong uchar get a_ar add get a_rb 4 i
13127else
13128if ne findfn w 0 0 0
13129note d2site 248|s_enlarge: duplicate name; condition if ne findfn w 0 0 0
13130put d2site 0 248
13131fail 10
13132end
13133r = alloc
13134put held 0 get nslot 0
13135end
13136if eq get xtarget 0 0
13137en_help
13138end
13139p = arrname 1
13140if ne uchar get a_ar add get a_rb 7 sub p 1 10
13141note d2site 249|s_enlarge: type mismatch; condition if ne uchar get a_ar add get a_rb 7 sub p 1 10
13142put d2site 0 249
13143fail 7
13144end
13145sl = get nslot 0
13146rdval 0 5 255 0
13147if eq get rk 0 2
13148note d2site 250|s_enlarge: bare number without a type from its context; condition if eq get rk 0 2
13149put d2site 0 250
13150fail 11
13151end
13152if ne get rt 0 5
13153note d2site 251|s_enlarge: type mismatch; condition if ne get rt 0 5
13154put d2site 0 251
13155fail 7
13156end
13157nv = matreg get rk 0 get rv 0 5
13158if ne get xtarget 0 0
13159xenlarge p nv
13160put nslot 0 sl
13161xstore 0 r
13162if eq e 0
13163addname w r 9 0 0 0
13164end
13165eol
13166ret
13167end
13168save
13169loadarg 1 1 nv
13170mataddr 0 get a_ar add get a_rb 8 sub p 1
13171matconst 2 tlog ulong uchar get a_ar add get a_rb 5 sub p 1
13172en_bl
13173n = get svn 0
13174a = get sva 0
13175r = restore r sl n a 1
13176if eq e 0
13177addname w r 9 0 0 0
13178end
13179eol
13180end
13181
13182note en_help: the unit's omc_enlarge helper (docs/RUNTIME-POOLS.md s4), emitted once, at the unit's first
13183note enlarge, behind a B over it (C6.2.35); a unit without enlarge has neither it nor any pool slot. In: X0 the
13184note slot (base, length), X1 the count n, X2 log2 of the element size; out X0. n <= length: 0. n << X2 past
13185note 2^63 (LSR, CBNZ): -22. Bytes rounded up to the page (4096): a growth within the pages already mapped
13186note only stores the length (they are still zero: nothing writes past the length and nothing shrinks); length
13187note 0 maps (mmap 222, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS); else mremap (216, MREMAP_MAYMOVE),
13188note which moves page tables, not data. A result in -4095..-1 (CMN, B.HS) returns as it is with the slot
13189note untouched; else the new base and then the length are stored and the result is 0. It clobbers X0..X6,
13190note X8..X10 only, all saved by the caller (save); X7, X16..X30 and SP are untouched.
13191note en_bl: BL omc_enlarge (C6.2.43): the helper is behind, so the offset is negative, kept to imm26
13192fn en_bl to void
13193d = sub sub get enl_at 0 1 get oc 0
13194emit or 2483027968 and shr d 2 67108863
13195end
13196
13197fn en_help to void
13198if ne get enl_at 0 0
13199ret
13200end
13201emit 335544362
13202put enl_at 0 add get oc 0 1
13203emit 2852127721
13204emit 2852193258
13205emit 4181722403
13206emit 3942842719
13207note POOLMUT belowlen
13208emit 1409287209
13209emit 3531605988
13210emit 3405906052
13211emit 2596545861
13212note POOLMUT ovf
13213emit 3036677093
13214emit 2596413765
13215emit 2436889765
13216emit 2457128101
13217emit 2596413542
13218emit 2436889798
13219emit 2457128134
13220emit 3943039167
13221emit 1409286793
13222emit 3019899142
13223emit 4181721376
13224emit 2852520929
13225emit 2852455394
13226emit 3531604003
13227emit 3531610888
13228emit 3556769793
13229emit 335544329
13230emit 3531603968
13231emit 2852455393
13232emit 3531604066
13233emit 3531605059
13234emit 2457862148
13235emit 3531603973
13236emit 3531611080
13237emit 3556769793
13238emit 2973760543
13239note POOLMUT slotfail
13240emit 1409286274
13241emit 4177527072
13242note POOLMUT caplen
13243emit 4177528106
13244emit 3531603968
13245emit 3596551104
13246emit 2457862816
13247emit 3596551104
13248note POOLMUT-ALT belowlen emit 3573751839
13249note POOLMUT-ALT caplen emit 4177528101
13250note POOLMUT-ALT ovf emit 3573751839
13251note POOLMUT-ALT slotfail emit 3573751839
13252end
13253
13254note s_name: a name at the start of a line: a call of a void function, or name [=] value. om4 S_NAME.
13255fn s_name w ulong to void
13256if ne findname w 0
13257s_assign w
13258ret
13259end
13260f = findfn w get tl 0 0
13261if eq f 0
13262s_assign w
13263ret
13264end
13265if ne uchar get a_ar add get a_rb 23 sub f 1 12
13266note d2site 252|s_name: type mismatch; condition if ne uchar get a_ar add get a_rb 23 sub f 1 12
13267put d2site 0 252
13268fail 7
13269end
13270rdval 2 0 255 f
13271eol
13272end
13273
13274note fn_p: the type of parameter np (name pw) of function f (index): T, or view / edit T N (an array:
13275note kind 2 / 3, element type, length 1 .. 2^24). om4 FN_P .. FN_ADD.
13276fn fn_p f ulong np ulong pw ulong to void
13277tok
13278if ne get tk 0 1
13279note d2site 253|fn_p: syntax: unknown or misplaced word; condition if ne get tk 0 1
13280put d2site 0 253
13281fail 16
13282end
13283if gt get tl 0 8
13284note d2site 254|fn_p: syntax: unknown or misplaced word; condition if gt get tl 0 8
13285put d2site 0 254
13286fail 16
13287end
13288c = kw get tw 0
13289t = ulong 0
13290ln = ulong 0
13291k = ulong 0
13292if eq c 194
13293fn_p_out f np pw
13294ret
13295end
13296if or eq c 57 eq c 58
13297k = sub c 55
13298sid = peek_struct
13299if ne sid 0
13300fn_p_st f np pw sid k
13301ret
13302end
13303if ne get om2 0 0
13304lid = peek_lay
13305if ne lid 0
13306fn_p_ly f np pw lid k
13307ret
13308end
13309end
13310t = typeword
13311elemtype t
13312if and ne get om2 0 0 ne peekstar 0
13313tok
13314else
13315ln = lenval 16
13316arrlen ln
13317if ne get om2 0 0
13318if eq peekw 183
13319tok
13320fz_par f np k ln
13321end
13322end
13323end
13324else
13325if eq c 88
13326t = ulong 10
13327else
13328if eq c 89
13329t = ulong 11
13330else
13331if eq c 223
13332t = ulong 13
13333else
13334if gt sub c 1 8
13335t = abty
13336else
13337t = c
13338end
13339end
13340end
13341end
13342end
13343addname pw poolc get psl 0 t ln k 0
13344if and ne k 0 eq ln 0
13345a_pc 14 sub get nn 0 1 uchar poolc add get psl 0 1
13346end
13347fz_bind add mul f 6 np ln
13348p = add mul f 6 np
13349a_pc 35 p uchar t
13350put a_ar add get a_rb 36 p ln
13351a_pc 37 p uchar k
13352end
13353
13354note fn_p_out (OM-2, spec 6, erratum E1): `NAME out T N`, a sized array the unit writes and the bridge owns
13355note (copied out only after status 0). Inside the unit it is an edit of T N (kind 3) in one slot, its
13356note pointer; a length `*` is error 16, and so is `fresh` after it.
13357fn fn_p_out f ulong np ulong pw ulong to void
13358t = typeword
13359elemtype t
13360ln = lenval 16
13361arrlen ln
13362addname pw poolc get psl 0 t ln 3 0
13363p = add mul f 6 np
13364a_pc 35 p uchar t
13365put a_ar add get a_rb 36 p ln
13366a_pc 37 p 3
13367end
13368
13369note fn_to: to T | to void at the end of a fn line; the function's state starts. om4 FN_TO .. FN_T2.
13370fn fn_to f ulong np ulong to void
13371tok
13372if eq get tk 0 0
13373note d2site 255|fn_to: the line ends where a word or value is needed; condition if eq get tk 0 0
13374put d2site 0 255
13375fail 4
13376end
13377if ne get tk 0 1
13378note d2site 256|fn_to: syntax: unknown or misplaced word; condition if ne get tk 0 1
13379put d2site 0 256
13380fail 16
13381end
13382if gt get tl 0 8
13383note d2site 257|fn_to: syntax: unknown or misplaced word; condition if gt get tl 0 8
13384put d2site 0 257
13385fail 16
13386end
13387c = kw get tw 0
13388r = c
13389if eq c 76
13390r = ulong 12
13391else
13392if eq c 88
13393r = ulong 10
13394else
13395if eq c 89
13396r = ulong 11
13397else
13398if eq c 223
13399r = ulong 13
13400else
13401if gt sub c 1 8
13402r = abty
13403else
13404r = c
13405end
13406end
13407end
13408end
13409end
13410put curret 0 r
13411a_pc 23 f uchar r
13412a_pc 24 f uchar np
13413put stkbytes 0 0
13414put osp 0 0
13415put osmax 0 0
13416put osbad 0 0
13417put dead 0 0
13418put npar 0 get psl 0
13419put nslot 0 0
13420for j ulong 16
13421put vsl j 0
13422end
13423put held 0 0
13424put nb 0 0
13425put nt 0 0
13426put tpend 0 0
13427fn_tail f
13428if and ne get xtarget 0 0 eq get scanning 0 0
13429xpro get psl 0
13430end
13431end
13432
13433note s_fn: fn name (param type | param view T N | param edit T N)* to type | void. om4 S_FN.
13434note A name of 9..63 bytes is never a keyword: tw packs only its first 8 bytes (continue_x is not continue).
13435fn s_fn to void
13436if ne get curret 0 0
13437note d2site 258|s_fn: missing end; condition if ne get curret 0 0
13438put d2site 0 258
13439fail 15
13440end
13441tok
13442if ne get tk 0 1
13443note d2site 259|s_fn: syntax: unknown or misplaced word; condition if ne get tk 0 1
13444put d2site 0 259
13445fail 16
13446end
13447if gt get tl 0 63
13448note d2site 260|s_fn: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
13449put d2site 0 260
13450fail 13
13451end
13452w = get tw 0
13453if and ne get objmode 0 0 eq w 121437607458917
13454if eq get tl 0 6
13455note d2site 261|s_fn: syntax: unknown or misplaced word; condition if eq get tl 0 6
13456put d2site 0 261
13457fail 16
13458end
13459end
13460if le get tl 0 8
13461if ne kw w 0
13462note d2site 262|s_fn: syntax: unknown or misplaced word; condition if ne kw w 0
13463put d2site 0 262
13464fail 16
13465end
13466end
13467l = get tl 0
13468s = get ts 0
13469f = ulong 0
13470if eq get scanning 0 1
13471newname w l s
13472f = get nf 0
13473if ge f get a_gp 7
13474a_need 7 f
13475end
13476if ne get objmode 0 0
13477a_need 21 f
13478a_p 86 f 0
13479end
13480put nf 0 add f 1
13481put curfn 0 add f 1
13482put lastfn 0 add f 1
13483put a_ar add get a_rb 21 f w
13484fn_link f
13485put a_ar add get a_rb 22 f get oc 0
13486a_pc 23 f 0
13487a_pc 24 f 0
13488put a_ar add get a_rb 25 f l
13489put a_ar add get a_rb 26 f s
13490a_pc 32 f uchar get expf 0
13491else
13492f = sub findfn w l s 1
13493put curfn 0 add f 1
13494put lastfn 0 add f 1
13495put a_ar add get a_rb 22 f get oc 0
13496put fstart 0 get oc 0
13497put pinshut 0 1
13498put fuel 0 0
13499put fz_n 0 0
13500end
13501nm_set get nglob 0
13502put psl 0 0
13503np = ulong 0
13504go = true
13505while go
13506tok
13507if eq get tk 0 0
13508note d2site 263|s_fn: the line ends where a word or value is needed; condition if eq get tk 0 0
13509put d2site 0 263
13510fail 4
13511end
13512if ne get tk 0 1
13513note d2site 264|s_fn: syntax: unknown or misplaced word; condition if ne get tk 0 1
13514put d2site 0 264
13515fail 16
13516end
13517if gt get tl 0 63
13518note d2site 265|s_fn: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
13519put d2site 0 265
13520fail 13
13521end
13522pw = get tw 0
13523c = kw pw
13524if eq c 65
13525go = false
13526else
13527if ne c 0
13528note d2site 266|s_fn: syntax: unknown or misplaced word; condition if ne c 0
13529put d2site 0 266
13530fail 16
13531end
13532newname pw get tl 0 get ts 0
13533if ge get psl 0 6
13534note d2site 267|s_fn: word or declaration in a place that does not allow it; condition if ge get psl 0 6
13535put d2site 0 267
13536fail 9
13537end
13538fn_p f np pw
13539a_p 34 add mul f 6 np pw
13540put psl 0 add get psl 0 pwid add mul f 6 np
13541if gt get psl 0 6
13542note d2site 268|s_fn: word or declaration in a place that does not allow it; condition if gt get psl 0 6
13543put d2site 0 268
13544fail 9
13545end
13546np = add np 1
13547end
13548end
13549fn_to f np
13550if and ne get objmode 0 0 eq get expf 0 2
13551obj_import f
13552ret
13553end
13554ab_entry f
13555if eq get scanning 0 0
13556cp_entry
13557end
13558if eq get scanning 0 1
13559put curret 0 0
13560note keep the top-level consts read so far: a later const must not take an earlier one's slot.
13561nm_set get nglob 0
13562end
13563end
13564
13565note s_ret: ret [value]: the value into X0, give back the local arrays' stack, RET. om4 S_RET.
13566fn s_ret to void
13567if ne get inl 0 0
13568s_iret
13569ret
13570end
13571r = get curret 0
13572if eq r 12
13573eol
13574cp_post 0 0 r
13575epi
13576dead1
13577ret
13578end
13579dst = ulong 0
13580if and ne get cfhas 0 0 eq get crel 0 0
13581dst = ulong 255
13582end
13583rdval 0 r dst 0
13584if ne get rt 0 r
13585note d2site 269|s_ret: type mismatch; condition if ne get rt 0 r
13586put d2site 0 269
13587fail 7
13588end
13589if and ne get cfhas 0 0 eq get crel 0 0
13590rr = matreg get rk 0 get rv 0 r
13591eol
13592cp_post 1 rr r
13593force 1 rr r 0
13594else
13595force get rk 0 get rv 0 get rt 0 0
13596eol
13597cp_post 1 0 r
13598end
13599epi
13600dead1
13601end
13602
13603note s_break: leave the innermost loop: find the nearest block of kind 3 (while) or 4 (for), emit an
13604note always-taken B.cond to the loop's exit and record the word for s_end to patch. Outside a loop the
13605note line is error 9. Like ret, the line ends the path (a later line in the same block is error 17).
13606fn s_break to void
13607j = get nb 0
13608found = ulong 0
13609bi = ulong 0
13610while and eq found 0 gt j 0
13611j = sub j 1
13612if ge get a_ar add get a_rb 49 j 3
13613found = ulong 1
13614bi = j
13615end
13616end
13617if eq found 0
13618note d2site 270|s_break: word or declaration in a place that does not allow it; condition if eq found 0
13619put d2site 0 270
13620fail 9
13621end
13622if ge get a_ar add get a_rb 49 bi 5
13623note d2site 271|s_break: word or declaration in a place that does not allow it; condition if ge get a_ar add get a_rb 49 bi 5
13624put d2site 0 271
13625fail 9
13626end
13627n = get nbrk 0
13628if ge n get a_gp 14
13629a_need 14 n
13630end
13631put a_ar add get a_rb 70 n get oc 0
13632put a_ar add get a_rb 71 n bi
13633put nbrk 0 add n 1
13634if ne get xtarget 0 0
13635p = xbranch 14
13636else
13637emit 1409286158
13638end
13639dead1
13640eol
13641end
13642
13643note s_cont: continue: like break it finds the innermost loop, but its exit is the latch: the head of a
13644note while, the increment of a for (patched by s_end). Outside a loop it is error 9; the line ends the
13645note path (error 17 for a later line in the same block).
13646fn s_cont to void
13647j = get nb 0
13648found = ulong 0
13649bi = ulong 0
13650while and eq found 0 gt j 0
13651j = sub j 1
13652if ge get a_ar add get a_rb 49 j 3
13653found = ulong 1
13654bi = j
13655end
13656end
13657if eq found 0
13658note d2site 272|s_cont: word or declaration in a place that does not allow it; condition if eq found 0
13659put d2site 0 272
13660fail 9
13661end
13662if ge get a_ar add get a_rb 49 bi 5
13663note d2site 273|s_cont: word or declaration in a place that does not allow it; condition if ge get a_ar add get a_rb 49 bi 5
13664put d2site 0 273
13665fail 9
13666end
13667n = get ncont 0
13668if ge n get a_gp 15
13669a_need 15 n
13670end
13671put a_ar add get a_rb 72 n get oc 0
13672put a_ar add get a_rb 73 n bi
13673put ncont 0 add n 1
13674if ne get xtarget 0 0
13675p = xbranch 14
13676else
13677emit 1409286158
13678end
13679dead1
13680eol
13681end
13682
13683note stel: the checked store of v (type t) at ea_b / ea_i (the STOP table: register offset, scaled)
13684fn stel t ulong v ulong to void
13685if ne get xtarget 0 0
13686xmemval 1 get ea_b 0 get ea_i 0 t v
13687ret
13688end
13689eaem stop t v
13690end
13691
13692note s_put: put A i v: index, then value, then the checked store (STOP table). om4 S_PUT.
13693fn s_put to void
13694e = arrname 1
13695k = uchar get a_ar add get a_rb 7 sub e 1
13696if ge k 6
13697if ne k 10
13698s_putf e
13699ret
13700end
13701end
13702if or eq k 2 eq k 5
13703note d2site 274|s_put: write to a view or a text; condition if or eq k 2 eq k 5
13704put d2site 0 274
13705fail 20
13706end
13707if ne ly_put e 0
13708ret
13709end
13710rdval 0 5 255 0
13711ik = get rk 0
13712iv = get rv 0
13713it = get rt 0
13714note POOLMUT-ALT slotearly.1 elemaddr e ik iv it
13715note POOLMUT-ALT slotearly.2 note removed
13716note POOLMUT slotearly.1
13717note the element address comes after the value (docs/RUNTIME-POOLS.md s4, rule B1)
13718t = ulong uchar get a_ar add get a_rb 5 sub e 1
13719if ne isfloat t 0
13720put fpw 0 1
13721end
13722rdval 0 t 255 0
13723if ne get rt 0 t
13724note d2site 275|s_put: type mismatch; condition if ne get rt 0 t
13725put d2site 0 275
13726fail 7
13727end
13728if eq get rk 0 9
13729vv = vtw get rv 0
13730fz_put e ik iv
13731elemaddr e ik iv it
13732eaem or stop t 67108864 vv
13733eol
13734ret
13735end
13736v = matreg get rk 0 get rv 0 get rt 0
13737fz_put e ik iv
13738note POOLMUT slotearly.2
13739elemaddr e ik iv it
13740stel t v
13741eol
13742end
13743
13744note s_const: const NAME TYPE LITERAL at top level. The value is a typed number (integer or float)
13745note read wherever a value goes; it may not be assigned and is refused in IR mode.
13746fn s_const to void
13747tok
13748if ne get tk 0 1
13749note d2site 276|s_const: syntax: unknown or misplaced word; condition if ne get tk 0 1
13750put d2site 0 276
13751fail 16
13752end
13753if gt get tl 0 63
13754note d2site 277|s_const: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
13755put d2site 0 277
13756fail 13
13757end
13758w = get tw 0
13759if ne kw w 0
13760note d2site 278|s_const: syntax: unknown or misplaced word; condition if ne kw w 0
13761put d2site 0 278
13762fail 16
13763end
13764newname w get tl 0 get ts 0
13765t = typeword
13766if ge t 64
13767note d2site 279|s_const: type mismatch; condition if ge t 64
13768put d2site 0 279
13769fail 7
13770end
13771if ne isfloat t 0
13772note float constant: rdval reads the float token as a value (kind 6); fspan converts it to the
13773note target type's bits and rdval has already balanced the nesting depth.
13774rdval 0 0 255 0
13775if ne get rk 0 6
13776note d2site 280|s_const: syntax: unknown or misplaced word; condition if ne get rk 0 6
13777put d2site 0 280
13778fail 16
13779end
13780v = fspan t get rv 0
13781addname w 0 t 0 9 v
13782put nglob 0 get nn 0
13783eol
13784ret
13785end
13786tok
13787if eq get tk 0 0
13788note d2site 281|s_const: the line ends where a word or value is needed; condition if eq get tk 0 0
13789put d2site 0 281
13790fail 4
13791end
13792if eq get tk 0 5
13793note d2site 282|s_const: type mismatch; condition if eq get tk 0 5
13794put d2site 0 282
13795fail 7
13796end
13797if ne get tk 0 2
13798note d2site 283|s_const: syntax: unknown or misplaced word; condition if ne get tk 0 2
13799put d2site 0 283
13800fail 16
13801end
13802v = get tw 0
13803range v t get tbig 0
13804addname w 0 t 0 9 v
13805put nglob 0 get nn 0
13806eol
13807end
13808
13809note s_global: global NAME T N: a fixed pool of N elements, zero at start, in the read/write part of the
13810note program image after the 8 MiB stack pool (address 0x10800000 + pool bytes so far); at most 1 GiB of
13811note pools (error 23). om4 S_GLOBAL.
13812fn s_global to void
13813w = topname
13814t = typeword
13815elemtype t
13816pc = get cur 0
13817pl = get line 0
13818tok
13819if eq get tk 0 1
13820if eq get tl 0 1
13821if eq get tw 0 42
13822sg_pool w t
13823ret
13824end
13825end
13826end
13827put cur 0 pc
13828put line 0 pl
13829n = lenval 16
13830arrlen n
13831by = shl shr add shl n tlog t 15 4 4
13832pb = get poolb 0
13833a = add 276824064 pb
13834s = add pb by
13835if gt s 1073741824
13836note d2site 284|s_global: size capacity; condition if gt s 1073741824
13837put d2site 0 284
13838fail 23
13839end
13840put poolb 0 s
13841addname w 0 t n 4 a
13842put nglob 0 get nn 0
13843if ne om2cg 0
13844pinset sub get nn 0 1 a n
13845end
13846eol
13847end
13848
13849note sg_pool: global NAME T * (docs/RUNTIME-POOLS.md s3, s4): a run-time pool of element type t, name kind
13850note 10, length 0 when the program starts. Its 16-byte slot in the global pool area (zero at start) holds the
13851note base address, then the length in elements. Program mode on AArch64 and x86linux: function mode and IR mode
13852note are error 9, x86efi and a64efi error 25. Never pinned: no X18..X26 holds its base or length.
13853fn sg_pool w ulong t ulong to void
13854if eq get progmode 0 0
13855note d2site 285|sg_pool: word or declaration in a place that does not allow it; condition if eq get progmode 0 0
13856put d2site 0 285
13857fail 9
13858end
13859if ne get irmode 0 0
13860note d2site 286|sg_pool: word or declaration in a place that does not allow it; condition if ne get irmode 0 0
13861put d2site 0 286
13862fail 9
13863end
13864if gt get xtarget 0 1
13865note d2site 287|sg_pool: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if gt get xtarget 0 1
13866put d2site 0 287
13867fail 25
13868end
13869if ne get xefa 0 0
13870note d2site 288|sg_pool: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xefa 0 0
13871put d2site 0 288
13872fail 25
13873end
13874pb = get poolb 0
13875a = add 276824064 pb
13876s = add pb 16
13877if gt s 1073741824
13878note d2site 289|sg_pool: size capacity; condition if gt s 1073741824
13879put d2site 0 289
13880fail 23
13881end
13882put poolb 0 s
13883addname w 0 t 0 10 a
13884put nglob 0 get nn 0
13885note POOLMUT-ALT pinned pinset sub get nn 0 1 a 0
13886note POOLMUT pinned
13887eol
13888end
13889
13890note om2cg: 1 when the unit gets the OM-2 AArch64 code improvements (an OM-2 unit, AArch64, not IR mode),
13891note else 0. An OM-1 unit keeps om4's machine words exactly (gate5 compares them word for word).
13892note Not under target a64efi: the improvements pin globals in X18..X26, and X18 belongs to the platform
13893note under UEFI (the entry never sets those registers either). `target a64efi` then `om2` is the OM-2
13894note language with the OM-1 addressing, as on the x86 targets.
13895fn om2cg to ulong
13896if ne get xefa 0 0
13897ret 0
13898end
13899if and and ne get om2 0 0 eq get xtarget 0 0 eq get irmode 0 0
13900ret 1
13901end
13902ret 0
13903end
13904
13905note pinset: give global name i (address a, n elements) the next free pinned register for its base, then
13906note one for its length when n is above 4095 (no CMP immediate); nothing once X18..X26 are all taken, and
13907note nothing for a global declared after the first function body (pinshut).
13908fn pinset i ulong a ulong n ulong to void
13909p = get npin 0
13910if or ge p 9 ne get pinshut 0 0
13911ret
13912end
13913a_pc 10 i uchar add 18 p
13914put pinv p a
13915p = add p 1
13916if and gt n 4095 lt p 9
13917a_pc 11 i uchar add 18 p
13918put pinv p n
13919p = add p 1
13920end
13921put npin 0 p
13922end
13923
13924note pinlo: MOVZ/MOVK (matconst) every pinned register X18 + p with its value pinv p
13925fn pinlo to void
13926p = ulong 0
13927while lt p get npin 0
13928matconst add 18 p get pinv p
13929p = add p 1
13930end
13931end
13932
13933note s_text: text NAME "...": read-only bytes in the program image (escapes \n \t \\ \", any other is error
13934note 22), padded to a word, with their length; address 0x400000 + its place. om4 S_TEXT.
13935fn s_text to void
13936w = topname
13937tok
13938if ne get tk 0 4
13939note d2site 290|s_text: syntax: unknown or misplaced word; condition if ne get tk 0 4
13940put d2site 0 290
13941fail 16
13942end
13943br = ulong 0
13944if and ne get xtarget 0 0 ne get tl 0 0
13945br = xbranch 14
13946end
13947a = add get oc 0 4194304
13948p = get tw 0
13949e = add p get tl 0
13950n = ulong 0
13951go = true
13952while go
13953m = ulong 0
13954while and go lt m 999999
13955if ge p e
13956go = false
13957else
13958b = a_ib p
13959p = add p 1
13960if eq b 92
13961b = a_ib p
13962p = add p 1
13963if eq b 110
13964b = uchar 10
13965else
13966if eq b 116
13967b = uchar 9
13968else
13969if and ne b 92 ne b 34
13970note d2site 291|s_text: malformed text literal; condition if and ne b 92 ne b 34
13971put d2site 0 291
13972fail 22
13973end
13974end
13975end
13976end
13977emitb b
13978n = add n 1
13979end
13980m = add m 1
13981end
13982end
13983note Empty text carries no data or padding; its zero count forbids every access.
13984if ne n 0
13985while ne and get oc 0 3 0
13986emitb 0
13987end
13988end
13989if ne br 0
13990xpatch br get oc 0
13991end
13992addname w 0 2 n 5 a
13993put nglob 0 get nn 0
13994eol
13995end
13996
13997note s_else: jump over the else part (B, C6.2.35); the if's false branch lands after that jump. om4 S_ELSE.
13998fn s_else to void
13999n = get nb 0
14000if eq n 0
14001note d2site 292|s_else: missing end; condition if eq n 0
14002put d2site 0 292
14003fail 15
14004end
14005i = sub n 1
14006if ne get a_ar add get a_rb 49 i 1
14007note d2site 293|s_else: missing end; condition if ne get a_ar add get a_rb 49 i 1
14008put d2site 0 293
14009fail 15
14010end
14011b = get oc 0
14012if ne get xtarget 0 0
14013note A terminated then-path needs no skip jump, particularly at a bare unit's final byte.
14014if eq get dead 0 0
14015p = xbranch 14
14016end
14017else
14018emit 335544320
14019end
14020patch19 get a_ar add get a_rb 50 i get oc 0
14021put a_ar add get a_rb 49 i 2
14022put a_ar add get a_rb 50 i b
14023fz_else i
14024nm_set get a_ar add get a_rb 54 i
14025put held 0 get a_ar add get a_rb 55 i
14026put a_ar add get a_rb 56 i get dead 0
14027put dead 0 0
14028eol
14029end
14030
14031note lpcnt: the hidden counter check of a loop: CMP Xc, #N (C6.2.96) or CMP Xc, Xn (C6.2.97); B.HS trap
14032note 4; ADD Xc, Xc, #1 (C6.2.5). om4 SW_NOB .. SW_G and the same in S_FOR.
14033fn lpcnt c ulong n ulong to void
14034if ne get xtarget 0 0
14035xcmp c n 1
14036trapc 2 4
14037xarith 33 5 c 1 1 c
14038ret
14039end
14040if le n 4095
14041emit or or 4043309087 shl n 10 shl c 5
14042else
14043m = alloc
14044matconst m n
14045emit or or 3942645791 shl c 5 shl m 16
14046end
14047trapc 2 4
14048emit or or 2432697344 c shl c 5
14049end
14050
14051note lpmark: after pushb of a for in an OM-2 unit on AArch64 whose head ran no clause code (cphn 0): move its
14052note test to the latch (lpback). br is the head's exit branch; the latch branches back to the word after it.
14053note kk is K when K is a number, kr K's register + 1 when K is a value (0 for a number).
14054fn lpmark br ulong kk ulong kr ulong to void
14055if eq get om2 0 0
14056ret
14057end
14058if ne get cphn 0 0
14059ret
14060end
14061b = sub get nb 0 1
14062put a_ar add get a_rb 57 b add br 4
14063put a_ar add get a_rb 58 b kk
14064put a_ar add get a_rb 59 b kr
14065end
14066
14067note lpback: the latch test of a for whose test moved there (block b): CMP Xi, #K (C6.2.96), CMP Xi, Xk or
14068note CMP Xi, X(matconst K) (C6.2.97), then B.LO (unsigned) or B.LT (signed) back to the first word after
14069note the head's exit branch (C6.2.34). The head keeps its test for the first pass only; every later pass
14070note is tested here, after the increment, so a pass runs one branch instead of two. When K needs a register
14071note and none is free here (alloc would be error 12), the latch is B head (C6.2.35), as without the move.
14072fn lpback b ulong to void
14073r = get a_ar add get a_rb 52 b
14074kr = get a_ar add get a_rb 59 b
14075if ne kr 0
14076emit or or 3942645791 shl sub kr 1 16 shl r 5
14077else
14078kk = get a_ar add get a_rb 58 b
14079if le kk 4095
14080emit or or 4043309087 shl kk 10 shl r 5
14081else
14082if ge add get npar 0 get nslot 0 16
14083back get a_ar add get a_rb 51 b
14084ret
14085end
14086m = alloc
14087matconst m kk
14088emit or or 3942645791 shl r 5 shl m 16
14089end
14090end
14091cc = ulong 3
14092if ge get a_ar add get a_rb 53 b 6
14093cc = ulong 11
14094end
14095emit or or 1409286144 shl bdisp get oc 0 get a_ar add get a_rb 57 b 19 5 cc
14096end
14097
14098note s_while: while cond [bound N]: hidden counter = 0; head: cond false -> exit; counter >= N -> trap 4;
14099note counter = counter + 1; body; B head. N is 1 .. 9223372036854775807 (error 8), 1000000 with no bound. om4 S_WHILE.
14100fn s_while to void
14101sn = get nn 0
14102sh = get held 0
14103c = alloc
14104put held 0 get nslot 0
14105if ne get xtarget 0 0
14106matconst c 0
14107else
14108emit or 3531603968 c
14109end
14110hd = get oc 0
14111cp_head skipln get cur 0 add get line 0 1
14112br = cond
14113n = ulong 1000000
14114tok
14115k = get tk 0
14116if and ne k 0 ne k 3
14117if ne k 1
14118note d2site 294|s_while: extra words after a complete statement; condition if ne k 1
14119put d2site 0 294
14120fail 5
14121end
14122if gt get tl 0 8
14123note d2site 295|s_while: extra words after a complete statement; condition if gt get tl 0 8
14124put d2site 0 295
14125fail 5
14126end
14127if ne kw get tw 0 70
14128note d2site 296|s_while: extra words after a complete statement; condition if ne kw get tw 0 70
14129put d2site 0 296
14130fail 5
14131end
14132v = lenval 4
14133if ge sub v 1 9223372036854775807
14134note d2site 297|s_while: number out of range for its type or place; condition if ge sub v 1 9223372036854775807
14135put d2site 0 297
14136fail 8
14137end
14138n = v
14139eol
14140end
14141lpcnt c n
14142pushb br 3 hd c 0
14143pushnh sn sh
14144cp_skip
14145end
14146
14147note sf_br: B.HS (unsigned) or B.GE (signed) to the loop exit, C6.2.34 (distance filled at end); returns
14148note its place. om4 SF_BR.
14149fn sf_br t ulong to ulong
14150if ne get xtarget 0 0
14151if lt t 6
14152ret xbranch 2
14153end
14154ret xbranch 10
14155end
14156at = get oc 0
14157if lt t 6
14158emit 1409286146
14159else
14160emit 1409286154
14161end
14162ret at
14163end
14164
14165note sf_num: for i T K with K a number: i = 0 (MOVZ, C6.2.285); head: CMP Xi, #K or Xk; B.HS/B.GE exit.
14166note With `bound N` a hidden counter c = 0 is checked after the exit test, as in s_while. om4 SF_NUM .. SF_PUSH.
14167note The optional `bound N` before the line's end: N a number or an integer constant, 1 ..
14168note 9223372036854775807 (error 8, as s_while; 4 when N is missing); bn = 0 when no bound is written.
14169fn sf_num w ulong t ulong kk ulong sn ulong sh ulong to void
14170bn = ulong 0
14171if eq peekw 70
14172tok
14173bn = lenval 4
14174if ge sub bn 1 9223372036854775807
14175note d2site 298|sf_num: number out of range for its type or place; condition if ge sub bn 1 9223372036854775807
14176put d2site 0 298
14177fail 8
14178end
14179end
14180if ne get xtarget 0 0
14181xfornum w t kk sn sh bn
14182ret
14183end
14184eol
14185i = alloc
14186put held 0 get nslot 0
14187addname w i t 0 0 0
14188emit or 3531603968 i
14189c = ulong 0
14190if ne bn 0
14191c = alloc
14192put held 0 get nslot 0
14193emit or 3531603968 c
14194end
14195hd = get oc 0
14196cp_head get cur 0 get line 0
14197if le kk 4095
14198emit or or 4043309087 shl kk 10 shl i 5
14199else
14200k = alloc
14201matconst k kk
14202emit or or 3942645791 shl i 5 shl k 16
14203end
14204br = sf_br t
14205if ne bn 0
14206lpcnt c bn
14207end
14208pushb br 4 hd i t
14209lpmark br kk 0
14210pushnh sn sh
14211cp_skip
14212end
14213
14214note sf_val: for i T K with K a value of type T in register kr: i = 0; the hidden counter c = 0; head: CMP
14215note Xi, Xk; B.HS/B.GE exit; the counter guard of a while: `bound N` (read as in sf_num), else 1000000.
14216note om4 SF_VAL.
14217fn sf_val w ulong t ulong kr ulong sn ulong sh ulong to void
14218n = ulong 1000000
14219if eq peekw 70
14220tok
14221n = lenval 4
14222if ge sub n 1 9223372036854775807
14223note d2site 299|sf_val: number out of range for its type or place; condition if ge sub n 1 9223372036854775807
14224put d2site 0 299
14225fail 8
14226end
14227end
14228if ne get xtarget 0 0
14229xforval w t kr sn sh n
14230ret
14231end
14232eol
14233i = alloc
14234put held 0 get nslot 0
14235addname w i t 0 0 0
14236emit or 3531603968 i
14237c = alloc
14238put held 0 get nslot 0
14239emit or 3531603968 c
14240hd = get oc 0
14241cp_head get cur 0 get line 0
14242emit or or 3942645791 shl kr 16 shl i 5
14243br = sf_br t
14244lpcnt c n
14245pushb br 4 hd i t
14246lpmark br 0 add kr 1
14247pushnh sn sh
14248cp_skip
14249end
14250
14251note s_for: for i T K [bound N]: i = 0; head: not i < K -> exit; body; latch i = add i 1; B head. K a number,
14252note or a value of type T: a name is read at every pass, another value once before the loop. More than N
14253note passes (default 1000000 for a value K, no limit for a number K) trap 4. om4 S_FOR.
14254fn s_for to void
14255sn = get nn 0
14256sh = get held 0
14257tok
14258if eq get tk 0 0
14259note d2site 300|s_for: the line ends where a word or value is needed; condition if eq get tk 0 0
14260put d2site 0 300
14261fail 4
14262end
14263if ne get tk 0 1
14264note d2site 301|s_for: syntax: unknown or misplaced word; condition if ne get tk 0 1
14265put d2site 0 301
14266fail 16
14267end
14268if gt get tl 0 63
14269note d2site 302|s_for: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
14270put d2site 0 302
14271fail 13
14272end
14273w = get tw 0
14274if ne kw w 0
14275note d2site 303|s_for: syntax: unknown or misplaced word; condition if ne kw w 0
14276put d2site 0 303
14277fail 16
14278end
14279newname w get tl 0 get ts 0
14280t = typeword
14281if or eq t 1 ge t 10
14282note d2site 304|s_for: type mismatch; condition if or eq t 1 ge t 10
14283put d2site 0 304
14284fail 7
14285end
14286tok
14287if eq get tk 0 0
14288note d2site 305|s_for: the line ends where a word or value is needed; condition if eq get tk 0 0
14289put d2site 0 305
14290fail 4
14291end
14292if eq get tk 0 2
14293range get tw 0 t get tbig 0
14294if ne get om2 0 0
14295kk = get tw 0
14296if eq peekw 181
14297s_unroll w t kk sn sh
14298ret
14299end
14300put tw 0 kk
14301end
14302sf_num w t get tw 0 sn sh
14303ret
14304end
14305rdval 1 t 255 0
14306if ne get rt 0 t
14307note d2site 306|s_for: type mismatch; condition if ne get rt 0 t
14308put d2site 0 306
14309fail 7
14310end
14311if ne get om2 0 0
14312if eq peekw 181
14313note d2site 307|s_for: syntax: unknown or misplaced word; condition if eq peekw 181
14314put d2site 0 307
14315fail 16
14316end
14317end
14318if eq get rk 0 3
14319sf_num w t get rv 0 sn sh
14320ret
14321end
14322kr = matreg get rk 0 get rv 0 get rt 0
14323sf_val w t kr sn sh
14324end
14325
14326note ======== OM-2 section 4: unroll, inline, folding, the growth bound and trap-site records ========
14327note peekstar: 1 when the next word is `*` (an unsized array, OM-2), without reading it
14328fn peekstar to ulong
14329c0 = get cur 0
14330l0 = get line 0
14331a0 = get tka 0
14332b0 = get tkb 0
14333tok
14334r = ulong 0
14335if and eq get tk 0 1 eq get tl 0 1
14336if eq get tw 0 42
14337r = ulong 1
14338end
14339end
14340put cur 0 c0
14341put line 0 l0
14342put tka 0 a0
14343put tkb 0 b0
14344ret r
14345end
14346
14347note peekw: the keyword code of the next word (0 for anything else) without reading it
14348fn peekw to ulong
14349c0 = get cur 0
14350l0 = get line 0
14351a0 = get tka 0
14352b0 = get tkb 0
14353tok
14354r = ulong 0
14355if eq get tk 0 1
14356if le get tl 0 8
14357r = kw get tw 0
14358end
14359end
14360put cur 0 c0
14361put line 0 l0
14362put tka 0 a0
14363put tkb 0 b0
14364ret r
14365end
14366
14367note s_unroll: for i T K unroll (K a number 1..64, error 8 outside). i is a constant name (kind 9) bound to
14368note 0..K-1 in turn; the body is read K times from its first line (s_unr). No branch is emitted.
14369fn s_unroll w ulong t ulong kk ulong sn ulong sh ulong to void
14370if or eq kk 0 gt kk 64
14371note d2site 308|s_unroll: number out of range for its type or place; condition if or eq kk 0 gt kk 64
14372put d2site 0 308
14373fail 8
14374end
14375fuelc get line 0 kk
14376tok
14377eol
14378addname w 0 t 0 9 0
14379n = get nb 0
14380pushb 0 5 0 sub get nn 0 1 t
14381pushnh sn sh
14382put a_ar add get a_rb 62 n get cur 0
14383put a_ar add get a_rb 63 n get line 0
14384put a_ar add get a_rb 64 n 0
14385put a_ar add get a_rb 65 n kk
14386put a_ar add get a_rb 66 n get nn 0
14387put a_ar add get a_rb 67 n get held 0
14388put fzone 0 add get fzone 0 1
14389cp_head get cur 0 get line 0
14390cp_skip
14391end
14392
14393note fuelc: charge n to the function's fuel at the construct on line ln, before anything of it expands; a
14394note total above 65536 is error 14 on line ln (E14, E16)
14395fn fuelc ln ulong n ulong to void
14396if gt add get fuel 0 n 65536
14397put line 0 ln
14398note d2site 309|fuelc: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if gt add get fuel 0 n 65536
14399put d2site 0 309
14400fail 14
14401end
14402put fuel 0 add get fuel 0 n
14403end
14404
14405note s_unr: the end of an unrolled body: read it again with the next value of i, or close the block
14406fn s_unr i ulong to void
14407eol
14408it = add get a_ar add get a_rb 64 i 1
14409if lt it get a_ar add get a_rb 65 i
14410put a_ar add get a_rb 64 i it
14411put a_ar add get a_rb 8 get a_ar add get a_rb 52 i it
14412nm_set get a_ar add get a_rb 66 i
14413put held 0 get a_ar add get a_rb 67 i
14414put nslot 0 get a_ar add get a_rb 67 i
14415put dead 0 0
14416put cur 0 get a_ar add get a_rb 62 i
14417put line 0 get a_ar add get a_rb 63 i
14418cp_head get cur 0 get line 0
14419cp_skip
14420ret
14421end
14422put a_ar add get a_rb 64 i it
14423put a_ar add get a_rb 8 get a_ar add get a_rb 52 i it
14424nm_set get a_ar add get a_rb 66 i
14425put nslot 0 get a_ar add get a_rb 67 i
14426cp_head get a_ar add get a_rb 62 i get a_ar add get a_rb 63 i
14427put nb 0 i
14428nm_set get a_ar add get a_rb 54 i
14429put held 0 get a_ar add get a_rb 55 i
14430put dead 0 0
14431put fzone 0 sub get fzone 0 1
14432end
14433
14434note fn_tail: the end of a fn line: an optional inline (OM-2), then the line ends; records the body start
14435fn fn_tail f ulong to void
14436tok
14437k = get tk 0
14438if eq k 1
14439if ne get om2 0 0
14440if le get tl 0 8
14441if eq kw get tw 0 182
14442a_pc 27 f 1
14443eol
14444put a_ar add get a_rb 28 f get cur 0
14445put a_ar add get a_rb 29 f get line 0
14446ret
14447end
14448end
14449end
14450end
14451if and ne k 0 ne k 3
14452put dexp 0 6
14453note d2site 310|fn_tail: extra words after a complete statement; condition if and ne k 0 ne k 3
14454put d2site 0 310
14455fail 5
14456end
14457put a_ar add get a_rb 28 f get cur 0
14458put a_ar add get a_rb 29 f get line 0
14459end
14460
14461note inl_call: a call of an inline function fe (index + 1): the result register first (dst, or the next
14462note pool slot), then the arguments left to right exactly as for a call, then the body in place.
14463fn inl_call fe ulong dst ulong to void
14464s0 = get nslot 0
14465rres = ulong 255
14466ns = s0
14467if ne uchar get a_ar add get a_rb 23 sub fe 1 12
14468if eq dst 255
14469rres = alloc
14470ns = add s0 1
14471else
14472rres = dst
14473end
14474end
14475cb = add mul get depth 0 32 8
14476np = ulong uchar get a_ar add get a_rb 24 sub fe 1
14477put a_ar add get a_rb 77 add cb 18 np
14478a_p 77 add cb 19 get nslot 0
14479i = ulong 0
14480while lt i np
14481p = add mul sub fe 1 6 i
14482if eq a_gu 37 p 0
14483rdval 0 ulong a_gu 35 p 255 0
14484ca_scal p add cb mul i 3
14485else
14486if ge a_gu 37 p 6
14487ca_st fe i cb
14488else
14489ca_arr fe i cb
14490end
14491end
14492i = add i 1
14493end
14494inl_body fe cb ns rres
14495end
14496
14497note inl_par: bind parameter i of inline function fe to its argument in frame cb. A scalar held in a
14498note temporary register (pool index hb or above) is taken as it is; any other scalar is copied to a new
14499note register. An array or struct takes its base register; a text's address is loaded into one. An
14500note unsized array parameter also takes its count register, or a new one holding a number count.
14501fn inl_par fe ulong cb ulong i ulong hb ulong to void
14502p = add mul sub fe 1 6 i
14503q = add cb mul i 3
14504k = get a_ar add get a_rb 77 q
14505v = get a_ar add get a_rb 77 add q 1
14506r = ulong 0
14507if eq a_gu 37 p 0
14508if and eq k 1 ge regidx v hb
14509r = v
14510else
14511r = alloc
14512force k v ulong a_gu 35 p r
14513end
14514else
14515if eq k 5
14516r = v
14517else
14518r = alloc
14519matconst r v
14520end
14521end
14522inl_add p r
14523if eq pwid p 2
14524inl_lr add mul div cb 32 6 i
14525end
14526fz_inl p a_g 77 add q 2
14527end
14528
14529note inl_lr: the unsized parameter name just added gets the count of argument ux (ul_k / ul_v): its
14530note register, or a new one holding the number
14531fn inl_lr ux ulong to void
14532lr = get a_ar add get a_rb 80 ux
14533if ne get a_ar add get a_rb 79 ux 1
14534lr = alloc
14535matconst lr get a_ar add get a_rb 80 ux
14536end
14537a_pc 14 sub get nn 0 1 uchar lr
14538end
14539
14540note inl_add: the name of parameter slot p on register r (a view struct is name kind 8, an edit one 7)
14541fn inl_add p ulong r ulong to void
14542pk = ulong uchar get a_ar add get a_rb 37 p
14543if eq pk 0
14544addname a_g 34 p r ulong a_gu 35 p 0 0 0
14545ret
14546end
14547nk = pk
14548if eq pk 6
14549nk = ulong 8
14550end
14551addname a_g 34 p r ulong a_gu 35 p a_g 36 p nk 0
14552a_pc 12 sub get nn 0 1 uchar get a_ar add get a_rb 38 p
14553end
14554
14555note inl_edge: record the call-graph edge (expanding function -> inline function) once (arena group 17)
14556fn inl_edge a ulong b ulong to void
14557n = get nie 0
14558j = ulong 0
14559go = true
14560while go
14561m = ulong 0
14562while and go lt m 999999
14563if ge j n
14564go = false
14565else
14566if and eq a_g 75 j a eq a_g 76 j b
14567ret
14568end
14569j = add j 1
14570end
14571m = add m 1
14572end
14573end
14574if ge n get a_gp 17
14575a_need 17 n
14576end
14577put a_ar add get a_rb 75 n a
14578put a_ar add get a_rb 76 n b
14579put nie 0 add n 1
14580end
14581
14582note inl_body: at most 4 nested inline frames (error 14); an inline function reached again while it is
14583note being inlined, or from its own body, is error 9. The caller's local names are hidden, the parameters
14584note bound, and the body's lines compiled here until its end (s_inlx) closes the frame.
14585note Each expansion costs one unit of the function's fuel (E14).
14586fn inl_body fe ulong cb ulong ns ulong rres ulong to void
14587lv = get inl 0
14588fuelc get line 0 1
14589if ge lv 4
14590note d2site 311|inl_body: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge lv 4
14591put d2site 0 311
14592fail 14
14593end
14594if eq get curfn 0 fe
14595note d2site 312|inl_body: word or declaration in a place that does not allow it; condition if eq get curfn 0 fe
14596put d2site 0 312
14597fail 9
14598end
14599j = ulong 0
14600while lt j lv
14601if eq get il_fn j fe
14602note d2site 313|inl_body: word or declaration in a place that does not allow it; condition if eq get il_fn j fe
14603put d2site 0 313
14604fail 9
14605end
14606j = add j 1
14607end
14608inl_edge get curfn 0 fe
14609put il_cur lv get cur 0
14610put il_line lv get line 0
14611put il_ret lv get curret 0
14612put il_nn lv get nn 0
14613put il_lo lv get nmlo 0
14614put il_held lv get held 0
14615put il_ns lv ns
14616put il_res lv rres
14617put il_fn lv fe
14618put il_p0 lv get nilp 0
14619put il_fz lv get fz_n 0
14620inl_bind fe cb
14621pushb 0 6 0 fe 0
14622pushnh get il_nn lv get il_held lv
14623put inl 0 add lv 1
14624put fzone 0 add get fzone 0 1
14625put curret 0 ulong a_gu 23 sub fe 1
14626put dead 0 0
14627put cur 0 get a_ar add get a_rb 28 sub fe 1
14628put line 0 get a_ar add get a_rb 29 sub fe 1
14629cp_entry
14630inl_run lv
14631end
14632
14633note inl_bind: hide the caller's local names, bind the parameters, protect every register in use
14634fn inl_bind fe ulong cb ulong to void
14635hb = add get npar 0 get held 0
14636put nmlo 0 get nn 0
14637np = ulong uchar get a_ar add get a_rb 24 sub fe 1
14638i = ulong 0
14639while lt i np
14640inl_par fe cb i hb
14641i = add i 1
14642end
14643put held 0 get nslot 0
14644end
14645
14646note inl_run: compile the inlined body's lines until its frame (level lv) is closed
14647fn inl_run lv ulong to void
14648go = true
14649while go
14650m = ulong 0
14651while and go lt m 999999
14652if ne stmt 0
14653note d2site 314|inl_run: missing end; condition if ne stmt 0
14654put d2site 0 314
14655fail 15
14656end
14657if le get inl 0 lv
14658go = false
14659end
14660m = add m 1
14661end
14662end
14663end
14664
14665note inlb: the B of an inlined ret, patched to the frame's end (arena group 16)
14666fn inlb to void
14667n = get nilp 0
14668if ge n get a_gp 16
14669a_need 16 n
14670end
14671put a_ar add get a_rb 74 n get oc 0
14672put nilp 0 add n 1
14673if ne get xtarget 0 0
14674p = xbranch 14
14675put a_ar add get a_rb 74 n p
14676else
14677emit 335544320
14678end
14679put lastb 0 get oc 0
14680end
14681
14682note s_iret: ret inside an inlined body: the value into the frame's result register, then B to its end
14683fn s_iret to void
14684lv = sub get inl 0 1
14685r = get curret 0
14686if eq r 12
14687eol
14688cp_post 0 0 r
14689inlb
14690dead1
14691ret
14692end
14693if and ne get cfhas get inl 0 0 eq get crel 0 0
14694rdval 0 r 255 0
14695if ne get rt 0 r
14696note d2site 315|s_iret: type mismatch; condition if ne get rt 0 r
14697put d2site 0 315
14698fail 7
14699end
14700rr = matreg get rk 0 get rv 0 r
14701eol
14702cp_post 1 rr r
14703force 1 rr r get il_res lv
14704else
14705rdval 0 r get il_res lv 0
14706if ne get rt 0 r
14707note d2site 316|s_iret: type mismatch; condition if ne get rt 0 r
14708put d2site 0 316
14709fail 7
14710end
14711force get rk 0 get rv 0 get rt 0 get il_res lv
14712eol
14713cp_post 1 get il_res lv r
14714end
14715inlb
14716dead1
14717end
14718
14719note s_inlx: the end of an inlined body: a value function must not reach it (error 18). A last ret's B
14720note that is the last word, with no branch patched to the place after it, is taken back; the other rets
14721note branch here. The caller's line, names, registers and return type come back; the result is in rk/rv/rt.
14722fn s_inlx i ulong to void
14723eol
14724lv = sub get inl 0 1
14725fe = get il_fn lv
14726if eq get dead 0 0
14727if ne uchar get a_ar add get a_rb 23 sub fe 1 12
14728note d2site 317|s_inlx: a function with a result can reach its end; condition if ne uchar get a_ar add get a_rb 23 sub fe 1 12
14729put d2site 0 317
14730fail 18
14731end
14732cp_post 0 0 12
14733end
14734inl_pat get il_p0 lv
14735put nb 0 i
14736put cur 0 get il_cur lv
14737put line 0 get il_line lv
14738put curret 0 get il_ret lv
14739nm_set get il_nn lv
14740put nmlo 0 get il_lo lv
14741put held 0 get il_held lv
14742put nslot 0 get il_ns lv
14743put dead 0 0
14744put inl 0 lv
14745put fzone 0 sub get fzone 0 1
14746put fz_n 0 get il_fz lv
14747put rk 0 1
14748put rv 0 get il_res lv
14749put rt 0 ulong uchar get a_ar add get a_rb 23 sub fe 1
14750end
14751
14752note inl_pat: patch the frame's ret B words (from p0) to here, after taking back a last one that is the
14753note last word and that no branch was patched past
14754fn inl_pat p0 ulong to void
14755n = get nilp 0
14756o = get oc 0
14757if and ne get dead 0 0 gt n p0
14758if eq get lastb 0 o
14759if ne get tgoc 0 o
14760if eq get a_ar add get a_rb 74 sub n 1 sub o 4
14761put oc 0 sub o 4
14762n = sub n 1
14763end
14764end
14765end
14766end
14767j = p0
14768go = true
14769while go
14770m = ulong 0
14771while and go lt m 999999
14772if ge j n
14773go = false
14774else
14775patch26 a_g 74 j get oc 0
14776j = add j 1
14777end
14778m = add m 1
14779end
14780end
14781put nilp 0 p0
14782end
14783
14784note ---- folding (only while fzone is above 0): an operation on two typed numbers is computed with OM-1
14785note arithmetic: unsigned wraps to its width, signed results are sign-extended; an operation that would
14786note trap (signed overflow, divide by 0, a shift or rotate amount at or above the width) is not folded.
14787fn fmask w ulong to ulong
14788if ge w 64
14789ret not ulong 0
14790end
14791ret sub shl ulong 1 w 1
14792end
14793
14794fn fasr x ulong s ulong to ulong
14795if eq shr x 63 0
14796ret shr x s
14797end
14798ret not shr not x s
14799end
14800
14801fn fsext r ulong w ulong to ulong
14802if ge w 64
14803ret r
14804end
14805ret fasr shl r sub 64 w sub 64 w
14806end
14807
14808fn fyes v ulong t ulong to void
14809put fval 0 v
14810put fty 0 t
14811put fok 0 1
14812end
14813
14814fn fb_cmp op ulong sg ulong a ulong b ulong to void
14815x = a
14816y = b
14817if ne sg 0
14818x = xor a shl ulong 1 63
14819y = xor b shl ulong 1 63
14820end
14821r = false
14822if eq op 43
14823r = eq x y
14824end
14825if eq op 44
14826r = ne x y
14827end
14828if eq op 45
14829r = lt x y
14830end
14831if eq op 46
14832r = le x y
14833end
14834if eq op 47
14835r = gt x y
14836end
14837if eq op 48
14838r = ge x y
14839end
14840v = ulong 0
14841if r
14842v = ulong 1
14843end
14844fyes v 1
14845end
14846
14847fn fb_arith op ulong ty ulong w ulong sg ulong a ulong b ulong to void
14848r = ulong 0
14849if eq op 33
14850r = add a b
14851end
14852if eq op 34
14853r = sub a b
14854end
14855if eq op 35
14856if ne sg 0
14857if ge add a shl ulong 1 31 shl ulong 1 32
14858ret
14859end
14860if ge add b shl ulong 1 31 shl ulong 1 32
14861ret
14862end
14863end
14864r = mul a b
14865end
14866if eq sg 0
14867fyes and r fmask w ty
14868ret
14869end
14870if eq w 64
14871if eq op 33
14872if ne shr and xor a r xor b r 63 0
14873ret
14874end
14875end
14876if eq op 34
14877if ne shr and xor a b xor a r 63 0
14878ret
14879end
14880end
14881fyes r ty
14882ret
14883end
14884if ne fsext r w r
14885ret
14886end
14887fyes r ty
14888end
14889
14890fn fb_div op ulong ty ulong w ulong sg ulong a ulong b ulong to void
14891if eq b 0
14892ret
14893end
14894if eq sg 0
14895if eq op 36
14896fyes div a b ty
14897else
14898fyes rem a b ty
14899end
14900ret
14901end
14902na = shr a 63
14903sb = shr b 63
14904ma = a
14905if ne na 0
14906ma = sub 0 a
14907end
14908mb = b
14909if ne sb 0
14910mb = sub 0 b
14911end
14912if eq op 37
14913rr = rem ma mb
14914if ne na 0
14915rr = sub 0 rr
14916end
14917fyes rr ty
14918ret
14919end
14920if eq w 64
14921if eq a shl ulong 1 63
14922if eq b not ulong 0
14923ret
14924end
14925end
14926end
14927q = div ma mb
14928if ne xor na sb 0
14929q = sub 0 q
14930end
14931if ne fsext q w q
14932ret
14933end
14934fyes q ty
14935end
14936
14937fn fb_shift op ulong ty ulong w ulong sg ulong a ulong b ulong to void
14938if ge b w
14939ret
14940end
14941if eq op 42
14942if eq sg 0
14943fyes shr a b ty
14944else
14945fyes fasr a b ty
14946end
14947ret
14948end
14949r = shl a b
14950if eq sg 0
14951fyes and r fmask w ty
14952ret
14953end
14954if eq w 64
14955if ne fasr r b a
14956ret
14957end
14958fyes r ty
14959ret
14960end
14961if ne fsext r w r
14962ret
14963end
14964fyes r ty
14965end
14966
14967fn fb_rot op ulong ty ulong w ulong a ulong b ulong to void
14968if ge b w
14969ret
14970end
14971s = b
14972if and eq op 60 ne s 0
14973s = sub w s
14974end
14975if eq s 0
14976fyes a ty
14977ret
14978end
14979fyes and or shr a s shl a sub w s fmask w ty
14980end
14981
14982note foldbin: op on the typed numbers a, b of type ty (b's own type for a shift); fok 1 when folded
14983fn foldbin op ulong ty ulong a ulong b ulong to void
14984put fok 0 0
14985if or eq ty 0 ge ty 10
14986ret
14987end
14988sg = ulong 0
14989if ge ty 6
14990sg = ulong 1
14991end
14992if and ge op 43 le op 48
14993fb_cmp op sg a b
14994ret
14995end
14996if and ge op 38 le op 40
14997r = and a b
14998if eq op 39
14999r = or a b
15000end
15001if eq op 40
15002r = xor a b
15003end
15004fyes r ty
15005ret
15006end
15007if eq ty 1
15008ret
15009end
15010w = twid ty
15011if le op 35
15012fb_arith op ty w sg a b
15013ret
15014end
15015if le op 37
15016fb_div op ty w sg a b
15017ret
15018end
15019if le op 42
15020fb_shift op ty w sg a b
15021ret
15022end
15023if or eq op 59 eq op 60
15024if le ty 5
15025fb_rot op ty w a b
15026end
15027end
15028end
15029
15030note foldun: neg (49) / not (50) of the typed number a
15031fn foldun c ulong ty ulong a ulong to void
15032put fok 0 0
15033if or eq ty 0 ge ty 10
15034ret
15035end
15036if eq c 50
15037if eq ty 1
15038fyes xor a 1 ty
15039ret
15040end
15041if lt ty 6
15042fyes and not a fmask twid ty ty
15043ret
15044end
15045fyes not a ty
15046ret
15047end
15048if eq ty 1
15049ret
15050end
15051r = sub 0 a
15052if lt ty 6
15053fyes and r fmask twid ty ty
15054ret
15055end
15056w = twid ty
15057if eq w 64
15058if eq a shl ulong 1 63
15059ret
15060end
15061fyes r ty
15062ret
15063end
15064if ne fsext r w r
15065ret
15066end
15067fyes r ty
15068end
15069
15070note ---- omc-site records (om2 diag): one per runtime trap site, in emission order, after the artifact
15071note on stderr: omc-site 1 line=N iter=k, k the counters of the open unrolled loops outer to inner
15072note joined by '.', or '-'.
15073fn siteb b ulong to void
15074n = get nsite 0
15075if ge n get a_gp 2
15076a_need 2 n
15077end
15078a_bput 2 n uchar b
15079put nsite 0 add n 1
15080end
15081
15082fn sitew w ulong n ulong to void
15083i = ulong 0
15084x = w
15085while lt i n
15086siteb and x 255
15087x = shr x 8
15088i = add i 1
15089end
15090end
15091
15092fn siten v ulong to void
15093d = new uchar 20 0
15094i = ulong 0
15095x = v
15096put d 0 uchar add rem x 10 48
15097x = div x 10
15098i = add i 1
15099while gt x 0
15100put d i uchar add rem x 10 48
15101x = div x 10
15102i = add i 1
15103end
15104j = i
15105while gt j 0
15106j = sub j 1
15107siteb ulong get d j
15108end
15109end
15110
15111fn siterec to void
15112sitew 7310584038532803951 8
15113sitew 4424063608026050848 8
15114siten add get line 0 get lbase 0
15115sitew 67561537693984 6
15116any = false
15117j = ulong 0
15118while lt j get nb 0
15119if eq get a_ar add get a_rb 49 j 5
15120if any
15121siteb 46
15122end
15123siten get a_ar add get a_rb 64 j
15124any = true
15125end
15126j = add j 1
15127end
15128if not any
15129siteb 45
15130end
15131siteb 10
15132end
15133
15134fn sitesout to void
15135z = a_out 2 2 0 get nsite 0
15136end
15137
15138note finish: end of a function: a function that needs a value must not reach its end (error 18), a void
15139note one returns; then the trap stubs of the sites no island took (stubs). om4 FINISH.
15140fn finish to void
15141if ne get xtarget 0 0
15142xfinish
15143ret
15144end
15145eol
15146if eq get dead 0 0
15147if ne get curret 0 12
15148note d2site 318|finish: a function with a result can reach its end; condition if ne get curret 0 12
15149put d2site 0 318
15150fail 18
15151end
15152cp_post 0 0 12
15153epi
15154end
15155nt0 = get nt 0
15156p0 = get tpend 0
15157if lt p0 nt0
15158stubs p0 nt0
15159end
15160put tpend 0 nt0
15161if ne get objmode 0 0
15162if or ne get osbad 0 0 ne get osp 0 0
15163note d2site 628|finish: word or declaration in a place that does not allow it; condition if or ne get osbad 0 0 ne get osp 0 0
15164put d2site 0 628
15165fail 9
15166end
15167a_p 86 sub get curfn 0 1 add get stkbytes 0 get osmax 0
15168end
15169put curret 0 0
15170nm_set get nglob 0
15171put curfn 0 0
15172put nbrk 0 0
15173put ncont 0 0
15174end
15175
15176note stubs: the trap stubs of trap sites p .. n - 1: shared tail, function mode MOV X0, X7; LDR X16,
15177note [X7, #16]; BR X16 (C6.2.282, C6.2.216, C6.2.46: OscRt.trap); program mode ADD X0, X1, #100; MOVZ X8,
15178note #93; SVC #0 (exit 100 + code). Per trap code used: MOVZ X1, #code (C6.2.285); B tail. Each site's
15179note B.cond is patched to its code's stub. om4 FINISH, for the sites of a whole function.
15180fn stubs p ulong n ulong to void
15181tail = get oc 0
15182if eq get progmode 0 0
15183emit 2852586464
15184emit 4181723376
15185emit 3592356352
15186else
15187if ne get xefa 0 0
15188note a64efi: ADD X0, X1, #100; ORR X0, X0, #2^63 (C6.2.240); B to the shared firmware return (aefx)
15189emit 2432798752
15190emit 2990604288
15191emit or 335544320 bdisp get oc 0 520 26
15192else
15193emit 2432798752
15194emit 3531606952
15195emit 3556769793
15196end
15197end
15198code = ulong 1
15199while le code 14
15200st = ulong 0
15201j = p
15202go = true
15203while go
15204m = ulong 0
15205while and go lt m 999999
15206if ge j n
15207go = false
15208else
15209if eq a_g 45 j code
15210if eq st 0
15211st = get oc 0
15212emit or 3531603969 shl code 5
15213back tail
15214end
15215patch19 a_g 44 j st
15216end
15217j = add j 1
15218end
15219m = add m 1
15220end
15221end
15222code = add code 1
15223end
15224end
15225
15226note island: a B.cond reaches 1 MiB (19-bit word field), and a function's stubs used to sit only at its
15227note end. When the oldest site no stub was patched to yet is 512 KiB back, B over a group of stubs here
15228note and patch the waiting sites to it (stubs), so a function of any length keeps every trap branch in
15229note reach. Only between lines of a function body (stmt: AArch64, not IR mode, no open inline frame, so
15230note never inside a contract's evaluation, which may expand an inline function and then erase its code)
15231note and outside every if, else, while and for (open unrolled bodies only, which no branch spans): an
15232note island never lengthens a block, so every block keeps the branch spans it had (an if or loop body over
15233note 1 MiB stays error 24, as before). A function whose sites never wait that long compiles as before.
15234fn island to void
15235p = get tpend 0
15236n = get nt 0
15237if ge p n
15238ret
15239end
15240if lt sub get oc 0 get a_ar add get a_rb 44 p 524288
15241ret
15242end
15243i = ulong 0
15244go = true
15245while go
15246m = ulong 0
15247while and go lt m 999999
15248if ge i get nb 0
15249go = false
15250else
15251k = get a_ar add get a_rb 49 i
15252if and ge k 1 le k 4
15253ret
15254end
15255i = add i 1
15256end
15257m = add m 1
15258end
15259end
15260bo = get oc 0
15261emit 335544320
15262stubs p n
15263patch26 bo get oc 0
15264put tpend 0 n
15265end
15266
15267note patchl: patch to t every entry of loop i in the break (w 0) or continue (w 1) list, from the list's
15268note count when loop i opened (bk0 / bc0) to its end
15269fn patchl w ulong i ulong t ulong to void
15270j = ulong 0
15271n = ulong 0
15272if eq w 0
15273j = get a_ar add get a_rb 60 i
15274n = get nbrk 0
15275else
15276j = get a_ar add get a_rb 61 i
15277n = get ncont 0
15278end
15279go = true
15280while go
15281m = ulong 0
15282while and go lt m 999999
15283if ge j n
15284go = false
15285else
15286if eq w 0
15287if eq get a_ar add get a_rb 71 j i
15288patch19 get a_ar add get a_rb 70 j t
15289put a_ar add get a_rb 71 j 65535
15290end
15291else
15292if eq get a_ar add get a_rb 73 j i
15293patch19 get a_ar add get a_rb 72 j t
15294put a_ar add get a_rb 73 j 65535
15295end
15296end
15297j = add j 1
15298end
15299m = add m 1
15300end
15301end
15302end
15303
15304note s_end: close the innermost block (if: patch its branch; else: patch its jump; while: B head; for: i =
15305note add i 1, B head), or the function. om4 S_END.
15306fn s_end to void
15307n = get nb 0
15308if eq n 0
15309finish
15310ret
15311end
15312i = sub n 1
15313if eq get a_ar add get a_rb 49 i 5
15314s_unr i
15315ret
15316end
15317if eq get a_ar add get a_rb 49 i 6
15318s_inlx i
15319ret
15320end
15321put nb 0 i
15322k = get a_ar add get a_rb 49 i
15323fz_join i k
15324if eq k 2
15325put dead 0 and get dead 0 get a_ar add get a_rb 56 i
15326else
15327put dead 0 0
15328end
15329if eq k 4
15330lat = get oc 0
15331patchl 1 i lat
15332put a_ar add get a_rb 77 0 1
15333a_p 77 1 a_g 52 i
15334a_p 77 2 a_g 53 i
15335put a_ar add get a_rb 77 3 3
15336put a_ar add get a_rb 77 4 1
15337a_p 77 5 a_g 53 i
15338binop 33 get a_ar add get a_rb 52 i 0
15339end
15340if eq k 3
15341patchl 1 i get a_ar add get a_rb 51 i
15342end
15343if ge k 3
15344if ne get a_ar add get a_rb 57 i 0
15345lpback i
15346else
15347back get a_ar add get a_rb 51 i
15348end
15349ex = get oc 0
15350note the breaks and continues of loop i are the entries recorded since it opened (bk0, bc0): an inner
15351note loop gave its own back when it closed, so this is linear in them, and they are given back below
15352patchl 0 i ex
15353put nbrk 0 get a_ar add get a_rb 60 i
15354put ncont 0 get a_ar add get a_rb 61 i
15355end
15356if eq k 2
15357if or eq get xtarget 0 0 eq get a_ar add get a_rb 56 i 0
15358patch26 get a_ar add get a_rb 50 i get oc 0
15359end
15360else
15361patch19 get a_ar add get a_rb 50 i get oc 0
15362end
15363nm_set get a_ar add get a_rb 54 i
15364put held 0 get a_ar add get a_rb 55 i
15365eol
15366end
15367
15368note ======== the end of the input: the output ========
15369note writeout: the output from byte st to the end, to stdout (error 2), then exit 0. om4 WRITEOUT.
15370fn writeout st ulong to void
15371if eq get chkmode 0 1
15372put mc 0 0
15373mputw 7594244768023276911 8
15374mputw 11207551510369 6
15375mflush
15376exit int 0
15377end
15378if eq get chkmode 0 3
15379a_rec 1
15380exit int 0
15381end
15382if ne get fmtm 0 0
15383fmtout
15384end
15385o = sub get oc 0 st
15386if eq get om2m 0 1
15387o = add o get nsite 0
15388end
15389a_ceilo o
15390if eq a_out 1 1 st get oc 0 0
15391note d2site 319|writeout: the compiler's standard output could not be written; condition if eq a_out 1 1 st get oc 0 0
15392put d2site 0 319
15393fail 2
15394end
15395if eq get om2m 0 1
15396sitesout
15397end
15398rc_emit st
15399exit int 0
15400end
15401
15402note elfhdr: the 176-byte file header (om4 ELFHDR, 44 words): ELF64 little-endian, executable, AArch64,
15403note entry 0x4000b0 (the word after the header), 2 program headers: code read+execute from 0x400000, and
15404note the read/write pools from 0x10000000. Only the words that are not 0 (the output starts at 0).
15405fn elfhdr to void
15406wrword 0 1179403647
15407wrword 4 65794
15408wrword 16 11993090
15409wrword 20 1
15410wrword 24 4194480
15411wrword 32 64
15412wrword 52 3670080
15413wrword 56 2
15414wrword 64 1
15415wrword 68 5
15416wrword 80 4194304
15417wrword 88 4194304
15418wrword 112 4096
15419wrword 120 1
15420wrword 124 6
15421wrword 136 268435456
15422wrword 144 268435456
15423wrword 168 4096
15424end
15425
15426note eof_prog: program mode: start code = MOVZ X28, #0x1000, LSL 16 (stack pool floor); MOVZ X16, #0x1080,
15427note LSL 16; MOV SP, X16 (ADD immediate, C6.2.5); BL main (C6.2.43); [MOVZ X0, #0 for a void main]; MOVZ X8,
15428note #93; SVC #0. The entry word after the header is a B to it; the header gets the file and pool sizes.
15429note om4 EOF_PROG. An OM-2 unit with pinned registers sets them (pinlo) just before the BL.
15430fn eof_prog to void
15431if ne get xtarget 0 0
15432xeof
15433ret
15434end
15435if ne get xefa 0 0
15436aeof
15437ret
15438end
15439f = findfn 1852399981 4 0
15440if eq f 0
15441note d2site 320|eof_prog: syntax: unknown or misplaced word; condition if eq f 0
15442put d2site 0 320
15443fail 16
15444end
15445if ne uchar get a_ar add get a_rb 24 sub f 1 0
15446note d2site 321|eof_prog: word or declaration in a place that does not allow it; condition if ne uchar get a_ar add get a_rb 24 sub f 1 0
15447put d2site 0 321
15448fail 9
15449end
15450wrword 176 or 335544320 bdisp 176 get oc 0 26
15451if ne get hostargs 0 0
15452note Preserve Linux's initial argument stack privately before installing Omega's bounded stack.
15453emit 2432697339
15454end
15455emit 3533832220
15456emit 3533836304
15457emit 2432696863
15458pinlo
15459emit or 2483027968 bdisp get oc 0 get a_ar add get a_rb 22 sub f 1 26
15460if eq uchar get a_ar add get a_rb 23 sub f 1 12
15461emit 3531603968
15462end
15463emit 3531606952
15464emit 3556769793
15465elfhdr
15466wrword 96 get oc 0
15467wrword 104 get oc 0
15468wrword 160 add get poolb 0 8388608
15469writeout 0
15470end
15471
15472note s_eof: end of input: no open function (error 15), some function (16); function mode: no globals or
15473note texts (9, fnstore; consts fold and are allowed); one function: its bare words; more: the entry word, a
15474note B to the last function. om4 S_EOF.
15475note Resolve every call after all addresses are known. In function mode a function is settled when every
15476note function it calls is (leaves of the call graph first); any function left unsettled forms or reaches a
15477note cycle (error 9). ksettle finds the same set as the old nf rounds over every call, in linear time.
15478fn resolve to void
15479n = get ncalls 0
15480i = ulong 0
15481go = true
15482while go
15483m = ulong 0
15484while and go lt m 999999
15485if ge i n
15486go = false
15487else
15488s = get a_ar add get a_rb 41 i
15489f = sub get a_ar add get a_rb 43 i 1
15490if ne get xtarget 0 0
15491wrword add s 1 sub a_g 22 f add s 5
15492else
15493if and ne get objmode 0 0 eq a_gu 32 f 2
15494wrword s 2483027968
15495else
15496wrword s or 2483027968 bdisp s get a_ar add get a_rb 22 f 26
15497end
15498end
15499i = add i 1
15500end
15501m = add m 1
15502end
15503end
15504if eq get progmode 0 0
15505ksettle n
15506kunset
15507end
15508end
15509
15510note ksettle: Kahn's order over the n call records (callfrom 0 is no function's call and is skipped).
15511note k_deg: the calls function f makes to functions not yet settled; k_st / k_ed: the callers of each
15512note callee, grouped by callee (k_st g .. k_st g + 1 - 1 in k_ed), k_cu the fill cursor; k_q: the
15513note settled functions in order. A function is settled when its count reaches 0. Arena groups 19, 20.
15514fn ksettle n ulong to void
15515fc = get nf 0
15516if ge fc get a_gp 19
15517a_need 19 fc
15518end
15519if ge n get a_gp 20
15520a_need 20 n
15521end
15522kcount n fc
15523kfill n fc
15524t = ulong 0
15525f = ulong 0
15526while lt f fc
15527if eq get a_ar add get a_rb 81 f 0
15528put a_ar add get a_rb 84 t f
15529t = add t 1
15530end
15531f = add f 1
15532end
15533h = ulong 0
15534go = true
15535while go
15536m = ulong 0
15537while and go lt m 999999
15538if ge h t
15539go = false
15540else
15541g = get a_ar add get a_rb 84 h
15542h = add h 1
15543a_pc 30 g 1
15544t = kpop g t
15545end
15546m = add m 1
15547end
15548end
15549end
15550
15551note kcount: k_deg and the per-callee counts k_st g + 1 from the call records, then k_st as starts
15552fn kcount n ulong fc ulong to void
15553f = ulong 0
15554while le f fc
15555put a_ar add get a_rb 81 f 0
15556put a_ar add get a_rb 82 f 0
15557f = add f 1
15558end
15559i = ulong 0
15560go = true
15561while go
15562m = ulong 0
15563while and go lt m 999999
15564if ge i n
15565go = false
15566else
15567a = get a_ar add get a_rb 42 i
15568if ne a 0
15569b = get a_ar add get a_rb 43 i
15570a_p 81 sub a 1 add a_g 81 sub a 1 1
15571a_p 82 b add a_g 82 b 1
15572end
15573i = add i 1
15574end
15575m = add m 1
15576end
15577end
15578f = ulong 1
15579while le f fc
15580a_p 82 f add a_g 82 f a_g 82 sub f 1
15581f = add f 1
15582end
15583end
15584
15585note kfill: each call record's caller into k_ed at its callee's place
15586fn kfill n ulong fc ulong to void
15587f = ulong 0
15588while lt f fc
15589a_p 83 f a_g 82 f
15590f = add f 1
15591end
15592i = ulong 0
15593go = true
15594while go
15595m = ulong 0
15596while and go lt m 999999
15597if ge i n
15598go = false
15599else
15600a = get a_ar add get a_rb 42 i
15601if ne a 0
15602g = sub a_g 43 i 1
15603a_p 85 a_g 83 g sub a 1
15604a_p 83 g add a_g 83 g 1
15605end
15606i = add i 1
15607end
15608m = add m 1
15609end
15610end
15611end
15612
15613note kpop: function g is settled: each caller's count drops by one per call; a caller at 0 joins the
15614note queue at t. Returns the new end of the queue.
15615fn kpop g ulong t ulong to ulong
15616e = get a_ar add get a_rb 82 add g 1
15617j = get a_ar add get a_rb 82 g
15618q = t
15619go = true
15620while go
15621m = ulong 0
15622while and go lt m 999999
15623if ge j e
15624go = false
15625else
15626c = get a_ar add get a_rb 85 j
15627d = sub a_g 81 c 1
15628a_p 81 c d
15629if eq d 0
15630a_p 84 q c
15631q = add q 1
15632end
15633j = add j 1
15634end
15635m = add m 1
15636end
15637end
15638ret q
15639end
15640
15641note kunset: a function ksettle left unsettled is error 9 at the end of the input
15642fn kunset to void
15643f = ulong 0
15644while lt f get nf 0
15645if eq uchar get a_ar add get a_rb 30 f 0
15646put dsev 0 3
15647note d2site 322|kunset: word or declaration in a place that does not allow it; condition if eq uchar get a_ar add get a_rb 30 f 0
15648put d2site 0 322
15649fail 9
15650end
15651f = add f 1
15652end
15653end
15654
15655note reachself: 1 when function f (index + 1) reaches itself
15656fn reachself f ulong to ulong
15657i = ulong 0
15658while lt i get nf 0
15659a_pc 31 i 0
15660i = add i 1
15661end
15662a_pc 31 sub f 1 1
15663go = true
15664pass = ulong 0
15665while and go le pass get nf 0
15666r = rscan f 0
15667if eq r 2
15668ret 1
15669end
15670s = rscan f 1
15671if eq s 2
15672ret 1
15673end
15674go = or ne r 0 ne s 0
15675pass = add pass 1
15676end
15677ret 0
15678end
15679
15680note rscan: one pass over the calls (w 0) or the inline edges (w 1): 2 when an edge from a reached
15681note function leads to f, 1 when a function was newly reached, else 0. A pass reads only its own regions: the
15682note calls (42/43) below ncalls or the inline edges (75/76) below nie. (Reading the call regions at an edge
15683note index ran past them once the edges outnumbered their room: trap 3 in omc c52e986e and 1e628c80.)
15684fn rscan f ulong w ulong to ulong
15685n = get ncalls 0
15686ra = ulong 42
15687rb = ulong 43
15688if ne w 0
15689n = get nie 0
15690ra = ulong 75
15691rb = ulong 76
15692end
15693ch = ulong 0
15694j = ulong 0
15695go = true
15696while go
15697m = ulong 0
15698while and go lt m 999999
15699if ge j n
15700go = false
15701else
15702a = a_g ra j
15703b = a_g rb j
15704if ne a_gu 31 sub a 1 0
15705if eq b f
15706ret 2
15707end
15708if eq a_gu 31 sub b 1 0
15709a_pc 31 sub b 1 1
15710ch = ulong 1
15711end
15712end
15713j = add j 1
15714end
15715m = add m 1
15716end
15717end
15718ret ch
15719end
15720
15721fn s_eof to void
15722if eq get chkmode 0 2
15723emit_query
15724end
15725if ne get curret 0 0
15726note d2site 323|s_eof: missing end; condition if ne get curret 0 0
15727put d2site 0 323
15728fail 15
15729end
15730if eq get nf 0 0
15731note d2site 324|s_eof: syntax: unknown or misplaced word; condition if eq get nf 0 0
15732put d2site 0 324
15733fail 16
15734end
15735if ne get om2 0 0
15736note inlcyc (OM-2): an inline function that reaches itself through the whole call graph (the calls made,
15737note plus an edge from each function to every inline function expanded in it) is error 9 at the end.
15738f = ulong 1
15739while le f get nf 0
15740if ne uchar get a_ar add get a_rb 27 sub f 1 0
15741if ne reachself f 0
15742put dsev 0 3
15743note d2site 325|s_eof: word or declaration in a place that does not allow it; condition if ne reachself f 0
15744put d2site 0 325
15745fail 9
15746end
15747end
15748f = add f 1
15749end
15750end
15751resolve
15752if ne get progmode 0 0
15753eof_prog
15754end
15755if eq get progmode 0 0
15756note fnstore: function mode. A top-level global pool (kind 4) or text (kind 5) needs the program image and
15757note is error 9; a const (kind 9) is folded to a typed number wherever it is read, so it composes here too.
15758i = ulong 0
15759go = true
15760while go
15761m = ulong 0
15762while and go lt m 999999
15763if ge i get nglob 0
15764go = false
15765else
15766if ne uchar get a_ar add get a_rb 7 i 9
15767note d2site 326|s_eof: word or declaration in a place that does not allow it; condition if ne uchar get a_ar add get a_rb 7 i 9
15768put d2site 0 326
15769fail 9
15770end
15771i = add i 1
15772end
15773m = add m 1
15774end
15775end
15776end
15777if ne get objmode 0 0
15778obj_write
15779end
15780if ne get xtarget 0 0
15781note Bare x86 units share the private frame ABI; exports have six-byte JMP/NOP slots.
15782n = get nexp 0
15783p = ulong 512
15784f = ulong 0
15785while lt f get nf 0
15786take = ne uchar get a_ar add get a_rb 32 f 0
15787if eq n 0
15788take = eq f sub get lastfn 0 1
15789end
15790if take
15791a_bput 1 p 233
15792wrword add p 1 sub get a_ar add get a_rb 22 f add p 5
15793a_bput 1 add p 5 144
15794p = add p 6
15795end
15796f = add f 1
15797end
15798writeout 512
15799end
15800if ne get nexp 0 0
15801note expwords (OM-2, spec 6): words 0 .. E-1 of a multi-entry unit, B to each export in source order
15802at = ulong 176
15803f = ulong 0
15804while lt f get nf 0
15805if ne uchar get a_ar add get a_rb 32 f 0
15806wrword at or 335544320 bdisp at get a_ar add get a_rb 22 f 26
15807at = add at 4
15808end
15809f = add f 1
15810end
15811writeout 176
15812end
15813if eq get nf 0 1
15814writeout 180
15815end
15816a = get a_ar add get a_rb 22 sub get lastfn 0 1
15817wrword 176 or 335544320 bdisp 176 a 26
15818writeout 176
15819end
15820
15821note stmt: one line. Returns 1 at the end of the input. om4 STMT.
15822fn stmt to ulong
15823put dexp 0 0
15824put nslot 0 get held 0
15825if lt get tpend 0 get nt 0
15826if and ne get curret 0 0 eq get inl 0 0
15827if and eq get xtarget 0 0 eq get irmode 0 0
15828island
15829end
15830end
15831end
15832tok
15833k = get tk 0
15834if eq k 0
15835ret 0
15836end
15837if eq k 3
15838s_eof
15839ret 1
15840end
15841if ne k 1
15842note d2site 327|stmt: syntax: unknown or misplaced word; condition if ne k 1
15843put d2site 0 327
15844fail 16
15845end
15846if and ne get chkmode 0 0 eq get line 0 get chkln 0
15847skipnl
15848ret 0
15849end
15850if and ne get om2 0 0 eq get line 0 get om2ln 0
15851skipnl
15852ret 0
15853end
15854if ne get objmode 0 0
15855if and eq get tl 0 6 eq get tw 0 121437607458917
15856s_extern
15857ret 0
15858end
15859end
15860if ne cp_kind 0
15861note d2site 328|stmt: contract syntax misplaced or not supported here (IR mode included); condition if ne cp_kind 0
15862put d2site 0 328
15863fail 30
15864end
15865if gt get tl 0 8
15866note s_long: a word over 8 characters at the start of a line: a call of a void function (om4 S_LONG), or
15867note a long name of up to 63 bytes, which goes on below as a short name does.
15868if eq get curret 0 0
15869note d2site 329|stmt: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if eq get curret 0 0
15870put d2site 0 329
15871fail 13
15872end
15873if ne get dead 0 0
15874note d2site 330|stmt: line after ret, break, continue, trap or exit in the same block; condition if ne get dead 0 0
15875put d2site 0 330
15876fail 17
15877end
15878f = findfn get tw 0 get tl 0 get ts 0
15879if eq f 0
15880if gt get tl 0 63
15881note d2site 331|stmt: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
15882put d2site 0 331
15883unkfail 13
15884end
15885else
15886if ne uchar get a_ar add get a_rb 23 sub f 1 12
15887note d2site 332|stmt: type mismatch; condition if ne uchar get a_ar add get a_rb 23 sub f 1 12
15888put d2site 0 332
15889fail 7
15890end
15891rdval 2 0 255 f
15892eol
15893ret 0
15894end
15895end
15896w = get tw 0
15897c = kw w
15898if eq c 83
15899skipnl
15900ret 0
15901end
15902if eq c 64
15903s_fn
15904ret 0
15905end
15906if eq get curret 0 0
15907if eq c 78
15908s_global
15909ret 0
15910end
15911if eq c 79
15912s_text
15913ret 0
15914end
15915if eq c 152
15916s_const
15917ret 0
15918end
15919if eq c 85
15920skipnl
15921ret 0
15922end
15923if eq c 195
15924s_export
15925ret 0
15926end
15927if eq c 188
15928note s_lyskip: the body pass jumps to the place after the layout's end (read in the names pass)
15929tok
15930li = sub findlay get tw 0 1
15931put cur 0 get ly_ec li
15932put line 0 get ly_el li
15933ret 0
15934end
15935if or eq c 184 eq c 187
15936skipnl
15937ret 0
15938end
15939note d2site 333|stmt: syntax: unknown or misplaced word; condition if eq get curret 0 0
15940put d2site 0 333
15941fail 16
15942end
15943if eq c 66
15944s_end
15945ret 0
15946end
15947if eq c 68
15948s_else
15949ret 0
15950end
15951if ne get dead 0 0
15952note d2site 334|stmt: line after ret, break, continue, trap or exit in the same block; condition if ne get dead 0 0
15953put d2site 0 334
15954fail 17
15955end
15956if eq c 0
15957s_name w
15958ret 0
15959end
15960if eq c 67
15961note s_if: if cond: the false branch is patched at else / end. om4 S_IF.
15962at = cond
15963pushb at 1 0 0 0
15964pushnh get nn 0 get held 0
15965eol
15966ret 0
15967end
15968if eq c 69
15969s_while
15970ret 0
15971end
15972if eq c 71
15973s_for
15974ret 0
15975end
15976if eq c 72
15977s_ret
15978ret 0
15979end
15980if eq c 80
15981s_put
15982ret 0
15983end
15984if eq c 82
15985eff_rec 82
15986note exit compiles the same in a native object as in function mode.
15987note s_exit: exit value (int): Linux exit (system call 93: MOVZ X8, #93, C6.2.285; SVC #0, C6.2.466); the
15988note path ends. om4 S_EXIT.
15989rdval 0 8 255 0
15990if ne get rt 0 8
15991note d2site 336|stmt: type mismatch; condition if ne get rt 0 8
15992put d2site 0 336
15993fail 7
15994end
15995force get rk 0 get rv 0 get rt 0 0
15996if ne get xtarget 0 0
15997xload 0 0
15998xleave
15999else
16000if ne get xefa 0 0
16001emit or 335544320 bdisp get oc 0 520 26
16002else
16003emit 3531606952
16004emit 3556769793
16005end
16006end
16007dead1
16008eol
16009ret 0
16010end
16011if eq c 86
16012s_break
16013ret 0
16014end
16015if eq c 87
16016note s_trap: trap N (1 .. 14): an always-taken branch to the trap stub for code N, which finish makes.
16017note Program mode exits 100 + N; function mode calls OscRt.trap (OMEGESE 9.1). The line ends the path.
16018v = lenval 4
16019if or lt v 1 gt v 14
16020note d2site 337|stmt: number out of range for its type or place; condition if or lt v 1 gt v 14
16021put d2site 0 337
16022fail 8
16023end
16024trapc 14 v
16025dead1
16026eol
16027ret 0
16028end
16029note cpufence (keyword 199, a statement without operands): the host CPU publication barrier. AArch64:
16030note DSB SY (d5033f9f, the full-system barrier mapget/mapset already bracket their access with). x86-64:
16031note MFENCE (0F AE F0), the fence the x86 mapget/mapset use. Every earlier load and store completes before
16032note any later one, so a GPU or another CPU that observes a later store also observes the earlier ones.
16033note Inline here, not a function: om4 builds omc and holds at most 512 functions, 511 in use.
16034if eq c 199
16035eff_rec 199
16036if ne get objmode 0 0
16037note d2site 338|stmt: word or declaration in a place that does not allow it; condition if ne get objmode 0 0
16038put d2site 0 338
16039fail 9
16040end
16041eol
16042if ne get xtarget 0 0
16043xb 15 174 240
16044else
16045emit 3573759903
16046end
16047ret 0
16048end
16049note cpurelax (keyword 200, a statement without operands): spin-wait hint, no ordering. AArch64: YIELD
16050note (d503203f). x86-64: PAUSE (F3 90). Use it in a bounded poll loop; pair it with cpufence for order.
16051if eq c 200
16052eff_rec 200
16053if ne get objmode 0 0
16054note d2site 339|stmt: word or declaration in a place that does not allow it; condition if ne get objmode 0 0
16055put d2site 0 339
16056fail 9
16057end
16058eol
16059if ne get xtarget 0 0
16060emitb 243
16061emitb 144
16062else
16063emit 3573751871
16064end
16065ret 0
16066end
16067if eq c 97
16068s_cont
16069ret 0
16070end
16071if or or or eq c 77 eq c 78 eq c 79 eq c 81
16072note d2site 340|stmt: word or declaration in a place that does not allow it; condition if or or or eq c 77 eq c 78 eq c 79 eq c 81
16073put d2site 0 340
16074fail 9
16075end
16076if or eq c 85 eq c 193
16077note d2site 341|stmt: word or declaration in a place that does not allow it; condition if or eq c 85 eq c 193
16078put d2site 0 341
16079fail 9
16080end
16081note d2site 342|stmt: syntax: unknown or misplaced word
16082put d2site 0 342
16083fail 16
16084ret 0
16085end
16086
16087note ======== program mode: some line is `fn main` (blanks, fn, blanks, main, then a blank or the end) ========
16088note skipbl: the first place at or after q that is not a space or tab (or the end)
16089fn skipbl q ulong to ulong
16090e = get inlen 0
16091p = q
16092go = true
16093while go
16094m = ulong 0
16095while and go lt m 999999
16096if ge p e
16097go = false
16098else
16099b = a_ib p
16100if or eq b 32 eq b 9
16101p = add p 1
16102else
16103go = false
16104end
16105end
16106m = add m 1
16107end
16108end
16109ret p
16110end
16111
16112note skipln: the place after the next newline at or after q (or the end)
16113fn skipln q ulong to ulong
16114e = get inlen 0
16115p = q
16116go = true
16117while go
16118m = ulong 0
16119while and go lt m 999999
16120if ge p e
16121go = false
16122else
16123b = a_ib p
16124p = add p 1
16125if eq b 10
16126go = false
16127end
16128end
16129m = add m 1
16130end
16131end
16132ret p
16133end
16134
16135note ps_at: the line's first byte that is not blank is at p: 1 when the line is `fn main`, 2 when the input
16136note ends while deciding, else 0. om4 PS_LINE .. PS_YES.
16137fn ps_at p ulong to ulong
16138e = get inlen 0
16139if ne uchar and shr get a_ar shr p 3 shl and p 7 3 255 102
16140ret 0
16141end
16142q = add p 1
16143if ge q e
16144ret 2
16145end
16146if ne uchar and shr get a_ar shr q 3 shl and q 7 3 255 110
16147ret 0
16148end
16149r = add q 1
16150q = skipbl r
16151if ge q e
16152ret 2
16153end
16154if eq q r
16155ret 0
16156end
16157if gt add q 4 e
16158ret 0
16159end
16160if ne uchar and shr get a_ar shr q 3 shl and q 7 3 255 109
16161ret 0
16162end
16163if ne a_ib add q 1 97
16164ret 0
16165end
16166if ne a_ib add q 2 105
16167ret 0
16168end
16169if ne a_ib add q 3 110
16170ret 0
16171end
16172if ge add q 4 e
16173ret 1
16174end
16175if gt a_ib add q 4 32
16176ret 0
16177end
16178ret 1
16179end
16180
16181fn prescan to void
16182e = get inlen 0
16183p = ulong 0
16184go = true
16185while go
16186m = ulong 0
16187while and go lt m 999999
16188p = skipbl p
16189if ge p e
16190go = false
16191else
16192r = ps_at p
16193if eq r 1
16194put progmode 0 1
16195go = false
16196end
16197if eq r 2
16198go = false
16199end
16200if go
16201p = skipln p
16202if ge p e
16203go = false
16204end
16205end
16206end
16207m = add m 1
16208end
16209end
16210end
16211
16212note First collect signatures. Only fn headers are parsed here; other lines are read in the body pass.
16213fn namescan to void
16214put scanning 0 1
16215put line 0 1
16216go = true
16217while go
16218n = ulong 0
16219while and go lt n 999999
16220tok
16221if eq get tk 0 3
16222go = false
16223else
16224if ne get tk 0 0
16225if and eq get tk 0 1 eq get tw 0 28262
16226s_fn
16227else
16228if and eq get tk 0 1 eq get tw 0 127970521019507
16229s_struct
16230else
16231if and eq get tk 0 1 eq get tw 0 500152823651
16232s_const
16233else
16234if eq ns_om2 0
16235skipnl
16236end
16237end
16238end
16239end
16240end
16241end
16242n = add n 1
16243end
16244end
16245put scanning 0 0
16246put cur 0 0
16247put line 0 1
16248nm_set 0
16249put nglob 0 0
16250put curfn 0 0
16251put curret 0 0
16252put npar 0 0
16253put nslot 0 0
16254for j ulong 16
16255put vsl j 0
16256end
16257put held 0 0
16258end
16259
16260note ======== R6 structs (omc only; om4 stays the parent that rebuilds this file) ========
16261note A struct is 8-byte cells, declaration order, no padding (OSC-2). new is a stack slot, given
16262note back at ret, like a local array. There is no free (decision 24). Field scale: cell << (3 - tlog)
16263note so a typed store lands on cell * 8. Pack of struct is 127970521019507 (Wolfram, little-endian).
16264
16265note findstruct: packed name -> index + 1, or 0
16266fn findstruct w ulong to ulong
16267i = ulong 0
16268n = get nst 0
16269while lt i n
16270if eq get st_name i w
16271ret add i 1
16272end
16273i = add i 1
16274end
16275ret 0
16276end
16277
16278note findfield: struct index, packed field name -> field-table index + 1, or 0
16279fn findfield si ulong w ulong to ulong
16280fo = ulong get st_foff si
16281nfd = ulong get st_nf si
16282i = ulong 0
16283while lt i nfd
16284j = add fo i
16285if eq get sf_name j w
16286ret add j 1
16287end
16288i = add i 1
16289end
16290ret 0
16291end
16292
16293note field_dup: 1 if w is already a field of the struct being read (fields fo .. nsf)
16294fn field_dup fo ulong w ulong to ulong
16295i = fo
16296e = get nsf 0
16297while lt i e
16298if eq get sf_name i w
16299ret 1
16300end
16301i = add i 1
16302end
16303ret 0
16304end
16305
16306note s_field: the current word is a field name of struct w. Returns the cell count after this field.
16307fn s_field w ulong fo ulong cells ulong to ulong
16308if gt get tl 0 63
16309note d2site 343|s_field: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
16310put d2site 0 343
16311fail 13
16312end
16313if ne kw get tw 0 0
16314note d2site 344|s_field: syntax: unknown or misplaced word; condition if ne kw get tw 0 0
16315put d2site 0 344
16316fail 16
16317end
16318fw = get tw 0
16319if eq fw w
16320note d2site 345|s_field: duplicate name; condition if eq fw w
16321put d2site 0 345
16322fail 10
16323end
16324if ne findstruct fw 0
16325note d2site 346|s_field: duplicate name; condition if ne findstruct fw 0
16326put d2site 0 346
16327fail 10
16328end
16329if ne field_dup fo fw 0
16330note d2site 347|s_field: duplicate name; condition if ne field_dup fo fw 0
16331put d2site 0 347
16332fail 10
16333end
16334t = typeword
16335if ge t 64
16336note d2site 348|s_field: type mismatch; condition if ge t 64
16337put d2site 0 348
16338fail 7
16339end
16340ln = ulong 0
16341p = get cur 0
16342ln0 = get line 0
16343tok
16344k = get tk 0
16345if eq k 2
16346ln = get tw 0
16347if ne get tbig 0 0
16348note d2site 349|s_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ne get tbig 0 0
16349put d2site 0 349
16350fail 14
16351end
16352if or eq ln 0 gt ln 64
16353note d2site 350|s_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if or eq ln 0 gt ln 64
16354put d2site 0 350
16355fail 14
16356end
16357else
16358if eq k 1
16359e = findname get tw 0
16360if ne e 0
16361if eq a_gu 7 sub e 1 9
16362ct = ulong a_gu 5 sub e 1
16363if ge ct 10
16364note d2site 351|s_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge ct 10
16365put d2site 0 351
16366fail 14
16367end
16368ln = a_g 8 sub e 1
16369if or eq ln 0 gt ln 64
16370note d2site 352|s_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if or eq ln 0 gt ln 64
16371put d2site 0 352
16372fail 14
16373end
16374else
16375put cur 0 p
16376put line 0 ln0
16377end
16378else
16379put cur 0 p
16380put line 0 ln0
16381end
16382else
16383put cur 0 p
16384put line 0 ln0
16385end
16386end
16387addc = ulong 1
16388if ne ln 0
16389addc = ln
16390end
16391if gt add cells addc 64
16392note d2site 353|s_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if gt add cells addc 64
16393put d2site 0 353
16394fail 14
16395end
16396put sf_name get nsf 0 fw
16397put sf_type get nsf 0 uchar t
16398put sf_len get nsf 0 uchar ln
16399put sf_off get nsf 0 uchar cells
16400put nsf 0 add get nsf 0 1
16401ret add cells addc
16402end
16403
16404note s_struct: struct Name (field type [len])* end. Before any fn (namescan). 1..16 fields, <= 64 cells.
16405fn s_struct to void
16406if ne get nf 0 0
16407note d2site 354|s_struct: word or declaration in a place that does not allow it; condition if ne get nf 0 0
16408put d2site 0 354
16409fail 9
16410end
16411tok
16412if ne get tk 0 1
16413note d2site 355|s_struct: syntax: unknown or misplaced word; condition if ne get tk 0 1
16414put d2site 0 355
16415fail 16
16416end
16417if gt get tl 0 63
16418note d2site 356|s_struct: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
16419put d2site 0 356
16420fail 13
16421end
16422if ne kw get tw 0 0
16423note d2site 357|s_struct: syntax: unknown or misplaced word; condition if ne kw get tw 0 0
16424put d2site 0 357
16425fail 16
16426end
16427w = get tw 0
16428if ne findstruct w 0
16429note d2site 358|s_struct: duplicate name; condition if ne findstruct w 0
16430put d2site 0 358
16431fail 10
16432end
16433if ne findfn w get tl 0 get ts 0 0
16434note d2site 359|s_struct: duplicate name; condition if ne findfn w get tl 0 get ts 0 0
16435put d2site 0 359
16436fail 10
16437end
16438if ge get nst 0 16
16439note d2site 360|s_struct: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge get nst 0 16
16440put d2site 0 360
16441fail 14
16442end
16443sid = get nst 0
16444fo = get nsf 0
16445cells = ulong 0
16446nfld = ulong 0
16447go = true
16448while go
16449tok
16450if eq get tk 0 0
16451note d2site 361|s_struct: the line ends where a word or value is needed; condition if eq get tk 0 0
16452put d2site 0 361
16453fail 4
16454end
16455if ne get tk 0 1
16456note d2site 362|s_struct: syntax: unknown or misplaced word; condition if ne get tk 0 1
16457put d2site 0 362
16458fail 16
16459end
16460if eq kw get tw 0 66
16461go = false
16462else
16463if ge nfld 16
16464note d2site 363|s_struct: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge nfld 16
16465put d2site 0 363
16466fail 14
16467end
16468cells = s_field w fo cells
16469nfld = add nfld 1
16470end
16471end
16472if eq nfld 0
16473note d2site 364|s_struct: syntax: unknown or misplaced word; condition if eq nfld 0
16474put d2site 0 364
16475fail 16
16476end
16477put st_name sid w
16478put st_nf sid uchar nfld
16479put st_cells sid uchar cells
16480put st_foff sid uchar fo
16481put nst 0 add sid 1
16482eol
16483end
16484
16485note peek_struct: if the next word is a struct name, consume it and return index + 1; else rewind
16486fn peek_struct to ulong
16487p = get cur 0
16488ln = get line 0
16489tok
16490if ne get tk 0 1
16491put cur 0 p
16492put line 0 ln
16493ret 0
16494end
16495sid = findstruct get tw 0
16496if eq sid 0
16497put cur 0 p
16498put line 0 ln
16499ret 0
16500end
16501ret sid
16502end
16503
16504note fn_p_st: parameter pw is view (k 2, name kind 8) or edit (k 3, name kind 7). fn_pk is 6 or 7.
16505fn fn_p_st f ulong np ulong pw ulong sid ulong k ulong to void
16506si = sub sid 1
16507t = add si 16
16508ln = ulong get st_cells si
16509sk = add k 4
16510if eq k 2
16511addname pw poolc get psl 0 t ln 8 0
16512else
16513addname pw poolc get psl 0 t ln 7 0
16514end
16515p = add mul f 6 np
16516a_pc 35 p uchar t
16517put a_ar add get a_rb 36 p ln
16518a_pc 37 p uchar sk
16519end
16520
16521note sa_new: name = new <type or struct>. Rewind unless the next word is a struct name.
16522fn sa_new w ulong to void
16523if ne get om2 0 0
16524if ne get inl 0 0
16525note d2site 365|sa_new: word or declaration in a place that does not allow it; condition if ne get inl 0 0
16526put d2site 0 365
16527fail 9
16528end
16529if ne uchar get a_ar add get a_rb 27 sub get curfn 0 1 0
16530note d2site 366|sa_new: word or declaration in a place that does not allow it; condition if ne uchar get a_ar add get a_rb 27 sub get curfn 0 1 0
16531put d2site 0 366
16532fail 9
16533end
16534end
16535p = get cur 0
16536ln = get line 0
16537tok
16538sid = ulong 0
16539if eq get tk 0 1
16540sid = findstruct get tw 0
16541end
16542if ne sid 0
16543sa_st w sid
16544ret
16545end
16546put cur 0 p
16547put line 0 ln
16548sa_arr w
16549end
16550
16551note st_read: one value per field, saved in svk/svv/svt. An array field takes one value.
16552fn st_read si ulong to void
16553fo = ulong get st_foff si
16554nfd = ulong get st_nf si
16555i = ulong 0
16556while lt i nfd
16557ft = ulong get sf_type add fo i
16558rdval 0 ft 255 0
16559if ne get rt 0 ft
16560note d2site 367|st_read: type mismatch; condition if ne get rt 0 ft
16561put d2site 0 367
16562fail 7
16563end
16564put svk i get rk 0
16565put svv i get rv 0
16566put svt i get rt 0
16567i = add i 1
16568end
16569end
16570
16571note st_store: STR of v at cell, scaled so the typed store lands on cell * 8. ADD is not used; the
16572note index register holds cell << (3 - tlog). STR register-offset is the STOP table (om4).
16573fn st_store base ulong idx ulong cell ulong t ulong v ulong to void
16574matconst idx shl cell sub 3 tlog t
16575put ea_b 0 base
16576put ea_i 0 idx
16577stel t v
16578end
16579
16580note st_ixreg: runtime element index iv, field length fl, cell offset off. CMP + B.HS trap 3
16581note (elemaddr, C6.2.96 / C6.2.34), then ADD Xidx, Xiv, #off (C6.2.5, base word 2432696320) and
16582note LSL by 3 - tlog (bo_lsl) so the STOP store lands on (off + i) * 8.
16583fn st_ixreg idx ulong iv ulong off ulong fl ulong t ulong to void
16584if ne get xtarget 0 0
16585xcmp iv fl 1
16586trapc 2 3
16587xarith 33 5 iv off 1 idx
16588sh = sub 3 tlog t
16589if ne sh 0
16590bo_lsl idx sh idx
16591end
16592ret
16593end
16594emit or or 4043309087 shl fl 10 shl iv 5
16595trapc 2 3
16596emit or or or 2432696320 idx shl iv 5 shl off 10
16597sh = sub 3 tlog t
16598if ne sh 0
16599bo_lsl idx sh idx
16600end
16601end
16602
16603note st_ld: LDR of type t from base + idx into dst (or a new register). LDOP table, as vt_get.
16604fn st_ld base ulong idx ulong t ulong dst ulong to void
16605rd = destreg dst
16606if ne get xtarget 0 0
16607xmemval 0 base idx t rd
16608else
16609w = or ldop t rd
16610emit or or w shl base 5 shl idx 16
16611end
16612put rk 0 1
16613put rv 0 rd
16614put rt 0 t
16615end
16616
16617note st_write1: store field j (value saved at sv* i) into the struct at base.
16618fn st_write1 base ulong tmp ulong idx ulong j ulong i ulong to void
16619ft = ulong get sf_type j
16620fl = ulong get sf_len j
16621off = ulong get sf_off j
16622force get svk i get svv i get svt i tmp
16623if eq fl 0
16624st_store base idx off ft tmp
16625else
16626k = ulong 0
16627while lt k fl
16628st_store base idx add off k ft tmp
16629k = add k 1
16630end
16631end
16632end
16633
16634note st_write: store each field value. An array field is filled with its one value.
16635fn st_write base ulong tmp ulong idx ulong si ulong to void
16636fo = ulong get st_foff si
16637nfd = ulong get st_nf si
16638i = ulong 0
16639while lt i nfd
16640st_write1 base tmp idx add fo i i
16641i = add i 1
16642end
16643end
16644
16645note sa_st: p = new S v1 .. vn. Stack slot of the cell count, 16-byte aligned, outermost block only.
16646fn sa_st w ulong sid ulong to void
16647if ne get nb 0 0
16648note d2site 368|sa_st: word or declaration in a place that does not allow it; condition if ne get nb 0 0
16649put d2site 0 368
16650fail 9
16651end
16652si = sub sid 1
16653cells = ulong get st_cells si
16654by = shl shr add shl cells 3 15 4 4
16655s = add get stkbytes 0 by
16656if gt s 4194304
16657note d2site 369|sa_st: size capacity; condition if gt s 4194304
16658put d2site 0 369
16659fail 23
16660end
16661put stkbytes 0 s
16662r = alloc
16663put held 0 get nslot 0
16664st_read si
16665spsubk by
16666stkchk
16667if ne get xtarget 0 0
16668xmovsp r
16669else
16670emit or 2432697312 r
16671end
16672tmp = alloc
16673idx = alloc
16674st_write r tmp idx si
16675addname w r add si 16 cells 6 0
16676end
16677
16678note ======== OM-2 section 5: abstract types (spec 5, errata E8, E9). `abstract NAME T [ops W..]` and
16679note `holds NAME dup32` at top level before the first fn (names pass). NAME is type 64 + index: a value of
16680note it comes only from `seal NAME v` inside the function NAMEmk returning NAME (else error 28), `open v`
16681note gives the T value, and the listed operations (rotr/rotl with a T count, and/or/xor of two NAME
16682note values) keep NAME; anything else on it, a T value or a number where NAME is needed, an array of it and
16683note the entry function's parameters and result are error 7. With holds, seal checks high32 == low32
16684note (LSR, CMP ..., UXTW, B.NE trap 10) unless the constructor body is exactly `ret seal NAME or shl ulong
16685note x 32 ulong x` with x a uint parameter (rule dup32: uint values are held zero-extended). om2 diag
16686note reports each check as omc-check 1 kept|erased line=N rule=dup32|-. ========
16687fn findab w ulong to ulong
16688i = ulong 0
16689while lt i get nab 0
16690if eq get ab_name i w
16691ret add i 1
16692end
16693i = add i 1
16694end
16695ret 0
16696end
16697
16698note abty: the current word (not a type word) as an abstract type; anything else is error 16
16699fn abty to ulong
16700a = findab get tw 0
16701if eq a 0
16702note d2site 370|abty: syntax: unknown or misplaced word; condition if eq a 0
16703put d2site 0 370
16704fail 16
16705end
16706ret add a 63
16707end
16708
16709note opbit: the ops bit of a preserving operation (rotr rotl and or xor), else 0
16710fn opbit c ulong to ulong
16711if eq c 59
16712ret 1
16713end
16714if eq c 60
16715ret 2
16716end
16717if eq c 38
16718ret 4
16719end
16720if eq c 39
16721ret 8
16722end
16723if eq c 40
16724ret 16
16725end
16726ret 0
16727end
16728
16729note s_abstract: abstract NAME uint|ulong [ops W ..] (another type is error 7, another op word 16)
16730fn s_abstract to void
16731if ne get nf 0 0
16732note d2site 371|s_abstract: word or declaration in a place that does not allow it; condition if ne get nf 0 0
16733put d2site 0 371
16734fail 9
16735end
16736tok
16737if ne get tk 0 1
16738note d2site 372|s_abstract: syntax: unknown or misplaced word; condition if ne get tk 0 1
16739put d2site 0 372
16740fail 16
16741end
16742if gt get tl 0 8
16743note d2site 373|s_abstract: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 8
16744put d2site 0 373
16745fail 13
16746end
16747w = get tw 0
16748if ne kw w 0
16749note d2site 374|s_abstract: syntax: unknown or misplaced word; condition if ne kw w 0
16750put d2site 0 374
16751fail 16
16752end
16753newname w get tl 0 get ts 0
16754n = get nab 0
16755if ge n 16
16756note d2site 375|s_abstract: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 16
16757put d2site 0 375
16758fail 14
16759end
16760put ab_len n get tl 0
16761t = typeword
16762if and ne t 4 ne t 5
16763note d2site 376|s_abstract: type mismatch; condition if and ne t 4 ne t 5
16764put d2site 0 376
16765fail 7
16766end
16767ops = ulong 0
16768tok
16769if eq get tk 0 1
16770if or gt get tl 0 8 ne kw get tw 0 196
16771note d2site 377|s_abstract: extra words after a complete statement; condition if or gt get tl 0 8 ne kw get tw 0 196
16772put d2site 0 377
16773fail 5
16774end
16775go = true
16776while go
16777tok
16778k = get tk 0
16779if or eq k 0 eq k 3
16780go = false
16781else
16782if or ne k 1 gt get tl 0 8
16783note d2site 378|s_abstract: syntax: unknown or misplaced word; condition if or ne k 1 gt get tl 0 8
16784put d2site 0 378
16785fail 16
16786end
16787b = opbit kw get tw 0
16788if eq b 0
16789note d2site 379|s_abstract: syntax: unknown or misplaced word; condition if eq b 0
16790put d2site 0 379
16791fail 16
16792end
16793ops = or ops b
16794end
16795end
16796else
16797if and ne get tk 0 0 ne get tk 0 3
16798note d2site 380|s_abstract: extra words after a complete statement; condition if and ne get tk 0 0 ne get tk 0 3
16799put d2site 0 380
16800fail 5
16801end
16802end
16803put ab_name n w
16804put ab_base n uchar t
16805put ab_ops n ops
16806put nab 0 add n 1
16807end
16808
16809note ab_entry: function f (index) is the entry of a function-mode unit: no abstract parameter or result
16810fn ab_entry f ulong to void
16811if eq get om2 0 0
16812ret
16813end
16814if ne get scanning 0 0
16815ret
16816end
16817if ne get progmode 0 0
16818ret
16819end
16820if ne get nexp 0 0
16821if eq uchar get a_ar add get a_rb 32 f 0
16822ret
16823end
16824else
16825if ne add f 1 get nf 0
16826ret
16827end
16828end
16829if ge uchar get a_ar add get a_rb 23 f 64
16830note d2site 381|ab_entry: type mismatch; condition if ge uchar get a_ar add get a_rb 23 f 64
16831put d2site 0 381
16832fail 7
16833end
16834i = ulong 0
16835while lt i ulong uchar get a_ar add get a_rb 24 f
16836if ge uchar get a_ar add get a_rb 35 add mul f 6 i 64
16837note d2site 382|ab_entry: type mismatch; condition if ge uchar get a_ar add get a_rb 35 add mul f 6 i 64
16838put d2site 0 382
16839fail 7
16840end
16841i = add i 1
16842end
16843end
16844
16845note ab_open: open v (the value read): an abstract value becomes its representation type
16846fn ab_open to void
16847t = get rt 0
16848if lt t 64
16849note d2site 383|ab_open: type mismatch; condition if lt t 64
16850put d2site 0 383
16851fail 7
16852end
16853put rt 0 ulong get ab_base sub t 64
16854end
16855
16856note ab_seal: seal NAME v, only in the function NAMEmk (inlined or not) returning NAME (else error 28)
16857fn ab_seal to void
16858tok
16859if or eq get tk 0 0 eq get tk 0 3
16860note d2site 384|ab_seal: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3
16861put d2site 0 384
16862fail 4
16863end
16864a = ulong 0
16865if and eq get tk 0 1 le get tl 0 8
16866a = findab get tw 0
16867end
16868if eq a 0
16869note d2site 385|ab_seal: syntax: unknown or misplaced word; condition if eq a 0
16870put d2site 0 385
16871fail 16
16872end
16873a = sub a 1
16874fe = get curfn 0
16875if ne get inl 0 0
16876fe = get il_fn sub get inl 0 1
16877end
16878if eq ab_ctor fe a 0
16879note d2site 386|ab_seal: abstract type: seal outside its constructor, or an unsupported holds; condition if eq ab_ctor fe a 0
16880put d2site 0 386
16881fail 28
16882end
16883t = ulong get ab_base a
16884rdval 0 t 255 0
16885if ne get rt 0 t
16886note d2site 387|ab_seal: type mismatch; condition if ne get rt 0 t
16887put d2site 0 387
16888fail 7
16889end
16890r = matreg get rk 0 get rv 0 get rt 0
16891if ne get ab_holds a 0
16892ab_check fe a r
16893end
16894put rk 0 1
16895put rv 0 r
16896put rt 0 add a 64
16897end
16898
16899note ab_ctor: 1 when function fe (index + 1) is NAMEmk for abstract a and returns it
16900fn ab_ctor fe ulong a ulong to ulong
16901if eq fe 0
16902ret 0
16903end
16904f = sub fe 1
16905if ne ulong uchar get a_ar add get a_rb 23 f add a 64
16906ret 0
16907end
16908l = get ab_len a
16909if ne get a_ar add get a_rb 25 f add l 2
16910ret 0
16911end
16912o = get a_ar add get a_rb 26 f
16913w = get ab_name a
16914i = ulong 0
16915while lt i l
16916if ne ulong a_ib add o i and shr w shl i 3 255
16917ret 0
16918end
16919i = add i 1
16920end
16921if ne a_ib add o l 109
16922ret 0
16923end
16924if ne a_ib add add o l 1 107
16925ret 0
16926end
16927ret 1
16928end
16929
16930note ab_check: the dup32 check of a seal (value in r): erased for the exact body, else LSR Xt, Xr, #32
16931note (UBFM, C6.2.487); CMP Xt, Wr, UXTW (SUBS extended, C6.2.463); B.NE trap 10
16932fn ab_check fe ulong a ulong r ulong to void
16933ex = ab_exact fe a
16934if eq get om2m 0 1
16935note ab_rec: omc-check 1 kept|erased line=N rule=dup32|- (om2 diag, with the omc-site records)
16936sitew 7162245557575183727 8
16937sitew 540090475 4
16938if ne ex 0
16939sitew 110386890240613 6
16940else
16941sitew 1953523051 4
16942end
16943sitew 67505853393952 6
16944siten add get line 0 get lbase 0
16945sitew 67505820627488 6
16946if ne ex 0
16947sitew 215611372900 5
16948else
16949siteb 45
16950end
16951siteb 10
16952end
16953if eq ex 0
16954t = alloc
16955if ne get xtarget 0 0
16956xload 0 r
16957xload 1 r
16958emitb 137
16959emitb 192
16960xb 72 193 233
16961emitb 32
16962xrr 57 0 1
16963xtrap 1 10
16964else
16965emit or or 3546348544 t shl r 5
16966emit or or 3944759327 shl r 16 shl t 5
16967trapc 1 10
16968end
16969end
16970end
16971
16972note aw_next: the next word of the input from aw_p (blanks skipped, newlines counted in aw_nl)
16973fn aw_next to void
16974p = get aw_p 0
16975e = get inlen 0
16976nl = ulong 0
16977go = true
16978while and go lt p e
16979b = a_ib p
16980if or eq b 32 eq b 9
16981p = add p 1
16982else
16983if eq b 10
16984nl = add nl 1
16985p = add p 1
16986else
16987go = false
16988end
16989end
16990end
16991w = ulong 0
16992l = ulong 0
16993go2 = true
16994while and go2 lt p e
16995c = a_ib p
16996if or or eq c 32 eq c 9 eq c 10
16997go2 = false
16998else
16999if lt l 8
17000w = or w shl ulong c shl l 3
17001end
17002l = add l 1
17003p = add p 1
17004end
17005end
17006put aw_p 0 p
17007put aw_w 0 w
17008put aw_l 0 l
17009put aw_nl 0 nl
17010end
17011
17012note aw_is: the next word is w (length l) after exactly nl newlines
17013fn aw_is w ulong l ulong nl ulong to ulong
17014aw_next
17015if ne get aw_w 0 w
17016ret 0
17017end
17018if ne get aw_l 0 l
17019ret 0
17020end
17021if ne get aw_nl 0 nl
17022ret 0
17023end
17024ret 1
17025end
17026
17027note ab_upar: x (length xl) is a uint scalar parameter of function f (index)
17028fn ab_upar f ulong x ulong xl ulong to ulong
17029if gt xl 8
17030ret 0
17031end
17032i = ulong 0
17033while lt i ulong uchar get a_ar add get a_rb 24 f
17034p = add mul f 6 i
17035if eq get a_ar add get a_rb 34 p x
17036if eq uchar get a_ar add get a_rb 37 p 0
17037if eq uchar get a_ar add get a_rb 35 p 4
17038ret 1
17039end
17040end
17041end
17042i = add i 1
17043end
17044ret 0
17045end
17046
17047note ab_exact: the body of constructor fe is exactly `ret seal NAME or shl ulong x 32 ulong x` then `end`
17048fn ab_exact fe ulong a ulong to ulong
17049f = sub fe 1
17050put aw_p 0 get a_ar add get a_rb 28 f
17051if eq aw_is 7628146 3 0 0
17052ret 0
17053end
17054if eq aw_is 1818322291 4 0 0
17055ret 0
17056end
17057if eq aw_is get ab_name a get ab_len a 0 0
17058ret 0
17059end
17060if eq aw_is 29295 2 0 0
17061ret 0
17062end
17063if eq aw_is 7104627 3 0 0
17064ret 0
17065end
17066if eq aw_is 444234427509 5 0 0
17067ret 0
17068end
17069aw_next
17070if ne get aw_nl 0 0
17071ret 0
17072end
17073x = get aw_w 0
17074xl = get aw_l 0
17075if eq ab_upar f x xl 0
17076ret 0
17077end
17078if eq aw_is 12851 2 0 0
17079ret 0
17080end
17081if eq aw_is 444234427509 5 0 0
17082ret 0
17083end
17084if eq aw_is x xl 0 0
17085ret 0
17086end
17087if eq aw_is 6581861 3 1 0
17088ret 0
17089end
17090aw_next
17091if and ne get aw_l 0 0 eq get aw_nl 0 0
17092ret 0
17093end
17094ret 1
17095end
17096
17097note ab_bin: a binary operation whose operand (fr[x..x+5]) is abstract: only a listed preserving one, run
17098note on the representation type T and giving NAME; rotr/rotl take a T count (E9), and/or/xor two NAME values
17099fn ab_bin c ulong dst ulong x ulong to void
17100at = get a_ar add get a_rb 77 add x 2
17101if lt at 64
17102note d2site 388|ab_bin: type mismatch; condition if lt at 64
17103put d2site 0 388
17104fail 7
17105end
17106a = sub at 64
17107b = opbit c
17108if eq b 0
17109note d2site 389|ab_bin: type mismatch; condition if eq b 0
17110put d2site 0 389
17111fail 7
17112end
17113if eq and get ab_ops a b 0
17114note d2site 390|ab_bin: type mismatch; condition if eq and get ab_ops a b 0
17115put d2site 0 390
17116fail 7
17117end
17118t = ulong get ab_base a
17119bk = get a_ar add get a_rb 77 add x 3
17120bt = get a_ar add get a_rb 77 add x 5
17121if or eq c 59 eq c 60
17122if eq bk 2
17123range a_g 77 add x 4 t bt
17124a_p 77 add x 3 3
17125else
17126if ne bt t
17127note d2site 391|ab_bin: type mismatch; condition if ne bt t
17128put d2site 0 391
17129fail 7
17130end
17131end
17132else
17133if ne bt at
17134note d2site 392|ab_bin: type mismatch; condition if ne bt at
17135put d2site 0 392
17136fail 7
17137end
17138end
17139put a_ar add get a_rb 77 add x 2 t
17140put a_ar add get a_rb 77 add x 5 t
17141binop c dst x
17142put rt 0 at
17143end
17144
17145note ======== OM-2 section 5: fresh scratch (spec 5, erratum E8). `NAME edit T N fresh` (N <= 64): the
17146note incoming elements are unspecified. Each such array has a written set (bit i: element i definitely
17147note written on the path being compiled). A put with a number index (after unrolling and inlining) sets
17148note its bit; a get with a number index needs its bit, any other get all N bits (else error 27,
17149note obligation=init). Joins: an if without else, a while and a rolled for keep the set they opened with;
17150note an if/else takes the intersection of its arms (or the arm that does not end in ret); an unrolled
17151note body and an inlined body keep what they wrote. Passing the array to a non-inline call, read, write or
17152note a host operation is error 27; an inline callee works on the same set. ========
17153note fz_par: parameter slot f*6+np of kind k with N = ln is fresh: an edit only (else 16), N <= 64 (else 14)
17154fn fz_par f ulong np ulong k ulong ln ulong to void
17155if ne k 3
17156note d2site 393|fz_par: syntax: unknown or misplaced word; condition if ne k 3
17157put d2site 0 393
17158fail 16
17159end
17160if gt ln 64
17161put dobx 0 1
17162note d2site 394|fz_par: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if gt ln 64
17163put d2site 0 394
17164fail 14
17165end
17166a_pc 39 add mul f 6 np 1
17167end
17168
17169note fz_bind: the parameter name just added for slot p gets a new written set in the body pass
17170fn fz_bind p ulong ln ulong to void
17171if eq uchar get a_ar add get a_rb 39 p 0
17172ret
17173end
17174if ne get scanning 0 0
17175ret
17176end
17177fz_new sub get nn 0 1 ln
17178end
17179
17180note fz_new: a new, empty written set of N elements for name index n (16 per function, error 14)
17181fn fz_new n ulong ln ulong to void
17182s = get fz_n 0
17183if ge s 16
17184put dobx 0 1
17185note d2site 395|fz_new: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge s 16
17186put d2site 0 395
17187fail 14
17188end
17189put fz_len s ln
17190put fz_cur s 0
17191a_pc 13 n uchar add s 1
17192put fz_n 0 add s 1
17193end
17194
17195note fz_inl: an inline parameter slot p bound to array name e: its own fresh set, or e's set
17196fn fz_inl p ulong e ulong to void
17197pk = ulong uchar get a_ar add get a_rb 37 p
17198if or eq pk 0 ge pk 6
17199ret
17200end
17201n = sub get nn 0 1
17202if ne uchar get a_ar add get a_rb 39 p 0
17203fz_new n get a_ar add get a_rb 36 p
17204ret
17205end
17206a_pc 13 n uchar get a_ar add get a_rb 13 sub e 1
17207end
17208
17209fn fz_else i ulong to void
17210j = ulong 0
17211while lt j get fz_n 0
17212x = add mul i 16 j
17213put a_ar add get a_rb 69 x get fz_cur j
17214put fz_cur j get a_ar add get a_rb 68 x
17215j = add j 1
17216end
17217end
17218
17219fn fz_join i ulong k ulong to void
17220td = get a_ar add get a_rb 56 i
17221ed = get dead 0
17222j = ulong 0
17223while lt j get fz_n 0
17224x = add mul i 16 j
17225if eq k 2
17226v = and get fz_cur j a_g 69 x
17227if and ne td 0 eq ed 0
17228v = get fz_cur j
17229end
17230if and ne ed 0 eq td 0
17231v = get a_ar add get a_rb 69 x
17232end
17233put fz_cur j v
17234else
17235put fz_cur j get a_ar add get a_rb 68 x
17236end
17237j = add j 1
17238end
17239end
17240
17241note fz_get: get e i with the index in rk/rv/rt
17242fn fz_get e ulong to void
17243if ne get cvalid 0 0
17244ret
17245end
17246s = ulong uchar get a_ar add get a_rb 13 sub e 1
17247if eq s 0
17248ret
17249end
17250s = sub s 1
17251n = get fz_len s
17252if eq get rk 0 3
17253v = get rv 0
17254if lt v n
17255if eq and shr get fz_cur s v 1 0
17256note d2site 396|fz_get: fresh element read before it is definitely written, or fresh array passed on; condition if eq and shr get fz_cur s v 1 0
17257put d2site 0 396
17258fail 27
17259end
17260end
17261ret
17262end
17263if ne get fz_cur s fmask n
17264note d2site 397|fz_get: fresh element read before it is definitely written, or fresh array passed on; condition if ne get fz_cur s fmask n
17265put d2site 0 397
17266fail 27
17267end
17268end
17269
17270note fz_put: put e i v with index (k, v): a number index sets its bit
17271fn fz_put e ulong k ulong v ulong to void
17272s = ulong uchar get a_ar add get a_rb 13 sub e 1
17273if eq s 0
17274ret
17275end
17276s = sub s 1
17277if eq k 3
17278if lt v get fz_len s
17279put fz_cur s or get fz_cur s shl ulong 1 v
17280end
17281end
17282end
17283
17284note fz_arg: array name e leaves the analysis (a non-inline call, read, write, a host operation): error 27
17285note when it is tracked
17286fn fz_arg e ulong to void
17287if ne uchar get a_ar add get a_rb 13 sub e 1 0
17288note d2site 398|fz_arg: fresh element read before it is definitely written, or fresh array passed on; condition if ne uchar get a_ar add get a_rb 13 sub e 1 0
17289put d2site 0 398
17290fail 27
17291end
17292end
17293
17294note ======== OM-2 section 5: external layouts (spec 5, errata E5, E8, E9). `layout NAME SIZE`, then one
17295note `field F T [COUNT] at OFF little|big` per line, then `end`, before the first fn. Read in the names pass;
17296note the body pass jumps over the block. A parameter `c view|edit NAME` is a uchar array of SIZE bytes (one
17297note pointer); `get c F [i]` / `put c F [i] v` load / store the field at its width and byte order:
17298note LDR/STR (register, unscaled offset; C6.2.216 family) at base + OFF + i * width, REV16 / REV (C6.2.333,
17299note C6.2.331) for big, a run-time index checked like an array's (CMP, B.HS trap 3) ========
17300note findlay: packed name -> layout index + 1, or 0
17301fn findlay w ulong to ulong
17302i = ulong 0
17303while lt i get nly 0
17304if eq get ly_name i w
17305ret add i 1
17306end
17307i = add i 1
17308end
17309ret 0
17310end
17311
17312note findlf: layout index li, packed field name -> field-table index + 1, or 0
17313fn findlf li ulong w ulong to ulong
17314fo = get ly_fo li
17315i = ulong 0
17316while lt i get ly_nf li
17317if eq get lf_name add fo i w
17318ret add add fo i 1
17319end
17320i = add i 1
17321end
17322ret 0
17323end
17324
17325note ns_om2: an OM-2 declaration line in the names pass (1 when it was read), else 0
17326fn ns_om2 to ulong
17327if ne get objmode 0 0
17328if and eq get tl 0 6 eq get tw 0 121437607458917
17329s_extern
17330ret 1
17331end
17332end
17333if eq get om2 0 0
17334ret 0
17335end
17336if ne get tk 0 1
17337ret 0
17338end
17339if gt get tl 0 8
17340ret 0
17341end
17342if eq get tw 0 128047730221420
17343s_layout
17344ret 1
17345end
17346if eq get tw 0 8386654075301880417
17347s_abstract
17348ret 1
17349end
17350if eq get tw 0 495606067048
17351note s_holds: holds NAME dup32 (ulong representation only); any other predicate is error 28 on this line
17352if ne get nf 0 0
17353note d2site 399|ns_om2: word or declaration in a place that does not allow it; condition if ne get nf 0 0
17354put d2site 0 399
17355fail 9
17356end
17357tok
17358if ne get tk 0 1
17359note d2site 400|ns_om2: syntax: unknown or misplaced word; condition if ne get tk 0 1
17360put d2site 0 400
17361fail 16
17362end
17363a = ulong 0
17364if le get tl 0 8
17365a = findab get tw 0
17366end
17367if eq a 0
17368note d2site 401|ns_om2: syntax: unknown or misplaced word; condition if eq a 0
17369put d2site 0 401
17370fail 16
17371end
17372a = sub a 1
17373tok
17374if or eq get tk 0 0 eq get tk 0 3
17375note d2site 402|ns_om2: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3
17376put d2site 0 402
17377fail 4
17378end
17379if ne get tk 0 1
17380note d2site 403|ns_om2: abstract type: seal outside its constructor, or an unsupported holds; condition if ne get tk 0 1
17381put d2site 0 403
17382fail 28
17383end
17384if or ne get tl 0 5 ne get tw 0 215611372900
17385note d2site 404|ns_om2: abstract type: seal outside its constructor, or an unsupported holds; condition if or ne get tl 0 5 ne get tw 0 215611372900
17386put d2site 0 404
17387fail 28
17388end
17389if ne get ab_base a 5
17390note d2site 405|ns_om2: abstract type: seal outside its constructor, or an unsupported holds; condition if ne get ab_base a 5
17391put d2site 0 405
17392fail 28
17393end
17394if ne get ab_holds a 0
17395note d2site 406|ns_om2: duplicate name; condition if ne get ab_holds a 0
17396put d2site 0 406
17397fail 10
17398end
17399put ab_holds a 1
17400eol
17401ret 1
17402end
17403if eq get tw 0 128034844735589
17404s_export
17405ret 1
17406end
17407ret 0
17408end
17409
17410note s_export (OM-2, spec 6): `export fn ...` at top level: the fn line of an exported entry, in both
17411note passes. Function mode only (error 9), at most 32 (error 14), counted and marked in the names pass.
17412fn s_export to void
17413tok
17414if or ne get tk 0 1 ne get tw 0 28262
17415note d2site 407|s_export: syntax: unknown or misplaced word; condition if or ne get tk 0 1 ne get tw 0 28262
17416put d2site 0 407
17417fail 16
17418end
17419if eq get scanning 0 1
17420if ne get progmode 0 0
17421note d2site 408|s_export: word or declaration in a place that does not allow it; condition if ne get progmode 0 0
17422put d2site 0 408
17423fail 9
17424end
17425if eq get objmode 0 0
17426if ge get nexp 0 32
17427note d2site 409|s_export: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge get nexp 0 32
17428put d2site 0 409
17429fail 14
17430end
17431end
17432put nexp 0 add get nexp 0 1
17433end
17434put expf 0 1
17435s_fn
17436put expf 0 0
17437end
17438
17439note ly_num: the next token must be a number (error 4 at the line end, 16 for another token, 29 when it
17440note was written as 2^63 or more)
17441fn ly_num to ulong
17442tok
17443if or eq get tk 0 0 eq get tk 0 3
17444note d2site 410|ly_num: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3
17445put d2site 0 410
17446fail 4
17447end
17448if ne get tk 0 2
17449note d2site 411|ly_num: syntax: unknown or misplaced word; condition if ne get tk 0 2
17450put d2site 0 411
17451fail 16
17452end
17453if ne get tbig 0 0
17454note d2site 412|ly_num: external layout out of bounds or misplaced; condition if ne get tbig 0 0
17455put d2site 0 412
17456fail 29
17457end
17458ret get tw 0
17459end
17460
17461note s_layout: SIZE 1..4096 and a layout after the first fn are error 29 on the layout line
17462fn s_layout to void
17463if ne get nf 0 0
17464note d2site 413|s_layout: external layout out of bounds or misplaced; condition if ne get nf 0 0
17465put d2site 0 413
17466fail 29
17467end
17468tok
17469if ne get tk 0 1
17470note d2site 414|s_layout: syntax: unknown or misplaced word; condition if ne get tk 0 1
17471put d2site 0 414
17472fail 16
17473end
17474if gt get tl 0 8
17475note d2site 415|s_layout: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 8
17476put d2site 0 415
17477fail 13
17478end
17479w = get tw 0
17480if ne kw w 0
17481note d2site 416|s_layout: syntax: unknown or misplaced word; condition if ne kw w 0
17482put d2site 0 416
17483fail 16
17484end
17485newname w get tl 0 get ts 0
17486if ge get nly 0 16
17487note d2site 417|s_layout: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge get nly 0 16
17488put d2site 0 417
17489fail 14
17490end
17491sz = ly_num
17492if or eq sz 0 gt sz 4096
17493note d2site 418|s_layout: external layout out of bounds or misplaced; condition if or eq sz 0 gt sz 4096
17494put d2site 0 418
17495fail 29
17496end
17497eol
17498li = get nly 0
17499fo = get nlf 0
17500i = ulong 0
17501while lt i sz
17502put lymap i 0
17503i = add i 1
17504end
17505go = true
17506while go
17507tok
17508k = get tk 0
17509if eq k 3
17510note d2site 419|s_layout: the line ends where a word or value is needed; condition if eq k 3
17511put d2site 0 419
17512fail 4
17513end
17514if eq k 1
17515c = ulong 0
17516if le get tl 0 8
17517c = kw get tw 0
17518end
17519if eq c 66
17520eol
17521go = false
17522else
17523if eq c 83
17524skipnl
17525else
17526if ne c 189
17527note d2site 420|s_layout: syntax: unknown or misplaced word; condition if ne c 189
17528put d2site 0 420
17529fail 16
17530end
17531ly_field fo sz
17532end
17533end
17534else
17535if ne k 0
17536note d2site 421|s_layout: syntax: unknown or misplaced word; condition if ne k 0
17537put d2site 0 421
17538fail 16
17539end
17540end
17541end
17542put ly_name li w
17543put ly_size li sz
17544put ly_fo li fo
17545put ly_nf li sub get nlf 0 fo
17546put ly_ec li get cur 0
17547put ly_el li get line 0
17548put nly 0 add li 1
17549end
17550
17551note ly_field: F T [COUNT] at OFF little|big. A field over SIZE, a COUNT outside 1..4096, an OFF out of range
17552note or two fields sharing a byte are error 29 on the field line. Field types are the integer types.
17553fn ly_field fo ulong sz ulong to void
17554tok
17555if or eq get tk 0 0 eq get tk 0 3
17556note d2site 422|ly_field: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3
17557put d2site 0 422
17558fail 4
17559end
17560if ne get tk 0 1
17561note d2site 423|ly_field: syntax: unknown or misplaced word; condition if ne get tk 0 1
17562put d2site 0 423
17563fail 16
17564end
17565if gt get tl 0 8
17566note d2site 424|ly_field: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 8
17567put d2site 0 424
17568fail 13
17569end
17570fw = get tw 0
17571if ne kw fw 0
17572note d2site 425|ly_field: syntax: unknown or misplaced word; condition if ne kw fw 0
17573put d2site 0 425
17574fail 16
17575end
17576n = get nlf 0
17577i = fo
17578while lt i n
17579if eq get lf_name i fw
17580note d2site 426|ly_field: duplicate name; condition if eq get lf_name i fw
17581put d2site 0 426
17582fail 10
17583end
17584i = add i 1
17585end
17586if ge n 256
17587note d2site 427|ly_field: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 256
17588put d2site 0 427
17589fail 14
17590end
17591t = typeword
17592if or lt t 2 gt t 9
17593note d2site 428|ly_field: type mismatch; condition if or lt t 2 gt t 9
17594put d2site 0 428
17595fail 7
17596end
17597cnt = ulong 0
17598tok
17599if eq get tk 0 2
17600if ne get tbig 0 0
17601note d2site 429|ly_field: external layout out of bounds or misplaced; condition if ne get tbig 0 0
17602put d2site 0 429
17603fail 29
17604end
17605cnt = get tw 0
17606if or eq cnt 0 gt cnt 4096
17607note d2site 430|ly_field: external layout out of bounds or misplaced; condition if or eq cnt 0 gt cnt 4096
17608put d2site 0 430
17609fail 29
17610end
17611tok
17612end
17613if or eq get tk 0 0 eq get tk 0 3
17614note d2site 431|ly_field: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3
17615put d2site 0 431
17616fail 4
17617end
17618if ne get tk 0 1
17619note d2site 432|ly_field: syntax: unknown or misplaced word; condition if ne get tk 0 1
17620put d2site 0 432
17621fail 16
17622end
17623if ne kw get tw 0 190
17624note d2site 433|ly_field: syntax: unknown or misplaced word; condition if ne kw get tw 0 190
17625put d2site 0 433
17626fail 16
17627end
17628off = ly_num
17629big = ly_end
17630ly_mark off cnt t sz
17631eol
17632put lf_name n fw
17633put lf_type n uchar t
17634put lf_cnt n cnt
17635put lf_off n off
17636put lf_big n uchar big
17637put nlf 0 add n 1
17638end
17639
17640note ly_end: little (0) or big (1)
17641fn ly_end to ulong
17642tok
17643if or eq get tk 0 0 eq get tk 0 3
17644note d2site 434|ly_end: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3
17645put d2site 0 434
17646fail 4
17647end
17648if ne get tk 0 1
17649note d2site 435|ly_end: syntax: unknown or misplaced word; condition if ne get tk 0 1
17650put d2site 0 435
17651fail 16
17652end
17653c = kw get tw 0
17654if eq c 191
17655ret 0
17656end
17657if eq c 192
17658ret 1
17659end
17660note d2site 436|ly_end: syntax: unknown or misplaced word
17661put d2site 0 436
17662fail 16
17663ret 0
17664end
17665
17666note ly_mark: the bytes OFF .. OFF + max(COUNT, 1) * width must lie inside SIZE and be free (error 29)
17667fn ly_mark off ulong cnt ulong t ulong sz ulong to void
17668n = cnt
17669if eq n 0
17670n = ulong 1
17671end
17672by = shl n tlog t
17673if gt off sz
17674note d2site 437|ly_mark: external layout out of bounds or misplaced; condition if gt off sz
17675put d2site 0 437
17676fail 29
17677end
17678e = add off by
17679if gt e sz
17680note d2site 438|ly_mark: external layout out of bounds or misplaced; condition if gt e sz
17681put d2site 0 438
17682fail 29
17683end
17684i = off
17685while lt i e
17686if ne get lymap i 0
17687note d2site 439|ly_mark: external layout out of bounds or misplaced; condition if ne get lymap i 0
17688put d2site 0 439
17689fail 29
17690end
17691put lymap i 1
17692i = add i 1
17693end
17694end
17695
17696note peek_lay: if the next word is a layout name, consume it and return index + 1; else rewind
17697fn peek_lay to ulong
17698p = get cur 0
17699ln = get line 0
17700tok
17701if eq get tk 0 1
17702if le get tl 0 8
17703lid = findlay get tw 0
17704if ne lid 0
17705ret lid
17706end
17707end
17708end
17709put cur 0 p
17710put line 0 ln
17711ret 0
17712end
17713
17714note fn_p_ly: parameter pw is a layout (view k 2 / edit k 3): a uchar array of SIZE bytes, name kind 2 / 3
17715fn fn_p_ly f ulong np ulong pw ulong lid ulong k ulong to void
17716ln = get ly_size sub lid 1
17717addname pw poolc get psl 0 2 ln k 0
17718a_pc 12 sub get nn 0 1 uchar lid
17719p = add mul f 6 np
17720a_pc 35 p 2
17721put a_ar add get a_rb 36 p ln
17722a_pc 37 p uchar k
17723a_pc 38 p uchar lid
17724end
17725
17726note ly_fld: for a layout name e, when the next word is one of its fields: consume it, return the field-table
17727note index + 1; otherwise rewind and return 0 (the name is then an ordinary uchar array)
17728fn ly_fld e ulong to ulong
17729lid = ulong uchar get a_ar add get a_rb 12 sub e 1
17730if eq lid 0
17731ret 0
17732end
17733p = get cur 0
17734ln = get line 0
17735tok
17736if eq get tk 0 1
17737if le get tl 0 8
17738j = findlf sub lid 1 get tw 0
17739if ne j 0
17740ret j
17741end
17742end
17743end
17744put cur 0 p
17745put line 0 ln
17746ret 0
17747end
17748
17749note ldun / stun: LDRB / LDRH / LDR w / LDR x and the stores, register offset, LSL #0 (S = 0)
17750fn ldun t ulong to ulong
17751if or eq t 2 eq t 6
17752ret 945842176
17753end
17754if or eq t 3 eq t 7
17755ret 2019584000
17756end
17757if or eq t 4 eq t 8
17758ret 3093325824
17759end
17760ret 4167067648
17761end
17762
17763fn stun t ulong to ulong
17764if or eq t 2 eq t 6
17765ret 941647872
17766end
17767if or eq t 3 eq t 7
17768ret 2015389696
17769end
17770if or eq t 4 eq t 8
17771ret 3089131520
17772end
17773ret 4162873344
17774end
17775
17776note ly_rev: Rd = the bytes of Rs reversed at width t: REV16 Wd (C6.2.333), REV Wd, REV Xd (C6.2.331)
17777fn ly_rev t ulong s ulong d ulong to void
17778if ne get xtarget 0 0
17779xload 0 s
17780if or eq t 2 eq t 6
17781xstore 0 d
17782ret
17783end
17784if or eq t 3 eq t 7
17785emitb 102
17786xb 193 200 8
17787else
17788if or eq t 5 eq t 9
17789emitb 72
17790end
17791emitb 15
17792emitb 200
17793end
17794xstore 0 d
17795ret
17796end
17797if or eq t 3 eq t 7
17798emit or or 1522533376 d shl s 5
17799end
17800if or eq t 4 eq t 8
17801emit or or 1522534400 d shl s 5
17802end
17803if or eq t 5 eq t 9
17804emit or or 3670019072 d shl s 5
17805end
17806end
17807
17808note ly_ix: the byte-offset register of element (k, v, t) of array field j: a number index must be below
17809note COUNT (error 21); a register index: CMP Xi, #COUNT or Xc (C6.2.96 / C6.2.97), B.HS trap 3, then
17810note Xo = OFF; ADD Xo, Xo, Xi, LSL #log2 width (C6.2.6)
17811fn ly_ix j ulong k ulong v ulong t ulong to ulong
17812if or eq t 1 ge t 10
17813note d2site 440|ly_ix: type mismatch; condition if or eq t 1 ge t 10
17814put d2site 0 440
17815fail 7
17816end
17817cnt = get lf_cnt j
17818sh = tlog ulong get lf_type j
17819x = alloc
17820if eq k 3
17821if ge v cnt
17822note d2site 441|ly_ix: constant index outside the array; condition if ge v cnt
17823put d2site 0 441
17824fail 21
17825end
17826matconst x add get lf_off j shl v sh
17827ret x
17828end
17829r = matreg k v t
17830if ne get xtarget 0 0
17831xcmp r cnt 1
17832xtrap 2 3
17833xload 0 r
17834xb 72 193 224
17835emitb uchar sh
17836ximm 1 get lf_off j
17837xrr 1 0 1
17838xstore 0 x
17839ret x
17840end
17841if le cnt 4095
17842emit or or 4043309087 shl cnt 10 shl r 5
17843else
17844y = alloc
17845matconst y cnt
17846emit or or 3942645791 shl y 16 shl r 5
17847end
17848trapc 2 3
17849matconst x get lf_off j
17850emit or or or or 2332033024 x shl x 5 shl r 16 shl sh 10
17851ret x
17852end
17853
17854note ly_get: get c F [i] on a layout name e (1 when it was a field, the value in rk/rv/rt), else 0
17855fn ly_get e ulong dst ulong to ulong
17856j = ly_fld e
17857if eq j 0
17858ret 0
17859end
17860j = sub j 1
17861ft = ulong get lf_type j
17862x = ulong 0
17863if eq get lf_cnt j 0
17864x = alloc
17865matconst x get lf_off j
17866else
17867rdval 0 5 255 0
17868x = ly_ix j get rk 0 get rv 0 get rt 0
17869end
17870rd = destreg dst
17871if ne get xtarget 0 0
17872xlayout 0 ulong uchar get a_ar add get a_rb 4 sub e 1 x ft rd
17873else
17874emit or or or ldun ft rd shl ulong a_gu 4 sub e 1 5 shl x 16
17875end
17876if ne get lf_big j 0
17877ly_rev ft rd rd
17878end
17879if gt ft 5
17880canon rd ft
17881end
17882put rk 0 1
17883put rv 0 rd
17884put rt 0 ft
17885ret 1
17886end
17887
17888note ly_put: put c F [i] v on a layout name e (an edit; a view was refused 20 before): index, value, then
17889note the store; 1 when it was a field, else 0
17890fn ly_put e ulong to ulong
17891j = ly_fld e
17892if eq j 0
17893ret 0
17894end
17895j = sub j 1
17896if ne get lf_cnt j 0
17897rdval 0 5 255 0
17898put svk 0 get rk 0
17899put svv 0 get rv 0
17900put svt 0 get rt 0
17901end
17902ly_st e j
17903eol
17904ret 1
17905end
17906
17907note ly_st: the value of field j (index saved in svk/svv/svt), then the store through layout name e
17908fn ly_st e ulong j ulong to void
17909ft = ulong get lf_type j
17910cnt = get lf_cnt j
17911rdval 0 ft 255 0
17912if ne get rt 0 ft
17913note d2site 442|ly_st: type mismatch; condition if ne get rt 0 ft
17914put d2site 0 442
17915fail 7
17916end
17917v = matreg get rk 0 get rv 0 get rt 0
17918x = ulong 0
17919if eq cnt 0
17920x = alloc
17921matconst x get lf_off j
17922else
17923x = ly_ix j get svk 0 get svv 0 get svt 0
17924end
17925if and ne get lf_big j 0 ne tlog ft 0
17926y = alloc
17927ly_rev ft v y
17928v = y
17929end
17930if ne get xtarget 0 0
17931xlayout 1 ulong uchar get a_ar add get a_rb 4 sub e 1 x ft v
17932else
17933emit or or or stun ft v shl ulong a_gu 4 sub e 1 5 shl x 16
17934end
17935end
17936
17937note vt_fget_go: field j of struct name e. Scalar, or an index then the element.
17938fn vt_fget_go e ulong dst ulong j ulong to void
17939fl = ulong get sf_len j
17940ft = ulong get sf_type j
17941off = ulong get sf_off j
17942base = ulong uchar get a_ar add get a_rb 4 sub e 1
17943idx = alloc
17944if eq fl 0
17945st_store_ld base idx off ft dst
17946else
17947rdval 0 5 255 0
17948if eq get rt 0 1
17949note d2site 443|vt_fget_go: type mismatch; condition if eq get rt 0 1
17950put d2site 0 443
17951fail 7
17952end
17953if eq get rk 0 3
17954if ge get rv 0 fl
17955note d2site 444|vt_fget_go: constant index outside the array; condition if ge get rv 0 fl
17956put d2site 0 444
17957fail 21
17958end
17959st_store_ld base idx add off get rv 0 ft dst
17960else
17961if ne get rk 0 1
17962note d2site 445|vt_fget_go: type mismatch; condition if ne get rk 0 1
17963put d2site 0 445
17964fail 7
17965end
17966st_ixreg idx get rv 0 off fl ft
17967st_ld base idx ft dst
17968end
17969end
17970end
17971
17972note vt_fget: get p f, or get p f i for an array field. Kind 6 own, 7 edit, 8 view; all may be read.
17973fn vt_fget e ulong dst ulong to void
17974i = sub e 1
17975tok
17976if ne get tk 0 1
17977note d2site 446|vt_fget: syntax: unknown or misplaced word; condition if ne get tk 0 1
17978put d2site 0 446
17979fail 16
17980end
17981if gt get tl 0 63
17982note d2site 447|vt_fget: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
17983put d2site 0 447
17984fail 13
17985end
17986si = sub ulong uchar get a_ar add get a_rb 5 i 16
17987fid = findfield si get tw 0
17988if eq fid 0
17989note d2site 448|vt_fget: unknown name or field, or a word this mode does not provide; condition if eq fid 0
17990put d2site 0 448
17991fail 3
17992end
17993vt_fget_go e dst sub fid 1
17994end
17995
17996note st_store_ld: constant cell, then load. Split out so vt_fget stays under 16 registers.
17997fn st_store_ld base ulong idx ulong cell ulong t ulong dst ulong to void
17998matconst idx shl cell sub 3 tlog t
17999st_ld base idx t dst
18000end
18001
18002note s_putf_go: field j of struct name e. Read the value (and the index, if an array field) and store.
18003fn s_putf_go e ulong j ulong to void
18004fl = ulong get sf_len j
18005ft = ulong get sf_type j
18006off = ulong get sf_off j
18007base = ulong uchar get a_ar add get a_rb 4 sub e 1
18008if ne fl 0
18009rdval 0 5 255 0
18010if eq get rt 0 1
18011note d2site 449|s_putf_go: type mismatch; condition if eq get rt 0 1
18012put d2site 0 449
18013fail 7
18014end
18015put svk 0 get rk 0
18016put svv 0 get rv 0
18017put svt 0 get rt 0
18018end
18019rdval 0 ft 255 0
18020if ne get rt 0 ft
18021note d2site 450|s_putf_go: type mismatch; condition if ne get rt 0 ft
18022put d2site 0 450
18023fail 7
18024end
18025v = matreg get rk 0 get rv 0 get rt 0
18026idx = alloc
18027if eq fl 0
18028st_store base idx off ft v
18029else
18030s_putf_ix base idx v off fl ft
18031end
18032eol
18033end
18034
18035note s_putf: put p f v, or put p f i v. A view struct is error 20.
18036fn s_putf e ulong to void
18037i = sub e 1
18038if eq ulong uchar get a_ar add get a_rb 7 i 8
18039note d2site 451|s_putf: write to a view or a text; condition if eq ulong uchar get a_ar add get a_rb 7 i 8
18040put d2site 0 451
18041fail 20
18042end
18043tok
18044if ne get tk 0 1
18045note d2site 452|s_putf: syntax: unknown or misplaced word; condition if ne get tk 0 1
18046put d2site 0 452
18047fail 16
18048end
18049if gt get tl 0 63
18050note d2site 453|s_putf: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
18051put d2site 0 453
18052fail 13
18053end
18054si = sub ulong uchar get a_ar add get a_rb 5 i 16
18055fid = findfield si get tw 0
18056if eq fid 0
18057note d2site 454|s_putf: unknown name or field, or a word this mode does not provide; condition if eq fid 0
18058put d2site 0 454
18059fail 3
18060end
18061s_putf_go e sub fid 1
18062end
18063
18064note s_putf_ix: the index was saved in svk/svv/svt before the value was read
18065fn s_putf_ix base ulong idx ulong v ulong off ulong fl ulong ft ulong to void
18066ik = get svk 0
18067iv = get svv 0
18068if eq get svt 0 1
18069note d2site 455|s_putf_ix: type mismatch; condition if eq get svt 0 1
18070put d2site 0 455
18071fail 7
18072end
18073if eq ik 3
18074if ge iv fl
18075note d2site 456|s_putf_ix: constant index outside the array; condition if ge iv fl
18076put d2site 0 456
18077fail 21
18078end
18079st_store base idx add off iv ft v
18080else
18081if ne ik 1
18082note d2site 457|s_putf_ix: type mismatch; condition if ne ik 1
18083put d2site 0 457
18084fail 7
18085end
18086st_ixreg idx iv off fl ft
18087put ea_b 0 base
18088put ea_i 0 idx
18089stel ft v
18090end
18091end
18092
18093note ca_st_ok: read one struct argument of parameter i of function f. Returns the name entry.
18094fn ca_st_ok f ulong i ulong to ulong
18095md = ulong 0
18096aa_word
18097w = get tw 0
18098c = kw w
18099if ne c 0
18100if or lt c 57 gt c 58
18101note d2site 458|ca_st_ok: syntax: unknown or misplaced word; condition if or lt c 57 gt c 58
18102put d2site 0 458
18103fail 16
18104end
18105md = c
18106aa_word
18107w = get tw 0
18108end
18109e = findname w
18110if eq e 0
18111note d2site 459|ca_st_ok: unknown name or field, or a word this mode does not provide; condition if eq e 0
18112put d2site 0 459
18113fail 3
18114end
18115ni = sub e 1
18116k = ulong uchar get a_ar add get a_rb 7 ni
18117if eq k 10
18118note d2site 460|ca_st_ok: type mismatch; condition if eq k 10
18119put d2site 0 460
18120fail 7
18121end
18122if lt k 6
18123note d2site 461|ca_st_ok: type mismatch; condition if lt k 6
18124put d2site 0 461
18125fail 7
18126end
18127p = add mul sub f 1 6 i
18128pk = ulong a_gu 37 p
18129if eq pk 7
18130if eq md 57
18131note d2site 462|ca_st_ok: write to a view or a text; condition if eq md 57
18132put d2site 0 462
18133fail 20
18134end
18135if eq k 8
18136note d2site 463|ca_st_ok: write to a view or a text; condition if eq k 8
18137put d2site 0 463
18138fail 20
18139end
18140else
18141if eq md 58
18142note d2site 464|ca_st_ok: type mismatch; condition if eq md 58
18143put d2site 0 464
18144fail 7
18145end
18146end
18147if ne ulong a_gu 5 ni ulong a_gu 35 p
18148note d2site 465|ca_st_ok: type mismatch; condition if ne ulong a_gu 5 ni ulong a_gu 35 p
18149put d2site 0 465
18150fail 7
18151end
18152ret e
18153end
18154
18155note ca_st: a struct argument. edit (fn_pk 7) needs own or edit; view takes any. Same struct.
18156fn ca_st f ulong i ulong cb ulong to void
18157e = ca_st_ok f i
18158note ca_dist: the same struct name passed twice in one call is error 19.
18159j = ulong 0
18160while lt j i
18161if eq a_g 77 add add cb mul j 3 2 e
18162note d2site 466|ca_st: global passed as an argument, or one array twice in a call; condition if eq a_g 77 add add cb mul j 3 2 e
18163put d2site 0 466
18164fail 19
18165end
18166j = add j 1
18167end
18168q = add cb mul i 3
18169put a_ar add get a_rb 77 q 5
18170a_p 77 add q 1 ulong a_gu 4 sub e 1
18171put a_ar add get a_rb 77 add q 2 e
18172end
18173note ---- R6 IR. A leading line `ir` writes OSC IR version 1. The AArch64 path is not taken.
18174note Worksheet ir_match.py matched omega_emit on the 10 dev programs; this is that algorithm.
18175
18176global ir_rty uchar 64
18177global ir_nreg ulong 1
18178global ir_nm ulong 32
18179global ir_nrr uchar 32
18180global ir_nn ulong 1
18181global ir_cty uchar 32
18182global ir_cm ulong 32
18183global ir_cr uchar 32
18184global ir_nc ulong 1
18185global ir_bord ulong 32
18186global ir_nord ulong 1
18187global ir_cur ulong 1
18188global ir_dead ulong 1
18189global ir_nb ulong 1
18190global ir_ok uchar 256
18191global ir_oa ulong 256
18192global ir_ob ulong 256
18193global ir_oc ulong 256
18194global ir_od ulong 256
18195global ir_obl ulong 256
18196global ir_no ulong 1
18197global ir_bf ulong 32
18198global ir_bc ulong 32
18199global ir_fk uchar 8
18200global ir_fa ulong 8
18201global ir_fb ulong 8
18202global ir_fc ulong 8
18203global ir_fd ulong 8
18204global ir_nf ulong 1
18205global ir_ret ulong 1
18206global ir_npar ulong 1
18207global ir_rr ulong 1
18208global ir_vt ulong 1
18209global ir_bare ulong 1
18210global ir_isb ulong 1
18211global ir_ns ulong 1
18212global ir_nl ulong 1
18213global ir_have ulong 1
18214global irrec uchar 2620252
18215global irrlen ulong 1
18216global irnf ulong 1
18217global irf_nm ulong 32
18218global irf_ns ulong 32
18219global irf_nl ulong 32
18220global irf_np ulong 32
18221global irf_ret uchar 32
18222global irf_pt uchar 192
18223global irf_n ulong 1
18224global ir_args ulong 6
18225global ir_oarg ulong 1536
18226global ir_miss ulong 1
18227global ir_cl ulong 1
18228global ir_cs ulong 1
18229note per open block frame, the local count when it opened (names bound inside go out of scope at else / end)
18230global ir_fnn ulong 8
18231note ir_bbig: tbig of the bare number in ir_bare, for the range check once its type is known (error 8).
18232global ir_bbig ulong 1
18233
18234note ir_lead: 1 when the first line is "ir" (after blanks). Both scans run as nested 999999-pass loops,
18235note so more than 1000000 leading blanks or first-line bytes are read, not trapped 4 (#671).
18236fn ir_lead to ulong
18237p = ulong 0
18238go = true
18239while go
18240m = ulong 0
18241while and go lt m 999999
18242if ge p get inlen 0
18243go = false
18244else
18245c = a_ib p
18246if gt c 32
18247go = false
18248else
18249if eq c 10
18250ret 0
18251end
18252p = add p 1
18253end
18254end
18255m = add m 1
18256end
18257end
18258if ge add p 3 get inlen 0
18259ret 0
18260end
18261if ne uchar and shr get a_ar shr p 3 shl and p 7 3 255 105
18262ret 0
18263end
18264if ne uchar and shr get a_ar shr add p 1 3 shl and add p 1 7 3 255 114
18265ret 0
18266end
18267if gt uchar and shr get a_ar shr add p 2 3 shl and add p 2 7 3 255 32
18268ret 0
18269end
18270q = add p 2
18271go = true
18272while go
18273m = ulong 0
18274while and go lt m 999999
18275if ge q get inlen 0
18276go = false
18277else
18278if eq a_ib q 10
18279go = false
18280else
18281q = add q 1
18282end
18283end
18284m = add m 1
18285end
18286end
18287if lt q get inlen 0
18288q = add q 1
18289end
18290put cur 0 q
18291put line 0 2
18292ret 1
18293end
18294
18295fn ir_w16 v ulong to void
18296emitb uchar and v 255
18297emitb uchar and shr v 8 255
18298end
18299
18300fn ir_w32 v ulong to void
18301ir_w16 v
18302ir_w16 shr v 16
18303end
18304
18305fn ir_w64 v ulong to void
18306ir_w32 v
18307ir_w32 shr v 32
18308end
18309
18310fn ir_newreg ty ulong to ulong
18311r = get ir_nreg 0
18312if ge r 64
18313note d2site 467|ir_newreg: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge r 64
18314put d2site 0 467
18315fail 14
18316end
18317put ir_rty r uchar ty
18318put ir_nreg 0 add r 1
18319ret r
18320end
18321
18322fn ir_block to ulong
18323b = get ir_nb 0
18324if ge b 32
18325note d2site 468|ir_block: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge b 32
18326put d2site 0 468
18327fail 14
18328end
18329put ir_bord b 65535
18330put ir_nb 0 add b 1
18331ret b
18332end
18333
18334fn ir_start b ulong to void
18335put ir_bord b get ir_nord 0
18336put ir_nord 0 add get ir_nord 0 1
18337put ir_cur 0 b
18338put ir_dead 0 0
18339end
18340
18341fn ir_op k ulong a ulong b ulong c ulong d ulong to void
18342if ne get ir_dead 0 0
18343note d2site 469|ir_op: line after ret, break, continue, trap or exit in the same block; condition if ne get ir_dead 0 0
18344put d2site 0 469
18345fail 17
18346end
18347n = get ir_no 0
18348if ge n 256
18349note d2site 470|ir_op: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 256
18350put d2site 0 470
18351fail 14
18352end
18353put ir_ok n uchar k
18354put ir_oa n a
18355put ir_ob n b
18356put ir_oc n c
18357put ir_od n d
18358put ir_obl n get ir_cur 0
18359put ir_no 0 add n 1
18360end
18361
18362fn ir_lit mag ulong ty ulong to ulong
18363i = ulong 0
18364n = get ir_nc 0
18365while lt i n
18366if and eq ulong get ir_cty i ty eq get ir_cm i mag
18367ret ulong get ir_cr i
18368end
18369i = add i 1
18370end
18371if ge n 32
18372note d2site 471|ir_lit: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 32
18373put d2site 0 471
18374fail 14
18375end
18376r = ir_newreg ty
18377put ir_cty n uchar ty
18378put ir_cm n mag
18379put ir_cr n uchar r
18380put ir_nc 0 add n 1
18381ret r
18382end
18383
18384note ir_find: the local in scope named w (packed) -> its index + 1, or 0. Locals are at most 8 bytes, so a
18385note word of length l over 8 is never one (its packed first 8 bytes may equal a local's name).
18386fn ir_find w ulong l ulong to ulong
18387if gt l 8
18388ret 0
18389end
18390i = ulong 0
18391while lt i get ir_nn 0
18392if eq get ir_nm i w
18393ret add i 1
18394end
18395i = add i 1
18396end
18397ret 0
18398end
18399
18400fn ir_bind w ulong r ulong to void
18401n = get ir_nn 0
18402if ge n 32
18403note d2site 472|ir_bind: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 32
18404put d2site 0 472
18405fail 14
18406end
18407put ir_nm n w
18408put ir_nrr n uchar r
18409put ir_nn 0 add n 1
18410end
18411
18412note ir_kwt: the keyword number of the current word, or 0 for a word over 8 bytes (only 8 are packed).
18413fn ir_kwt to ulong
18414if gt get tl 0 8
18415ret 0
18416end
18417ret kw get tw 0
18418end
18419
18420note ir_newname: a new local, parameter or function name must not be a keyword (16), a local in scope, a
18421note constant, or a function of the unit so far, the current one included (10, as newname). Function
18422note names compare in full (up to 63 bytes).
18423fn ir_newname w ulong s ulong l ulong to void
18424if le l 8
18425if ne kw w 0
18426note d2site 473|ir_newname: syntax: unknown or misplaced word; condition if ne kw w 0
18427put d2site 0 473
18428fail 16
18429end
18430if ne findname w 0
18431note d2site 474|ir_newname: duplicate name; condition if ne findname w 0
18432put d2site 0 474
18433fail 10
18434end
18435end
18436if ne ir_find w l 0
18437note d2site 475|ir_newname: duplicate name; condition if ne ir_find w l 0
18438put d2site 0 475
18439fail 10
18440end
18441put ir_cl 0 l
18442put ir_cs 0 s
18443j = ulong 0
18444while lt j get irf_n 0
18445if eq get irf_nm j w
18446if ne ir_nameeq j 0
18447note d2site 476|ir_newname: duplicate name; condition if ne ir_nameeq j 0
18448put d2site 0 476
18449fail 10
18450end
18451end
18452j = add j 1
18453end
18454end
18455
18456note ir_newloc: a new local, parameter or for counter: at most 8 bytes (13, as native), then ir_newname.
18457fn ir_newloc w ulong s ulong l ulong to void
18458if gt l 8
18459note d2site 477|ir_newloc: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt l 8
18460put d2site 0 477
18461fail 13
18462end
18463ir_newname w s l
18464end
18465
18466note ir_type: a type word IR v1 lowers: 1 .. 9, or void (76) when isret is 1. A float, a view / edit array or
18467note void elsewhere is error 9 (as typeword in IR mode); no word is 4; another word 16.
18468fn ir_type isret ulong to ulong
18469tok
18470if or eq get tk 0 0 eq get tk 0 3
18471note d2site 478|ir_type: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3
18472put d2site 0 478
18473fail 4
18474end
18475if ne get tk 0 1
18476note d2site 479|ir_type: syntax: unknown or misplaced word; condition if ne get tk 0 1
18477put d2site 0 479
18478fail 16
18479end
18480c = ir_kwt
18481if and ge c 1 le c 9
18482ret c
18483end
18484if and eq c 76 eq isret 1
18485ret c
18486end
18487if or or eq c 76 eq c 88 eq c 89
18488note d2site 480|ir_type: word or declaration in a place that does not allow it; condition if or or eq c 76 eq c 88 eq c 89
18489put d2site 0 480
18490fail 9
18491end
18492if or eq c 57 eq c 58
18493note d2site 481|ir_type: word or declaration in a place that does not allow it; condition if or eq c 57 eq c 58
18494put d2site 0 481
18495fail 9
18496end
18497note d2site 482|ir_type: syntax: unknown or misplaced word
18498put d2site 0 482
18499fail 16
18500ret 0
18501end
18502
18503fn ir_push k ulong a ulong b ulong c ulong d ulong to void
18504n = get ir_nf 0
18505if ge n 8
18506note d2site 483|ir_push: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 8
18507put d2site 0 483
18508fail 14
18509end
18510put ir_fk n uchar k
18511put ir_fa n a
18512put ir_fb n b
18513put ir_fc n c
18514put ir_fd n d
18515put ir_fnn n get ir_nn 0
18516put ir_nf 0 add n 1
18517end
18518
18519fn ir_set dst ulong r ulong ty ulong to void
18520put ir_isb 0 0
18521if eq dst 65534
18522put ir_rr 0 r
18523put ir_vt 0 ty
18524ret
18525end
18526d = dst
18527if eq dst 65535
18528d = ir_newreg ty
18529end
18530ir_op 2 d r 0 0
18531put ir_rr 0 d
18532put ir_vt 0 ty
18533end
18534
18535fn ir_ord id ulong to ulong
18536ret get ir_bord id
18537end
18538
18539
18540
18541
18542fn ir_wins k ulong to void
18543if eq k 0
18544i = ulong 0
18545while lt i get ir_nc 0
18546emitb 1
18547ir_w16 ulong get ir_cr i
18548ir_w64 get ir_cm i
18549i = add i 1
18550end
18551end
18552i = ulong 0
18553while lt i get ir_no 0
18554if eq ir_ord get ir_obl i k
18555op = ulong get ir_ok i
18556emitb uchar op
18557if eq op 1
18558ir_w16 get ir_oa i
18559ir_w64 get ir_ob i
18560end
18561if eq op 2
18562ir_w16 get ir_oa i
18563ir_w16 get ir_ob i
18564end
18565if eq op 3
18566emitb uchar get ir_oa i
18567ir_w16 get ir_ob i
18568ir_w16 get ir_oc i
18569ir_w16 get ir_od i
18570end
18571if eq op 4
18572emitb uchar get ir_oa i
18573ir_w16 get ir_ob i
18574ir_w16 get ir_oc i
18575end
18576if eq op 5
18577emitb uchar get ir_oa i
18578ir_w16 get ir_ob i
18579ir_w16 get ir_oc i
18580ir_w16 get ir_od i
18581end
18582if eq op 6
18583ir_w16 get ir_oa i
18584ir_w16 get ir_ob i
18585end
18586if eq op 11
18587ir_w16 get ir_oa i
18588ir_w16 get ir_ob i
18589emitb uchar get ir_oc i
18590j = ulong 0
18591while lt j get ir_oc i
18592ir_w16 get ir_oarg add mul i 6 j
18593j = add j 1
18594end
18595end
18596if eq op 12
18597emitb uchar get ir_oa i
18598end
18599if eq op 13
18600ir_w16 ir_ord get ir_oa i
18601end
18602if eq op 14
18603ir_w16 get ir_oa i
18604ir_w16 ir_ord get ir_ob i
18605ir_w16 ir_ord get ir_oc i
18606end
18607if eq op 15
18608ir_w16 get ir_oa i
18609end
18610end
18611i = add i 1
18612end
18613end
18614
18615fn ir_record to void
18616emitb uchar get ir_nl 0
18617p = get ir_ns 0
18618e = add p get ir_nl 0
18619while lt p e
18620emitb uchar and shr get a_ar shr p 3 shl and p 7 3 255
18621p = add p 1
18622end
18623emitb uchar get ir_npar 0
18624if eq get ir_ret 0 76
18625emitb 0
18626else
18627emitb uchar get ir_ret 0
18628end
18629ir_w16 get ir_nreg 0
18630i = ulong 0
18631while lt i get ir_nreg 0
18632emitb get ir_rty i
18633i = add i 1
18634end
18635note Lay out blocks and count their instructions here, preserving constant records in block zero.
18636k = ulong 0
18637at = ulong 0
18638while lt k get ir_nord 0
18639put ir_bf k at
18640c = ulong 0
18641if eq k 0
18642c = get ir_nc 0
18643end
18644i = ulong 0
18645while lt i get ir_no 0
18646if eq ir_ord get ir_obl i k
18647c = add c 1
18648end
18649i = add i 1
18650end
18651put ir_bc k c
18652at = add at c
18653k = add k 1
18654end
18655put ir_no 0 get ir_no 0
18656ir_w16 get ir_nord 0
18657k = ulong 0
18658while lt k get ir_nord 0
18659ir_w32 get ir_bf k
18660ir_w32 get ir_bc k
18661k = add k 1
18662end
18663tot = ulong 0
18664k = ulong 0
18665while lt k get ir_nord 0
18666tot = add tot get ir_bc k
18667k = add k 1
18668end
18669ir_w32 tot
18670k = ulong 0
18671while lt k get ir_nord 0
18672ir_wins k
18673k = add k 1
18674end
18675ir_w16 0
18676ir_w16 0
18677end
18678
18679note ir_emit_record: encode the current function into irrec and count it. The per-function IR state is
18680note reset by ir_fn, so this must run before the next fn line.
18681fn ir_emit_record to void
18682if ge get irnf 0 32
18683note d2site 484|ir_emit_record: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge get irnf 0 32
18684put d2site 0 484
18685fail 14
18686end
18687put oc 0 0
18688ir_record
18689n = get oc 0
18690base = get irrlen 0
18691i = ulong 0
18692while lt i n
18693put irrec add base i a_ob i
18694i = add i 1
18695end
18696put irrlen 0 add base n
18697put irnf 0 add get irnf 0 1
18698end
18699
18700
18701note ir_nameeq: table entry j's name equals the current source name token (length and bytes past 8).
18702fn ir_nameeq j ulong to ulong
18703fl = get irf_nl j
18704if ne fl get ir_cl 0
18705ret 0
18706end
18707k = ulong 8
18708same = ulong 1
18709while and eq same 1 lt k get ir_cl 0
18710left = a_ib add get irf_ns j k
18711right = a_ib add get ir_cs 0 k
18712if ne left right
18713same = 0
18714end
18715k = add k 1
18716end
18717ret same
18718end
18719
18720note ir_findfn: packed name -> earlier function index + 1, or 0. The current function is the newest
18721note table entry and is never returned, so self and forward calls fail.
18722fn ir_findfn w ulong to ulong
18723if le get irf_n 0 1
18724ret 0
18725end
18726fc = sub get irf_n 0 1
18727j = ulong 0
18728while lt j fc
18729if eq get irf_nm j w
18730if ne ir_nameeq j 0
18731ret add j 1
18732end
18733end
18734j = add j 1
18735end
18736ret 0
18737end
18738
18739note ir_callop: CALL in the IR's five-field form; the argument registers live in ir_args[0..nargs).
18740fn ir_callop dst ulong callee ulong nargs ulong to void
18741if ne get ir_dead 0 0
18742note d2site 485|ir_callop: line after ret, break, continue, trap or exit in the same block; condition if ne get ir_dead 0 0
18743put d2site 0 485
18744fail 17
18745end
18746n = get ir_no 0
18747if ge n 256
18748note d2site 486|ir_callop: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 256
18749put d2site 0 486
18750fail 14
18751end
18752put ir_ok n 11
18753put ir_oa n dst
18754put ir_ob n callee
18755put ir_oc n nargs
18756put ir_od n 0
18757put ir_obl n get ir_cur 0
18758j = ulong 0
18759while lt j nargs
18760put ir_oarg add mul n 6 j get ir_args j
18761j = add j 1
18762end
18763put ir_no 0 add n 1
18764end
18765
18766fn ir_name to void
18767e = ir_find get tw 0 get tl 0
18768if eq e 0
18769if le get tl 0 8
18770e = findname get tw 0
18771end
18772if ne e 0
18773if eq uchar get a_ar add get a_rb 7 sub e 1 9
18774t = ulong uchar get a_ar add get a_rb 5 sub e 1
18775if ge t 10
18776note d2site 487|ir_name: word or declaration in a place that does not allow it; condition if ge t 10
18777put d2site 0 487
18778fail 9
18779end
18780r = ir_lit get a_ar add get a_rb 8 sub e 1 t
18781ir_set 65534 r t
18782ret
18783end
18784end
18785put ir_miss 0 1
18786ret
18787end
18788r = ulong get ir_nrr sub e 1
18789ir_set 65534 r ulong get ir_rty r
18790end
18791
18792fn ir_un c ulong dst ulong to void
18793ir_val 65534 0
18794if ne get ir_isb 0 0
18795note d2site 488|ir_un: bare number without a type from its context; condition if ne get ir_isb 0 0
18796put d2site 0 488
18797fail 11
18798end
18799ty = get ir_vt 0
18800if and eq c 49 eq ty 1
18801note d2site 489|ir_un: type mismatch; condition if and eq c 49 eq ty 1
18802put d2site 0 489
18803fail 7
18804end
18805d = dst
18806if or eq dst 65534 eq dst 65535
18807d = ir_newreg ty
18808end
18809su = ulong 1
18810if eq c 50
18811su = ulong 3
18812if ne ty 1
18813su = ulong 2
18814end
18815end
18816ir_op 4 su d get ir_rr 0 0
18817put ir_rr 0 d
18818put ir_vt 0 ty
18819put ir_isb 0 0
18820end
18821
18822fn ir_bin_r left ulong lty ulong c ulong dst ulong to void
18823exp2 = lty
18824if or eq c 41 eq c 42
18825exp2 = ulong 0
18826end
18827ir_val 65534 exp2
18828ir_bin_done left lty c dst
18829end
18830
18831fn ir_bin_done left ulong lty ulong c ulong dst ulong to void
18832isb2 = get ir_isb 0
18833ty2 = get ir_vt 0
18834if or eq c 41 eq c 42
18835if or ge lty 10 eq lty 1
18836note d2site 490|ir_bin_done: type mismatch; condition if or ge lty 10 eq lty 1
18837put d2site 0 490
18838fail 7
18839end
18840if eq isb2 0
18841if or ge ty2 10 eq ty2 1
18842note d2site 491|ir_bin_done: type mismatch; condition if or ge ty2 10 eq ty2 1
18843put d2site 0 491
18844fail 7
18845end
18846end
18847else
18848if ge lty 10
18849note d2site 492|ir_bin_done: type mismatch; condition if ge lty 10
18850put d2site 0 492
18851fail 7
18852end
18853if and eq isb2 0 ne ty2 lty
18854note d2site 493|ir_bin_done: type mismatch; condition if and eq isb2 0 ne ty2 lty
18855put d2site 0 493
18856fail 7
18857end
18858if and and ge c 33 le c 37 eq lty 1
18859note d2site 494|ir_bin_done: type mismatch; condition if and and ge c 33 le c 37 eq lty 1
18860put d2site 0 494
18861fail 7
18862end
18863end
18864right = get ir_rr 0
18865if ne isb2 0
18866range get ir_bare 0 lty get ir_bbig 0
18867right = ir_lit get ir_bare 0 lty
18868end
18869if ge c 43
18870d = dst
18871if or eq dst 65534 eq dst 65535
18872d = ir_newreg 1
18873end
18874ir_op 5 sub c 42 d left right
18875put ir_rr 0 d
18876put ir_vt 0 1
18877ret
18878end
18879d = dst
18880if or eq dst 65534 eq dst 65535
18881d = ir_newreg lty
18882end
18883ir_op 3 sub c 32 d left right
18884put ir_rr 0 d
18885put ir_vt 0 lty
18886put ir_isb 0 0
18887end
18888
18889fn ir_bin c ulong dst ulong to void
18890ir_val 65534 0
18891if ne get ir_isb 0 0
18892mag = get ir_bare 0
18893bg = get ir_bbig 0
18894ir_val 65534 0
18895if ne get ir_isb 0 0
18896note d2site 495|ir_bin: bare number without a type from its context; condition if ne get ir_isb 0 0
18897put d2site 0 495
18898fail 11
18899end
18900ty = get ir_vt 0
18901range mag ty bg
18902left = ir_lit mag ty
18903ir_bin_done left ty c dst
18904ret
18905end
18906left = get ir_rr 0
18907lty = get ir_vt 0
18908ir_bin_r left lty c dst
18909end
18910
18911note ir_cast: TYPE v. The operand keeps its own type (as native rdval reads it, exp 0); a bare number is
18912note checked against TYPE (8). bool converts to and from numbers only by comparison (9, as vt_conv).
18913note Only a constant of TYPE is the value itself; any other same-type value is a mov, as the C oracle.
18914fn ir_cast c ulong dst ulong to void
18915ir_val 65534 0
18916if ne get ir_isb 0 0
18917range get ir_bare 0 c get ir_bbig 0
18918r = ir_lit get ir_bare 0 c
18919ir_set dst r c
18920ret
18921end
18922src = get ir_rr 0
18923sty = get ir_vt 0
18924if xor eq sty 1 eq c 1
18925note d2site 496|ir_cast: word or declaration in a place that does not allow it; condition if xor eq sty 1 eq c 1
18926put d2site 0 496
18927fail 9
18928end
18929k = ulong 0
18930if and eq sty c eq dst 65534
18931i = ulong 0
18932while lt i get ir_nc 0
18933if eq ulong get ir_cr i src
18934k = ulong 1
18935end
18936i = add i 1
18937end
18938end
18939if ne k 0
18940put ir_rr 0 src
18941put ir_vt 0 c
18942put ir_isb 0 0
18943ret
18944end
18945d = dst
18946if or eq dst 65534 eq dst 65535
18947d = ir_newreg c
18948end
18949if eq sty c
18950ir_op 2 d src 0 0
18951else
18952ir_op 6 d src 0 0
18953end
18954put ir_rr 0 d
18955put ir_vt 0 c
18956put ir_isb 0 0
18957end
18958
18959note ir_val: one IR-mode value (ir_valb), counted in irdep. IR mode reads values by recursion as rdval does,
18960note so it has the same stack-derived bound (rdval's notes): deeper than 32768 is error 14 on its line,
18961note never a trap 6 in omc. Measured 2026-11-11: omc f4fa7951 trapped 6 at 140000 nested IR calls.
18962global irdep ulong 1
18963fn ir_val dst ulong exp ulong to void
18964put irdep 0 add get irdep 0 1
18965if gt get irdep 0 32768
18966note d2site 497|ir_val: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if gt get irdep 0 32768
18967put d2site 0 497
18968fail 14
18969end
18970ir_valb dst exp
18971put irdep 0 sub get irdep 0 1
18972end
18973
18974fn ir_valb dst ulong exp ulong to void
18975put ir_isb 0 0
18976put ir_miss 0 0
18977tok
18978if or eq get tk 0 0 eq get tk 0 3
18979note d2site 498|ir_valb: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3
18980put d2site 0 498
18981fail 4
18982end
18983if or eq get tk 0 4 eq get tk 0 5
18984note d2site 499|ir_valb: word or declaration in a place that does not allow it; condition if or eq get tk 0 4 eq get tk 0 5
18985put d2site 0 499
18986fail 9
18987end
18988if eq get tk 0 2
18989if eq exp 0
18990put ir_bare 0 get tw 0
18991put ir_bbig 0 get tbig 0
18992put ir_isb 0 1
18993ret
18994end
18995range get tw 0 exp get tbig 0
18996r = ir_lit get tw 0 exp
18997ir_set dst r exp
18998ret
18999end
19000c = ir_kwt
19001if and ge c 1 le c 9
19002ir_cast c dst
19003ret
19004end
19005if and ge c 33 le c 48
19006ir_bin c dst
19007if and ne exp 0 ne get ir_vt 0 exp
19008note d2site 500|ir_valb: type mismatch; condition if and ne exp 0 ne get ir_vt 0 exp
19009put d2site 0 500
19010fail 7
19011end
19012ret
19013end
19014if or eq c 49 eq c 50
19015ir_un c dst
19016if and ne exp 0 ne get ir_vt 0 exp
19017note d2site 501|ir_valb: type mismatch; condition if and ne exp 0 ne get ir_vt 0 exp
19018put d2site 0 501
19019fail 7
19020end
19021ret
19022end
19023if eq c 55
19024if and ne exp 0 ne exp 1
19025note d2site 502|ir_valb: type mismatch; condition if and ne exp 0 ne exp 1
19026put d2site 0 502
19027fail 7
19028end
19029r = ir_lit 1 1
19030ir_set dst r 1
19031ret
19032end
19033if eq c 56
19034if and ne exp 0 ne exp 1
19035note d2site 503|ir_valb: type mismatch; condition if and ne exp 0 ne exp 1
19036put d2site 0 503
19037fail 7
19038end
19039r = ir_lit 0 1
19040ir_set dst r 1
19041ret
19042end
19043ir_name
19044if ne get ir_miss 0 0
19045put ir_cl 0 get tl 0
19046put ir_cs 0 get ts 0
19047f = ir_findfn get tw 0
19048if eq f 0
19049note d2site 504|ir_valb: unknown name or field, or a word this mode does not provide; condition if eq f 0
19050put d2site 0 504
19051fail 3
19052end
19053j = sub f 1
19054rtv = ulong get irf_ret j
19055if eq rtv 76
19056note d2site 505|ir_valb: type mismatch; condition if eq rtv 76
19057put d2site 0 505
19058fail 7
19059end
19060np = get irf_np j
19061i = ulong 0
19062while lt i np
19063ty = ulong get irf_pt add mul j 6 i
19064ir_val 65534 ty
19065if ne get ir_vt 0 ty
19066note d2site 506|ir_valb: type mismatch; condition if ne get ir_vt 0 ty
19067put d2site 0 506
19068fail 7
19069end
19070put ir_args i get ir_rr 0
19071i = add i 1
19072end
19073r = dst
19074if or eq dst 65534 eq dst 65535
19075r = ir_newreg rtv
19076end
19077ir_callop r j np
19078put ir_rr 0 r
19079put ir_vt 0 rtv
19080ret
19081end
19082if ne dst 65534
19083ir_set dst get ir_rr 0 get ir_vt 0
19084end
19085end
19086
19087fn ir_end to void
19088n = sub get ir_nf 0 1
19089put ir_nf 0 n
19090k = ulong get ir_fk n
19091put ir_nn 0 get ir_fnn n
19092if eq k 1
19093if eq get ir_fc n 0
19094if eq get ir_dead 0 0
19095ir_op 13 get ir_fb n 0 0 0
19096put ir_dead 0 1
19097end
19098ir_start get ir_fb n
19099else
19100if eq get ir_dead 0 0
19101if eq get ir_fd n 65535
19102j = ir_block
19103put ir_fd n j
19104end
19105ir_op 13 get ir_fd n 0 0 0
19106put ir_dead 0 1
19107end
19108if ne get ir_fd n 65535
19109ir_start get ir_fd n
19110end
19111end
19112end
19113if eq k 2
19114if eq get ir_dead 0 0
19115ir_op 13 get ir_fa n 0 0 0
19116put ir_dead 0 1
19117end
19118ir_start get ir_fb n
19119end
19120if eq k 3
19121if eq get ir_dead 0 0
19122one = ir_lit 1 ulong get ir_rty get ir_fc n
19123ir_op 3 1 get ir_fc n get ir_fc n one
19124ir_op 13 get ir_fa n 0 0 0
19125put ir_dead 0 1
19126end
19127ir_start get ir_fb n
19128end
19129if eq k 4
19130if eq get ir_dead 0 0
19131if ne get ir_ret 0 76
19132note d2site 507|ir_end: a function with a result can reach its end; condition if ne get ir_ret 0 76
19133put d2site 0 507
19134fail 18
19135end
19136ir_op 15 65535 0 0 0
19137put ir_dead 0 1
19138end
19139put ir_have 0 1
19140end
19141eol
19142end
19143
19144note ir_bound: the rest of a while or for line: `bound N` (1 .. 1000000, error 8: the C oracle's range,
19145note omegese.c, and the guard range checker2 proves) -> N, or 0 when the line ends there.
19146fn ir_bound to ulong
19147tok
19148if or eq get tk 0 0 eq get tk 0 3
19149ret 0
19150end
19151if or ne get tk 0 1 ne ir_kwt 70
19152note d2site 508|ir_bound: extra words after a complete statement; condition if or ne get tk 0 1 ne ir_kwt 70
19153put d2site 0 508
19154fail 5
19155end
19156bnd = lenval 4
19157if ge sub bnd 1 1000000
19158note d2site 509|ir_bound: number out of range for its type or place; condition if ge sub bnd 1 1000000
19159put d2site 0 509
19160fail 8
19161end
19162eol
19163ret bnd
19164end
19165
19166fn ir_while to void
19167z = ir_lit 0 5
19168one = ir_lit 1 5
19169cnt = ir_newreg 5
19170ir_op 2 cnt z 0 0
19171h = ir_block
19172g = ir_block
19173tb = ir_block
19174body = ir_block
19175ex = ir_block
19176ir_op 13 h 0 0 0
19177put ir_dead 0 1
19178ir_start h
19179ir_val 65534 1
19180if ne get ir_vt 0 1
19181note d2site 510|ir_while: type mismatch; condition if ne get ir_vt 0 1
19182put d2site 0 510
19183fail 7
19184end
19185lim = ir_bound
19186if eq lim 0
19187lim = ulong 1000000
19188end
19189lim = ir_lit lim 5
19190ir_op 14 get ir_rr 0 g ex 0
19191ir_start g
19192ger = ir_newreg 1
19193ir_op 5 6 ger cnt lim
19194ir_op 14 ger tb body 0
19195ir_start tb
19196ir_op 12 4 0 0 0
19197ir_op 13 ex 0 0 0
19198put ir_dead 0 1
19199ir_start body
19200ir_op 3 1 cnt cnt one
19201ir_push 2 h ex cnt 0
19202end
19203
19204note ir_for: for name type count [bound N]. The counter is bound after the count is read, so the count cannot
19205note name it. nc: 1 when the count is a number or an integer constant name (not a local), seen ahead without
19206note reading it. Such a count must be 0..1000000 (error 8 otherwise, a minus sign included): the C oracle's
19207note count range (omegese.c for_line), so a plain loop never counts past what checker2 proves. Such a count
19208note with no bound opens the plain loop (ir_forg with N = 0); any other count, and any count with a bound,
19209note opens the guarded loop with N, default 1000000. The counter leaves scope at its end.
19210fn ir_for to void
19211tok
19212if or eq get tk 0 0 eq get tk 0 3
19213note d2site 511|ir_for: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3
19214put d2site 0 511
19215fail 4
19216end
19217if ne get tk 0 1
19218note d2site 512|ir_for: syntax: unknown or misplaced word; condition if ne get tk 0 1
19219put d2site 0 512
19220fail 16
19221end
19222w = get tw 0
19223ir_newloc w get ts 0 get tl 0
19224ty = ir_type 0
19225if eq ty 1
19226note d2site 513|ir_for: type mismatch; condition if eq ty 1
19227put d2site 0 513
19228fail 7
19229end
19230c0 = get cur 0
19231l0 = get line 0
19232a0 = get tka 0
19233b0 = get tkb 0
19234tok
19235nc = ulong 0
19236if eq get tk 0 2
19237nc = ulong 1
19238if eq a_ib get ts 0 45
19239note d2site 514|ir_for: number out of range for its type or place; condition if eq a_ib get ts 0 45
19240put d2site 0 514
19241fail 8
19242end
19243if gt get tw 0 1000000
19244note d2site 515|ir_for: number out of range for its type or place; condition if gt get tw 0 1000000
19245put d2site 0 515
19246fail 8
19247end
19248end
19249if and eq get tk 0 1 le get tl 0 8
19250if eq ir_find get tw 0 get tl 0 0
19251e = findname get tw 0
19252if ne e 0
19253if eq a_gu 7 sub e 1 9
19254nc = ulong 1
19255if lt a_gu 5 sub e 1 10
19256if gt a_g 8 sub e 1 1000000
19257note d2site 516|ir_for: number out of range for its type or place; condition if gt a_g 8 sub e 1 1000000
19258put d2site 0 516
19259fail 8
19260end
19261end
19262end
19263end
19264end
19265end
19266put cur 0 c0
19267put line 0 l0
19268put tka 0 a0
19269put tkb 0 b0
19270if eq nc 1
19271z = ir_lit 0 ty
19272end
19273ir_val 65534 ty
19274if ne get ir_vt 0 ty
19275note d2site 517|ir_for: type mismatch; condition if ne get ir_vt 0 ty
19276put d2site 0 517
19277fail 7
19278end
19279kr = get ir_rr 0
19280bn = ir_bound
19281if and eq bn 0 eq nc 0
19282bn = ulong 1000000
19283end
19284ir_forg w ty kr bn
19285end
19286
19287note ir_forg: the for loop over counter ctr = 0 below kr. N = 0: the plain loop, head: lt ctr kr -> body | exit.
19288note Else the guarded loop, the C oracle's shape (omegese.c guarded_loop): a ulong counter cnt = 0 as well; head:
19289note lt ctr kr -> guard | exit; guard: ge cnt N -> trap 4 | body; body starts with cnt = add cnt 1. Literals and
19290note blocks are made in the oracle's order (literals are shared). The latch adds 1 to ctr (ir_end kind 3). The
19291note for frame (kind 3: head h, exit ex, counter ctr): the counter, bound last, leaves scope at the end.
19292note The literals 0 and 1 are made first (shared; ir_lit returns the same register again), then the counters.
19293note om4 holds 16 registers per function, so the guard blocks reuse names already dead: ty is the guard block
19294note and w the trap block (both after ir_bind); cnt is 0 only in the plain loop (two literals precede it).
19295fn ir_forg w ulong ty ulong kr ulong bn ulong to void
19296cnt = ulong 0
19297if ne bn 0
19298cnt = ir_lit 0 5
19299cnt = ir_lit 1 5
19300cnt = ir_newreg 5
19301end
19302ctr = ir_lit 0 ty
19303ctr = ir_lit 1 ty
19304ctr = ir_newreg ty
19305ir_op 2 ctr ir_lit 0 ty 0 0
19306ir_bind w ctr
19307h = ir_block
19308if ne bn 0
19309ir_op 2 cnt ir_lit 0 5 0 0
19310ty = ir_block
19311w = ir_block
19312end
19313body = ir_block
19314ex = ir_block
19315ir_op 13 h 0 0 0
19316put ir_dead 0 1
19317ir_start h
19318c = ir_newreg 1
19319ir_op 5 3 c ctr kr
19320if eq bn 0
19321ir_op 14 c body ex 0
19322else
19323bn = ir_lit bn 5
19324ir_op 14 c ty ex 0
19325ir_start ty
19326c = ir_newreg 1
19327ir_op 5 6 c cnt bn
19328ir_op 14 c w body 0
19329ir_start w
19330ir_op 12 4 0 0 0
19331ir_op 13 ex 0 0 0
19332put ir_dead 0 1
19333end
19334ir_start body
19335if ne cnt 0
19336ir_op 3 1 cnt cnt ir_lit 1 5
19337end
19338ir_push 3 h ex ctr 0
19339kr = sub get ir_nf 0 1
19340put ir_fnn kr sub get ir_nn 0 1
19341end
19342
19343note ir_stmtcall: a void call as a statement; f is the table index + 1.
19344fn ir_stmtcall f ulong to void
19345j = sub f 1
19346if ne get irf_ret j 76
19347note d2site 518|ir_stmtcall: type mismatch; condition if ne get irf_ret j 76
19348put d2site 0 518
19349fail 7
19350end
19351np = get irf_np j
19352i = ulong 0
19353while lt i np
19354ty = ulong get irf_pt add mul j 6 i
19355ir_val 65534 ty
19356if ne get ir_vt 0 ty
19357note d2site 519|ir_stmtcall: type mismatch; condition if ne get ir_vt 0 ty
19358put d2site 0 519
19359fail 7
19360end
19361put ir_args i get ir_rr 0
19362i = add i 1
19363end
19364ir_callop 65535 j np
19365eol
19366end
19367
19368note ir_assign: name [=] value for a local in scope, a void call, or a new typed local (a new name that is
19369note a keyword, constant, local or function is refused; a bare number has no type, error 11).
19370fn ir_assign w ulong to void
19371p = get ts 0
19372l = get tl 0
19373c0 = get cur 0
19374tok
19375eqs = false
19376if and eq get tk 0 1 eq ir_kwt 73
19377eqs = true
19378else
19379put cur 0 c0
19380if eq get tk 0 0
19381put line 0 sub get line 0 1
19382end
19383end
19384e = ir_find w l
19385if ne e 0
19386r = ulong get ir_nrr sub e 1
19387ir_val r ulong get ir_rty r
19388if ne get ir_vt 0 ulong get ir_rty r
19389note d2site 520|ir_assign: type mismatch; condition if ne get ir_vt 0 ulong get ir_rty r
19390put d2site 0 520
19391fail 7
19392end
19393eol
19394ret
19395end
19396put ir_cl 0 l
19397put ir_cs 0 p
19398f = ir_findfn w
19399if ne f 0
19400if eqs
19401note d2site 521|ir_assign: type mismatch; condition if eqs
19402put d2site 0 521
19403fail 7
19404end
19405ir_stmtcall f
19406ret
19407end
19408if le l 8
19409if ne findname w 0
19410note d2site 522|ir_assign: type mismatch; condition if ne findname w 0
19411put d2site 0 522
19412fail 7
19413end
19414end
19415ir_newloc w p l
19416ir_val 65535 0
19417if ne get ir_isb 0 0
19418note d2site 523|ir_assign: bare number without a type from its context; condition if ne get ir_isb 0 0
19419put d2site 0 523
19420fail 11
19421end
19422eol
19423ir_bind w get ir_rr 0
19424end
19425
19426note ir_loopexit: innermost loop block's exit + 1, or 0 outside a loop.
19427fn ir_loopexit to ulong
19428i = get ir_nf 0
19429while gt i 0
19430i = sub i 1
19431k = ulong get ir_fk i
19432if or eq k 2 eq k 3
19433ret add get ir_fb i 1
19434end
19435end
19436ret 0
19437end
19438
19439note ir_stmt: one line. The end of the input inside a function is error 15; a line starting with a number
19440note is 16; a note is skipped even after the path ended; a statement IR v1 does not lower is 9.
19441fn ir_stmt to ulong
19442tok
19443if eq get tk 0 0
19444ret 0
19445end
19446if eq get tk 0 3
19447note d2site 524|ir_stmt: missing end; condition if eq get tk 0 3
19448put d2site 0 524
19449fail 15
19450end
19451if ne get tk 0 1
19452note d2site 525|ir_stmt: syntax: unknown or misplaced word; condition if ne get tk 0 1
19453put d2site 0 525
19454fail 16
19455end
19456c = ir_kwt
19457if eq c 83
19458skipnl
19459ret 0
19460end
19461if and ne c 66 ne c 68
19462if ne get ir_dead 0 0
19463note d2site 526|ir_stmt: line after ret, break, continue, trap or exit in the same block; condition if ne get ir_dead 0 0
19464put d2site 0 526
19465fail 17
19466end
19467end
19468if eq c 77
19469note d2site 527|ir_stmt: word or declaration in a place that does not allow it; condition if eq c 77
19470put d2site 0 527
19471fail 9
19472end
19473if eq c 87
19474note ir_trap: OMEGESE section 4. A trap ends the path but the IR still
19475note needs an unreachable ret terminator (zero of the return type, or void).
19476note trap is packed little endian 1885434484; independently checked in Wolfram.
19477code = lenval 4
19478if or lt code 1 gt code 14
19479note d2site 528|ir_stmt: number out of range for its type or place; condition if or lt code 1 gt code 14
19480put d2site 0 528
19481fail 8
19482end
19483tok
19484if not or eq get tk 0 0 eq get tk 0 3
19485note d2site 529|ir_stmt: the line ends where a word or value is needed; condition if not or eq get tk 0 0 eq get tk 0 3
19486put d2site 0 529
19487fail 4
19488end
19489ir_op 12 code 0 0 0
19490z = ulong 65535
19491if ne get ir_ret 0 76
19492z = ir_lit 0 get ir_ret 0
19493end
19494ir_op 15 z 0 0 0
19495put ir_dead 0 1
19496ret 0
19497end
19498if eq c 86
19499note ir_break: BR to the innermost loop's exit, then the path is dead. The if/loop closes skip the
19500note unreachable join exactly as they do after ret or trap.
19501ex = ir_loopexit
19502if eq ex 0
19503note d2site 530|ir_stmt: word or declaration in a place that does not allow it; condition if eq ex 0
19504put d2site 0 530
19505fail 9
19506end
19507ir_op 13 sub ex 1 0 0 0
19508put ir_dead 0 1
19509eol
19510ret 0
19511end
19512if eq c 66
19513ir_end
19514ret 0
19515end
19516if eq c 68
19517n = sub get ir_nf 0 1
19518if or ne get ir_fk n 1 ne get ir_fc n 0
19519note d2site 531|ir_stmt: missing end; condition if or ne get ir_fk n 1 ne get ir_fc n 0
19520put d2site 0 531
19521fail 15
19522end
19523eol
19524put ir_nn 0 get ir_fnn n
19525if eq get ir_dead 0 0
19526j = ir_block
19527ir_op 13 j 0 0 0
19528put ir_dead 0 1
19529put ir_fd n j
19530else
19531put ir_fd n 65535
19532end
19533put ir_fc n 1
19534ir_start get ir_fb n
19535ret 0
19536end
19537if eq c 67
19538ir_val 65534 1
19539if ne get ir_vt 0 1
19540note d2site 532|ir_stmt: type mismatch; condition if ne get ir_vt 0 1
19541put d2site 0 532
19542fail 7
19543end
19544eol
19545th = ir_block
19546el = ir_block
19547ir_op 14 get ir_rr 0 th el 0
19548ir_push 1 th el 0 65535
19549ir_start th
19550ret 0
19551end
19552if eq c 69
19553ir_while
19554ret 0
19555end
19556if eq c 71
19557ir_for
19558ret 0
19559end
19560if eq c 72
19561note ir_doret: ret alone in a void function, ret value otherwise (4 when the value is missing, 5 for a
19562note value or any other word after it); the value is read from just after ret.
19563c0 = get cur 0
19564tok
19565if or eq get tk 0 0 eq get tk 0 3
19566if ne get ir_ret 0 76
19567note d2site 533|ir_stmt: the line ends where a word or value is needed; condition if ne get ir_ret 0 76
19568put d2site 0 533
19569fail 4
19570end
19571ir_op 15 65535 0 0 0
19572else
19573if eq get ir_ret 0 76
19574note d2site 534|ir_stmt: extra words after a complete statement; condition if eq get ir_ret 0 76
19575put d2site 0 534
19576fail 5
19577end
19578put cur 0 c0
19579ir_val 65534 get ir_ret 0
19580if ne get ir_vt 0 get ir_ret 0
19581note d2site 535|ir_stmt: type mismatch; condition if ne get ir_vt 0 get ir_ret 0
19582put d2site 0 535
19583fail 7
19584end
19585eol
19586ir_op 15 get ir_rr 0 0 0 0
19587end
19588put ir_dead 0 1
19589ret 0
19590end
19591if eq c 64
19592note d2site 536|ir_stmt: missing end; condition if eq c 64
19593put d2site 0 536
19594fail 15
19595end
19596if ne c 0
19597if eq c 97
19598note continue keeps its documented IR refusal, error 3 (gate-ir.sh continue_use)
19599note d2site 537|ir_stmt: unknown name or field, or a word this mode does not provide; condition if eq c 97
19600put d2site 0 537
19601fail 3
19602end
19603if or eq c 80 eq c 82
19604note d2site 538|ir_stmt: word or declaration in a place that does not allow it; condition if or eq c 80 eq c 82
19605put d2site 0 538
19606fail 9
19607end
19608if or or or eq c 78 eq c 79 eq c 81 eq c 85
19609note d2site 539|ir_stmt: word or declaration in a place that does not allow it; condition if or or or eq c 78 eq c 79 eq c 81 eq c 85
19610put d2site 0 539
19611fail 9
19612end
19613if eq c 193
19614note d2site 540|ir_stmt: word or declaration in a place that does not allow it; condition if eq c 193
19615put d2site 0 540
19616fail 9
19617end
19618note d2site 541|ir_stmt: syntax: unknown or misplaced word; condition if ne c 0
19619put d2site 0 541
19620fail 16
19621end
19622note a contract clause (requires, ensures, invariant not followed by =) is not an IR v1 statement: refuse it, never
19623note read it as a local (#791). `ensures = v` assigns a local of that name, as the C oracle and native mode accept.
19624if ne cp_kind 0
19625p = get ts 0
19626l = get line 0
19627tok
19628eqs = and eq get tk 0 1 eq ir_kwt 73
19629put cur 0 p
19630put line 0 l
19631tok
19632if not eqs
19633note d2site 542|ir_stmt: contract syntax misplaced or not supported here (IR mode included); condition if not eqs
19634put d2site 0 542
19635fail 30
19636end
19637end
19638ir_assign get tw 0
19639ret 0
19640end
19641
19642note ir_param: parameter np of function f, named by the current word: a new name and an IR v1 type.
19643fn ir_param f ulong to void
19644w = get tw 0
19645s = get ts 0
19646l = get tl 0
19647ir_newloc w s l
19648np = get irf_np f
19649if ge np 6
19650note d2site 543|ir_param: word or declaration in a place that does not allow it; condition if ge np 6
19651put d2site 0 543
19652fail 9
19653end
19654ty = ir_type 0
19655put irf_pt add mul f 6 np uchar ty
19656put irf_np f add np 1
19657r = ir_newreg ty
19658ir_bind w r
19659end
19660
19661note ir_fn: fn name (param type)* to type | void, then the body. The name is checked (16, 13 over 63
19662note bytes, 10 when in use) and entered before the parameters, so a parameter cannot reuse it.
19663fn ir_fn to void
19664tok
19665if ne get tk 0 1
19666note d2site 544|ir_fn: syntax: unknown or misplaced word; condition if ne get tk 0 1
19667put d2site 0 544
19668fail 16
19669end
19670if gt get tl 0 63
19671note d2site 545|ir_fn: name too long (63 bytes; 8 for an abstract, a layout, a layout field, or any name in IR mode); condition if gt get tl 0 63
19672put d2site 0 545
19673fail 13
19674end
19675fcur = get irf_n 0
19676if ge fcur 32
19677note d2site 546|ir_fn: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge fcur 32
19678put d2site 0 546
19679fail 14
19680end
19681put ir_nn 0 0
19682ir_newname get tw 0 get ts 0 get tl 0
19683put irf_nm fcur get tw 0
19684put irf_ns fcur get ts 0
19685put irf_nl fcur get tl 0
19686put irf_np fcur 0
19687put irf_n 0 add fcur 1
19688put ir_ns 0 get ts 0
19689put ir_nl 0 get tl 0
19690put ir_nreg 0 0
19691put ir_nc 0 0
19692put ir_nb 0 0
19693put ir_nord 0 0
19694put ir_no 0 0
19695put ir_nf 0 0
19696put ir_dead 0 0
19697go = true
19698while go
19699tok
19700if or eq get tk 0 0 eq get tk 0 3
19701note d2site 547|ir_fn: the line ends where a word or value is needed; condition if or eq get tk 0 0 eq get tk 0 3
19702put d2site 0 547
19703fail 4
19704end
19705if ne get tk 0 1
19706note d2site 548|ir_fn: syntax: unknown or misplaced word; condition if ne get tk 0 1
19707put d2site 0 548
19708fail 16
19709end
19710if eq ir_kwt 65
19711go = false
19712else
19713ir_param fcur
19714end
19715end
19716put ir_ret 0 ir_type 1
19717eol
19718put irf_ret fcur uchar get ir_ret 0
19719put ir_npar 0 get ir_nreg 0
19720b = ir_block
19721ir_start b
19722ir_push 4 0 0 0 0
19723put ir_have 0 0
19724while eq get ir_have 0 0
19725ignored = ir_stmt
19726end
19727end
19728
19729fn ir_run to void
19730go = true
19731while go
19732tok
19733k = get tk 0
19734if eq k 3
19735go = false
19736else
19737if eq k 0
19738else
19739if ne k 1
19740note d2site 549|ir_run: syntax: unknown or misplaced word; condition if ne k 1
19741put d2site 0 549
19742fail 16
19743end
19744c = kw get tw 0
19745if eq c 64
19746ir_fn
19747ir_emit_record
19748else
19749if eq c 83
19750skipnl
19751else
19752if eq c 152
19753s_const
19754else
19755if or or eq c 85 eq c 78 eq c 79
19756note d2site 550|ir_run: word or declaration in a place that does not allow it; condition if or or eq c 85 eq c 78 eq c 79
19757put d2site 0 550
19758fail 9
19759end
19760note d2site 551|ir_run: syntax: unknown or misplaced word; condition otherwise: if eq c 152
19761put d2site 0 551
19762fail 16
19763end
19764end
19765end
19766end
19767end
19768end
19769note ir_encode: header (magic, version 1, nfuncs) followed by every collected function record.
19770put oc 0 0
19771emitb 79
19772emitb 83
19773emitb 67
19774emitb 49
19775emitb 73
19776emitb 82
19777emitb 0
19778emitb 1
19779ir_w16 get irnf 0
19780i = ulong 0
19781while lt i get irrlen 0
19782emitb get irrec i
19783i = add i 1
19784end
19785if ne get fmtm 0 0
19786fmtout
19787end
19788a_ceilo get oc 0
19789n = a_out 1 1 0 get oc 0
19790exit 0
19791end
19792
19793note ======== executable contract predicates (OM-2, native targets) ========
19794note Token packs below: Wolfram FromDigits[Reverse[ToCharacterCode[word]],256].
19795note Contract words are contextual: OM-1 name meanings and keyword-table bytes do not change.
19796note Explicit native build policy, with syntax and purity checked in both policies.
19797note om2 debug / om2 release and om2 diag debug / om2 diag release; fmt stays canonical.
19798fn cp_mode q ulong to ulong
19799if gt add q 4 get inlen 0
19800ret 0
19801end
19802if ne uchar and shr get a_ar shr q 3 shl and q 7 3 255 111
19803ret 0
19804end
19805if ne uchar and shr get a_ar shr add q 1 3 shl and add q 1 7 3 255 109
19806ret 0
19807end
19808if ne uchar and shr get a_ar shr add q 2 3 shl and add q 2 7 3 255 50
19809ret 0
19810end
19811if ne uchar and shr get a_ar shr add q 3 3 shl and add q 3 7 3 255 32
19812ret 0
19813end
19814p = add q 4
19815m = ulong 1
19816if le add p 5 get inlen 0
19817if and eq a_ib p 100 eq a_ib add p 1 105
19818if and eq a_ib add p 2 97 eq a_ib add p 3 103
19819if eq uchar and shr get a_ar shr add p 4 3 shl and add p 4 7 3 255 32
19820p = add p 5
19821m = ulong 2
19822end
19823end
19824end
19825end
19826if ne lineis p 28555834798400882 7 0
19827put crel 0 1
19828ret m
19829end
19830if ne lineis p 444351014244 5 0
19831ret m
19832end
19833ret 0
19834end
19835
19836fn cp_kind to ulong
19837if and eq get om2 0 0 eq get irmode 0 0
19838ret 0
19839end
19840if ne get tk 0 1
19841ret 0
19842end
19843if and eq get tl 0 8 eq get tw 0 8315178084276987250
19844ret 1
19845end
19846if and eq get tl 0 7 eq get tw 0 32481164592901733
19847ret 2
19848end
19849if and eq get tl 0 9 eq get tw8 0 7953754356895346281
19850if eq a_ib add get ts 0 8 116
19851ret 3
19852end
19853end
19854ret 0
19855end
19856
19857note cp_next reads the next prefix clause, ignoring comments and blanks; a nonclause is unread.
19858fn cp_next to ulong
19859p = get cur 0
19860l = get line 0
19861go = true
19862while go
19863tok
19864if eq get tk 0 1
19865if and eq get tl 0 4 eq get tw 0 1702129518
19866skipnl
19867else
19868go = false
19869end
19870else
19871if ne get tk 0 0
19872go = false
19873end
19874end
19875end
19876k = cp_kind
19877if eq k 0
19878put cur 0 p
19879put line 0 l
19880end
19881ret k
19882end
19883
19884note Recursive purity allowlist, before rdval dispatch. No calls, floats, host or mapped operations.
19885fn cp_token to void
19886if eq get tk 0 2
19887ret
19888end
19889if ne get tk 0 1
19890note d2site 552|cp_token: contract syntax misplaced or not supported here (IR mode included); condition if ne get tk 0 1
19891put d2site 0 552
19892fail 30
19893end
19894if gt get tl 0 63
19895note d2site 553|cp_token: contract syntax misplaced or not supported here (IR mode included); condition if gt get tl 0 63
19896put d2site 0 553
19897fail 30
19898end
19899c = kw get tw 0
19900if eq c 0
19901ret
19902end
19903if le sub c 1 8
19904ret
19905end
19906if le sub c 33 19
19907ret
19908end
19909if or eq c 55 eq c 56
19910ret
19911end
19912if or or eq c 59 eq c 60 eq c 74
19913ret
19914end
19915note d2site 554|cp_token: contract syntax misplaced or not supported here (IR mode included)
19916put d2site 0 554
19917fail 30
19918end
19919
19920fn cp_erase to void
19921put oc 0 get csnap 0
19922put nt 0 get csnap 1
19923put nsite 0 get csnap 2
19924put tgoc 0 get csnap 5
19925put lastb 0 get csnap 6
19926note no island is ever emitted inside an evaluation (island runs only between body lines, never inside an
19927note inline frame); tpend is kept within the trap list all the same
19928if gt get tpend 0 get nt 0
19929put tpend 0 get nt 0
19930end
19931end
19932
19933fn cp_eval code ulong erase ulong to void
19934ln = get line 0
19935rule = ulong 0
19936note Pure evaluation changes no names, calls, inline frames or writes.
19937note Snapshot emission effects, including trap records, diagnostic sites and branch targets.
19938put csnap 0 get oc 0
19939put csnap 1 get nt 0
19940put csnap 2 get nsite 0
19941put csnap 3 get nslot 0
19942put csnap 4 get fzone 0
19943put csnap 5 get tgoc 0
19944put csnap 6 get lastb 0
19945put cpure 0 1
19946put fzone 0 1
19947rdval 0 1 255 0
19948if ne get rt 0 1
19949note d2site 555|cp_eval: type mismatch; condition if ne get rt 0 1
19950put d2site 0 555
19951fail 7
19952end
19953eol
19954nextln = get line 0
19955put line 0 ln
19956if and eq get rk 0 3 ne get rv 0 0
19957rule = ulong 1
19958cp_erase
19959else
19960if or ne erase 0 ne get crel 0 0
19961rule = ulong 2
19962cp_erase
19963else
19964if eq get rk 0 3
19965trapc 14 code
19966else
19967if eq get rk 0 4
19968trapc xor get rv 0 1 code
19969else
19970r = matreg get rk 0 get rv 0 get rt 0
19971trapsite or 3019898880 r code
19972end
19973end
19974end
19975end
19976if and eq get om2m 0 1 eq erase 0
19977cp_rec rule
19978end
19979put line 0 nextln
19980put cpure 0 0
19981put cvalid 0 0
19982put fzone 0 get csnap 4
19983put nslot 0 get csnap 3
19984end
19985
19986note omc-check distinguishes a proof from release policy; initial deferred validation is silent.
19987fn cp_rec rule ulong to void
19988put rc_ccnt 0 add get rc_ccnt 0 1
19989sitew 7162245557575183727 8
19990sitew 540090475 4
19991if eq rule 0
19992sitew 1953523051 4
19993else
19994sitew 110386890240613 6
19995end
19996sitew 67505853393952 6
19997siten add get line 0 get lbase 0
19998sitew 67505820627488 6
19999if eq rule 0
20000sitew 28549272340166002 7
20001end
20002if eq rule 1
20003sitew 8389750308618530659 8
20004sitew 435762132013 5
20005end
20006if eq rule 2
20007sitew 28555834798400882 7
20008end
20009sitew 67501558426400 6
20010if eq get ckind 0 1
20011sitew 8315178084276987250 8
20012end
20013if eq get ckind 0 2
20014sitew 32481164592901733 7
20015end
20016if eq get ckind 0 3
20017sitew 7953754356895346281 8
20018siteb 116
20019end
20020siteb 10
20021end
20022
20023note Function prefix predicates bind only globals and parameters visible on entry.
20024fn cp_entry to void
20025lv = get inl 0
20026put cfhas lv 0
20027if eq get om2 0 0
20028ret
20029end
20030put cfpos lv get cur 0
20031put cfline lv get line 0
20032put cflim lv get nn 0
20033put clim 0 get nn 0
20034k = cp_next
20035n = ulong 0
20036while ne k 0
20037put ckind 0 k
20038if ge n 64
20039note d2site 556|cp_entry: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 64
20040put d2site 0 556
20041fail 14
20042end
20043if eq k 3
20044note d2site 557|cp_entry: contract syntax misplaced or not supported here (IR mode included); condition if eq k 3
20045put d2site 0 557
20046fail 30
20047end
20048put crkind 0 0
20049if eq k 1
20050cp_eval 9 0
20051else
20052put cfhas lv 1
20053ns = get nslot 0
20054put crtype 0 get curret 0
20055if ne get curret 0 12
20056put crkind 0 1
20057put crval 0 alloc
20058end
20059put cvalid 0 1
20060cp_eval 10 1
20061put nslot 0 ns
20062end
20063n = add n 1
20064k = cp_next
20065end
20066end
20067
20068note Return expressions are evaluated once, before postconditions, without overwriting argument X0.
20069fn cp_post kind ulong value ulong ty ulong to void
20070lv = get inl 0
20071if eq get cfhas lv 0
20072ret
20073end
20074p = get cur 0
20075l = get line 0
20076put cur 0 get cfpos lv
20077put line 0 get cfline lv
20078put clim 0 get cflim lv
20079put crkind 0 kind
20080put crval 0 value
20081put crtype 0 ty
20082k = cp_next
20083while ne k 0
20084if eq k 2
20085put ckind 0 2
20086cp_eval 10 0
20087else
20088skipnl
20089end
20090k = cp_next
20091end
20092put cur 0 p
20093put line 0 l
20094end
20095
20096note Loop invariants execute at the head, including zero trips and final false condition.
20097note Continue reaches the checked head (for increments first); break bypasses it.
20098fn cp_head pos ulong ln ulong to void
20099if eq get om2 0 0
20100ret
20101end
20102p = get cur 0
20103l = get line 0
20104put cur 0 pos
20105put line 0 ln
20106put clim 0 get nn 0
20107put crkind 0 0
20108k = cp_next
20109n = ulong 0
20110while eq k 3
20111put ckind 0 3
20112if ge n 64
20113note d2site 558|cp_head: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 64
20114put d2site 0 558
20115fail 14
20116end
20117cp_eval 10 0
20118n = add n 1
20119k = cp_next
20120end
20121put cphn 0 n
20122put cur 0 p
20123put line 0 l
20124end
20125
20126note Head clauses have already been checked and emitted before the condition, never at body entry.
20127fn cp_skip to void
20128if eq get om2 0 0
20129ret
20130end
20131p = get cur 0
20132l = get line 0
20133k = cp_next
20134while eq k 3
20135skipnl
20136p = get cur 0
20137l = get line 0
20138k = cp_next
20139end
20140put cur 0 p
20141put line 0 l
20142end
20143
20144note main: read all of stdin into the arena (a read error is 1, no room is 14), find the mode, then one
20145note statement per line from output byte 180 (om4 START .. STMT)
20146fn main to int
20147note the input becomes region 0 of the arena (a_rdin), then every other region gets its first room
20148d2env
20149put a_nr 0 1
20150a_env
20151a_rdin
20152a_init
20153xlead
20154chk_lead
20155om2lead
20156if eq get chkmode 0 4
20157put objmode 0 1
20158if or eq get om2 0 0 ne get om2m 0 0
20159note d2site 559|main: syntax: unknown or misplaced word; condition if or eq get om2 0 0 ne get om2m 0 0
20160put d2site 0 559
20161fail 16
20162end
20163if or ne get xtarget 0 0 ne get xefa 0 0
20164note d2site 560|main: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if or ne get xtarget 0 0 ne get xefa 0 0
20165put d2site 0 560
20166fail 25
20167end
20168end
20169if eq get om2m 0 2
20170fmtprep
20171end
20172if ne ir_lead 0
20173put irmode 0 1
20174ir_run
20175end
20176prescan
20177if ne get objmode 0 0
20178put progmode 0 0
20179end
20180namescan
20181if eq get nexp 0 0
20182put oc 0 180
20183else
20184put oc 0 add 176 shl get nexp 0 2
20185end
20186if ne get xefa 0 0
20187if eq get progmode 0 0
20188note d2site 561|main: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if eq get progmode 0 0
20189put d2site 0 561
20190fail 25
20191end
20192note PE headers and the 8-byte relocation block fill 520 bytes; the shared firmware return is first.
20193put oc 0 520
20194aefx
20195end
20196if ne get xtarget 0 0
20197put oc 0 512
20198if eq get xtarget 0 2
20199if eq get progmode 0 0
20200note d2site 562|main: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if eq get progmode 0 0
20201put d2site 0 562
20202fail 25
20203end
20204note The PE headers fill 520 bytes; code is mapped from file offset 512 at RVA 4096 (xefx 2).
20205put oc 0 520
20206end
20207if eq get progmode 0 0
20208m = get nexp 0
20209if eq m 0
20210m = ulong 1
20211end
20212put oc 0 add 512 mul m 6
20213end
20214end
20215put line 0 1
20216done = false
20217while not done
20218m = ulong 0
20219while and not done lt m 999999
20220if ne stmt 0
20221done = true
20222end
20223m = add m 1
20224end
20225end
20226ret 0
20227end
20228
20229note Linux x86-64 host ABI: Linux v6.17 arch/x86/entry/syscalls/syscall_64.tbl.
20230note RBX anchors the saved slot snapshot; preserve R13 (initial argument stack) in its spare tail.
20231note R12 (nonlocal native return), R14 (runtime dispatch), R15 (stack floor) are never scratch.
20232fn xhbegin to void
20233save
20234xmem 137 13 4 144
20235xrr 137 3 4
20236end
20237fn xha x ulong i ulong r ulong to void
20238q = add add x 8 mul i 2
20239k = get a_ar add get a_rb 77 q
20240v = get a_ar add get a_rb 77 add q 1
20241if or eq k 3 eq k 7
20242ximm r v
20243else
20244if eq k 6
20245xaddr r v
20246else
20247xmem 139 r 3 mul v 8
20248end
20249end
20250end
20251fn xhs r ulong s ulong to void
20252xmem 139 r 3 mul s 8
20253end
20254fn xhb r ulong e ulong off ulong to void
20255if ge uchar get a_ar add get a_rb 7 sub e 1 4
20256xaddr r get a_ar add get a_rb 8 sub e 1
20257else
20258xhs r ulong uchar get a_ar add get a_rb 4 sub e 1
20259end
20260xhs 0 off
20261xrr 1 r 0
20262end
20263fn xhcall n ulong to void
20264ximm 0 n
20265emitb 15
20266emitb 5
20267end
20268fn xhdone dst ulong x ulong bytes ulong to void
20269xsp 0 bytes
20270xmem 139 13 3 144
20271hreturn dst x
20272end
20273fn xhcmp r ulong v ulong to void
20274ximm 11 v
20275xrr 57 r 11
20276end
20277fn xhadd r ulong v ulong to void
20278ximm 11 v
20279xrr 1 r 11
20280end
20281fn xhsub r ulong v ulong to void
20282ximm 11 v
20283xrr 41 r 11
20284end
20285fn xhraw r ulong b ulong off ulong size ulong to void
20286emitb uchar add add 64 shl shr r 3 2 shr b 3
20287if lt size 4
20288emitb 15
20289if eq size 1
20290emitb 182
20291else
20292emitb 183
20293end
20294else
20295emitb 139
20296end
20297emitb uchar add add 128 shl and r 7 3 and b 7
20298if eq and b 7 4
20299emitb 36
20300end
20301xword off
20302end
20303fn xhput r ulong b ulong off ulong size ulong to void
20304if eq size 2
20305emitb 102
20306end
20307emitb uchar add add 64 shl shr r 3 2 shr b 3
20308if eq size 1
20309emitb 136
20310else
20311emitb 137
20312end
20313emitb uchar add add 128 shl and r 7 3 and b 7
20314if eq and b 7 4
20315emitb 36
20316end
20317xword off
20318end
20319fn xhpath x ulong to void
20320xhb 6 a_g 77 add x 20 a_g 77 add x 21
20321xhs 2 get a_ar add get a_rb 77 add x 22
20322xhcmp 2 4095
20323xtrap 8 3
20324xsp 1 4096
20325xrr 137 7 4
20326loop = get oc 0
20327xrr 133 2 2
20328done = xbranch 0
20329xhraw 0 6 0 1
20330xrr 133 0 0
20331xtrap 0 3
20332xhput 0 7 0 1
20333xhadd 6 1
20334xhadd 7 1
20335xhsub 2 1
20336p = xbranch 14
20337xpatch p loop
20338xpatch done get oc 0
20339ximm 0 0
20340xhput 0 7 0 1
20341end
20342fn xhscalar c ulong dst ulong x ulong to void
20343np = hargc c
20344for i ulong np
20345ty = ulong 8
20346if or and eq c 103 eq i 1 and eq c 139 eq i 1
20347ty = ulong 9
20348end
20349harg x i ty
20350end
20351xhbegin
20352for i ulong np
20353r = ulong 7
20354if eq i 1
20355r = ulong 6
20356end
20357if eq i 2
20358r = ulong 2
20359end
20360xha x i r
20361end
20362nr = ulong 292
20363if eq c 100
20364nr = ulong 3
20365end
20366if eq c 101
20367nr = ulong 74
20368end
20369if eq c 102
20370nr = ulong 91
20371end
20372if eq c 103
20373nr = ulong 8
20374end
20375if eq c 104
20376nr = ulong 41
20377end
20378if eq c 105
20379nr = ulong 50
20380end
20381if eq c 106
20382nr = ulong 288
20383xha x 1 10
20384ximm 6 0
20385ximm 2 0
20386end
20387if eq c 107
20388nr = ulong 57
20389end
20390if eq c 127
20391nr = ulong 62
20392end
20393if eq c 129
20394nr = ulong 39
20395end
20396if eq c 139
20397nr = ulong 77
20398end
20399if eq c 145
20400nr = ulong 102
20401end
20402if eq c 146
20403nr = ulong 107
20404end
20405if eq c 147
20406nr = ulong 104
20407end
20408if eq c 148
20409nr = ulong 108
20410end
20411if eq c 153
20412nr = ulong 81
20413end
20414if eq c 154
20415nr = ulong 110
20416end
20417if eq c 155
20418nr = ulong 95
20419end
20420if eq c 156
20421nr = ulong 75
20422end
20423if eq c 158
20424nr = ulong 112
20425end
20426if eq c 159
20427nr = ulong 121
20428end
20429if eq c 160
20430nr = ulong 109
20431end
20432if eq c 163
20433nr = ulong 124
20434end
20435if eq c 164
20436nr = ulong 306
20437end
20438if eq c 165
20439nr = ulong 48
20440end
20441if eq c 197
20442nr = ulong 73
20443end
20444if eq c 239
20445nr = ulong 141
20446end
20447if eq c 240
20448nr = ulong 140
20449end
20450xhcall nr
20451xhdone dst x 0
20452end
20453note xoflags: RDX holds fopen's flags in the language's values, which are Linux asm-generic (AArch64). x86-64
20454note numbers four of them differently (asm/fcntl.h): O_DIRECTORY 040000 -> 0200000, O_NOFOLLOW 0100000 ->
20455note 0400000, O_DIRECT 0200000 -> 040000, O_LARGEFILE 0400000 -> 0100000; every other O_ flag is the same.
20456note So bits 14..15 move up 2 and bits 16..17 move down 2: MOV RAX, RDX (89 /r); AND RAX, 0xC000 (REX.W 25
20457note id); SHL RAX, 2 (C1 /4 ib); MOV RCX, RDX; AND RCX, 0x30000 (REX.W 81 /4 id); SHR RCX, 2 (C1 /5 ib); OR RAX,
20458note RCX (09 /r); AND RDX, ~0x3C000 (REX.W 81 /4 id, sign-extended); OR RDX, RAX. RAX and RCX are scratch here:
20459note xhcall sets RAX, and SYSCALL clobbers RCX.
20460fn xoflags to void
20461xrr 137 0 2
20462emitb 72
20463emitb 37
20464xword 49152
20465xb 72 193 224
20466emitb 2
20467xrr 137 1 2
20468xb 72 129 225
20469xword 196608
20470xb 72 193 233
20471emitb 2
20472xrr 9 0 1
20473xb 72 129 226
20474xword 4294721535
20475xrr 9 2 0
20476end
20477
20478fn xhpaths c ulong dst ulong x ulong to void
20479e = harray x 0
20480if or eq c 110 eq c 151
20481harg x 2 8
20482harg x 3 8
20483end
20484if or or or eq c 112 eq c 143 eq c 144 eq c 157
20485harg x 2 8
20486end
20487if eq c 150
20488harg x 2 9
20489end
20490xhbegin
20491xhpath x
20492ximm 7 18446744073709551516
20493xrr 137 6 4
20494nr = ulong 257
20495if eq c 110
20496xha x 2 2
20497xoflags
20498xha x 3 10
20499end
20500if or eq c 111 eq c 126
20501nr = ulong 263
20502ximm 2 0
20503if eq c 126
20504ximm 2 512
20505end
20506end
20507if eq c 112
20508nr = ulong 258
20509xha x 2 2
20510end
20511if eq c 138
20512nr = ulong 80
20513xrr 137 7 6
20514end
20515if or eq c 143 eq c 144
20516nr = ulong 268
20517if eq c 144
20518nr = ulong 269
20519end
20520xha x 2 2
20521ximm 10 0
20522end
20523if eq c 150
20524nr = ulong 76
20525xrr 137 7 6
20526xha x 2 6
20527end
20528if eq c 151
20529nr = ulong 260
20530xha x 2 2
20531xha x 3 10
20532ximm 8 0
20533end
20534if eq c 157
20535nr = ulong 319
20536xrr 137 7 6
20537xha x 2 6
20538end
20539xhcall nr
20540xhdone dst x 4096
20541end
20542note Native x86 struct stat is private; output remains Omega's 128-byte asm-generic ABI.
20543fn xhstatcv to void
20544xrr 133 0 0
20545bad = xbranch 11
20546ximm 2 0
20547for j ulong 16
20548xmem 137 2 13 mul j 8
20549end
20550for j ulong 2
20551xmem 139 2 4 mul j 8
20552xmem 137 2 13 mul j 8
20553end
20554xhraw 2 4 24 4
20555xhput 2 13 16 4
20556xhraw 2 4 16 4
20557xhput 2 13 20 4
20558xmem 139 2 4 28
20559xmem 137 2 13 24
20560xmem 139 2 4 40
20561xmem 137 2 13 32
20562xmem 139 2 4 48
20563xmem 137 2 13 48
20564xhraw 2 4 56 4
20565xhput 2 13 56 4
20566for j ulong 7
20567xmem 139 2 4 add 64 mul j 8
20568xmem 137 2 13 add 64 mul j 8
20569end
20570ximm 0 0
20571xpatch bad get oc 0
20572end
20573fn xhbuffer c ulong dst ulong x ulong to void
20574harg x 4 8
20575wr = ulong 0
20576if or or or or or eq c 113 eq c 116 eq c 117 eq c 118 eq c 131 eq c 161
20577wr = ulong 1
20578end
20579if eq c 224
20580wr = ulong 1
20581end
20582e = harray x wr
20583if or or eq c 116 eq c 118 eq c 119
20584harg x 2 8
20585end
20586if or eq c 161 eq c 162
20587harg x 3 9
20588end
20589xhbegin
20590xha x 4 7
20591xhb 6 e get a_ar add get a_rb 77 add x 21
20592xhs 2 get a_ar add get a_rb 77 add x 22
20593nr = ulong 217
20594if or eq c 114 eq c 115
20595nr = ulong 42
20596if eq c 115
20597nr = ulong 49
20598end
20599end
20600if eq c 116
20601xhcmp 2 4
20602xtrap 3 3
20603nr = ulong 61
20604xha x 2 2
20605ximm 10 0
20606end
20607if eq c 117
20608xhcmp 2 128
20609xtrap 3 3
20610xrr 137 13 6
20611xsp 1 144
20612xrr 137 6 4
20613xhcall 5
20614xhstatcv
20615xhdone dst x 144
20616ret
20617end
20618if or eq c 118 eq c 119
20619nr = ulong 45
20620xha x 2 10
20621ximm 8 0
20622ximm 9 0
20623if eq c 119
20624nr = ulong 44
20625ximm 0 16384
20626xrr 9 10 0
20627end
20628end
20629if or eq c 131 eq c 224
20630note peername shares the private 32-bit socklen; x86-64 getsockname 51, getpeername 52.
20631xsp 1 16
20632xhput 2 4 0 4
20633xrr 137 2 4
20634if eq c 224
20635xhcall 52
20636else
20637xhcall 51
20638end
20639xrr 133 0 0
20640bad = xbranch 11
20641xhraw 0 4 0 4
20642xpatch bad get oc 0
20643xhdone dst x 16
20644ret
20645end
20646if or eq c 161 eq c 162
20647nr = ulong 17
20648if eq c 162
20649nr = ulong 18
20650end
20651xha x 3 10
20652end
20653xhcall nr
20654xhdone dst x 0
20655end
20656fn xhstats c ulong dst ulong x ulong to void
20657e = harray x 0
20658put a_ar add get a_rb 77 add x 23 e
20659a_p 77 add x 24 a_g 77 add x 21
20660a_p 77 add x 25 a_g 77 add x 22
20661e = harray x 1
20662put a_ar add get a_rb 77 add x 26 e
20663a_p 77 add x 27 a_g 77 add x 21
20664a_p 77 add x 28 a_g 77 add x 22
20665a_p 77 add x 20 a_g 77 add x 23
20666a_p 77 add x 21 a_g 77 add x 24
20667a_p 77 add x 22 a_g 77 add x 25
20668xhbegin
20669xhs 2 get a_ar add get a_rb 77 add x 22
20670xrr 133 2 2
20671xtrap 0 3
20672xhpath x
20673xhb 13 e get a_ar add get a_rb 77 add x 27
20674xhs 2 get a_ar add get a_rb 77 add x 28
20675xhcmp 2 128
20676xtrap 3 3
20677ximm 7 18446744073709551516
20678xrr 137 6 4
20679xsp 1 144
20680xrr 137 2 4
20681ximm 10 0
20682if eq c 149
20683ximm 10 256
20684end
20685xhcall 262
20686xhstatcv
20687xhdone dst x 4240
20688end
20689fn xhtime c ulong dst ulong x ulong to void
20690if eq c 120
20691harg x 0 9
20692end
20693xhbegin
20694xsp 1 16
20695if eq c 120
20696xha x 0 0
20697xrr 133 0 0
20698xtrap 11 3
20699ximm 1 1000000000
20700ximm 2 0
20701xb 72 247 241
20702xmem 137 0 4 0
20703xmem 137 2 4 8
20704xrr 137 7 4
20705ximm 6 0
20706xhcall 35
20707else
20708ximm 7 1
20709if eq c 130
20710ximm 7 0
20711end
20712xrr 137 6 4
20713xhcall 228
20714xrr 133 0 0
20715bad = xbranch 11
20716xmem 139 2 4 0
20717xhcmp 2 9223372036
20718xtrap 8 1
20719ximm 0 1000000000
20720xb 72 15 175
20721emitb 194
20722xmem 139 2 4 8
20723xrr 1 0 2
20724xtrap 6 1
20725xpatch bad get oc 0
20726end
20727xhdone dst x 16
20728end
20729
20730fn xrot ty ulong ra ulong b ulong imm ulong rd ulong to void
20731xload 0 ra
20732if ne imm 0
20733ximm 1 b
20734else
20735xload 1 b
20736end
20737if eq ty 3
20738emitb 102
20739end
20740if eq ty 5
20741emitb 72
20742end
20743if eq ty 2
20744emitb 210
20745else
20746emitb 211
20747end
20748emitb 200
20749xstore 0 rd
20750canon rd ty
20751end
20752
20753fn xhts off ulong to void
20754xrr 133 2 2
20755forever = xbranch 11
20756xrr 137 0 2
20757ximm 1 1000000000
20758ximm 2 0
20759xb 72 247 241
20760xmem 137 0 4 off
20761xmem 137 2 4 add off 8
20762xmem 141 2 4 off
20763jump = xbranch 14
20764xpatch forever get oc 0
20765ximm 2 0
20766xpatch jump get oc 0
20767end
20768fn xhpoll c ulong dst ulong x ulong to void
20769if eq c 123
20770harg x 0 8
20771harg x 1 8
20772harg x 2 9
20773xhbegin
20774xha x 0 7
20775xha x 1 6
20776xha x 2 2
20777xrr 133 6 6
20778xtrap 11 3
20779xhcmp 6 65535
20780xtrap 8 3
20781xsp 1 32
20782ximm 0 0
20783xmem 137 0 4 0
20784xhput 7 4 0 4
20785xhput 6 4 4 2
20786xhts 16
20787xrr 137 7 4
20788ximm 6 1
20789else
20790e = harray x 1
20791harg x 2 9
20792xhbegin
20793xhb 7 e get a_ar add get a_rb 77 add x 21
20794xhs 6 get a_ar add get a_rb 77 add x 22
20795xhcmp 6 8192
20796xtrap 8 3
20797xrr 137 0 6
20798ximm 1 7
20799xrr 33 0 1
20800xrr 133 0 0
20801xtrap 1 3
20802xb 72 193 238
20803emitb 3
20804xha x 2 2
20805xsp 1 32
20806xhts 16
20807end
20808ximm 10 0
20809ximm 8 8
20810xhcall 271
20811if eq c 123
20812xrr 133 0 0
20813bad = xbranch 13
20814xhraw 0 4 6 2
20815xpatch bad get oc 0
20816end
20817xhdone dst x 32
20818end
20819fn xhargs c ulong dst ulong x ulong to void
20820put hostargs 0 1
20821if or eq c 121 eq c 136
20822xhbegin
20823xmem 139 0 13 0
20824if eq c 136
20825xmem 141 6 13 16
20826xb 72 193 224
20827emitb 3
20828xrr 1 6 0
20829ximm 0 0
20830loop = get oc 0
20831xmem 139 2 6 0
20832xrr 133 2 2
20833done = xbranch 0
20834xhadd 6 8
20835xhadd 0 1
20836p = xbranch 14
20837xpatch p loop
20838xpatch done get oc 0
20839end
20840xhdone dst x 0
20841ret
20842end
20843harg x 4 5
20844e = harray x 1
20845xhbegin
20846xha x 4 2
20847xmem 139 1 13 0
20848xmem 141 6 13 8
20849if eq c 137
20850xhadd 1 1
20851xb 72 193 225
20852emitb 3
20853xrr 1 6 1
20854loop = get oc 0
20855xmem 139 0 6 0
20856xrr 133 0 0
20857xtrap 0 3
20858xrr 133 2 2
20859done = xbranch 0
20860xhsub 2 1
20861xhadd 6 8
20862p = xbranch 14
20863xpatch p loop
20864xpatch done get oc 0
20865else
20866xrr 57 2 1
20867xtrap 2 3
20868xb 72 193 226
20869emitb 3
20870xrr 1 6 2
20871end
20872xmem 139 6 6 0
20873xrr 137 13 6
20874ximm 2 0
20875scan = get oc 0
20876xhraw 0 6 0 1
20877xrr 133 0 0
20878found = xbranch 0
20879xhadd 6 1
20880xhadd 2 1
20881xhcmp 2 1048576
20882xtrap 2 3
20883p = xbranch 14
20884xpatch p scan
20885xpatch found get oc 0
20886xhs 1 get a_ar add get a_rb 77 add x 22
20887xrr 57 2 1
20888small = xbranch 8
20889xhb 7 e get a_ar add get a_rb 77 add x 21
20890xrr 137 6 13
20891xrr 137 1 2
20892emitb 243
20893emitb 164
20894xrr 137 0 2
20895tail = xbranch 14
20896xpatch small get oc 0
20897ximm 0 18446744073709551511
20898xpatch tail get oc 0
20899xhdone dst x 0
20900end
20901fn xhsimple c ulong dst ulong x ulong to void
20902e = harray x 1
20903if or eq c 128 eq c 135
20904harg x 2 8
20905end
20906xhbegin
20907xhb 7 e get a_ar add get a_rb 77 add x 21
20908xhs 6 get a_ar add get a_rb 77 add x 22
20909nr = ulong 79
20910if eq c 128
20911xhcmp 6 8
20912xtrap 3 3
20913xha x 2 6
20914nr = ulong 293
20915end
20916if eq c 135
20917xha x 2 2
20918nr = ulong 318
20919end
20920xhcall nr
20921xhdone dst x 0
20922end
20923fn xhreadln dst ulong x ulong to void
20924e = harray x 0
20925put a_ar add get a_rb 77 add x 23 e
20926a_p 77 add x 24 a_g 77 add x 21
20927a_p 77 add x 25 a_g 77 add x 22
20928e = harray x 1
20929put a_ar add get a_rb 77 add x 26 e
20930a_p 77 add x 27 a_g 77 add x 21
20931a_p 77 add x 28 a_g 77 add x 22
20932a_p 77 add x 20 a_g 77 add x 23
20933a_p 77 add x 21 a_g 77 add x 24
20934a_p 77 add x 22 a_g 77 add x 25
20935xhbegin
20936xhs 2 get a_ar add get a_rb 77 add x 22
20937xrr 133 2 2
20938xtrap 0 3
20939xhpath x
20940xhb 2 e get a_ar add get a_rb 77 add x 27
20941xhs 10 get a_ar add get a_rb 77 add x 28
20942ximm 7 18446744073709551516
20943xrr 137 6 4
20944xhcall 267
20945xhdone dst x 4096
20946end
20947note Scheduler host words 236..238 on x86linux. Linux syscall_64.tbl: affinity 203/204, getcpu 309.
20948fn xhsched c ulong dst ulong x ulong to void
20949if eq c 238
20950xhbegin
20951xsp 1 16
20952xrr 137 7 4
20953ximm 6 0
20954ximm 2 0
20955xhcall 309
20956xrr 133 0 0
20957bad = xbranch 11
20958xhraw 0 4 0 4
20959xpatch bad get oc 0
20960xhdone dst x 16
20961ret
20962end
20963harg x 2 8
20964w = ulong 0
20965if eq c 237
20966w = ulong 1
20967end
20968e = harray x w
20969xhbegin
20970xha x 2 7
20971xhb 2 e get a_ar add get a_rb 77 add x 21
20972xhs 6 get a_ar add get a_rb 77 add x 22
20973xhcall add 203 w
20974xhdone dst x 0
20975end
20976note prlimit (235) on x86-64: prlimit64 302, RDI pid, RSI res, RDX new, R10 old; n 16 reads (RDX 0, R10
20977note &A[off]), n 32 sets (RDX &A[off], R10 &A[off+16]), other n -22 without a kernel call.
20978fn xhprlim dst ulong x ulong to void
20979harg x 2 8
20980harg x 3 8
20981e = harray x 1
20982xhbegin
20983xha x 2 7
20984xha x 3 6
20985xhb 10 e get a_ar add get a_rb 77 add x 21
20986xhs 8 get a_ar add get a_rb 77 add x 22
20987ximm 2 0
20988xhcmp 8 16
20989rd = xbranch 0
20990xhcmp 8 32
20991setp = xbranch 0
20992ximm 0 sub ulong 0 22
20993bad = xbranch 14
20994xpatch setp get oc 0
20995xrr 137 2 10
20996xhadd 10 16
20997xpatch rd get oc 0
20998xhcall 302
20999xpatch bad get oc 0
21000xhdone dst x 0
21001end
21002fn xhsock c ulong dst ulong x ulong to void
21003ok = new ulong 6 0
21004if eq c 134
21005harg x 2 8
21006harg x 3 8
21007harg x 4 8
21008e = harray x 0
21009xhbegin
21010xha x 2 7
21011xha x 3 6
21012xha x 4 2
21013xhb 10 e get a_ar add get a_rb 77 add x 21
21014xhs 8 get a_ar add get a_rb 77 add x 22
21015xhcmp 6 1
21016tcp = xbranch 1
21017for j ulong 5
21018v = add j 5
21019if eq j 0
21020v = ulong 2
21021end
21022if eq j 1
21023v = ulong 15
21024end
21025xhcmp 2 v
21026put ok j xbranch 0
21027end
21028badso = xbranch 14
21029xpatch tcp get oc 0
21030xhcmp 6 6
21031badtcp = xbranch 1
21032xhcmp 2 1
21033put ok 5 xbranch 0
21034xpatch badso get oc 0
21035xpatch badtcp get oc 0
21036ximm 0 sub ulong 0 92
21037done = xbranch 14
21038for j ulong 6
21039xpatch get ok j get oc 0
21040end
21041xhcmp 8 4
21042sizeok = xbranch 0
21043ximm 0 sub ulong 0 22
21044badsize = xbranch 14
21045xpatch sizeok get oc 0
21046xhcall 54
21047xpatch done get oc 0
21048xpatch badsize get oc 0
21049xhdone dst x 0
21050ret
21051end
21052harg x 4 8
21053if eq c 220
21054e = harray x 1
21055xhbegin
21056xha x 4 7
21057xhb 10 e get a_ar add get a_rb 77 add x 21
21058xhs 8 get a_ar add get a_rb 77 add x 22
21059xhcmp 8 12
21060xtrap 3 3
21061ximm 6 1
21062ximm 2 17
21063xsp 1 16
21064ximm 8 12
21065xhput 8 4 0 4
21066xrr 137 8 4
21067xhcall 55
21068xhdone dst x 16
21069ret
21070end
21071e = harray x 0
21072harg x 2 8
21073xhbegin
21074xha x 4 7
21075xha x 2 2
21076ximm 0 16384
21077xrr 9 2 0
21078xhb 6 e get a_ar add get a_rb 77 add x 21
21079xhs 8 get a_ar add get a_rb 77 add x 22
21080xsp 1 80
21081ximm 0 0
21082for j ulong 10
21083xmem 137 0 4 mul j 8
21084end
21085xmem 137 6 4 64
21086xmem 137 8 4 72
21087xmem 141 6 4 64
21088xmem 137 6 4 16
21089ximm 6 1
21090xmem 137 6 4 24
21091xrr 137 6 4
21092xhcall 46
21093xhdone dst x 80
21094end
21095note execenv 233 on x86-64: as on AArch64, a second pass decodes the environment packet (every record
21096note nonempty) into env strings at RSP+81920 and env pointers at RSP+86016; both checks precede close_range.
21097note Exec argv packets (execprog, execenv) allow 65536 bytes and 1024 records, pointers at RSP+65536;
21098note renames, link, symlnk and the environment packet keep 4096 bytes and 64 records.
21099fn xhpack c ulong dst ulong x ulong to void
21100e = harray x 0
21101if eq c 125
21102harg x 2 8
21103end
21104if eq c 233
21105put a_ar add get a_rb 77 add x 23 e
21106a_p 77 add x 24 a_g 77 add x 21
21107a_p 77 add x 25 a_g 77 add x 22
21108e = harray x 0
21109put a_ar add get a_rb 77 add x 26 e
21110a_p 77 add x 27 a_g 77 add x 21
21111a_p 77 add x 28 a_g 77 add x 22
21112a_p 77 add x 20 a_g 77 add x 23
21113a_p 77 add x 21 a_g 77 add x 24
21114a_p 77 add x 22 a_g 77 add x 25
21115e = get a_ar add get a_rb 77 add x 23
21116end
21117xhbegin
21118note stack: 8192 bytes for renames, link and symlnk; 81920 for execprog; 90112 for execenv (two passes).
21119stack = ulong 8192
21120if ne hexw c 0
21121stack = ulong 81920
21122end
21123if eq c 233
21124stack = ulong 90112
21125end
21126pass = ulong 0
21127while lt pass hnpass c
21128if eq pass 0
21129xhb 6 e get a_ar add get a_rb 77 add x 21
21130xhs 2 get a_ar add get a_rb 77 add x 22
21131else
21132note The slot snapshot is RBX-relative, so the environment slice is read after the RSP move.
21133xhb 6 a_g 77 add x 26 a_g 77 add x 27
21134xhs 2 get a_ar add get a_rb 77 add x 28
21135end
21136if eq hplim c pass 1024
21137xhcmp 2 65536
21138else
21139xhcmp 2 4096
21140end
21141xtrap 8 3
21142xhcmp 2 2
21143xtrap 3 3
21144xhraw 8 6 0 2
21145xhadd 6 2
21146xhsub 2 2
21147xrr 133 8 8
21148xtrap 0 3
21149xhcmp 8 hplim c pass
21150xtrap 8 3
21151if or or eq c 125 eq c 141 eq c 142
21152xhcmp 8 2
21153xtrap 1 3
21154end
21155if eq pass 0
21156xsp 1 stack
21157xrr 137 10 4
21158if ne hexw c 0
21159xmem 141 13 4 65536
21160else
21161xmem 141 13 4 4096
21162end
21163else
21164xmem 141 10 4 81920
21165xmem 141 13 4 86016
21166end
21167ximm 9 0
21168outer = get oc 0
21169xrr 57 9 8
21170done = xbranch 2
21171xhcmp 2 2
21172xtrap 3 3
21173xhraw 1 6 0 2
21174xhadd 6 2
21175xhsub 2 2
21176xrr 57 1 2
21177xtrap 8 3
21178if and eq pass 0 or eq c 124 eq c 233
21179xrr 133 9 9
21180notfirst = xbranch 1
21181xrr 133 1 1
21182xtrap 0 3
21183xpatch notfirst get oc 0
21184else
21185xrr 133 1 1
21186xtrap 0 3
21187end
21188xmem 137 10 13 0
21189xhadd 13 8
21190xrr 41 2 1
21191inner = get oc 0
21192xrr 133 1 1
21193endstr = xbranch 0
21194xhraw 0 6 0 1
21195xrr 133 0 0
21196xtrap 0 3
21197xhput 0 10 0 1
21198xhadd 6 1
21199xhadd 10 1
21200xhsub 1 1
21201p = xbranch 14
21202xpatch p inner
21203xpatch endstr get oc 0
21204ximm 0 0
21205xhput 0 10 0 1
21206xhadd 10 1
21207xhadd 9 1
21208p = xbranch 14
21209xpatch p outer
21210xpatch done get oc 0
21211xrr 133 2 2
21212xtrap 1 3
21213ximm 0 0
21214xmem 137 0 13 0
21215pass = add pass 1
21216end
21217if or eq c 124 eq c 233
21218note As on AArch64: close_range(3, ~0U, CLOSE_RANGE_UNSHARE) first; a nonzero result skips execve
21219note and returns that kernel error. RDI/RSI/RDX are reloaded after the call; R13 holds the argv end.
21220ximm 7 3
21221ximm 6 4294967295
21222ximm 2 2
21223xhcall 436
21224xrr 133 0 0
21225p = xbranch 1
21226xmem 139 7 4 65536
21227xmem 141 6 4 65536
21228if eq c 233
21229xmem 141 2 4 86016
21230else
21231xrr 137 2 13
21232end
21233xhcall 59
21234xpatch p get oc 0
21235else
21236xmem 139 6 4 4096
21237xmem 139 10 4 4104
21238ximm 7 18446744073709551516
21239ximm 2 18446744073709551516
21240ximm 8 0
21241if eq c 125
21242xha x 2 8
21243xhcall 316
21244else
21245if eq c 141
21246xhcall 265
21247else
21248xrr 137 7 6
21249ximm 6 18446744073709551516
21250xrr 137 2 10
21251xhcall 266
21252end
21253end
21254end
21255xhdone dst x stack
21256end
21257note Hosted handles use the entry31 context header and 13 slot bits; programs retain raw128 slots.
21258fn xhmcheck to void
21259xrr 137 13 10
21260if eq get progmode 0 0
21261ximm 0 8191
21262else
21263ximm 0 255
21264end
21265xrr 33 13 0
21266xhcmp 13 1
21267xtrap 3 3
21268if eq get progmode 0 0
21269xmem 139 0 14 248
21270xmem 139 0 0 0
21271xhcmp 0 1
21272xtrap 3 3
21273xhcmp 0 4098
21274xtrap 8 3
21275xrr 57 13 0
21276xtrap 8 3
21277else
21278xhcmp 13 128
21279xtrap 8 3
21280end
21281xhsub 13 1
21282xb 73 193 229
21283emitb 5
21284if eq get progmode 0 0
21285xmem 139 0 14 248
21286xhadd 0 32
21287else
21288xaddr 0 get maptab 0
21289end
21290xrr 1 13 0
21291xmem 139 9 13 16
21292xrr 133 9 9
21293xtrap 0 3
21294xb 73 193 234
21295if eq get progmode 0 0
21296emitb 13
21297else
21298emitb 8
21299end
21300xrr 57 10 9
21301xtrap 1 3
21302xmem 139 8 13 0
21303xrr 133 8 8
21304xtrap 0 3
21305xmem 139 9 13 8
21306end
21307fn xhmnew c ulong dst ulong x ulong to void
21308acc = ulong 0
21309mode = ulong 1048610
21310if eq c 167
21311harg x 0 8
21312harg x 1 5
21313harg x 2 5
21314harg x 3 8
21315harg x 4 8
21316if or ne a_g 77 add x 14 3 ne a_g 77 add x 16 3
21317note d2site 563|xhmnew: word or declaration in a place that does not allow it; condition if or ne a_g 77 add x 14 3 ne a_g 77 add x 16 3
21318put d2site 0 563
21319fail 9
21320end
21321acc = get a_ar add get a_rb 77 add x 15
21322mode = get a_ar add get a_rb 77 add x 17
21323if and ne acc 1 ne acc 3
21324note d2site 564|xhmnew: word or declaration in a place that does not allow it; condition if and ne acc 1 ne acc 3
21325put d2site 0 564
21326fail 9
21327end
21328if and and and ne mode 1 ne mode 2 ne mode 33 ne mode 34
21329note d2site 565|xhmnew: word or declaration in a place that does not allow it; condition if and and and ne mode 1 ne mode 2 ne mode 33 ne mode 34
21330put d2site 0 565
21331fail 9
21332end
21333end
21334if eq c 176
21335harg x 1 5
21336harg x 2 5
21337end
21338if eq c 242
21339harg x 0 8
21340harg x 1 5
21341harg x 2 5
21342acc = ulong 3
21343mode = ulong 1
21344end
21345if eq c 243
21346harg x 2 5
21347mode = ulong 34
21348end
21349xhbegin
21350if eq c 242
21351xha x 0 7
21352kmapfd
21353end
21354xha x 2 6
21355xrr 133 6 6
21356xtrap 0 3
21357if lt c 242
21358xhcmp 6 68719476736
21359xtrap 8 3
21360end
21361if or eq c 167 eq c 242
21362xha x 0 8
21363xha x 1 9
21364if ge mode 32
21365xhcmp 8 18446744073709551615
21366xtrap 1 3
21367xrr 133 9 9
21368xtrap 1 3
21369end
21370end
21371if eq c 243
21372ximm 8 18446744073709551615
21373ximm 9 0
21374end
21375if eq c 176
21376xha x 1 7
21377xhcmp 7 65536
21378xtrap 3 3
21379ximm 0 1099511627776
21380xrr 41 0 6
21381xrr 57 7 0
21382xtrap 8 3
21383ximm 0 4095
21384xrr 137 1 7
21385xrr 33 1 0
21386xrr 133 1 1
21387xtrap 1 3
21388xrr 137 1 6
21389xrr 33 1 0
21390xrr 133 1 1
21391xtrap 1 3
21392ximm 8 18446744073709551615
21393ximm 9 0
21394end
21395if eq get progmode 0 0
21396xmem 139 13 14 248
21397xmem 139 0 13 0
21398xhcmp 0 1
21399xtrap 3 3
21400xhcmp 0 4098
21401xtrap 8 3
21402xmem 139 0 13 16
21403xhcmp 0 1
21404xtrap 3 3
21405xhcmp 0 1125899906842623
21406xtrap 8 3
21407xhadd 13 32
21408else
21409xaddr 13 get maptab 0
21410end
21411ximm 2 1
21412head = get oc 0
21413xmem 139 0 13 0
21414xrr 133 0 0
21415used = xbranch 1
21416xmem 139 10 13 16
21417if eq get progmode 0 0
21418xmem 139 11 14 248
21419xmem 139 11 11 16
21420xrr 57 10 11
21421else
21422xhcmp 10 36028797018963967
21423end
21424vacant = xbranch 3
21425xpatch used get oc 0
21426xhadd 13 32
21427xhadd 2 1
21428if eq get progmode 0 0
21429xmem 139 11 14 248
21430xmem 139 11 11 0
21431xrr 57 2 11
21432else
21433xhcmp 2 128
21434end
21435again = xbranch 9
21436xpatch again head
21437ximm 0 sub ulong 0 24
21438full = xbranch 14
21439xpatch vacant get oc 0
21440xsp 1 32
21441if eq c 243
21442xsp 1 16
21443end
21444xmem 137 2 4 0
21445xmem 137 6 4 8
21446xmem 137 10 4 16
21447if eq c 176
21448xha x 1 7
21449else
21450ximm 7 0
21451end
21452ximm 2 acc
21453if eq c 243
21454ximm 11 4095
21455xrr 137 0 6
21456xrr 33 0 11
21457xhcmp 0 0
21458xtrap 1 3
21459ximm 11 2097152
21460xrr 1 6 11
21461xtrap 3 3
21462end
21463ximm 10 mode
21464xhcall 9
21465xrr 133 0 0
21466failed = xbranch 11
21467if eq c 243
21468xrr 137 7 0
21469xhadd 0 2097151
21470ximm 11 18446744073707454464
21471xrr 33 0 11
21472xmem 137 0 4 24
21473xrr 137 6 0
21474xrr 41 6 7
21475xmem 137 6 4 32
21476xrr 133 6 6
21477aligned = xbranch 0
21478xhcall 11
21479xrr 133 0 0
21480xtrap 1 3
21481xpatch aligned get oc 0
21482xmem 139 7 4 24
21483xmem 139 6 4 8
21484xrr 1 7 6
21485note Suffix = 2MiB - prefix, both page aligned.
21486xmem 139 0 4 32
21487ximm 6 2097152
21488xrr 41 6 0
21489xhcall 11
21490xrr 133 0 0
21491xtrap 1 3
21492xmem 139 0 4 24
21493end
21494wrong = ulong 0
21495if eq c 176
21496xha x 1 2
21497xrr 57 0 2
21498exact = xbranch 0
21499xrr 137 7 0
21500xmem 139 6 4 8
21501xhcall 11
21502xrr 133 0 0
21503xtrap 1 3
21504ximm 0 sub ulong 0 95
21505wrong = xbranch 14
21506xpatch exact get oc 0
21507end
21508xmem 137 0 13 0
21509xmem 139 2 4 8
21510xmem 137 2 13 8
21511xmem 139 2 4 16
21512xhadd 2 1
21513xmem 137 2 13 16
21514ximm 0 acc
21515xmem 137 0 13 24
21516xrr 137 0 2
21517xb 72 193 224
21518if eq get progmode 0 0
21519emitb 13
21520else
21521emitb 8
21522end
21523xmem 139 2 4 0
21524xrr 9 0 2
21525xpatch failed get oc 0
21526if ne wrong 0
21527xpatch wrong get oc 0
21528end
21529xsp 0 32
21530if eq c 243
21531xsp 0 16
21532end
21533xpatch full get oc 0
21534xhdone dst x 0
21535end
21536fn xhmbind dst ulong x ulong to void
21537harg x 0 9
21538harg x 1 8
21539harg x 2 5
21540harg x 3 8
21541if ne get a_ar add get a_rb 77 add x 14 3
21542note d2site 566|xhmbind: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 14 3
21543put d2site 0 566
21544fail 9
21545end
21546acc = get a_ar add get a_rb 77 add x 15
21547if and ne acc 1 ne acc 3
21548note d2site 567|xhmbind: word or declaration in a place that does not allow it; condition if and ne acc 1 ne acc 3
21549put d2site 0 567
21550fail 9
21551end
21552xhbegin
21553xha x 0 10
21554xhmcheck
21555xmem 139 0 13 24
21556xrr 133 0 0
21557xtrap 1 3
21558xsp 1 32
21559xmem 137 8 4 0
21560xmem 137 9 4 8
21561xrr 137 7 8
21562xrr 137 6 9
21563xha x 1 8
21564xha x 2 9
21565ximm 2 acc
21566ximm 10 17
21567xhcall 9
21568xrr 133 0 0
21569failed = xbranch 11
21570xmem 139 2 4 0
21571xrr 57 0 2
21572xtrap 1 3
21573ximm 0 acc
21574xmem 137 0 13 24
21575ximm 0 0
21576done = xbranch 14
21577xpatch failed get oc 0
21578xmem 137 0 4 16
21579ximm 0 4
21580xmem 137 0 13 24
21581xmem 139 7 4 0
21582xmem 139 6 4 8
21583xhcall 11
21584xrr 133 0 0
21585xtrap 1 3
21586ximm 0 0
21587xmem 137 0 13 0
21588xmem 137 0 13 8
21589xmem 137 0 13 24
21590xmem 139 0 4 16
21591xpatch done get oc 0
21592xhdone dst x 32
21593end
21594fn xhmcopy c ulong dst ulong x ulong to void
21595harg x 4 9
21596harg x 3 5
21597wr = ulong 0
21598if eq c 169
21599wr = ulong 1
21600end
21601e = harray x wr
21602xhbegin
21603xha x 4 10
21604xhmcheck
21605xmem 139 0 13 24
21606xrr 133 0 0
21607xtrap 0 3
21608xhcmp 0 3
21609xtrap 8 3
21610xha x 3 2
21611xrr 57 2 9
21612xtrap 8 3
21613xrr 41 9 2
21614xhs 1 get a_ar add get a_rb 77 add x 22
21615xrr 57 1 9
21616xtrap 8 3
21617xrr 1 8 2
21618xhb 7 e get a_ar add get a_rb 77 add x 21
21619xrr 137 6 8
21620if eq c 170
21621xmem 139 0 13 24
21622xhcmp 0 3
21623xtrap 1 3
21624xrr 137 6 7
21625xrr 137 7 8
21626end
21627xrr 137 2 1
21628emitb 243
21629emitb 164
21630xrr 137 0 2
21631xhdone dst x 0
21632end
21633fn xhmmio c ulong dst ulong x ulong to void
21634harg x 0 9
21635if eq c 173
21636xhbegin
21637xha x 0 10
21638xhmcheck
21639xrr 137 0 8
21640xhdone dst x 0
21641put rt 0 5
21642ret
21643end
21644harg x 1 5
21645harg x 2 8
21646if ne get a_ar add get a_rb 77 add x 12 3
21647note d2site 568|xhmmio: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 12 3
21648put d2site 0 568
21649fail 9
21650end
21651w = get a_ar add get a_rb 77 add x 13
21652if and ne w 4 ne w 8
21653note d2site 569|xhmmio: word or declaration in a place that does not allow it; condition if and ne w 4 ne w 8
21654put d2site 0 569
21655fail 9
21656end
21657if eq c 175
21658harg x 3 5
21659end
21660xhbegin
21661xha x 0 10
21662xhmcheck
21663xha x 1 2
21664xmem 139 0 13 24
21665xrr 133 0 0
21666xtrap 0 3
21667xhcmp 0 3
21668xtrap 8 3
21669xrr 57 2 9
21670xtrap 8 3
21671xrr 41 9 2
21672xhcmp 9 w
21673xtrap 3 3
21674xrr 137 0 2
21675ximm 1 sub w 1
21676xrr 33 0 1
21677xrr 133 0 0
21678xtrap 1 3
21679xrr 1 8 2
21680if eq c 175
21681xmem 139 0 13 24
21682xhcmp 0 3
21683xtrap 1 3
21684xha x 3 2
21685if eq w 4
21686xhcmp 2 4294967295
21687xtrap 8 3
21688end
21689xb 15 174 240
21690if eq w 4
21691xhput 2 8 0 4
21692else
21693xmem 137 2 8 0
21694end
21695xb 15 174 240
21696ximm 0 0
21697xhdone dst x 0
21698else
21699xb 15 174 240
21700if eq w 4
21701xhraw 0 8 0 4
21702else
21703xmem 139 0 8 0
21704end
21705xb 15 174 240
21706xhdone dst x 0
21707put rt 0 5
21708end
21709end
21710note One compile-time ioctl allowlist is shared by both native Linux backends.
21711fn xhreq c ulong x ulong to ulong
21712harg x 4 8
21713harg x 2 4
21714if ne get a_ar add get a_rb 77 add x 12 3
21715note d2site 570|xhreq: word or declaration in a place that does not allow it; condition if ne get a_ar add get a_rb 77 add x 12 3
21716put d2site 0 570
21717fail 9
21718end
21719q = get a_ar add get a_rb 77 add x 13
21720n = ulong 4
21721if eq c 166
21722if ne q 21531
21723if ne and q 3221290752 3221243392
21724ok = eq q 2154840336
21725ok = or ok eq q 3224387873
21726ok = or ok eq q 3222815010
21727ok = or ok eq q 3225960739
21728ok = or ok eq q 3222815012
21729if not ok
21730note d2site 571|xhreq: word or declaration in a place that does not allow it; condition if not ok
21731put d2site 0 571
21732fail 9
21733end
21734end
21735n = and shr q 16 16383
21736if eq n 0
21737note d2site 572|xhreq: word or declaration in a place that does not allow it; condition if eq n 0
21738put d2site 0 572
21739fail 9
21740end
21741end
21742end
21743if eq c 172
21744n = ulong 0
21745if eq q 805306369
21746n = ulong 16
21747end
21748if eq q 75
21749n = ulong 8
21750end
21751if eq q 37
21752n = ulong 40
21753end
21754if or eq q 38 eq q 26
21755n = ulong 20
21756end
21757if eq q 25
21758n = ulong 32
21759end
21760if eq q 27
21761n = ulong 56
21762end
21763if eq q 28
21764n = ulong 28
21765end
21766if eq q 33
21767n = ulong 9264
21768end
21769if or eq q 34 eq q 73
21770n = ulong 24
21771end
21772if eq n 0
21773note d2site 573|xhreq: word or declaration in a place that does not allow it; condition if eq n 0
21774put d2site 0 573
21775fail 9
21776end
21777end
21778if eq c 171
21779if and ne q 3223340586 ne q 3223340587
21780note d2site 574|xhreq: word or declaration in a place that does not allow it; condition if and ne q 3223340586 ne q 3223340587
21781put d2site 0 574
21782fail 9
21783end
21784n = ulong 32
21785end
21786ret n
21787end
21788fn xhdev c ulong dst ulong x ulong to void
21789n = xhreq c x
21790put a_ar add get a_rb 77 add x 23 n
21791e = harray x 1
21792if ne c 171
21793xhbegin
21794xhs 2 get a_ar add get a_rb 77 add x 22
21795xhcmp 2 get a_ar add get a_rb 77 add x 23
21796xtrap 1 3
21797xha x 4 7
21798xha x 2 6
21799xhb 2 e get a_ar add get a_rb 77 add x 21
21800xhcall 16
21801xhdone dst x 0
21802ret
21803end
21804put a_ar add get a_rb 77 add x 23 e
21805a_p 77 add x 24 a_g 77 add x 21
21806a_p 77 add x 25 a_g 77 add x 22
21807f = harray x 1
21808if eq e f
21809note d2site 575|xhdev: global passed as an argument, or one array twice in a call; condition if eq e f
21810put d2site 0 575
21811fail 19
21812end
21813xhbegin
21814xhs 2 get a_ar add get a_rb 77 add x 25
21815xhcmp 2 32
21816xtrap 1 3
21817xhs 9 get a_ar add get a_rb 77 add x 22
21818xhcmp 9 1048576
21819xtrap 8 3
21820xhb 13 e get a_ar add get a_rb 77 add x 24
21821xhb 8 f get a_ar add get a_rb 77 add x 21
21822xrr 133 9 9
21823empty = xbranch 0
21824xrr 137 2 8
21825xrr 1 2 9
21826xrr 57 2 13
21827before = xbranch 9
21828xmem 141 2 13 32
21829xrr 57 8 2
21830xtrap 3 3
21831xpatch before get oc 0
21832xpatch empty get oc 0
21833xmem 139 2 13 16
21834xrr 133 2 2
21835xtrap 1 3
21836xrr 133 9 9
21837nonzero = xbranch 1
21838ximm 8 0
21839xpatch nonzero get oc 0
21840xsp 1 32
21841for j ulong 4
21842xmem 139 0 13 mul j 8
21843xmem 137 0 4 mul j 8
21844end
21845xmem 137 8 4 16
21846xhput 9 4 24 4
21847xha x 4 7
21848xha x 2 6
21849xrr 137 2 4
21850xhcall 16
21851for j ulong 4
21852if ne j 2
21853xmem 139 2 4 mul j 8
21854xmem 137 2 13 mul j 8
21855end
21856end
21857xhdone dst x 32
21858end
21859fn xhost c ulong dst ulong to void
21860if ne get xtarget 0 1
21861note d2site 576|xhost: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xtarget 0 1
21862put d2site 0 576
21863fail 25
21864end
21865if eq 0 get progmode 0
21866if eq 0 get om2 0
21867note d2site 577|xhost: word or declaration in a place that does not allow it; condition if eq 0 get om2 0
21868put d2site 0 577
21869fail 9
21870end
21871ok = ulong 0
21872if or or eq c 100 eq c 110 or eq c 117 eq c 140
21873ok = ulong 1
21874end
21875if and le c 149 ge c 145
21876ok = ulong 1
21877end
21878if or or eq c 130 eq c 109 eq c 120
21879ok = ulong 1
21880end
21881if and le c 177 ge c 166
21882ok = ulong 1
21883end
21884if eq ok 0
21885note d2site 578|xhost: word or declaration in a place that does not allow it; condition if eq ok 0
21886put d2site 0 578
21887fail 9
21888end
21889end
21890note execpure (198) has no x86 strict-profile lowering; refuse it rather than run an unconfined exec.
21891if eq c 198
21892note d2site 579|xhost: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if eq c 198
21893put d2site 0 579
21894fail 25
21895end
21896eff_rec c
21897x = mul get depth 0 32
21898put a_ar add get a_rb 77 add x 7 get nslot 0
21899if and ge c 241 le c 243
21900mtinit
21901if eq c 241
21902kctl dst x
21903else
21904xhmnew c dst x
21905end
21906ret
21907end
21908if and ge c 236 le c 238
21909xhsched c dst x
21910ret
21911end
21912if eq c 235
21913xhprlim dst x
21914ret
21915end
21916if or eq c 220 eq c 222
21917xhsock c dst x
21918ret
21919end
21920if or eq c 123 eq c 221
21921xhpoll c dst x
21922ret
21923end
21924if and ge c 167 le c 177
21925if or eq c 171 eq c 172
21926xhdev c dst x
21927ret
21928end
21929mtinit
21930if or eq c 167 eq c 176
21931xhmnew c dst x
21932ret
21933end
21934if eq c 177
21935xhmbind dst x
21936ret
21937end
21938if eq c 168
21939harg x 0 9
21940xhbegin
21941xha x 0 10
21942xhmcheck
21943xrr 137 7 8
21944xrr 137 6 9
21945xhcall 11
21946xrr 133 0 0
21947failed = xbranch 1
21948xmem 137 0 13 0
21949xmem 137 0 13 8
21950xmem 137 0 13 24
21951xpatch failed get oc 0
21952xhdone dst x 0
21953ret
21954end
21955if or eq c 169 eq c 170
21956xhmcopy c dst x
21957ret
21958end
21959xhmmio c dst x
21960ret
21961end
21962if eq c 166
21963xhdev c dst x
21964ret
21965end
21966if or eq c 132 eq c 128
21967xhsimple c dst x
21968ret
21969end
21970if eq c 135
21971xhsimple c dst x
21972ret
21973end
21974if eq c 133
21975xhreadln dst x
21976ret
21977end
21978if eq c 134
21979xhsock c dst x
21980ret
21981end
21982if or or eq c 109 eq c 130 eq c 120
21983xhtime c dst x
21984ret
21985end
21986if or or or and ge c 113 le c 119 eq c 131 or eq c 161 eq c 162 eq c 224
21987xhbuffer c dst x
21988ret
21989end
21990if or or or eq c 121 eq c 122 eq c 136 eq c 137
21991xhargs c dst x
21992ret
21993end
21994if or or or or eq c 124 eq c 125 eq c 141 eq c 142 eq c 233
21995xhpack c dst x
21996ret
21997end
21998if or eq c 140 eq c 149
21999xhstats c dst x
22000ret
22001end
22002if or or or or eq c 110 eq c 111 eq c 112 eq c 126 eq c 138
22003xhpaths c dst x
22004ret
22005end
22006if or or or or eq c 143 eq c 144 eq c 150 eq c 151 eq c 157
22007xhpaths c dst x
22008ret
22009end
22010xhscalar c dst x
22011end
22012
22013note ======== Native x86-64 semantic backend ========
22014note Intel SDM volume 2 instruction entries MOV, LEA, CALL, RET, Jcc, SETcc, MOVSX,
22015note MOVZX, ADD, SUB, IMUL, DIV, IDIV, SHL, SHR, SAR, SYSCALL; volume 2 chapter 2
22016note supplies REX, ModRM and SIB. No A64 word decoding occurs in this backend.
22017fn xb a ulong b ulong c ulong to void
22018emitb uchar a
22019emitb uchar b
22020emitb uchar c
22021end
22022
22023fn xword v ulong to void
22024emitb uchar and v 255
22025emitb uchar and shr v 8 255
22026emitb uchar and shr v 16 255
22027emitb uchar and shr v 24 255
22028end
22029
22030fn ximm r ulong v ulong to void
22031emitb uchar add 72 shr r 3
22032emitb uchar add 184 and r 7
22033xword v
22034xword shr v 32
22035end
22036
22037note Hardware registers are private emitter operands. Language values are RBP slots.
22038fn xrr op ulong d ulong s ulong to void
22039emitb uchar add add 72 shl shr s 3 2 shr d 3
22040emitb uchar op
22041emitb uchar add add 192 shl and s 7 3 and d 7
22042end
22043
22044fn xmem op ulong r ulong b ulong off ulong to void
22045emitb uchar add add 72 shl shr r 3 2 shr b 3
22046emitb uchar op
22047emitb uchar add add 128 shl and r 7 3 and b 7
22048if eq and b 7 4
22049emitb 36
22050end
22051xword off
22052end
22053
22054fn xload r ulong s ulong to void
22055xmem 139 r 5 sub ulong 0 mul add s 1 8
22056end
22057
22058fn xstore r ulong s ulong to void
22059xmem 137 r 5 sub ulong 0 mul add s 1 8
22060end
22061
22062fn xcc cc ulong to ulong
22063if eq cc 0
22064ret 4
22065end
22066if eq cc 1
22067ret 5
22068end
22069if eq cc 2
22070ret 3
22071end
22072if eq cc 3
22073ret 2
22074end
22075if eq cc 6
22076ret 0
22077end
22078if eq cc 7
22079ret 1
22080end
22081if eq cc 8
22082ret 7
22083end
22084if eq cc 9
22085ret 6
22086end
22087if eq cc 10
22088ret 13
22089end
22090if eq cc 11
22091ret 12
22092end
22093if eq cc 12
22094ret 15
22095end
22096if eq cc 13
22097ret 14
22098end
22099note d2site 580|xcc: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14)
22100put d2site 0 580
22101fail 25
22102ret 0
22103end
22104
22105note Every branch reserves six bytes; all targets are byte offsets, not word offsets.
22106fn xbranch cc ulong to ulong
22107p = get oc 0
22108if eq cc 14
22109emitb 233
22110xword 0
22111emitb 144
22112else
22113emitb 15
22114emitb uchar add 128 xcc cc
22115xword 0
22116end
22117ret p
22118end
22119
22120fn xpatch p ulong dest ulong to void
22121if eq a_ob p 233
22122wrword add p 1 sub dest add p 5
22123else
22124wrword add p 2 sub dest add p 6
22125end
22126end
22127
22128fn xtrap cc ulong code ulong to void
22129n = get nt 0
22130if ge n get a_gp 10
22131a_need 10 n
22132end
22133put a_ar add get a_rb 45 n code
22134put a_ar add get a_rb 44 n xbranch cc
22135put nt 0 add n 1
22136if eq get om2m 0 1
22137siterec
22138end
22139end
22140
22141fn xcmp a ulong b ulong imm ulong to void
22142xload 0 a
22143if ne imm 0
22144ximm 1 b
22145else
22146xload 1 b
22147end
22148xrr 57 0 1
22149end
22150
22151note Canonicalization uses shifts, preserving the checked language's signed widths.
22152fn xcanrax t ulong to void
22153if eq t 10
22154emitb 137
22155emitb 192
22156ret
22157end
22158w = twid t
22159if eq w 64
22160ret
22161end
22162xb 72 193 224
22163emitb uchar sub 64 w
22164xb 72 193 232
22165if ge t 6
22166a_bput 1 sub get oc 0 1 248
22167end
22168emitb uchar sub 64 w
22169end
22170
22171fn xext r ulong t ulong code ulong to void
22172xload 0 r
22173xrr 137 2 0
22174xcanrax t
22175xrr 57 0 2
22176xtrap 1 code
22177end
22178
22179fn xarith op ulong ty ulong a ulong b ulong imm ulong d ulong to void
22180if or eq ty 10 eq ty 11
22181if or lt op 33 gt op 35
22182note d2site 581|xarith: type mismatch; condition if or lt op 33 gt op 35
22183put d2site 0 581
22184fail 7
22185end
22186if ne imm 0
22187matconst 16 b
22188b = ulong 16
22189end
22190xfbin op ty a b d
22191ret
22192end
22193xload 0 a
22194if ne imm 0
22195ximm 1 b
22196else
22197xload 1 b
22198end
22199if eq op 33
22200xrr 1 0 1
22201if eq ty 13
22202xtrap 3 1
22203end
22204end
22205if eq op 34
22206xrr 41 0 1
22207if eq ty 13
22208xtrap 3 1
22209end
22210end
22211if eq op 35
22212if eq ty 13
22213xb 72 247 225
22214xrr 133 2 2
22215xtrap 1 1
22216else
22217xb 72 15 175
22218emitb 193
22219end
22220end
22221if eq op 38
22222xrr 33 0 1
22223end
22224if eq op 39
22225xrr 9 0 1
22226end
22227if eq op 40
22228xrr 49 0 1
22229end
22230if and eq ty 9 le op 35
22231xtrap 6 1
22232end
22233xstore 0 d
22234if le op 35
22235bo_fix d ty
22236end
22237end
22238
22239fn xdiv op ulong ty ulong a ulong b ulong d ulong fl ulong to void
22240if or eq ty 10 eq ty 11
22241if ne op 36
22242note d2site 582|xdiv: type mismatch; condition if ne op 36
22243put d2site 0 582
22244fail 7
22245end
22246xfbin op ty a b d
22247ret
22248end
22249xload 0 a
22250xload 1 b
22251note Match bo_div's constant-divisor proofs and source trap sites.
22252if eq and fl 1 0
22253xrr 133 1 1
22254xtrap 0 2
22255end
22256done = ulong 0
22257if and ge ty 6 le ty 9
22258if and eq ty 9 eq and fl 2 0
22259note Only 64-bit IDIV can fault on MIN/-1; remainder must bypass with zero.
22260ximm 2 18446744073709551615
22261xrr 57 1 2
22262other = xbranch 1
22263if eq op 37
22264ximm 0 0
22265done = xbranch 14
22266else
22267xb 72 247 216
22268xtrap 6 1
22269done = xbranch 14
22270end
22271xpatch other get oc 0
22272end
22273xb 72 153 144
22274xb 72 247 249
22275else
22276xrr 49 2 2
22277xb 72 247 241
22278end
22279if eq op 37
22280xrr 137 0 2
22281end
22282if ne done 0
22283xpatch done get oc 0
22284end
22285xstore 0 d
22286note Narrow signed quotients can overflow; remainders and unsigned quotients cannot.
22287if and eq op 36 and ge ty 6 lt ty 9
22288bo_fix d ty
22289end
22290end
22291
22292fn xshift op ulong ty ulong a ulong b ulong imm ulong d ulong to void
22293xload 0 a
22294if ne imm 0
22295ximm 1 b
22296else
22297xload 1 b
22298end
22299note imm is set only for a statically valid shift amount, as in bo_shl/bo_shr.
22300if eq imm 0
22301ximm 2 twid ty
22302xrr 57 1 2
22303xtrap 2 7
22304end
22305xrr 137 2 0
22306if eq op 41
22307xb 72 211 224
22308if eq ty 9
22309xrr 137 8 0
22310xb 73 211 248
22311xrr 57 8 2
22312xtrap 1 1
22313end
22314else
22315if ge ty 6
22316xb 72 211 248
22317else
22318xb 72 211 232
22319end
22320end
22321xstore 0 d
22322if eq op 41
22323bo_fix d ty
22324end
22325end
22326
22327fn xunary op ulong dst ulong to void
22328ty = get rt 0
22329if eq ty 13
22330note d2site 583|xunary: type mismatch; condition if eq ty 13
22331put d2site 0 583
22332fail 7
22333end
22334if or eq ty 10 eq ty 11
22335if eq op 50
22336note d2site 584|xunary: type mismatch; condition if eq op 50
22337put d2site 0 584
22338fail 7
22339end
22340fa = matreg get rk 0 get rv 0 ty
22341fd = destreg dst
22342note xfneg / xfsqrt / xfabs: the x86 forms of fp_neg / fp_un1 on x registers ra into rd (sign mask, SQRTS).
22343xload 0 fa
22344ximm 1 xfmask ty 0
22345xrr 49 0 1
22346xstore 0 fd
22347put rk 0 1
22348put rv 0 fd
22349put rt 0 ty
22350ret
22351end
22352a = matreg get rk 0 get rv 0 ty
22353d = destreg dst
22354xload 0 a
22355if eq op 50
22356if eq ty 1
22357ximm 1 1
22358xrr 49 0 1
22359else
22360xb 72 247 208
22361end
22362else
22363if eq ty 1
22364note d2site 585|xunary: type mismatch; condition if eq ty 1
22365put d2site 0 585
22366fail 7
22367end
22368xb 72 247 216
22369if eq ty 9
22370xtrap 6 1
22371end
22372end
22373xstore 0 d
22374if eq op 50
22375canon d ty
22376else
22377bo_fix d ty
22378end
22379put rk 0 1
22380put rv 0 d
22381put rt 0 ty
22382end
22383
22384fn xconv tt ulong to void
22385ft = get rt 0
22386if or or or eq ft 10 eq ft 11 eq tt 10 eq tt 11
22387if or eq ft 13 eq tt 13
22388note d2site 586|xconv: type mismatch; condition if or eq ft 13 eq tt 13
22389put d2site 0 586
22390fail 7
22391end
22392if or eq ft 1 eq tt 1
22393note d2site 587|xconv: word or declaration in a place that does not allow it; condition if or eq ft 1 eq tt 1
22394put d2site 0 587
22395fail 9
22396end
22397fa = matreg get rk 0 get rv 0 ft
22398fd = fp_conv ft tt fa
22399put rk 0 1
22400put rv 0 fd
22401put rt 0 tt
22402ret
22403end
22404if or eq ft 1 eq tt 1
22405note d2site 588|xconv: word or declaration in a place that does not allow it; condition if or eq ft 1 eq tt 1
22406put d2site 0 588
22407fail 9
22408end
22409r = matreg get rk 0 get rv 0 ft
22410wf = twid ft
22411wt = twid tt
22412s = ulong 99
22413if not and ge ft 6 le ft 9
22414if and ge tt 6 le tt 9
22415if ge wf wt
22416s = sub wt 1
22417end
22418else
22419if gt wf wt
22420s = wt
22421end
22422end
22423else
22424if not and ge tt 6 le tt 9
22425s = wt
22426if gt s 63
22427s = ulong 63
22428end
22429else
22430if gt wf wt
22431xext r tt 5
22432end
22433end
22434end
22435if ne s 99
22436xload 0 r
22437xb 72 193 232
22438emitb uchar s
22439xrr 133 0 0
22440xtrap 1 5
22441end
22442put rk 0 1
22443put rv 0 r
22444put rt 0 tt
22445end
22446
22447note Reserve checked stack BEFORE stores, CALL return addresses, or PUSH.
22448fn xcheck bytes ulong to void
22449xmem 141 0 4 sub ulong 0 bytes
22450xrr 57 0 15
22451xtrap 3 6
22452end
22453
22454fn xsp down ulong bytes ulong to void
22455if eq bytes 0
22456ret
22457end
22458if ne down 0
22459xcheck bytes
22460xb 72 129 236
22461else
22462xb 72 129 196
22463end
22464xword bytes
22465end
22466
22467fn xmovsp r ulong to void
22468xrr 137 0 4
22469xstore 0 r
22470end
22471
22472fn xpro np ulong to void
22473xrr 137 11 5
22474emitb 85
22475xrr 137 5 4
22476xb 72 129 236
22477xword 256
22478j = ulong 0
22479while lt j np
22480xmem 139 0 11 sub ulong 0 mul add j 1 8
22481xstore 0 j
22482j = add j 1
22483end
22484end
22485
22486
22487fn xarg t ulong k ulong v ulong to void
22488if eq k 6
22489mataddr t v
22490ret
22491end
22492if or eq k 3 eq k 7
22493matconst t v
22494ret
22495end
22496xmem 139 0 4 mul v 8
22497xstore 0 t
22498end
22499
22500fn xrestore d ulong slot ulong res ulong to ulong
22501put nslot 0 slot
22502rd = ulong 255
22503if ne res 0
22504rd = destreg d
22505xstore 0 rd
22506end
22507j = ulong 0
22508while lt j 18
22509if ne j rd
22510xmem 139 0 4 mul j 8
22511xstore 0 j
22512end
22513j = add j 1
22514end
22515xsp 0 256
22516ret rd
22517end
22518
22519note Typed addresses carry origin through fixup records. Numeric constants never relocate.
22520fn mataddr r ulong v ulong to void
22521if eq get xtarget 0 0
22522if ne get xefa 0 0
22523note a64efi: the image loads anywhere. A pool address (0x10000000 up) is its offset plus X27, the base of
22524note the .bss the entry found; a text address (0x400000 + file offset) is ADRP + ADD from this instruction
22525note (C6.2.11, C6.2.5), both as RVAs = file offset + 3584.
22526if ge v 268435456
22527matconst r sub v 268435456
22528e3 2332033024 r r 27
22529ret
22530end
22531t = add sub v 4194304 3584
22532d = and sub shr t 12 shr add get oc 0 3584 12 2097151
22533emit or or or 2415919104 shl and d 3 29 shl shr d 2 5 r
22534emit or or or 2432696320 shl and t 4095 10 shl r 5 r
22535ret
22536end
22537matconst r v
22538ret
22539end
22540xaddr 0 v
22541xstore 0 r
22542end
22543
22544fn xaddr r ulong v ulong to void
22545n = get xnaddr 0
22546if ge n get a_gp 11
22547a_need 11 n
22548end
22549emitb uchar add 72 shl shr r 3 2
22550emitb 141
22551emitb uchar add 5 shl and r 7 3
22552put a_ar add get a_rb 46 n get oc 0
22553put a_ar add get a_rb 47 n v
22554put xnaddr 0 add n 1
22555xword 0
22556end
22557
22558fn xelem e ulong k ulong v ulong t ulong to void
22559if or or eq t 1 eq t 10 eq t 11
22560note d2site 589|xelem: type mismatch; condition if or or eq t 1 eq t 10 eq t 11
22561put d2site 0 589
22562fail 7
22563end
22564i = sub e 1
22565if eq get a_ar add get a_rb 6 i 0
22566if eq uchar get a_ar add get a_rb 7 i 10
22567xepool i k v t
22568ret
22569end
22570end
22571ln = get a_ar add get a_rb 6 i
22572x = v
22573if ne unsz i 0
22574x = matreg k v t
22575xcmp x ulong uchar get a_ar add get a_rb 14 i 0
22576xtrap 2 3
22577else
22578if eq k 3
22579if le ln v
22580note d2site 590|xelem: constant index outside the array; condition if le ln v
22581put d2site 0 590
22582fail 21
22583end
22584if and ne get om2 0 0 le v 4095
22585x = ulong 255
22586put ea_k 0 v
22587else
22588x = alloc
22589matconst x v
22590end
22591else
22592xcmp v ln 1
22593xtrap 2 3
22594end
22595end
22596put ea_i 0 x
22597note A global's base is not held in an operand slot: ea_b 254 tells xbase to LEA it into RDX at the access
22598note itself (xaddr), which follows elemaddr directly in every x86 caller (vt_get, stel), so OM-2 units whose
22599note AArch64 form pins globals keep their operand budget on x86 too.
22600if ge uchar get a_ar add get a_rb 7 i 4
22601put xea_g 0 get a_ar add get a_rb 8 i
22602put ea_b 0 254
22603else
22604put ea_b 0 ulong a_gu 4 i
22605end
22606end
22607
22608note xepool: the element address of run-time pool i (docs/RUNTIME-POOLS.md s4) on x86linux for index (k, v, t).
22609note The slot is read here, after every operand of the access (soundness rule B1): RCX = index, LEA RDX,
22610note [RIP + slot], MOV RAX, [RDX + 8] (length), MOV RDX, [RDX] (base), CMP RCX, RAX (39 /r), JAE trap 3, so
22611note a negative signed index traps as a large unsigned one. The base goes to a new operand slot; a number
22612note index is checked at run time too (no error 21, no check elimination).
22613fn xepool i ulong k ulong v ulong t ulong to void
22614x = matreg k v t
22615b = alloc
22616xload 1 x
22617xaddr 2 get a_ar add get a_rb 8 i
22618xmem 139 0 2 8
22619xmem 139 2 2 0
22620xrr 57 1 0
22621note POOLMUT-ALT x86cmp note removed
22622note POOLMUT x86cmp
22623xtrap 2 3
22624xstore 2 b
22625put ea_i 0 x
22626put ea_b 0 b
22627end
22628
22629note xenlarge: r = enlarge P n on x86linux (docs/RUNTIME-POOLS.md s3, s4), emitted inline at each site, so it
22630note needs no call frame. In: p the pool's name (index + 1), whose slot address a holds (base, length) and
22631note s log2 of its element size, nv n's operand
22632note slot. Out: RAX = 0, -22 when n << s reaches 2^63, or the host's -errno; the slot changes only on success.
22633note Intel SDM vol 2: MOV 8B/89 /r, LEA 8D /r, CMP 39 /r and REX.W 3D id, TEST 85 /r, SHL/SHR C1 /4 /5 ib,
22634note ADD/AND 81 /0 /4 id, MOV B8+r io, Jcc 0F 8x cd, JMP E9 cd, SYSCALL 0F 05. Linux x86-64: mmap 9 (RDI 0,
22635note RSI bytes, RDX PROT_READ|PROT_WRITE 3, R10 MAP_PRIVATE|MAP_ANONYMOUS 0x22, R8 -1, R9 0), mremap 25
22636note (RDI old base, RSI old bytes, RDX new bytes, R10 MREMAP_MAYMOVE 1). SYSCALL clobbers RCX and R11 only.
22637note Language values live in RBP slots, so only RAX, RCX, RDX, RSI, RDI, R8..R11 change here.
22638fn xenlarge p ulong nv ulong to void
22639a = get a_ar add get a_rb 8 sub p 1
22640s = tlog ulong uchar get a_ar add get a_rb 5 sub p 1
22641note RSI = n, RDI = slot, RAX = length; n <= length: nothing changes (JBE)
22642xload 6 nv
22643xaddr 7 a
22644xmem 139 0 7 8
22645xrr 57 6 0
22646note POOLMUT-ALT x86belowlen sm = xbranch 0
22647note POOLMUT x86belowlen
22648sm = xbranch 9
22649note RDX = n >> (63 - s): nonzero means n << s reaches 2^63 (JNE to -22)
22650xrr 137 2 6
22651xb 72 193 234
22652emitb uchar sub 63 s
22653xrr 133 2 2
22654note POOLMUT-ALT x86ovf ov = xbranch 0
22655note POOLMUT x86ovf
22656ov = xbranch 1
22657note RDX = new bytes, RSI = old bytes, each rounded up to the 4096-byte page
22658xrr 137 2 6
22659xb 72 193 226
22660emitb uchar s
22661xb 72 129 194
22662xword 4095
22663xb 72 129 226
22664xword 4294963200
22665xrr 137 6 0
22666xb 72 193 230
22667emitb uchar s
22668xb 72 129 198
22669xword 4095
22670xb 72 129 230
22671xword 4294963200
22672note within the pages already mapped (JBE): store only the length; they are still zero
22673xrr 57 2 6
22674ft = xbranch 9
22675note length 0: mmap; else mremap
22676xrr 133 0 0
22677rm = xbranch 1
22678ximm 7 0
22679xrr 137 6 2
22680ximm 2 3
22681ximm 10 34
22682ximm 8 18446744073709551615
22683ximm 9 0
22684ximm 0 9
22685emitb 15
22686emitb 5
22687cl = xbranch 14
22688xpatch rm get oc 0
22689xmem 139 7 7 0
22690ximm 10 1
22691ximm 0 25
22692emitb 15
22693emitb 5
22694xpatch cl get oc 0
22695note RAX in -4095..-1 (CMP RAX, -4095; JAE): the host refused, RAX is the result, the slot is untouched
22696emitb 72
22697emitb 61
22698xword 4294963201
22699note POOLMUT-ALT x86slotfail hf = xbranch 3
22700note POOLMUT x86slotfail
22701hf = xbranch 2
22702xaddr 7 a
22703note POOLMUT-ALT x86base note removed
22704note POOLMUT x86base
22705xmem 137 0 7 0
22706xpatch ft get oc 0
22707xload 0 nv
22708xmem 137 0 7 8
22709xpatch sm get oc 0
22710ximm 0 0
22711dn = xbranch 14
22712xpatch ov get oc 0
22713ximm 0 18446744073709551594
22714xpatch dn get oc 0
22715xpatch hf get oc 0
22716end
22717
22718note xbase: RDX = the base of the element access: the global address xea_g when base is 254 (LEA RDX,
22719note [RIP + disp32], SDM vol 2 LEA, with an xaddr fixup), else the operand slot base (MOV RDX, [RBP - ...]).
22720fn xbase base ulong to void
22721if eq base 254
22722xaddr 2 get xea_g 0
22723ret
22724end
22725xload 2 base
22726end
22727
22728note Indexed load/store uses RDX=base+index*element-size; pointers never enter source scalars.
22729fn xmemval store ulong base ulong idx ulong ty ulong val ulong to void
22730xbase base
22731if eq idx 255
22732ximm 1 get ea_k 0
22733else
22734xload 1 idx
22735end
22736xb 72 193 225
22737emitb uchar tlog ty
22738xrr 1 2 1
22739xmemraw store ty val
22740end
22741
22742note RDX is a checked aggregate address; layout byte offsets do not scale by the field width.
22743fn xlayout store ulong base ulong idx ulong ty ulong val ulong to void
22744xbase base
22745xload 1 idx
22746xrr 1 2 1
22747xmemraw store ty val
22748end
22749
22750fn xmemraw store ulong ty ulong val ulong to void
22751if ne store 0
22752xload 0 val
22753if eq twid ty 16
22754emitb 102
22755end
22756if eq twid ty 64
22757emitb 72
22758end
22759if le twid ty 8
22760emitb 136
22761else
22762emitb 137
22763end
22764emitb 2
22765else
22766if eq twid ty 64
22767xb 72 139 2
22768else
22769if eq twid ty 32
22770if and ge ty 6 le ty 9
22771xb 72 99 2
22772else
22773emitb 139
22774emitb 2
22775end
22776else
22777emitb 72
22778emitb 15
22779op = ulong 182
22780if eq twid ty 16
22781op = ulong 183
22782end
22783if and ge ty 6 le ty 9
22784op = add op 8
22785end
22786emitb uchar op
22787emitb 2
22788end
22789end
22790xstore 0 val
22791end
22792end
22793
22794fn xio c ulong fk ulong fv ulong e ulong ro ulong rn ulong to void
22795if ne get xtarget 0 1
22796note d2site 591|xio: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xtarget 0 1
22797put d2site 0 591
22798fail 25
22799end
22800save
22801i = sub e 1
22802if eq uchar get a_ar add get a_rb 7 i 10
22803note pool: RSI = the base word of its slot, loaded after every operand (soundness rule B1)
22804xaddr 6 get a_ar add get a_rb 8 i
22805xmem 139 6 6 0
22806else
22807if ge uchar get a_ar add get a_rb 7 i 4
22808xaddr 6 get a_ar add get a_rb 8 i
22809else
22810xload 6 ulong uchar get a_ar add get a_rb 4 i
22811end
22812end
22813xmem 139 0 4 mul ro 8
22814xrr 1 6 0
22815if eq fk 3
22816ximm 7 fv
22817else
22818xmem 139 7 4 mul fv 8
22819end
22820xmem 139 2 4 mul rn 8
22821ximm 0 sub c 53
22822emitb 15
22823emitb 5
22824end
22825
22826fn xarray w ulong to void
22827if ne get nb 0 0
22828note d2site 592|xarray: word or declaration in a place that does not allow it; condition if ne get nb 0 0
22829put d2site 0 592
22830fail 9
22831end
22832t = typeword
22833elemtype t
22834n = lenval 16
22835arrlen n
22836by = shl shr add shl n tlog t 15 4 4
22837if gt add get stkbytes 0 by 4194304
22838note d2site 593|xarray: size capacity; condition if gt add get stkbytes 0 by 4194304
22839put d2site 0 593
22840fail 23
22841end
22842put stkbytes 0 add get stkbytes 0 by
22843r = alloc
22844put held 0 get nslot 0
22845rdval 0 t 255 0
22846if ne get rt 0 t
22847note d2site 594|xarray: type mismatch; condition if ne get rt 0 t
22848put d2site 0 594
22849fail 7
22850end
22851v = matreg get rk 0 get rv 0 t
22852xsp 1 by
22853xmovsp r
22854i = alloc
22855matconst i 0
22856lp = get oc 0
22857xmemval 1 r i t v
22858xarith 33 5 i 1 1 i
22859xcmp i n 1
22860blo lp
22861addname w r t n 1 0
22862end
22863
22864note xfornum / xforval: the x86 sf_num / sf_val. bn and n come from sf_num / sf_val, which parse the bound
22865note themselves (sf_val: 1000000 when no bound is written); bn = 0 leaves a number count unguarded, as on Arm.
22866fn xfornum w ulong t ulong k ulong sn ulong sh ulong bn ulong to void
22867eol
22868i = alloc
22869put held 0 get nslot 0
22870addname w i t 0 0 0
22871matconst i 0
22872c = ulong 0
22873if ne bn 0
22874c = alloc
22875put held 0 get nslot 0
22876matconst c 0
22877end
22878hd = get oc 0
22879cp_head get cur 0 get line 0
22880xcmp i k 1
22881br = sf_br t
22882if ne bn 0
22883lpcnt c bn
22884end
22885pushb br 4 hd i t
22886pushnh sn sh
22887cp_skip
22888end
22889
22890fn xforval w ulong t ulong kr ulong sn ulong sh ulong n ulong to void
22891eol
22892i = alloc
22893put held 0 get nslot 0
22894addname w i t 0 0 0
22895matconst i 0
22896c = alloc
22897put held 0 get nslot 0
22898matconst c 0
22899hd = get oc 0
22900cp_head get cur 0 get line 0
22901xcmp i kr 0
22902br = sf_br t
22903lpcnt c n
22904pushb br 4 hd i t
22905pushnh sn sh
22906cp_skip
22907end
22908
22909fn xleave to void
22910if eq get xtarget 0 2
22911note UEFI: every exit jumps to the shared firmware return emitted by xefx 1; RAX is the status.
22912n = get xnexit 0
22913if ge n get a_gp 12
22914a_need 12 n
22915end
22916put a_ar add get a_rb 48 n xbranch 14
22917put xnexit 0 add n 1
22918ret
22919end
22920xrr 137 7 0
22921ximm 0 60
22922emitb 15
22923emitb 5
22924end
22925
22926fn xfinish to void
22927eol
22928if eq get dead 0 0
22929if ne get curret 0 12
22930note d2site 595|xfinish: a function with a result can reach its end; condition if ne get curret 0 12
22931put d2site 0 595
22932fail 18
22933end
22934cp_post 0 0 12
22935epi
22936end
22937j = ulong 0
22938n = get nt 0
22939go = true
22940while go
22941m = ulong 0
22942while and go lt m 999999
22943if ge j n
22944go = false
22945else
22946xpatch get a_ar add get a_rb 44 j get oc 0
22947if eq get progmode 0 0
22948note Bare units reserve physical R12/R14: recovery stack and immutable runtime table.
22949note Host helpers clobber these registers and must remain forbidden in bare units.
22950emitb 190
22951xword get a_ar add get a_rb 45 j
22952xb 65 255 102
22953emitb 16
22954else
22955if eq get xtarget 0 2
22956ximm 0 or 9223372036854775808 add 100 a_g 45 j
22957else
22958ximm 0 add 100 get a_ar add get a_rb 45 j
22959end
22960xleave
22961end
22962j = add j 1
22963end
22964m = add m 1
22965end
22966end
22967put curret 0 0
22968nm_set get nglob 0
22969put curfn 0 0
22970put nbrk 0 0
22971put ncont 0 0
22972end
22973
22974fn xlead to void
22975note Only the exact bytes "target " at offset zero select x86. Default parsing is untouched.
22976if lt get inlen 0 8
22977ret
22978end
22979if or ne a_ib 0 116 ne a_ib 1 97
22980ret
22981end
22982if or ne a_ib 2 114 ne a_ib 3 103
22983ret
22984end
22985if or ne a_ib 4 101 ne a_ib 5 116
22986ret
22987end
22988if ne uchar and shr get a_ar 0 48 255 32
22989ret
22990end
22991put cur 0 0
22992put line 0 1
22993tok
22994tok
22995if and eq get tw 0 8679965255892613240 eq get tl 0 8
22996put xtarget 0 1
22997else
22998if and eq get tw 0 115888505632888 eq get tl 0 6
22999put xtarget 0 2
23000else
23001if and eq get tw 0 115888505501281 eq get tl 0 6
23002put xefa 0 1
23003else
23004note d2site 596|xlead: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition otherwise: if and eq get tw 0 115888505501281 eq get tl 0 6
23005put d2site 0 596
23006fail 25
23007end
23008end
23009end
23010eol
23011p = ulong 0
23012while lt p get cur 0
23013if ne uchar and shr get a_ar shr p 3 shl and p 7 3 255 10
23014a_bput 0 p 32
23015end
23016p = add p 1
23017end
23018put cur 0 0
23019put line 0 1
23020end
23021
23022
23023fn xeof to void
23024f = findfn 1852399981 4 0
23025if eq f 0
23026note d2site 597|xeof: syntax: unknown or misplaced word; condition if eq f 0
23027put d2site 0 597
23028fail 16
23029end
23030if ne uchar get a_ar add get a_rb 24 sub f 1 0
23031note d2site 598|xeof: word or declaration in a place that does not allow it; condition if ne uchar get a_ar add get a_rb 24 sub f 1 0
23032put d2site 0 598
23033fail 9
23034end
23035entry = get oc 0
23036efi = eq get xtarget 0 2
23037if efi
23038xefx 0 0
23039else
23040xrr 137 13 4
23041ximm 15 268435456
23042ximm 4 276824064
23043ximm 5 0
23044end
23045emitb 232
23046p = get oc 0
23047xword sub get a_ar add get a_rb 22 sub f 1 add p 4
23048if eq uchar get a_ar add get a_rb 23 sub f 1 12
23049ximm 0 0
23050end
23051xleave
23052if efi
23053xefx 1 0
23054xefx 2 entry
23055else
23056elfhdr
23057wrword 16 4063234
23058wrword 24 add 4194304 entry
23059wrword 96 get oc 0
23060wrword 104 get oc 0
23061wrword 160 add get poolb 0 8388608
23062end
23063i = ulong 0
23064go = true
23065while go
23066m = ulong 0
23067while and go lt m 999999
23068if ge i get xnaddr 0
23069go = false
23070else
23071p = get a_ar add get a_rb 46 i
23072v = get a_ar add get a_rb 47 i
23073if efi
23074note PE: code RVA = file offset + 3584; static data lives in the bss section at xbss.
23075if ge v 268435456
23076v = add get xbss 0 sub v 268435456
23077else
23078v = add sub v 4194304 3584
23079end
23080p = add p 3584
23081else
23082v = sub v 4194304
23083end
23084wrword a_g 46 i sub v add p 4
23085i = add i 1
23086end
23087m = add m 1
23088end
23089end
23090writeout 0
23091end
23092
23093note ======== x86efi: UEFI 2.10 PE32+ application (docs/X86-EFI.md) ========
23094note efi OP ARG A OFF N -> ulong EFI_STATUS or result. OP is a literal 0..14; A is writable uchar
23095note storage, bounds checked before any firmware call; ARG is never a pointer. Errors are 2^63|code.
23096note Private state occupies the first 16 KiB of the PE .bss, below the owned 8 MiB stack. Firmware is
23097note called per UEFI 2.3.4.2: RCX/RDX/R8/R9, 32-byte home area, an 80-byte 16-aligned reservation.
23098note Language values stay in RBP slots, so integers and floats survive every firmware call.
23099note Port of the Allen x86efi fork (operations 0..11) onto main's backend; 12, 13 and 14 are new.
23100
23101note xp k: 0 LEA r,private+off; 1 load r from private+off; 2 store r to private+off (via R10);
23102note 3 call BootServices+off (R11); 4 call method off of the protocol held in private slot r (RCX = This).
23103fn xp k ulong r ulong off ulong to void
23104if eq k 0
23105xaddr r add 268435456 off
23106ret
23107end
23108if eq k 1
23109xaddr r add 268435456 off
23110xmem 139 r r 0
23111ret
23112end
23113if eq k 2
23114xaddr 10 add 268435456 off
23115xmem 137 r 10 0
23116ret
23117end
23118if eq k 3
23119xaddr 11 268435456
23120xmem 139 11 11 0
23121xmem 139 11 11 96
23122xmem 139 11 11 off
23123xb 65 255 211
23124ret
23125end
23126xaddr 1 add 268435456 r
23127xmem 139 1 1 0
23128xmem 139 11 1 off
23129xb 65 255 211
23130end
23131
23132note xer k: 0 branch on cc to an error tail that returns 2^63|code; 1 jump to the operation's end;
23133note 2 RDTSC into RAX (Intel SDM: LFENCE before and after serializes local instruction execution).
23134fn xer k ulong cc ulong code ulong to void
23135if eq k 2
23136xb 15 174 232
23137emitb 15
23138emitb 49
23139xb 15 174 232
23140xb 72 193 226
23141emitb 32
23142xrr 9 0 2
23143ret
23144end
23145if eq k 0
23146n = get xenerr 0
23147if ge n 256
23148note d2site 599|xer: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge n 256
23149put d2site 0 599
23150fail 14
23151end
23152put xerrpos n xbranch cc
23153put xerrcode n code
23154put xenerr 0 add n 1
23155ret
23156end
23157m = get xenend 0
23158if ge m 256
23159note d2site 600|xer: capacity exceeded (the host refused to grow the compiler's arena or its memory ceiling OMC_MEMORY_MAX was reached, value nesting past omc's own stack, the program image, or an OM-2 expansion bound); condition if ge m 256
23160put d2site 0 600
23161fail 14
23162end
23163put xendpos m xbranch 14
23164put xenend 0 add m 1
23165end
23166
23167note xg k: inline constant data skipped by a jump; returns its address for xaddr. k 0..7 a UEFI GUID
23168note packed Data1|Data2<<32|Data3<<48 then Data4 little-endian (0 GOP, 1 SNP, 2 RNG, 3 simple pointer,
23169note 4 absolute pointer, 5 Simple File System, 6 LoadedImage, 7 FileInfo, 9 SMBIOS3 table, 10 SMBIOS
23170note table); 8 UCS-2 \EFI\BOOT\BOOTX64.EFI.
23171fn xg k ulong to ulong
23172br = xbranch 14
23173p = get oc 0
23174if eq k 8
23175xb 92 0 69
23176xb 0 70 0
23177xb 73 0 92
23178xb 0 66 0
23179xb 79 0 79
23180xb 0 84 0
23181xb 92 0 66
23182xb 0 79 0
23183xb 79 0 84
23184xb 0 88 0
23185xb 54 0 52
23186xb 0 46 0
23187xb 69 0 70
23188xb 0 73 0
23189emitb 0
23190emitb 0
23191else
23192a = ulong 5348063987722529246
23193b = ulong 7661046075708078998
23194if eq k 1
23195a = ulong 1284559596355596985
23196b = ulong 5602828850577812890
23197end
23198if eq k 2
23199a = ulong 4845287014151666853
23200b = ulong 4908688144209030790
23201end
23202if eq k 3
23203a = ulong 1284945866654190727
23204b = ulong 5602828850577821594
23205end
23206if eq k 4
23207a = ulong 5398063699126244139
23208b = ulong 4839848993530975643
23209end
23210if eq k 5
23211a = ulong 1284199179690597154
23212b = ulong 4283602510276475278
23213end
23214if eq k 6
23215a = ulong 1284253093421855137
23216b = ulong 4283602510276476814
23217end
23218if eq k 7
23219a = ulong 1284208961261104786
23220b = ulong 4283602510276475278
23221end
23222if eq k 9
23223a = ulong 5344813523769562436
23224b = ulong 10728454813909331609
23225end
23226if eq k 10
23227a = ulong 1284420384822471985
23228b = ulong 5602828850577807002
23229end
23230xword a
23231xword shr a 32
23232xword b
23233xword shr b 32
23234end
23235xpatch br get oc 0
23236ret add p 4194304
23237end
23238
23239note xe k: 2 close the operation (error tails, then the shared end); 3 need N >= a (5); 4 need the
23240note protocol in private slot a (3); 5 leave on a firmware error; 7 OR a into the info flags at A+4;
23241note 8 LocateProtocol GUID a into slot b; 9 calibrate TSC ticks/ms over a 100 ms Stall (176, base 168);
23242note 10 settle the transmit buffer at exit (status 88); 12 elapsed milliseconds into A.
23243fn xe k ulong a ulong b ulong to void
23244if eq k 2
23245xer 1 0 0
23246j = ulong 0
23247while lt j get xenerr 0
23248xpatch get xerrpos j get oc 0
23249ximm 0 or 9223372036854775808 get xerrcode j
23250xer 1 0 0
23251j = add j 1
23252end
23253i = ulong 0
23254while lt i get xenend 0
23255xpatch get xendpos i get oc 0
23256i = add i 1
23257end
23258ret
23259end
23260if eq k 3
23261ximm 0 a
23262xrr 57 13 0
23263xer 0 3 5
23264ret
23265end
23266if eq k 4
23267xp 1 1 a
23268xrr 133 1 1
23269xer 0 0 3
23270ret
23271end
23272if eq k 5
23273xrr 133 0 0
23274ok = xbranch 0
23275xleave
23276xpatch ok get oc 0
23277ret
23278end
23279if eq k 7
23280xhraw 0 12 4 4
23281ximm 2 a
23282xrr 9 0 2
23283xhput 0 12 4 4
23284ret
23285end
23286if eq k 8
23287g = xg a
23288xaddr 1 g
23289ximm 2 0
23290xp 0 8 b
23291xp 3 0 320
23292note LocateProtocol is optional. Failed output is discarded, never dereferenced.
23293xrr 133 0 0
23294ok8 = xbranch 0
23295ximm 0 0
23296xp 2 0 b
23297xpatch ok8 get oc 0
23298ret
23299end
23300if eq k 9
23301xer 2 0 0
23302xp 2 0 160
23303ximm 1 100000
23304xp 3 0 248
23305xrr 133 0 0
23306ok9 = xbranch 0
23307xleave
23308xpatch ok9 get oc 0
23309xer 2 0 0
23310xp 1 1 160
23311xrr 41 0 1
23312mono = xbranch 3
23313ximm 1 100
23314ximm 2 0
23315xb 72 247 241
23316xp 2 0 176
23317xer 2 0 0
23318xp 2 0 168
23319xpatch mono get oc 0
23320ret
23321end
23322if eq k 10
23323xp 1 1 96
23324xrr 133 1 1
23325none = xbranch 0
23326xp 1 0 72
23327xrr 133 0 0
23328idle = xbranch 0
23329ximm 0 0
23330xp 2 0 80
23331ximm 2 0
23332xp 0 8 80
23333xp 4 24 88
23334xp 1 0 80
23335xp 1 2 96
23336xrr 57 0 2
23337busy = xbranch 1
23338xpatch idle get oc 0
23339xp 1 1 96
23340xp 3 0 72
23341xrr 133 0 0
23342freed = xbranch 0
23343xp 2 0 88
23344xpatch freed get oc 0
23345fin = xbranch 14
23346xpatch busy get oc 0
23347note Do not free or reuse an unreturned DMA buffer. Expose NOT_READY on exit.
23348ximm 0 9223372036854775814
23349xp 2 0 88
23350xpatch fin get oc 0
23351xpatch none get oc 0
23352ret
23353end
23354xp 1 1 176
23355xrr 133 1 1
23356xer 0 0 3
23357xer 2 0 0
23358xp 1 2 168
23359xrr 41 0 2
23360xer 0 3 3
23361ximm 2 0
23362xb 72 247 241
23363xmem 137 0 12 0
23364ximm 0 0
23365end
23366
23367note xefx k: 0 image entry, 1 the shared firmware return (every exit site lands here), 2 PE32+ headers.
23368fn xefx k ulong a ulong to void
23369if eq k 0
23370note Preserve the integer nonvolatiles, MXCSR and XMM6-15 (UEFI 2.3.4.2), then install the owned stack.
23371emitb 83
23372emitb 85
23373emitb 86
23374emitb 87
23375xb 65 84 65
23376emitb 85
23377xb 65 86 65
23378emitb 87
23379xp 2 4 2048
23380xp 2 1 8
23381xp 2 2 0
23382xp 0 10 2056
23383xb 65 15 174
23384emitb 26
23385xp 0 10 2080
23386j = ulong 6
23387while lt j 16
23388emitb 243
23389emitb uchar add 65 mul shr j 3 4
23390xb 15 127 add 130 shl and j 7 3
23391xword mul sub j 6 16
23392j = add j 1
23393end
23394note MXCSR 0x1F80: all exceptions masked, round to nearest, as on x86 Linux.
23395ximm 0 8064
23396xp 2 0 2064
23397xp 0 10 2064
23398xb 65 15 174
23399emitb 18
23400xp 0 15 16384
23401xp 0 4 8388608
23402ximm 5 0
23403note Entry has its own 80-byte EFI home/argument reservation, not an Omega frame.
23404xb 72 129 236
23405xword 80
23406ximm 1 0
23407ximm 2 0
23408ximm 8 0
23409ximm 9 0
23410xp 3 0 256
23411xe 5 0 0
23412note TX storage outlives the image if firmware fails to release an in-flight packet.
23413ximm 1 2
23414ximm 2 2048
23415xp 0 8 96
23416xp 3 0 64
23417xe 5 0 0
23418xe 8 0 16
23419xe 8 2 32
23420xe 8 3 40
23421xe 8 4 48
23422note Intel SDM 20.17.1 invariant TSC, CPUID.80000007H:EDX[8]; otherwise calibrate lazily (op 10).
23423ximm 0 1
23424emitb 15
23425emitb 162
23426ximm 0 16
23427xrr 33 2 0
23428xrr 133 2 2
23429no1 = xbranch 0
23430ximm 0 2147483648
23431emitb 15
23432emitb 162
23433ximm 2 2147483655
23434xrr 57 0 2
23435no2 = xbranch 3
23436ximm 0 2147483655
23437emitb 15
23438emitb 162
23439ximm 0 256
23440xrr 33 2 0
23441xrr 133 2 2
23442no3 = xbranch 0
23443xe 9 0 0
23444xpatch no1 get oc 0
23445xpatch no2 get oc 0
23446xpatch no3 get oc 0
23447xb 72 129 196
23448xword 80
23449ret
23450end
23451if eq k 1
23452i = ulong 0
23453go = true
23454while go
23455m = ulong 0
23456while and go lt m 999999
23457if ge i get xnexit 0
23458go = false
23459else
23460xpatch a_g 48 i get oc 0
23461i = add i 1
23462end
23463m = add m 1
23464end
23465end
23466note Restore a known-good private stack even when an Omega stack check failed.
23467xp 0 4 8388608
23468xb 72 129 236
23469xword 80
23470xp 2 0 88
23471note An efi 12 file still open at exit (return, exit or trap) is flushed when writable, then the file
23472note and its volume root are closed and the slot cleared, as a process exit closes descriptors.
23473xp 1 1 2304
23474xrr 133 1 1
23475p1 = xbranch 0
23476xp 1 0 2320
23477xrr 133 0 0
23478p2 = xbranch 0
23479xp 4 2304 80
23480xpatch p2 get oc 0
23481xp 4 2304 16
23482xpatch p1 get oc 0
23483xp 1 1 2312
23484xrr 133 1 1
23485p3 = xbranch 0
23486xp 4 2312 16
23487xpatch p3 get oc 0
23488ximm 0 0
23489xp 2 0 2304
23490xp 2 0 2312
23491xp 2 0 2320
23492xe 10 0 0
23493xp 0 10 2080
23494r = ulong 6
23495while lt r 16
23496emitb 243
23497emitb uchar add 65 mul shr r 3 4
23498xb 15 111 add 130 shl and r 7 3
23499xword mul sub r 6 16
23500r = add r 1
23501end
23502xp 0 10 2056
23503xb 65 15 174
23504emitb 18
23505xp 1 0 88
23506xp 1 11 2048
23507xrr 137 4 11
23508xb 65 95 65
23509emitb 94
23510xb 65 93 65
23511emitb 92
23512emitb 95
23513emitb 94
23514emitb 93
23515emitb 91
23516emitb 195
23517ret
23518end
23519note PE32+ UEFI application. Section/file alignment 4096/512; every address is RIP-relative, so the
23520note image is position independent. A valid empty relocation block keeps loader relocation support.
23521while ne and get oc 0 511 0
23522emitb 0
23523end
23524raw = sub get oc 0 512
23525bs = shl shr add add raw 4096 4095 12 12
23526put xbss 0 bs
23527wrword 0 23117
23528wrword 60 64
23529wrword 64 17744
23530wrword 68 165476
23531wrword 84 2228464
23532wrword 88 523
23533wrword 92 raw
23534wrword 100 add get poolb 0 8388608
23535wrword 104 add a 3584
23536wrword 108 4096
23537wrword 112 4194304
23538wrword 120 4096
23539wrword 124 512
23540wrword 128 6
23541wrword 136 6
23542wrword 144 shl shr add add bs add get poolb 0 8388608 4095 12 12
23543wrword 148 512
23544wrword 156 4194314
23545wrword 160 1048576
23546wrword 168 4096
23547wrword 176 1048576
23548wrword 184 4096
23549wrword 196 16
23550wrword 512 0
23551wrword 516 8
23552note Base relocation directory points to the first eight bytes of .text, reserved by the driver.
23553wrword 240 4096
23554wrword 244 8
23555wrword 328 2019914798
23556wrword 332 116
23557wrword 336 raw
23558wrword 340 4096
23559wrword 344 raw
23560wrword 348 512
23561wrword 364 1610612768
23562wrword 368 1936941614
23563wrword 376 add get poolb 0 8388608
23564wrword 380 bs
23565wrword 404 3221225600
23566end
23567
23568fn xefival dst ulong to void
23569if ne get xtarget 0 2
23570note d2site 601|xefival: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne get xtarget 0 2
23571put d2site 0 601
23572fail 25
23573end
23574x = mul get depth 0 32
23575put a_ar add get a_rb 77 add x 7 get nslot 0
23576op = lenval 4
23577if gt op 14
23578note d2site 602|xefival: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if gt op 14
23579put d2site 0 602
23580fail 25
23581end
23582harg x 2 5
23583e = harray x 1
23584note RBX anchors the snapshot only until ARG is loaded; firmware-preserved R14 carries it across the call
23585note (UEFI 2.3.4.2), and the caller's R14 waits in the snapshot tail beside R13.
23586xhbegin
23587xmem 137 14 3 152
23588xrr 137 14 3
23589xhb 12 e get a_ar add get a_rb 77 add x 21
23590xhs 13 get a_ar add get a_rb 77 add x 22
23591xha x 2 3
23592note Firmware runs on the owned stack: reserve 64 KiB (trap 6), then align RSP for UEFI 2.3.4.2.
23593xcheck 65536
23594xb 72 131 228
23595emitb 240
23596xb 72 129 236
23597xword 80
23598put xenerr 0 0
23599put xenend 0 0
23600xeop op
23601xe 2 0 0
23602xrr 137 4 14
23603xmem 139 13 4 144
23604xmem 139 14 4 152
23605r = restore dst a_g 77 add x 7 get svn 0 get sva 0 1
23606vdone 1 r 5
23607end
23608
23609note Operation registers: RBX = ARG, R12 = A+OFF, R13 = N; the result or error is RAX.
23610fn xeop op ulong to void
23611if eq op 1
23612xe 3 4 0
23613xp 1 1 0
23614xmem 139 1 1 48
23615xrr 133 1 1
23616xer 0 0 3
23617xrr 137 2 12
23618xmem 139 11 1 8
23619xb 65 255 211
23620ret
23621end
23622if eq op 2
23623xrr 137 1 3
23624xp 3 0 248
23625ret
23626end
23627if eq op 4
23628xe 3 16 0
23629xp 1 11 0
23630xmem 139 11 11 88
23631xmem 139 11 11 24
23632xrr 137 1 12
23633ximm 2 0
23634xb 65 255 211
23635ret
23636end
23637if eq op 8
23638xenet
23639ret
23640end
23641if eq op 10
23642xe 3 8 0
23643xp 1 1 176
23644xrr 133 1 1
23645ok = xbranch 1
23646xe 9 0 0
23647xpatch ok get oc 0
23648xe 12 0 0
23649ret
23650end
23651if eq op 11
23652xefile
23653ret
23654end
23655if eq op 12
23656xf12
23657ret
23658end
23659if eq op 14
23660xf14
23661ret
23662end
23663xdev op
23664end
23665
23666note efi 14 machine identity; ARG bits 0..15 sub, 16..63 its parameter. Sub 0: CPUID leaf ARG>>16
23667note (below 2^32, else 32) with ECX 0, EAX EBX ECX EDX as four u32 at A+OFF (N >= 16, else 5),
23668note result 16. ARG 1: the UCS-2 code units of SystemTable FirmwareVendor (+24) up to its NUL, at
23669note most N bytes in whole units, result bytes copied (0 when the pointer is NULL). ARG 2: result
23670note FirmwareRevision (+32). Sub 3: SMBIOS structure table bytes from position ARG>>16 into A
23671note (at most N), result bytes copied, 0 at or past the end. The table comes from the configuration
23672note table: the SMBIOS3 entry point (_SM3_, size u32 @12, address u64 @16) first, else SMBIOS 2.x
23673note (_SM_, length u16 @22, address u32 @24); 44 when neither is there, an anchor is wrong or the
23674note address is 0. Any other ARG is 32. Nothing is written past A+OFF+N.
23675fn xf14 to void
23676ximm 0 1
23677xrr 57 3 0
23678p = xbranch 1
23679xp 1 1 0
23680xmem 139 6 1 24
23681ximm 0 0
23682xrr 137 7 12
23683xrr 137 9 13
23684xrr 133 6 6
23685z = xbranch 0
23686loop = get oc 0
23687ximm 2 2
23688xrr 57 9 2
23689d1 = xbranch 3
23690xhraw 2 6 0 2
23691xrr 133 2 2
23692d2 = xbranch 0
23693xhput 2 7 0 2
23694xb 72 131 198
23695emitb 2
23696xb 72 131 199
23697emitb 2
23698xb 72 131 192
23699emitb 2
23700xb 73 131 233
23701emitb 2
23702q = xbranch 14
23703xpatch q loop
23704xpatch z get oc 0
23705xpatch d1 get oc 0
23706xpatch d2 get oc 0
23707xer 1 0 0
23708xpatch p get oc 0
23709ximm 0 2
23710xrr 57 3 0
23711p = xbranch 1
23712xp 1 1 0
23713xhraw 0 1 32 4
23714xer 1 0 0
23715xpatch p get oc 0
23716xrr 137 6 3
23717ximm 0 65535
23718xrr 33 6 0
23719p = xbranch 1
23720xe 3 16 0
23721xrr 137 0 3
23722xb 72 193 232
23723emitb 16
23724xrr 137 2 0
23725xb 72 193 234
23726emitb 32
23727xrr 133 2 2
23728xer 0 1 32
23729ximm 1 0
23730emitb 15
23731emitb 162
23732xhput 0 12 0 4
23733xhput 3 12 4 4
23734xhput 1 12 8 4
23735xhput 2 12 12 4
23736ximm 0 16
23737xer 1 0 0
23738xpatch p get oc 0
23739ximm 0 3
23740xrr 57 6 0
23741xer 0 1 32
23742xp 1 1 0
23743xmem 139 8 1 104
23744xmem 139 9 1 112
23745f3 = ulong 0
23746f = ulong 0
23747g = ulong 9
23748while le g 10
23749xaddr 10 xg g
23750xrr 137 11 9
23751xrr 137 1 8
23752loop = get oc 0
23753xrr 133 1 1
23754miss = xbranch 0
23755xmem 139 0 11 0
23756xmem 59 0 10 0
23757n1 = xbranch 1
23758xmem 139 0 11 8
23759xmem 59 0 10 8
23760n2 = xbranch 1
23761xmem 139 6 11 16
23762f = xbranch 14
23763xpatch n1 get oc 0
23764xpatch n2 get oc 0
23765xb 73 131 195
23766emitb 24
23767xb 72 131 233
23768emitb 1
23769q = xbranch 14
23770xpatch q loop
23771xpatch miss get oc 0
23772if eq g 9
23773f3 = f
23774end
23775g = add g 1
23776end
23777xer 0 14 44
23778xpatch f get oc 0
23779xrr 133 6 6
23780xer 0 0 44
23781xhraw 0 6 0 4
23782ximm 2 1598903135
23783xrr 57 0 2
23784xer 0 1 44
23785xhraw 8 6 22 2
23786xhraw 6 6 24 4
23787cp = xbranch 14
23788xpatch f3 get oc 0
23789xrr 133 6 6
23790xer 0 0 44
23791xhraw 0 6 0 4
23792ximm 2 860705631
23793xrr 57 0 2
23794xer 0 1 44
23795xhraw 8 6 12 4
23796xmem 139 6 6 16
23797xpatch cp get oc 0
23798xrr 133 6 6
23799xer 0 0 44
23800xrr 137 2 3
23801xb 72 193 234
23802emitb 16
23803ximm 0 0
23804xrr 57 2 8
23805done = xbranch 2
23806xrr 137 1 8
23807xrr 41 1 2
23808xrr 57 1 13
23809ok = xbranch 9
23810xrr 137 1 13
23811xpatch ok get oc 0
23812xrr 1 6 2
23813xrr 137 7 12
23814xrr 137 0 1
23815emitb 252
23816emitb 243
23817emitb 164
23818xpatch done get oc 0
23819end
23820
23821note Device operations: 0 info, 3 GOP Blt, 5 entropy, 6 receive, 7 transmit, 9 pointer, 13 console.
23822note OP0 info, 64 bytes: u32 version=1, flags (1 GOP, 2 net, 4 RNG, 8 pointer), u32 width/height@8,
23823note pixelFormat@16, stride@20, MAC[6]@24, maxPacket@32, hwAddrSize@36, media@40, state@44, txBusy@48.
23824note OP3 ARG: width bits0..31, height bits32..47, destination row bits48..63 (UEFI 12.9.2 Blt).
23825fn xdev op ulong to void
23826if eq op 0
23827xe 3 64 0
23828ximm 0 0
23829j = ulong 0
23830while lt j 64
23831xmem 137 0 12 j
23832j = add j 8
23833end
23834ximm 0 1
23835xmem 137 0 12 0
23836xp 1 1 16
23837xrr 133 1 1
23838p = xbranch 0
23839xmem 139 1 1 24
23840xrr 133 1 1
23841z1 = xbranch 0
23842xmem 139 1 1 8
23843xrr 133 1 1
23844z2 = xbranch 0
23845xmem 139 0 1 4
23846xmem 137 0 12 8
23847xhraw 0 1 12 4
23848xhput 0 12 16 4
23849xhraw 0 1 32 4
23850xhput 0 12 20 4
23851ximm 0 1
23852xhput 0 12 4 4
23853xpatch p get oc 0
23854xp 1 1 24
23855xrr 133 1 1
23856p = xbranch 0
23857xmem 139 1 1 120
23858xrr 133 1 1
23859z3 = xbranch 0
23860xhraw 0 1 552 4
23861xhput 0 12 24 4
23862xhraw 0 1 556 2
23863xhput 0 12 28 4
23864xhraw 0 1 12 4
23865xhput 0 12 32 4
23866xhraw 0 1 4 4
23867xhput 0 12 36 4
23868xhraw 0 1 652 1
23869xhput 0 12 40 4
23870xhraw 0 1 0 4
23871xhput 0 12 44 4
23872xp 1 0 72
23873xhput 0 12 48 4
23874xe 7 2 0
23875xpatch p get oc 0
23876xp 1 1 32
23877xrr 133 1 1
23878p = xbranch 0
23879xe 7 4 0
23880xpatch p get oc 0
23881xp 1 1 40
23882xp 1 2 48
23883xrr 9 1 2
23884xrr 133 1 1
23885p = xbranch 0
23886xe 7 8 0
23887xpatch p get oc 0
23888xpatch z1 get oc 0
23889xpatch z2 get oc 0
23890xpatch z3 get oc 0
23891ximm 0 0
23892ret
23893end
23894if eq op 3
23895xe 4 16 0
23896xrr 137 8 3
23897xb 73 193 232
23898emitb 32
23899ximm 0 65535
23900xrr 33 8 0
23901xrr 137 10 3
23902xb 73 193 234
23903emitb 48
23904xrr 137 9 3
23905ximm 0 4294967295
23906xrr 33 9 0
23907xrr 133 8 8
23908xer 0 0 2
23909xrr 133 9 9
23910xer 0 0 2
23911xmem 139 2 1 24
23912xrr 133 2 2
23913xer 0 0 2
23914xmem 139 2 2 8
23915xrr 133 2 2
23916xer 0 0 2
23917xhraw 0 2 4 4
23918xrr 57 9 0
23919xer 0 8 2
23920xhraw 0 2 8 4
23921xrr 41 0 10
23922xer 0 3 2
23923xrr 57 8 0
23924xer 0 8 2
23925xrr 137 0 8
23926xb 73 15 175
23927emitb 193
23928xb 72 193 224
23929emitb 2
23930xrr 57 0 13
23931xer 0 1 2
23932xmem 137 9 4 56
23933xmem 137 8 4 64
23934ximm 0 0
23935xmem 137 0 4 32
23936xmem 137 0 4 40
23937xmem 137 10 4 48
23938xmem 137 0 4 72
23939xrr 137 2 12
23940ximm 8 2
23941ximm 9 0
23942xp 4 16 16
23943ret
23944end
23945if eq op 5
23946note RNG protocol when present; else Intel SDM RDRAND (CPUID.1:ECX[30], CF = valid), ten attempts
23947note per byte, then EFI_NOT_READY, never fallback data.
23948xp 1 1 32
23949xrr 133 1 1
23950p = xbranch 0
23951ximm 2 0
23952xrr 137 8 13
23953xrr 137 9 12
23954xp 4 32 8
23955xer 1 0 0
23956xpatch p get oc 0
23957ximm 0 0
23958emitb 15
23959emitb 162
23960ximm 2 1
23961xrr 57 0 2
23962xer 0 3 3
23963ximm 0 1
23964emitb 15
23965emitb 162
23966ximm 2 1073741824
23967xrr 33 1 2
23968xrr 133 1 1
23969xer 0 0 3
23970xrr 137 7 12
23971xrr 137 6 13
23972lp = get oc 0
23973xrr 133 6 6
23974q = xbranch 0
23975ximm 1 10
23976rw = get oc 0
23977xb 72 15 199
23978emitb 240
23979s = xbranch 3
23980xb 72 255 201
23981p = xbranch 1
23982xpatch p rw
23983xer 0 14 6
23984xpatch s get oc 0
23985emitb 136
23986emitb 7
23987xb 72 255 199
23988xb 72 255 206
23989back lp
23990xpatch q get oc 0
23991ximm 0 0
23992ret
23993end
23994if eq op 6
23995xe 3 9 0
23996xe 4 24 0
23997xrr 137 0 13
23998xb 72 131 232
23999emitb 8
24000xmem 137 0 12 0
24001ximm 2 0
24002xrr 137 8 12
24003xmem 141 9 12 8
24004ximm 0 0
24005xmem 137 0 4 32
24006xmem 137 0 4 40
24007xmem 137 0 4 48
24008xp 4 24 104
24009ret
24010end
24011if eq op 7
24012note Transmit always owns its private packet until GetStatus reclaims that exact address (UEFI 24.1.12).
24013xe 4 24 0
24014xe 3 14 0
24015ximm 0 2048
24016xrr 57 13 0
24017xer 0 8 4
24018xp 1 0 72
24019xrr 133 0 0
24020p = xbranch 0
24021ximm 0 0
24022xp 2 0 80
24023ximm 2 0
24024xp 0 8 80
24025xp 4 24 88
24026xrr 133 0 0
24027xer 0 1 6
24028xp 1 0 80
24029xp 1 2 96
24030xrr 57 0 2
24031xer 0 1 6
24032ximm 0 0
24033xp 2 0 72
24034xpatch p get oc 0
24035xrr 137 6 12
24036xp 1 7 96
24037xrr 137 1 13
24038emitb 252
24039emitb 243
24040emitb 164
24041ximm 2 0
24042xrr 137 8 13
24043xp 1 9 96
24044ximm 0 0
24045xmem 137 0 4 32
24046xmem 137 0 4 40
24047xmem 137 0 4 48
24048xp 4 24 96
24049xrr 133 0 0
24050p = xbranch 1
24051ximm 2 1
24052xp 2 2 72
24053xpatch p get oc 0
24054ret
24055end
24056if eq op 9
24057xe 3 32 0
24058xp 1 1 40
24059xrr 133 1 1
24060q = xbranch 0
24061xp 0 2 256
24062xp 4 40 8
24063xrr 133 0 0
24064p = xbranch 1
24065xp 0 2 256
24066ximm 0 1
24067xmem 137 0 12 0
24068xhraw 0 2 12 1
24069xhraw 1 2 13 1
24070xb 72 193 225
24071emitb 1
24072xrr 9 0 1
24073xhput 0 12 4 4
24074i = ulong 0
24075while lt i 3
24076note MOVSXD rax,dword [rdx+disp32], Intel MOVSX/MOVSXD.
24077xb 72 99 130
24078xword mul i 4
24079xmem 137 0 12 add 8 mul i 8
24080i = add i 1
24081end
24082ximm 0 0
24083xpatch p get oc 0
24084xer 1 0 0
24085xpatch q get oc 0
24086xe 4 48 0
24087xp 0 2 256
24088xp 4 48 8
24089xrr 133 0 0
24090p = xbranch 1
24091xp 0 2 256
24092ximm 0 2
24093xmem 137 0 12 0
24094xhraw 0 2 24 4
24095xhput 0 12 4 4
24096i = ulong 0
24097while lt i 3
24098xmem 139 0 2 mul i 8
24099xmem 137 0 12 add 8 mul i 8
24100i = add i 1
24101end
24102ximm 0 0
24103xpatch p get oc 0
24104ret
24105end
24106if ne op 13
24107note d2site 603|xdev: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if ne op 13
24108put d2site 0 603
24109fail 25
24110end
24111note efi 13: write A[OFF..OFF+N) to ConOut (UEFI 12.4 OutputString). ARG must be 0; only bytes 9, 10,
24112note 13 and 32..126, all checked before any output; LF becomes CR LF; UCS-2 chunks of at most 255
24113note characters in private 4096. Warnings (bit 63 clear) are not errors. Result N.
24114xrr 133 3 3
24115xer 0 1 32
24116xrr 137 8 12
24117xrr 137 9 13
24118lp = get oc 0
24119xrr 133 9 9
24120p = xbranch 0
24121xhraw 0 8 0 1
24122ximm 2 9
24123xrr 57 0 2
24124q = xbranch 0
24125ximm 2 10
24126xrr 57 0 2
24127rw = xbranch 0
24128ximm 2 13
24129xrr 57 0 2
24130s = xbranch 0
24131ximm 2 32
24132xrr 57 0 2
24133xer 0 3 42
24134ximm 2 126
24135xrr 57 0 2
24136xer 0 8 42
24137xpatch q get oc 0
24138xpatch rw get oc 0
24139xpatch s get oc 0
24140xb 73 131 192
24141emitb 1
24142xb 73 131 233
24143emitb 1
24144back lp
24145xpatch p get oc 0
24146note ConOut (SystemTable+64) may be NULL on headless firmware: refuse with 43 before any call.
24147xp 1 1 0
24148xmem 139 1 1 64
24149xrr 133 1 1
24150xer 0 0 43
24151xrr 137 6 12
24152xrr 137 3 13
24153ximm 7 0
24154lp = get oc 0
24155xrr 133 3 3
24156p = xbranch 0
24157ximm 0 254
24158xrr 57 7 0
24159q = xbranch 3
24160xpatch p get oc 0
24161xrr 133 7 7
24162rw = xbranch 0
24163xp 0 10 4096
24164xrr 137 11 7
24165xrr 1 11 11
24166xrr 1 10 11
24167ximm 0 0
24168xhput 0 10 0 2
24169xp 1 1 0
24170xmem 139 1 1 64
24171xp 0 2 4096
24172xmem 139 11 1 8
24173xb 65 255 211
24174xrr 133 0 0
24175xer 0 11 43
24176ximm 7 0
24177xpatch rw get oc 0
24178xrr 133 3 3
24179s = xbranch 0
24180xpatch q get oc 0
24181xp 0 10 4096
24182xrr 137 11 7
24183xrr 1 11 11
24184xrr 1 10 11
24185xhraw 0 6 0 1
24186ximm 2 10
24187xrr 57 0 2
24188p = xbranch 1
24189ximm 0 13
24190xhput 0 10 0 2
24191ximm 0 10
24192xhput 0 10 2 2
24193xb 72 131 199
24194emitb 1
24195q = xbranch 14
24196xpatch p get oc 0
24197xhput 0 10 0 2
24198xpatch q get oc 0
24199xb 72 131 199
24200emitb 1
24201xb 72 131 198
24202emitb 1
24203xb 72 131 235
24204emitb 1
24205back lp
24206xpatch s get oc 0
24207xrr 137 0 13
24208end
24209
24210note UEFI 24.1 SNP mode: MAC array capacity 16, 32-byte MAC cells, current@552, IfType@648,
24211note MediaPresentSupported@651, MediaPresent@652. k 0 probe candidate 128 (own error scope);
24212note k 1 reject it: shut down/stop only what this application initialized/started.
24213fn xenpr k ulong to void
24214if eq k 1
24215xp 1 0 144
24216xrr 133 0 0
24217p = xbranch 0
24218xp 4 128 40
24219xpatch p get oc 0
24220xp 1 0 136
24221xrr 133 0 0
24222p = xbranch 0
24223xp 4 128 16
24224xpatch p get oc 0
24225ret
24226end
24227put xenerr 0 0
24228put xenend 0 0
24229ximm 0 0
24230xp 2 0 136
24231xp 2 0 144
24232xp 1 1 128
24233xmem 139 2 1 120
24234xrr 133 2 2
24235xer 0 0 3
24236xhraw 0 2 4 4
24237ximm 8 6
24238xrr 57 0 8
24239xer 0 1 3
24240xhraw 0 2 648 1
24241ximm 8 1
24242xrr 57 0 8
24243xer 0 1 3
24244xhraw 0 2 0 4
24245xrr 133 0 0
24246q = xbranch 1
24247xp 4 128 8
24248xrr 133 0 0
24249xer 0 1 7
24250ximm 0 1
24251xp 2 0 136
24252xpatch q get oc 0
24253xp 1 1 128
24254xmem 139 2 1 120
24255xhraw 0 2 0 4
24256ximm 8 1
24257xrr 57 0 8
24258q = xbranch 1
24259ximm 2 0
24260ximm 8 0
24261xp 4 128 24
24262xrr 133 0 0
24263xer 0 1 7
24264ximm 0 1
24265xp 2 0 144
24266xpatch q get oc 0
24267ximm 2 0
24268ximm 8 0
24269xp 4 128 88
24270xrr 133 0 0
24271xer 0 1 7
24272xp 1 1 128
24273xmem 139 2 1 120
24274xhraw 0 2 0 4
24275ximm 8 2
24276xrr 57 0 8
24277xer 0 1 6
24278note MediaPresent is binding only when the driver says media detection is supported.
24279xhraw 0 2 651 1
24280xrr 133 0 0
24281q = xbranch 0
24282xhraw 0 2 652 1
24283xrr 133 0 0
24284xer 0 0 12
24285xpatch q get oc 0
24286xhraw 0 2 24 4
24287ximm 8 5
24288xrr 33 0 8
24289xrr 57 0 8
24290xer 0 1 3
24291ximm 2 5
24292ximm 8 0
24293ximm 9 0
24294ximm 0 0
24295xmem 137 0 4 32
24296xmem 137 0 4 40
24297xp 4 128 48
24298xe 2 0 0
24299end
24300
24301note UEFI 2.4 7.3 OpenProtocol EXCLUSIVE (32) disconnects MNP and the IP stack above SNP; while they
24302note stay bound, MNP's poll timer drains frames no child wants (aienux#454). Firmware that refuses
24303note keeps the shared HandleProtocol path. All candidates are tried for a live link.
24304fn xenscan g ulong to void
24305ximm 3 0
24306lp = get oc 0
24307xrr 57 3 7
24308ex = xbranch 2
24309xrr 137 0 3
24310xb 72 193 224
24311emitb 3
24312xrr 1 0 6
24313xmem 139 1 0 0
24314xaddr 2 g
24315xp 0 8 128
24316xp 1 9 8
24317ximm 0 0
24318xmem 137 0 4 32
24319ximm 0 32
24320xmem 137 0 4 40
24321xp 3 0 280
24322xrr 133 0 0
24323p = xbranch 0
24324xrr 137 0 3
24325xb 72 193 224
24326emitb 3
24327xrr 1 0 6
24328xmem 139 1 0 0
24329xaddr 2 g
24330xp 0 8 128
24331xp 3 0 152
24332xpatch p get oc 0
24333xrr 133 0 0
24334sk = xbranch 1
24335xenpr 0
24336xrr 133 0 0
24337p = xbranch 1
24338xp 1 0 128
24339xp 2 0 24
24340sel = xbranch 14
24341xpatch p get oc 0
24342xenpr 1
24343xpatch sk get oc 0
24344xb 72 255 195
24345back lp
24346xpatch ex get oc 0
24347ximm 0 9223372036854775822
24348p = xbranch 14
24349xpatch sel get oc 0
24350ximm 0 0
24351xpatch p get oc 0
24352end
24353
24354note OP8: select a live Simple Network Protocol interface once (result 0), or an EFI status.
24355fn xenet to void
24356xp 1 1 24
24357xrr 133 1 1
24358al = xbranch 1
24359g = xg 1
24360ximm 1 2
24361xaddr 2 g
24362ximm 8 0
24363xp 0 9 104
24364xp 0 0 112
24365xmem 137 0 4 32
24366xp 3 0 312
24367xrr 133 0 0
24368lerr = xbranch 1
24369xp 1 6 112
24370xp 1 7 104
24371ximm 0 1024
24372xrr 57 7 0
24373lg = xbranch 8
24374xenscan g
24375sv = xbranch 14
24376xpatch lg get oc 0
24377ximm 0 9223372036854775813
24378xpatch sv get oc 0
24379xp 2 0 152
24380xrr 137 1 6
24381xp 3 0 72
24382xrr 133 0 0
24383fe = xbranch 1
24384xp 1 0 152
24385dn = xbranch 14
24386xpatch al get oc 0
24387ximm 0 0
24388xpatch dn get oc 0
24389xpatch lerr get oc 0
24390xpatch fe get oc 0
24391put xenerr 0 0
24392put xenend 0 0
24393end
24394
24395note Volumes (UEFI 13.4 Simple File System, 9.1 LoadedImage). k 0: copy the handles (at most 64) to
24396note private 1024 and free the firmware buffer (clobbers RSI/RDI/RCX); 1: result count | boot index<<8
24397note (255 none) and finish; 2: open the root of volume RDI into slot root (19 index, 21, 22);
24398note 3: open the root of the volume this image was loaded from into slot root (18, 21, 22).
24399fn xvol k ulong root ulong to void
24400if eq k 0
24401g = xg 5
24402ximm 1 2
24403xaddr 2 g
24404ximm 8 0
24405xp 0 9 512
24406xp 0 0 520
24407xmem 137 0 4 32
24408xp 3 0 312
24409xrr 133 0 0
24410xer 0 1 16
24411xp 1 1 512
24412ximm 0 64
24413xrr 57 1 0
24414p = xbranch 3
24415ximm 1 64
24416xpatch p get oc 0
24417xp 2 1 512
24418xp 1 6 520
24419xp 0 7 1024
24420emitb 252
24421emitb 243
24422emitb 72
24423emitb 165
24424xp 1 1 520
24425xp 3 0 72
24426xrr 133 0 0
24427xer 0 1 17
24428ret
24429end
24430if eq k 1
24431gl = xg 6
24432xp 1 1 8
24433xaddr 2 gl
24434xp 0 8 528
24435xp 3 0 152
24436xrr 133 0 0
24437xer 0 1 18
24438xp 1 0 528
24439xmem 139 0 0 24
24440xp 1 6 512
24441xp 0 7 1024
24442ximm 2 0
24443lp = get oc 0
24444xrr 57 2 6
24445nm = xbranch 2
24446xmem 139 1 7 0
24447xrr 57 1 0
24448fd = xbranch 0
24449xb 72 131 199
24450emitb 8
24451xb 72 255 194
24452back lp
24453xpatch nm get oc 0
24454ximm 2 255
24455xpatch fd get oc 0
24456xrr 137 0 6
24457xb 72 193 226
24458emitb 8
24459xrr 9 0 2
24460xer 1 0 0
24461ret
24462end
24463gs = xg 5
24464if eq k 3
24465gi = xg 6
24466xp 1 1 8
24467xaddr 2 gi
24468xp 0 8 528
24469xp 3 0 152
24470xrr 133 0 0
24471xer 0 1 18
24472xp 1 1 528
24473xmem 139 1 1 24
24474else
24475xp 1 0 512
24476xrr 57 7 0
24477xer 0 2 19
24478xp 0 1 1024
24479xrr 137 0 7
24480xb 72 193 224
24481emitb 3
24482xrr 1 1 0
24483xmem 139 1 1 0
24484end
24485xaddr 2 gs
24486xp 0 8 536
24487xp 3 0 152
24488xrr 133 0 0
24489xer 0 1 21
24490xp 0 2 root
24491xp 4 536 8
24492xrr 133 0 0
24493xer 0 1 22
24494end
24495
24496note File I/O (UEFI 13.5). k 0: Open(root, path, mode) into slot file; the path is the fixed
24497note \EFI\BOOT\BOOTX64.EFI for root 544 (efi 11), else the UCS-2 copy at private 3584 (efi 12).
24498note k 1: efi 11 Read/Write (method mode) of N bytes at R12 via size slot 560. Failure: RDI = code,
24499note jump to cleanup.
24500fn xfio k ulong root ulong file ulong mode ulong code ulong cleanup ulong to void
24501if eq k 0
24502if eq root 544
24503p = xg 8
24504xaddr 8 p
24505else
24506xp 0 8 3584
24507end
24508xp 0 2 file
24509ximm 9 mode
24510ximm 0 0
24511xmem 137 0 4 32
24512xp 4 root 8
24513else
24514xp 2 13 560
24515xp 0 2 560
24516xrr 137 8 12
24517xp 4 552 mode
24518end
24519xrr 133 0 0
24520ximm 7 code
24521bad = xbranch 1
24522xpatch bad cleanup
24523end
24524
24525note OP11 (Allen fork contract): ARG sub bits0..7, volume bits8..15. Sub 0 counts the volumes and
24526note finds the boot one (count | index<<8); sub 1 reads \EFI\BOOT\BOOTX64.EFI of volume k into A
24527note (result bytes); sub 2 writes A's N bytes as that file (deleted first; result bytes). File and
24528note root handles are closed on every path.
24529fn xefile to void
24530xrr 137 0 3
24531ximm 2 255
24532xrr 33 0 2
24533ximm 2 2
24534xrr 57 0 2
24535xer 0 8 15
24536ximm 0 0
24537xp 2 0 544
24538xp 2 0 552
24539skip = xbranch 14
24540cleanup = get oc 0
24541xp 1 1 552
24542xrr 133 1 1
24543p = xbranch 0
24544xp 4 552 16
24545xpatch p get oc 0
24546xp 1 1 544
24547xrr 133 1 1
24548p = xbranch 0
24549xp 4 544 16
24550xpatch p get oc 0
24551xrr 133 7 7
24552p = xbranch 0
24553ximm 0 9223372036854775808
24554xrr 9 0 7
24555xer 1 0 0
24556xpatch p get oc 0
24557xp 1 0 568
24558xer 1 0 0
24559xpatch skip get oc 0
24560xvol 0 0
24561xrr 137 6 3
24562ximm 2 255
24563xrr 33 6 2
24564xrr 137 7 3
24565xb 72 193 239
24566emitb 8
24567xrr 33 7 2
24568xrr 133 6 6
24569p = xbranch 1
24570xvol 1 0
24571xpatch p get oc 0
24572xp 1 0 512
24573xrr 57 7 0
24574xer 0 2 19
24575xe 3 1 0
24576xvol 2 544
24577ximm 0 1
24578xrr 57 6 0
24579wr = xbranch 1
24580xfio 0 544 552 1 23 cleanup
24581xfio 1 0 0 32 25 cleanup
24582xp 1 0 560
24583xp 2 0 568
24584ximm 0 1
24585xp 2 0 560
24586xp 0 2 560
24587xp 0 8 576
24588xp 4 552 32
24589xrr 133 0 0
24590ximm 7 25
24591p = xbranch 1
24592xpatch p cleanup
24593xp 1 0 560
24594xrr 133 0 0
24595ximm 7 24
24596p = xbranch 1
24597xpatch p cleanup
24598ximm 7 0
24599p = xbranch 14
24600xpatch p cleanup
24601xpatch wr get oc 0
24602xfio 0 544 552 3 26 cleanup
24603xp 4 552 24
24604ximm 2 0
24605xp 2 2 552
24606xrr 133 0 0
24607ximm 7 27
24608p = xbranch 1
24609xpatch p cleanup
24610xfio 0 544 552 9223372036854775811 28 cleanup
24611xfio 1 0 0 40 29 cleanup
24612xp 1 0 560
24613xrr 57 0 13
24614ximm 7 30
24615p = xbranch 1
24616xpatch p cleanup
24617xp 4 552 80
24618xrr 133 0 0
24619ximm 7 31
24620p = xbranch 1
24621xpatch p cleanup
24622xp 1 0 560
24623xp 2 0 568
24624ximm 7 0
24625p = xbranch 14
24626xpatch p cleanup
24627end
24628
24629note OP12 general file (new): ARG sub bits0..7, volume bits8..15 (255 = the volume this image was
24630note loaded from), position bits16..63. Open subs take the path A[OFF..OFF+N): 1..255 bytes, first
24631note '\', each 32..126. Sub 0 open read-only, 5 open an existing file read/write (no truncate), both
24632note result FileSize; 1 create empty, replacing any file (result 0). Sub 2 reads up to N bytes at
24633note the position into A (result bytes read, 0 at end), 3 writes N bytes there (result N; needs sub
24634note 1 or 5), 4 flushes and closes (result 0). One file at a time: its handle stays in private 2304
24635note and its volume root in 2312 between operations. Errors: 32 sub, 33 path, 34 busy, 35 nothing
24636note open, 36 open/create/delete, 37 read, 38 write (or not writable), 39 short write, 40 flush,
24637note 41 GetInfo; volume errors 16..22 as efi 11. Refusals 32..35 and 38 not-writable leave the slot
24638note as it was (the caller still owns an open file); so do the firmware errors 37, 38 and 39 of subs
24639note 2 and 3. Volume errors leave the slot empty. 36 and 41 close the file and root, slot empty;
24640note sub 4 with a file open closes both and empties the slot on every path, returning 40 when Flush
24641note failed. A file still open at exit is flushed and closed by the shared exit (xefx 1).
24642fn xf12 to void
24643skip = xbranch 14
24644cleanup = get oc 0
24645xp 1 1 2304
24646xrr 133 1 1
24647p = xbranch 0
24648xp 4 2304 16
24649xpatch p get oc 0
24650xp 1 1 2312
24651xrr 133 1 1
24652p = xbranch 0
24653xp 4 2312 16
24654xpatch p get oc 0
24655ximm 0 0
24656xp 2 0 2304
24657xp 2 0 2312
24658xp 2 0 2320
24659xrr 133 7 7
24660p = xbranch 0
24661ximm 0 9223372036854775808
24662xrr 9 0 7
24663xer 1 0 0
24664xpatch p get oc 0
24665xer 1 0 0
24666xpatch skip get oc 0
24667xrr 137 6 3
24668ximm 0 255
24669xrr 33 6 0
24670ximm 0 5
24671xrr 57 6 0
24672xer 0 8 32
24673ximm 0 2
24674xrr 57 6 0
24675opn = xbranch 3
24676ximm 0 5
24677xrr 57 6 0
24678op5 = xbranch 0
24679xp 1 1 2304
24680xrr 133 1 1
24681xer 0 0 35
24682ximm 0 4
24683xrr 57 6 0
24684p = xbranch 1
24685ximm 7 0
24686xp 1 0 2320
24687xrr 133 0 0
24688q = xbranch 0
24689xp 4 2304 80
24690xrr 133 0 0
24691rw = xbranch 0
24692ximm 7 40
24693xpatch rw get oc 0
24694xpatch q get oc 0
24695ximm 0 0
24696rw = xbranch 14
24697xpatch rw cleanup
24698xpatch p get oc 0
24699xrr 137 2 3
24700xb 72 193 234
24701emitb 16
24702ximm 0 3
24703xrr 57 6 0
24704p = xbranch 0
24705xp 4 2304 56
24706xrr 133 0 0
24707xer 0 1 37
24708xp 2 13 2336
24709xp 0 2 2336
24710xrr 137 8 12
24711xp 4 2304 32
24712xrr 133 0 0
24713xer 0 1 37
24714xp 1 0 2336
24715xer 1 0 0
24716xpatch p get oc 0
24717xp 1 0 2320
24718xrr 133 0 0
24719xer 0 0 38
24720xp 4 2304 56
24721xrr 133 0 0
24722xer 0 1 38
24723xp 2 13 2336
24724xp 0 2 2336
24725xrr 137 8 12
24726xp 4 2304 40
24727xrr 133 0 0
24728xer 0 1 38
24729xp 1 0 2336
24730xrr 57 0 13
24731xer 0 1 39
24732xrr 137 0 13
24733xer 1 0 0
24734xpatch opn get oc 0
24735xpatch op5 get oc 0
24736xp 1 1 2304
24737xrr 133 1 1
24738xer 0 1 34
24739xrr 133 13 13
24740xer 0 0 33
24741ximm 0 255
24742xrr 57 13 0
24743xer 0 8 33
24744xhraw 0 12 0 1
24745ximm 2 92
24746xrr 57 0 2
24747xer 0 1 33
24748xrr 137 8 12
24749xrr 137 9 13
24750xp 0 10 3584
24751lp = get oc 0
24752xrr 133 9 9
24753p = xbranch 0
24754xhraw 0 8 0 1
24755ximm 2 32
24756xrr 57 0 2
24757xer 0 3 33
24758ximm 2 126
24759xrr 57 0 2
24760xer 0 8 33
24761xhput 0 10 0 2
24762xb 73 131 192
24763emitb 1
24764xb 73 131 194
24765emitb 2
24766xb 73 131 233
24767emitb 1
24768back lp
24769xpatch p get oc 0
24770ximm 0 0
24771xhput 0 10 0 2
24772xrr 137 0 3
24773ximm 2 65280
24774xrr 33 0 2
24775xrr 57 0 2
24776p = xbranch 0
24777xvol 0 0
24778xrr 137 7 3
24779xb 72 193 239
24780emitb 8
24781ximm 2 255
24782xrr 33 7 2
24783xvol 2 2312
24784q = xbranch 14
24785xpatch p get oc 0
24786xvol 3 2312
24787xpatch q get oc 0
24788xrr 137 6 3
24789ximm 0 255
24790xrr 33 6 0
24791ximm 0 1
24792xrr 57 6 0
24793p = xbranch 1
24794note Sub 1: delete an existing file first (UEFI 13.5 Delete closes the handle), then create.
24795xp 0 8 3584
24796xp 0 2 2304
24797ximm 9 3
24798ximm 0 0
24799xmem 137 0 4 32
24800xp 4 2312 8
24801xrr 133 0 0
24802q = xbranch 1
24803xp 4 2304 24
24804ximm 2 0
24805xp 2 2 2304
24806xrr 133 0 0
24807ximm 7 36
24808rw = xbranch 1
24809xpatch rw cleanup
24810xpatch q get oc 0
24811ximm 2 0
24812xp 2 2 2304
24813xfio 0 2312 2304 9223372036854775811 36 cleanup
24814ximm 0 1
24815xp 2 0 2320
24816ximm 0 0
24817xer 1 0 0
24818xpatch p get oc 0
24819ximm 0 5
24820xrr 57 6 0
24821p = xbranch 0
24822xfio 0 2312 2304 1 36 cleanup
24823ximm 0 0
24824xp 2 0 2320
24825q = xbranch 14
24826xpatch p get oc 0
24827xfio 0 2312 2304 3 36 cleanup
24828ximm 0 1
24829xp 2 0 2320
24830xpatch q get oc 0
24831ximm 0 1024
24832xp 2 0 2336
24833gi = xg 7
24834xaddr 2 gi
24835xp 0 8 2336
24836xp 0 9 2560
24837xp 4 2304 64
24838xrr 133 0 0
24839ximm 7 41
24840p = xbranch 1
24841xpatch p cleanup
24842xp 1 0 2568
24843xp 2 0 2328
24844end
24845
24846
24847
24848note ======== a64efi: UEFI AArch64 PE32+ application (docs/A64-EFI.md) ========
24849note The default AArch64 code generator with three differences: addresses are base-relative (mataddr),
24850note every exit branches to the shared firmware return at file offset 520 (aefx), and there are no host
24851note words. Private state is the first 16 KiB of the .bss, whose base stays in X27: 0 ImageHandle,
24852note 8 SystemTable, 16..111 X19..X30, 112 the firmware SP, 120..183 D8..D15 (AAPCS64 callee-saved, UEFI
24853note 2.10 2.3.6), 184 the address of fn efiexit when the program has one, 192 the status across it.
24854note The Omega stack is the rest of the first 8 MiB (X28 = base + 16 KiB), the globals follow.
24855
24856note aefx: the shared return, X0 = EFI_STATUS. When slot 184 holds a function it is called once on a
24857note fresh stack (the slot is cleared first, so a trap inside it returns), then the callee-saved
24858note registers and the firmware stack come back and RET returns to the firmware.
24859fn aefx to void
24860emit 4181747561
24861emit 3036676841
24862emit 4181745520
24863emit 3019899152
24864emit 4177551231
24865emit 4177552224
24866emit 2438988649
24867emit 2432696639
24868emit 2436895612
24869emit 3594453504
24870emit 4181746528
24871emit 4181736297
24872emit 2432696639
24873emit 1833412456
24874emit 1833480042
24875emit 1833547628
24876emit 1833615214
24877emit 2839630707
24878emit 2839698293
24879emit 2839765879
24880emit 2839833465
24881emit 2839968637
24882emit 2839901051
24883emit 3596551104
24884emit 3573764063
24885emit 3577233993
24886emit 3544321321
24887emit 4043311423
24888emit 1409286304
24889emit 3577238017
24890emit 3577233442
24891emit 3577241603
24892emit 335544324
24893emit 3577500161
24894emit 3577495586
24895emit 3577503747
24896emit 3573764063
24897emit 2438988649
24898emit 2432696639
24899emit 2436895612
24900emit 4181754736
24901emit 3019898992
24902emit 4177560447
24903emit 3594453504
24904emit 4181749609
24905emit 4043310399
24906emit 1409286305
24907emit 3531604256
24908emit 4071653376
24909emit 3556769795
24910emit 335544326
24911emit 4043311423
24912emit 1409286273
24913emit 3531604256
24914emit 4071653376
24915emit 3556769794
24916emit 3573751903
24917emit 402653183
24918emit 4043309087
24919emit 1409286305
24920emit 3573759903
24921emit 3573759967
24922emit 3531603968
24923emit 3596551104
24924emit 4043310111
24925emit 1409286305
24926emit 3573758879
24927emit 3573759967
24928emit 3531603968
24929emit 3596551104
24930emit 4043311135
24931emit 1409286273
24932emit 3573759967
24933emit 3531603968
24934emit 3596551104
24935emit 4043312159
24936emit 1409286337
24937emit 3574104863
24938emit 3573758879
24939emit 3573759967
24940emit 3531603968
24941emit 3596551104
24942emit 4043313183
24943emit 1409286273
24944emit 3574300193
24945emit 3531603968
24946emit 3596551104
24947emit 4043314207
24948emit 1409286273
24949emit 3574299169
24950emit 3531603968
24951emit 3596551104
24952emit 4043315231
24953emit 1409286337
24954emit 3574101279
24955emit 3573758879
24956emit 3573759967
24957emit 3531603968
24958emit 3596551104
24959emit 4043316255
24960emit 1409286305
24961emit 3573764063
24962emit 3573759967
24963emit 3531603968
24964emit 3596551104
24965emit 4043317279
24966emit 1409286305
24967emit 3573760767
24968emit 3573759967
24969emit 3531603968
24970emit 3596551104
24971emit 4043318303
24972emit 1409286273
24973emit 3573751903
24974emit 3531603968
24975emit 3596551104
24976emit 4043319327
24977emit 1409286273
24978emit 3573751967
24979emit 3531603968
24980emit 3596551104
24981emit 4043320351
24982emit 1409286273
24983emit 3573751935
24984emit 3531603968
24985emit 3596551104
24986emit 4043325471
24987emit 1409288960
24988emit 4043326495
24989emit 1409292416
24990emit 4043327519
24991emit 1409286816
24992emit 4043328543
24993emit 1409286944
24994emit 4043329567
24995emit 1409294976
24996emit 4043330591
24997emit 1409296576
24998emit 4043331615
24999emit 1409287616
25000emit 4043332639
25001emit 1409287296
25002emit 4043335711
25003emit 1409286816
25004emit 4043336735
25005emit 1409286880
25006emit 4043337759
25007emit 1409286944
25008emit 4043338783
25009emit 1409286944
25010emit 2457862144
25011emit 3596551104
25012emit 2852193248
25013emit 2852258785
25014emit 2852324322
25015emit 3531603971
25016emit 3556769795
25017emit 3596551104
25018emit 2852193248
25019emit 2852258785
25020emit 2852324322
25021emit 3531603971
25022emit 3556769794
25023emit 3596551104
25024emit 3531604064
25025emit 4072177664
25026emit 3556769795
25027emit 3596551104
25028emit 3531604064
25029emit 4072177664
25030emit 3556769794
25031emit 3596551104
25032emit 3370122272
25033emit 3596551104
25034emit 3365927970
25035emit 3531603968
25036emit 3596551104
25037emit 3531604009
25038emit 4177553257
25039emit 4177554273
25040emit 4177555298
25041emit 3573759903
25042emit 3573759967
25043emit 3531603968
25044emit 3596551104
25045emit 4043309119
25046emit 1409286241
25047emit 4181756768
25048emit 3596551104
25049emit 4043310143
25050emit 1409286241
25051emit 2853897184
25052emit 3596551104
25053emit 4043311167
25054emit 1409286241
25055emit 4181757792
25056emit 3596551104
25057emit 4043313215
25058emit 1409286241
25059emit 4181751648
25060emit 3596551104
25061emit 4043314239
25062emit 1409286241
25063emit 4181752672
25064emit 3596551104
25065emit 4043315263
25066emit 1409286241
25067emit 4181759840
25068emit 3596551104
25069emit 4043316287
25070emit 1409286241
25071emit 4181755744
25072emit 3596551104
25073emit 3531603968
25074emit 3596551104
25075emit 4043309119
25076emit 1409286241
25077emit 3577233984
25078emit 3596551104
25079emit 4043310143
25080emit 1409286241
25081emit 3577217184
25082emit 3596551104
25083emit 4043311167
25084emit 1409286241
25085emit 3577413664
25086emit 3596551104
25087emit 4043312191
25088emit 1409286241
25089emit 3577218816
25090emit 3596551104
25091emit 4043313215
25092emit 1409286241
25093emit 3577218048
25094emit 3596551104
25095emit 4043314239
25096emit 1409286241
25097emit 3577221120
25098emit 3596551104
25099emit 4043315263
25100emit 1409286241
25101emit 3577225216
25102emit 3596551104
25103emit 4043316287
25104emit 1409286241
25105emit 3577225280
25106emit 3596551104
25107emit 4043317311
25108emit 1409286241
25109emit 3577258496
25110emit 3596551104
25111emit 4043318335
25112emit 1409286241
25113emit 3577266176
25114emit 3596551104
25115emit 4043319359
25116emit 1409286241
25117emit 3577269408
25118emit 3596551104
25119emit 4043320383
25120emit 1409286241
25121emit 3577269248
25122emit 3596551104
25123emit 4043321407
25124emit 1409286241
25125emit 3577234944
25126emit 3596551104
25127emit 4043322431
25128emit 1409286241
25129emit 3577269344
25130emit 3596551104
25131emit 4043323455
25132emit 1409286241
25133emit 3577269472
25134emit 3596551104
25135emit 4043324479
25136emit 1409286241
25137emit 3577269376
25138emit 3596551104
25139emit 4043325503
25140emit 1409286241
25141emit 3577483520
25142emit 3596551104
25143emit 4043326527
25144emit 1409286241
25145emit 3577483264
25146emit 3596551104
25147emit 4043327551
25148emit 1409286241
25149emit 3577487360
25150emit 3596551104
25151emit 4043328575
25152emit 1409286241
25153emit 3577530784
25154emit 3596551104
25155emit 4043329599
25156emit 1409286241
25157emit 3577238016
25158emit 3596551104
25159emit 4043330623
25160emit 1409286241
25161emit 3577233440
25162emit 3596551104
25163emit 4043331647
25164emit 1409286241
25165emit 3577241600
25166emit 3596551104
25167emit 4043332671
25168emit 1409286241
25169emit 3577430560
25170emit 3596551104
25171emit 4043333695
25172emit 1409286241
25173emit 2432697312
25174emit 3596551104
25175emit 4043334719
25176emit 1409286241
25177emit 3577471520
25178emit 3596551104
25179emit 4043335743
25180emit 1409286241
25181emit 3577471488
25182emit 3596551104
25183emit 3531603968
25184emit 3596551104
25185emit 4043314239
25186emit 1409286305
25187emit 3575123970
25188emit 3573759967
25189emit 3531603968
25190emit 3596551104
25191emit 4043315263
25192emit 1409286305
25193emit 3575128066
25194emit 3573759967
25195emit 3531603968
25196emit 3596551104
25197emit 4043316287
25198emit 1409286305
25199emit 3575128130
25200emit 3573759967
25201emit 3531603968
25202emit 3596551104
25203emit 4043317311
25204emit 1409286305
25205emit 3575161346
25206emit 3573759967
25207emit 3531603968
25208emit 3596551104
25209emit 4043318335
25210emit 1409286305
25211emit 3575169026
25212emit 3573759967
25213emit 3531603968
25214emit 3596551104
25215emit 4043319359
25216emit 1409286305
25217emit 3575172258
25218emit 3573759967
25219emit 3531603968
25220emit 3596551104
25221emit 4043320383
25222emit 1409286305
25223emit 3575172130
25224emit 3573759967
25225emit 3531603968
25226emit 3596551104
25227emit 4043321407
25228emit 1409286305
25229emit 3575137794
25230emit 3573759967
25231emit 3531603968
25232emit 3596551104
25233emit 4043322431
25234emit 1409286305
25235emit 3575172194
25236emit 3573759967
25237emit 3531603968
25238emit 3596551104
25239emit 4043323455
25240emit 1409286305
25241emit 3575172322
25242emit 3573759967
25243emit 3531603968
25244emit 3596551104
25245emit 4043324479
25246emit 1409286305
25247emit 3575172226
25248emit 3573759967
25249emit 3531603968
25250emit 3596551104
25251emit 4043325503
25252emit 1409286305
25253emit 3575386370
25254emit 3573759967
25255emit 3531603968
25256emit 3596551104
25257emit 4043334719
25258emit 1409286305
25259emit 3575374370
25260emit 3573759967
25261emit 3531603968
25262emit 3596551104
25263emit 4043335743
25264emit 1409286305
25265emit 3575374338
25266emit 3573759967
25267emit 3531603968
25268emit 3596551104
25269emit 2457862144
25270emit 3596551104
25271emit 3573764063
25272emit 3577217033
25273emit 3575382025
25274emit 3577217193
25275emit 3575382185
25276emit 3534749705
25277emit 3575386377
25278emit 3573759967
25279emit 3532021737
25280emit 3575386441
25281emit 3575386495
25282emit 3575390495
25283emit 3531604073
25284emit 3575439625
25285emit 3575439487
25286emit 3577218057
25287emit 3545787689
25288emit 3019899113
25289emit 3577530793
25290emit 3531604266
25291emit 2852782377
25292emit 3575433641
25293emit 3573759967
25294emit 3575434015
25295emit 3533702665
25296emit 3575124041
25297emit 2839555114
25298emit 2839622700
25299emit 2839690286
25300emit 2839769120
25301emit 3575161355
25302emit 3575128140
25303emit 3575128074
25304emit 3575128127
25305emit 3573758879
25306emit 3574104863
25307emit 3573758879
25308emit 3574101279
25309emit 3573758879
25310emit 3573759967
25311emit 3575123981
25312emit 3573759967
25313emit 3575398670
25314emit 4181755753
25315emit 3575169033
25316emit 3531634857
25317emit 3575398409
25318emit 3575398447
25319emit 2854159357
25320emit 285199390
25321emit 3573759967
25322emit 3600745440
25323emit 3573764063
25324emit 3577221129
25325emit 2457860393
25326emit 3575123977
25327emit 3573759967
25328emit 2839555114
25329emit 2839622700
25330emit 2839690286
25331emit 2839769120
25332emit 3575161355
25333emit 3575128140
25334emit 3575128074
25335emit 3575128127
25336emit 3573758879
25337emit 3574104863
25338emit 3573758879
25339emit 3574101279
25340emit 3573758879
25341emit 3573759967
25342emit 3575123981
25343emit 3573759967
25344emit 2432696799
25345emit 4181755753
25346emit 3575169033
25347emit 3573759967
25348emit 2854159357
25349emit 285198462
25350emit 3592356320
25351emit 3573764063
25352emit 4181729307
25353emit 2852127713
25354emit 3577233993
25355emit 3544321321
25356emit 4043311423
25357emit 1426060608
25358emit 4043310399
25359emit 1426062208
25360emit 3573751903
25361emit 402653183
25362for i ulong 8
25363emit 3573751839
25364end
25365emit 3573764063
25366emit 3577238017
25367emit 3577233442
25368emit 3577241603
25369emit 3531612128
25370emit 2990604288
25371emit 402652704
25372for i ulong 25
25373emit 3573751839
25374end
25375emit 3573764063
25376emit 3577238017
25377emit 3577233442
25378emit 3577241603
25379emit 3531612128
25380emit 2990604288
25381emit 402652672
25382for i ulong 25
25383emit 3573751839
25384end
25385emit 3573764063
25386emit 3577238017
25387emit 3577233442
25388emit 3577241603
25389emit 3531612128
25390emit 2990604288
25391emit 402652640
25392for i ulong 25
25393emit 3573751839
25394end
25395emit 3573764063
25396emit 3577238017
25397emit 3577233442
25398emit 3577241603
25399emit 3531612128
25400emit 2990604288
25401emit 402652608
25402for i ulong 25
25403emit 3573751839
25404end
25405emit 3573764063
25406emit 3577238017
25407emit 3577233442
25408emit 3577241603
25409emit 3531612128
25410emit 2990604288
25411emit 402652576
25412for i ulong 25
25413emit 3573751839
25414end
25415emit 335544672
25416for i ulong 31
25417emit 3573751839
25418end
25419emit 3573764063
25420emit 3577238017
25421emit 3577233442
25422emit 3577241603
25423emit 3531612128
25424emit 2990604288
25425emit 402652512
25426for i ulong 25
25427emit 3573751839
25428end
25429emit 3573764063
25430emit 3577238017
25431emit 3577233442
25432emit 3577241603
25433emit 3531612128
25434emit 2990604288
25435emit 402652480
25436for i ulong 25
25437emit 3573751839
25438end
25439emit 3573764063
25440emit 3577238017
25441emit 3577233442
25442emit 3577241603
25443emit 3531612128
25444emit 2990604288
25445emit 402652448
25446for i ulong 25
25447emit 3573751839
25448end
25449emit 3573764063
25450emit 3577238017
25451emit 3577233442
25452emit 3577241603
25453emit 3531612128
25454emit 2990604288
25455emit 402652416
25456for i ulong 25
25457emit 3573751839
25458end
25459emit 3573764063
25460emit 3577238017
25461emit 3577233442
25462emit 3577241603
25463emit 3531612128
25464emit 2990604288
25465emit 402652384
25466for i ulong 25
25467emit 3573751839
25468end
25469emit 3573764063
25470emit 3577238017
25471emit 3577233442
25472emit 3577241603
25473emit 3531612128
25474emit 2990604288
25475emit 402652352
25476for i ulong 25
25477emit 3573751839
25478end
25479emit 3573764063
25480emit 3577238017
25481emit 3577233442
25482emit 3577241603
25483emit 3531612128
25484emit 2990604288
25485emit 402652320
25486for i ulong 25
25487emit 3573751839
25488end
25489emit 3573764063
25490emit 3577238017
25491emit 3577233442
25492emit 3577241603
25493emit 3531612128
25494emit 2990604288
25495emit 402652288
25496for i ulong 25
25497emit 3573751839
25498end
25499emit 3573764063
25500emit 3577238017
25501emit 3577233442
25502emit 3577241603
25503emit 3531612128
25504emit 2990604288
25505emit 402652256
25506for i ulong 25
25507emit 3573751839
25508end
25509emit 3573764063
25510emit 3577238017
25511emit 3577233442
25512emit 3577241603
25513emit 3531612128
25514emit 2990604288
25515emit 402652224
25516for i ulong 25
25517emit 3573751839
25518end
25519emit 2847213536
25520emit 2835419106
25521emit 2835486692
25522emit 2835554278
25523emit 2835621864
25524emit 2835689450
25525emit 2835757036
25526emit 2835824622
25527emit 2835892208
25528emit 2835959794
25529emit 2836036605
25530emit 3577269267
25531emit 2457794153
25532emit 4044353855
25533emit 1409286368
25534emit 4181753705
25535emit 3019898985
25536emit 2853372896
25537emit 3594453280
25538emit 3575172147
25539emit 3573759967
25540emit 2840230909
25541emit 2840154098
25542emit 2840086512
25543emit 2840018926
25544emit 2839951340
25545emit 2839883754
25546emit 2839816168
25547emit 2839748582
25548emit 2839680996
25549emit 2839613410
25550emit 2831878112
25551emit 3600745440
25552end
25553
25554note aadr: ADRP + ADD of register r to file offset t0 from the current instruction (RVA = offset + 3584)
25555fn aadr r ulong t0 ulong to void
25556t = add t0 3584
25557d = and sub shr t 12 shr add get oc 0 3584 12 2097151
25558emit or or or 2415919104 shl and d 3 29 shl shr d 2 5 r
25559emit or or or 2432696320 shl and t 4095 10 shl r 5 r
25560end
25561
25562note aeof: the entry (X0 ImageHandle, X1 SystemTable): X9 = the .bss page (ADRP, patched once the image
25563note size is known), save the callee-saved state, X27 = X9, X28 = X27 + 16 KiB, SP = X27 + 8 MiB, store
25564note efiexit's address when there is one, BL main, B to the shared return. Then the PE32+ headers, as
25565note x86efi's (xefx 2) with machine 0xAA64 and NX_COMPAT: .text from file offset 512 at RVA 4096, its
25566note first 8 bytes an empty base relocation block, .bss after it (zero filled by the loader).
25567fn aeof to void
25568f = findfn 1852399981 4 0
25569if eq f 0
25570note d2site 604|aeof: syntax: unknown or misplaced word; condition if eq f 0
25571put d2site 0 604
25572fail 16
25573end
25574if ne uchar get a_ar add get a_rb 24 sub f 1 0
25575note d2site 605|aeof: word or declaration in a place that does not allow it; condition if ne uchar get a_ar add get a_rb 24 sub f 1 0
25576put d2site 0 605
25577fail 9
25578end
25579entry = get oc 0
25580emit 2415919113
25581emit 2835435827
25582emit 2835503413
25583emit 2835570999
25584emit 2835638585
25585emit 2835706171
25586emit 2835773757
25587emit 2432697322
25588emit 4177541418
25589emit 1829217576
25590emit 1829285162
25591emit 1829352748
25592emit 1829420334
25593emit 2835350816
25594emit 2852717563
25595emit 2436895612
25596emit 2438988656
25597emit 2432696863
25598h = findfn 32767063116834405 7 0
25599if ne h 0
25600note the return sequence calls efiexit with no arguments and ignores a result: only `fn efiexit to void`
25601note is that function (region 23: the result type, 12 void); anything else is error 9
25602if ne ulong get a_ar add get a_rb 24 sub h 1 0
25603note d2site 606|aeof: word or declaration in a place that does not allow it; condition if ne ulong get a_ar add get a_rb 24 sub h 1 0
25604put d2site 0 606
25605fail 9
25606end
25607if ne ulong get a_ar add get a_rb 23 sub h 1 12
25608note d2site 607|aeof: word or declaration in a place that does not allow it; condition if ne ulong get a_ar add get a_rb 23 sub h 1 12
25609put d2site 0 607
25610fail 9
25611end
25612aadr 10 get a_ar add get a_rb 22 sub h 1
25613emit 4177551210
25614end
25615note bare-metal a64efi metadata and optional hooks: image_base [272], image_end [280], vbar_el1 [264],
25616note smp_trampoline [296], el1main [232], smpmain [240], irqhook [248], panichk [256]
25617aadr 10 512
25618emit 3510633802
25619emit 4177562474
25620matconst 10 shl shr add add get poolb 0 8388608 4095 12 12
25621emit 2332689258
25622emit 4177563498
25623aadr 10 2560
25624emit 4177561450
25625aadr 10 2484
25626emit 4177565546
25627h = findfn 31078114602871909 7 0
25628if ne h 0
25629aadr 10 get a_ar add get a_rb 22 sub h 1
25630emit 4177557354
25631end
25632h = findfn 31078114607000947 7 0
25633if ne h 0
25634aadr 10 get a_ar add get a_rb 22 sub h 1
25635emit 4177558378
25636end
25637h = findfn 30240346792358505 7 0
25638if ne h 0
25639aadr 10 get a_ar add get a_rb 22 sub h 1
25640emit 4177559402
25641end
25642h = findfn 30232598687932784 7 0
25643if ne h 0
25644aadr 10 get a_ar add get a_rb 22 sub h 1
25645emit 4177560426
25646end
25647emit or 2483027968 bdisp get oc 0 get a_ar add get a_rb 22 sub f 1 26
25648if eq uchar get a_ar add get a_rb 23 sub f 1 12
25649emit 3531603968
25650end
25651emit or 335544320 bdisp get oc 0 520 26
25652while ne and get oc 0 511 0
25653emit 0
25654end
25655raw = sub get oc 0 512
25656bs = shl shr add add raw 4096 4095 12 12
25657d = and sub shr bs 12 shr add entry 3584 12 2097151
25658wrword entry or or or 2415919104 shl and d 3 29 shl shr d 2 5 9
25659wrword 0 23117
25660wrword 60 64
25661wrword 64 17744
25662wrword 68 174692
25663wrword 84 2228464
25664wrword 88 523
25665wrword 92 raw
25666wrword 100 add get poolb 0 8388608
25667wrword 104 add entry 3584
25668wrword 108 4096
25669wrword 112 4194304
25670wrword 120 4096
25671wrword 124 512
25672wrword 128 6
25673wrword 136 6
25674wrword 144 shl shr add add bs add get poolb 0 8388608 4095 12 12
25675wrword 148 512
25676wrword 156 20971530
25677wrword 160 1048576
25678wrword 168 4096
25679wrword 176 1048576
25680wrword 184 4096
25681wrword 196 16
25682wrword 512 0
25683wrword 516 8
25684wrword 240 4096
25685wrword 244 8
25686wrword 328 2019914798
25687wrword 332 116
25688wrword 336 raw
25689wrword 340 4096
25690wrword 344 raw
25691wrword 348 512
25692wrword 364 1610612768
25693wrword 368 1936941614
25694wrword 376 add get poolb 0 8388608
25695wrword 380 bs
25696wrword 404 3221225600
25697writeout 0
25698end
25699
25700note aret: the result of a firmware word, X0 as a ulong, after the saved registers come back
25701fn aret dst ulong x ulong to void
25702sl = get a_ar add get a_rb 77 add x 7
25703r = restore dst sl get svn 0 get sva 0 1
25704vdone 1 r 5
25705end
25706
25707note aefival: efi OP ARG A OFF N -> ulong, the contract of x86efi's word. OP is a literal 0..14, A writable
25708note uchar storage with OFF + N inside it (trap 3). Here the operation is Omega code: the word is a call of
25709note the program's own fn efirt op arg addr n (four ulong, result ulong), which must be defined above its
25710note first use (error 16) and reaches the firmware through the fw words.
25711fn aefival dst ulong to void
25712x = mul get depth 0 32
25713put a_ar add get a_rb 77 add x 7 get nslot 0
25714op = lenval 4
25715if gt op 14
25716note d2site 608|aefival: unknown target, an AArch64-only path on another target, or an x86efi refusal (bare unit, Linux host word, efi OP literal outside 0..14); condition if gt op 14
25717put d2site 0 608
25718fail 25
25719end
25720harg x 2 5
25721e = harray x 1
25722f = findfn 500135716453 5 0
25723if eq f 0
25724note d2site 609|aefival: syntax: unknown or misplaced word; condition if eq f 0
25725put d2site 0 609
25726fail 16
25727end
25728note efirt takes four ulong values and gives a ulong: anything else is error 9 here, not a wrong call at
25729note run time (parameter i of function f is entry (f - 1) * 6 + i: region 37 its kind, 0 a scalar; region
25730note 35 its type, 5 ulong)
25731if ne ulong get a_ar add get a_rb 24 sub f 1 4
25732note d2site 610|aefival: word or declaration in a place that does not allow it; condition if ne ulong get a_ar add get a_rb 24 sub f 1 4
25733put d2site 0 610
25734fail 9
25735end
25736if ne ulong get a_ar add get a_rb 23 sub f 1 5
25737note d2site 611|aefival: word or declaration in a place that does not allow it; condition if ne ulong get a_ar add get a_rb 23 sub f 1 5
25738put d2site 0 611
25739fail 9
25740end
25741for i ulong 4
25742pe = add mul sub f 1 6 i
25743if ne a_gu 37 pe 0
25744note d2site 612|aefival: word or declaration in a place that does not allow it; condition if ne a_gu 37 pe 0
25745put d2site 0 612
25746fail 9
25747end
25748if ne ulong a_gu 35 pe 5
25749note d2site 613|aefival: word or declaration in a place that does not allow it; condition if ne ulong a_gu 35 pe 5
25750put d2site 0 613
25751fail 9
25752end
25753end
25754save
25755hload x 2 1
25756basearg 2 e
25757loadarg 16 1 get a_ar add get a_rb 77 add x 21
25758e3 2332033024 2 2 16
25759loadarg 3 1 get a_ar add get a_rb 77 add x 22
25760matconst 0 op
25761emit or 2483027968 bdisp get oc 0 get a_ar add get a_rb 22 sub f 1 26
25762aret dst x
25763end
25764
25765note afw: the firmware words, all ulong in and out. They carry raw addresses, which no other word does:
25766note fwcall F A0 A1 A2 A3 A4 A5: BLR F with A0..A5 in X0..X5 (AAPCS64), result X0; 64 KiB of stack must
25767note be free (trap 6). fwld ADDR W / fwst ADDR W V: load or store W = 1, 2, 4 or 8 bytes (another W is 1) at
25768note ADDR; fwst gives 0. fwsys K: 0 ImageHandle, 1 SystemTable, 2 CNTVCT_EL0 after ISB, 3 CNTFRQ_EL0, else
25769note MIDR_EL1. fwadr A OFF N: the address of A[OFF], with OFF + N inside A (trap 3).
25770fn afw c ulong dst ulong to void
25771x = mul get depth 0 32
25772put a_ar add get a_rb 77 add x 7 get nslot 0
25773if eq c 254
25774e = harray x 1
25775save
25776basearg 0 e
25777loadarg 16 1 get a_ar add get a_rb 77 add x 21
25778e3 2332033024 0 0 16
25779aret dst x
25780ret
25781end
25782np = ulong 7
25783if eq c 251
25784np = ulong 2
25785end
25786if eq c 252
25787np = ulong 3
25788end
25789if eq c 253
25790np = ulong 1
25791end
25792if eq c 255
25793np = ulong 4
25794end
25795for i ulong np
25796harg x i 5
25797end
25798save
25799for i ulong np
25800hload x i i
25801end
25802if eq c 250
25803emit 3510649840
25804emit 3944481311
25805trapc 3 6
25806emit 2852127728
25807emit 2852193248
25808emit 2852258785
25809emit 2852324322
25810emit 2852389859
25811emit 2852455396
25812emit 2852520933
25813emit 3594453504
25814end
25815if eq c 251
25816emit 4043317311
25817emit 1409286368
25818emit 4043313215
25819emit 1409286368
25820emit 4043311167
25821emit 1409286368
25822emit 960495616
25823emit 335544326
25824emit 4181721088
25825emit 335544324
25826emit 3107979264
25827emit 335544322
25828emit 2034237440
25829end
25830if eq c 252
25831emit 4043317311
25832emit 1409286368
25833emit 4043313215
25834emit 1409286368
25835emit 4043311167
25836emit 1409286368
25837emit 956301314
25838emit 335544326
25839emit 4177526786
25840emit 335544324
25841emit 3103784962
25842emit 335544322
25843emit 2030043138
25844emit 3531603968
25845end
25846if eq c 253
25847emit 4043311135
25848emit 1409286339
25849emit 1409286368
25850emit 4043312159
25851emit 1409286400
25852emit 3577217024
25853emit 335544327
25854emit 4167072608
25855emit 335544325
25856emit 3573759967
25857emit 3577471040
25858emit 335544322
25859emit 3577470976
25860end
25861if eq c 255
25862emit or 2483027968 bdisp get oc 0 752 26
25863end
25864aret dst x
25865end
25866
25867note Native object mode is opt-in with object then om2. Existing profiles retain their artifacts.
25868note An import has an ordinary compiler-checked signature but no body or address.
25869fn s_extern to void
25870if ne get curret 0 0
25871note d2site 614|s_extern: missing end; condition if ne get curret 0 0
25872put d2site 0 614
25873fail 15
25874end
25875tok
25876if or ne get tk 0 1 ne get tw 0 28262
25877note d2site 615|s_extern: syntax: unknown or misplaced word; condition if or ne get tk 0 1 ne get tw 0 28262
25878put d2site 0 615
25879fail 16
25880end
25881put expf 0 2
25882s_fn
25883put expf 0 0
25884end
25885
25886fn obj_import f ulong to void
25887if ne a_gu 27 f 0
25888note d2site 616|obj_import: word or declaration in a place that does not allow it; condition if ne a_gu 27 f 0
25889put d2site 0 616
25890fail 9
25891end
25892obj_signature f
25893a_p 22 f 0
25894put curret 0 0
25895put curfn 0 0
25896nm_set get nglob 0
25897end
25898
25899note Version 1 external interfaces carry primitive scalars and arrays. Nominal layouts need
25900note a separately versioned type identity; refusing them avoids equating unrelated definitions.
25901fn obj_signature f ulong to void
25902if gt a_gu 23 f 13
25903note d2site 617|obj_signature: type mismatch; condition if gt a_gu 23 f 13
25904put d2site 0 617
25905fail 7
25906end
25907i = ulong 0
25908while lt i ulong a_gu 24 f
25909p = add mul f 6 i
25910if gt a_gu 35 p 13
25911note d2site 618|obj_signature: type mismatch; condition if gt a_gu 35 p 13
25912put d2site 0 618
25913fail 7
25914end
25915k = ulong a_gu 37 p
25916if and ne k 0 and ne k 2 ne k 3
25917note d2site 619|obj_signature: type mismatch; condition if and ne k 0 and ne k 2 ne k 3
25918put d2site 0 619
25919fail 7
25920end
25921if ne a_gu 38 p 0
25922note d2site 620|obj_signature: type mismatch; condition if ne a_gu 38 p 0
25923put d2site 0 620
25924fail 7
25925end
25926if and eq a_gu 32 f 2 ne a_gu 39 p 0
25927note d2site 621|obj_signature: fresh element read before it is definitely written, or fresh array passed on; condition if and eq a_gu 32 f 2 ne a_gu 39 p 0
25928put d2site 0 621
25929fail 27
25930end
25931i = add i 1
25932end
25933end
25934
25935fn obj64 v ulong to void
25936emit and v 4294967295
25937emit shr v 32
25938end
25939
25940fn objhdr at ulong v ulong to void
25941wrword at and v 4294967295
25942wrword add at 4 shr v 32
25943end
25944
25945fn obj_fn f ulong to void
25946obj_signature f
25947obj64 ulong a_gu 32 f
25948obj64 a_g 22 f
25949obj64 ulong a_gu 23 f
25950obj64 ulong a_gu 24 f
25951obj64 a_g 86 f
25952n = a_g 25 f
25953obj64 n
25954p = a_g 26 f
25955i = ulong 0
25956while lt i n
25957emitb a_ib add p i
25958i = add i 1
25959end
25960while ne and get oc 0 7 0
25961emitb 0
25962end
25963i = ulong 0
25964while lt i ulong a_gu 24 f
25965p = add mul f 6 i
25966obj64 ulong a_gu 35 p
25967obj64 ulong a_gu 37 p
25968obj64 a_g 36 p
25969obj64 ulong a_gu 38 p
25970obj64 ulong a_gu 39 p
25971i = add i 1
25972end
25973end
25974
25975note Object header, native payload and compiler-produced symbols/call relocations. No executable
25976note header is emitted. The linker owns identity verification and cross-object graph/stack checks.
25977fn obj_write to void
25978ce = get oc 0
25979i = ulong 0
25980while lt i 176
25981wrword i 0
25982i = add i 4
25983end
25984objhdr 0 3544386002238786895
25985objhdr 8 1
25986objhdr 16 1
25987objhdr 24 get crel 0
25988objhdr 32 176
25989objhdr 40 ce
25990objhdr 48 get nf 0
25991objhdr 56 get ncalls 0
25992objhdr 64 get nexp 0
25993at = ulong 176
25994f = ulong 0
25995go = true
25996while go
25997chunk = ulong 0
25998while and go lt chunk 999999
25999if ge f get nf 0
26000go = false
26001else
26002if eq a_gu 32 f 1
26003wrword at or 335544320 bdisp at a_g 22 f 26
26004at = add at 4
26005end
26006f = add f 1
26007end
26008chunk = add chunk 1
26009end
26010end
26011put objmeta 0 1
26012f = ulong 0
26013go = true
26014while go
26015chunk = ulong 0
26016while and go lt chunk 999999
26017if ge f get nf 0
26018go = false
26019else
26020obj_fn f
26021f = add f 1
26022end
26023chunk = add chunk 1
26024end
26025end
26026i = ulong 0
26027go = true
26028while go
26029chunk = ulong 0
26030while and go lt chunk 999999
26031if ge i get ncalls 0
26032go = false
26033else
26034obj64 a_g 41 i
26035obj64 sub a_g 42 i 1
26036obj64 sub a_g 43 i 1
26037obj64 a_g 87 i
26038i = add i 1
26039end
26040chunk = add chunk 1
26041end
26042end
26043a_ceilo get oc 0
26044if eq a_out 1 1 0 get oc 0 0
26045note d2site 622|obj_write: the compiler's standard output could not be written; condition if eq a_out 1 1 0 get oc 0 0
26046put d2site 0 622
26047fail 2
26048end
26049rc_emit 0
26050exit int 0
26051end