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 / tests / slice_c_gate.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note tests/slice_c_gate.om: Host replay gate for Phase 2 Slice C (GB20B bare-metal GSP boot & |
| 3 | note compute channel 0xca6f/0xcec0 in pure .om, zero 184 MiB .bss, zero Linux syscalls in bare-metal units). |
| 4 | note Build: |
| 5 | note cat gpu/driver/gsp/bm_hal.om gpu/driver/gsp/profile.om gpu/driver/gsp/mmio_bm.om \ |
| 6 | note gpu/driver/gsp/sec2.om gpu/driver/gsp/seq.om gpu/driver/gsp/seqcore.om \ |
| 7 | note gpu/driver/gsp/rpc.om gpu/driver/gsp/sysinfo.om gpu/driver/chan/params.om \ |
| 8 | note gpu/driver/gsp/boot.om gpu/driver/gsp/dispatch.om gpu/driver/gsp/fw_bm.om \ |
| 9 | note gpu/driver/gsp/arena_bm.om gpu/driver/gsp/transport_bm.om \ |
| 10 | note gpu/driver/chan/gmmu_bm.om gpu/driver/chan/mem.om gpu/driver/chan/chan.om \ |
| 11 | note gpu/driver/chan/complete.om gpu/driver/chan/rmchan.om \ |
| 12 | note gpu/driver/tests/slice_c_gate.om | seed/out/omc > slice_c_gate |
| 13 | note Host replay ONLY; never touches real Spark silicon (hardware=NOT_RUN). |
| 14 | |
| 15 | const TBASE ulong 2147483648 |
| 16 | const TRAMSZ ulong 4194304 |
| 17 | const THEAPPA ulong 3221225472 |
| 18 | const THEAPSZ ulong 139460608 |
| 19 | const TBARSZ ulong 16777216 |
| 20 | const TFRQ ulong 1000000000 |
| 21 | const TBOOT42 uint 465178624 |
| 22 | |
| 23 | text TPASS "PASS slice_c_gate\n" |
| 24 | text TGNUN "GNU" |
| 25 | text TSTG "123456\n" |
| 26 | |
| 27 | note Small 4 MiB host replay RAM + BAR0 register model (replaces 184 MiB host-sim .bss) |
| 28 | global tram uchar 4194304 |
| 29 | global ttick ulong 1 |
| 30 | global tsec2st ulong 1 |
| 31 | global tmsgqok ulong 1 |
| 32 | global ttailfirst ulong 1 |
| 33 | global tememw ulong 1 |
| 34 | global tememr ulong 1 |
| 35 | global temem uchar 1024 |
| 36 | global ts2rsp uchar 24 |
| 37 | global tbellcnt ulong 1 |
| 38 | global tlastdb ulong 1 |
| 39 | global tlastreg ulong 1 |
| 40 | global tseqreg ulong 1 |
| 41 | global tcorest ulong 1 |
| 42 | global tmmutrig ulong 1 |
| 43 | global tmmpdb ulong 1 |
| 44 | global tmmupr ulong 1 |
| 45 | global trmseq uint 1 |
| 46 | global tfreeord ulong 8 |
| 47 | global tfreecnt ulong 1 |
| 48 | global tengst ulong 1 |
| 49 | global tfbif ulong 1 |
| 50 | global tdmactl ulong 1 |
| 51 | global tgspalias ulong 1 |
| 52 | global tbcr ulong 1 |
| 53 | global tmb0 ulong 1 |
| 54 | global tmb1 ulong 1 |
| 55 | global tsecalias ulong 1 |
| 56 | global tgos ulong 1 |
| 57 | |
| 58 | fn tck ok bool to void |
| 59 | if not ok |
| 60 | trap 1 |
| 61 | end |
| 62 | end |
| 63 | |
| 64 | note Stubs for dead simulator branches in sec2.om and chan.om (never called in gspmode=2 / mmmode=2) |
| 65 | fn s2simrd off ulong to ulong |
| 66 | trap 9 |
| 67 | end |
| 68 | fn s2simwr off ulong v ulong to void |
| 69 | trap 9 |
| 70 | end |
| 71 | fn gsbind chid uint tok uint ent uint gpva ulong upa ulong ipa ulong to long |
| 72 | trap 9 |
| 73 | end |
| 74 | fn gsdisable chid uint to long |
| 75 | trap 9 |
| 76 | end |
| 77 | fn gsidle chid uint to long |
| 78 | trap 9 |
| 79 | end |
| 80 | |
| 81 | note Host replay callbacks for bm_hal.om |
| 82 | fn bmrcntvct to ulong |
| 83 | t = get ttick 0 |
| 84 | put ttick 0 add t 10000 |
| 85 | ret t |
| 86 | end |
| 87 | |
| 88 | fn bmrmemrd8 pa ulong to uchar |
| 89 | o = sub pa TBASE |
| 90 | if ge o TRAMSZ |
| 91 | trap 3 |
| 92 | end |
| 93 | ret get tram o |
| 94 | end |
| 95 | |
| 96 | fn bmrmemwr8 pa ulong v uchar to void |
| 97 | o = sub pa TBASE |
| 98 | if ge o TRAMSZ |
| 99 | trap 3 |
| 100 | end |
| 101 | put tram o v |
| 102 | end |
| 103 | |
| 104 | fn bmrbarrd off ulong to ulong |
| 105 | note FWSEC scratch 0x5e0 (1504): returns 0xFF |
| 106 | if eq off 1504 |
| 107 | ret 255 |
| 108 | end |
| 109 | note SEC2 QUEUE_HEAD(0) 0x840c00 / QUEUE_TAIL(0) 0x840c04: empty |
| 110 | if or eq off 8653824 eq off 8653828 |
| 111 | ret 0 |
| 112 | end |
| 113 | note SEC2 EMEMC(0) 0x840ac0: return current dword offset in [7:2] and block in [15:8] |
| 114 | if eq off 8653504 |
| 115 | dw = get tememw 0 |
| 116 | if ne get tsec2st 0 1 |
| 117 | dw = get tememr 0 |
| 118 | end |
| 119 | blk = div dw 64 |
| 120 | remdw = rem dw 64 |
| 121 | ret or shl blk 8 shl remdw 2 |
| 122 | end |
| 123 | note SEC2 EMEMD(0) 0x840ac4: return reply dword when reading MSGQ (reply starts at dword 4) |
| 124 | if eq off 8653508 |
| 125 | dw = get tememr 0 |
| 126 | put tememr 0 add dw 1 |
| 127 | if lt dw 4 |
| 128 | ret 0 |
| 129 | end |
| 130 | o = mul sub dw 4 4 |
| 131 | if gt add o 4 24 |
| 132 | ret 0 |
| 133 | end |
| 134 | v = ulong 0 |
| 135 | for i ulong 4 |
| 136 | v = or v shl ulong get ts2rsp add o i mul i 8 |
| 137 | end |
| 138 | ret v |
| 139 | end |
| 140 | note SEC2 MSGQ_HEAD(0) 0x840c80 / MSGQ_TAIL(0) 0x840c84 |
| 141 | if eq off 8653952 |
| 142 | if eq get tsec2st 0 2 |
| 143 | ret 16 |
| 144 | end |
| 145 | ret 16 |
| 146 | end |
| 147 | if eq off 8653956 |
| 148 | if eq get tsec2st 0 2 |
| 149 | ret 32 |
| 150 | end |
| 151 | ret 16 |
| 152 | end |
| 153 | note GSP HWCFG2 0x1100f4: mask released, lockdown clear, mem scrubbing clear |
| 154 | if eq off 1114356 |
| 155 | ret 1 |
| 156 | end |
| 157 | note GSP MAILBOX0 0x110040: 0 = FMC OK |
| 158 | if eq off 1114176 |
| 159 | ret 0 |
| 160 | end |
| 161 | note GSP RISCV_CPUCTL 0x111388: ACTIVE_STAT bit 7 (128) |
| 162 | if eq off 1119112 |
| 163 | ret 128 |
| 164 | end |
| 165 | note GSP FALCON_CPUCTL 0x110100: HALTED (16) | ALIAS_EN (64) = 80 |
| 166 | if eq off 1114368 |
| 167 | ret 80 |
| 168 | end |
| 169 | note GSP FALCON_RESET_PRIV_LEVEL_MASK 0x1103c4: LEVEL0 RW enabled (0x11 = 17) |
| 170 | if eq off 1115076 |
| 171 | ret 17 |
| 172 | end |
| 173 | note GSP FALCON_ENGINE 0x1103c0: RESET_STATUS = ASSERTED (0) when reset=1, DEASSERTED (0x200=512) when reset=0 |
| 174 | if eq off 1115072 |
| 175 | if eq get tengst 0 1 |
| 176 | ret 0 |
| 177 | end |
| 178 | ret 512 |
| 179 | end |
| 180 | note GSP FBIF_CTL 0x110624 |
| 181 | if eq off 1115684 |
| 182 | ret get tfbif 0 |
| 183 | end |
| 184 | note SEC2 FALCON_CPUCTL 0x840100: ALIAS_EN (64) |
| 185 | if eq off 8651008 |
| 186 | ret 64 |
| 187 | end |
| 188 | note BSI_SECURE_SCRATCH_14 0x1180f8: BOOT_STAGE_3_HANDOFF_VALUE_DONE (bit 26 = 67108864) after SEC2 start |
| 189 | if eq off 1147128 |
| 190 | if eq get tsecalias 0 2 |
| 191 | ret 67108864 |
| 192 | end |
| 193 | ret 0 |
| 194 | end |
| 195 | note SEC2 MAILBOX0 0x840040: 0 = OK |
| 196 | if eq off 8650816 |
| 197 | ret 0 |
| 198 | end |
| 199 | note Sequencer test register 0x123400 (1192960) |
| 200 | if eq off 1192960 |
| 201 | ret get tseqreg 0 |
| 202 | end |
| 203 | note GMMU invalidate 0xB830B0: trigger bit cleared immediately |
| 204 | if eq off 12071088 |
| 205 | ret 0 |
| 206 | end |
| 207 | ret 0 |
| 208 | end |
| 209 | |
| 210 | fn bmrbarwr off ulong v ulong to void |
| 211 | put tlastreg 0 off |
| 212 | note SEC2 EMEMC(0) 0x840ac0 |
| 213 | if eq off 8653504 |
| 214 | if ne and v 16777216 0 |
| 215 | put tsec2st 0 1 |
| 216 | put tememw 0 0 |
| 217 | end |
| 218 | if ne and v 33554432 0 |
| 219 | put tememr 0 ememdw v |
| 220 | end |
| 221 | ret |
| 222 | end |
| 223 | note SEC2 EMEMD(0) 0x840ac4 |
| 224 | if eq off 8653508 |
| 225 | dw = get tememw 0 |
| 226 | put tememw 0 add dw 1 |
| 227 | ret |
| 228 | end |
| 229 | note SEC2 QUEUE_HEAD(0) 0x840c00: triggers reply ready |
| 230 | if eq off 8653824 |
| 231 | put tsec2st 0 2 |
| 232 | ret |
| 233 | end |
| 234 | note SEC2 MSGQ_TAIL(0) 0x840c84 MUST be written before MSGQ_HEAD(0) 0x840c80 |
| 235 | if eq off 8653956 |
| 236 | if eq get tsec2st 0 2 |
| 237 | put ttailfirst 0 1 |
| 238 | put tsec2st 0 3 |
| 239 | end |
| 240 | ret |
| 241 | end |
| 242 | if eq off 8653952 |
| 243 | if eq get tsec2st 0 3 |
| 244 | put tmsgqok 0 1 |
| 245 | put tsec2st 0 4 |
| 246 | end |
| 247 | ret |
| 248 | end |
| 249 | note PGSP_QUEUE_HEAD(0) 0x110c00 |
| 250 | if eq off 1117184 |
| 251 | put tbellcnt 0 add get tbellcnt 0 1 |
| 252 | ret |
| 253 | end |
| 254 | note BAR0 VF Doorbell 0x00BB0090 (12255376) |
| 255 | if eq off 12255376 |
| 256 | put tlastdb 0 v |
| 257 | ret |
| 258 | end |
| 259 | note Sequencer test register 0x123400 (1192960) |
| 260 | if eq off 1192960 |
| 261 | put tseqreg 0 v |
| 262 | ret |
| 263 | end |
| 264 | note GB20B seqcore registers |
| 265 | if eq off 1115072 |
| 266 | put tengst 0 v |
| 267 | ret |
| 268 | end |
| 269 | if eq off 1115684 |
| 270 | put tfbif 0 v |
| 271 | ret |
| 272 | end |
| 273 | if eq off 1114380 |
| 274 | put tdmactl 0 v |
| 275 | ret |
| 276 | end |
| 277 | if eq off 1114416 |
| 278 | put tgspalias 0 v |
| 279 | ret |
| 280 | end |
| 281 | if eq off 1119848 |
| 282 | put tbcr 0 v |
| 283 | ret |
| 284 | end |
| 285 | if eq off 1114176 |
| 286 | put tmb0 0 v |
| 287 | ret |
| 288 | end |
| 289 | if eq off 1114180 |
| 290 | put tmb1 0 v |
| 291 | ret |
| 292 | end |
| 293 | if eq off 8651056 |
| 294 | put tsecalias 0 v |
| 295 | ret |
| 296 | end |
| 297 | if eq off 1114240 |
| 298 | put tgos 0 v |
| 299 | ret |
| 300 | end |
| 301 | note GMMU invalidate regs |
| 302 | if eq off 12071072 |
| 303 | put tmmpdb 0 v |
| 304 | ret |
| 305 | end |
| 306 | if eq off 12071076 |
| 307 | put tmmupr 0 v |
| 308 | ret |
| 309 | end |
| 310 | if eq off 12071088 |
| 311 | put tmmutrig 0 v |
| 312 | ret |
| 313 | end |
| 314 | end |
| 315 | |
| 316 | note Helper: write a string into replay RAM at pa and return next offset |
| 317 | fn twrstr pa ulong s ulong to ulong |
| 318 | n = ulong 0 |
| 319 | if eq s 0 |
| 320 | n = len FBNIMG |
| 321 | for i ulong n |
| 322 | bmmemwr8 add pa i get FBNIMG i |
| 323 | end |
| 324 | end |
| 325 | if eq s 1 |
| 326 | n = len FBNVER |
| 327 | for i ulong n |
| 328 | bmmemwr8 add pa i get FBNVER i |
| 329 | end |
| 330 | end |
| 331 | if eq s 2 |
| 332 | n = len FBNBID |
| 333 | for i ulong n |
| 334 | bmmemwr8 add pa i get FBNBID i |
| 335 | end |
| 336 | end |
| 337 | if eq s 3 |
| 338 | n = len FBNSIG |
| 339 | for i ulong n |
| 340 | bmmemwr8 add pa i get FBNSIG i |
| 341 | end |
| 342 | end |
| 343 | if eq s 4 |
| 344 | n = len FBVER |
| 345 | for i ulong n |
| 346 | bmmemwr8 add pa i get FBVER i |
| 347 | end |
| 348 | end |
| 349 | bmmemwr8 add pa n 0 |
| 350 | ret add n 1 |
| 351 | end |
| 352 | |
| 353 | fn twrshdr pa ulong nm ulong ty ulong of ulong sz ulong to void |
| 354 | bmmemwr32 pa nm |
| 355 | bmmemwr32 add pa 4 ty |
| 356 | bmmemwr64 add pa 24 of |
| 357 | bmmemwr64 add pa 32 sz |
| 358 | end |
| 359 | |
| 360 | note Test 1: fw_bm.om in-RAM ELF64 GspFwBundle parser (zero 16 MiB .bss) |
| 361 | fn test_fw_bm to void |
| 362 | elfpa = TBASE |
| 363 | bmmemzero elfpa 32768 |
| 364 | note ELF64 header: magic, class=2, data=1, ver=1, ET_REL=1, EM_RISCV=243, shoff=64, shentsize=64, shnum=6, shstrndx=1 |
| 365 | bmmemwr8 elfpa 127 |
| 366 | bmmemwr8 add elfpa 1 69 |
| 367 | bmmemwr8 add elfpa 2 76 |
| 368 | bmmemwr8 add elfpa 3 70 |
| 369 | bmmemwr8 add elfpa 4 2 |
| 370 | bmmemwr8 add elfpa 5 1 |
| 371 | bmmemwr8 add elfpa 6 1 |
| 372 | bmmemwr32 add elfpa 16 or 1 shl ulong 243 16 |
| 373 | bmmemwr64 add elfpa 40 64 |
| 374 | bmmemwr32 add elfpa 56 shl ulong 64 16 |
| 375 | bmmemwr32 add elfpa 60 or 6 shl ulong 1 16 |
| 376 | note String table at offset 1024 |
| 377 | sp = add elfpa 1024 |
| 378 | bmmemwr8 sp 0 |
| 379 | o0 = ulong 1 |
| 380 | o1 = add o0 twrstr add sp o0 0 |
| 381 | o2 = add o1 twrstr add sp o1 1 |
| 382 | o3 = add o2 twrstr add sp o2 2 |
| 383 | o4 = add o3 twrstr add sp o3 3 |
| 384 | note Section data: .fwversion at 2048, .note.gnu.build-id at 2112, .fwsignature_gb20y at 4096 (4096 B), .fwimage at 8192 (8192 B) |
| 385 | vlen = twrstr add elfpa 2048 4 |
| 386 | np = add elfpa 2112 |
| 387 | bmmemwr32 np 4 |
| 388 | bmmemwr32 add np 4 20 |
| 389 | bmmemwr32 add np 8 3 |
| 390 | for i ulong 3 |
| 391 | bmmemwr8 add np add 12 i get TGNUN i |
| 392 | end |
| 393 | bmmemwr8 add np 15 0 |
| 394 | bmmemwr8 add elfpa 4096 171 |
| 395 | bmmemwr8 add elfpa 8192 205 |
| 396 | note Section headers at offset 64 (6 * 64 = 384 bytes) |
| 397 | sh = add elfpa 64 |
| 398 | twrshdr sh 0 0 0 0 |
| 399 | twrshdr add sh 64 0 3 1024 o4 |
| 400 | twrshdr add sh 128 o0 1 8192 8192 |
| 401 | twrshdr add sh 192 o1 1 2048 vlen |
| 402 | twrshdr add sh 256 o2 7 2112 36 |
| 403 | twrshdr add sh 320 o3 1 4096 4096 |
| 404 | note Negative check: elfpa == 0 refused cleanly with FBEHDR |
| 405 | tck eq fbparseelf 0 16384 FBEHDR |
| 406 | tck eq fbparseelf elfpa 16384 FBOK |
| 407 | tck eq get fbimgpa 0 add elfpa 8192 |
| 408 | tck eq get fbimgsz 0 8192 |
| 409 | tck eq get fbsigpa 0 add elfpa 4096 |
| 410 | tck eq get fbsigsz 0 4096 |
| 411 | note Negative check: bad signature size (4095) refused with FBESIG |
| 412 | bmmemwr64 add add sh 320 32 4095 |
| 413 | tck eq fbparseelf elfpa 16384 FBESIG |
| 414 | bmmemwr64 add add sh 320 32 4096 |
| 415 | note Negative check: bad version string refused with FBEVER |
| 416 | bmmemwr8 add elfpa 2057 49 |
| 417 | tck eq fbparseelf elfpa 16384 FBEVER |
| 418 | bmmemwr8 add elfpa 2057 50 |
| 419 | note Negative check: elfpa == 0 refused cleanly with FBEHDR |
| 420 | tck eq fbparseelf 0 16384 FBEHDR |
| 421 | tck eq fbparseelf elfpa 16384 FBOK |
| 422 | test_fw_blobs |
| 423 | end |
| 424 | |
| 425 | fn test_fw_blobs to void |
| 426 | note Bind 5 pre-extracted GB20B bindata blobs in replay RAM (offsets 65536..524288) |
| 427 | blpa = add TBASE 65536 |
| 428 | fmcpa = add TBASE 286720 |
| 429 | hshpa = add TBASE 507904 |
| 430 | pkpa = add TBASE 512000 |
| 431 | sgpa = add TBASE 516096 |
| 432 | bmmemwr8 hshpa 90 |
| 433 | bmmemwr8 pkpa 165 |
| 434 | bmmemwr8 sgpa 60 |
| 435 | tck eq fbbindblobs blpa 212991 fmcpa 212296 hshpa pkpa FBEBLOB |
| 436 | tck eq fbbindblobs blpa 212992 fmcpa 212296 hshpa pkpa FBOK |
| 437 | tck eq fbbindsig sgpa 12345 FBOK |
| 438 | end |
| 439 | |
| 440 | note Test 2: arena_bm.om direct Normal-NC Profile 2 composition (zero 160 MiB .bss, empty RPC 73) |
| 441 | fn test_arena_bm to void |
| 442 | sireset |
| 443 | tck eq siseti 0 603979776 SIEOK |
| 444 | tck eq siseti 4 64424509696 SIEOK |
| 445 | siencode |
| 446 | abp = add TBASE 1048576 |
| 447 | note Negative checks (#67): basepa==0, overlapping arena/heap, missing fbfsigpa==0 |
| 448 | tck eq abbuild 0 2621440 THEAPPA THEAPSZ ABECFG |
| 449 | tck eq abbuild abp 2621440 abp THEAPSZ ABECFG |
| 450 | savsig = get fbfsigpa 0 |
| 451 | put fbfsigpa 0 0 |
| 452 | tck eq abbuild abp 2621440 THEAPPA THEAPSZ ABECFG |
| 453 | put fbfsigpa 0 savsig |
| 454 | tck eq abbuild abp 2621440 THEAPPA THEAPSZ ABOK |
| 455 | note Verify WPR meta magic, rev=1, 133 MiB heap, CrashCat +224/+232 |
| 456 | w = abpa 0 |
| 457 | tck eq bmmemrd64 w ABWPRMAG |
| 458 | tck eq bmmemrd64 add w 8 1 |
| 459 | tck eq bmmemrd64 add w 128 ABHEAPSZ |
| 460 | tck eq bmmemrd64 add w 224 abpa 17 |
| 461 | tck eq bmmemrd64 add w 232 4096 |
| 462 | note Verify RPC 72 pre-queued and RPC 73 omitted (cmdq.writePtr == 1) |
| 463 | tck eq bmmemrd32 add get abcmdpa 0 16 1 |
| 464 | note Verify 868 B COTv2 packet: MCTP=0xc0000000, NVDM=0x1410de7e, ver=2, size=860, FRTS=0 |
| 465 | tck eq get abclen 0 868 |
| 466 | tck eq get abtail 0 864 |
| 467 | tck eq get abcot 3 192 |
| 468 | tck eq get abcot 8 2 |
| 469 | tck eq get abcot 44 90 |
| 470 | tck eq get abcot 92 165 |
| 471 | tck eq get abcot 476 60 |
| 472 | for i ulong 24 |
| 473 | tck eq get abcot add 20 i 0 |
| 474 | end |
| 475 | end |
| 476 | |
| 477 | note Test 3: sec2.om + mmio_bm.om in gspmode=2 (MSGQ TAIL before HEAD, CNTVCT_EL0 timer) |
| 478 | fn test_sec2_bm to void |
| 479 | tck eq bmticks2ms 1000000000 1000 |
| 480 | tck eq bmticks2us 1000000 1000 |
| 481 | tck eq bmdelayus 5000 BMOK |
| 482 | put gspmode 0 2 |
| 483 | put gspd0ok 0 1 |
| 484 | put gsppns 0 1000 |
| 485 | for i ulong 1024 |
| 486 | put gpkt i get abcot i |
| 487 | end |
| 488 | put gin 0 get abclen 0 |
| 489 | put gin 1 abpa 15 |
| 490 | put gin 2 get fbappver 0 |
| 491 | for i ulong 4 |
| 492 | put gin add i 3 4 |
| 493 | end |
| 494 | for i ulong 7 |
| 495 | put s2cfg i 1 |
| 496 | end |
| 497 | put s2cfg 0 2 |
| 498 | put s2cfg 1 2 |
| 499 | put s2cfg 2 4 |
| 500 | put s2cfg 3 4 |
| 501 | note Prepare valid 20-byte SEC2 COTv2 response: MCTP SOM|EOM, NVDM 0x1510de7e, seq=0, cmd=0x14 (20), err=0 |
| 502 | for i ulong 24 |
| 503 | put ts2rsp i 0 |
| 504 | end |
| 505 | put ts2rsp 3 192 |
| 506 | put ts2rsp 4 126 |
| 507 | put ts2rsp 5 222 |
| 508 | put ts2rsp 6 16 |
| 509 | put ts2rsp 7 21 |
| 510 | put ts2rsp 12 20 |
| 511 | tck eq s2boot TBOOT42 EOK |
| 512 | tck eq get ttailfirst 0 1 |
| 513 | tck eq get tmsgqok 0 1 |
| 514 | end |
| 515 | |
| 516 | fn tstatpub e ulong to void |
| 517 | spa = get abstatpa 0 |
| 518 | wr = bmmemrd32 add spa 16 |
| 519 | for s ulong e |
| 520 | slot = rem add wr s RQCOUNT |
| 521 | dst = add spa mul add slot 1 RQSLOT |
| 522 | src = mul s RQSLOT |
| 523 | for j ulong RQSLOT |
| 524 | bmmemwr8 add dst j get rqtmp add src j |
| 525 | end |
| 526 | end |
| 527 | bmmemwr32 add spa 16 rem add wr e RQCOUNT |
| 528 | end |
| 529 | |
| 530 | note Helper: inject one GSP->CPU message frame into statq in replay RAM |
| 531 | fn tstatpush fnid ulong seqnum ulong res ulong priv ulong n ulong to void |
| 532 | e = div add n 4175 4096 |
| 533 | for i ulong mul e 4096 |
| 534 | put rqtmp i 0 |
| 535 | end |
| 536 | rqput32 2 36 ulong get trmseq 0 |
| 537 | put trmseq 0 add get trmseq 0 1 |
| 538 | rqput32 2 40 e |
| 539 | rqput32 2 48 RQVER |
| 540 | rqput32 2 52 RQSIG |
| 541 | logn = n |
| 542 | if eq fnid 103 |
| 543 | logn = ulong 32 |
| 544 | end |
| 545 | rqput32 2 56 add 32 logn |
| 546 | rqput32 2 60 fnid |
| 547 | rqput32 2 64 res |
| 548 | rqput32 2 68 priv |
| 549 | rqput32 2 72 seqnum |
| 550 | for i ulong n |
| 551 | put rqtmp add 80 i get rqpay i |
| 552 | end |
| 553 | rqput32 2 32 rqsum 2 mul div add logn 87 8 8 |
| 554 | tstatpub e |
| 555 | end |
| 556 | |
| 557 | note Test 4: transport_bm.om + boot.om + seq.om + seqcore.om (opcodes 5..8) + RPC 54/79 |
| 558 | fn test_boot_seq_pd to void |
| 559 | note Initialize statq header in replay RAM |
| 560 | spa = get abstatpa 0 |
| 561 | bmmemwr32 spa 0 |
| 562 | bmmemwr32 add spa 4 RQQSZ |
| 563 | bmmemwr32 add spa 8 RQSLOT |
| 564 | bmmemwr32 add spa 12 RQCOUNT |
| 565 | bmmemwr32 add spa 16 0 |
| 566 | bmmemwr32 add spa 20 1 |
| 567 | bmmemwr32 add spa 24 32 |
| 568 | bmmemwr32 add spa 28 RQSLOT |
| 569 | bmmemwr32 add spa 32 0 |
| 570 | put bstate 0 4 |
| 571 | put bbudget 0 64 |
| 572 | put bstaticn 0 64 |
| 573 | put bgen 0 1 |
| 574 | note Negative checks (#67): cmdpa==0, overlapping cmdq/statq, out-of-pool cmdq |
| 575 | tck eq tbattach 0 spa TBOOT42 -1 |
| 576 | tck eq tbattach get abcmdpa 0 add get abcmdpa 0 4096 TBOOT42 -1 |
| 577 | tck eq tbattach add TBASE 8388608 spa TBOOT42 -1 |
| 578 | tck eq tbattach get abcmdpa 0 spa TBOOT42 0 |
| 579 | note [18..21]: CORE_RESET(5), CORE_START(6), CORE_WAIT_FOR_HALT(7), CORE_RESUME(8) -> ci=22, words=23 |
| 580 | rqclear 132 |
| 581 | rqput32 4 0 23 |
| 582 | rqput32 4 4 22 |
| 583 | rqput32 4 40 0 |
| 584 | rqput32 4 44 1192960 |
| 585 | rqput32 4 48 16 |
| 586 | rqput32 4 52 1 |
| 587 | rqput32 4 56 1192960 |
| 588 | rqput32 4 60 15 |
| 589 | rqput32 4 64 5 |
| 590 | rqput32 4 68 2 |
| 591 | rqput32 4 72 1192960 |
| 592 | rqput32 4 76 255 |
| 593 | rqput32 4 80 21 |
| 594 | rqput32 4 84 1 |
| 595 | rqput32 4 88 0 |
| 596 | rqput32 4 92 3 |
| 597 | rqput32 4 96 5 |
| 598 | rqput32 4 100 4 |
| 599 | rqput32 4 104 1192960 |
| 600 | rqput32 4 108 0 |
| 601 | rqput32 4 112 5 |
| 602 | rqput32 4 116 6 |
| 603 | rqput32 4 120 7 |
| 604 | rqput32 4 124 8 |
| 605 | tstatpush 4098 0 0 0 132 |
| 606 | tck eq bpoll 2 |
| 607 | tck eq get bstate 0 11 |
| 608 | dspinit |
| 609 | dspperms DSPMALL |
| 610 | put sqcore 0 1 |
| 611 | put sqbud 0 4 |
| 612 | put tdmactl 0 99 |
| 613 | sccfg abpa 1 get fbappver 0 |
| 614 | tck eq dspauto 0 |
| 615 | tck eq get bstate 0 4 |
| 616 | tck eq get tseqreg 0 21 |
| 617 | tck eq get sqsave 0 21 |
| 618 | tck eq get sccount 0 1 |
| 619 | tck eq get sccount 1 1 |
| 620 | tck eq get sccount 2 1 |
| 621 | tck eq get sccount 3 1 |
| 622 | tck eq get tfbif 0 128 |
| 623 | tck eq get tdmactl 0 0 |
| 624 | tck eq get tgspalias 0 2 |
| 625 | tck eq get tbcr 0 273 |
| 626 | tck eq get tmb0 0 and abpa 1 M32 |
| 627 | tck eq get tmb1 0 shr abpa 1 32 |
| 628 | tck eq get tsecalias 0 2 |
| 629 | tck eq get tgos 0 get fbappver 0 |
| 630 | note Inject 0x1001 (GSP_INIT_DONE) |
| 631 | rqclear 4 |
| 632 | tstatpush 4097 0 0 0 4 |
| 633 | tck eq bpoll 1 |
| 634 | tck eq get bstate 0 5 |
| 635 | note RPC 1 SET_GUEST_SYSTEM_INFO (792 B) |
| 636 | rqclear 792 |
| 637 | rqput32 4 0 580 |
| 638 | rqput32 4 4 173 |
| 639 | tck eq bguest 0 |
| 640 | tstatpush 1 ulong get rqsent 0 0 0 792 |
| 641 | tck eq bpoll 1 |
| 642 | tck eq get bstate 0 7 |
| 643 | note RPC 65 GET_GSP_STATIC_INFO (64 B) |
| 644 | tck eq bstatic 0 |
| 645 | rqclear 64 |
| 646 | tstatpush 65 ulong get rqsent 0 0 0 64 |
| 647 | tck eq bpoll 1 |
| 648 | tck eq get bstate 0 9 |
| 649 | note RPC 54 SET_PAGE_DIRECTORY (48 B) |
| 650 | for i ulong 11 |
| 651 | put pain i 0 |
| 652 | end |
| 653 | put pain 0 1001 |
| 654 | put pain 1 1002 |
| 655 | put pain 3 add TBASE 3670016 |
| 656 | put pain 4 512 |
| 657 | put pain 5 2 |
| 658 | put pain 7 1004 |
| 659 | tck eq pasetpd 48 |
| 660 | tck eq bsetpd 8 0 |
| 661 | for i ulong 48 |
| 662 | put rqpay i get pabuf i |
| 663 | end |
| 664 | tstatpush 54 ulong get rqsent 0 0 0 48 |
| 665 | tck eq bpoll 1 |
| 666 | tck eq get bstate 0 9 |
| 667 | note RPC 79 UNSET_PAGE_DIRECTORY (16 B) |
| 668 | tck eq paunsetpd 1001 1002 1004 0 16 |
| 669 | tck eq bunsetpd 8 0 |
| 670 | for i ulong 16 |
| 671 | put rqpay i get pabuf i |
| 672 | end |
| 673 | tstatpush 79 ulong get rqsent 0 0 0 16 |
| 674 | tck eq bpoll 1 |
| 675 | tck eq get bstate 0 9 |
| 676 | end |
| 677 | |
| 678 | note Test 5: gmmu_bm.om 32 GiB (29+ GiB) 2 MiB-page mapping & TLB invalidate |
| 679 | fn test_gmmu_bm to void |
| 680 | tck eq mmwinit 0 137438953472 MMEINVAL |
| 681 | tck eq mmwinit TBASE 137438953472 MMOK |
| 682 | ptpool = add TBASE 3670016 |
| 683 | tck eq mmasinit ptpool 128 MMOK |
| 684 | note Map 32 GiB (34359738368 B) of 2 MiB pages at VA 0x10_0000_0000 -> PA 0x3_2380_0000 |
| 685 | va32g = ulong 68719476736 |
| 686 | pa32g = ulong 13480493056 |
| 687 | sz32g = ulong 34359738368 |
| 688 | note Negative checks (#67): pa==0, >999998 4K pages (no Trap 4), budget==0 |
| 689 | tck eq mmmap va32g 0 MMSZ2M MMSZ2M MMAPSYS 0 MMEALIGN |
| 690 | tck eq mmmap va32g pa32g mul ulong 999999 MMSZ4K MMSZ4K MMAPSYS 0 MMERANGE |
| 691 | tck eq mminval 0 MMEINVAL |
| 692 | tck eq mmmap va32g pa32g sz32g MMSZ2M MMAPSYS 0 MMOK |
| 693 | tck eq mmwalk va32g MMSZ2M false MMWMAP |
| 694 | tck eq mmwalk add va32g sub sz32g MMSZ2M MMSZ2M false MMWMAP |
| 695 | tck eq mminval 4 MMOK |
| 696 | tck ne get tmmutrig 0 0 |
| 697 | end |
| 698 | |
| 699 | note Helper: respond to the currently pending RM RPC in boot.om |
| 700 | fn treplyrm tok ulong to void |
| 701 | f = get bfunc 0 |
| 702 | seq = get bseq 0 |
| 703 | if eq f 103 |
| 704 | n = get bplen 0 |
| 705 | rqclear add 32 n |
| 706 | for i ulong 4 |
| 707 | rqput32 4 mul i 4 get bhead i |
| 708 | end |
| 709 | rqput32 4 20 n |
| 710 | for i ulong n |
| 711 | put rqpay add 32 i get pabuf i |
| 712 | end |
| 713 | tstatpush 103 seq 0 0 add 32 n |
| 714 | ret |
| 715 | end |
| 716 | if eq f 76 |
| 717 | n = get bplen 0 |
| 718 | rqclear add 40 n |
| 719 | for i ulong 3 |
| 720 | rqput32 4 mul i 4 get bhead i |
| 721 | end |
| 722 | rqput32 4 16 n |
| 723 | if eq get bhead 2 PACMWST |
| 724 | rqput32 4 40 tok |
| 725 | else |
| 726 | for i ulong n |
| 727 | put rqpay add 40 i get pabuf i |
| 728 | end |
| 729 | end |
| 730 | tstatpush 76 seq 0 0 add 40 n |
| 731 | ret |
| 732 | end |
| 733 | if eq f 10 |
| 734 | k = get tfreecnt 0 |
| 735 | if lt k 8 |
| 736 | put tfreeord k get bhead 1 |
| 737 | put tfreecnt 0 add k 1 |
| 738 | end |
| 739 | rqclear 16 |
| 740 | rqput32 4 0 get bhead 0 |
| 741 | rqput32 4 8 get bhead 1 |
| 742 | tstatpush 10 seq 0 0 16 |
| 743 | ret |
| 744 | end |
| 745 | end |
| 746 | |
| 747 | note Test 6: rmchan.om GB20B (0xca6f + 0xcec0 + 0xc36f0108 bit-30 token + rl>=127 reject + DSB SY chain) |
| 748 | fn test_rmchan_gb20b to void |
| 749 | note Initialize mem allocator + channel slot 0 over gmmu_bm.om |
| 750 | gmbufpa = add TBASE 3407872 |
| 751 | tck eq gminit 8 gmbufpa 64 8589934592 GMOK |
| 752 | chinit |
| 753 | tck eq chprep 0 42 3 64 CHOK |
| 754 | tck eq cminit CMOK |
| 755 | tck eq gmalloc 4096 1 GMHPOLL GMOK |
| 756 | semslot = get gmout 0 |
| 757 | tck eq cmbind 0 semslot 0 get mmwgen 0 CMOK |
| 758 | tck eq rminit RMOK |
| 759 | rmcfg 1001 1002 1003 1004 1005 1006 |
| 760 | rmcfgch 1007 42 1 99 |
| 761 | rmcfg20 true 1008 |
| 762 | tck eq rmbind 0 get mmwgen 0 RMOK |
| 763 | tck eq rmstart 8 RMOK |
| 764 | note Step through ROOT -> DEV -> SUB -> VAS -> TSG -> CTX -> 0xca6f -> 0xcec0 -> RMSREADY |
| 765 | tok20 = ulong 1073938474 |
| 766 | while ne get rmst 0 RMSREADY bound 32 |
| 767 | if eq get rmst 0 RMSACHAN |
| 768 | tck eq get bhead 3 PACGPFB |
| 769 | end |
| 770 | if eq get rmst 0 RMSACMP |
| 771 | tck eq get bhead 3 PACCMP |
| 772 | end |
| 773 | treplyrm tok20 |
| 774 | tck eq rmstep 1 |
| 775 | end |
| 776 | note Schedule + GET_WORK_SUBMIT_TOKEN (0xc36f0108) -> verify bit-30 token stored in chtok[0] |
| 777 | tck eq rmsched 8 RMOK |
| 778 | treplyrm tok20 |
| 779 | tck eq rmstep 1 |
| 780 | tck eq get rmst 0 RMSWST |
| 781 | treplyrm tok20 |
| 782 | tck eq rmstep 1 |
| 783 | tck eq get rmst 0 RMSACTV |
| 784 | tck eq get rmtok 0 tok20 |
| 785 | tck eq ulong get chtok 0 tok20 |
| 786 | note Verify rl >= 127 (INVALID_RUNLIST) is rejected by both bmtokgb20 and chtokgb20chk |
| 787 | tck eq bmtokgb20 127 0 BMERANGE |
| 788 | tck eq chtokgb20chk 127 0 -1 |
| 789 | tck eq bmtokgb20 3 42 long tok20 |
| 790 | tck eq chtokgb20chk 3 42 long tok20 |
| 791 | note Verify strict DSB SY submission chain: PB(1) -> DSB(2) -> GPFIFO(3) -> DSB(2) -> USERD(4) -> DSB(2) -> DB(5) |
| 792 | put bmtrcn 0 0 |
| 793 | tck eq bmsettok 3 42 BMOK |
| 794 | gppa = get gmbpa get chgp 0 |
| 795 | udpa = get gmbpa get chud 0 |
| 796 | tck eq rmpub get mmwgen 0 RMOK |
| 797 | tck eq bmsubmit gppa udpa 8589938688 16 0 64 1 |
| 798 | put chput 0 1 |
| 799 | tck eq cmsub 0 1 CMOK |
| 800 | bmmemwr32 get gmbpa semslot 1 |
| 801 | tck eq get bmtrcn 0 7 |
| 802 | tck eq get bmtrc 0 1 |
| 803 | tck eq get bmtrc 1 2 |
| 804 | tck eq get bmtrc 2 3 |
| 805 | tck eq get bmtrc 3 2 |
| 806 | tck eq get bmtrc 4 4 |
| 807 | tck eq get bmtrc 5 2 |
| 808 | tck eq get bmtrc 6 5 |
| 809 | tck eq get tlastdb 0 tok20 |
| 810 | note Teardown: disable -> drain -> reverse free (0xcec0 freed strictly before 0xca6f) |
| 811 | tck eq rmdis 8 RMOK |
| 812 | treplyrm tok20 |
| 813 | tck eq rmstep 1 |
| 814 | tck eq get rmst 0 RMSDRAIN |
| 815 | tck eq rmdrain 0 4 RMOK |
| 816 | put tfreecnt 0 0 |
| 817 | tck eq rmfree 8 RMOK |
| 818 | while ne get rmst 0 RMSDONE bound 32 |
| 819 | treplyrm tok20 |
| 820 | tck eq rmstep 1 |
| 821 | end |
| 822 | tck eq get tfreecnt 0 8 |
| 823 | tck eq get tfreeord 0 1008 |
| 824 | tck eq get tfreeord 1 1007 |
| 825 | tck eq get tfreeord 7 1001 |
| 826 | end |
| 827 | |
| 828 | fn main to int |
| 829 | note Negative bminit checks (#67): dmabase==0, frq>18e12, mode1 barbase==0 |
| 830 | tck eq bminit 0 603979776 TBARSZ 0 TRAMSZ TFRQ BMEINVAL |
| 831 | tck eq bminit 0 603979776 TBARSZ TBASE TRAMSZ 18000000000001 BMEINVAL |
| 832 | tck eq bminit 1 0 TBARSZ TBASE TRAMSZ TFRQ BMEALIGN |
| 833 | tck eq bminit 0 603979776 TBARSZ TBASE TRAMSZ TFRQ BMOK |
| 834 | test_fw_bm |
| 835 | r = write 1 TSTG 0 1 |
| 836 | test_arena_bm |
| 837 | r = write 1 TSTG 1 1 |
| 838 | test_sec2_bm |
| 839 | r = write 1 TSTG 2 1 |
| 840 | test_boot_seq_pd |
| 841 | r = write 1 TSTG 3 1 |
| 842 | test_gmmu_bm |
| 843 | r = write 1 TSTG 4 1 |
| 844 | test_rmchan_gb20b |
| 845 | r = write 1 TSTG 5 2 |
| 846 | note Verify quarantined GMMU refuses re-init (#67) |
| 847 | tck eq mmwquar get mmwgen 0 MMOK |
| 848 | tck eq mmwinit TBASE 137438953472 MMESTATE |
| 849 | r = write 1 TPASS 0 len TPASS |
| 850 | ret 0 |
| 851 | end |