aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / boot / efi_allen.c
| 1 | /* efi_allen.c -- read \EFI\AIENOS\ALLEN.EXM from the boot volume before ExitBootServices (pi5-allen image, |
| 2 | * CK_ALLEN, PI5-8 cut K). Nothing is written. The bytes are kept as read; the kernel stage (core/allen.c) has the |
| 3 | * Rust unit check the whole file before any case runs. Result in ck_allen_boot: ABSENT (no file: the stage says so |
| 4 | * and runs nothing), REFUSED (unreadable or over the size bound), FOUND. */ |
| 5 | #include "efi.h" |
| 6 | #include "../kernel/core/allen.h" |
| 7 | #include "../kernel/arch/arch.h" |
| 8 | #include "../kernel/core/ck_internal.h" |
| 9 | |
| 10 | struct ck_allen_boot ck_allen_boot __attribute__((aligned(64))); |
| 11 | |
| 12 | void ck_boot_allen_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) |
| 13 | { |
| 14 | static const EFI_GUID li_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID_INIT; |
| 15 | static const EFI_GUID fs_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID_INIT; |
| 16 | static CHAR16 path[] = {'\\', 'E', 'F', 'I', '\\', 'A', 'I', 'E', 'N', 'O', 'S', '\\', |
| 17 | 'A', 'L', 'L', 'E', 'N', '.', 'E', 'X', 'M', 0}; |
| 18 | EFI_BOOT_SERVICES *bs = st->BootServices; |
| 19 | EFI_LOADED_IMAGE_PROTOCOL *li = 0; |
| 20 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs = 0; |
| 21 | EFI_FILE_PROTOCOL *root = 0, *f = 0; |
| 22 | ck_allen_boot.state = CK_ALLEN_EXM_ABSENT; |
| 23 | ck_allen_boot.len = 0; |
| 24 | if (bs->HandleProtocol(image, &li_guid, (void **)&li) != EFI_SUCCESS || !li || !li->DeviceHandle || |
| 25 | bs->HandleProtocol(li->DeviceHandle, &fs_guid, (void **)&fs) != EFI_SUCCESS || !fs || |
| 26 | fs->OpenVolume(fs, &root) != EFI_SUCCESS || !root) { |
| 27 | ck_puts("allen_exam: absent (boot volume not readable)\n"); |
| 28 | return; |
| 29 | } |
| 30 | if (root->Open(root, &f, path, EFI_FILE_MODE_READ, 0) != EFI_SUCCESS || !f) { |
| 31 | root->Close(root); |
| 32 | ck_puts("allen_exam: absent (no " CK_ALLEN_EXM_PATH ")\n"); |
| 33 | return; |
| 34 | } |
| 35 | uint64_t n = sizeof ck_allen_boot.buf; /* one byte more than the format allows: a longer file is refused */ |
| 36 | EFI_STATUS s = f->Read(f, &n, ck_allen_boot.buf); |
| 37 | f->Close(f); |
| 38 | root->Close(root); |
| 39 | if (s != EFI_SUCCESS || n < 1 || n > CK_ALLEN_FILE_MAX) { |
| 40 | ck_allen_boot.state = CK_ALLEN_EXM_REFUSED; |
| 41 | ck_printf("allen_exam: refused (read status=0x%llx bytes=%llu, want 1..%u)\n", (unsigned long long)s, |
| 42 | (unsigned long long)n, (unsigned)CK_ALLEN_FILE_MAX); |
| 43 | return; |
| 44 | } |
| 45 | ck_allen_boot.len = (uint32_t)n; |
| 46 | ck_allen_boot.state = CK_ALLEN_EXM_FOUND; |
| 47 | ck_printf("allen_exam: read %llu bytes from " CK_ALLEN_EXM_PATH " (QUALIFICATION ONLY)\n", (unsigned long long)n); |
| 48 | } |