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 / kernel / core / ck_internal.h

157 lines · 7094 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/* ck_internal.h -- declarations shared inside the C kernel core (boot stub,
18 * arch, mm, core). Not part of the stage contract (that is ck.h). */
19#ifndef AIENOS_CK_INTERNAL_H
20#define AIENOS_CK_INTERNAL_H
21
22#include "ck.h"
23#include "handoff.h"
24#include "acpi.h"
25#include "fmt.h"
26
27void *memcpy(void *dst, const void *src, size_t n);
28void *memset(void *dst, int c, size_t n);
29int memcmp(const void *a, const void *b, size_t n);
30size_t strlen(const char *s);
31
32/* ---- console (core/console.c) ---- */
33/* While UEFI boot services live: writer for ConOut (NULL to detach). */
34void ck_console_set_efi(void (*write)(const char *s, size_t n));
35/* SPCR UART: returns 0 if the interface type is supported. */
36int ck_console_set_uart(const struct ck_spcr *spcr);
37/* Name of the active UART driver for the report, e.g. "pl011". */
38const char *ck_console_uart_name(void);
39uint64_t ck_console_uart_base(void);
40/* GOP framebuffer console (core/fbcon.c): set up and clear the screen, then
41 * mirror every console byte on it. -1 if the geometry is unusable. */
42int ck_console_set_fb(volatile void *base, uint32_t width, uint32_t height, uint32_t pitch,
43 uint32_t format);
44/* 0 and the grid while the screen console is on, else -1. */
45int ck_console_fb_info(uint32_t *scale, uint32_t *cols, uint32_t *rows);
46/* Called by ck_reset: hold the screen CK_FB_HOLD_S seconds (build knob). */
47void ck_console_fb_hold(void);
48/* Boot sequence (core/boot_screen.c): stop drawing on the screen; draw again on a cleared one. */
49void ck_console_fb_pause(void);
50void ck_console_fb_resume(void);
51
52/* ---- report (core/report.c) ---- */
53void ck_set_stage(const char *name);
54const char *ck_stage_name(void);
55void ck_report_header(const char *kind);
56__attribute__((noreturn)) void ck_reset(void);
57/* PSCI conduit from the FADT; default SMC. */
58void ck_psci_configure(const void *fadt);
59/* One PSCI call (SMC32/SMC64 calling convention, x0-x3 in, x0 out) on the
60 * configured conduit: HVC only at EL1 when the FADT says HVC, else SMC. */
61int64_t ck_psci_call(uint64_t fn, uint64_t a1, uint64_t a2, uint64_t a3);
62/* "hvc" or "smc": the conduit ck_psci_call uses at the current EL. */
63const char *ck_psci_conduit(void);
64__attribute__((noreturn)) void ck_fault_report(const char *what, uint64_t esr, uint64_t far,
65 uint64_t elr, unsigned el);
66
67/* ---- memory (mm/mmu.c) ---- */
68#define CK_MM_FB_NONE 0u
69#define CK_MM_FB_MAPPED 1u
70#define CK_MM_FB_OVERLAPS_RAM 2u
71struct ck_mm_report {
72 uint64_t root;
73 uint64_t pt_tables;
74 uint64_t stack_lo, stack_hi, stack_guard;
75 uint64_t heap_lo, heap_hi, heap_guard_lo, heap_guard_hi;
76 uint64_t dma_lo, dma_hi;
77 uint64_t ram_ranges, free_bytes;
78 /* CHANDOF3 framebuffer: CK_MM_FB_NONE / _MAPPED (Device-nGnRE, ck_mmio_map)
79 * / _OVERLAPS_RAM (refused: inside a RAM range mapped write-back). */
80 uint32_t fb_map;
81 uint64_t fb_map_bytes;
82};
83/* EL2/firmware phase: frames from the map, our tables, stack, heap, DMA pool.
84 * Returns the stack top for the EL1 entry. */
85uint64_t ck_mm_build(const struct ck_handoff *h);
86const struct ck_handoff *ck_handoff_get(void); /* the record the stub passed (kmain.c) */
87/* EL1 phase: heap ready after the MMU is on. */
88void ck_mm_el1_ready(void);
89const struct ck_mm_report *ck_mm_report(void);
90/* High-water marks: stack words ever written (painted at build), heap free
91 * bytes now and at the lowest point since the heap came up. */
92struct ck_mm_usage {
93 uint64_t stack_bytes, stack_used, heap_bytes, heap_free, heap_min_free;
94};
95void ck_mm_usage(struct ck_mm_usage *u);
96uint64_t ck_mm_mair(void);
97uint64_t ck_mm_tcr(void);
98uint64_t ck_mm_sctlr(void);
99/* Guard-page self test (EL1). 0 if every guard faulted and was contained. */
100int ck_mm_guard_selftest(char *detail, size_t n);
101
102/* ---- artifact loader support (mm/mmu.c) ---- */
103/* Contiguous 4 KiB frames from the free list; 0 on success. */
104int ck_mm_frames_alloc(uint64_t npages, uint64_t *pa);
105/* Returns the frames; nonzero if the free list refused them. */
106int ck_mm_frames_free(uint64_t pa, uint64_t npages);
107uint64_t ck_mm_free_frames(void);
108/* 1 if [pa, pa+len) is identity mapped in the kernel tables. */
109int ck_mm_mapped(uint64_t pa, uint64_t len);
110/* ck_mmio_map without the panic: 0 on RAM overlap or map failure. */
111volatile void *ck_mm_mmio_try_map(uint64_t phys, size_t len);
112
113/* ---- P2 artifact loader (core/artifact_loader.c) ---- */
114void ck_artifact_run(void);
115void ck_artifact_final(void);
116
117/* ---- GIC and timer (arch/gic.c, arch/timer.c) ---- */
118struct ck_gic_report {
119 uint64_t gicd, gicr;
120 uint64_t gicc; /* GICv2 CPU interface base (0 on GICv3) */
121 uint32_t kind; /* 2 = GICv2 MMIO CPU interface, 3 = GICv3 system registers */
122 uint32_t arch_rev;
123 uint64_t icc_sre;
124 uint64_t rd_frame; /* this CPU's redistributor frame */
125};
126int ck_gic_init(const struct ck_madt_gic *madt, struct ck_gic_report *out);
127uint32_t ck_gic_ack(void); /* IRQ entry: INTID, 1020-1023 = spurious */
128void ck_gic_eoi(uint32_t intid);
129struct ck_timer_window {
130 uint64_t ticks, ms, freq_hz, min_interval, max_interval, span;
131};
132int ck_timer_window(uint32_t ms, struct ck_timer_window *out);
133uint64_t ck_counter_to_us(uint64_t counter, uint64_t freq);
134void ck_timer_tick(void); /* IRQ dispatcher: INTID 30 */
135/* M3 isolation checks: threads, el0, preempt, placement, ipc (core/m3.c). */
136void ck_m3_run(void);
137/* arch/rndr.c: probe FEAT_RNG + two RNDR words once, before any consumer.
138 * Returns CK_RNG_OK or the refusal (see core/entropy.h). */
139int ck_entropy_init(void);
140const char *ck_entropy_source(void); /* "rndr" (default) or "rng200" (CK_PI5) */
141uint64_t ck_entropy_retries(void);
142/* core/smp.c: secondary cores through PSCI CPU_ON, each on its own stack with
143 * the MMU on the boot core's tables, checked in and parked in WFE. Prints
144 * the smp: lines scripts/qemu_ck_smp_test.sh judges; never panics. */
145void ck_smp_run(void);
146#ifdef CK_B7B_PROBE
147/* Cut B7b preparation probe (core/smmu_svc.c), probe build only. */
148void ck_b7b_probe(void);
149#ifdef CK_B7B_EVENT_READOUT
150void ck_b7b_event_readout(void);
151#endif
152#endif
153void ck_fpu_run(void); /* core/fpu.c: probe build only (CK_RUST_LIBS), else a no-op */
154void ck_infer_run(void); /* core/infer.c: probe build only (CK_INFER_LIB), else a no-op */
155void ck_allen_run(void); /* core/allen.c: pi5-allen exam stage only (CK_ALLEN, CK_ALLEN_LIB), else a no-op */
156
157#endif