interplane.Get Omega
Read in your language

physics-mv

FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.

Brought by drakestapleton

branch main Branches Tags History

physics-mv / atlas_m2.s

174 lines · 4727 bytes Raw Blame History
1/*
2 * ATLAS M2: Bootstrap Seed for Milestone 2 (PHYSICS_BOOT)
3 *
4 * The pinned SHA-256 of physics.bin lives in physics_pin.inc, which
5 * build_m2.py regenerates from the physics.bin it just built. That file is
6 * the single source for the pin; this file carries no digest copy.
7 *
8 * Descriptor fields and PHYSICS_ENTRY_ABI registers default to the
9 * CONTRACT-QEMU-VIRT-AARCH64-M2 values. The Seam 2 hostile matrix overrides
10 * one at a time with `--defsym NAME=value`; the canonical build overrides none.
11 */
12
13.ifndef DESC_MAGIC
14.equ DESC_MAGIC, 0x4D424453435F3031
15.endif
16.ifndef DESC_VERSION
17.equ DESC_VERSION, 1
18.endif
19.ifndef DESC_LENGTH
20.equ DESC_LENGTH, 64
21.endif
22.ifndef DESC_FLAGS
23.equ DESC_FLAGS, 0
24.endif
25.ifndef DESC_RAM_BASE
26.equ DESC_RAM_BASE, 0x40000000
27.endif
28.ifndef DESC_RAM_SIZE
29.equ DESC_RAM_SIZE, 0x08000000
30.endif
31.ifndef DESC_UART_BASE
32.equ DESC_UART_BASE, 0x09000000
33.endif
34.ifndef DESC_PHYSICS_BASE
35.equ DESC_PHYSICS_BASE, 0x40200000
36.endif
37.ifndef DESC_PHYSICS_SIZE
38.equ DESC_PHYSICS_SIZE, 6144
39.endif
40.ifndef ABI_X0
41.equ ABI_X0, 0x401FE000
42.endif
43.ifndef ABI_X1
44.equ ABI_X1, 6144
45.endif
46.ifndef ABI_X2
47.equ ABI_X2, 0x5048595349435330
48.endif
49
50.global _start
51.section .text
52.balign 64
53
54_start:
55 /* 1. Mask all interrupts (DAIF: D=1, A=1, I=1, F=1) */
56 msr daifset, #0xf
57
58 /* 2. Initialize Stack Pointer to Scratchpad RAM (Disjoint from Descriptor @ 0x401FE000) */
59 ldr x0, =0x401FC000
60 mov sp, x0
61
62 /* 3. Initialize UART MMIO Base Pointer in x20 */
63 ldr x20, =0x09000000
64
65 /* 4. Emit Diagnostic Checkpoint 1: AWAKEN */
66 adr x21, msg_awaken
67 bl print_string
68
69 /* 5. Populate Machine Boot Descriptor at 0x401FE000 (64 bytes) */
70 ldr x22, =0x401FE000
71 ldr x0, =DESC_MAGIC /* +0x00: magic = 'MBDSC_01' */
72 str x0, [x22, #0]
73 ldr w0, =DESC_VERSION /* +0x08: version (u32) */
74 str w0, [x22, #8]
75 ldr w0, =DESC_LENGTH /* +0x0C: length (u32) */
76 str w0, [x22, #12]
77 ldr x0, =DESC_FLAGS /* +0x10: flags_reserved (u64) */
78 str x0, [x22, #16]
79 ldr x0, =DESC_RAM_BASE /* +0x18: RAM Base */
80 str x0, [x22, #24]
81 ldr x0, =DESC_RAM_SIZE /* +0x20: RAM Size */
82 str x0, [x22, #32]
83 ldr x0, =DESC_UART_BASE /* +0x28: UART MMIO Base */
84 str x0, [x22, #40]
85 ldr x0, =DESC_PHYSICS_BASE /* +0x30: Physics Payload Base */
86 str x0, [x22, #48]
87 ldr x0, =DESC_PHYSICS_SIZE /* +0x38: Physics Payload Size */
88 str x0, [x22, #56]
89
90 /* 6. Emit Diagnostic Checkpoint 2: VERIFY */
91 adr x21, msg_verify
92 bl print_string
93
94 /* 7. Verify PHYSICS Integrity using Cryptographic SHA-256 */
95 /* sha256_compute(payload, len, scratch_buf, out_digest) */
96 ldr x0, =0x40200000 /* Arg 0: Payload base */
97 ldr x1, =6144 /* Arg 1: Length = 6144 bytes */
98 ldr x2, =0x401FE100 /* Arg 2: 128-byte scratchpad for padding block */
99 ldr x3, =0x401FE080 /* Arg 3: 32-byte digest output buffer */
100 bl sha256_compute
101
102 /* Compare computed 32-byte SHA-256 against pinned expected digest */
103 ldr x2, =0x401FE080
104 adr x3, pinned_sha256_digest
105
106 /* Compare 8 x 32-bit words (2 x 64-bit pair loads) */
107 ldp x4, x5, [x2, #0]
108 ldp x6, x7, [x3, #0]
109 cmp x4, x6
110 b.ne .Lrefuse_handoff
111 cmp x5, x7
112 b.ne .Lrefuse_handoff
113
114 ldp x4, x5, [x2, #16]
115 ldp x6, x7, [x3, #16]
116 cmp x4, x6
117 b.ne .Lrefuse_handoff
118 cmp x5, x7
119 b.ne .Lrefuse_handoff
120
121 /* 8. Emit Diagnostic Checkpoint 3: HANDOFF */
122 adr x21, msg_handoff
123 bl print_string
124
125 /* 9. Establish PHYSICS_ENTRY_ABI */
126 ldr x0, =ABI_X0 /* x0 = pointer to Boot Descriptor (0x401FE000) */
127 ldr x1, =ABI_X1 /* x1 = payload size (6144 bytes) */
128 ldr x2, =ABI_X2 /* x2 = verification cookie ('PHYSICS0') */
129
130 /* Static Target Proof: x19 is explicitly loaded from literal 0x40200000 immediately before branch */
131 ldr x19, =0x40200000 /* Target: Contract-defined Physics Entry */
132
133 /* 10. Transfer Control to Physics */
134 br x19
135
136 /* Terminal fallthrough trap */
137 b .Lquiescent_halt
138
139.Lrefuse_handoff:
140 /* Emit Refusal Diagnostic */
141 adr x21, msg_refuse
142 bl print_string
143
144.Lquiescent_halt:
145 /* Fail-Closed Quiescence */
146 wfe
147 b .Lquiescent_halt
148
149/* Helper: Polled UART String Output */
150print_string:
151.Lprint_char:
152 ldrb w0, [x21], #1
153 cbz w0, .Lprint_ret
154 str w0, [x20]
155 b .Lprint_char
156.Lprint_ret:
157 ret
158
159.balign 8
160msg_awaken:
161 .asciz "ATLAS: AWAKEN\n"
162msg_verify:
163 .asciz "ATLAS: VERIFY\n"
164msg_handoff:
165 .asciz "ATLAS: HANDOFF\n"
166msg_refuse:
167 .asciz "ATLAS: REFUSE\n"
168
169.balign 8
170pinned_sha256_digest:
171 .include "physics_pin.inc"
172
173.ltorg
174.balign 64