2009-05-03 Vladimir Serbinenko <phcoder@gmail.com>

xnu support

	* conf/i386-efi.rmk (kernel_mod_HEADERS): added i386/pit.h
	(pkglib_MODULES): add xnu.mod
	(xnu_mod_SOURCES): new variable
	(xnu_mod_CFLAGS): likewise
	(xnu_mod_LDFLAGS): likewise
	(xnu_mod_ASFLAGS): likewise
	* conf/i386-pc.rmk: likewise
	* conf/x86_64-efi.rmk: likewise
	* include/grub/efi/efi.h (grub_efi_finish_boot_services): 
	new declaration
	* include/grub/i386/macho.h: new file
	* include/grub/i386/xnu.h: likewise
	* include/grub/macho.h: likewise
	* include/grub/machoload.h: likewise
	* include/grub/x86_64/macho.h: likewise
	* include/grub/x86_64/xnu.h: likewise
	* include/grub/xnu.h: likewise
	* kern/efi/efi.c (grub_efi_finish_boot_services): new function
	* kern/efi/mm.c (MAX_HEAP_SIZE): increase
	* loader/i386/efi/xnu.c: new file
	* loader/i386/pc/xnu.c: likewise
	* loader/i386/xnu.c: likewise
	* loader/i386/xnu_helper.S: likewise
	* loader/macho.c: likewise
	* loader/xnu.c: likewise
	* loader/xnu_resume.c: likewise
	* util/grub-dumpdevtree: likewise
	* include/grub/i386/pit.h: include grub/err.h
	(grub_pit_wait): export
	* util/grub.d/30_os-prober.in: support Darwin/Mac OS X
This commit is contained in:
phcoder 2009-05-02 23:19:20 +00:00
parent 5caf964d75
commit bbee0f2b56
24 changed files with 3378 additions and 6 deletions

View file

@ -56,6 +56,7 @@ EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);
int EXPORT_FUNC(grub_efi_exit_boot_services) (grub_efi_uintn_t map_key);
void EXPORT_FUNC (grub_reboot) (void);
void EXPORT_FUNC (grub_halt) (void);
int EXPORT_FUNC (grub_efi_finish_boot_services) (void);
void grub_efi_mm_init (void);
void grub_efi_mm_fini (void);

11
include/grub/i386/macho.h Normal file
View file

@ -0,0 +1,11 @@
#define GRUB_MACHO_CPUTYPE_IS_HOST32(x) ((x)==0x00000007)
#define GRUB_MACHO_CPUTYPE_IS_HOST64(x) ((x)==0x01000007)
struct grub_macho_thread32
{
grub_uint32_t cmd;
grub_uint32_t cmdsize;
grub_uint8_t unknown1[48];
grub_uint32_t entry_point;
grub_uint8_t unknown2[20];
} __attribute__ ((packed));

View file

@ -20,7 +20,8 @@
#define KERNEL_CPU_PIT_HEADER 1
#include <grub/types.h>
#include <grub/err.h>
extern void grub_pit_wait (grub_uint16_t tics);
void EXPORT_FUNC(grub_pit_wait) (grub_uint16_t tics);
#endif /* ! KERNEL_CPU_PIT_HEADER */

60
include/grub/i386/xnu.h Normal file
View file

@ -0,0 +1,60 @@
#ifndef GRUB_CPU_XNU_H
#define GRUB_CPU_XNU_H 1
#define GRUB_XNU_PAGESIZE 4096
typedef grub_uint32_t grub_xnu_ptr_t;
struct grub_xnu_boot_params
{
grub_uint16_t verminor;
grub_uint16_t vermajor;
/* Command line passed to xnu. */
grub_uint8_t cmdline[1024];
/* Later are the same as EFI's get_memory_map (). */
grub_xnu_ptr_t efi_mmap;
grub_uint32_t efi_mmap_size;
grub_uint32_t efi_mem_desc_size;
grub_uint32_t efi_mem_desc_version;
/* Later are video parameters. */
grub_xnu_ptr_t lfb_base;
#define GRUB_XNU_VIDEO_SPLASH 1
#define GRUB_XNU_VIDEO_TEXT_IN_VIDEO 2
grub_uint32_t lfb_mode;
grub_uint32_t lfb_line_len;
grub_uint32_t lfb_width;
grub_uint32_t lfb_height;
grub_uint32_t lfb_depth;
/* Pointer to device tree and its len. */
grub_xnu_ptr_t devtree;
grub_uint32_t devtreelen;
/* First used address by kernel or boot structures. */
grub_xnu_ptr_t heap_start;
/* Last used address by kernel or boot structures minus previous value. */
grub_uint32_t heap_size;
/* First memory page containing runtime code or data. */
grub_uint32_t efi_runtime_first_page;
/* First memory page containing runtime code or data minus previous value. */
grub_uint32_t efi_runtime_npages;
grub_uint32_t efi_system_table;
/* Size of grub_efi_uintn_t in bits. */
grub_uint8_t efi_uintnbits;
} __attribute__ ((packed));
#define GRUB_XNU_BOOTARGS_VERMINOR 4
#define GRUB_XNU_BOOTARGS_VERMAJOR 1
extern grub_uint32_t grub_xnu_entry_point;
extern grub_uint32_t grub_xnu_stack;
extern grub_uint32_t grub_xnu_arg1;
extern char grub_xnu_cmdline[1024];
grub_err_t grub_xnu_boot (void);
grub_err_t grub_cpu_xnu_fill_devicetree (void);
grub_err_t grub_xnu_set_video (struct grub_xnu_boot_params *bootparams_relloc);
extern grub_uint32_t grub_xnu_heap_will_be_at;
extern grub_uint8_t grub_xnu_launcher_start[];
extern grub_uint8_t grub_xnu_launcher_end[];
#endif

