aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
GitHub aien-dev/aienux#343 (code only)
Apply it
git checkout -b patch-4f3beccf44769b67 99803441867a61c82c135fdbba9c217b1949dff3 curl -fsSL https://interplane.io/drakestapleton/aienux/patches/4f3beccf44769b67.patch | git am
Provenance
github-import 1
aien-dev/aienux
343
4d9c4e2981ffdd4f100eb95445389919353f8ab7
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":343,"url":"https://github.com/aien-dev/aienux/pull/343","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:14Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index 718be415..1d416af4 100644 --- a/.crumb +++ b/.crumb @@ -33,27 +33,27 @@ "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "6cc9d9e29fa3474d7c9223f2da8e3a245524880d8c69ded50e5af4bdfc96d6a8", - "last_commit": "1adbd4b", + "digest": "14abb7c618d5192662cfd3248161b7bb356c5b304611ff1d034c905f95e5d3c0", + "last_commit": "391fcd5", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "789ab6f9dbc46868a4b3e1541d7e66381b8241f58501ba512ead25c3a40fd471", - "last_commit": "1adbd4b", + "digest": "b0f4248c62a868c7b516d0a639ca2ecd1b1a5c0a4c732d64ad102749c8dfdd7b", + "last_commit": "391fcd5", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:801dea0a1eca64203458df980107b1b8edc62bd51358b561377f0e41a7926fa0", - "compiled_at": "2026-10-13T03:39:20Z", + "children_root": "sha256:fc2a422de557ffcd776711b98718080981836d9c43b5c2e209604ead08a49ad3", + "compiled_at": "2026-10-13T04:45:02Z", "compiler": "crumb-compile/1", - "digest": "sha256:fdd9dca042265294f0810e6b006e5dc19d5485f95f4ef053fe865ddfcb944f82", + "digest": "sha256:2eac9ae595eba28a9f52f9d8efb615c63ce03951b245ecf07b6b0dcc73c0685c", "evidence_files": 156, "evidence_root": "sha256:cd53ab119be9de6ce28c4f5949b106c9622f1fe105611de3de21c3bce7932694", "files": 3119, - "generated_at_commit": "1adbd4b7707bd586c253296ab4ca9f1e57015a9d", - "source_tree": "sha256:27a1e423ddad05c5e50d69ec032ce37be23bc9bede61825540648379c8527b21" + "generated_at_commit": "391fcd54707b2ba006e0652c71259a17ef78ec6a", + "source_tree": "sha256:2776a1b24ed444cb4cab16e0376a23124e6ff067d135c441683042f84eee9e0e" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/ck-kernel.yml b/.github/workflows/ck-kernel.yml index 2967fac9..0f61eb29 100644 --- a/.github/workflows/ck-kernel.yml +++ b/.github/workflows/ck-kernel.yml @@ -115,6 +115,13 @@ jobs: sudo apt-get install -y mtools bash scripts/qemu_ck_pi5_diag_test.sh + - name: C kernel boot on a GICv2 machine (AIENOS-PI5 step 1, the Raspberry Pi 5 GIC-400 shape, QEMU gic-version=2) + env: + AIENOS_QUIET_FLAG: ${{ runner.temp }}/spark-quiet + AIENOS_GATE_LOCK: ${{ runner.temp }}/qemu-gate-lock + AIENOS_QEMU_GIC: "2" + run: bash scripts/qemu_ck_boot_test.sh + - name: Check the host tests left the tree clean (the gate runner refuses a dirty tree) run: | git status --porcelain --untracked-files=normal diff --git a/native/.crumb b/native/.crumb index d32ea7c9..1edf029f 100644 --- a/native/.crumb +++ b/native/.crumb @@ -56,7 +56,7 @@ }, { "digest": "75239007e38138a416cfa36166d3c95837b7f0f4c1daab6182cd1d9c034dab14", - "last_commit": "1adbd4b", + "last_commit": "9980344", "name": "boot", "purpose": "Directory native/boot. Purpose not yet described by a human." }, @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "17da0efd01cac3b85c8eff9cb5aa97cf910ec231f27cafecc76e98fe67207055", - "last_commit": "1adbd4b", + "digest": "d42b02fe5930b1f65af466ecded139a8c4562a28ffcad4dc3e7481407894e13f", + "last_commit": "391fcd5", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, @@ -109,15 +109,15 @@ "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:138b39a0443ea9ebfc8bdbc791d629bd0ddbeca661f8764892187cac7476579e", - "compiled_at": "2026-10-13T03:39:20Z", + "children_root": "sha256:f81941d430e2ccb2a33a6d7bc6a68c57d864a45ab5427651bf543fb481f9e815", + "compiled_at": "2026-10-13T04:45:02Z", "compiler": "crumb-compile/1", - "digest": "sha256:6cc9d9e29fa3474d7c9223f2da8e3a245524880d8c69ded50e5af4bdfc96d6a8", + "digest": "sha256:14abb7c618d5192662cfd3248161b7bb356c5b304611ff1d034c905f95e5d3c0", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", "files": 489, - "generated_at_commit": "1adbd4b7707bd586c253296ab4ca9f1e57015a9d", - "source_tree": "sha256:7db1e9ecbf2a2958b627a710cb6ecb8e163d4a90b22124f875d569a44b465e64" + "generated_at_commit": "391fcd54707b2ba006e0652c71259a17ef78ec6a", + "source_tree": "sha256:f7ea589aa7b49f381e29dfaaf8500f601f6dc9457ffba18d57711c9e1524eeec" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 51e26f82..c74facef 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -45,8 +45,8 @@ "generated": { "children": [ { - "digest": "4c9da3fdaf762c784403ae3281c3a7e49b891596ed52ab27aaf62f2ea66c5502", - "last_commit": "2ee61b4", + "digest": "b12ce043af831c40220c7546c603e941604e5875d0bd5b591df1d650a5053ef0", + "last_commit": "391fcd5", "name": "arch", "purpose": "Directory native/kernel/arch. Purpose not yet described by a human." }, @@ -57,8 +57,8 @@ "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { - "digest": "5f5def88e2ef4bbd425e833cecb75d7cc805e7516a5128a88a7dea4e9b87cdd9", - "last_commit": "2cdd37f", + "digest": "3113e99820041c9ba4481d6da5d6dcebb3eaaf25867e4278945544260466d5f3", + "last_commit": "391fcd5", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, @@ -87,8 +87,8 @@ "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { - "digest": "515f5d05394be70d66a845c3d5f2aecdd11e5402c189aefeb817577857ad0118", - "last_commit": "2cdd37f", + "digest": "da6470d80184ef3a173623e87a9712d4643f67d73dbab6be80f7e41902fc81e4", + "last_commit": "391fcd5", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, @@ -99,15 +99,15 @@ "purpose": "Hosted (Linux-built) checkers for the native kernel, run by `make -C native/kernel test`; nothin" } ], - "children_root": "sha256:6e029b6ca56fd468865463b2676ec83380dc39ac2541d45078cfb2e1e35f0669", - "compiled_at": "2026-10-13T03:39:20Z", + "children_root": "sha256:c4368bc26c5db8c0657821ed5865ceaf328cb8c0519af1b83d4da60f73503ef6", + "compiled_at": "2026-10-13T04:45:02Z", "compiler": "crumb-compile/1", - "digest": "sha256:17da0efd01cac3b85c8eff9cb5aa97cf910ec231f27cafecc76e98fe67207055", + "digest": "sha256:d42b02fe5930b1f65af466ecded139a8c4562a28ffcad4dc3e7481407894e13f", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 317, - "generated_at_commit": "1adbd4b7707bd586c253296ab4ca9f1e57015a9d", - "source_tree": "sha256:5fa209d14d2d416fc07a3afc91759bdf850729cc019687447e2aad73cbff9466" + "generated_at_commit": "391fcd54707b2ba006e0652c71259a17ef78ec6a", + "source_tree": "sha256:34a46f83a39f76993699af90e537d258752aefffff99710bce173113079fce2d" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/README.md b/native/kernel/README.md index 802d357c..865dbfd7 100644 --- a/native/kernel/README.md +++ b/native/kernel/README.md @@ -9,7 +9,7 @@ QEMU qualifies nothing physical: a PASS here says nothing about real hardware. | Path | What | | --- | --- | | `include/ck.h` | Frozen contract for stage code (devices, security, store). Lane 18 core added only `ck_irq_register`, `ck_irq_enable`, `ck_irq_cpu_enable`. | -| `arch/` | Vectors, EL2 -> EL1h entry (ADR 0009), recoverable probe, exception and IRQ dispatch, GICv3, EL1 physical timer. | +| `arch/` | Vectors, EL2 -> EL1h entry (ADR 0009), recoverable probe, exception and IRQ dispatch, GICv3 or GICv2 (picked from the MADT; GICv2 is the Raspberry Pi 5 GIC-400 shape, QEMU gate `AIENOS_QEMU_GIC=2 scripts/qemu_ck_boot_test.sh`), EL1 physical timer. | | `mm/` | Frame allocator (UEFI map), 4 KiB-granule page-table builder, heap, the kernel address space (`mmu.c`). | | `core/` | Console, printf, ACPI, reports/panic/PSCI reset, M3 (threads, scheduler, EL0, capabilities, IPC), `kmain.c`. | | `tests/` | Host unit tests. | diff --git a/native/kernel/arch/.crumb b/native/kernel/arch/.crumb index b18b85a0..a30a4598 100644 --- a/native/kernel/arch/.crumb +++ b/native/kernel/arch/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-04T13:47:18Z", + "compiled_at": "2026-10-13T04:45:02Z", "compiler": "crumb-compile/1", - "digest": "sha256:4c9da3fdaf762c784403ae3281c3a7e49b891596ed52ab27aaf62f2ea66c5502", + "digest": "sha256:b12ce043af831c40220c7546c603e941604e5875d0bd5b591df1d650a5053ef0", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 8, - "generated_at_commit": "a863d5c1f5bd89c88c5f6671eecfd27b599ee512", - "source_tree": "sha256:4a52e32ff5b03da822abdbf8b12e84e7b4ce62afa965002966470544a4922e2d" + "generated_at_commit": "391fcd54707b2ba006e0652c71259a17ef78ec6a", + "source_tree": "sha256:7aa547afeb178b071ac7b759fe076a594cb67a63367dd21e83523a771cc09c7d" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/arch/exception.c b/native/kernel/arch/exception.c index 6a562f51..7ba4a355 100644 --- a/native/kernel/arch/exception.c +++ b/native/kernel/arch/exception.c @@ -74,7 +74,7 @@ static uint64_t spurious, unhandled; struct ck_frame *ck_irq_dispatch(struct ck_frame *f) { - uint32_t id = (uint32_t)ck_rd_s(ICC_IAR1_EL1) & 0xffffff; + uint32_t id = ck_gic_ack(); if (id >= 1020) { spurious++; return f; @@ -85,7 +85,7 @@ struct ck_frame *ck_irq_dispatch(struct ck_frame *f) irq_table[id].fn(irq_table[id].arg); else unhandled++; - ck_wr_s(ICC_EOIR1_EL1, id); + ck_gic_eoi(id); ck_isb(); if (id == 30 && ck_tick_switch) return ck_tick_switch(f); diff --git a/native/kernel/arch/gic.c b/native/kernel/arch/gic.c index 8a36b213..0ef3146d 100644 --- a/native/kernel/arch/gic.c +++ b/native/kernel/arch/gic.c @@ -1,6 +1,16 @@ -/* gic.c -- GICv3 from the ACPI MADT: distributor, this CPU's redistributor - * (found by GICR_TYPER affinity), system-register CPU interface, and the - * IRQ enable service for device code. Register offsets: GICv3 spec 12.8-12.11. */ +/* gic.c -- the interrupt controller from the ACPI MADT, and the IRQ enable + * service for device code. Two kinds: + * - GICv3 (Spark, QEMU gic-version=3): distributor, this CPU's redistributor + * (found by GICR_TYPER affinity), system-register CPU interface. Register + * offsets: GICv3 spec 12.8-12.11. + * - GICv2 (Raspberry Pi 5 GIC-400, QEMU gic-version=2): distributor and the + * memory-mapped CPU interface from the MADT GICC Physical Base Address. + * Offsets as Linux include/linux/irqchip/arm-gic.h (GIC_DIST_*, GIC_CPU_*). + * Group registers are left as firmware set them: with the Security + * Extensions (the Pi) this non-secure view enables Group 1 through bit 0 of + * GICD_CTLR/GICC_CTLR and IGROUPR is not ours; without them (QEMU) bit 0 + * enables Group 0, the reset group, which GICC_IAR acknowledges. Same as + * Linux irq-gic.c (GICD_ENABLE, GICC_ENABLE, priority mask 0xf0). */ #include "arch.h" #include "ck_internal.h" @@ -8,16 +18,24 @@ #define GICD_IGROUPR 0x0080 #define GICD_ISENABLER 0x0100 #define GICD_IPRIORITYR 0x0400 +#define GICD_ITARGETSR 0x0800 #define GICD_IROUTER 0x6000 #define GICD_PIDR2 0xffe8 +#define GICD_V2_PIDR2 0x0fe8 #define GICR_TYPER 0x0008 #define GICR_WAKER 0x0014 #define GICR_SGI 0x10000 #define GICR_IGROUPR0 (GICR_SGI + 0x0080) #define GICR_ISENABLER0 (GICR_SGI + 0x0100) #define GICR_IPRIORITYR (GICR_SGI + 0x0400) +#define GICC_CTLR 0x00 +#define GICC_PMR 0x04 +#define GICC_BPR 0x08 +#define GICC_IAR 0x0c +#define GICC_EOIR 0x10 -static volatile uint8_t *gicd, *rd; +static volatile uint8_t *gicd, *rd, *gicc; +static unsigned gic_kind; /* 0 none, 2 GICv2 (MMIO CPU interface), 3 GICv3 */ static uint32_t r32(volatile uint8_t *b, uint32_t off) { return *(volatile uint32_t *)(b + off); } static void w32(volatile uint8_t *b, uint32_t off, uint32_t v) { *(volatile uint32_t *)(b + off) = v; } @@ -44,16 +62,46 @@ static uint64_t my_affinity(void) static void ppi_enable(uint32_t intid, uint8_t prio) { + if (gic_kind == 2) { /* GICv2: SGIs/PPIs are banked in the distributor */ + set_prio(gicd, GICD_IPRIORITYR, intid, prio); + w32(gicd, GICD_ISENABLER, 1u << intid); + return; + } w32(rd, GICR_IGROUPR0, r32(rd, GICR_IGROUPR0) | (1u << intid)); set_prio(rd, GICR_IPRIORITYR, intid, prio); w32(rd, GICR_ISENABLER0, 1u << intid); } +static int gicv2_init(const struct ck_madt_gic *m, struct ck_gic_report *out) +{ + gicd = ck_mmio_map(m->gicd, 0x1000); + gicc = ck_mmio_map(m->gicc_base, 0x2000); + gic_kind = 2; + w32(gicd, GICD_CTLR, 1); + w32(gicc, GICC_PMR, 0xf0); + w32(gicc, GICC_BPR, 0); + w32(gicc, GICC_CTLR, 1); + ppi_enable(30, 0x80); /* EL1 physical timer */ + out->gicd = m->gicd; + out->gicr = 0; + out->gicc = m->gicc_base; + out->kind = 2; + out->arch_rev = (r32(gicd, GICD_V2_PIDR2) >> 4) & 0xf; + out->icc_sre = 0; + out->rd_frame = 0; + return 0; +} + int ck_gic_init(const struct ck_madt_gic *m, struct ck_gic_report *out) { + int kind = ck_madt_gic_kind(m); + if (!m->gicd || !kind) + return -1; + if (kind == 2) + return gicv2_init(m, out); uint64_t region = m->gicr ? m->gicr : m->gicc_gicr; uint64_t len = m->gicr ? m->gicr_len : 0x20000; - if (!m->gicd || !region || !len) + if (!region || !len) return -1; gicd = ck_mmio_map(m->gicd, 0x10000); volatile uint8_t *r = ck_mmio_map(region, (len + 0xfff) & ~0xfffull); @@ -78,6 +126,7 @@ int ck_gic_init(const struct ck_madt_gic *m, struct ck_gic_report *out) ; if (i == 1000000) return -3; + gic_kind = 3; /* Distributor: affinity routing, group 1 enabled (as the Rust kernel). */ w32(gicd, GICD_CTLR, (1u << 4) | (1u << 1)); rwp_wait(); @@ -91,21 +140,47 @@ int ck_gic_init(const struct ck_madt_gic *m, struct ck_gic_report *out) ppi_enable(30, 0x80); /* EL1 physical timer */ out->gicd = m->gicd; out->gicr = region; + out->gicc = 0; + out->kind = 3; out->arch_rev = (r32(gicd, GICD_PIDR2) >> 4) & 0xf; out->icc_sre = ck_rd_s(ICC_SRE_EL1) & 1; out->rd_frame = (uint64_t)(uintptr_t)rd; return 0; } +/* Acknowledge the highest-priority pending interrupt; 1020-1023 = none. */ +uint32_t ck_gic_ack(void) +{ + if (gic_kind == 2) + return r32(gicc, GICC_IAR) & 0x3ff; /* GICC_IAR_INT_ID_MASK; CPUID bits only for SGIs */ + return (uint32_t)ck_rd_s(ICC_IAR1_EL1) & 0xffffff; +} + +void ck_gic_eoi(uint32_t intid) +{ + if (gic_kind == 2) + w32(gicc, GICC_EOIR, intid); + else + ck_wr_s(ICC_EOIR1_EL1, intid); +} + int ck_irq_enable(uint32_t intid) { - if (!gicd || !rd || intid >= 1020) + if (!gicd || !gic_kind || intid >= 1020) return -1; if (intid < 32) { ppi_enable(intid, 0xa0); return 0; } uint32_t word = intid / 32, bit = 1u << (intid % 32); + if (gic_kind == 2) { + /* ITARGETSR0-7 read back this CPU's own target bit (GICv2 4.3.12). */ + uint8_t self = (uint8_t)(r32(gicd, GICD_ITARGETSR) & 0xff); + set_prio(gicd, GICD_IPRIORITYR, intid, 0xa0); + set_prio(gicd, GICD_ITARGETSR, intid, self); + w32(gicd, GICD_ISENABLER + word * 4, bit); + return 0; + } w32(gicd, GICD_IGROUPR + word * 4, r32(gicd, GICD_IGROUPR + word * 4) | bit); set_prio(gicd, GICD_IPRIORITYR, intid, 0xa0); uint64_t m = ck_rd(mpidr_el1); diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index b6e9ce01..8496eb05 100644 --- a/native/kernel/core/.crumb +++ b/native/kernel/core/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-12T20:56:51Z", + "compiled_at": "2026-10-13T04:45:02Z", "compiler": "crumb-compile/1", - "digest": "sha256:5f5def88e2ef4bbd425e833cecb75d7cc805e7516a5128a88a7dea4e9b87cdd9", + "digest": "sha256:3113e99820041c9ba4481d6da5d6dcebb3eaaf25867e4278945544260466d5f3", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 45, - "generated_at_commit": "04e39e7223149deef6c14e4175d40e80c63eee0a", - "source_tree": "sha256:c20518c21d9654bc4cf8e3743341819b51a61470925b09a70790849c2596e0af" + "generated_at_commit": "391fcd54707b2ba006e0652c71259a17ef78ec6a", + "source_tree": "sha256:8cdf83971a1cde5fc3427130f19faa502874e0c594be76cc884311dbfa21ce30" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/acpi.c b/native/kernel/core/acpi.c index 9b3f3e68..3c2d7cef 100644 --- a/native/kernel/core/acpi.c +++ b/native/kernel/core/acpi.c @@ -121,8 +121,10 @@ int ck_madt_parse(const void *madt, struct ck_madt_gic *out) return -1; uint32_t flags = rd32(e + 12); if (flags & (1u | 8u)) { - if (!g.gicc_count) + if (!g.gicc_count) { + g.gicc_base = rd64(e + 32); g.gicc_gicr = rd64(e + 60); + } g.gicc_count++; } } else if (type == 0x0c) { /* GICD */ @@ -147,6 +149,21 @@ int ck_madt_parse(const void *madt, struct ck_madt_gic *out) } +int ck_madt_gic_kind(const struct ck_madt_gic *m) +{ + if (m->gic_version == 2) + return m->gicc_base ? 2 : 0; + if (m->gic_version >= 3) + return 3; + if (m->gic_version == 0) { + if (m->gicr || m->gicc_gicr) + return 3; + if (m->gicc_base) + return 2; + } + return 0; +} + int ck_madt_mpidrs(const void *madt, uint64_t *out, unsigned max, unsigned *n) { const uint8_t *m = madt; diff --git a/native/kernel/core/acpi.h b/native/kernel/core/acpi.h index 0f0aeab5..61cf65ba 100644 --- a/native/kernel/core/acpi.h +++ b/native/kernel/core/acpi.h @@ -41,9 +41,15 @@ struct ck_madt_gic { uint32_t gicr_len; uint32_t gicc_count; /* enabled or online-capable GICC entries */ uint64_t gicc_gicr; /* GICR base from the first GICC, if no 0x0E range */ + uint64_t gicc_base; /* GICv2 CPU interface (Physical Base Address) from the first GICC */ }; /* 0 on success, -1 on a malformed table (bad entry length, truncation). */ int ck_madt_parse(const void *madt, struct ck_madt_gic *out); +/* Which GIC the parsed MADT describes: 2 (GICv2, MMIO CPU interface at + * gicc_base), 3 (GICv3/v4, redistributors), 0 (unusable: GICv1, or v2 with no + * CPU interface). GICD version 0 ("discover") is GICv3 when a redistributor is + * named anywhere, else GICv2 when a GICC base is given. */ +int ck_madt_gic_kind(const struct ck_madt_gic *m); /* CPU topology from the MADT GICC entries (acpi.rs madt_cpu_topology): enabled * or online-capable cores, (efficiency class, count) pairs sorted by class, diff --git a/native/kernel/core/ck_internal.h b/native/kernel/core/ck_internal.h index 447c06cc..eb1d19f6 100644 --- a/native/kernel/core/ck_internal.h +++ b/native/kernel/core/ck_internal.h @@ -98,11 +98,15 @@ void ck_artifact_final(void); /* ---- GIC and timer (arch/gic.c, arch/timer.c) ---- */ struct ck_gic_report { uint64_t gicd, gicr; + uint64_t gicc; /* GICv2 CPU interface base (0 on GICv3) */ + uint32_t kind; /* 2 = GICv2 MMIO CPU interface, 3 = GICv3 system registers */ uint32_t arch_rev; uint64_t icc_sre; uint64_t rd_frame; /* this CPU's redistributor frame */ }; int ck_gic_init(const struct ck_madt_gic *madt, struct ck_gic_report *out); +uint32_t ck_gic_ack(void); /* IRQ entry: INTID, 1020-1023 = spurious */ +void ck_gic_eoi(uint32_t intid); struct ck_timer_window { uint64_t ticks, ms, freq_hz, min_interval, max_interval, span; }; diff --git a/native/kernel/core/kmain.c b/native/kernel/core/kmain.c index 55aa4605..84831d77 100644 --- a/native/kernel/core/kmain.c +++ b/native/kernel/core/kmain.c @@ -163,7 +163,7 @@ static __attribute__((noreturn)) void ck_el1_main(void *arg) else ck_printf("guard_page: FAIL %s\n", detail); - /* GICv3 from the MADT, then the EL1 physical timer window. */ + /* GICv3 or GICv2 (arch/gic.c) from the MADT, then the EL1 physical timer window. */ ck_set_stage("gic"); const void *madt = ck_acpi_find("APIC"); struct ck_madt_gic mg; @@ -185,7 +185,10 @@ static __attribute__((noreturn)) void ck_el1_main(void *arg) ck_printf("gic_madt: gicd=0x%llx gicr=0x%llx arch_rev=%u icc_sre=%llu\n", (unsigned long long)gr.gicd, (unsigned long long)gr.gicr, gr.arch_rev, (unsigned long long)gr.icc_sre); - ck_printf("gic_redistributor: frame=0x%llx\n", (unsigned long long)gr.rd_frame); + if (gr.kind == 2) + ck_printf("gic_cpu_interface: mmio gicc=0x%llx\n", (unsigned long long)gr.gicc); + else + ck_printf("gic_redistributor: frame=0x%llx\n", (unsigned long long)gr.rd_frame); ck_printf("timer_stats: intid=30 freq_hz=%llu period_us=%llu min_us=%llu avg_us=%llu max_us=%llu\n", (unsigned long long)f, (unsigned long long)ck_counter_to_us(f / 100, f), (unsigned long long)ck_counter_to_us(tw.min_interval, f), diff --git a/native/kernel/tests/.crumb b/native/kernel/tests/.crumb index 1e601908..19b0d843 100644 --- a/native/kernel/tests/.crumb +++ b/native/kernel/tests/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-12T20:56:51Z", + "compiled_at": "2026-10-13T04:45:02Z", "compiler": "crumb-compile/1", - "digest": "sha256:515f5d05394be70d66a845c3d5f2aecdd11e5402c189aefeb817577857ad0118", + "digest": "sha256:da6470d80184ef3a173623e87a9712d4643f67d73dbab6be80f7e41902fc81e4", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 151, - "generated_at_commit": "04e39e7223149deef6c14e4175d40e80c63eee0a", - "source_tree": "sha256:b4a14f3b8d7e17e89a2842c17a0dd6b5ae21123cd00c3c0032729582ac9743a5" + "generated_at_commit": "391fcd54707b2ba006e0652c71259a17ef78ec6a", + "source_tree": "sha256:63ed02b105fb0934e800ed8c6f3656af5fe7fb9c1ff1c101f8aa227fc146fd4f" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tests/test_acpi.c b/native/kernel/tests/test_acpi.c index dd391894..d2b0cbcd 100644 --- a/native/kernel/tests/test_acpi.c +++ b/native/kernel/tests/test_acpi.c @@ -101,6 +101,7 @@ int main(void) e[0] = 0x0b; e[1] = 80; w32(e + 12, i == 0 ? 1 : 0); + w64(e + 32, 0x08010000 + i * 0x1000); w64(e + 60, 0x080a0000 + i * 0x20000); w64(e + 68, (uint64_t)i); at += 80; @@ -152,6 +153,20 @@ int main(void) CHECK(ck_madt_parse(madt, &g) == 0); CHECK(g.gicd == 0x08000000 && g.gic_version == 3 && g.gicr == 0x080a0000 && g.gicr_len == 0xf60000); CHECK(g.gicc_count == 1 && g.gicc_gicr == 0x080a0000); + CHECK(g.gicc_base == 0x08010000 && ck_madt_gic_kind(&g) == 3); + { /* GICv2 MADT shapes (Pi 5 GIC-400, QEMU gic-version=2) */ + struct ck_madt_gic v = { 0 }; + v.gicd = 0x107fff9000ull; v.gicc_base = 0x107fffa000ull; v.gic_version = 2; + CHECK(ck_madt_gic_kind(&v) == 2); + v.gic_version = 0; /* discover: no redistributor anywhere, GICC base given */ + CHECK(ck_madt_gic_kind(&v) == 2); + v.gicc_gicr = 0x080a0000; /* a redistributor named: GICv3 */ + CHECK(ck_madt_gic_kind(&v) == 3); + v.gicc_gicr = 0; v.gicc_base = 0; v.gic_version = 2; /* v2 without a CPU interface */ + CHECK(ck_madt_gic_kind(&v) == 0); + v.gic_version = 1; /* GICv1: unsupported */ + CHECK(ck_madt_gic_kind(&v) == 0); + } struct ck_spcr s; CHECK(ck_spcr_parse(spcr, &s) == 0 && s.interface_type == 3 && s.space == 0 && diff --git a/scripts/.crumb b/scripts/.crumb index 4b201d9e..8b15200f 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T03:39:20Z", + "compiled_at": "2026-10-13T04:45:02Z", "compiler": "crumb-compile/1", - "digest": "sha256:789ab6f9dbc46868a4b3e1541d7e66381b8241f58501ba512ead25c3a40fd471", + "digest": "sha256:b0f4248c62a868c7b516d0a639ca2ecd1b1a5c0a4c732d64ad102749c8dfdd7b", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 90, - "generated_at_commit": "1adbd4b7707bd586c253296ab4ca9f1e57015a9d", - "source_tree": "sha256:8bd83b793ebfc69249908e7d6bd2c15733d4f7e85f62132d63bd33d7d61a0c48" + "generated_at_commit": "391fcd54707b2ba006e0652c71259a17ef78ec6a", + "source_tree": "sha256:763aa9b66254d5dbc5b8403b52ef11c8d34f48058d3758d2e0779f3dd77ef5d8" }, "owner_lane": "", "provenance": { diff --git a/scripts/lib_ck_m1_checks.sh b/scripts/lib_ck_m1_checks.sh index e2778bf7..34af716c 100644 --- a/scripts/lib_ck_m1_checks.sh +++ b/scripts/lib_ck_m1_checks.sh @@ -39,7 +39,13 @@ ck_m1_checks() { check "left firmware and entered the kernel" "kernel: alive" check "kernel entered EL1h" "kernel_el: EL1h" check "EL1 page tables and caches enabled" "mmu: enabled" - check "GICv3 enabled" "gic: v3" + # AIENOS_QEMU_GIC=2: QEMU gic-version=2, the Raspberry Pi 5 shape (GIC-400, + # memory-mapped CPU interface). Default 3: the GB10 shape. + if [[ "${AIENOS_QEMU_GIC:-3}" == 2 ]]; then + check "GICv2 enabled" "gic: v2" + else + check "GICv3 enabled" "gic: v3" + fi if grep -qE 'timer_irq: ([0-9]+) ticks' "${work}/serial.txt"; then ticks=$(grep -oE 'timer_irq: ([0-9]+) ticks' "${work}/serial.txt" | tail -1 | grep -oE '[0-9]+') [[ "${ticks}" -ge 5 ]] && echo "PASS timer IRQ delivered at least five ticks" || { echo "FAIL timer IRQ delivered fewer than five ticks"; failed=1; } @@ -63,8 +69,15 @@ ck_m1_checks() { echo "FAIL MMU switch from firmware tables reported" failed=1 fi - check "GIC bases from the ACPI MADT, GICv3 architecture and ICC system registers" \ - "gic_madt: gicd=0x[0-9a-f]* gicr=0x[0-9a-f]* arch_rev=3 icc_sre=1" + if [[ "${AIENOS_QEMU_GIC:-3}" == 2 ]]; then + check "GIC distributor from the ACPI MADT, GICv2 architecture, no ICC system registers" \ + "gic_madt: gicd=0x[0-9a-f]* gicr=0x0 arch_rev=2 icc_sre=0" + check "GICv2 CPU interface from the MADT GICC base, memory-mapped" \ + "gic_cpu_interface: mmio gicc=0x[0-9a-f]*[1-9a-f][0-9a-f]*" + else + check "GIC bases from the ACPI MADT, GICv3 architecture and ICC system registers" \ + "gic_madt: gicd=0x[0-9a-f]* gicr=0x[0-9a-f]* arch_rev=3 icc_sre=1" + fi # Issue #28: tick statistics. The dispatcher re-arms the timer 10 ms after each # tick, so no interval may be shorter than half a period (a missing re-arm or a # missing EOI would show as an interrupt storm or no second tick). diff --git a/scripts/qemu_ck_boot_test.sh b/scripts/qemu_ck_boot_test.sh index fe735408..10f7af79 100755 --- a/scripts/qemu_ck_boot_test.sh +++ b/scripts/qemu_ck_boot_test.sh @@ -26,6 +26,9 @@ # - AIENOS_QEMU_CPU overrides "-cpu max" for a manual negative run (e.g. # neoverse-n1, which has no FEAT_RNG/RNDR: M1 must FAIL on the entropy # row). scripts/ck_gates.sh unsets it, so receipts always use -cpu max. +# - AIENOS_QEMU_GIC=2 boots QEMU with gic-version=2 (the Raspberry Pi 5 GIC-400 +# shape: GICv2, memory-mapped CPU interface) and the checks expect "gic: v2"; +# default 3 (GB10 shape). # Needs qemu-system-aarch64 and AAVMF (Ubuntu: qemu-system-arm qemu-efi-aarch64). set -euo pipefail @@ -73,7 +76,7 @@ qemu_cpu="${AIENOS_QEMU_CPU:-max}" started=$(date +%s) set +e timeout "${AIENOS_QEMU_TIMEOUT:-180}" qemu-system-aarch64 \ - -M virt,virtualization=on,gic-version=3 "${qemu_accel[@]}" -cpu "${qemu_cpu}" -smp 4 -m 2048 \ + -M virt,virtualization=on,gic-version="${AIENOS_QEMU_GIC:-3}" "${qemu_accel[@]}" -cpu "${qemu_cpu}" -smp 4 -m 2048 \ -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ -drive if=pflash,format=raw,file="${work}/vars.fd" \ -drive if=none,id=esp,format=raw,file=fat:rw:"${work}/esp" \