interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / src / kernel_leaf.om

121 lines · 2396 bytes Raw Blame History
1note Isolated kernel-leaf instruction envelope, not a loader or code validator.
2note Input must be exact compiler-produced kleaf bytes with source/compiler custody.
3note Target matches Linux 7.0.0-1019-nvidia tracing 4,2 and PAC property, no BTI config.
4note No arbitrary external symbols, effects, C implementation, device or kernel access.
5global src uchar 4097
6global out uchar 65536
7global cursor ulong 1
8global digits uchar 20
9text head ".text\n.p2align 3\n.Lkleaf_start:\n"
10text entry ".global omega_kernel_unit\n.type omega_kernel_unit,%function\nomega_kernel_unit:\n"
11text inst ".inst "
12text tail ".size omega_kernel_unit,.-omega_kernel_unit\n.pushsection __patchable_function_entries,\"awo\",%progbits,.Lkleaf_start\n.p2align 3\n.xword .Lkleaf_start\n.popsection\n.section .note.GNU-stack,\"\",%progbits\n.section .note.gnu.property,\"a\"\n.p2align 3\n.long 2f-1f,6f-3f,5\n1: .asciz \"GNU\"\n2: .p2align 3\n3: .long 0xc0000000,5f-4f\n4: .long 2\n5: .p2align 3\n6:\n"
13fn putc c uchar to void
14p = get cursor 0
15if ge p len out
16trap 10
17end
18put out p c
19put cursor 0 add p 1
20end
21fn append id ulong to void
22if eq id 0
23for i ulong len head
24putc get head i
25end
26end
27if eq id 1
28for i ulong len entry
29putc get entry i
30end
31end
32if eq id 2
33for i ulong len inst
34putc get inst i
35end
36end
37if eq id 3
38for i ulong len tail
39putc get tail i
40end
41end
42end
43fn decimal v ulong to void
44n = ulong 0
45x = v
46go = true
47while go
48put digits n uchar add rem x 10 48
49n = add n 1
50x = div x 10
51if eq x 0
52go = false
53end
54end
55while gt n 0
56n = sub n 1
57p = get cursor 0
58if ge p len out
59trap 10
60end
61put out p get digits n
62put cursor 0 add p 1
63end
64p = get cursor 0
65put out p uchar 10
66put cursor 0 add p 1
67end
68fn word at ulong to ulong
69v = ulong 0
70for i ulong 4
71v = or v shl ulong get src add at i mul i 8
72end
73ret v
74end
75fn main to int
76n = ulong 0
77go = true
78while go
79if ge n len src
80ret 110
81end
82r = read 0 src n sub len src n
83if lt r 0
84ret 110
85end
86if eq r 0
87go = false
88else
89n = add n ulong r
90end
91end
92if or or lt n 20 gt n 4096 ne rem n 4 0
93ret 110
94end
95note Wolfram FromDigits["d503201f",16] = 3573751839, matches configured GCC ftrace oracle.
96for i ulong 4
97if ne word mul i 4 3573751839
98ret 110
99end
100end
101append 0
102p = ulong 0
103while lt p n
104if eq p 8
105append 1
106end
107append 2
108decimal word p
109p = add p 4
110end
111append 3
112p = ulong 0
113while lt p get cursor 0
114r = write 1 out p sub get cursor 0 p
115if le r 0
116ret 110
117end
118p = add p ulong r
119end
120ret 0
121end