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 / physics.s

336 lines · 8246 bytes Raw Blame History
1/*
2 * physics.s - Bare-Metal Authority Nucleus for Milestone 2 (PHYSICS_BOOT)
3 * Target Platform: QEMU virt AArch64 / Sovereign Machine
4 * Entry Point: _physics_entry @ 0x40200000
5 * ABI: PHYSICS_ENTRY_ABI
6 */
7
8 .global _physics_entry
9 .global _start
10 .global print_string
11 .global print_hex64
12 .global print_char
13
14 .extern vector_table
15 .extern init_frame_authority
16 .extern init_root_capability
17
18 .section .text.entry, "ax"
19 .balign 64
20
21_physics_entry:
22_start:
23 /*
24 * 1. Validate Verification Cookie in x2:
25 * Must match strictly 0x5048595349435330 (ASCII 'PHYSICS0').
26 */
27 ldr x3, =0x5048595349435330
28 cmp x2, x3
29 b.ne .Lpanic_bad_cookie
30
31 /*
32 * 1b. Validate payload size in x1 against PHYSICS_ENTRY_ABI (6144 bytes).
33 */
34 ldr x3, =6144
35 cmp x1, x3
36 b.ne .Lpanic_bad_payload_size
37
38 /*
39 * 2. Validate Boot Descriptor Pointer in x0:
40 * Must match strictly 0x401FE000.
41 */
42 ldr x3, =0x401FE000
43 cmp x0, x3
44 b.ne .Lpanic_bad_descriptor
45
46 /*
47 * 3. Validate Descriptor Structural Header:
48 * +0x00: magic (u64 == 0x4D424453435F3031, 'MBDSC_01')
49 * +0x08: version (u32 == 1)
50 * +0x0C: length (u32 == 64)
51 * +0x10: flags_reserved (u64 == 0)
52 */
53 ldr x4, [x0, #0]
54 ldr x5, =0x4D424453435F3031
55 cmp x4, x5
56 b.ne .Lpanic_bad_desc_magic
57
58 ldr w4, [x0, #8]
59 cmp w4, #1
60 b.ne .Lpanic_bad_desc_version
61
62 ldr w4, [x0, #12]
63 cmp w4, #64
64 b.ne .Lpanic_bad_desc_length
65
66 ldr x4, [x0, #16]
67 cbnz x4, .Lpanic_bad_desc_reserved
68
69 /*
70 * 4. Validate Machine Profile (Ingress Authority Anti-Expansion Boundary):
71 * For CONTRACT-QEMU-VIRT-AARCH64-M2, require EXACT machine profile matches:
72 * +0x18: ram_base == 0x40000000
73 * +0x20: ram_size == 0x08000000 (128 MiB, DRAM_END strictly 0x48000000)
74 * +0x28: uart_base == 0x09000000 (PL011 MMIO)
75 * +0x30: physics_base == 0x40200000
76 * +0x38: physics_size == 6144
77 */
78 ldr x19, [x0, #24] /* x19 = ram_base */
79 ldr x5, =0x40000000
80 cmp x19, x5
81 b.ne .Lpanic_ingress_corrupt
82
83 ldr x20, [x0, #32] /* x20 = ram_size */
84 ldr x5, =0x08000000
85 cmp x20, x5
86 b.ne .Lpanic_ingress_corrupt
87
88 ldr x21, [x0, #40] /* x21 = uart_base */
89 ldr x5, =0x09000000
90 cmp x21, x5
91 b.ne .Lpanic_ingress_corrupt
92
93 ldr x22, [x0, #48] /* x22 = physics_base */
94 ldr x5, =0x40200000
95 cmp x22, x5
96 b.ne .Lpanic_ingress_corrupt
97
98 ldr x23, [x0, #56] /* x23 = physics_size */
99 ldr x5, =6144
100 cmp x23, x5
101 b.ne .Lpanic_ingress_corrupt
102
103 /*
104 * 5. Copy Validated Ingress Data to PHYSICS_BOOT_STATE @ 0x40205800:
105 * Copy all 64 bytes (8 x 64-bit words) from [x0] to [0x40205800].
106 */
107 ldr x8, =0x40205800
108 ldp x4, x5, [x0, #0]
109 stp x4, x5, [x8, #0]
110 ldp x4, x5, [x0, #16]
111 stp x4, x5, [x8, #16]
112 ldp x4, x5, [x0, #32]
113 stp x4, x5, [x8, #32]
114 ldp x4, x5, [x0, #48]
115 stp x4, x5, [x8, #48]
116
117 /*
118 * 6. Contract-Driven Exception Level Verification (Item 6):
119 * For CONTRACT-QEMU-VIRT-AARCH64-M2, entry level MUST be strictly EL1 (0x04).
120 */
121 mrs x9, CurrentEL
122 and x9, x9, #0x0C
123 cmp x9, #0x04
124 b.ne .Lpanic_uncontracted_el
125
126 /*
127 * Record the verified CurrentEL in the PHYSICS_BOOT_STATE entry record
128 * (+0x40), outside the 64-byte descriptor copy at +0x00..+0x3F.
129 */
130 str x9, [x8, #0x40]
131
132 /*
133 * 7. Switch to Dedicated Kernel Stack:
134 * SP = 0x40205800 (growing downward toward 0x40201800, 16 KiB span).
135 * Zero x0 to abandon Atlas scratchpad pointer.
136 */
137 ldr x10, =0x40205800
138 mov sp, x10
139 mov x0, #0
140
141 /*
142 * 8. Emit Diagnostic Checkpoints:
143 */
144 ldr x0, =msg_awaken
145 bl print_string
146
147 ldr x0, =msg_ingress_valid
148 bl print_string
149
150 ldr x0, =msg_entry_el1_verified
151 bl print_string
152
153 /*
154 * 9. Install Exception Vector Table:
155 */
156 ldr x1, =vector_table
157 msr vbar_el1, x1
158 isb
159
160 ldr x0, =msg_vbar_installed
161 bl print_string
162
163 /*
164 * 10. Initialize Physical Frame Authority:
165 * init_frame_authority(ram_base=0x40000000, ram_size=0x08000000)
166 */
167 ldr x8, =0x40205800
168 ldr x0, [x8, #24] /* ram_base from PHYSICS-owned copy */
169 ldr x1, [x8, #32] /* ram_size from PHYSICS-owned copy */
170 bl init_frame_authority
171 cbz x0, .Lpanic_frame_authority
172
173 /*
174 * 11. Initialize Root Capability (CAP_ROOT):
175 * init_root_capability()
176 */
177 bl init_root_capability
178
179 /*
180 * 12. Normal Boot Milestone Complete:
181 * Emit "PHYSICS: QUIESCENT_READY\n" and enter wfe loop.
182 */
183 ldr x0, =msg_quiescent_ready
184 bl print_string
185
186.Lquiescent_halt:
187 wfe
188 b .Lquiescent_halt
189
190/*
191 * Fail-Closed Panic Traps
192 */
193.Lpanic_bad_cookie:
194 ldr x0, =msg_panic_cookie
195 bl print_string
196 b .Lquiescent_halt
197
198.Lpanic_bad_descriptor:
199 ldr x0, =msg_panic_desc
200 bl print_string
201 b .Lquiescent_halt
202
203.Lpanic_bad_desc_magic:
204 ldr x0, =msg_panic_desc_magic
205 bl print_string
206 b .Lquiescent_halt
207
208.Lpanic_bad_desc_version:
209 ldr x0, =msg_panic_desc_version
210 bl print_string
211 b .Lquiescent_halt
212
213.Lpanic_bad_desc_length:
214 ldr x0, =msg_panic_desc_length
215 bl print_string
216 b .Lquiescent_halt
217
218.Lpanic_bad_desc_reserved:
219 ldr x0, =msg_panic_desc_reserved
220 bl print_string
221 b .Lquiescent_halt
222
223.Lpanic_ingress_corrupt:
224 ldr x0, =msg_panic_ingress
225 bl print_string
226 b .Lquiescent_halt
227
228.Lpanic_bad_payload_size:
229 ldr x0, =msg_panic_payload_size
230 bl print_string
231 b .Lquiescent_halt
232
233.Lpanic_frame_authority:
234 ldr x0, =msg_panic_frame_auth
235 bl print_string
236 b .Lquiescent_halt
237
238.Lpanic_uncontracted_el:
239 ldr x0, =msg_panic_el
240 bl print_string
241 b .Lquiescent_halt
242
243/*
244 * Polled UART String Routines
245 * Uses MMIO base 0x09000000 (PL011 UART).
246 * Clobbers only x0, x2 and x16 (print_string also x1). Callee-saved
247 * registers x19-x28 are never touched, so callers may keep state there.
248 */
249print_string:
250 ldr x16, =0x09000000
251.Lprint_str_loop:
252 ldrb w1, [x0], #1
253 cbz w1, .Lprint_str_ret
254.Lpoll_txff:
255 ldr w2, [x16, #24] /* UART Flag Register (FR) */
256 tbnz w2, #5, .Lpoll_txff /* Wait if TXFF (bit 5) is set */
257 str w1, [x16, #0] /* UART Data Register (DR) */
258 b .Lprint_str_loop
259.Lprint_str_ret:
260 ret
261
262print_char:
263 ldr x16, =0x09000000
264.Lpoll_char:
265 ldr w2, [x16, #24]
266 tbnz w2, #5, .Lpoll_char
267 str w0, [x16, #0]
268 ret
269
270print_hex64:
271 /* Prints 64-bit value in x0 as 16 hex digits with '0x' prefix */
272 stp x29, x30, [sp, #-32]!
273 mov x29, sp
274 stp x19, x20, [sp, #16]
275
276 mov x19, x0
277
278 /* Print '0x' */
279 mov w0, #'0'
280 bl print_char
281 mov w0, #'x'
282 bl print_char
283
284 /* Print 16 nibbles from MSB to LSB */
285 mov w20, #60
286.Lhex_loop:
287 lsr x2, x19, x20
288 and w2, w2, #0x0F
289 cmp w2, #10
290 b.lt .Lhex_digit
291 add w0, w2, #('a' - 10)
292 b .Lhex_out
293.Lhex_digit:
294 add w0, w2, #'0'
295.Lhex_out:
296 bl print_char
297 subs w20, w20, #4
298 b.ge .Lhex_loop
299
300 ldp x19, x20, [sp, #16]
301 ldp x29, x30, [sp], #32
302 ret
303
304 .section .rodata
305 .balign 8
306msg_awaken:
307 .asciz "PHYSICS: AWAKEN\n"
308msg_ingress_valid:
309 .asciz "PHYSICS: INGRESS_VALID\n"
310msg_entry_el1_verified:
311 .asciz "PHYSICS: ENTRY_EL1_VERIFIED\n"
312msg_vbar_installed:
313 .asciz "PHYSICS: VBAR_INSTALLED\n"
314msg_quiescent_ready:
315 .asciz "PHYSICS: QUIESCENT_READY\n"
316
317msg_panic_cookie:
318 .asciz "PHYSICS: PANIC_BAD_COOKIE\n"
319msg_panic_desc:
320 .asciz "PHYSICS: PANIC_BAD_DESCRIPTOR_PTR\n"
321msg_panic_desc_magic:
322 .asciz "PHYSICS: PANIC_BAD_DESC_MAGIC\n"
323msg_panic_desc_version:
324 .asciz "PHYSICS: PANIC_BAD_DESC_VERSION\n"
325msg_panic_desc_length:
326 .asciz "PHYSICS: PANIC_BAD_DESC_LENGTH\n"
327msg_panic_desc_reserved:
328 .asciz "PHYSICS: PANIC_BAD_DESC_RESERVED\n"
329msg_panic_ingress:
330 .asciz "PHYSICS: PANIC_INGRESS_CORRUPT\n"
331msg_panic_payload_size:
332 .asciz "PHYSICS: PANIC_BAD_PAYLOAD_SIZE\n"
333msg_panic_frame_auth:
334 .asciz "PHYSICS: PANIC_FRAME_AUTHORITY\n"
335msg_panic_el:
336 .asciz "PHYSICS: PANIC_UNCONTRACTED_EL\n"