physics-mv
FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.
Brought by drakestapleton
physics-mv / m3 / physics.s
| 1 | /* |
| 2 | * m3/physics.s - Bare-Metal Authority Nucleus for Milestone 3 (PHYSICS_EFFECTS) |
| 3 | * Target Platform: QEMU virt AArch64 / Sovereign Machine |
| 4 | * Entry Point: _physics_entry @ 0x40200000 |
| 5 | * ABI: PHYSICS_ENTRY_ABI (x0 = 0x401FE000, x1 = 18432, x2 = 'PHYSICS0') |
| 6 | */ |
| 7 | |
| 8 | .global _physics_entry |
| 9 | .global _start |
| 10 | .global print_string |
| 11 | .global print_char |
| 12 | |
| 13 | .extern vector_table |
| 14 | .extern init_frame_authority |
| 15 | .extern init_capability_table |
| 16 | .extern init_receipt_ledger |
| 17 | .extern init_replay_cache |
| 18 | .extern run_m3_unit_tests |
| 19 | |
| 20 | .section .text.entry, "ax" |
| 21 | .balign 64 |
| 22 | |
| 23 | _physics_entry: |
| 24 | _start: |
| 25 | /* 0. Initialize Physics Kernel Stack @ 0x40208800 (growing downward) */ |
| 26 | ldr x3, =0x40208800 |
| 27 | mov sp, x3 |
| 28 | |
| 29 | /* 1. Validate Verification Cookie in x2: 'PHYSICS0' (0x5048595349435330) */ |
| 30 | ldr x3, =0x5048595349435330 |
| 31 | cmp x2, x3 |
| 32 | b.ne .Lpanic_bad_cookie |
| 33 | |
| 34 | /* 1b. Validate payload size in x1 (18,432 bytes) */ |
| 35 | ldr x3, =18432 |
| 36 | cmp x1, x3 |
| 37 | b.ne .Lpanic_bad_payload_size |
| 38 | |
| 39 | /* 2. Validate Boot Descriptor Pointer in x0: 0x401FE000 */ |
| 40 | ldr x3, =0x401FE000 |
| 41 | cmp x0, x3 |
| 42 | b.ne .Lpanic_bad_descriptor |
| 43 | |
| 44 | /* 3. Validate Descriptor Structural Header */ |
| 45 | ldr x4, [x0, #0] |
| 46 | ldr x5, =0x4D424453435F3031 /* 'MBDSC_01' */ |
| 47 | cmp x4, x5 |
| 48 | b.ne .Lpanic_bad_desc_magic |
| 49 | |
| 50 | ldr w4, [x0, #8] /* version == 1 */ |
| 51 | cmp w4, #1 |
| 52 | b.ne .Lpanic_bad_desc_version |
| 53 | |
| 54 | ldr w4, [x0, #12] /* length == 64 */ |
| 55 | cmp w4, #64 |
| 56 | b.ne .Lpanic_bad_desc_length |
| 57 | |
| 58 | ldr x4, [x0, #16] /* flags_reserved == 0 */ |
| 59 | cbnz x4, .Lpanic_bad_desc_reserved |
| 60 | |
| 61 | /* 4. Validate Machine Profile */ |
| 62 | ldr x19, [x0, #24] /* ram_base == 0x40000000 */ |
| 63 | ldr x5, =0x40000000 |
| 64 | cmp x19, x5 |
| 65 | b.ne .Lpanic_ingress_corrupt |
| 66 | |
| 67 | ldr x20, [x0, #32] /* ram_size == 0x08000000 (128 MiB) */ |
| 68 | ldr x5, =0x08000000 |
| 69 | cmp x20, x5 |
| 70 | b.ne .Lpanic_ingress_corrupt |
| 71 | |
| 72 | ldr x21, [x0, #40] /* uart_base == 0x09000000 */ |
| 73 | ldr x5, =0x09000000 |
| 74 | cmp x21, x5 |
| 75 | b.ne .Lpanic_ingress_corrupt |
| 76 | |
| 77 | ldr x22, [x0, #48] /* physics_base == 0x40200000 */ |
| 78 | ldr x5, =0x40200000 |
| 79 | cmp x22, x5 |
| 80 | b.ne .Lpanic_ingress_corrupt |
| 81 | |
| 82 | ldr x23, [x0, #56] /* physics_size == 18432 */ |
| 83 | ldr x5, =18432 |
| 84 | cmp x23, x5 |
| 85 | b.ne .Lpanic_ingress_corrupt |
| 86 | |
| 87 | /* 5. Copy Validated Ingress Data to PHYSICS_BOOT_STATE @ 0x40208800 */ |
| 88 | ldr x8, =0x40208800 |
| 89 | ldp x4, x5, [x0, #0] |
| 90 | stp x4, x5, [x8, #0] |
| 91 | ldp x4, x5, [x0, #16] |
| 92 | stp x4, x5, [x8, #16] |
| 93 | ldp x4, x5, [x0, #32] |
| 94 | stp x4, x5, [x8, #32] |
| 95 | ldp x4, x5, [x0, #48] |
| 96 | stp x4, x5, [x8, #48] |
| 97 | |
| 98 | /* 6. Verify CurrentEL == EL1 (0x04) */ |
| 99 | mrs x9, CurrentEL |
| 100 | and x9, x9, #0x0C |
| 101 | cmp x9, #0x04 |
| 102 | b.ne .Lpanic_uncontracted_el |
| 103 | str x9, [x8, #0x40] /* Record verified CurrentEL */ |
| 104 | |
| 105 | /* 7. Switch to Dedicated Kernel Stack: SP = 0x40208800 */ |
| 106 | ldr x10, =0x40208800 |
| 107 | mov sp, x10 |
| 108 | mov x0, #0 /* Drop Atlas scratchpad reference */ |
| 109 | |
| 110 | /* 8. Diagnostic Checkpoints */ |
| 111 | adr x0, msg_awaken |
| 112 | bl print_string |
| 113 | |
| 114 | adr x0, msg_ingress_valid |
| 115 | bl print_string |
| 116 | |
| 117 | adr x0, msg_entry_el1_verified |
| 118 | bl print_string |
| 119 | |
| 120 | /* 9. Install Exception Vector Table */ |
| 121 | ldr x1, =vector_table |
| 122 | msr vbar_el1, x1 |
| 123 | isb |
| 124 | |
| 125 | adr x0, msg_vbar_installed |
| 126 | bl print_string |
| 127 | |
| 128 | /* 10. Initialize Physical Frame Authority */ |
| 129 | ldr x8, =0x40208800 |
| 130 | ldr x0, [x8, #24] /* ram_base */ |
| 131 | ldr x1, [x8, #32] /* ram_size */ |
| 132 | bl init_frame_authority |
| 133 | cbz x0, .Lpanic_frame_authority |
| 134 | |
| 135 | adr x0, msg_frame_auth_bound |
| 136 | bl print_string |
| 137 | |
| 138 | /* 11. Initialize Capability Table (CAP_ROOT Genesis) */ |
| 139 | bl init_capability_table |
| 140 | adr x0, msg_cap_root_genesis |
| 141 | bl print_string |
| 142 | |
| 143 | /* 12. Initialize Receipt Ledger */ |
| 144 | bl init_receipt_ledger |
| 145 | adr x0, msg_receipt_ledger_init |
| 146 | bl print_string |
| 147 | |
| 148 | /* 13. Initialize Replay Cache */ |
| 149 | bl init_replay_cache |
| 150 | adr x0, msg_replay_cache_init |
| 151 | bl print_string |
| 152 | |
| 153 | /* 14. Milestone 3 Ready */ |
| 154 | adr x0, msg_quiescent_ready |
| 155 | bl print_string |
| 156 | |
| 157 | /* 15. Execute Milestone 3 Unit Tests */ |
| 158 | bl run_m3_unit_tests |
| 159 | |
| 160 | .Lquiescent_halt: |
| 161 | wfe |
| 162 | b .Lquiescent_halt |
| 163 | |
| 164 | /* Panic handlers */ |
| 165 | .Lpanic_bad_cookie: |
| 166 | adr x0, msg_panic_cookie |
| 167 | bl print_string |
| 168 | b .Lquiescent_halt |
| 169 | |
| 170 | .Lpanic_bad_payload_size: |
| 171 | adr x0, msg_panic_payload_size |
| 172 | bl print_string |
| 173 | b .Lquiescent_halt |
| 174 | |
| 175 | .Lpanic_bad_descriptor: |
| 176 | adr x0, msg_panic_desc |
| 177 | bl print_string |
| 178 | b .Lquiescent_halt |
| 179 | |
| 180 | .Lpanic_bad_desc_magic: |
| 181 | adr x0, msg_panic_desc_magic |
| 182 | bl print_string |
| 183 | b .Lquiescent_halt |
| 184 | |
| 185 | .Lpanic_bad_desc_version: |
| 186 | adr x0, msg_panic_desc_version |
| 187 | bl print_string |
| 188 | b .Lquiescent_halt |
| 189 | |
| 190 | .Lpanic_bad_desc_length: |
| 191 | adr x0, msg_panic_desc_length |
| 192 | bl print_string |
| 193 | b .Lquiescent_halt |
| 194 | |
| 195 | .Lpanic_bad_desc_reserved: |
| 196 | adr x0, msg_panic_desc_reserved |
| 197 | bl print_string |
| 198 | b .Lquiescent_halt |
| 199 | |
| 200 | .Lpanic_ingress_corrupt: |
| 201 | adr x0, msg_panic_ingress |
| 202 | bl print_string |
| 203 | b .Lquiescent_halt |
| 204 | |
| 205 | .Lpanic_uncontracted_el: |
| 206 | adr x0, msg_panic_el |
| 207 | bl print_string |
| 208 | b .Lquiescent_halt |
| 209 | |
| 210 | .Lpanic_frame_authority: |
| 211 | adr x0, msg_panic_frame_auth |
| 212 | bl print_string |
| 213 | b .Lquiescent_halt |
| 214 | |
| 215 | /* UART Polled Telemetry */ |
| 216 | print_string: |
| 217 | ldr x1, =0x09000000 /* PL011 UART */ |
| 218 | .Lputs_loop: |
| 219 | ldrb w2, [x0], #1 |
| 220 | cbz w2, .Lputs_done |
| 221 | 1: ldrb w3, [x1, #24] /* UARTFR */ |
| 222 | tst w3, #32 /* TXFF */ |
| 223 | b.ne 1b |
| 224 | strb w2, [x1] |
| 225 | b .Lputs_loop |
| 226 | .Lputs_done: |
| 227 | ret |
| 228 | |
| 229 | print_char: |
| 230 | ldr x1, =0x09000000 |
| 231 | 1: ldrb w2, [x1, #24] |
| 232 | tst w2, #32 |
| 233 | b.ne 1b |
| 234 | strb w0, [x1] |
| 235 | ret |
| 236 | |
| 237 | .section .rodata |
| 238 | .balign 8 |
| 239 | msg_awaken: |
| 240 | .asciz "PHYSICS: AWAKEN\n" |
| 241 | msg_ingress_valid: |
| 242 | .asciz "PHYSICS: INGRESS_VALID\n" |
| 243 | msg_entry_el1_verified: |
| 244 | .asciz "PHYSICS: ENTRY_EL1_VERIFIED\n" |
| 245 | msg_vbar_installed: |
| 246 | .asciz "PHYSICS: VBAR_INSTALLED\n" |
| 247 | msg_frame_auth_bound: |
| 248 | .asciz "PHYSICS: FRAME_AUTH_BOUND\n" |
| 249 | msg_cap_root_genesis: |
| 250 | .asciz "PHYSICS: CAP_ROOT_GENESIS\n" |
| 251 | msg_receipt_ledger_init: |
| 252 | .asciz "PHYSICS: RECEIPT_LEDGER_INIT\n" |
| 253 | msg_replay_cache_init: |
| 254 | .asciz "PHYSICS: REPLAY_CACHE_INIT\n" |
| 255 | msg_quiescent_ready: |
| 256 | .asciz "PHYSICS: QUIESCENT_READY\n" |
| 257 | |
| 258 | msg_panic_cookie: |
| 259 | .asciz "PANIC: BAD VERIFICATION COOKIE\n" |
| 260 | msg_panic_payload_size: |
| 261 | .asciz "PANIC: BAD PAYLOAD SIZE\n" |
| 262 | msg_panic_desc: |
| 263 | .asciz "PANIC: BAD BOOT DESCRIPTOR POINTER\n" |
| 264 | msg_panic_desc_magic: |
| 265 | .asciz "PANIC: BAD DESCRIPTOR MAGIC\n" |
| 266 | msg_panic_desc_version: |
| 267 | .asciz "PANIC: UNSUPPORTED DESCRIPTOR VERSION\n" |
| 268 | msg_panic_desc_length: |
| 269 | .asciz "PANIC: TRUNCATED/OVERSIZED DESCRIPTOR\n" |
| 270 | msg_panic_desc_reserved: |
| 271 | .asciz "PANIC: NON-ZERO RESERVED FLAGS\n" |
| 272 | msg_panic_ingress: |
| 273 | .asciz "PANIC: INGRESS MACHINE PROFILE VIOLATION\n" |
| 274 | msg_panic_el: |
| 275 | .asciz "PANIC: UNCONTRACTED ENTRY EXCEPTION LEVEL\n" |
| 276 | msg_panic_frame_auth: |
| 277 | .asciz "PANIC: FRAME AUTHORITY REJECTED\n" |