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 / gpu / driver / gsp / bootfs.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note gpu/driver/gsp/bootfs.om: Pure-Omega (OM-1) GB20B .fwimage BootFS 0x6d000 directory parser. |
| 3 | note Host-only parser over caller-supplied 01_file_directory.bin bytes; never opens devices or MMIO. |
| 4 | note Reference: nvidia-gb10/references/gsp-firmware-580-173-02.md (lines 18-20, MEASURED): |
| 5 | note .fwimage total size: 74,969,088 B (0x477f000) |
| 6 | note 00_libos_root_boot_code.bin: 0x0..0x6c000 (442,368 B) |
| 7 | note 01_file_directory.bin: 0x6c000..0x6e000 (8,192 B): |
| 8 | note 4,096 B zero guard page (0x6c000..0x6d000) |
| 9 | note 1,832 B BootFS directory at 0x6d000 (magic 0x81b26a705c10e14d, 12 records / 23 mappings) |
| 10 | note 2,264 B zero tail (0x6d728..0x6e000) |
| 11 | note Remaining .fwimage payload: 0x6e000..0x477f000 (74,518,528 B), tiled with 0 gaps / 0 overlaps. |
| 12 | note Clean-room wire note (NOT DETERMINED from gsp-firmware-580-173-02.md): |
| 13 | note Beyond +0 magic (u64 LE) and total directory size (1,832 B), internal header/record/mapping |
| 14 | note field offsets of NVIDIA's LibosBootfs structs are NOT DETERMINED in gsp-firmware-580-173-02.md. |
| 15 | note This unit defines an explicit self-describing little-endian record/mapping layout at 0x6d000: |
| 16 | note Header (16 B): +0 u64 magic, +8 u32 dir_bytes (16..4096), +12 u32 rec_count (1..64). |
| 17 | note Record (rec_size B, 8B-aligned, >= 16 B): |
| 18 | note +0 u32 rec_size, +4 u32 map_count (1..64), +8 u32 name_len, +12 u32 rec_flags, |
| 19 | note +16 map_count * 24 B mappings (each: +0 u64 fw_off, +8 u64 fw_len, +16 u64 va_attr), |
| 20 | note followed by optional name bytes (name_len) and zero padding to rec_size. |
| 21 | note Prefix bf. Library unit: no fn main. |
| 22 | |
| 23 | note ---- MEASURED 580.173.02 .fwimage / 01_file_directory.bin constants ---- |
| 24 | const BFFWIMG ulong 74969088 |
| 25 | const BFDOFF ulong 442368 |
| 26 | const BFDEND ulong 450560 |
| 27 | const BFDSZ ulong 8192 |
| 28 | const BFGUARD ulong 4096 |
| 29 | const BFBOFF ulong 446464 |
| 30 | const BFDLEN ulong 1832 |
| 31 | const BFTAIL ulong 2264 |
| 32 | const BFMAGIC ulong 9345649207560692045 |
| 33 | const BFREMLEN ulong 74518528 |
| 34 | const BFEXPREC ulong 12 |
| 35 | const BFEXPMAP ulong 23 |
| 36 | |
| 37 | note ---- Clean-room directory record/mapping layout constants (NOT DETERMINED vs NVIDIA struct) ---- |
| 38 | const BFHDRSZ ulong 16 |
| 39 | const BFRECSZ ulong 16 |
| 40 | const BFMAPSZ ulong 24 |
| 41 | const BFMAXR ulong 64 |
| 42 | const BFMAXM ulong 64 |
| 43 | |
| 44 | note ---- Caller input buffer and parsed directory state ---- |
| 45 | global bfbuf uchar 8192 |
| 46 | global bfdirsz ulong 1 |
| 47 | global bfrcnt ulong 1 |
| 48 | global bfmcnt ulong 1 |
| 49 | global bfcov ulong 1 |
| 50 | global bfroff ulong 64 |
| 51 | global bfrlen ulong 64 |
| 52 | global bfrmcnt ulong 64 |
| 53 | global bfrnlen ulong 64 |
| 54 | global bfrflg ulong 64 |
| 55 | global bfmrec ulong 64 |
| 56 | global bfmoff ulong 64 |
| 57 | global bfmlen ulong 64 |
| 58 | global bfmva ulong 64 |
| 59 | global bford ulong 64 |
| 60 | |
| 61 | note ---- Little-endian readers over bfbuf (bounds-checked by callers) ---- |
| 62 | fn bfu32 o ulong to ulong |
| 63 | v = ulong 0 |
| 64 | for i ulong 4 |
| 65 | b = ulong get bfbuf add o i |
| 66 | v = or v shl b mul i 8 |
| 67 | end |
| 68 | ret v |
| 69 | end |
| 70 | |
| 71 | fn bfu64 o ulong to ulong |
| 72 | v = ulong 0 |
| 73 | for i ulong 8 |
| 74 | b = ulong get bfbuf add o i |
| 75 | v = or v shl b mul i 8 |
| 76 | end |
| 77 | ret v |
| 78 | end |
| 79 | |
| 80 | note ---- State reset ---- |
| 81 | fn bfreset to void |
| 82 | put bfdirsz 0 0 |
| 83 | put bfrcnt 0 0 |
| 84 | put bfmcnt 0 0 |
| 85 | put bfcov 0 0 |
| 86 | end |
| 87 | |
| 88 | note ---- Zero-region verifier over bfbuf[start .. start + count) ---- |
| 89 | fn bfchkzero start ulong count ulong to bool |
| 90 | if gt start BFDSZ |
| 91 | ret false |
| 92 | end |
| 93 | if gt count sub BFDSZ start |
| 94 | ret false |
| 95 | end |
| 96 | for i ulong count |
| 97 | if ne get bfbuf add start i 0 |
| 98 | ret false |
| 99 | end |
| 100 | end |
| 101 | ret true |
| 102 | end |
| 103 | |
| 104 | note ---- Stage 1: verify 4,096 B zero guard page (0x6c000..0x6d000) ---- |
| 105 | fn bfchkguard to long |
| 106 | if not bfchkzero 0 BFGUARD |
| 107 | ret -2 |
| 108 | end |
| 109 | ret 0 |
| 110 | end |
| 111 | |
| 112 | note ---- Stage 2: verify BootFS directory header at 0x6d000 (bfbuf + 4096) ---- |
| 113 | fn bfchkhdr to long |
| 114 | if ne bfu64 BFGUARD BFMAGIC |
| 115 | ret -3 |
| 116 | end |
| 117 | dsz = bfu32 add BFGUARD 8 |
| 118 | if or lt dsz BFHDRSZ gt dsz sub BFDSZ BFGUARD |
| 119 | ret -4 |
| 120 | end |
| 121 | rc = bfu32 add BFGUARD 12 |
| 122 | if or eq rc 0 gt rc BFMAXR |
| 123 | ret -5 |
| 124 | end |
| 125 | put bfdirsz 0 dsz |
| 126 | put bfrcnt 0 rc |
| 127 | ret 0 |
| 128 | end |
| 129 | |
| 130 | note ---- Stage 3: verify zero tail (0x6d000 + dir_bytes .. 0x6e000) ---- |
| 131 | fn bfchktail to long |
| 132 | dsz = get bfdirsz 0 |
| 133 | tstart = add BFGUARD dsz |
| 134 | tlen = sub BFDSZ tstart |
| 135 | if not bfchkzero tstart tlen |
| 136 | ret -6 |
| 137 | end |
| 138 | ret 0 |
| 139 | end |
| 140 | |
| 141 | note ---- Stage 4: parse one record at bfbuf[cur .. endpos) ---- |
| 142 | fn bfwalkrec ridx ulong cur ulong endpos ulong to long |
| 143 | if gt cur endpos |
| 144 | ret -7 |
| 145 | end |
| 146 | remb = sub endpos cur |
| 147 | if lt remb BFRECSZ |
| 148 | ret -7 |
| 149 | end |
| 150 | rsz = bfu32 cur |
| 151 | mc = bfu32 add cur 4 |
| 152 | nlen = bfu32 add cur 8 |
| 153 | if or lt rsz BFRECSZ gt rsz remb |
| 154 | ret -7 |
| 155 | end |
| 156 | if ne and rsz 7 0 |
| 157 | ret -7 |
| 158 | end |
| 159 | if or eq mc 0 gt mc BFMAXM |
| 160 | ret -7 |
| 161 | end |
| 162 | mbase = get bfmcnt 0 |
| 163 | if gt add mbase mc BFMAXM |
| 164 | ret -7 |
| 165 | end |
| 166 | need = add BFRECSZ mul mc BFMAPSZ |
| 167 | if gt need rsz |
| 168 | ret -7 |
| 169 | end |
| 170 | if gt nlen sub rsz need |
| 171 | ret -7 |
| 172 | end |
| 173 | put bfroff ridx cur |
| 174 | put bfrlen ridx rsz |
| 175 | put bfrmcnt ridx mc |
| 176 | put bfrnlen ridx nlen |
| 177 | put bfrflg ridx bfu32 add cur 12 |
| 178 | for j ulong mc |
| 179 | mo = add cur add BFRECSZ mul j BFMAPSZ |
| 180 | mi = add mbase j |
| 181 | put bfmrec mi ridx |
| 182 | put bfmoff mi bfu64 mo |
| 183 | put bfmlen mi bfu64 add mo 8 |
| 184 | put bfmva mi bfu64 add mo 16 |
| 185 | end |
| 186 | put bfmcnt 0 add mbase mc |
| 187 | ret long rsz |
| 188 | end |
| 189 | |
| 190 | note ---- Stage 4 driver: walk all bfrcnt records inside [4096 + 16 .. 4096 + bfdirsz) ---- |
| 191 | fn bfwalk to long |
| 192 | rc = get bfrcnt 0 |
| 193 | cur = add BFGUARD BFHDRSZ |
| 194 | endpos = add BFGUARD get bfdirsz 0 |
| 195 | for r ulong rc |
| 196 | step = bfwalkrec r cur endpos |
| 197 | if lt step 0 |
| 198 | ret step |
| 199 | end |
| 200 | cur = add cur ulong step |
| 201 | end |
| 202 | if ne cur endpos |
| 203 | ret -7 |
| 204 | end |
| 205 | mc = get bfmcnt 0 |
| 206 | if eq mc 0 |
| 207 | ret -7 |
| 208 | end |
| 209 | ret long mc |
| 210 | end |
| 211 | |
| 212 | note ---- Sort mapping indices 0..bfmcnt-1 by ascending bfmoff into bford ---- |
| 213 | fn bfsort to void |
| 214 | mc = get bfmcnt 0 |
| 215 | for i ulong mc |
| 216 | put bford i i |
| 217 | end |
| 218 | i = ulong 1 |
| 219 | while lt i mc bound 64 |
| 220 | key = get bford i |
| 221 | koff = get bfmoff key |
| 222 | j = i |
| 223 | while gt j 0 bound 64 |
| 224 | prev = get bford sub j 1 |
| 225 | if le get bfmoff prev koff |
| 226 | break |
| 227 | end |
| 228 | put bford j prev |
| 229 | j = sub j 1 |
| 230 | end |
| 231 | put bford j key |
| 232 | i = add i 1 |
| 233 | end |
| 234 | end |
| 235 | |
| 236 | note ---- Stage 5: verify bounds, non-overlap, and zero-gap tiling of [base .. base + span) ---- |
| 237 | note Returns 0 on exact tiling, -8 bounds violation, -9 overlap, -10 gap. |
| 238 | fn bftilechk base ulong span ulong to long |
| 239 | if eq span 0 |
| 240 | ret -8 |
| 241 | end |
| 242 | mc = get bfmcnt 0 |
| 243 | if eq mc 0 |
| 244 | ret -8 |
| 245 | end |
| 246 | lim = add base span |
| 247 | for i ulong mc |
| 248 | mo = get bfmoff i |
| 249 | ml = get bfmlen i |
| 250 | if eq ml 0 |
| 251 | ret -8 |
| 252 | end |
| 253 | if or lt mo base gt mo lim |
| 254 | ret -8 |
| 255 | end |
| 256 | if gt ml sub lim mo |
| 257 | ret -8 |
| 258 | end |
| 259 | end |
| 260 | bfsort |
| 261 | expect = base |
| 262 | tot = ulong 0 |
| 263 | for i ulong mc |
| 264 | idx = get bford i |
| 265 | mo = get bfmoff idx |
| 266 | ml = get bfmlen idx |
| 267 | if lt mo expect |
| 268 | ret -9 |
| 269 | end |
| 270 | if gt mo expect |
| 271 | ret -10 |
| 272 | end |
| 273 | expect = add mo ml |
| 274 | tot = add tot ml |
| 275 | end |
| 276 | if ne expect lim |
| 277 | ret -10 |
| 278 | end |
| 279 | if ne tot span |
| 280 | ret -10 |
| 281 | end |
| 282 | put bfcov 0 tot |
| 283 | ret 0 |
| 284 | end |
| 285 | |
| 286 | note ---- Full parser/validator over bfbuf[0..n) for .fwimage of total size fwsz ---- |
| 287 | note Returns mapping count (>= 1) on success, or negative error: |
| 288 | note -1 truncated buffer (n < 8192) or invalid fwsz (<= 0x6e000) |
| 289 | note -2 non-zero byte in 4,096 B guard page (0x6c000..0x6d000) |
| 290 | note -3 bad BootFS magic at 0x6d000 (not 0x81b26a705c10e14d) |
| 291 | note -4 invalid directory byte size (< 16 or > 4096) |
| 292 | note -5 invalid record count (0 or > 64) |
| 293 | note -6 non-zero byte in zero tail (0x6d000 + dir_bytes .. 0x6e000) |
| 294 | note -7 malformed or truncated record/mapping table or trailing dir bytes |
| 295 | note -8 mapping out of [0x6e000 .. fwsz) bounds or zero length |
| 296 | note -9 overlapping mappings |
| 297 | note -10 gap in tiling of [0x6e000 .. fwsz) |
| 298 | fn bfparse n ulong fwsz ulong to long |
| 299 | bfreset |
| 300 | if or lt n BFDSZ le fwsz BFDEND |
| 301 | ret -1 |
| 302 | end |
| 303 | r = bfchkguard |
| 304 | if lt r 0 |
| 305 | ret r |
| 306 | end |
| 307 | r = bfchkhdr |
| 308 | if lt r 0 |
| 309 | ret r |
| 310 | end |
| 311 | r = bfchktail |
| 312 | if lt r 0 |
| 313 | ret r |
| 314 | end |
| 315 | r = bfwalk |
| 316 | if lt r 0 |
| 317 | ret r |
| 318 | end |
| 319 | t = bftilechk BFDEND sub fwsz BFDEND |
| 320 | if lt t 0 |
| 321 | ret t |
| 322 | end |
| 323 | ret r |
| 324 | end |
| 325 | |
| 326 | note ---- Pinned 580.173.02 validator: checks exact 74,969,088 B .fwimage, 1,832 B dir, 12 rec / 23 maps ---- |
| 327 | note Returns 23 on success, -1..-10 from bfparse, or -11 if 580.173.02 counts/sizes differ. |
| 328 | fn bfparse580 n ulong to long |
| 329 | r = bfparse n BFFWIMG |
| 330 | if lt r 0 |
| 331 | ret r |
| 332 | end |
| 333 | if ne get bfdirsz 0 BFDLEN |
| 334 | ret -11 |
| 335 | end |
| 336 | if ne get bfrcnt 0 BFEXPREC |
| 337 | ret -11 |
| 338 | end |
| 339 | if ne get bfmcnt 0 BFEXPMAP |
| 340 | ret -11 |
| 341 | end |
| 342 | ret r |
| 343 | end |
| 344 | |
| 345 | note ---- Read-only accessors ---- |
| 346 | fn bfdirlen to ulong |
| 347 | ret get bfdirsz 0 |
| 348 | end |
| 349 | |
| 350 | fn bfrecn to ulong |
| 351 | ret get bfrcnt 0 |
| 352 | end |
| 353 | |
| 354 | fn bfmapn to ulong |
| 355 | ret get bfmcnt 0 |
| 356 | end |
| 357 | |
| 358 | fn bfcovered to ulong |
| 359 | ret get bfcov 0 |
| 360 | end |
| 361 | |
| 362 | fn bfmapoff i ulong to ulong |
| 363 | if ge i get bfmcnt 0 |
| 364 | ret 0 |
| 365 | end |
| 366 | ret get bfmoff i |
| 367 | end |
| 368 | |
| 369 | fn bfmaplen i ulong to ulong |
| 370 | if ge i get bfmcnt 0 |
| 371 | ret 0 |
| 372 | end |
| 373 | ret get bfmlen i |
| 374 | end |
| 375 | |
| 376 | fn bfmapva i ulong to ulong |
| 377 | if ge i get bfmcnt 0 |
| 378 | ret 0 |
| 379 | end |
| 380 | ret get bfmva i |
| 381 | end |
| 382 | |
| 383 | fn bfmaprec i ulong to ulong |
| 384 | if ge i get bfmcnt 0 |
| 385 | ret 0 |
| 386 | end |
| 387 | ret get bfmrec i |
| 388 | end |