Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/physics-mv/blob/main/m3/tests/test_m3_authority.s # physics-mv FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `physics-mv / m3 / tests / test_m3_authority.s` 843 lines · 24225 bytes Raw Blame History 1 /* 2 * m3/tests/test_m3_authority.s - Bare-Metal Dynamic Qualification Test Suite 3 * Milestone 3: PHYSICS_EFFECTS (Sovereign Machine) 4 * 5 * Runs end-to-end derivation, attenuation, execution, rejection, revocation, 6 * receipt chaining, replay idempotency, replay conflict, and adversarial matrix. 7 * Records results in PHYSICS_BOOT_STATE + 0x200 (0x40208A00). 8 */ 9 10 .global run_m3_unit_tests 11 12 .extern submit_effect 13 .extern derive_capability 14 .extern revoke_capability 15 .extern lookup_capability 16 .extern get_receipt_count 17 .extern print_string 18 19 .section .text, "ax" 20 .balign 4 21 22 .equ TEST_RECORD_BASE, 0x40208A00 23 .equ TEST_MAGIC, 0x4D33544553545355 /* 'M3TESTSU' */ 24 25 .equ RES_UNIVERSAL_ROOT, 1 26 .equ RES_MEMORY_FRAME, 2 27 .equ RES_CONSOLE, 3 28 .equ RES_MEASUREMENT, 4 29 30 .equ OP_FRAME_GRANT, 1 31 .equ OP_FRAME_RELEASE, 2 32 .equ OP_CONSOLE_WRITE, 1 33 .equ OP_MEASUREMENT_READ, 1 34 35 .equ DEC_ADMITTED, 1 36 .equ DEC_REJECTED_STRUCTURAL, 2 37 .equ DEC_REJECTED_UNKNOWN_CAP, 3 38 .equ DEC_REJECTED_STALE_GENERATION, 4 39 .equ DEC_REJECTED_REVOKED, 5 40 .equ DEC_REJECTED_WRONG_PRINCIPAL, 6 41 .equ DEC_REJECTED_OPERATION, 7 42 .equ DEC_REJECTED_RESOURCE, 8 43 .equ DEC_REJECTED_BOUNDS, 9 44 .equ DEC_REJECTED_CONSTRAINT, 10 45 .equ DEC_REJECTED_REPLAY_CONFLICT, 11 46 .equ DEC_REJECTED_EXHAUSTED, 12 47 .equ DEC_EXECUTION_FAILED, 13 48 49 /* 50 * run_m3_unit_tests(): 51 * Executes all M3 test scenarios. 52 */ 53 run_m3_unit_tests: 54 stp x29, x30, [sp, #-160]! 55 mov x29, sp 56 stp x19, x20, [sp, #16] 57 stp x21, x22, [sp, #32] 58 stp x23, x24, [sp, #48] 59 60 /* x19 = pass count, x20 = test count, x21 = bitmask */ 61 mov x19, #0 62 mov x20, #0 63 mov x21, #0 64 65 adr x0, msg_unit_tests_start 66 bl print_string 67 68 /* ------------------------------------------------------------- 69 * TEST 1: End-to-End Scenario — Derive Memory Cap A from CAP_ROOT 70 * Parent: Slot 0, Gen 1, caller=1. Child: principal=2, rtype=FRAME, 71 * ops=FRAME_GRANT, bounds=[0x40210000, 0x40220000) (64 KiB), lifetime=0. 72 * ------------------------------------------------------------- */ 73 add x20, x20, #1 74 mov w0, #0 /* parent_slot = 0 */ 75 mov w1, #1 /* parent_gen = 1 */ 76 mov x2, #1 /* caller_principal = 1 */ 77 mov x3, #2 /* child_principal = 2 */ 78 mov w4, #RES_MEMORY_FRAME /* rtype */ 79 mov w5, #OP_FRAME_GRANT /* ops */ 80 ldr x6, =0x40210000 /* base */ 81 ldr x7, =0x00010000 /* size = 64 KiB */ 82 mov x8, #0 /* lifetime = 0 */ 83 bl derive_capability 84 /* Expected: Cap A in Slot 1, Gen 1 -> (1 << 32) | 1 */ 85 ldr x1, =(1 << 32) | 1 86 cmp x0, x1 87 b.ne 1f 88 add x19, x19, #1 89 orr x21, x21, #(1 << 0) 90 1: 91 mov x22, x0 /* x22 = Cap A handle */ 92 93 /* ------------------------------------------------------------- 94 * TEST 2: Valid Intent on Cap A -> ADMITTED, Frame Granted 95 * Intent: req_id=101, principal=2, slot=1, gen=1, rtype=FRAME, 96 * op=FRAME_GRANT, target=0x40210000, size=4096. 97 * ------------------------------------------------------------- */ 98 add x20, x20, #1 99 add x0, sp, #64 /* Intent buffer (64 bytes) */ 100 mov w1, #1 101 strh w1, [x0, #0] /* version = 1 */ 102 mov w1, #64 103 strh w1, [x0, #2] /* length = 64 */ 104 str wzr, [x0, #4] /* reserved0 = 0 */ 105 mov x1, #101 106 str x1, [x0, #8] /* request_id = 101 */ 107 mov x1, #2 108 str x1, [x0, #16] /* principal_id = 2 */ 109 mov w1, #1 110 str w1, [x0, #24] /* slot = 1 */ 111 mov w1, #1 112 str w1, [x0, #28] /* generation = 1 */ 113 mov w1, #RES_MEMORY_FRAME 114 str w1, [x0, #32] /* rtype */ 115 mov w1, #OP_FRAME_GRANT 116 str w1, [x0, #36] /* op */ 117 ldr x1, =0x40210000 118 str x1, [x0, #40] /* target_base = 0x40210000 */ 119 mov x1, #4096 120 str x1, [x0, #48] /* target_size = 4096 */ 121 str xzr, [x0, #56] /* reserved1 */ 122 123 bl submit_effect 124 cbz x0, 2f 125 ldr w1, [x0, #4] /* decision */ 126 cmp w1, #DEC_ADMITTED 127 b.ne 2f 128 ldr x2, [x0, #0x38] /* actual_effect */ 129 ldr x3, =0x40210000 130 cmp x2, x3 131 b.ne 2f 132 add x19, x19, #1 133 orr x21, x21, #(1 << 1) 134 2: 135 136 /* ------------------------------------------------------------- 137 * TEST 3: Derive Cap B from Cap A (Strict subset) 138 * Parent: Slot 1, Gen 1, caller=2. Child: principal=3, rtype=FRAME, 139 * ops=FRAME_GRANT, bounds=[0x40210000, 0x40218000) (32 KiB, subset). 140 * ------------------------------------------------------------- */ 141 add x20, x20, #1 142 mov w0, #1 /* parent_slot = 1 */ 143 mov w1, #1 /* parent_gen = 1 */ 144 mov x2, #2 /* caller_principal = 2 */ 145 mov x3, #3 /* child_principal = 3 */ 146 mov w4, #RES_MEMORY_FRAME 147 mov w5, #OP_FRAME_GRANT 148 ldr x6, =0x40210000 149 ldr x7, =0x00008000 /* size = 32 KiB */ 150 mov x8, #0 151 bl derive_capability 152 /* Expected: Cap B in Slot 2, Gen 1 */ 153 ldr x1, =(1 << 32) | 2 154 cmp x0, x1 155 b.ne 3f 156 add x19, x19, #1 157 orr x21, x21, #(1 << 2) 158 3: 159 mov x23, x0 /* x23 = Cap B handle */ 160 161 /* ------------------------------------------------------------- 162 * TEST 4: Intent on Cap B Targeting Outside B's Bounds -> REJECTED_BOUNDS 163 * Target: 0x40219000 (outside [0x40210000, 0x40218000)) 164 * ------------------------------------------------------------- */ 165 add x20, x20, #1 166 add x0, sp, #64 167 mov w1, #1 168 strh w1, [x0, #0] 169 mov w1, #64 170 strh w1, [x0, #2] 171 str wzr, [x0, #4] 172 mov x1, #102 173 str x1, [x0, #8] /* request_id = 102 */ 174 mov x1, #3 175 str x1, [x0, #16] /* principal_id = 3 */ 176 mov w1, #2 177 str w1, [x0, #24] /* slot = 2 */ 178 mov w1, #1 179 str w1, [x0, #28] /* generation = 1 */ 180 mov w1, #RES_MEMORY_FRAME 181 str w1, [x0, #32] 182 mov w1, #OP_FRAME_GRANT 183 str w1, [x0, #36] 184 ldr x1, =0x40219000 /* OUTSIDE B */ 185 str x1, [x0, #40] 186 mov x1, #4096 187 str x1, [x0, #48] 188 str xzr, [x0, #56] 189 190 bl submit_effect 191 cbz x0, 4f 192 ldr w1, [x0, #4] /* decision */ 193 cmp w1, #DEC_REJECTED_BOUNDS 194 b.ne 4f 195 add x19, x19, #1 196 orr x21, x21, #(1 << 3) 197 4: 198 199 /* ------------------------------------------------------------- 200 * TEST 5: Revoke Cap A (Slot 1) 201 * ------------------------------------------------------------- */ 202 add x20, x20, #1 203 mov w0, #1 /* slot = 1 */ 204 mov w1, #1 /* gen = 1 */ 205 mov x2, #2 /* principal = 2 */ 206 bl revoke_capability 207 cmp x0, #1 208 b.ne 5f 209 add x19, x19, #1 210 orr x21, x21, #(1 << 4) 211 5: 212 213 /* ------------------------------------------------------------- 214 * TEST 6: Exercising Directly Revoked Cap A -> REJECTED_REVOKED 215 * ------------------------------------------------------------- */ 216 add x20, x20, #1 217 add x0, sp, #64 218 mov w1, #1 219 strh w1, [x0, #0] 220 mov w1, #64 221 strh w1, [x0, #2] 222 str wzr, [x0, #4] 223 mov x1, #103 224 str x1, [x0, #8] 225 mov x1, #2 226 str x1, [x0, #16] 227 mov w1, #1 228 str w1, [x0, #24] /* slot = 1 (revoked) */ 229 mov w1, #1 230 str w1, [x0, #28] 231 mov w1, #RES_MEMORY_FRAME 232 str w1, [x0, #32] 233 mov w1, #OP_FRAME_GRANT 234 str w1, [x0, #36] 235 ldr x1, =0x40211000 236 str x1, [x0, #40] 237 mov x1, #4096 238 str x1, [x0, #48] 239 str xzr, [x0, #56] 240 241 bl submit_effect 242 cbz x0, 6f 243 ldr w1, [x0, #4] 244 cmp w1, #DEC_REJECTED_REVOKED 245 b.ne 6f 246 add x19, x19, #1 247 orr x21, x21, #(1 << 5) 248 6: 249 250 /* ------------------------------------------------------------- 251 * TEST 7: Exercising Descendant Cap B (Parent A Revoked) -> REJECTED_REVOKED 252 * ------------------------------------------------------------- */ 253 add x20, x20, #1 254 add x0, sp, #64 255 mov w1, #1 256 strh w1, [x0, #0] 257 mov w1, #64 258 strh w1, [x0, #2] 259 str wzr, [x0, #4] 260 mov x1, #104 261 str x1, [x0, #8] 262 mov x1, #3 263 str x1, [x0, #16] 264 mov w1, #2 265 str w1, [x0, #24] /* slot = 2 (descendant of 1) */ 266 mov w1, #1 267 str w1, [x0, #28] 268 mov w1, #RES_MEMORY_FRAME 269 str w1, [x0, #32] 270 mov w1, #OP_FRAME_GRANT 271 str w1, [x0, #36] 272 ldr x1, =0x40210000 273 str x1, [x0, #40] 274 mov x1, #4096 275 str x1, [x0, #48] 276 str xzr, [x0, #56] 277 278 bl submit_effect 279 cbz x0, 7f 280 ldr w1, [x0, #4] 281 cmp w1, #DEC_REJECTED_REVOKED 282 b.ne 7f 283 add x19, x19, #1 284 orr x21, x21, #(1 << 6) 285 7: 286 287 /* ------------------------------------------------------------- 288 * TEST 8: Adversarial Matrix — Forged Slot (Slot 15 unallocated) 289 * ------------------------------------------------------------- */ 290 add x20, x20, #1 291 add x0, sp, #64 292 mov w1, #1 293 strh w1, [x0, #0] 294 mov w1, #64 295 strh w1, [x0, #2] 296 str wzr, [x0, #4] 297 mov x1, #105 298 str x1, [x0, #8] 299 mov x1, #2 300 str x1, [x0, #16] 301 mov w1, #15 /* Forged slot */ 302 str w1, [x0, #24] 303 mov w1, #1 304 str w1, [x0, #28] 305 mov w1, #RES_MEMORY_FRAME 306 str w1, [x0, #32] 307 mov w1, #OP_FRAME_GRANT 308 str w1, [x0, #36] 309 ldr x1, =0x40210000 310 str x1, [x0, #40] 311 mov x1, #4096 312 str x1, [x0, #48] 313 str xzr, [x0, #56] 314 315 bl submit_effect 316 cbz x0, 8f 317 ldr w1, [x0, #4] 318 cmp w1, #DEC_REJECTED_UNKNOWN_CAP 319 b.ne 8f 320 add x19, x19, #1 321 orr x21, x21, #(1 << 7) 322 8: 323 324 /* ------------------------------------------------------------- 325 * TEST 9: Adversarial Matrix — Out-of-Range Slot (Slot 40 >= 32) 326 * ------------------------------------------------------------- */ 327 add x20, x20, #1 328 add x0, sp, #64 329 mov w1, #1 330 strh w1, [x0, #0] 331 mov w1, #64 332 strh w1, [x0, #2] 333 str wzr, [x0, #4] 334 mov x1, #106 335 str x1, [x0, #8] 336 mov x1, #2 337 str x1, [x0, #16] 338 mov w1, #40 /* Out of range */ 339 str w1, [x0, #24] 340 mov w1, #1 341 str w1, [x0, #28] 342 mov w1, #RES_MEMORY_FRAME 343 str w1, [x0, #32] 344 mov w1, #OP_FRAME_GRANT 345 str w1, [x0, #36] 346 ldr x1, =0x40210000 347 str x1, [x0, #40] 348 mov x1, #4096 349 str x1, [x0, #48] 350 str xzr, [x0, #56] 351 352 bl submit_effect 353 cbz x0, 9f 354 ldr w1, [x0, #4] 355 cmp w1, #DEC_REJECTED_UNKNOWN_CAP 356 b.ne 9f 357 add x19, x19, #1 358 orr x21, x21, #(1 << 8) 359 9: 360 361 /* ------------------------------------------------------------- 362 * TEST 10: Adversarial Matrix — Stale Generation 363 * Re-allocate slot 1. Slot 1 becomes gen 2. Present gen 1. 364 * ------------------------------------------------------------- */ 365 add x20, x20, #1 366 /* Derive fresh cap in slot 1 from root */ 367 mov w0, #0 368 mov w1, #1 369 mov x2, #1 370 mov x3, #4 /* principal 4 */ 371 mov w4, #RES_MEMORY_FRAME 372 mov w5, #OP_FRAME_GRANT 373 ldr x6, =0x40210000 374 ldr x7, =0x00010000 375 mov x8, #0 376 bl derive_capability 377 /* Should be slot 1, gen 2 -> (2 << 32) | 1 */ 378 ldr x1, =(2 << 32) | 1 379 cmp x0, x1 380 b.ne 10f 381 382 /* Now submit intent presenting gen 1 (stale) */ 383 add x0, sp, #64 384 mov w1, #1 385 strh w1, [x0, #0] 386 mov w1, #64 387 strh w1, [x0, #2] 388 str wzr, [x0, #4] 389 mov x1, #107 390 str x1, [x0, #8] 391 mov x1, #4 392 str x1, [x0, #16] 393 mov w1, #1 /* slot 1 */ 394 str w1, [x0, #24] 395 mov w1, #1 /* STALE generation 1 (current is 2) */ 396 str w1, [x0, #28] 397 mov w1, #RES_MEMORY_FRAME 398 str w1, [x0, #32] 399 mov w1, #OP_FRAME_GRANT 400 str w1, [x0, #36] 401 ldr x1, =0x40210000 402 str x1, [x0, #40] 403 mov x1, #4096 404 str x1, [x0, #48] 405 str xzr, [x0, #56] 406 407 bl submit_effect 408 cbz x0, 10f 409 ldr w1, [x0, #4] 410 cmp w1, #DEC_REJECTED_STALE_GENERATION 411 b.ne 10f 412 add x19, x19, #1 413 orr x21, x21, #(1 << 9) 414 10: 415 416 /* ------------------------------------------------------------- 417 * TEST 11: Adversarial Matrix — Wrong Principal 418 * Slot 1 gen 2 owned by principal 4. Caller presents principal 99. 419 * ------------------------------------------------------------- */ 420 add x20, x20, #1 421 add x0, sp, #64 422 mov w1, #1 423 strh w1, [x0, #0] 424 mov w1, #64 425 strh w1, [x0, #2] 426 str wzr, [x0, #4] 427 mov x1, #108 428 str x1, [x0, #8] 429 mov x1, #99 /* Wrong principal */ 430 str x1, [x0, #16] 431 mov w1, #1 432 str w1, [x0, #24] 433 mov w1, #2 /* Current gen = 2 */ 434 str w1, [x0, #28] 435 mov w1, #RES_MEMORY_FRAME 436 str w1, [x0, #32] 437 mov w1, #OP_FRAME_GRANT 438 str w1, [x0, #36] 439 ldr x1, =0x40210000 440 str x1, [x0, #40] 441 mov x1, #4096 442 str x1, [x0, #48] 443 str xzr, [x0, #56] 444 445 bl submit_effect 446 cbz x0, 11f 447 ldr w1, [x0, #4] 448 cmp w1, #DEC_REJECTED_WRONG_PRINCIPAL 449 b.ne 11f 450 add x19, x19, #1 451 orr x21, x21, #(1 << 10) 452 11: 453 454 /* ------------------------------------------------------------- 455 * TEST 12: Adversarial Matrix — Forbidden Operation 456 * Slot 1 gen 2 allows only FRAME_GRANT. Request FRAME_RELEASE. 457 * ------------------------------------------------------------- */ 458 add x20, x20, #1 459 add x0, sp, #64 460 mov w1, #1 461 strh w1, [x0, #0] 462 mov w1, #64 463 strh w1, [x0, #2] 464 str wzr, [x0, #4] 465 mov x1, #109 466 str x1, [x0, #8] 467 mov x1, #4 /* correct principal */ 468 str x1, [x0, #16] 469 mov w1, #1 470 str w1, [x0, #24] 471 mov w1, #2 472 str w1, [x0, #28] 473 mov w1, #RES_MEMORY_FRAME 474 str w1, [x0, #32] 475 mov w1, #OP_FRAME_RELEASE /* Forbidden operation */ 476 str w1, [x0, #36] 477 ldr x1, =0x40210000 478 str x1, [x0, #40] 479 mov x1, #4096 480 str x1, [x0, #48] 481 str xzr, [x0, #56] 482 483 bl submit_effect 484 cbz x0, 12f 485 ldr w1, [x0, #4] 486 cmp w1, #DEC_REJECTED_OPERATION 487 b.ne 12f 488 add x19, x19, #1 489 orr x21, x21, #(1 << 11) 490 12: 491 492 /* ------------------------------------------------------------- 493 * TEST 13: Adversarial Matrix — Wrong Resource Type 494 * Slot 1 gen 2 is RES_MEMORY_FRAME. Request RES_CONSOLE. 495 * ------------------------------------------------------------- */ 496 add x20, x20, #1 497 add x0, sp, #64 498 mov w1, #1 499 strh w1, [x0, #0] 500 mov w1, #64 501 strh w1, [x0, #2] 502 str wzr, [x0, #4] 503 mov x1, #110 504 str x1, [x0, #8] 505 mov x1, #4 506 str x1, [x0, #16] 507 mov w1, #1 508 str w1, [x0, #24] 509 mov w1, #2 510 str w1, [x0, #28] 511 mov w1, #RES_CONSOLE /* Wrong resource */ 512 str w1, [x0, #32] 513 mov w1, #OP_CONSOLE_WRITE 514 str w1, [x0, #36] 515 ldr x1, =0x09000000 516 str x1, [x0, #40] 517 mov x1, #1 518 str x1, [x0, #48] 519 str xzr, [x0, #56] 520 521 bl submit_effect 522 cbz x0, 13f 523 ldr w1, [x0, #4] 524 cmp w1, #DEC_REJECTED_RESOURCE 525 b.ne 13f 526 add x19, x19, #1 527 orr x21, x21, #(1 << 12) 528 13: 529 530 /* ------------------------------------------------------------- 531 * TEST 14: Adversarial Matrix — Child Rights Widening Refused 532 * Parent has only FRAME_GRANT. Attempt to derive child with FRAME_RELEASE. 533 * ------------------------------------------------------------- */ 534 add x20, x20, #1 535 mov w0, #1 /* parent_slot = 1 (gen 2) */ 536 mov w1, #2 537 mov x2, #4 /* caller = 4 */ 538 mov x3, #5 /* child = 5 */ 539 mov w4, #RES_MEMORY_FRAME 540 mov w5, #(OP_FRAME_GRANT | OP_FRAME_RELEASE) /* Widened ops! */ 541 ldr x6, =0x40210000 542 ldr x7, =0x00010000 543 mov x8, #0 544 bl derive_capability 545 /* Must return 0 (refusal) */ 546 cbnz x0, 14f 547 add x19, x19, #1 548 orr x21, x21, #(1 << 13) 549 14: 550 551 /* ------------------------------------------------------------- 552 * TEST 15: Adversarial Matrix — Child Bounds Widening Refused 553 * Parent bound is [0x40210000, 0x40220000). Child requests 0x40230000 end. 554 * ------------------------------------------------------------- */ 555 add x20, x20, #1 556 mov w0, #1 557 mov w1, #2 558 mov x2, #4 559 mov x3, #5 560 mov w4, #RES_MEMORY_FRAME 561 mov w5, #OP_FRAME_GRANT 562 ldr x6, =0x40210000 563 ldr x7, =0x00020000 /* Widened bound: 128 KiB > 64 KiB! */ 564 mov x8, #0 565 bl derive_capability 566 cbnz x0, 15f 567 add x19, x19, #1 568 orr x21, x21, #(1 << 14) 569 15: 570 571 /* ------------------------------------------------------------- 572 * TEST 16: Adversarial Matrix — Integer Overflow in Child Bounds Refused 573 * base = 0xFFFFFFFFFFFFF000, size = 0x2000 (wraps around 0) 574 * ------------------------------------------------------------- */ 575 add x20, x20, #1 576 mov w0, #1 577 mov w1, #2 578 mov x2, #4 579 mov x3, #5 580 mov w4, #RES_MEMORY_FRAME 581 mov w5, #OP_FRAME_GRANT 582 ldr x6, =0xFFFFFFFFFFFFF000 583 ldr x7, =0x2000 584 mov x8, #0 585 bl derive_capability 586 cbnz x0, 16f 587 add x19, x19, #1 588 orr x21, x21, #(1 << 15) 589 16: 590 591 /* ------------------------------------------------------------- 592 * TEST 17: Adversarial Matrix — Root Capability Export Attempt 593 * External principal (principal 9) attempts to exercise slot 0. 594 * ------------------------------------------------------------- */ 595 add x20, x20, #1 596 add x0, sp, #64 597 mov w1, #1 598 strh w1, [x0, #0] 599 mov w1, #64 600 strh w1, [x0, #2] 601 str wzr, [x0, #4] 602 mov x1, #111 603 str x1, [x0, #8] 604 mov x1, #9 /* External caller */ 605 str x1, [x0, #16] 606 mov w1, #0 /* CAP_ROOT slot 0 */ 607 str w1, [x0, #24] 608 mov w1, #1 609 str w1, [x0, #28] 610 mov w1, #RES_UNIVERSAL_ROOT 611 str w1, [x0, #32] 612 mov w1, #1 613 str w1, [x0, #36] 614 ldr x1, =0x40210000 615 str x1, [x0, #40] 616 mov x1, #4096 617 str x1, [x0, #48] 618 str xzr, [x0, #56] 619 620 bl submit_effect 621 cbz x0, 17f 622 ldr w1, [x0, #4] 623 cmp w1, #DEC_REJECTED_WRONG_PRINCIPAL 624 b.ne 17f 625 add x19, x19, #1 626 orr x21, x21, #(1 << 16) 627 17: 628 629 /* ------------------------------------------------------------- 630 * TEST 18: Replay Semantics — Identical Intent Returns Cached Result 631 * Submit intent with request_id=200 on slot 1 gen 2 (principal 4). 632 * Then submit duplicate request_id=200 with identical intent. 633 * ------------------------------------------------------------- */ 634 add x20, x20, #1 635 /* First submission */ 636 add x0, sp, #64 637 mov w1, #1 638 strh w1, [x0, #0] 639 mov w1, #64 640 strh w1, [x0, #2] 641 str wzr, [x0, #4] 642 mov x1, #200 643 str x1, [x0, #8] /* request_id = 200 */ 644 mov x1, #4 /* principal 4 */ 645 str x1, [x0, #16] 646 mov w1, #1 /* slot 1 */ 647 str w1, [x0, #24] 648 mov w1, #2 /* gen 2 */ 649 str w1, [x0, #28] 650 mov w1, #RES_MEMORY_FRAME 651 str w1, [x0, #32] 652 mov w1, #OP_FRAME_GRANT 653 str w1, [x0, #36] 654 ldr x1, =0x40212000 655 str x1, [x0, #40] 656 mov x1, #4096 657 str x1, [x0, #48] 658 str xzr, [x0, #56] 659 660 bl submit_effect 661 cbz x0, 18f 662 mov x24, x0 /* x24 = first receipt */ 663 664 /* Second submission (identical request_id 200 and intent) */ 665 add x0, sp, #64 666 bl submit_effect 667 cmp x0, x24 /* Must return identical receipt pointer! */ 668 b.ne 18f 669 add x19, x19, #1 670 orr x21, x21, #(1 << 17) 671 18: 672 673 /* ------------------------------------------------------------- 674 * TEST 19: Replay Semantics — Replay Conflict (Same ID, altered intent) 675 * Submit request_id=200 with target=0x40213000 (altered!) 676 * ------------------------------------------------------------- */ 677 add x20, x20, #1 678 add x0, sp, #64 679 mov w1, #1 680 strh w1, [x0, #0] 681 mov w1, #64 682 strh w1, [x0, #2] 683 str wzr, [x0, #4] 684 mov x1, #200 /* Same request_id = 200 */ 685 str x1, [x0, #8] 686 mov x1, #4 687 str x1, [x0, #16] 688 mov w1, #1 689 str w1, [x0, #24] 690 mov w1, #2 691 str w1, [x0, #28] 692 mov w1, #RES_MEMORY_FRAME 693 str w1, [x0, #32] 694 mov w1, #OP_FRAME_GRANT 695 str w1, [x0, #36] 696 ldr x1, =0x40213000 /* ALTERED TARGET! */ 697 str x1, [x0, #40] 698 mov x1, #4096 699 str x1, [x0, #48] 700 str xzr, [x0, #56] 701 702 bl submit_effect 703 cbz x0, 19f 704 ldr w1, [x0, #4] 705 cmp w1, #DEC_REJECTED_REPLAY_CONFLICT 706 b.ne 19f 707 add x19, x19, #1 708 orr x21, x21, #(1 << 18) 709 19: 710 711 /* ------------------------------------------------------------- 712 * TEST 20: Console Resource Test (CONSOLE_WRITE to UART) 713 * Derive Console Cap C (slot 3) from CAP_ROOT (caller 1, child 6) 714 * Submit CONSOLE_WRITE intent. 715 * ------------------------------------------------------------- */ 716 add x20, x20, #1 717 mov w0, #0 /* parent = 0 */ 718 mov w1, #1 719 mov x2, #1 720 mov x3, #6 /* child = 6 */ 721 mov w4, #RES_CONSOLE 722 mov w5, #OP_CONSOLE_WRITE 723 ldr x6, =0x09000000 /* base = UART MMIO */ 724 ldr x7, =0x1000 /* size = 4 KiB */ 725 mov x8, #0 726 bl derive_capability 727 cbz x0, 20f 728 729 /* Submit CONSOLE_WRITE intent with character '*' (0x2A) */ 730 add x0, sp, #64 731 mov w1, #1 732 strh w1, [x0, #0] 733 mov w1, #64 734 strh w1, [x0, #2] 735 str wzr, [x0, #4] 736 mov x1, #300 737 str x1, [x0, #8] 738 mov x1, #6 /* principal 6 */ 739 str x1, [x0, #16] 740 mov w1, #3 /* slot 3 */ 741 str w1, [x0, #24] 742 mov w1, #1 /* gen 1 */ 743 str w1, [x0, #28] 744 mov w1, #RES_CONSOLE 745 str w1, [x0, #32] 746 mov w1, #OP_CONSOLE_WRITE 747 str w1, [x0, #36] 748 ldr x1, =0x09000000 749 str x1, [x0, #40] 750 mov x1, #1 751 str x1, [x0, #48] 752 mov x1, #0x2A /* character '*' in param0 (+0x38 = 56) */ 753 str x1, [x0, #56] 754 755 bl submit_effect 756 cbz x0, 20f 757 ldr w1, [x0, #4] 758 cmp w1, #DEC_ADMITTED 759 b.ne 20f 760 add x19, x19, #1 761 orr x21, x21, #(1 << 19) 762 20: 763 764 /* ------------------------------------------------------------- 765 * TEST 21: Measurement Resource Test (MEASUREMENT_READ) 766 * Derive Measurement Cap D (slot 4) from CAP_ROOT (caller 1, child 7) 767 * Submit MEASUREMENT_READ intent. 768 * ------------------------------------------------------------- */ 769 add x20, x20, #1 770 mov w0, #0 771 mov w1, #1 772 mov x2, #1 773 mov x3, #7 /* child 7 */ 774 mov w4, #RES_MEASUREMENT 775 mov w5, #OP_MEASUREMENT_READ 776 mov x6, #0 777 mov x7, #0 778 mov x8, #0 779 bl derive_capability 780 cbz x0, 21f 781 782 add x0, sp, #64 783 mov w1, #1 784 strh w1, [x0, #0] 785 mov w1, #64 786 strh w1, [x0, #2] 787 str wzr, [x0, #4] 788 mov x1, #400 789 str x1, [x0, #8] 790 mov x1, #7 791 str x1, [x0, #16] 792 mov w1, #4 /* slot 4 */ 793 str w1, [x0, #24] 794 mov w1, #1 /* gen 1 */ 795 str w1, [x0, #28] 796 mov w1, #RES_MEASUREMENT 797 str w1, [x0, #32] 798 mov w1, #OP_MEASUREMENT_READ 799 str w1, [x0, #36] 800 mov x1, #0 801 str x1, [x0, #40] 802 str x1, [x0, #48] 803 str x1, [x0, #56] 804 805 bl submit_effect 806 cbz x0, 21f 807 ldr w1, [x0, #4] 808 cmp w1, #DEC_ADMITTED 809 b.ne 21f 810 add x19, x19, #1 811 orr x21, x21, #(1 << 20) 812 21: 813 814 /* ------------------------------------------------------------- 815 * Write Test Summary Record to PHYSICS_BOOT_STATE + 0x200 (0x40208A00) 816 * +0x00: magic (0x4D33544553545355 'M3TESTSU') 817 * +0x08: tests_run (u64) 818 * +0x10: tests_passed (u64) 819 * +0x18: bitmask_results (u64) 820 * ------------------------------------------------------------- */ 821 ldr x0, =TEST_RECORD_BASE 822 ldr x1, =TEST_MAGIC 823 str x1, [x0, #0] 824 str x20, [x0, #8] /* tests_run */ 825 str x19, [x0, #16] /* tests_passed */ 826 str x21, [x0, #24] /* bitmask_results */ 827 828 /* Emit telemetry */ 829 adr x0, msg_unit_tests_done 830 bl print_string 831 832 ldp x23, x24, [sp, #48] 833 ldp x21, x22, [sp, #32] 834 ldp x19, x20, [sp, #16] 835 ldp x29, x30, [sp], #160 836 ret 837 838 .section .rodata 839 .balign 8 840 msg_unit_tests_start: 841 .asciz "PHYSICS: M3_TESTS_START\n" 842 msg_unit_tests_done: 843 .asciz "PHYSICS: M3_TESTS_DONE\n"