Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
A run after a panic no longer hangs: end interrupt 0 before a core goes
vcvkkf7f7fab95b30
diff --git a/README.md b/README.mdindex 6b4d23e..7563b55 100644--- a/README.md+++ b/README.md@@ -187,7 +187,7 @@ XL_CMDLINE="touchscreen=1 cpufreq=1 bootcpu=7 cpus=4 adreno=21 adreno_skip=0x1c0против 35 (`adreno_speed=3`, 550 МГц; без него 315 МГц и 46 кадров/с). Кадр при прокрутке стоит около 19 мс, доровных 60 кадров/с ещё не дотянуто. Известные дефекты: приложение «Часы» рисуется чёрным, на домашнем экране поднекоторыми значками бывают лишние треугольники. Прерываний нет (ожидание опросом). GPU выключается при любом-штатном конце сеанса (таймер, `./xl stop`, пять пальцев); после паники — `./xl reboot`. Приложения, использующие+штатном конце сеанса (таймер, `./xl stop`, пять пальцев); после паники с включённым GPU — `./xl reboot`. Приложения, использующиеMetal сами, от этого ничего не получают.## Сборка из исходниковdiff --git a/prebuilt/SHA256SUMS b/prebuilt/SHA256SUMSindex ac7b6ae..7771edd 100644--- a/prebuilt/SHA256SUMS+++ b/prebuilt/SHA256SUMS@@ -1,6 +1,6 @@-Built 2026-10-13 02:02 from this tree.+Built 2026-10-13 02:27 from this tree.-74611fb6b6e0d7351eb6e14c79c6f97400f093d9c050d1f95d916d0d4882337d prebuilt/mach.development.bcm2837+165b31a6f71a22a06e7d7d6a08573f9a031e9353c68394a40c36f2ad9a60fa22 prebuilt/mach.development.bcm28371332a598d2dec00a1d8e930044e4f00a12ad44c6e5e50eecf4b7fe7fae803bf2 prebuilt/loader.efid2a35a4a1d6658ffb3696914f727661b52c9333de8a3af8a31642b8023ce03ac prebuilt/userland/child1a413befd511384052e1962c1394adce20f718e1f2657ce63ab09828ebc4bd1b prebuilt/userland/cpu_testdiff --git a/prebuilt/mach.development.bcm2837 b/prebuilt/mach.development.bcm2837index 33c0c7a..32e4c09 100755Binary files a/prebuilt/mach.development.bcm2837 and b/prebuilt/mach.development.bcm2837 differdiff --git a/xnu/files/osfmk/arm64/gic_v3_irq.c b/xnu/files/osfmk/arm64/gic_v3_irq.cindex 31a0925..8b87974 100644--- a/xnu/files/osfmk/arm64/gic_v3_irq.c+++ b/xnu/files/osfmk/arm64/gic_v3_irq.c@@ -51,6 +51,7 @@#define GICR_IGROUPR0 (GICR_SGI_BASE + 0x0080)#define GICR_ISENABLER0 (GICR_SGI_BASE + 0x0100)#define GICR_ICENABLER0 (GICR_SGI_BASE + 0x0180)+#define GICR_ICPENDR0 (GICR_SGI_BASE + 0x0280)#define GICR_ICACTIVER0 (GICR_SGI_BASE + 0x0380)#define GICR_IPRIORITYR(n) (GICR_SGI_BASE + 0x0400 + (n))#define GICR_IGRPMODR0 (GICR_SGI_BASE + 0x0d00)@@ -65,12 +66,21 @@ static vm_offset_t gicd_base, gicr_base;static vm_size_t gicr_size;static vm_offset_t gicr_cpu_base[MAX_CPUS]; /* each processor's redistributor frame */-static uint64_t gic_active_iar[MAX_CPUS]; /* acknowledged, not yet EOI'd */+/*+ * Acknowledged, not yet EOI'd; 0: none. The signal between processors is interrupt 0 and reads+ * as 0 from ICC_IAR1_EL1, hence the mark: without it a core switched off in the middle of that+ * signal (which is where every core but one is during a panic) kept it active, and with the+ * active priority still set in its CPU interface the next kernel on that core saw no interrupt+ * at all.+ */+#define GIC_IAR_TAKEN (1ULL << 63)+static uint64_t gic_active_iar[MAX_CPUS];uint64_t gic_unhandled_count;uint32_t gic_last_unhandled;void gic_v3_irq_cpu_init(void);void gic_v3_irq_quiesce(void);+void gic_v3_irq_cpu_shutdown(void);void gic_v3_irq_signal(uint32_t phys_id);void gic_v3_irq_signal_stop(uint32_t phys_id);@@ -136,7 +146,7 @@ gic_irq_handler(__unused void *target, __unused void *refCon, __unused void *nubif (intid >= GIC_INTID_SPURIOUS_MIN) {break;}- gic_active_iar[cpu] = iar;+ gic_active_iar[cpu] = iar | GIC_IAR_TAKEN;if (intid == GIC_INTID_VTIMER) {/* same sequence as the FIQ path in sleh_fiq() */@@ -176,12 +186,40 @@ gic_v3_irq_quiesce(void)}cpu = cpu_number();if (gic_active_iar[cpu] != 0) {- __builtin_arm_wsr64("ICC_EOIR1_EL1", gic_active_iar[cpu]);+ __builtin_arm_wsr64("ICC_EOIR1_EL1", gic_active_iar[cpu] & ~GIC_IAR_TAKEN);__builtin_arm_isb(ISB_SY);gic_active_iar[cpu] = 0;}}+/*+ * This processor is leaving for good: the firmware is about to be asked to switch it off+ * (psci_smp_cpu_off(), and the boot processor in the loader's stub when the kernel has a core of+ * its own). Nothing may be left that could interrupt it. The redistributor outlives the core, and+ * so does what is pending in it: the "stop" signal that reached a core whose interrupts were off+ * (every core is in that state while another one panics), or its timer. A core asked to go with+ * an interrupt pending and the CPU interface still passing it on does not go cleanly, and the+ * next kernel that is started on it hangs.+ */+void+gic_v3_irq_cpu_shutdown(void)+{+ vm_offset_t gicr;++ if (gicd_base == 0) {+ return;+ }+ gic_v3_irq_quiesce();+ gicr = gicr_cpu_base[cpu_number()];+ if (gicr != 0) {+ gic_write32(gicr + GICR_ICENABLER0, 0xffffffffu);+ gic_write32(gicr + GICR_ICPENDR0, 0xffffffffu);+ gic_write32(gicr + GICR_ICACTIVER0, 0xffffffffu);+ }+ __builtin_arm_wsr64("ICC_IGRPEN1_EL1", 0);+ __builtin_arm_isb(ISB_SY);+}+static vm_offset_tgic_find_redistributor(void){@@ -256,6 +294,7 @@ gic_v3_irq_cpu_init(void)uint32_t sgis = (1u << GIC_SGI_SIGNAL) | (1u << GIC_SGI_STOP);gic_write32(gicr + GICR_ICACTIVER0, sgis);+ gic_write32(gicr + GICR_ICPENDR0, sgis); /* ... or one that it never took */*(volatile uint8_t *)(gicr + GICR_IPRIORITYR(GIC_SGI_SIGNAL)) = GIC_PRIORITY_DEFAULT;*(volatile uint8_t *)(gicr + GICR_IPRIORITYR(GIC_SGI_STOP)) = GIC_PRIORITY_DEFAULT;mine |= sgis;@@ -276,7 +315,13 @@ gic_v3_irq_cpu_init(void)}}- /* CPU interface: accept all priorities, no preemption grouping, Group 1 on */+ /*+ * CPU interface: accept all priorities, no preemption grouping, Group 1 on. And no priority+ * active: a core that the firmware switches off and on again need not lose that, and a+ * kernel that left in the middle of an interrupt without ending it would leave this one+ * waiting for an end that never comes.+ */+ __builtin_arm_wsr64("ICC_AP1R0_EL1", 0);__builtin_arm_wsr64("ICC_PMR_EL1", 0xff);__builtin_arm_wsr64("ICC_BPR1_EL1", 0);__builtin_arm_wsr64("ICC_IGRPEN1_EL1", 1);diff --git a/xnu/files/osfmk/arm64/loader_return.c b/xnu/files/osfmk/arm64/loader_return.cindex 49f09bb..74a1006 100644--- a/xnu/files/osfmk/arm64/loader_return.c+++ b/xnu/files/osfmk/arm64/loader_return.c@@ -39,6 +39,7 @@#if defined(GENERIC_GIC_V3_IRQ)extern void gic_v3_irq_quiesce(void);+extern void gic_v3_irq_cpu_shutdown(void);#endifvoid loader_log_putc(char c);@@ -180,6 +181,7 @@ loader_jump(uint64_t reason, uint64_t code)#if ARM_PGSHIFT == 12uint64_t stub = loader_stub_slot[1];uint64_t tcr, t0sz;+ uint32_t own_core = 0;if (stub == 0 || loader_return_entered) {return;@@ -194,6 +196,16 @@ loader_jump(uint64_t reason, uint64_t code)loader_return_entered = true;#if defined(GENERIC_GIC_V3_IRQ)gic_v3_irq_quiesce();+ /*+ * With a core of its own (bootcpu=) the kernel does not go back into the loader's code on+ * this processor: the stub leaves the log where the loader's core finds it and has the+ * firmware switch this one off. It must go as the other cores do (psci_smp_cpu_off()), with+ * nothing pending: after a panic the "stop" signal and the timer are.+ */+ if (PE_parse_boot_argn("bootcpu", &own_core, sizeof(own_core))) {+ __builtin_arm_wsr64("CNTV_CTL_EL0", CNTV_CTL_EL0_IMASKED);+ gic_v3_irq_cpu_shutdown();+ }#endifloader_l1[stub >> 30] = static_kvtophys(loader_l2) | ARM_TTE_TYPE_TABLE | ARM_TTE_VALID;diff --git a/xnu/files/osfmk/arm64/psci_smp.c b/xnu/files/osfmk/arm64/psci_smp.cindex 545165f..221defa 100644--- a/xnu/files/osfmk/arm64/psci_smp.c+++ b/xnu/files/osfmk/arm64/psci_smp.c@@ -236,9 +236,7 @@ psci_smp_cpu_off(void)__builtin_arm_wsr("DAIFSet", DAIFSC_ALL);/* leave nothing behind that would interrupt a core that is no longer there */__builtin_arm_wsr64("CNTV_CTL_EL0", CNTV_CTL_EL0_IMASKED);- gic_v3_irq_quiesce();- __builtin_arm_wsr64("ICC_IGRPEN1_EL1", 0);- __builtin_arm_isb(ISB_SY);+ gic_v3_irq_cpu_shutdown();os_atomic_store(&psci_smp_cpu_stage[cpu_number()], PSCI_SMP_CPU_OFF, release);__builtin_arm_dsb(DSB_SY);diff --git a/xnu/files/osfmk/arm64/psci_smp.h b/xnu/files/osfmk/arm64/psci_smp.hindex 62541cf..1d9a693 100644--- a/xnu/files/osfmk/arm64/psci_smp.h+++ b/xnu/files/osfmk/arm64/psci_smp.h@@ -28,6 +28,7 @@ extern void psci_smp_stop_here(void);extern void gic_v3_irq_signal(uint32_t phys_id);extern void gic_v3_irq_signal_stop(uint32_t phys_id);extern void gic_v3_irq_quiesce(void);+extern void gic_v3_irq_cpu_shutdown(void);__END_DECLS