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