107
include/grub/macho.h Normal file
View file

@ -0,0 +1,107 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_MACHO_H
#define GRUB_MACHO_H 1
#include <grub/types.h>
/* Multi-architecture header. Always in big-endian. */
struct grub_macho_fat_header
{
grub_uint32_t magic;
grub_uint32_t nfat_arch;
} __attribute__ ((packed));
#define GRUB_MACHO_FAT_MAGIC 0xcafebabe
typedef grub_uint32_t grub_macho_cpu_type_t;
typedef grub_uint32_t grub_macho_cpu_subtype_t;
/* Architecture descriptor. Always in big-endian. */
struct grub_macho_fat_arch
{
grub_macho_cpu_type_t cputype;
grub_macho_cpu_subtype_t cpusubtype;
grub_uint32_t offset;
grub_uint32_t size;
grub_uint32_t align;
} __attribute__ ((packed));;
/* File header for 32-bit. Always in native-endian. */
struct grub_macho_header32
{
#define GRUB_MACHO_MAGIC32 0xfeedface
grub_uint32_t magic;
grub_macho_cpu_type_t cputype;
grub_macho_cpu_subtype_t cpusubtype;
grub_uint32_t filetype;
grub_uint32_t ncmds;
grub_uint32_t sizeofcmds;
grub_uint32_t flags;
} __attribute__ ((packed));
/* File header for 64-bit. Always in native-endian. */
struct grub_macho_header64
{
#define GRUB_MACHO_MAGIC64 0xfeedfacf
grub_uint32_t magic;
grub_macho_cpu_type_t cputype;
grub_macho_cpu_subtype_t cpusubtype;
grub_uint32_t filetype;
grub_uint32_t ncmds;
grub_uint32_t sizeofcmds;
grub_uint32_t flags;
grub_uint32_t reserved;
} __attribute__ ((packed));
/* Convenience union. What do we need to load to identify the file type. */
union grub_macho_filestart
{
struct grub_macho_fat_header fat;
struct grub_macho_header32 thin32;
struct grub_macho_header64 thin64;
} __attribute__ ((packed));
/* Common header of Mach-O commands. */
struct grub_macho_cmd
{
grub_uint32_t cmd;
grub_uint32_t cmdsize;
} __attribute__ ((packed));
typedef grub_uint32_t grub_macho_vmprot_t;
/* 32-bit segment command. */
struct grub_macho_segment32
{
#define GRUB_MACHO_CMD_SEGMENT32 1
grub_uint32_t cmd;
grub_uint32_t cmdsize;
grub_uint8_t segname[16];
grub_uint32_t vmaddr;
grub_uint32_t vmsize;
grub_uint32_t fileoff;
grub_uint32_t filesize;
grub_macho_vmprot_t maxprot;
grub_macho_vmprot_t initprot;
grub_uint32_t nsects;
grub_uint32_t flags;
} __attribute__ ((packed));
#define GRUB_MACHO_CMD_THREAD 5
#endif

62
include/grub/machoload.h Normal file
View file

