Skip to content

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

GPU, the iOS side: SpringBoard through CoreAnimation's OpenGL ES renderer

vcvkk8bcdf69f7270
diff --git a/README.md b/README.md
index b119d05..66ad385 100644
--- a/README.md
+++ b/README.md
@@ -159,8 +159,15 @@ Adreno 642L телефона заведён под нашим ядром: заг
на панель (`docs/gpu-first-frame.png`). Это опыт за параметром `adreno=N` (шаги описаны в начале
`bsd/dev/redwood_adreno.c`), iOS пока по-прежнему рисует процессором. Прошивки GPU берутся с самого телефона
(`adb pull /vendor/firmware/a660_{gmu.bin,sqe.fw,zap.mdt,zap.b00,zap.b01,zap.b02}` в каталог `fw-gpu/`, в git они
-не попадают) и едут в малом образе. Дальше — настоящая 3D-отрисовка и OpenGL ES для CoreAnimation: в QuartzCore
-16.5 есть рабочий рендер через OpenGL ES, на который сервер окон переходит сам, если нет Metal.
+не попадают) и едут в малом образе.
+
+Сторона iOS тоже проверена: в QuartzCore 16.5 есть рабочий рендер через OpenGL ES, на который сервер окон
+переходит сам, если нет Metal. `GL=1 REST=1 userland/build.sh` (перед этим `tools/mk-mesa.sh` — Mesa 25.0.7 под
+userland iOS, минута сборки) кладёт в малый образ Mesa и прослойку `userland/src/eagl.c`, которая подменяет шесть
+методов `EAGLContext` и таблицу функций OpenGL ES: SpringBoard рисуется через этот путь и в QEMU, и на телефоне
+(`docs/gles-on-phone.png`). Пока за ним стоит программный драйвер Mesa (softpipe), то есть это медленнее обычного
+режима и нужно только как проверка; на экране блокировки при этом не рисуются часы и обои. Дальше — интерфейс
+ядра под драйвер Adreno из Mesa (freedreno) и замена программного драйвера на него.
## Сборка из исходников
diff --git a/docs/gles-on-phone.png b/docs/gles-on-phone.png
new file mode 100644
index 0000000..7579c84
Binary files /dev/null and b/docs/gles-on-phone.png differ
diff --git a/prebuilt/SHA256SUMS b/prebuilt/SHA256SUMS
index 3971cd3..382bac3 100644
--- a/prebuilt/SHA256SUMS
+++ b/prebuilt/SHA256SUMS
@@ -1,13 +1,13 @@
-Built 2026-10-12 22:05 from this tree.
+Built 2026-10-12 23:02 from this tree.
-6a90f6523071ced387d80c6a71918a86f68055ffe7bb72e49e7754a0835344b4 prebuilt/mach.development.bcm2837
+30e96b37407464e40391ef99a0b933eafebb5105129ba1cf4aa254636eca4772 prebuilt/mach.development.bcm2837
1332a598d2dec00a1d8e930044e4f00a12ad44c6e5e50eecf4b7fe7fae803bf2 prebuilt/loader.efi
d2a35a4a1d6658ffb3696914f727661b52c9333de8a3af8a31642b8023ce03ac prebuilt/userland/child
1a413befd511384052e1962c1394adce20f718e1f2657ce63ab09828ebc4bd1b prebuilt/userland/cpu_test
db564073effc31e7ab1679a7ffe0631ec22c3030ad347c927028f3e53c8583c3 prebuilt/userland/hello
a8baa9ab38333280369b0824aafaf92c7aa6a85851ff0b2551a4c711dbe59cfd prebuilt/userland/hello_dyn
9d951ac5274c2f0868b5eeeb7589616301f3d8893a592ad49c3f4a5001230def prebuilt/userland/init
-0e745603f8e5e65867631133efe54311670d09b58ff04ceed86c7a94040303e1 prebuilt/userland/libredwood.dylib
+e6a64f55a810803473689b00e2425be1fba93c16ee8f4f1ef20e42def3488615 prebuilt/userland/libredwood.dylib
edbe8848a2c7556ca2a7c1d1e64c5af1cbff228e967b1bd01f6dc5cdc5623730 prebuilt/userland/libredwood-sb.dylib
b540c061fc5909e9c640cccf4f6f84fd15b58337caa4f95a3610aa694d198346 prebuilt/userland/mg_test
e9dd4a78e3f61d5001fd4745cbc3dd6d498850a4140b3e90eeb8592e9dccf349 prebuilt/userland/rwtouch
diff --git a/prebuilt/mach.development.bcm2837 b/prebuilt/mach.development.bcm2837
index 82714d2..b5dda07 100755
Binary files a/prebuilt/mach.development.bcm2837 and b/prebuilt/mach.development.bcm2837 differ
diff --git a/prebuilt/userland/libredwood.dylib b/prebuilt/userland/libredwood.dylib
index 51c47d0..34086fd 100755
Binary files a/prebuilt/userland/libredwood.dylib and b/prebuilt/userland/libredwood.dylib differ
diff --git a/xnu/files/iokit/Kernel/MiniIOSurface.cpp b/xnu/files/iokit/Kernel/MiniIOSurface.cpp
index d5ae49c..efaafbb 100644
--- a/xnu/files/iokit/Kernel/MiniIOSurface.cpp
+++ b/xnu/files/iokit/Kernel/MiniIOSurface.cpp
@@ -231,8 +231,9 @@ surfaceCreate(OSDictionary * props, IOReturn * error)
struct minisurf_result * info;
uint32_t width, height, format, bpe, ew, eh, bpr, alloc, offset, planeCount = 0;
uint32_t hsub, vsub;
- bool wide;
+ bool wide, onePlane = false;
OSArray * planeInfo;
+ OSNumber * wrapped;
uint64_t needed;
*error = kIOReturnBadArgument;
@@ -250,6 +251,15 @@ surfaceCreate(OSDictionary * props, IOReturn * error)
if (format == 'w30r' || format == 'l10r' || format == 'w30R') {
format = 'BGRA';
}
+ /*
+ * The same with alpha in a plane of its own: what CoreAnimation makes the screen's own
+ * surfaces of once it draws with a GPU's renderer (OpenGL ES, userland/src/eagl.c) instead
+ * of its software one. One plane of BGRA here too; the framebuffer shows nothing else.
+ */
+ if (format == 'b3a8') {
+ format = 'BGRA';
+ onePlane = true;
+ }
ew = dictNumber(props, "IOSurfaceElementWidth", 1);
eh = dictNumber(props, "IOSurfaceElementHeight", 1);
bpe = dictNumber(props, "IOSurfaceBytesPerElement", 0);
@@ -257,11 +267,18 @@ surfaceCreate(OSDictionary * props, IOReturn * error)
if (width > MINISURF_MAX_DIMENSION || height > MINISURF_MAX_DIMENSION || ew == 0 || eh == 0 || ew > 255 || eh > 255) {
return NULL;
}
- if (props->getObject("IOSurfaceAddress") != NULL || props->getObject("IOSurfaceAddressRanges") != NULL) {
- IOLog("MiniIOSurface: wrapping client memory is not supported\n");
+ if (props->getObject("IOSurfaceAddressRanges") != NULL) {
+ IOLog("MiniIOSurface: wrapping client memory in pieces is not supported\n");
*error = kIOReturnUnsupported;
return NULL;
}
+ /*
+ * A surface around memory the client has already: CoreAnimation's OpenGL ES renderer makes
+ * them around pictures it has in memory (an application's icon), to hand them to the GPU as
+ * they are. Here the surface is one of our own with a copy of that memory in it, made now:
+ * good for a picture that does not change, which is what these are.
+ */
+ wrapped = OSDynamicCast(OSNumber, props->getObject("IOSurfaceAddress"));
s = OSTypeAlloc(MiniIOSurface);
if (s == NULL || !s->init()) {
@@ -271,7 +288,7 @@ surfaceCreate(OSDictionary * props, IOReturn * error)
}
info = &s->info;
- planeInfo = OSDynamicCast(OSArray, props->getObject("IOSurfacePlaneInfo"));
+ planeInfo = onePlane ? NULL : OSDynamicCast(OSArray, props->getObject("IOSurfacePlaneInfo"));
needed = 0;
if (planeInfo != NULL && planeInfo->getCount() != 0) {
planeCount = planeInfo->getCount();
@@ -383,6 +400,16 @@ surfaceCreate(OSDictionary * props, IOReturn * error)
}
s->kbase = (uint8_t *) s->memory->getBytesNoCopy();
s->values = OSDictionary::withCapacity(4);
+ if (wrapped != NULL) {
+ uint32_t given = dictNumber(props, "IOSurfaceAllocSize", alloc);
+
+ if (copyin((user_addr_t) wrapped->unsigned64BitValue(), s->kbase + PAGE_SIZE, given < alloc ? given : alloc) != 0) {
+ IOLog("MiniIOSurface: the memory to make a surface around cannot be read\n");
+ s->release();
+ *error = kIOReturnVMError;
+ return NULL;
+ }
+ }
info->allocSize = alloc;
info->width = width;