atlas
aien-dev/atlas
Brought by drakestapleton
atlas / history / alpha / alpha.s
| 1 | /* |
| 2 | * ALPHA: Irreducible Bootstrap Seed |
| 3 | * Canonical Root Artifact: alpha.bin |
| 4 | * Machine Contract: CONTRACT-QEMU-VIRT-AARCH64-M1 |
| 5 | * Cryptographic Integrity Scheme: Standard SHA-256 |
| 6 | * Pinned Digest: e1d89bb1e0854ebaccd2be5c756c8a2ff8c5ecc8c0f90b4abd461fb7bf98374c |
| 7 | * Entry Point: 0x00000000 (Flash Base) |
| 8 | */ |
| 9 | |
| 10 | .global _start |
| 11 | .section .text |
| 12 | .balign 64 |
| 13 | |
| 14 | _start: |
| 15 | /* 1. Mask all interrupts (DAIF: D=1, A=1, I=1, F=1) */ |
| 16 | msr daifset, #0xf |
| 17 | |
| 18 | /* 2. Initialize Stack Pointer to Scratchpad RAM (Disjoint from Descriptor @ 0x401FE000) */ |
| 19 | ldr x0, =0x401FC000 |
| 20 | mov sp, x0 |
| 21 | |
| 22 | /* 3. Initialize UART MMIO Base Pointer in x20 */ |
| 23 | ldr x20, =0x09000000 |
| 24 | |
| 25 | /* 4. Emit Diagnostic Checkpoint 1: AWAKEN */ |
| 26 | adr x21, msg_awaken |
| 27 | bl print_string |
| 28 | |
| 29 | /* 5. Populate Machine Boot Descriptor at 0x401FE000 */ |
| 30 | ldr x22, =0x401FE000 |
| 31 | ldr x0, =0x40000000 |
| 32 | str x0, [x22, #0] /* +0: RAM Base */ |
| 33 | ldr x0, =0x08000000 |
| 34 | str x0, [x22, #8] /* +8: RAM Size (128 MiB) */ |
| 35 | mov x0, x20 |
| 36 | str x0, [x22, #16] /* +16: UART MMIO Base */ |
| 37 | ldr x0, =0x40200000 |
| 38 | str x0, [x22, #24] /* +24: Physics Payload Base */ |
| 39 | mov x0, #256 |
| 40 | str x0, [x22, #32] /* +32: Physics Payload Size */ |
| 41 | |
| 42 | /* 6. Emit Diagnostic Checkpoint 2: VERIFY */ |
| 43 | adr x21, msg_verify |
| 44 | bl print_string |
| 45 | |
| 46 | /* 7. Verify PHYSICS-0 Integrity using Cryptographic SHA-256 */ |
| 47 | /* sha256_256bytes(payload, scratch_buf, out_digest) */ |
| 48 | ldr x0, =0x40200000 /* Arg 0: Payload base */ |
| 49 | ldr x1, =0x401FE100 /* Arg 1: 64-byte scratchpad for padding block */ |
| 50 | ldr x2, =0x401FE080 /* Arg 2: 32-byte digest output buffer */ |
| 51 | bl sha256_256bytes |
| 52 | |
| 53 | /* Compare computed 32-byte SHA-256 against pinned expected digest */ |
| 54 | ldr x2, =0x401FE080 |
| 55 | adr x3, pinned_sha256_digest |
| 56 | |
| 57 | /* Compare 8 x 32-bit words (2 x 64-bit pair loads) */ |
| 58 | ldp x4, x5, [x2, #0] |
| 59 | ldp x6, x7, [x3, #0] |
| 60 | cmp x4, x6 |
| 61 | b.ne .Lrefuse_handoff |
| 62 | cmp x5, x7 |
| 63 | b.ne .Lrefuse_handoff |
| 64 | |
| 65 | ldp x4, x5, [x2, #16] |
| 66 | ldp x6, x7, [x3, #16] |
| 67 | cmp x4, x6 |
| 68 | b.ne .Lrefuse_handoff |
| 69 | cmp x5, x7 |
| 70 | b.ne .Lrefuse_handoff |
| 71 | |
| 72 | /* 8. Emit Diagnostic Checkpoint 3: HANDOFF */ |
| 73 | adr x21, msg_handoff |
| 74 | bl print_string |
| 75 | |
| 76 | /* 9. Establish PHYSICS_ENTRY_ABI */ |
| 77 | mov x0, x22 /* x0 = pointer to Boot Descriptor (0x401FE000) */ |
| 78 | mov x1, #256 /* x1 = payload size (256 bytes) */ |
| 79 | ldr x2, =0x5048595349435330 /* x2 = verification cookie ('PHYSICS0') */ |
| 80 | |
| 81 | /* Static Target Proof: x19 is explicitly loaded from literal 0x40200000 immediately before branch */ |
| 82 | ldr x19, =0x40200000 /* Target: Contract-defined Physics Entry */ |
| 83 | |
| 84 | /* 10. Transfer Control to Physics */ |
| 85 | br x19 |
| 86 | |
| 87 | /* Terminal fallthrough trap */ |
| 88 | b .Lquiescent_halt |
| 89 | |
| 90 | .Lrefuse_handoff: |
| 91 | /* Emit Refusal Diagnostic */ |
| 92 | adr x21, msg_refuse |
| 93 | bl print_string |
| 94 | |
| 95 | .Lquiescent_halt: |
| 96 | /* Fail-Closed Quiescence: no external side effects, no fallthrough */ |
| 97 | wfe |
| 98 | b .Lquiescent_halt |
| 99 | |
| 100 | /* Helper: Polled UART String Output */ |
| 101 | print_string: |
| 102 | .Lprint_char: |
| 103 | ldrb w0, [x21], #1 |
| 104 | cbz w0, .Lprint_ret |
| 105 | str w0, [x20] |
| 106 | b .Lprint_char |
| 107 | .Lprint_ret: |
| 108 | ret |
| 109 | |
| 110 | .balign 8 |
| 111 | msg_awaken: |
| 112 | .asciz "ALPHA: AWAKEN\n" |
| 113 | msg_verify: |
| 114 | .asciz "ALPHA: VERIFY\n" |
| 115 | msg_handoff: |
| 116 | .asciz "ALPHA: HANDOFF\n" |
| 117 | msg_refuse: |
| 118 | .asciz "ALPHA: REFUSE\n" |
| 119 | |
| 120 | .balign 8 |
| 121 | pinned_sha256_digest: |
| 122 | /* e1d89bb1 e0854eba ccd2be5c 756c8a2f f8c5ecc8 c0f90b4a bd461fb7 bf98374c */ |
| 123 | .word 0xe1d89bb1, 0xe0854eba, 0xccd2be5c, 0x756c8a2f |
| 124 | .word 0xf8c5ecc8, 0xc0f90b4a, 0xbd461fb7, 0xbf98374c |
| 125 | |
| 126 | .ltorg |
| 127 | .balign 64 |
| 128 | code_end: |