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 / aienux / allen / look-install.om

158 lines · 3263 bytes Raw Blame History
1note SPDX-License-Identifier: MIT
2note Install: the typed line `install allen on this computer` copies the running firmware image
3note from the stick's volume to the one other volume that already holds \EFI\BOOT\BOOTX64.EFI
4note (the internal EFI System Partition the C kernel made), through the compiler's file word
5note (efi 11: sub 0 counts volumes and finds the boot one, 1 reads that file, 2 writes it).
6note Nothing happens at boot; only the typed line installs. Needs look-home.om (Hmsay, hmsaid)
7note and base.om (In, Inlen) before it in the unit; look-show.om calls inmatch and ininstall.
8note Ins: 0 last attempt (ms), 1 bytes written, 2 failing step (0 none), 3 status low 16 bits.
9global Inimg uchar 4194304
10global Ins ulong 4
11text Incmd "install allen on this computer"
12text Inok "Installed on this computer: "
13text Inok2 " bytes. Shut down, take the stick out, start me again."
14text Inno "Not installed: "
15text Inno2 " status "
16text Insteps "count|boot volume|no other volume holds Allen|more than one volume holds Allen|read|write|size"
17fn inmatch to bool
18note The typed line, letters in either case, equals the command.
19n = get Inlen 0
20if ne n len Incmd
21ret false
22end
23for i ulong n
24c = get In i
25if and ge c 65 le c 90
26c = add c 32
27end
28if ne c get Incmd i
29ret false
30end
31end
32ret true
33end
34fn inchar at ulong c uchar to ulong
35if lt at len Hmsay
36put Hmsay at c
37end
38ret add at 1
39end
40fn innum at ulong v ulong to ulong
41note Decimal digits of v at position at; returns the position after them.
42d = ulong 1
43t = v
44while ge t 10
45t = div t 10
46d = add d 1
47end
48e = add at d
49p = e
50for i ulong d
51p = sub p 1
52q = inchar p uchar add 48 rem v 10
53v = div v 10
54end
55ret e
56end
57fn instep at ulong k ulong to ulong
58note Field k of Insteps (fields separated by |) at position at.
59f = ulong 0
60for i ulong len Insteps
61c = get Insteps i
62if eq c 124
63f = add f 1
64else
65if eq f k
66at = inchar at c
67end
68end
69end
70ret at
71end
72fn infail step ulong st ulong to void
73put Ins 2 add step 1
74put Ins 3 and st 65535
75at = ulong 0
76for i ulong len Inno
77at = inchar at get Inno i
78end
79at = instep at step
80for i ulong len Inno2
81at = inchar at get Inno2 i
82end
83at = innum at and st 65535
84at = inchar at 46
85put Hmsayn 0 at
86hmsaid
87end
88fn insaid bytes ulong to void
89put Ins 1 bytes
90put Ins 2 0
91put Ins 3 0
92at = ulong 0
93for i ulong len Inok
94at = inchar at get Inok i
95end
96at = innum at bytes
97for i ulong len Inok2
98at = inchar at get Inok2 i
99end
100put Hmsayn 0 at
101hmsaid
102end
103fn inholds k ulong to bool
104note True when volume k holds \EFI\BOOT\BOOTX64.EFI: a read succeeds, or fails only
105note because the file is larger than Inimg (file word code 24).
106rd = efi 11 or 1 shl k 8 Inimg 0 len Inimg
107if eq shr rd 63 0
108ret true
109end
110ret eq and rd 255 24
111end
112fn ininstall now ulong to void
113put Ins 0 now
114r = efi 11 0 Inimg 0 0
115if eq shr r 63 1
116infail 0 r
117ret
118end
119n = and r 255
120boot = and shr r 8 255
121if eq boot 255
122infail 1 n
123ret
124end
125found = ulong 0
126tgt = ulong 0
127for k ulong n
128if ne k boot
129if inholds k
130found = add found 1
131tgt = k
132end
133end
134end
135if eq found 0
136infail 2 n
137ret
138end
139if gt found 1
140infail 3 found
141ret
142end
143rd = efi 11 or 1 shl boot 8 Inimg 0 len Inimg
144if eq shr rd 63 1
145infail 4 rd
146ret
147end
148wr = efi 11 or 2 shl tgt 8 Inimg 0 rd
149if eq shr wr 63 1
150infail 5 wr
151ret
152end
153if ne wr rd
154infail 6 wr
155ret
156end
157insaid wr
158end