@ -0,0 +1,62 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_MACHOLOAD_HEADER
#define GRUB_MACHOLOAD_HEADER 1
#include <grub/err.h>
#include <grub/elf.h>
#include <grub/file.h>
#include <grub/symbol.h>
#include <grub/types.h>
struct grub_macho_file
{
grub_file_t file;
grub_ssize_t offset32;
grub_ssize_t end32;
int ncmds32;
grub_size_t cmdsize32;
grub_uint8_t *cmds32;
grub_ssize_t offset64;
grub_ssize_t end64;
int ncmds64;
grub_size_t cmdsize64;
grub_uint8_t *cmds64;
};
typedef struct grub_macho_file *grub_macho_t;
grub_macho_t grub_macho_open (const char *);
grub_macho_t grub_macho_file (grub_file_t);
grub_err_t grub_macho_close (grub_macho_t);
int grub_macho_contains_macho32 (grub_macho_t);
grub_err_t grub_macho32_size (grub_macho_t macho, grub_addr_t *segments_start,
grub_addr_t *segments_end, int flags);
grub_uint32_t grub_macho32_get_entry_point (grub_macho_t macho);
/* Ignore BSS segments when loading. */
#define GRUB_MACHO_NOBSS 0x1
grub_err_t grub_macho32_load (grub_macho_t macho, char *offset, int flags);
/* Like filesize and file_read but take only 32-bit part
for current architecture. */
grub_size_t grub_macho32_filesize (grub_macho_t macho);
grub_err_t grub_macho32_readfile (grub_macho_t macho, void *dest);
#endif /* ! GRUB_MACHOLOAD_HEADER */

View file

@ -0,0 +1 @@
#include <grub/i386/macho.h>

View file

@ -0,0 +1 @@
#include <grub/i386/xnu.h>

107
include/grub/xnu.h Normal file
View file

@ -0,0 +1,107 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_XNU_H
#define GRUB_XNU_H 1
#include <grub/bitmap.h>
/* Header of a hibernation image. */
struct grub_xnu_hibernate_header
{
/* Size of the image. Notice that file containing image is usually bigger. */
grub_uint64_t image_size;
grub_uint8_t unknown1[8];
/* Where to copy lauchcode?*/
grub_uint32_t launchcode_target_page;
/* How many pages of launchcode? */
grub_uint32_t launchcode_numpages;
/* Where to jump? */
grub_uint32_t entry_point;
/* %esp at start. */
grub_uint32_t stack;
grub_uint8_t unknown2[44];
#define GRUB_XNU_HIBERNATE_MAGIC 0x73696d65
grub_uint32_t magic;
grub_uint8_t unknown3[28];
/* This value is non-zero if page is encrypted. Unsupported. */
grub_uint64_t encoffset;
grub_uint8_t unknown4[360];
/* The size of additional header used to locate image without parsing FS.
Used only to skip it.
*/
grub_uint32_t extmapsize;
} __attribute__ ((packed));
/* In-memory structure for temporary keeping device tree. */
struct grub_xnu_devtree_key
{
char *name;
int datasize; /* -1 for not leaves. */
union
{
struct grub_xnu_devtree_key *first_child;
void *data;
};
struct grub_xnu_devtree_key *next;
};
/* A structure used in memory-map values. */
struct
grub_xnu_extdesc
{
grub_uint32_t addr;
grub_uint32_t size;
} __attribute__ ((packed));
/* Header describing extension in the memory. */
struct grub_xnu_extheader
{
grub_uint32_t infoplistaddr;
grub_uint32_t infoplistsize;
grub_uint32_t binaryaddr;
grub_uint32_t binarysize;
} __attribute__ ((packed));
struct grub_xnu_devtree_key *grub_xnu_create_key (struct grub_xnu_devtree_key **parent,
char *name);
extern struct grub_xnu_devtree_key *grub_xnu_devtree_root;
void grub_xnu_free_devtree (struct grub_xnu_devtree_key *cur);
grub_err_t grub_xnu_writetree_toheap (void **start, grub_size_t *size);
struct grub_xnu_devtree_key *grub_xnu_create_value (struct grub_xnu_devtree_key **parent,
char *name);
void grub_xnu_lock (void);
void grub_xnu_unlock (void);
grub_err_t grub_xnu_resume (char *imagename);
struct grub_xnu_devtree_key *grub_xnu_find_key (struct grub_xnu_devtree_key *parent,
char *name);
grub_err_t grub_xnu_align_heap (int align);
grub_err_t grub_xnu_scan_dir_for_kexts (char *dirname, char *osbundlerequired,
int maxrecursion);
grub_err_t grub_xnu_load_kext_from_dir (char *dirname, char *osbundlerequired,
int maxrecursion);
void *grub_xnu_heap_malloc (int size);
extern grub_uint32_t grub_xnu_heap_real_start;
extern grub_size_t grub_xnu_heap_size;
extern char *grub_xnu_heap_start;
extern struct grub_video_bitmap *grub_xnu_bitmap;
#endif