interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / boot / handoff.h

133 lines · 8501 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* handoff.h -- what the AIENOS UEFI boot stub passes to the C kernel core
18 * after ExitBootServices. Everything referenced here lives in memory the
19 * frame allocator never hands out (the loaded image, LoaderData, ACPI).
20 *
21 * CHANDOF2 (2026-10-04, aienos#34 lane 6): CHANDOF1 plus the yardstick
22 * model's bytes, read by the stub from the boot disk before ExitBootServices
23 * (native/boot/efi_model.c, map format native/boot/model_map.h).
24 * CHANDOF3 (2026-10-04, L6-C): CHANDOF2 plus the UEFI Graphics Output
25 * Protocol linear framebuffer the stub found before ExitBootServices
26 * (native/boot/efi_gop.c), so the kernel can show its report on a screen
27 * (core/fbcon.c). Per the contract (docs/BOOT_HANDOFF_CONTRACT.md section 8)
28 * a new layout gets a new magic; a kernel built for CHANDOF3 refuses
29 * CHANDOF1 and CHANDOF2 as "unsupported version <n>". */
30#ifndef AIENOS_CK_HANDOFF_H
31#define AIENOS_CK_HANDOFF_H
32#include <stdint.h>
33#include <stddef.h>
34
35#define CK_HANDOFF_MAGIC 0x33464f444e414843ull /* "CHANDOF3" */
36#define CK_HANDOFF_MAGIC_V1 0x31464f444e414843ull /* "CHANDOF1": refused */
37#define CK_HANDOFF_MAGIC_V2 0x32464f444e414843ull /* "CHANDOF2": refused */
38/* The seven bytes "CHANDOF" (little endian, low 56 bits); the top byte is
39 * the ASCII version digit. */
40#define CK_HANDOFF_MAGIC_STEM 0x00464f444e414843ull
41
42/* model_flags */
43#define CK_HANDOFF_MODEL_PRESENT 1u /* model_base/model_len hold the model */
44#define CK_HANDOFF_MODEL_BLOCKIO 2u /* read through UEFI Block I/O from MODEL.MAP */
45
46/* fb_status (CHANDOF3) */
47#define CK_HANDOFF_FB_NONE 0u /* no Graphics Output Protocol: every fb_* field zero */
48#define CK_HANDOFF_FB_PRESENT 1u /* linear 32-bit framebuffer, fb_format 0 (RGBX) or 1 (BGRX) */
49#define CK_HANDOFF_FB_NO_LINEAR 2u /* GOP found, but PixelBitMask/PixelBltOnly: fb_base/fb_size zero */
50/* fb_format: EFI_GRAPHICS_PIXEL_FORMAT (UEFI 2.10 section 12.9.2) */
51#define CK_HANDOFF_FB_RGBX 0u /* PixelRedGreenBlueReserved8BitPerColor: byte 0 red */
52#define CK_HANDOFF_FB_BGRX 1u /* PixelBlueGreenRedReserved8BitPerColor: byte 0 blue */
53#define CK_HANDOFF_FB_MAX_DIM 16384u /* refused above this width/height/pitch */
54
55struct ck_handoff {
56 uint64_t magic;
57 uint32_t firmware_el; /* CurrentEL at UEFI entry (2 on QEMU virtualization=on) */
58 uint32_t desc_version;
59 uint64_t firmware_ttbr0; /* TTBR0_EL2 (or EL1) firmware translated with */
60 uint64_t firmware_sctlr; /* SCTLR_EL2 (or EL1) of the firmware regime */
61 uint64_t rsdp; /* ACPI 2.0 RSDP physical address, 0 if absent */
62 uint64_t memory_map; /* copy of the final UEFI memory map */
63 uint64_t map_size;
64 uint64_t desc_size;
65 uint64_t image_base; /* loaded PE image, [base, end) */
66 uint64_t image_end;
67 uint64_t counter_freq_hz;
68 uint64_t uefi_entry_ticks;
69 uint32_t exit_attempts; /* ExitBootServices calls until success */
70 uint32_t reserved0;
71 const char *commit;
72 /* CHANDOF2: the model (EfiLoaderData pages, 4 KiB aligned), or all zero. */
73 uint64_t model_base;
74 uint64_t model_len; /* bytes */
75 uint8_t model_sha256[32]; /* declared by MODEL.MAP; the kernel recomputes */
76 uint32_t model_flags; /* CK_HANDOFF_MODEL_* */
77 uint32_t model_extents; /* extents read */
78 uint64_t model_read_us; /* firmware Block I/O time for the whole model */
79 uint64_t model_disk_last_block; /* EFI_BLOCK_IO_MEDIA.LastBlock of the disk */
80 uint32_t model_block_size; /* EFI_BLOCK_IO_MEDIA.BlockSize of the disk */
81 uint32_t reserved1; /* zero */
82 /* CHANDOF3: the GOP framebuffer (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE and its
83 * Info, UEFI 2.10 section 12.9.2), or all zero without a GOP. */
84 uint64_t fb_base; /* FrameBufferBase: physical, pixel (0,0) */
85 uint64_t fb_size; /* FrameBufferSize, bytes */
86 uint32_t fb_width; /* HorizontalResolution, pixels */
87 uint32_t fb_height; /* VerticalResolution, pixels */
88 uint32_t fb_pitch; /* PixelsPerScanLine (pixels, not bytes) */
89 uint32_t fb_format; /* CK_HANDOFF_FB_RGBX / _BGRX (EFI enum value) */
90 uint32_t fb_status; /* CK_HANDOFF_FB_* */
91 uint32_t fb_gop_handles; /* GOP handles the stub saw (report only) */
92};
93/* Layout pins for the frozen CHANDOF3 record (docs/BOOT_HANDOFF_CONTRACT.md
94 * section 3, LP64): a reorder, resize or new field fails the build. */
95_Static_assert(sizeof(struct ck_handoff) == 232, "ck_handoff size");
96_Static_assert(offsetof(struct ck_handoff, magic) == 0, "ck_handoff.magic offset");
97_Static_assert(offsetof(struct ck_handoff, firmware_el) == 8, "ck_handoff.firmware_el offset");
98_Static_assert(offsetof(struct ck_handoff, desc_version) == 12, "ck_handoff.desc_version offset");
99_Static_assert(offsetof(struct ck_handoff, firmware_ttbr0) == 16, "ck_handoff.firmware_ttbr0 offset");
100_Static_assert(offsetof(struct ck_handoff, firmware_sctlr) == 24, "ck_handoff.firmware_sctlr offset");
101_Static_assert(offsetof(struct ck_handoff, rsdp) == 32, "ck_handoff.rsdp offset");
102_Static_assert(offsetof(struct ck_handoff, memory_map) == 40, "ck_handoff.memory_map offset");
103_Static_assert(offsetof(struct ck_handoff, map_size) == 48, "ck_handoff.map_size offset");
104_Static_assert(offsetof(struct ck_handoff, desc_size) == 56, "ck_handoff.desc_size offset");
105_Static_assert(offsetof(struct ck_handoff, image_base) == 64, "ck_handoff.image_base offset");
106_Static_assert(offsetof(struct ck_handoff, image_end) == 72, "ck_handoff.image_end offset");
107_Static_assert(offsetof(struct ck_handoff, counter_freq_hz) == 80, "ck_handoff.counter_freq_hz offset");
108_Static_assert(offsetof(struct ck_handoff, uefi_entry_ticks) == 88, "ck_handoff.uefi_entry_ticks offset");
109_Static_assert(offsetof(struct ck_handoff, exit_attempts) == 96, "ck_handoff.exit_attempts offset");
110_Static_assert(offsetof(struct ck_handoff, reserved0) == 100, "ck_handoff.reserved0 offset");
111_Static_assert(offsetof(struct ck_handoff, commit) == 104, "ck_handoff.commit offset");
112_Static_assert(offsetof(struct ck_handoff, model_base) == 112, "ck_handoff.model_base offset");
113_Static_assert(offsetof(struct ck_handoff, model_len) == 120, "ck_handoff.model_len offset");
114_Static_assert(offsetof(struct ck_handoff, model_sha256) == 128, "ck_handoff.model_sha256 offset");
115_Static_assert(offsetof(struct ck_handoff, model_flags) == 160, "ck_handoff.model_flags offset");
116_Static_assert(offsetof(struct ck_handoff, model_extents) == 164, "ck_handoff.model_extents offset");
117_Static_assert(offsetof(struct ck_handoff, model_read_us) == 168, "ck_handoff.model_read_us offset");
118_Static_assert(offsetof(struct ck_handoff, model_disk_last_block) == 176, "ck_handoff.model_disk_last_block offset");
119_Static_assert(offsetof(struct ck_handoff, model_block_size) == 184, "ck_handoff.model_block_size offset");
120_Static_assert(offsetof(struct ck_handoff, reserved1) == 188, "ck_handoff.reserved1 offset");
121_Static_assert(offsetof(struct ck_handoff, fb_base) == 192, "ck_handoff.fb_base offset");
122_Static_assert(offsetof(struct ck_handoff, fb_size) == 200, "ck_handoff.fb_size offset");
123_Static_assert(offsetof(struct ck_handoff, fb_width) == 208, "ck_handoff.fb_width offset");
124_Static_assert(offsetof(struct ck_handoff, fb_height) == 212, "ck_handoff.fb_height offset");
125_Static_assert(offsetof(struct ck_handoff, fb_pitch) == 216, "ck_handoff.fb_pitch offset");
126_Static_assert(offsetof(struct ck_handoff, fb_format) == 220, "ck_handoff.fb_format offset");
127_Static_assert(offsetof(struct ck_handoff, fb_status) == 224, "ck_handoff.fb_status offset");
128_Static_assert(offsetof(struct ck_handoff, fb_gop_handles) == 228, "ck_handoff.fb_gop_handles offset");
129
130/* Kernel core entry, still at the firmware EL with firmware translation. */
131__attribute__((noreturn)) void ck_kernel_entry(struct ck_handoff *h);
132
133#endif