Skip to contentSkip to conversation

xnu support

PATCH phcoder 1 participant 1 message Jan 28, 2009

lore
Share & tools
lore

phcoder

author
#0 lore raw

Hello, I'm working on xnu (darwin kernel, under OSI approved APSL) support and would like to discuss some interfaces about it.
Issue 1) First in xnu world booter hands the loading of compressed hibernation image. Resuming doesn't need to load the kernel conventional way. And trying to resume from hibernate should be done before trying to load kernel. So I propose the following configuration entries:
menuentry "my XNU"
{
if ! xnu_resume <hibernate image>; then
xnu_kernel <kernel> <options>
xnu_extensions --cache=<cache file> --dir=<cache directory>
xnu_loadenv <environment description file>
fi
}

Issue 2) Also normally when hibernation succeeds kernel should invalidate the image. Unfortunately in some scenarios it doesn't. A reliable way to check the image is to compare modification timestamp of FS and image. I know where to find them on FS but unfortunately now grub has no way of interfacing this with FS code. I propose to modify
/* Call HOOK with each file under DIR. */
grub_err_t (*dir) (grub_device_t device, const char *path,

                     int (*hook) (const char *filename, int dir));

to
/* Call HOOK with each file under DIR. */
grub_err_t (*dir) (grub_device_t device, const char *path,
int (*hook) (const char *filename, int dir,
grub_time_t modtime));
Or add
grub_err_t (*file_modtime) (const char *name, grub_time_t *modtime);
and add a function for retrieving FS modification type
grub_err_t (*fs_modtime) (grub_device_t device, grub_time_t *modtime);
to grub_fs_t
This has an additional benefit of invalidating image if FS was modified by external tool. This may be overriden by --force option to override it.
File modification timestamp are also needed to check if the extension cache is up to date.
Issue 3) Kernel may theoretically request loading parts to any address. In practice it does it only in 1Mb-64Mb range. Is it possible to somehow secure this range from grub_malloc after xnu_kernel command? (I would like to avoid "just before boot" relocations if possible)

I send an implementation of xnu_resume. Not for inclusion of course but for illustration Thanks
Any opinion is appreciated
Vladimir 'phcoder' Serbinenko

i386.rmk +5 -0
Index: conf/i386.rmk
===================================================================
@@ -14,3 +14,8 @@
 vga_text_mod_SOURCES = term/i386/pc/vga_text.c term/i386/vga_common.c
 vga_text_mod_CFLAGS = $(COMMON_CFLAGS)
 vga_text_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+pkglib_MODULES += xnu.mod
+xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c
+xnu_mod_CFLAGS = $(COMMON_CFLAGS)
+xnu_mod_LDFLAGS = $(COMMON_LDFLAGS)
grub/i386/xnu.h +9 -0
Index: include/grub/i386/xnu.h
===================================================================
@@ -0,0 +1,9 @@
+#define XNU_MEMORY_START  0x100000
+#define XNU_MEMORY_END 0x4000000
+#define XNU_PAGESIZE 4096
+
+grub_err_t grub_xnu_boot (void);
+extern void *grub_xnu_entry_point;
+extern void *grub_xnu_stack;
+extern void *grub_xnu_arg1;
+
grub/xnu.h +18 -0
Index: include/grub/xnu.h
===================================================================
@@ -0,0 +1,18 @@
+#define XNU_HIBERNATE_MAGIC 0x73696d65
+struct xnu_hibernate_header
+{
+  grub_uint64_t image_size;
+  grub_uint8_t unknown1[8];
+  grub_uint32_t restorepage;
+  grub_uint32_t numofpages;
+  grub_uint32_t entry_point;
+  grub_uint32_t stack;
+  grub_uint8_t unknown2[20];
+  grub_uint32_t restored_checksum;
+  grub_uint8_t unknown3[20];
+  grub_uint32_t magic;
+  grub_uint8_t unknown4[28];
+  grub_uint64_t encoffset;
+  grub_uint8_t unknown5[360];
+  grub_uint32_t extmapsize;
+} __attribute__ ((packed));
i386/xnu.c +27 -0
Index: loader/i386/xnu.c
===================================================================
@@ -0,0 +1,27 @@
+#include <grub/normal.h>
+#include <grub/dl.h>
+#include <grub/arg.h>
+#include <grub/file.h>
+#include <grub/disk.h>
+#include <grub/misc.h>
+#include <grub/xnu.h>
+#include <grub/cpu/xnu.h>
+#include <grub/mm.h>
+#include <grub/loader.h>
+#include <grub/cpu/loader.h>
+
+/* Registers on XNU boot: eip,esp and eax*/
+void *grub_xnu_entry_point=0;
+void *grub_xnu_stack=0;
+void *grub_xnu_arg1=0;
+
+grub_err_t 
+grub_xnu_boot (void)
+{
+  /*Setup regs and launch xnu*/
+  asm volatile ("movl %0, %%eax" : : "m" (grub_xnu_arg1));
+  asm volatile ("movl %0, %%ebx" : : "m" (grub_xnu_stack));
+  asm volatile ("movl %0, %%ecx" : : "m" (grub_xnu_entry_point));
+  asm volatile ("movl %%ebx, %%esp" : : );
+  asm volatile ("jmp *%%ecx" : : );
+}
xnu_resume.c +141 -0

141 lines not on this page · raw message