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 / om / runtime / rx_coherent_om2.om

72 lines · 1562 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: AGPL-3.0-only
3note Pure seeded OM-2 coherent projection primitives backing src/runtime/rx_coherent.c:
4note Castagnoli CRC32C, ring message validation, required rights, and fault code mapping.
5
6const CRC32C_POLY ulong 0x82f63b78
7const U32_MASK ulong 0xffffffff
8
9note Compute Castagnoli CRC32C over data[0..n-1].
10export fn rx_coh_crc32c data view uchar * n ulong to ulong
11 c = U32_MASK
12 for i ulong n bound 65536
13 b = ulong get data i
14 c = xor c b
15 for bit ulong 8
16 low = and c 1
17 c = shr c 1
18 if ne low 0
19 c = xor c CRC32C_POLY
20 end
21 end
22 end
23 ret and xor c U32_MASK U32_MASK
24end
25
26note Validate coherent ring message type. Returns 1 if valid, 0 otherwise.
27export fn rx_coh_ring_msg t ulong to ulong
28 if eq t 0x0003
29 ret 1
30 end
31 if and ge t 0x0010 le t 0x0015
32 ret 1
33 end
34 ret 0
35end
36
37note Return required capability right for ring message type: READ (1) or WRITE (2).
38export fn rx_coh_msg_rights t ulong to ulong
39 if eq t 0x0003
40 ret 1
41 end
42 if or eq t 0x0010 eq t 0x0011
43 ret 1
44 end
45 if or eq t 0x0013 eq t 0x0014
46 ret 1
47 end
48 ret 2
49end
50
51note Map OMEGA_SW_FAULT_* / RX_FAULT_* to RX_ERR_*.
52export fn rx_coh_fault_err fault ulong to long
53 if or eq fault 0x0004 eq fault 0x0105
54 ret -3
55 end
56 if eq fault 0x0005
57 ret -21
58 end
59 if or eq fault 0x0008 eq fault 0x0103
60 ret -22
61 end
62 if or eq fault 0x0007 or eq fault 0x0101 eq fault 0x0104
63 ret -20
64 end
65 if eq fault 0x0102
66 ret -4
67 end
68 if eq fault 0x0106
69 ret -24
70 end
71 ret -23
72end