Skip to content

XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)

C

M2a: more stages between kernel_startup_bootstrap and arm_vm_init

Heyang Zhou40e43606dc69
diff --git a/xnu-ko/xnu_main.c b/xnu-ko/xnu_main.c
index e55d3b0..8d6c78e 100644
--- a/xnu-ko/xnu_main.c
+++ b/xnu-ko/xnu_main.c
@@ -95,6 +95,8 @@ long xnu_hook(unsigned long stage, unsigned long a1, unsigned long a2)
static const struct { unsigned long s; const char *what; } names[] = {
{ 101, "image slid, structors signed" }, { 110, "PE_init_platform: ADT parsed" },
{ 120, "ml_parse_cpu_topology" }, { 130, "kernel_startup_bootstrap returned" },
+ { 140, "timer_call_init" }, { 150, "cpu_init" }, { 160, "processor_bootstrap" },
+ { 170, "boot-arg parsing" }, { 175, "nanoseconds_to_absolutetime" }, { 180, "/chosen dram-base/size" },
{ 199, "arm_init reached arm_vm_init" },
};
const char *what = "?";
diff --git a/xnu-patches/0001-linux64-stage-hook.patch b/xnu-patches/0001-linux64-stage-hook.patch
index 77338d2..98df22d 100644
--- a/xnu-patches/0001-linux64-stage-hook.patch
+++ b/xnu-patches/0001-linux64-stage-hook.patch
@@ -1,5 +1,5 @@
diff --git a/osfmk/arm/arm_init.c b/osfmk/arm/arm_init.c
-index ac1713e..bd92789 100644
+index ac1713e..283fb99 100644
--- a/osfmk/arm/arm_init.c
+++ b/osfmk/arm/arm_init.c
@@ -228,6 +228,13 @@ extern vm_offset_t segLOWESTKC, segHIGHESTKC, segLOWESTROKC, segHIGHESTROKC;
@@ -84,7 +84,7 @@ index ac1713e..bd92789 100644
boot_cpu_id = ml_get_boot_cpu_number();
-@@ -511,6 +546,7 @@ arm_init(
+@@ -511,15 +546,19 @@ arm_init(
kernel_debug_string_early("kernel_startup_bootstrap");
kernel_startup_bootstrap();
@@ -92,7 +92,34 @@ index ac1713e..bd92789 100644
/*
* Initialize the timer callout world
-@@ -585,6 +621,7 @@ arm_init(
+ */
+ timer_call_init();
++ linux64_stage(140);
+
+ cpu_init();
++ linux64_stage(150);
+
+ processor_bootstrap();
++ linux64_stage(160);
+
+ if (PE_parse_boot_argn("maxmem", &maxmem, sizeof(maxmem))) {
+ xmaxmem = (uint64_t) maxmem * (1024 * 1024);
+@@ -544,7 +583,9 @@ arm_init(
+ }
+ #endif /* SCHED_HYGIENE_DEBUG */
+
++ linux64_stage(170);
+ nanoseconds_to_absolutetime(XCALL_ACK_TIMEOUT_NS, &xcall_ack_timeout_abstime);
++ linux64_stage(175);
+
+ #if HAS_BP_RET
+ PE_parse_boot_argn("bpret", &bp_ret, sizeof(bp_ret));
+@@ -581,10 +622,12 @@ arm_init(
+ panic("%s: Unable to find 'dram-size' entry in the 'chosen' DT node", __FUNCTION__);
+ }
+
++ linux64_stage(180);
+ gDramBase = *dram_base;
gDramSize = *dram_size;
pmap_first_pnum = (ppnum_t)atop(gDramBase);