Make grub2 compile with Apple's gcc
PATCH 1/1 Make grub2 compile with Apple's gcc
Hello. With this patch you can compile grub2 using Apple's gcc. Only partially tested. You need objconv available from
http://www.agner.org/optimize/ licensed under GPL and additionally patched with attached patch
Then you need to patch grub2 with attached patch. If you compile for i386-pcbefore you begin you need to compile execute:
gcc -o macho2img util/macho2img.c -Iinclude
Then just compile grub2 normally. I will look how to automatise the compilation of macho2img
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
mac2elf.cpp +7 -1
@@ -485,7 +485,13 @@ // Code section, assume this is a function sym.st_type = STT_FUNC; } - else { + else if (sym.st_shndx == 0) + { + // This is an external + sym.st_type = STT_NOTYPE; + } + else + { // This is a data object sym.st_type = STT_OBJECT; }
main.cpp +2 -2
@@ -547,11 +547,11 @@ // Check sectionname options if (cmd.SegmentDot && cmd.OutputType != 0) { if (cmd.SegmentDot == CMDL_SECTIONDOT_CHANGE) { - if (FileType == FILETYPE_ELF && cmd.OutputType == FILETYPE_COFF) { + if (FileType == FILETYPE_ELF && (cmd.OutputType == FILETYPE_COFF || FileType == FILETYPE_MACHO_LE)) { // Change leading '.' to '_' in nonstandard section names cmd.SegmentDot = CMDL_SECTIONDOT_DOT2U; } - else if (FileType == FILETYPE_COFF && cmd.OutputType == FILETYPE_ELF ) { + else if ((FileType == FILETYPE_COFF || FileType == FILETYPE_MACHO_LE) && cmd.OutputType == FILETYPE_ELF ) { // Change leading '_' to '.' in nonstandard section names cmd.SegmentDot = CMDL_SECTIONDOT_U2DOT; }
Makefile.in +6 -0
@@ -64,16 +64,22 @@ mkinstalldirs = $(srcdir)/mkinstalldirs CC = @CC@ CFLAGS = @CFLAGS@ +ASFLAGS = @ASFLAGS@ LDFLAGS = @LDFLAGS@ CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/include -Wall -W \ -DGRUB_LIBDIR=\"$(pkglibdir)\" TARGET_CC = @TARGET_CC@ TARGET_CFLAGS = @TARGET_CFLAGS@ +TARGET_ASFLAGS = @TARGET_ASFLAGS@ +TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@ +TARGET_APPLE_CC = @TARGET_APPLE_CC@ +OBJCONV = @OBJCONV@ TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/include \ -Wall -W TARGET_LDFLAGS = @TARGET_LDFLAGS@ TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@ TARGET_IMG_LDFLAGS = @TARGET_IMG_LDFLAGS@ +TARGET_IMG_CFLAGS = @TARGET_IMG_CFLAGS@ TARGET_OBJ2ELF = @TARGET_OBJ2ELF@ EXEEXT = @EXEEXT@ OBJCOPY = @OBJCOPY@
aclocal.m4 +31 -1
@@ -72,7 +72,7 @@ else AC_MSG_ERROR([${CC-cc} cannot compile C source code]) fi grub_cv_prog_objcopy_absolute=yes -for link_addr in 2000 8000 7C00; do +for link_addr in 2000 7C00 8000; do if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then : else AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
@@ -156,6 +156,36 @@ rm -f conftest*]) AC_MSG_RESULT([$grub_cv_i386_asm_addr32])]) +dnl check if our compiler is apple gcc +dnl because it requires numerous workarounds +AC_DEFUN(grub_apple_cc, +[AC_REQUIRE([AC_PROG_CC]) +AC_MSG_CHECKING([whether our compiler is apple cc]) +AC_CACHE_VAL(grub_cv_apple_cc, +[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then + grub_cv_apple_cc=yes +else + grub_cv_apple_cc=no +fi +]) + +AC_MSG_RESULT([$grub_cv_apple_cc])]) + +dnl check if our compiler is apple gcc +dnl because it requires numerous workarounds +AC_DEFUN(grub_apple_target_cc, +[AC_REQUIRE([AC_PROG_CC]) +AC_MSG_CHECKING([whether our target compiler is apple cc]) +AC_CACHE_VAL(grub_cv_apple_target_cc, +[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then + grub_cv_apple_target_cc=yes +else + grub_cv_apple_target_cc=no +fi +]) + +AC_MSG_RESULT([$grub_cv_apple_target_cc])]) + dnl Later versions of GAS requires that addr32 and data32 prefixes dnl appear in the same lines as the instructions they modify, while
boot/i386/pc/boot.S +68 -3
166 lines not on this page · raw message
boot/i386/pc/cdboot.S +12 -0
@@ -67,8 +67,15 @@ bi_reserved: movw %ax, %ds movw %ax, %es +#ifdef APPLE_CC + err_noboot_msg_abs = 0x7C00 + err_noboot_msg - start + movw $err_noboot_msg_abs, %si + bi_length_dif = bi_length - next + movl %cs:bi_length_dif(%bx), %ecx +#else movw $(0x7C00 + err_noboot_msg - start), %si movl %cs: bi_length - next(%bx), %ecx +#endif orl %ecx, %ecx jz fail
@@ -152,7 +159,12 @@ read_cdrom: ret cdrom_fail: +#ifdef APPLE_CC + err_cdfail_msg_abs = 0x7C00 + err_cdfail_msg - start + movw $(err_cdfail_msg_abs), %si +#else movw $(0x7C00 + err_cdfail_msg - start), %si +#endif fail: movb $0x0e, %ah
boot/i386/pc/diskboot.S +20 -0
@@ -28,7 +28,11 @@ #define ABS(x) (x-_start+GRUB_BOOT_MACHINE_KERNEL_ADDR) /* Print message string */ +#ifdef APPLE_CC +#define MSG(x) x ## _abs = ABS(x); mov $x ## _abs, %esi; call message +#else #define MSG(x) movw $ABS(x), %si; call message +#endif .file "diskboot.S"
@@ -61,7 +65,12 @@ _start: popw %si /* this sets up for the first run through "bootloop" */ +#ifdef APPLE_CC + firstlist_off_abs = ABS (firstlist - GRUB_BOOT_MACHINE_LIST_SIZE) + movl $firstlist_off_abs, %edi +#else movw $ABS(firstlist - GRUB_BOOT_MACHINE_LIST_SIZE), %di +#endif /* save the sector number of the second sector in %ebp */ movl (%di), %ebp
@@ -326,6 +335,16 @@ general_error: /* go here when you need to stop the machine hard after an error condition */ stop: jmp stop +#ifdef APPLE_CC +notification_string: .asciz "loading" + +notification_step: .asciz "." +notification_done: .asciz "\r\n" + +geometry_error_string: .asciz "Geom" +read_error_string: .asciz "Read" +general_error_string: .asciz " Error" +#else notification_string: .string "loading" notification_step: .string "."
@@ -334,6 +353,7 @@ notification_done: .string "\r\n" geometry_error_string: .string "Geom" read_error_string: .string "Read" general_error_string: .string " Error" +#endif /* * message: write the string pointed to by %si
boot/i386/pc/pxeboot.S +3 -1
@@ -23,7 +23,9 @@ .code16 /* Let's go */ -.globl _start; _start: +.globl start, _start; +_start: +start: /* Root drive will default to boot drive */ movb $0xFF, %dh
conf/i386-pc.rmk +41 -13
102 lines not on this page · raw message
configure.ac +68 -30
173 lines not on this page · raw message
efiemu/runtime/efiemu.c +25 -11
@@ -40,18 +40,23 @@ grub_efi_status_t efiemu_set_wakeup_time (grub_efi_boolean_t enabled, grub_efi_time_t *time); +#ifdef APPLE_CC +#define PHYSICAL_ATTRIBUTE __attribute__ ((section("_text-physical, _text-physical"))); +#else +#define PHYSICAL_ATTRIBUTE __attribute__ ((section(".text-physical"))); +#endif grub_efi_status_t efiemu_set_virtual_address_map (grub_efi_uintn_t memory_map_size, grub_efi_uintn_t descriptor_size, grub_efi_uint32_t descriptor_version, grub_efi_memory_descriptor_t *virtual_map) - __attribute__ ((section (".text-physical" ))); + PHYSICAL_ATTRIBUTE; grub_efi_status_t efiemu_convert_pointer (grub_efi_uintn_t debug_disposition, void **address) - __attribute__ ((section (".text-physical" ))); + PHYSICAL_ATTRIBUTE; grub_efi_status_t efiemu_get_variable (grub_efi_char16_t *variable_name,
@@ -84,17 +89,17 @@ EFI_FUNC (efiemu_set_virtual_address_map) (grub_efi_uintn_t, grub_efi_uintn_t, grub_efi_uint32_t, grub_efi_memory_descriptor_t *) - __attribute__ ((section(".text-physical"))); +PHYSICAL_ATTRIBUTE ; grub_efi_status_t EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition, void **address) - __attribute__ ((section (".text-physical" ))); + PHYSICAL_ATTRIBUTE; static grub_uint32_t efiemu_getcrc32 (grub_uint32_t crc, void *buf, int size) - __attribute__ ((section (".text-physical" ))); + PHYSICAL_ATTRIBUTE; static void init_crc32_table (void) - __attribute__ ((section (".text-physical" ))); + PHYSICAL_ATTRIBUTE;/* The log. It's used when examining memory dump
@@ -161,18 +166,26 @@ efiemu_memset (grub_uint8_t *a, grub_uint8_t b, grub_size_t n)static inline void write_cmos (grub_uint8_t addr,grub_uint8_t val) { +/* FIXME: make this chunk work with Apple's gcc */ +#ifndef APPLE_CC __asm__ __volatile__ ("outb %%al,$0x70\n" "mov %%bl, %%al\n" "outb %%al,$0x71" : :"a" (addr),"b" (val)); +#endif }static inline grub_uint8_t read_cmos (grub_uint8_t addr) { +/* FIXME: make this chunk work with Apple's gcc */ +#ifndef APPLE_CC grub_uint8_t ret; __asm__ __volatile__ ("outb %%al, $0x70\n" "inb $0x71, %%al" :"=a" (ret) :"a" (addr));return ret; +#else +return 0 ; +#endif }/* Needed by some gcc versions */
@@ -271,12 +284,9 @@ EFI_FUNC (efiemu_set_wakeup_time) (grub_efi_boolean_t enabled,static grub_uint32_t crc32_table [256 ]; -static void -init_crc32_table (void ) +static grub_uint32_t +reflect (grub_uint32_t ref,int len) { - autogrub_uint32_t reflect (grub_uint32_t ref,int len); -grub_uint32_t reflect (grub_uint32_t ref,int len) - {grub_uint32_t result =0 ;int i;
@@ -290,6 +300,10 @@ init_crc32_table (void)return result; } + +static void +init_crc32_table (void ) +{grub_uint32_t polynomial =0x04c11db7 ;int i, j;
gencmdlist.sh +3 -1
@@ -17,4 +17,6 @@ module=$1 grep -v "^#" | sed -n \ -e "/grub_register_command *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $module/;p;}" \ - -e "/\(grub_register_extcmd\|grub_register_command_p1\) *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $module/;p;}" + -e "/grub_register_extcmd *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $module/;p;}" \ + -e "/grub_register_command_p1 *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $module/;p;}" +
genmk.rb +30 -0
@@ -56,8 +56,21 @@ class Image "CLEANFILES += #{@name} #{exe} #{objs_str} MOSTLYCLEANFILES += #{deps_str} +ifneq ($(TARGET_APPLE_CC),1) #{@name}: #{exe} $(OBJCOPY) -O $(#{prefix}_FORMAT) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id $< $@ +endif + +ifeq ($(TARGET_APPLE_CC),1) +ifneq (#{exe},kernel.exec) +#{@name}: #{exe} + ./macho2img $< $@ +endif +ifeq (#{exe},kernel.exec) +#{@name}: #{exe} + ./macho2img --bss $< $@ +endif +endif #{exe}: #{objs_str} $(TARGET_CC) -o $@ $^ $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS)
@@ -112,11 +125,22 @@ endif MOSTLYCLEANFILES += #{deps_str} UNDSYMFILES += #{undsym} +ifneq ($(TARGET_APPLE_CC),1) #{@name}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF) -rm -f $@ $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ #{pre_obj} #{mod_obj} if test ! -z $(TARGET_OBJ2ELF); then ./$(TARGET_OBJ2ELF) $@ || (rm -f $@; exit 1); fi $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -K _grub_mod_init -K _grub_mod_fini -R .note -R .comment $@ +endif + +ifeq ($(TARGET_APPLE_CC),1) +#{@name}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF) + -rm -f $@ + -rm -f [email protected] + $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o [email protected] #{pre_obj} #{mod_obj} + $(OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -wd1106 -nu -nd [email protected] $@ + -rm -f [email protected] +endif #{pre_obj}: $(#{prefix}_DEPENDENCIES) #{objs_str} -rm -f $@
@@ -129,9 +153,15 @@ UNDSYMFILES += #{undsym} sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1) ifneq ($(#{prefix}_EXPORTS),no) +ifneq ($(TARGET_APPLE_CC),1) #{defsym}: #{pre_obj} $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@ endif +ifeq ($(TARGET_APPLE_CC),1) +#{defsym}: #{pre_obj} + $(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]' | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@ +endif +endif #{undsym}: #{pre_obj} echo '#{mod_name}' > $@
genmoddep.awk +1 -1
@@ -50,7 +50,7 @@ END { for (i in depmods) { depmod = depmods[i]; # Ignore kernel, as always loaded. - if (depmod != "kernel") + if (depmod != "kernel" && depmod != mod) uniqmods[depmod] = 1; } modlist = ""
include/grub/dl.h +8 -0
@@ -40,11 +40,19 @@ grub_##name##_fini (void) { grub_mod_fini (); } \static void \ grub_mod_fini (void) +#ifdef APPLE_CC +#define GRUB_MOD_NAME (name) \ +static char grub_modname[] __attribute__ ((section ("_modname, _modname"), used)) = #name; + +#define GRUB_MOD_DEP (name) \ +__asm__ (".section _moddeps, _moddeps\n.asciz \"" #name "\"\n") +#else #define GRUB_MOD_NAME (name) \ __asm__ (".section .modname\n.string \"" #name "\"\n")#define GRUB_MOD_DEP (name) \ __asm__ (".section .moddeps\n.string \"" #name "\"\n") +#endif struct grub_dl_segment {
include/grub/i386/pc/kernel.h +2 -0
@@ -74,8 +74,10 @@ extern grub_int32_t EXPORT_VAR(grub_boot_drive);/* The root BIOS drive number. */ extern grub_int32_t grub_root_drive; +#if 0 /* The end address of the kernel. */ extern grub_addr_t grub_end_addr; +#endif #endif /* ! ASM_FILE */
include/grub/i386/tsc.h +36 -2
@@ -29,8 +29,24 @@ grub_get_tsc (void)/* The CPUID instruction is a 'serializing' instruction, and avoids out-of-order execution of the RDTSC instruction. */ +#ifdef APPLE_CC __asm__ __volatile__ ("xorl %%eax, %%eax\n\t" -"cpuid" :::"%rax" ,"%rbx" ,"%rcx" ,"%rdx" ); +#ifdef __x86_64__ + "push %%rbx\n" +#else + "push %%ebx\n" +#endif + "cpuid\n" +#ifdef __x86_64__ + "pop %%rbx\n" +#else +"pop %%ebx\n" +#endif + :::"%rax" ,"%rcx" ,"%rdx" ); +#else + __asm__ __volatile__ ("xorl %%eax, %%eax\n\t" +"cpuid" :::"%rax" ,"%rbx" ,"%rcx" ,"%rdx" ); +#endif /* Read TSC value. We cannot use "=A", since this would use %rax on x86_64. */ __asm__ __volatile__ ("rdtsc" :"=a" (lo),"=d" (hi));
@@ -93,11 +109,29 @@ grub_cpu_is_tsc_supported (void)return 0 ;grub_uint32_t features; +#ifdef APPLE_CC __asm__ ("movl $1, %%eax\n\t" -"cpuid" +#ifdef __x86_64__ + "push %%rbx\n" +#else + "push %%ebx\n" +#endif + "cpuid\n" +#ifdef __x86_64__ + "pop %%rbx\n" +#else +"pop %%ebx\n" +#endif + :"=d" (features) + :/* No inputs. */ + :/* Clobbered: */ "%rax" ,"%rcx" ); +#else + __asm__ ("movl $1, %%eax\n\t" +"cpuid\n" :"=d" (features) :/* No inputs. */ :/* Clobbered: */ "%rax" ,"%rbx" ,"%rcx" ); +#endif return (features & (1 <<4 )) !=0 ; }
include/grub/list.h +11 -0
@@ -41,7 +41,18 @@ void EXPORT_FUNC(grub_list_insert) (grub_list_t *head, grub_list_t item,/* This function doesn't exist, so if assertion is false for some reason, the linker would fail. */ +#ifdef APPLE_CC +/* This approach fails with Apple's gcc. Use grub_abort. */ +#include <grub/misc.h> +static inline void * +grub_assert_fail (void ) +{ +grub_abort (); +return 0 ; +} +#else extern void *grub_assert_fail (void ); +#endif #define GRUB_FIELD_MATCH (ptr, type, field) \ ((char *) &(ptr)->field == (char *) &((type) (ptr))->field)
include/grub/misc.h +2 -0
@@ -40,8 +40,10 @@ char *EXPORT_FUNC(grub_strcat) (char *dest, const char *src);char *EXPORT_FUNC (grub_strncat ) (char *dest,const char *src,int c);/* Prototypes for aliases. */ +#if !defined (GRUB_UTIL ) || !defined (APPLE_CC )void *EXPORT_FUNC (memmove ) (void *dest,const void *src,grub_size_t n);void *EXPORT_FUNC (memcpy ) (void *dest,const void *src,grub_size_t n); +#endif int EXPORT_FUNC (grub_memcmp ) (const void *s1,const void *s2,grub_size_t n);int EXPORT_FUNC (grub_strcmp ) (const char *s1,const char *s2);
include/grub/symbol.h +4 -1
@@ -28,7 +28,10 @@# define EXT_C (sym) sym#endif -#if ! defined (__CYGWIN__) && ! defined (__MINGW32__) +#if defined (APPLE_CC ) +#define FUNCTION (x) .globl EXT_C(x) ; EXT_C(x): +#define VARIABLE (x) .globl EXT_C(x) ; EXT_C(x): +#elif ! defined (__CYGWIN__) && ! defined (__MINGW32__)#define FUNCTION (x) .globl EXT_C(x) ; .type EXT_C(x), "function" ; EXT_C(x):#define VARIABLE (x) .globl EXT_C(x) ; .type EXT_C(x), "object" ; EXT_C(x):#else
include/grub/term.h +1 -1
@@ -31,7 +31,7 @@#define GRUB_TERM_NPAGE 3#define GRUB_TERM_ESC '\e'#define GRUB_TERM_TAB '\t' -#define GRUB_TERM_BACKSPACE '\b' +#define GRUB_TERM_BACKSPACE 8#ifndef ASM_FILE
kern/i386/pc/startup.S +50 -2
117 lines not on this page · raw message
kern/misc.c +35 -1
@@ -44,11 +44,23 @@ grub_memmove (void *dest, const void *src, grub_size_t n)return dest; } + +#ifndef APPLE_CC void *memmove (void *dest,const void *src,grub_size_t n) __attribute__ ((alias ("grub_memmove" )));/* GCC emits references to memcpy() for struct copies etc. */ void *memcpy (void *dest,const void *src,grub_size_t n) __attribute__ ((alias ("grub_memmove" ))); +#else +void *memcpy (void *dest,const void *src,grub_size_t n) +{ +return grub_memmove (dest, src, n); +} +void *memmove (void *dest,const void *src,grub_size_t n) +{ +return grub_memmove (dest, src, n); +} +#endif char *grub_strcpy (char *dest,const char *src)
@@ -134,7 +146,22 @@ grub_printf (const char *fmt, ...)return ret; } -#ifndef GRUB_UTIL +#if defined (APPLE_CC ) && ! defined (GRUB_UTIL ) +int +grub_err_printf (const char *fmt, ...) +{ +va_list ap; +int ret; + +va_start (ap, fmt); + ret =grub_vprintf (fmt, ap); +va_end (ap); + +return ret; +} +#endif + +#if ! defined (APPLE_CC ) && ! defined (GRUB_UTIL )int grub_err_printf (const char *fmt, ...) __attribute__ ((alias ("grub_printf" )));#endif
@@ -185,8 +212,10 @@ grub_memcmp (const void *s1, const void *s2, grub_size_t n)return 0 ; } +#ifndef APPLE_CC int memcmp (const void *s1,const void *s2,grub_size_t n) __attribute__ ((alias ("grub_memcmp" ))); +#endif int grub_strcmp (const char *s1,const char *s2)
@@ -534,8 +563,10 @@ grub_memset (void *s, int c, grub_size_t n)return s; } +#ifndef APPLE_CC void *memset (void *s,int c,grub_size_t n) __attribute__ ((alias ("grub_memset" ))); +#endif grub_size_t grub_strlen (const char *s)
@@ -1066,8 +1097,11 @@ grub_abort (void)grub_exit (); } + +#ifndef APPLE_CC /* GCC emits references to abort(). */ void abort (void ) __attribute__ ((alias ("grub_abort" ))); +#endif #ifdef NEED_ENABLE_EXECUTE_STACK /* Some gcc versions generate a call to this function
loader/i386/xnu.c +41 -1
62 lines not on this page · raw message
loader/i386/xnu_helper.S +18 -0
@@ -94,11 +94,28 @@ VARIABLE(grub_xnu_heap_size) movsl mov %rax, %rsi +#ifdef APPLE_CC + add $(cont0-base), %eax +#else add $(cont0-base), %rax +#endif jmp *%rax cont0: +#ifdef APPLE_CC + lea (cont1-base)(%esi, 1), %eax + mov %eax, (jump_vector-base)(%esi,1) + + lea (gdt-base)(%esi, 1), %eax + mov %eax, (gdt_addr-base)(%esi,1) + + /* Switch to compatibility mode. */ + lgdt (gdtdesc-base)(%esi,1) + + /* Update %cs. Thanks to David Miller for pointing this mistake out. */ + ljmp *(jump_vector-base)(%esi,1) +#else lea (cont1-base)(%rsi, 1), %rax mov %eax, (jump_vector-base)(%rsi,1)
@@ -111,6 +128,7 @@ cont0: /* Update %cs. Thanks to David Miller for pointing this mistake out. */ ljmp *(jump_vector-base)(%rsi,1) +#endif cont1: .code32
mmap/i386/pc/mmap_helper.S +32 -0
@@ -28,7 +28,12 @@ VARIABLE(grub_machine_mmaphook_int12) push %ds push %cs pop %ds +#ifdef APPLE_CC + grub_machine_mmaphook_kblow_rel = DS (EXT_C (grub_machine_mmaphook_kblow)) + movw (grub_machine_mmaphook_kblow_rel), %ax +#else movw DS (EXT_C (grub_machine_mmaphook_kblow)), %ax +#endif pop %ds iret
@@ -53,8 +58,15 @@ e801: push %ds push %cs pop %ds +#ifdef APPLE_CC + grub_machine_mmaphook_kbin16mb_rel = DS (EXT_C (grub_machine_mmaphook_kbin16mb)) + grub_machine_mmaphook_64kbin4gb_rel = DS (EXT_C (grub_machine_mmaphook_64kbin4gb)) + movw (grub_machine_mmaphook_kbin16mb_rel), %ax + movw (grub_machine_mmaphook_64kbin4gb_rel), %bx +#else movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax movw DS (EXT_C (grub_machine_mmaphook_64kbin4gb)), %bx +#endif movw %ax, %cx movw %bx, %dx pop %ds
@@ -66,26 +78,42 @@ h88: push %ds push %cs pop %ds +#ifdef APPLE_CC + movw (grub_machine_mmaphook_kbin16mb_rel), %ax +#else movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax +#endif pop %ds clc iret e820: +#ifdef APPLE_CC + mmaphook_mmap_rel = DS(mmaphook_mmap) + mmaphook_mmap_num_rel = DS(EXT_C(grub_machine_mmaphook_mmap_num)) +#endif popf push %ds push %cs pop %ds cmpw $20, %cx jb errexit +#ifdef APPLE_CC + cmpw (mmaphook_mmap_num_rel), %bx +#else cmpw DS (EXT_C (grub_machine_mmaphook_mmap_num)), %bx +#endif jae errexit cmp $0x534d4150, %edx jne errexit push %si push %di movw $20, %cx +#ifdef APPLE_CC + movl $(mmaphook_mmap_rel), %esi +#else movw $(DS(mmaphook_mmap)), %si +#endif mov %bx, %ax imul $20, %ax add %ax, %si
@@ -94,7 +122,11 @@ e820: pop %si movl $20, %ecx inc %bx +#ifdef APPLE_CC + cmpw (mmaphook_mmap_num_rel), %bx +#else cmpw DS(EXT_C(grub_machine_mmaphook_mmap_num)), %bx +#endif jb noclean xor %bx, %bx noclean:
util/macho2img.c new file +116 -0
116 lines not on this page · raw message
Hi,
patches were applied with grub2 rev 2202, compiles and builds grub.efi in Mac OSX 10.5.6 , i686-apple-darwin9-gcc-4.0.1, with no errors, but fails to run grub.efi.
./configure --with-platform=efi --target=x86_64
./grub-mkimage -d . -o grubosx.efi appleldr boot cat cmp chain configfile crc date echo ext2 fixvideo fat fs_uuid gpt gptsync halt help hexdump hfs
hfsplus iso9660 linux loopback loadbios lspci ls minicmd memrw ntfs pc pci
reboot reiserfs read scsi sleep search sh video videotest xfs
rEFIt then gives -
Starting grubosx.efi
and hangs there (i.e. before the Welcome to GRUB).
Attempt to compile macho2img.c gave error, but is this needed for x86_64?
Quoted 19 lines · Vladimir 'phcoder' Serbinenko
Hello. With this patch you can compile grub2 using Apple's gcc. Only partially tested. You need objconv available from
http://www.agner.org/optimize/ licensed under GPL and additionally patched with attached patch
Then you need to patch grub2 with attached patch. If you compile for i386-pcbefore you begin you need to compile execute:
gcc -o macho2imgutil/macho2img.c-Iinclude
Then just compile grub2 normally. I will look how to automatise the compilation of macho2img
--
Regards
Vladimir 'phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Cros (pxw)
Quoted 8 lines · Peter Cros
Hi,
patches were applied with grub2 rev 2202, compiles and builds grub.efi in Mac OSX 10.5.6 , i686-apple-darwin9-gcc-4.0.1, with no errors, but fails to run grub.efi.
./configure --with-platform=efi --target=x86_64
./grub-mkimage -d . -o grubosx.efi appleldr boot cat cmp chain configfile crc date echo ext2 fixvideo fatfs_uuidgpt gptsync halt help hexdump hfs hfsplus iso9660 linux loopback loadbios lspci ls minicmd memrw ntfs pc pci reboot reiserfs read scsi sleep search sh video videotest xfs rEFIt then gives -
Starting grubosx.efi
and hangs there (i.e. before the Welcome to GRUB).
It's a bug in grub-mkimage - it inappropriately assumes that text is a first segment. I'll fix it. Temporarily you can just comment out the following line:util/i386/efi/grub-mkimage.c: line 104: strcpy (kernel_image + sizeof (Elf_Ehdr) + GRUB_KERNEL_MACHINE_PREFIX, prefix);
Quoted 26 lines
Attempt to compile
macho2img.cgave error, but is this needed forx86_64?Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Hello. With this patch you can compile grub2 using Apple's gcc. Only partially tested. You need objconv available from http://www.agner.org/optimize/ licensed under GPL and additionally patched with attached patch Then you need to patch grub2 with attached patch. If you compile for i386-pcbefore you begin you need to compile execute:
gcc -o macho2imgutil/macho2img.c-Iinclude
Then just compile grub2 normally. I will look how to automatise the compilation of macho2img
--
Regards
Vladimir 'phcoder' SerbinenkoQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Cros (pxw)
Quoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
--
Regards
Vladimir 'phcoder' Serbinenko
Quoted 10 lines · Vladimir 'phcoder' Serbinenko
Quoted 8 lines · Peter Cros
Hi,
patches were applied with grub2 rev 2202, compiles and builds grub.efi in Mac OSX 10.5.6 , i686-apple-darwin9-gcc-4.0.1, with no errors, but fails to run grub.efi.
./configure --with-platform=efi --target=x86_64
./grub-mkimage -d . -o grubosx.efi appleldr boot cat cmp chain configfile crc date echo ext2 fixvideo fatfs_uuidgpt gptsync halt help hexdump hfs hfsplus iso9660 linux loopback loadbios lspci ls minicmd memrw ntfs pc pci reboot reiserfs read scsi sleep search sh video videotest xfs rEFIt then gives -
Starting grubosx.efi
and hangs there (i.e. before the Welcome to GRUB).
Also it looks like the problems are limited to kernel.mod. If you take this file from linux build rest should be fine
Quoted 43 lines
It's a bug in grub-mkimage - it inappropriately assumes that text is a first segment. I'll fix it. Temporarily you can just comment out the following line:
util/i386/efi/grub-mkimage.c: line 104: strcpy (kernel_image+ sizeof (Elf_Ehdr) +GRUB_KERNEL_MACHINE_PREFIX, prefix);Quoted 26 lines
Attempt to compile
macho2img.cgave error, but is this needed forx86_64?Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Hello. With this patch you can compile grub2 using Apple's gcc. Only partially tested. You need objconv available from http://www.agner.org/optimize/ licensed under GPL and additionally patched with attached patch Then you need to patch grub2 with attached patch. If you compile for i386-pcbefore you begin you need to compile execute:
gcc -o macho2imgutil/macho2img.c-Iinclude
Then just compile grub2 normally. I will look how to automatise the compilation of macho2img
--
Regards
Vladimir 'phcoder' SerbinenkoQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Cros (pxw)Quoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Regards
Vladimir 'phcoder' Serbinenko
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
It compiles for me, but even with outcommented line in grub-mkimage.c it does not start.
Quoted 70 lines · Vladimir 'phcoder' Serbinenko
Quoted 10 lines · Vladimir 'phcoder' Serbinenko
Quoted 8 lines · Peter Cros
Hi,
patches were applied with grub2 rev 2202, compiles and builds grub.efi in Mac OSX 10.5.6 , i686-apple-darwin9-gcc-4.0.1, with no errors, but fails to run grub.efi.
./configure --with-platform=efi --target=x86_64
./grub-mkimage -d . -o grubosx.efi appleldr boot cat cmp chain configfile crc date echo ext2 fixvideo fatfs_uuidgpt gptsync halt help hexdump hfs hfsplus iso9660 linux loopback loadbios lspci ls minicmd memrw ntfs pc pci reboot reiserfs read scsi sleep search sh video videotest xfs rEFIt then gives -
Starting grubosx.efi
and hangs there (i.e. before the Welcome to GRUB).Also it looks like the problems are limited to kernel.mod. If you take this file from linux build rest should be fine
Quoted 39 lines
It's a bug in grub-mkimage - it inappropriately assumes that text is a first segment. I'll fix it. Temporarily you can just comment out the following line:
util/i386/efi/grub-mkimage.c: line 104: strcpy (kernel_image+ sizeof (Elf_Ehdr) +GRUB_KERNEL_MACHINE_PREFIX, prefix);Quoted 26 lines
Attempt to compile
macho2img.cgave error, but is this needed forx86_64?Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Hello. With this patch you can compile grub2 using Apple's gcc. Only partially tested. You need objconv available from http://www.agner.org/optimize/ licensed under GPL and additionally patched with attached patch Then you need to patch grub2 with attached patch. If you compile for i386-pcbefore you begin you need to compile execute:
gcc -o macho2imgutil/macho2img.c-Iinclude
Then just compile grub2 normally. I will look how to automatise the compilation of macho2img
--
Regards
Vladimir 'phcoder' SerbinenkoQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Cros (pxw)Quoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-develQuoted 4 lines
--
Regards
Vladimir 'phcoder' Serbinenko--
Regards
Vladimir 'phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 2 lines · On Mon, May 11, 2009 at 8:04 PM, step21 <[email protected]> wrote:
It compiles for me, but even with outcommented line in
grub-mkimage.cit does not start.
It's a bug in objconv with 64-bit images. Add this patch workaround (prefix workaround still applies). Also this patch-on-patch contains another improvement for 64-bit apple compiler
Quoted 80 lines
Quoted 65 lines · Vladimir 'phcoder' Serbinenko
Quoted 10 lines · Vladimir 'phcoder' Serbinenko
Quoted 8 lines · Peter Cros
Hi,
patches were applied with grub2 rev 2202, compiles and builds grub.efi in Mac OSX 10.5.6 , i686-apple-darwin9-gcc-4.0.1, with no errors, but fails to run grub.efi.
./configure --with-platform=efi --target=x86_64
./grub-mkimage -d . -o grubosx.efi appleldr boot cat cmp chain configfile crc date echo ext2 fixvideo fatfs_uuidgpt gptsync halt help hexdump hfs hfsplus iso9660 linux loopback loadbios lspci ls minicmd memrw ntfs pc pci reboot reiserfs read scsi sleep search sh video videotest xfs rEFIt then gives -
Starting grubosx.efi
and hangs there (i.e. before the Welcome to GRUB).Also it looks like the problems are limited to kernel.mod. If you take this file from linux build rest should be fine
Quoted 39 lines
It's a bug in grub-mkimage - it inappropriately assumes that text is a first segment. I'll fix it. Temporarily you can just comment out the following line:
util/i386/efi/grub-mkimage.c: line 104: strcpy (kernel_image+ sizeof (Elf_Ehdr) +GRUB_KERNEL_MACHINE_PREFIX, prefix);Quoted 26 lines
Attempt to compile
macho2img.cgave error, but is this needed forx86_64?Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Hello. With this patch you can compile grub2 using Apple's gcc. Only partially tested. You need objconv available from http://www.agner.org/optimize/ licensed under GPL and additionally patched with attached patch Then you need to patch grub2 with attached patch. If you compile for i386-pcbefore you begin you need to compile execute:
gcc -o macho2imgutil/macho2img.c-Iinclude
Then just compile grub2 normally. I will look how to automatise the compilation of macho2img
--
Regards
Vladimir 'phcoder' SerbinenkoQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Cros (pxw)Quoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-develQuoted 4 lines
--
Regards
Vladimir 'phcoder' Serbinenko--
Regards
Vladimir 'phcoder' SerbinenkoQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
configure.ac +9 -4
@@ -344,16 +344,21 @@ if test "x$target_m64" = x1; then TARGET_MODULE_FORMAT="elf64" fi -if test "$target_cpu"-"$platform" = x86_64-efi && test x$TARGET_APPLE_CC == x0; then +if test "$target_cpu"-"$platform" = x86_64-efi; then # Use large model to support 4G memory AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [ + SAVED_CFLAGS=$CFLAGS CFLAGS="$CFLAGS -m64 -mcmodel=large" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [grub_cv_cc_mcmodel=yes], [grub_cv_cc_mcmodel=no]) ]) - if test "x$grub_cv_cc_no_mcmodel" = xno; then - AC_MSG_ERROR([-mcmodel=large not supported, upgrade your gcc]) + if test "x$grub_cv_cc_mcmodel" = xno; then + CFLAGS="$SAVED_CFLAGS -m64 -DMCMODEL_SMALL=1" + TARGET_CFLAGS="$TARGET_CFLAGS -DMCMODEL_SMALL=1" + AC_MSG_WARN([-mcmodel=large not supported. You wan't be able to use the memory over 4GiB. Upgrade your gcc]) + else + TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large" fi # EFI writes to stack below %rsp, we must not use the red zone
@@ -367,7 +372,7 @@ if test "$target_cpu"-"$platform" = x86_64-efi && test x$TARGET_APPLE_CC == x0; AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc]) fi - TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large -mno-red-zone" + TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone" fi #
kern/efi/mm.c +4 -3
@@ -63,7 +63,8 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address,/* Limit the memory access to less than 4GB for 32-bit platforms. */ if (address >0xffffffff )return 0 ; - +#endif +#if GRUB_TARGET_SIZEOF_VOID_P <8 || defined (MCMODEL_SMALL )if (address ==0 ) { type =GRUB_EFI_ALLOCATE_MAX_ADDRESS ;
@@ -218,7 +219,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) {if (desc->type ==GRUB_EFI_CONVENTIONAL_MEMORY -#if GRUB_TARGET_SIZEOF_VOID_P < 8 +#if GRUB_TARGET_SIZEOF_VOID_P < 8 || defined (MCMODEL_SMALL) && desc->physical_start <=0xffffffff #endif && desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000
@@ -234,7 +235,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, desc->physical_start =0x100000 ; } -#if GRUB_TARGET_SIZEOF_VOID_P <8 +#if GRUB_TARGET_SIZEOF_VOID_P <8 || defined (MCMODEL_SMALL )if (BYTES_TO_PAGES (filtered_desc->physical_start) + filtered_desc->num_pages >BYTES_TO_PAGES (0x100000000LL ))
util/i386/efi/grub-mkimage.c +2 -2
@@ -386,8 +386,8 @@ relocate_addresses (Elf_Ehdr *e, Elf_Shdr *sections, sym_addr =get_symbol_address (e, symtab_section,ELF_R_SYM (info)); - value = (s->sh_type ==grub_cpu_to_le32 (SHT_RELA )) ? - (Elf_Addr *) &r->r_addend : target; + value =/*(s->sh_type == grub_cpu_to_le32 (SHT_RELA)) ? +(Elf_Addr *) &r->r_addend :*/ target;switch (ELF_R_TYPE (info)) {
All good now, with the addition of grub-mkimage.c prefix workaround and apple2.diff. (grub2 rev2202)
(x86_64 grub.efi booting ubuntu904 2.6.28-amd64 on MBP4,1).
Quoted 112 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines · On Mon, May 11, 2009 at 8:04 PM, step21 <[email protected]> wrote:
It compiles for me, but even with outcommented line in
grub-mkimage.cit does not start.It's a bug in objconv with 64-bit images. Add this patch workaround (prefix workaround still applies). Also this patch-on-patch contains another improvement for 64-bit apple compiler
Quoted 6 lines
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
Quoted 1 line · Vladimir 'phcoder' Serbinenko
On Mon, May 11, 2009 at 12:48 PM, Peter Cros <[email protected]>
Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hi,
patches were applied with grub2 rev 2202, compiles and builds grub.efiin Mac OSX 10.5.6 , i686-apple-darwin9-gcc-4.0.1, with no errors, but fails to run grub.efi.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
./configure --with-platform=efi --target=x86_64 ./grub-mkimage -d . -o grubosx.efi appleldr boot cat cmp chain
configfile crc date echo ext2 fixvideo fat
fs_uuidgpt gptsync halt help hexdump hfs hfsplus iso9660 linux loopback loadbios lspci ls minicmd memrw ntfs pc pci reboot reiserfs read scsi sleep search sh video videotest xfsQuoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
rEFIt then gives -
Starting grubosx.efi
and hangs there (i.e. before the Welcome to GRUB).Also it looks like the problems are limited to kernel.mod. If you take this file from linux build rest should be fine
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
It's a bug in grub-mkimage - it inappropriately assumes that text is a first segment. I'll fix it. Temporarily you can just comment out the following line:
util/i386/efi/grub-mkimage.c: line 104: strcpy (kernel_image+ sizeof (Elf_Ehdr) +GRUB_KERNEL_MACHINE_PREFIX, prefix);Quoted 2 lines
Attempt to compile
macho2img.cgave error, but is this needed for
x86_64?Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On Mon, May 11, 2009 at 2:46 AM, Vladimir 'phcoder' Serbinenko <
Quoted 2 lines · [email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Hello. With this patch you can compile grub2 using Apple's gcc. Only
partially tested. You need objconv available from
http://www.agner.org/optimize/ licensed under GPL and additionally patched with attached patchQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Then you need to patch grub2 with attached patch. If you compile for
i386-pcbefore you begin you need to compile execute:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
gcc -o macho2img
util/macho2img.c-Iinclude
Then just compile grub2 normally. I will look how to automatise thecompilation of macho2img
Quoted 44 lines
Quoted 37 lines
Quoted 25 lines
Quoted 17 lines
Quoted 9 lines
--
Regards
Vladimir 'phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Cros (pxw)Quoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-develQuoted 4 lines
--
Regards
Vladimir 'phcoder' Serbinenko--
Regards
Vladimir 'phcoder' SerbinenkoQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-develQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Regards
Vladimir 'phcoder' Serbinenko_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Cros (pxw)
Also good for cross compile --target=i386, running grub32.efi on MacBook2,1.
Quoted 9 lines · Peter Cros
All good now, with the addition of
grub-mkimage.cprefix workaround and apple2.diff. (grub2 rev2202)(
x86_64grub.efi booting ubuntu904 2.6.28-amd64 on MBP4,1).--
Cros (pxw)
it gets started now, but then goes to rescue mode. Possibly I just forgot to pass some module to grub-mkimage, but don't know which, cause in addition to configfile I also tried with almost all modules, but still only rescue mode. any ideas?
Quoted 21 lines · Peter Cros
Also good for cross compile --target=i386, running grub32.efi on MacBook2,1.
Quoted 6 lines · Peter Cros
All good now, with the addition of
grub-mkimage.cprefix workaround and apple2.diff. (grub2 rev2202)
(x86_64grub.efi booting ubuntu904 2.6.28-amd64 on MBP4,1).--
Cros (pxw)_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Hi,
Have you tried sh.mod and normal.mod ?
Quoted 34 lines · On Tue, May 12, 2009 at 7:48 PM, step21 <[email protected]> wrote:
it gets started now, but then goes to rescue mode. Possibly I just forgot to pass some module to grub-mkimage, but don't know which, cause in addition to configfile I also tried with almost all modules, but still only rescue mode. any ideas?
Quoted 15 lines · Peter Cros
Also good for cross compile --target=i386, running grub32.efi on MacBook2,1.
Quoted 6 lines · Peter Cros
All good now, with the addition of
grub-mkimage.cprefix workaround and apple2.diff. (grub2 rev2202)
(x86_64grub.efi booting ubuntu904 2.6.28-amd64 on MBP4,1).--
Cros (pxw)Quoted 6 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Bean
I didn't include sh.mod speifically in my past builds, but even with it specifically added somehow I only get rescue mode. My other grub.efi is in the same directory and still works perfectly. command used if you want to check it: "./grub-mkimage -d . -o grapple.efi configfile kernel normal xnu linux ntfs hfs hfsplus ext2 terminfo minicmd sleep search reboot pc pci gpt gptsync ls lspci loadenv hexdump fixvideo fat apple crc echo sh"
Quoted 51 lines · Bean
Hi,
Have you tried sh.mod and normal.mod ?
Quoted 29 lines · On Tue, May 12, 2009 at 7:48 PM, step21 <[email protected]> wrote:
it gets started now, but then goes to rescue mode. Possibly I just forgot to pass some module to grub-mkimage, but don't know which, cause in addition to configfile I also tried with almost all modules, but still only rescue mode. any ideas?
Quoted 15 lines · Peter Cros
Also good for cross compile --target=i386, running grub32.efi on MacBook2,1.
Quoted 6 lines · Peter Cros
All good now, with the addition of
grub-mkimage.cprefix workaround and apple2.diff. (grub2 rev2202)
(x86_64grub.efi booting ubuntu904 2.6.28-amd64 on MBP4,1).--
Cros (pxw)Quoted 6 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-develQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Bean_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 8 lines · On Tue, May 12, 2009 at 10:57 PM, step21 <[email protected]> wrote:
I didn't include sh.mod speifically in my past builds, but even with it specifically added somehow I only get rescue mode. My other grub.efi is in the same directory and still works perfectly. command used if you want to check it: "./grub-mkimage -d . -o grapple.efi configfile kernel normal xnu linux ntfs hfs hfsplus ext2 terminfo minicmd sleep search reboot pc pci gpt gptsync ls lspci loadenv hexdump fixvideo fat apple crc echo sh"
I recommend:
acorn acpi affs afs amiga apple appleldr bitmap blocklist boot bufio cat chain cmp configfile cpio crc date datehook datetime dm_nv echo elf ext2 extcmd fat fixvideo font fs_uuid fshelp gfxterm gpt gptsync gzio halt handler hello help hexdump hfs hfsplus iso9660 jfs jpeg linux loadbios loadenv loopback ls lspci lvm mdraid memrw minicmd minix mmap normal ntfs ntfscomp parttool pc pci pcpart png raid raid5rec raid6rec read reboot reiserfs scsi search setjmp sfs sh sleep sun tar terminfo test tga udf ufs video videotest xfs xnu (all except lua and kernel)
Quoted 60 lines · Bean
Quoted 42 lines
Hi,
Have you tried sh.mod and normal.mod ?
Quoted 29 lines · On Tue, May 12, 2009 at 7:48 PM, step21 <[email protected]> wrote:
it gets started now, but then goes to rescue mode. Possibly I just forgot to pass some module to grub-mkimage, but don't know which, cause in addition to configfile I also tried with almost all modules, but still only rescue mode. any ideas?
Quoted 15 lines · Peter Cros
Also good for cross compile --target=i386, running grub32.efi on MacBook2,1.
Quoted 6 lines · Peter Cros
All good now, with the addition of
grub-mkimage.cprefix workaround and apple2.diff. (grub2 rev2202)
(x86_64grub.efi booting ubuntu904 2.6.28-amd64 on MBP4,1).--
Cros (pxw)Quoted 6 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-develQuoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-develQuoted 9 lines
--
Bean_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Update
Quoted 13 lines · Vladimir 'phcoder' Serbinenko
Hello. With this patch you can compile grub2 using Apple's gcc. Only partially tested. You need objconv available from
http://www.agner.org/optimize/ licensed under GPL and additionally patched with attached patch
Then you need to patch grub2 with attached patch. If you compile for i386-pcbefore you begin you need to compile execute:
gcc -o macho2imgutil/macho2img.c-Iinclude
Then just compile grub2 normally. I will look how to automatise the compilation of macho2img
--
Regards
Vladimir 'phcoder' Serbinenko
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Makefile.in +6 -0
@@ -64,16 +64,22 @@ mkinstalldirs = $(srcdir)/mkinstalldirs CC = @CC@ CFLAGS = @CFLAGS@ +ASFLAGS = @ASFLAGS@ LDFLAGS = @LDFLAGS@ CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/include -Wall -W \ -DGRUB_LIBDIR=\"$(pkglibdir)\" TARGET_CC = @TARGET_CC@ TARGET_CFLAGS = @TARGET_CFLAGS@ +TARGET_ASFLAGS = @TARGET_ASFLAGS@ +TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@ +TARGET_APPLE_CC = @TARGET_APPLE_CC@ +OBJCONV = @OBJCONV@ TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/include \ -Wall -W TARGET_LDFLAGS = @TARGET_LDFLAGS@ TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@ TARGET_IMG_LDFLAGS = @TARGET_IMG_LDFLAGS@ +TARGET_IMG_CFLAGS = @TARGET_IMG_CFLAGS@ TARGET_OBJ2ELF = @TARGET_OBJ2ELF@ EXEEXT = @EXEEXT@ OBJCOPY = @OBJCOPY@
aclocal.m4 +31 -1
@@ -72,7 +72,7 @@ else AC_MSG_ERROR([${CC-cc} cannot compile C source code]) fi grub_cv_prog_objcopy_absolute=yes -for link_addr in 2000 8000 7C00; do +for link_addr in 2000 7C00 8000; do if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then : else AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
@@ -156,6 +156,36 @@ rm -f conftest*]) AC_MSG_RESULT([$grub_cv_i386_asm_addr32])]) +dnl check if our compiler is apple gcc +dnl because it requires numerous workarounds +AC_DEFUN(grub_apple_cc, +[AC_REQUIRE([AC_PROG_CC]) +AC_MSG_CHECKING([whether our compiler is apple cc]) +AC_CACHE_VAL(grub_cv_apple_cc, +[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then + grub_cv_apple_cc=yes +else + grub_cv_apple_cc=no +fi +]) + +AC_MSG_RESULT([$grub_cv_apple_cc])]) + +dnl check if our compiler is apple gcc +dnl because it requires numerous workarounds +AC_DEFUN(grub_apple_target_cc, +[AC_REQUIRE([AC_PROG_CC]) +AC_MSG_CHECKING([whether our target compiler is apple cc]) +AC_CACHE_VAL(grub_cv_apple_target_cc, +[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then + grub_cv_apple_target_cc=yes +else + grub_cv_apple_target_cc=no +fi +]) + +AC_MSG_RESULT([$grub_cv_apple_target_cc])]) + dnl Later versions of GAS requires that addr32 and data32 prefixes dnl appear in the same lines as the instructions they modify, while
boot/i386/pc/boot.S +62 -9
160 lines not on this page · raw message
boot/i386/pc/cdboot.S +12 -0
@@ -67,8 +67,15 @@ bi_reserved: movw %ax, %ds movw %ax, %es +#ifdef APPLE_CC + err_noboot_msg_abs = 0x7C00 + err_noboot_msg - start + movw $err_noboot_msg_abs, %si + bi_length_dif = bi_length - next + movl %cs:bi_length_dif(%bx), %ecx +#else movw $(0x7C00 + err_noboot_msg - start), %si movl %cs: bi_length - next(%bx), %ecx +#endif orl %ecx, %ecx jz fail
@@ -152,7 +159,12 @@ read_cdrom: ret cdrom_fail: +#ifdef APPLE_CC + err_cdfail_msg_abs = 0x7C00 + err_cdfail_msg - start + movw $(err_cdfail_msg_abs), %si +#else movw $(0x7C00 + err_cdfail_msg - start), %si +#endif fail: movb $0x0e, %ah
boot/i386/pc/diskboot.S +15 -6
@@ -28,7 +28,11 @@ #define ABS(x) (x-_start+GRUB_BOOT_MACHINE_KERNEL_ADDR) /* Print message string */ +#ifdef APPLE_CC +#define MSG(x) x ## _abs = ABS(x); mov $x ## _abs, %esi; call message +#else #define MSG(x) movw $ABS(x), %si; call message +#endif .file "diskboot.S"
@@ -61,7 +65,12 @@ _start: popw %si /* this sets up for the first run through "bootloop" */ +#ifdef APPLE_CC + firstlist_off_abs = ABS (firstlist - GRUB_BOOT_MACHINE_LIST_SIZE) + movl $firstlist_off_abs, %edi +#else movw $ABS(firstlist - GRUB_BOOT_MACHINE_LIST_SIZE), %di +#endif /* save the sector number of the second sector in %ebp */ movl (%di), %ebp
@@ -326,14 +335,14 @@ general_error: /* go here when you need to stop the machine hard after an error condition */ stop: jmp stop -notification_string: .string "loading" +notification_string: .asciz "loading" -notification_step: .string "." -notification_done: .string "\r\n" +notification_step: .asciz "." +notification_done: .asciz "\r\n" -geometry_error_string: .string "Geom" -read_error_string: .string "Read" -general_error_string: .string " Error" +geometry_error_string: .asciz "Geom" +read_error_string: .asciz "Read" +general_error_string: .asciz " Error" /* * message: write the string pointed to by %si
boot/i386/pc/lnxboot.S +77 -1
162 lines not on this page · raw message
boot/i386/pc/pxeboot.S +3 -1
@@ -23,7 +23,9 @@ .code16 /* Let's go */ -.globl _start; _start: +.globl start, _start; +_start: +start: /* Root drive will default to boot drive */ movb $0xFF, %dh
commands/i386/pc/drivemap_int13h.S +5 -0
@@ -30,7 +30,12 @@ FUNCTION(grub_drivemap_handler) /* Map the drive number (always in DL). */ push %ax push %bx +#ifdef APPLE_CC + grub_drivemap_mapstart_ofs = INT13H_OFFSET(EXT_C(grub_drivemap_mapstart)) + movw $grub_drivemap_mapstart_ofs, %bx +#else movw $INT13H_OFFSET(EXT_C(grub_drivemap_mapstart)), %bx +#endif more_remaining: movw %cs:(%bx), %ax
conf/common.rmk +10 -0
@@ -125,6 +125,16 @@ endif grub_pe2elf_SOURCES = util/grub-pe2elf.c util/misc.c CLEANFILES += grub-pe2elf +# grub_macho2img assumes a lot about source file. +# So installing it definitively is useless +# But adding to bin_UTILITIES is needed for +# genmk.rb to work +ifeq (0,1) +bin_UTILITIES += grub-macho2img +endif +grub_macho2img_SOURCES = util/grub-macho2img.c +CLEANFILES += grub-macho2img + # For grub-mkconfig grub-mkconfig: util/grub-mkconfig.in config.status ./config.status --file=$@:$<
conf/i386-pc.rmk +41 -13
102 lines not on this page · raw message
configure.ac +75 -32
191 lines not on this page · raw message
efiemu/runtime/efiemu.c +24 -18
95 lines not on this page · raw message
gencmdlist.sh +3 -1
@@ -17,4 +17,6 @@ module=$1 grep -v "^#" | sed -n \ -e "/grub_register_command *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $module/;p;}" \ - -e "/\(grub_register_extcmd\|grub_register_command_p1\) *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $module/;p;}" + -e "/grub_register_extcmd *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $module/;p;}" \ + -e "/grub_register_command_p1 *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $module/;p;}" +
genmk.rb +28 -0
@@ -56,8 +56,19 @@ class Image "CLEANFILES += #{@name} #{exe} #{objs_str} MOSTLYCLEANFILES += #{deps_str} +ifneq ($(TARGET_APPLE_CC),1) #{@name}: #{exe} $(OBJCOPY) -O $(#{prefix}_FORMAT) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id $< $@ +else +ifneq (#{exe},kernel.exec) +#{@name}: #{exe} ./grub-macho2img + ./grub-macho2img $< $@ +endif +ifeq (#{exe},kernel.exec) +#{@name}: #{exe} ./grub-macho2img + ./grub-macho2img --bss $< $@ +endif +endif #{exe}: #{objs_str} $(TARGET_CC) -o $@ $^ $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS)
@@ -112,11 +123,22 @@ endif MOSTLYCLEANFILES += #{deps_str} UNDSYMFILES += #{undsym} +ifneq ($(TARGET_APPLE_CC),1) #{@name}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF) -rm -f $@ $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ #{pre_obj} #{mod_obj} if test ! -z $(TARGET_OBJ2ELF); then ./$(TARGET_OBJ2ELF) $@ || (rm -f $@; exit 1); fi $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -K _grub_mod_init -K _grub_mod_fini -R .note -R .comment $@ +endif + +ifeq ($(TARGET_APPLE_CC),1) +#{@name}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF) + -rm -f $@ + -rm -f [email protected] + $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o [email protected] #{pre_obj} #{mod_obj} + $(OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -wd1106 -nu -nd [email protected] $@ + -rm -f [email protected] +endif #{pre_obj}: $(#{prefix}_DEPENDENCIES) #{objs_str} -rm -f $@
@@ -129,9 +151,15 @@ UNDSYMFILES += #{undsym} sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1) ifneq ($(#{prefix}_EXPORTS),no) +ifneq ($(TARGET_APPLE_CC),1) #{defsym}: #{pre_obj} $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@ endif +ifeq ($(TARGET_APPLE_CC),1) +#{defsym}: #{pre_obj} + $(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]' | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@ +endif +endif #{undsym}: #{pre_obj} echo '#{mod_name}' > $@
genmoddep.awk +1 -1
@@ -50,7 +50,7 @@ END { for (i in depmods) { depmod = depmods[i]; # Ignore kernel, as always loaded. - if (depmod != "kernel") + if (depmod != "kernel" && depmod != mod) uniqmods[depmod] = 1; } modlist = ""
include/grub/dl.h +8 -0
@@ -40,11 +40,19 @@ grub_##name##_fini (void) { grub_mod_fini (); } \static void \ grub_mod_fini (void) +#ifdef APPLE_CC +#define GRUB_MOD_NAME (name) \ +static char grub_modname[] __attribute__ ((section ("_modname, _modname"), used)) = #name; + +#define GRUB_MOD_DEP (name) \ +__asm__ (".section _moddeps, _moddeps\n.asciz \"" #name "\"\n") +#else #define GRUB_MOD_NAME (name) \ __asm__ (".section .modname\n.string \"" #name "\"\n")#define GRUB_MOD_DEP (name) \ __asm__ (".section .moddeps\n.string \"" #name "\"\n") +#endif struct grub_dl_segment {
include/grub/i386/pc/kernel.h +2 -0
@@ -74,8 +74,10 @@ extern grub_int32_t EXPORT_VAR(grub_boot_drive);/* The root BIOS drive number. */ extern grub_int32_t grub_root_drive; +#if 0 /* The end address of the kernel. */ extern grub_addr_t grub_end_addr; +#endif #endif /* ! ASM_FILE */
include/grub/i386/tsc.h +36 -2
@@ -29,8 +29,24 @@ grub_get_tsc (void)/* The CPUID instruction is a 'serializing' instruction, and avoids out-of-order execution of the RDTSC instruction. */ +#ifdef APPLE_CC __asm__ __volatile__ ("xorl %%eax, %%eax\n\t" -"cpuid" :::"%rax" ,"%rbx" ,"%rcx" ,"%rdx" ); +#ifdef __x86_64__ + "push %%rbx\n" +#else + "push %%ebx\n" +#endif + "cpuid\n" +#ifdef __x86_64__ + "pop %%rbx\n" +#else +"pop %%ebx\n" +#endif + :::"%rax" ,"%rcx" ,"%rdx" ); +#else + __asm__ __volatile__ ("xorl %%eax, %%eax\n\t" +"cpuid" :::"%rax" ,"%rbx" ,"%rcx" ,"%rdx" ); +#endif /* Read TSC value. We cannot use "=A", since this would use %rax on x86_64. */ __asm__ __volatile__ ("rdtsc" :"=a" (lo),"=d" (hi));
@@ -93,11 +109,29 @@ grub_cpu_is_tsc_supported (void)return 0 ;grub_uint32_t features; +#ifdef APPLE_CC __asm__ ("movl $1, %%eax\n\t" -"cpuid" +#ifdef __x86_64__ + "push %%rbx\n" +#else + "push %%ebx\n" +#endif + "cpuid\n" +#ifdef __x86_64__ + "pop %%rbx\n" +#else +"pop %%ebx\n" +#endif + :"=d" (features) + :/* No inputs. */ + :/* Clobbered: */ "%rax" ,"%rcx" ); +#else + __asm__ ("movl $1, %%eax\n\t" +"cpuid\n" :"=d" (features) :/* No inputs. */ :/* Clobbered: */ "%rax" ,"%rbx" ,"%rcx" ); +#endif return (features & (1 <<4 )) !=0 ; }
include/grub/list.h +11 -0
@@ -41,7 +41,18 @@ void EXPORT_FUNC(grub_list_insert) (grub_list_t *head, grub_list_t item,/* This function doesn't exist, so if assertion is false for some reason, the linker would fail. */ +#ifdef APPLE_CC +/* This approach fails with Apple's gcc. Use grub_abort. */ +#include <grub/misc.h> +static inline void * +grub_assert_fail (void ) +{ +grub_abort (); +return 0 ; +} +#else extern void *grub_assert_fail (void ); +#endif #define GRUB_FIELD_MATCH (ptr, type, field) \ ((char *) &(ptr)->field == (char *) &((type) (ptr))->field)
include/grub/misc.h +2 -0
@@ -40,8 +40,10 @@ char *EXPORT_FUNC(grub_strcat) (char *dest, const char *src);char *EXPORT_FUNC (grub_strncat ) (char *dest,const char *src,int c);/* Prototypes for aliases. */ +#if !defined (GRUB_UTIL ) || !defined (APPLE_CC )void *EXPORT_FUNC (memmove ) (void *dest,const void *src,grub_size_t n);void *EXPORT_FUNC (memcpy ) (void *dest,const void *src,grub_size_t n); +#endif int EXPORT_FUNC (grub_memcmp ) (const void *s1,const void *s2,grub_size_t n);int EXPORT_FUNC (grub_strcmp ) (const char *s1,const char *s2);
include/grub/symbol.h +4 -1
@@ -28,7 +28,10 @@# define EXT_C (sym) sym#endif -#if ! defined (__CYGWIN__) && ! defined (__MINGW32__) +#if defined (APPLE_CC ) +#define FUNCTION (x) .globl EXT_C(x) ; EXT_C(x): +#define VARIABLE (x) .globl EXT_C(x) ; EXT_C(x): +#elif ! defined (__CYGWIN__) && ! defined (__MINGW32__)#define FUNCTION (x) .globl EXT_C(x) ; .type EXT_C(x), "function" ; EXT_C(x):#define VARIABLE (x) .globl EXT_C(x) ; .type EXT_C(x), "object" ; EXT_C(x):#else
include/grub/term.h +1 -1
@@ -31,7 +31,7 @@#define GRUB_TERM_NPAGE 3#define GRUB_TERM_ESC '\e'#define GRUB_TERM_TAB '\t' -#define GRUB_TERM_BACKSPACE '\b' +#define GRUB_TERM_BACKSPACE 8#ifndef ASM_FILE
kern/efi/mm.c +4 -3
@@ -63,7 +63,8 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address,/* Limit the memory access to less than 4GB for 32-bit platforms. */ if (address >0xffffffff )return 0 ; - +#endif +#if GRUB_TARGET_SIZEOF_VOID_P <8 || defined (MCMODEL_SMALL )if (address ==0 ) { type =GRUB_EFI_ALLOCATE_MAX_ADDRESS ;
@@ -218,7 +219,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) {if (desc->type ==GRUB_EFI_CONVENTIONAL_MEMORY -#if GRUB_TARGET_SIZEOF_VOID_P < 8 +#if GRUB_TARGET_SIZEOF_VOID_P < 8 || defined (MCMODEL_SMALL) && desc->physical_start <=0xffffffff #endif && desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000
@@ -234,7 +235,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, desc->physical_start =0x100000 ; } -#if GRUB_TARGET_SIZEOF_VOID_P <8 +#if GRUB_TARGET_SIZEOF_VOID_P <8 || defined (MCMODEL_SMALL )if (BYTES_TO_PAGES (filtered_desc->physical_start) + filtered_desc->num_pages >BYTES_TO_PAGES (0x100000000LL ))
kern/i386/pc/startup.S +50 -2
117 lines not on this page · raw message
kern/misc.c +35 -1
@@ -44,11 +44,23 @@ grub_memmove (void *dest, const void *src, grub_size_t n)return dest; } + +#ifndef APPLE_CC void *memmove (void *dest,const void *src,grub_size_t n) __attribute__ ((alias ("grub_memmove" )));/* GCC emits references to memcpy() for struct copies etc. */ void *memcpy (void *dest,const void *src,grub_size_t n) __attribute__ ((alias ("grub_memmove" ))); +#else +void *memcpy (void *dest,const void *src,grub_size_t n) +{ +return grub_memmove (dest, src, n); +} +void *memmove (void *dest,const void *src,grub_size_t n) +{ +return grub_memmove (dest, src, n); +} +#endif char *grub_strcpy (char *dest,const char *src)
@@ -134,7 +146,22 @@ grub_printf (const char *fmt, ...)return ret; } -#ifndef GRUB_UTIL +#if defined (APPLE_CC ) && ! defined (GRUB_UTIL ) +int +grub_err_printf (const char *fmt, ...) +{ +va_list ap; +int ret; + +va_start (ap, fmt); + ret =grub_vprintf (fmt, ap); +va_end (ap); + +return ret; +} +#endif + +#if ! defined (APPLE_CC ) && ! defined (GRUB_UTIL )int grub_err_printf (const char *fmt, ...) __attribute__ ((alias ("grub_printf" )));#endif
@@ -185,8 +212,10 @@ grub_memcmp (const void *s1, const void *s2, grub_size_t n)return 0 ; } +#ifndef APPLE_CC int memcmp (const void *s1,const void *s2,grub_size_t n) __attribute__ ((alias ("grub_memcmp" ))); +#endif int grub_strcmp (const char *s1,const char *s2)
@@ -534,8 +563,10 @@ grub_memset (void *s, int c, grub_size_t n)return s; } +#ifndef APPLE_CC void *memset (void *s,int c,grub_size_t n) __attribute__ ((alias ("grub_memset" ))); +#endif grub_size_t grub_strlen (const char *s)
@@ -1066,8 +1097,11 @@ grub_abort (void)grub_exit (); } + +#ifndef APPLE_CC /* GCC emits references to abort(). */ void abort (void ) __attribute__ ((alias ("grub_abort" ))); +#endif #ifdef NEED_ENABLE_EXECUTE_STACK /* Some gcc versions generate a call to this function
loader/i386/xnu.c +41 -1
62 lines not on this page · raw message
loader/i386/xnu_helper.S +18 -0
@@ -94,11 +94,28 @@ VARIABLE(grub_xnu_heap_size) movsl mov %rax, %rsi +#ifdef APPLE_CC + add $(cont0-base), %eax +#else add $(cont0-base), %rax +#endif jmp *%rax cont0: +#ifdef APPLE_CC + lea (cont1-base)(%esi, 1), %eax + mov %eax, (jump_vector-base)(%esi,1) + + lea (gdt-base)(%esi, 1), %eax + mov %eax, (gdt_addr-base)(%esi,1) + + /* Switch to compatibility mode. */ + lgdt (gdtdesc-base)(%esi,1) + + /* Update %cs. Thanks to David Miller for pointing this mistake out. */ + ljmp *(jump_vector-base)(%esi,1) +#else lea (cont1-base)(%rsi, 1), %rax mov %eax, (jump_vector-base)(%rsi,1)
@@ -111,6 +128,7 @@ cont0: /* Update %cs. Thanks to David Miller for pointing this mistake out. */ ljmp *(jump_vector-base)(%rsi,1) +#endif cont1: .code32
mmap/i386/pc/mmap_helper.S +32 -0
@@ -28,7 +28,12 @@ VARIABLE(grub_machine_mmaphook_int12) push %ds push %cs pop %ds +#ifdef APPLE_CC + grub_machine_mmaphook_kblow_rel = DS (EXT_C (grub_machine_mmaphook_kblow)) + movw (grub_machine_mmaphook_kblow_rel), %ax +#else movw DS (EXT_C (grub_machine_mmaphook_kblow)), %ax +#endif pop %ds iret
@@ -53,8 +58,15 @@ e801: push %ds push %cs pop %ds +#ifdef APPLE_CC + grub_machine_mmaphook_kbin16mb_rel = DS (EXT_C (grub_machine_mmaphook_kbin16mb)) + grub_machine_mmaphook_64kbin4gb_rel = DS (EXT_C (grub_machine_mmaphook_64kbin4gb)) + movw (grub_machine_mmaphook_kbin16mb_rel), %ax + movw (grub_machine_mmaphook_64kbin4gb_rel), %bx +#else movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax movw DS (EXT_C (grub_machine_mmaphook_64kbin4gb)), %bx +#endif movw %ax, %cx movw %bx, %dx pop %ds
@@ -66,26 +78,42 @@ h88: push %ds push %cs pop %ds +#ifdef APPLE_CC + movw (grub_machine_mmaphook_kbin16mb_rel), %ax +#else movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax +#endif pop %ds clc iret e820: +#ifdef APPLE_CC + mmaphook_mmap_rel = DS(mmaphook_mmap) + mmaphook_mmap_num_rel = DS(EXT_C(grub_machine_mmaphook_mmap_num)) +#endif popf push %ds push %cs pop %ds cmpw $20, %cx jb errexit +#ifdef APPLE_CC + cmpw (mmaphook_mmap_num_rel), %bx +#else cmpw DS (EXT_C (grub_machine_mmaphook_mmap_num)), %bx +#endif jae errexit cmp $0x534d4150, %edx jne errexit push %si push %di movw $20, %cx +#ifdef APPLE_CC + movl $(mmaphook_mmap_rel), %esi +#else movw $(DS(mmaphook_mmap)), %si +#endif mov %bx, %ax imul $20, %ax add %ax, %si
@@ -94,7 +122,11 @@ e820: pop %si movl $20, %ecx inc %bx +#ifdef APPLE_CC + cmpw (mmaphook_mmap_num_rel), %bx +#else cmpw DS(EXT_C(grub_machine_mmaphook_mmap_num)), %bx +#endif jb noclean xor %bx, %bx noclean:
util/grub-macho2img.c new file +116 -0
116 lines not on this page · raw message
util/i386/efi/grub-mkimage.c +24 -8
@@ -88,7 +88,7 @@ align_pe32_section (Elf_Addr addr)/* Read the whole kernel image. Return the pointer to a read image, and store the size in bytes in *SIZE. */ static char * -read_kernel_module (const char *dir,char *prefix,size_t *size) +read_kernel_module (const char *dir,size_t *size) {char *kernel_image;char *kernel_path;
@@ -98,11 +98,6 @@ read_kernel_module (const char *dir, char *prefix, size_t *size) kernel_image =grub_util_read_image (kernel_path);free (kernel_path); -if (GRUB_KERNEL_MACHINE_PREFIX +strlen (prefix) +1 >GRUB_KERNEL_MACHINE_DATA_END ) -grub_util_error ("prefix too long" ); - -strcpy (kernel_image +sizeof (Elf_Ehdr) +GRUB_KERNEL_MACHINE_PREFIX , prefix); -return kernel_image; }
@@ -689,6 +684,8 @@ make_mods_section (FILE *out, Elf_Addr current_address,struct grub_module_info modinfo;Elf_Addr addr; +memset (&modinfo,0 ,sizeof (modinfo)); + path_list =grub_util_resolve_dependencies (dir,"moddep.lst" , mods); total_module_size =sizeof (struct grub_module_info );
@@ -712,7 +709,9 @@ make_mods_section (FILE *out, Elf_Addr current_address,struct grub_module_header header;size_t mod_size;char *mod_image; - + +memset (&header,0 ,sizeof (header)); +grub_util_info ("adding module %s" , p->name); mod_size =grub_util_get_image_size (p->name);
@@ -973,9 +972,11 @@ convert_elf (const char *dir, char *prefix, FILE *out, char *mods[])Elf_Addr start_address;Elf_Addr text_address, data_address, reloc_address, mods_address;Elf_Addr end_address; +Elf_Shdr *s; +int i;/* Get the kernel image and check the format. */ - kernel_image =read_kernel_module (dir, prefix, &kernel_size); + kernel_image =read_kernel_module (dir, &kernel_size); e = (Elf_Ehdr *) kernel_image;if (!check_elf_header (e, kernel_size))grub_util_error ("invalid ELF header" );
@@ -990,6 +991,21 @@ convert_elf (const char *dir, char *prefix, FILE *out, char *mods[]) sections = (Elf_Shdr *) (kernel_image + section_offset); strtab =find_strtab (e, sections, section_entsize); +for (i =0 , s = sections; + i < num_sections; + i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) +if (is_text_section (s)) + { +// const char *name = strtab + grub_le_to_cpu32 (s->sh_name); +Elf_Off offset =grub_le_to_cpu32 (s->sh_offset); + +if (GRUB_KERNEL_MACHINE_PREFIX +strlen (prefix) +1 >GRUB_KERNEL_MACHINE_DATA_END ) +grub_util_error ("prefix too long" ); + +strcpy (kernel_image + offset +GRUB_KERNEL_MACHINE_PREFIX , prefix); +break ; + } +/* Relocate sections then symbols in the virtual address space. */ section_addresses =locate_sections (sections, section_entsize, num_sections, strtab);
mac2elf.cpp +17 -0
@@ -480,6 +480,12 @@ } } else { + if (sym.st_shndx == 0) + { + // This is an external + sym.st_type = STT_NOTYPE; + } + else // This is a data definition record if (NewSectionHeaders[NewSectionIndex].sh_flags & SHF_EXECINSTR) { // Code section, assume this is a function
@@ -975,6 +981,17 @@ break; } } + if (relp->r_length == 2) { + NewRelocEntry.r_addend = *inlinep; + *inlinep = 0; + } + else if (relp->r_length == 3) { + NewRelocEntry.r_addend = *(int64*)inlinep; + *(int64*)inlinep = 0; + } + else { + err.submit(2044); // wrong size + } // Put relocation record into table NewSections[newsecr].Push(&NewRelocEntry, sizeof(NewRelocEntry)); }
main.cpp +2 -2
@@ -547,11 +547,11 @@ // Check sectionname options if (cmd.SegmentDot && cmd.OutputType != 0) { if (cmd.SegmentDot == CMDL_SECTIONDOT_CHANGE) { - if (FileType == FILETYPE_ELF && cmd.OutputType == FILETYPE_COFF) { + if (FileType == FILETYPE_ELF && (cmd.OutputType == FILETYPE_COFF || FileType == FILETYPE_MACHO_LE)) { // Change leading '.' to '_' in nonstandard section names cmd.SegmentDot = CMDL_SECTIONDOT_DOT2U; } - else if (FileType == FILETYPE_COFF && cmd.OutputType == FILETYPE_ELF ) { + else if ((FileType == FILETYPE_COFF || FileType == FILETYPE_MACHO_LE) && cmd.OutputType == FILETYPE_ELF ) { // Change leading '_' to '.' in nonstandard section names cmd.SegmentDot = CMDL_SECTIONDOT_U2DOT; }
Ident fixes.
Quoted 24 lines · Vladimir 'phcoder' Serbinenko
Update
Quoted 4 lines · Vladimir 'phcoder' Serbinenko
Hello. With this patch you can compile grub2 using Apple's gcc. Only partially tested. You need objconv available from
http://www.agner.org/optimize/ licensed under GPL and additionally patched with attached patchQuoted 9 lines
Then you need to patch grub2 with attached patch. If you compile for i386-pcbefore you begin you need to compile execute:
gcc -o macho2imgutil/macho2img.c-Iinclude
Then just compile grub2 normally. I will look how to automatise the compilation of macho2img
--
Regards
Vladimir 'phcoder' Serbinenko--
Regards
Vladimir 'phcoder' Serbinenko
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Makefile.in +6 -0
@@ -64,16 +64,22 @@ mkinstalldirs = $(srcdir)/mkinstalldirs CC = @CC@ CFLAGS = @CFLAGS@ +ASFLAGS = @ASFLAGS@ LDFLAGS = @LDFLAGS@ CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/include -Wall -W \ -DGRUB_LIBDIR=\"$(pkglibdir)\" TARGET_CC = @TARGET_CC@ TARGET_CFLAGS = @TARGET_CFLAGS@ +TARGET_ASFLAGS = @TARGET_ASFLAGS@ +TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@ +TARGET_APPLE_CC = @TARGET_APPLE_CC@ +OBJCONV = @OBJCONV@ TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/include \ -Wall -W TARGET_LDFLAGS = @TARGET_LDFLAGS@ TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@ TARGET_IMG_LDFLAGS = @TARGET_IMG_LDFLAGS@ +TARGET_IMG_CFLAGS = @TARGET_IMG_CFLAGS@ TARGET_OBJ2ELF = @TARGET_OBJ2ELF@ EXEEXT = @EXEEXT@ OBJCOPY = @OBJCOPY@
aclocal.m4 +30 -0
@@ -156,6 +156,36 @@ rm -f conftest*]) AC_MSG_RESULT([$grub_cv_i386_asm_addr32])]) +dnl check if our compiler is apple cc +dnl because it requires numerous workarounds +AC_DEFUN(grub_apple_cc, +[AC_REQUIRE([AC_PROG_CC]) +AC_MSG_CHECKING([whether our compiler is apple cc]) +AC_CACHE_VAL(grub_cv_apple_cc, +[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then + grub_cv_apple_cc=yes +else + grub_cv_apple_cc=no +fi +]) + +AC_MSG_RESULT([$grub_cv_apple_cc])]) + +dnl check if our target compiler is apple cc +dnl because it requires numerous workarounds +AC_DEFUN(grub_apple_target_cc, +[AC_REQUIRE([AC_PROG_CC]) +AC_MSG_CHECKING([whether our target compiler is apple cc]) +AC_CACHE_VAL(grub_cv_apple_target_cc, +[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then + grub_cv_apple_target_cc=yes +else + grub_cv_apple_target_cc=no +fi +]) + +AC_MSG_RESULT([$grub_cv_apple_target_cc])]) + dnl Later versions of GAS requires that addr32 and data32 prefixes dnl appear in the same lines as the instructions they modify, while
boot/i386/pc/boot.S +63 -8
159 lines not on this page · raw message
boot/i386/pc/cdboot.S +12 -0
@@ -67,8 +67,15 @@ bi_reserved: movw %ax, %ds movw %ax, %es +#ifdef APPLE_CC + err_noboot_msg_abs = 0x7C00 + err_noboot_msg - start + movw $err_noboot_msg_abs, %si + bi_length_dif = bi_length - next + movl %cs:bi_length_dif(%bx), %ecx +#else movw $(0x7C00 + err_noboot_msg - start), %si movl %cs: bi_length - next(%bx), %ecx +#endif orl %ecx, %ecx jz fail
@@ -152,7 +159,12 @@ read_cdrom: ret cdrom_fail: +#ifdef APPLE_CC + err_cdfail_msg_abs = 0x7C00 + err_cdfail_msg - start + movw $(err_cdfail_msg_abs), %si +#else movw $(0x7C00 + err_cdfail_msg - start), %si +#endif fail: movb $0x0e, %ah
boot/i386/pc/diskboot.S +15 -6
@@ -28,7 +28,11 @@ #define ABS(x) (x-_start+GRUB_BOOT_MACHINE_KERNEL_ADDR) /* Print message string */ +#ifdef APPLE_CC +#define MSG(x) x ## _abs = ABS(x); mov $x ## _abs, %esi; call message +#else #define MSG(x) movw $ABS(x), %si; call message +#endif .file "diskboot.S"
@@ -61,7 +65,12 @@ _start: popw %si /* this sets up for the first run through "bootloop" */ +#ifdef APPLE_CC + firstlist_off_abs = ABS (firstlist - GRUB_BOOT_MACHINE_LIST_SIZE) + movl $firstlist_off_abs, %edi +#else movw $ABS(firstlist - GRUB_BOOT_MACHINE_LIST_SIZE), %di +#endif /* save the sector number of the second sector in %ebp */ movl (%di), %ebp
@@ -326,14 +335,14 @@ general_error: /* go here when you need to stop the machine hard after an error condition */ stop: jmp stop -notification_string: .string "loading" +notification_string: .asciz "loading" -notification_step: .string "." -notification_done: .string "\r\n" +notification_step: .asciz "." +notification_done: .asciz "\r\n" -geometry_error_string: .string "Geom" -read_error_string: .string "Read" -general_error_string: .string " Error" +geometry_error_string: .asciz "Geom" +read_error_string: .asciz "Read" +general_error_string: .asciz " Error" /* * message: write the string pointed to by %si
boot/i386/pc/lnxboot.S +76 -0
160 lines not on this page · raw message
boot/i386/pc/pxeboot.S +3 -1
@@ -23,7 +23,9 @@ .code16 /* Let's go */ -.globl _start; _start: +.globl start, _start; +_start: +start: /* Root drive will default to boot drive */ movb $0xFF, %dh
commands/i386/pc/drivemap_int13h.S +5 -0
@@ -30,7 +30,12 @@ FUNCTION(grub_drivemap_handler) /* Map the drive number (always in DL). */ push %ax push %bx +#ifdef APPLE_CC + grub_drivemap_mapstart_ofs = INT13H_OFFSET(EXT_C(grub_drivemap_mapstart)) + movw $grub_drivemap_mapstart_ofs, %bx +#else movw $INT13H_OFFSET(EXT_C(grub_drivemap_mapstart)), %bx +#endif more_remaining: movw %cs:(%bx), %ax
conf/common.rmk +10 -0
@@ -125,6 +125,16 @@ endif grub_pe2elf_SOURCES = util/grub-pe2elf.c util/misc.c CLEANFILES += grub-pe2elf +# grub_macho2img assumes a lot about source file. +# So installing it definitively is useless +# But adding to bin_UTILITIES is needed for +# genmk.rb to work +ifeq (0,1) +bin_UTILITIES += grub-macho2img +endif +grub_macho2img_SOURCES = util/grub-macho2img.c +CLEANFILES += grub-macho2img + # For grub-mkconfig grub-mkconfig: util/grub-mkconfig.in config.status ./config.status --file=$@:$<
conf/i386-pc.rmk +45 -15
107 lines not on this page · raw message
configure.ac +75 -32
191 lines not on this page · raw message
efiemu/runtime/efiemu.c +28 -23
96 lines not on this page · raw message
gencmdlist.sh +3 -1
@@ -17,4 +17,6 @@ module=$1 grep -v "^#" | sed -n \ -e "/grub_register_command *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $module/;p;}" \ - -e "/\(grub_register_extcmd\|grub_register_command_p1\) *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $module/;p;}" + -e "/grub_register_extcmd *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $module/;p;}" \ + -e "/grub_register_command_p1 *( *\"/{s/.*( *\"\([^\"]*\)\".*/*\1: $module/;p;}" +
genmk.rb +24 -0
@@ -56,8 +56,18 @@ class Image "CLEANFILES += #{@name} #{exe} #{objs_str} MOSTLYCLEANFILES += #{deps_str} +ifneq ($(TARGET_APPLE_CC),1) #{@name}: #{exe} $(OBJCOPY) -O $(#{prefix}_FORMAT) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id $< $@ +else +ifneq (#{exe},kernel.exec) +#{@name}: #{exe} ./grub-macho2img + ./grub-macho2img $< $@ +else +#{@name}: #{exe} ./grub-macho2img + ./grub-macho2img --bss $< $@ +endif +endif #{exe}: #{objs_str} $(TARGET_CC) -o $@ $^ $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS)
@@ -112,11 +122,20 @@ endif MOSTLYCLEANFILES += #{deps_str} UNDSYMFILES += #{undsym} +ifneq ($(TARGET_APPLE_CC),1) #{@name}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF) -rm -f $@ $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ #{pre_obj} #{mod_obj} if test ! -z $(TARGET_OBJ2ELF); then ./$(TARGET_OBJ2ELF) $@ || (rm -f $@; exit 1); fi $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -K _grub_mod_init -K _grub_mod_fini -R .note -R .comment $@ +else +#{@name}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF) + -rm -f $@ + -rm -f [email protected] + $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o [email protected] #{pre_obj} #{mod_obj} + $(OBJCONV) -f$(TARGET_MODULE_FORMAT) -nr:_grub_mod_init:grub_mod_init -nr:_grub_mod_fini:grub_mod_fini -wd1106 -nu -nd [email protected] $@ + -rm -f [email protected] +endif #{pre_obj}: $(#{prefix}_DEPENDENCIES) #{objs_str} -rm -f $@
@@ -129,8 +148,13 @@ UNDSYMFILES += #{undsym} sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1) ifneq ($(#{prefix}_EXPORTS),no) +ifneq ($(TARGET_APPLE_CC),1) #{defsym}: #{pre_obj} $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@ +else +#{defsym}: #{pre_obj} + $(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]' | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@ +endif endif #{undsym}: #{pre_obj}
genmoddep.awk +1 -1
@@ -50,7 +50,7 @@ END { for (i in depmods) { depmod = depmods[i]; # Ignore kernel, as always loaded. - if (depmod != "kernel") + if (depmod != "kernel" && depmod != mod) uniqmods[depmod] = 1; } modlist = ""
include/grub/dl.h +8 -0
@@ -40,11 +40,19 @@ grub_##name##_fini (void) { grub_mod_fini (); } \static void \ grub_mod_fini (void) +#ifdef APPLE_CC +#define GRUB_MOD_NAME (name) \ +static char grub_modname[] __attribute__ ((section ("_modname, _modname"), used)) = #name; + +#define GRUB_MOD_DEP (name) \ +__asm__ (".section _moddeps, _moddeps\n.asciz \"" #name "\"\n") +#else #define GRUB_MOD_NAME (name) \ __asm__ (".section .modname\n.string \"" #name "\"\n")#define GRUB_MOD_DEP (name) \ __asm__ (".section .moddeps\n.string \"" #name "\"\n") +#endif struct grub_dl_segment {
include/grub/i386/pc/kernel.h +2 -0
@@ -74,8 +74,10 @@ extern grub_int32_t EXPORT_VAR(grub_boot_drive);/* The root BIOS drive number. */ extern grub_int32_t grub_root_drive; +#if 0 /* The end address of the kernel. */ extern grub_addr_t grub_end_addr; +#endif #endif /* ! ASM_FILE */
include/grub/i386/tsc.h +36 -2
@@ -29,8 +29,24 @@ grub_get_tsc (void)/* The CPUID instruction is a 'serializing' instruction, and avoids out-of-order execution of the RDTSC instruction. */ +#ifdef APPLE_CC __asm__ __volatile__ ("xorl %%eax, %%eax\n\t" -"cpuid" :::"%rax" ,"%rbx" ,"%rcx" ,"%rdx" ); +#ifdef __x86_64__ + "push %%rbx\n" +#else + "push %%ebx\n" +#endif + "cpuid\n" +#ifdef __x86_64__ + "pop %%rbx\n" +#else +"pop %%ebx\n" +#endif + :::"%rax" ,"%rcx" ,"%rdx" ); +#else + __asm__ __volatile__ ("xorl %%eax, %%eax\n\t" +"cpuid" :::"%rax" ,"%rbx" ,"%rcx" ,"%rdx" ); +#endif /* Read TSC value. We cannot use "=A", since this would use %rax on x86_64. */ __asm__ __volatile__ ("rdtsc" :"=a" (lo),"=d" (hi));
@@ -93,11 +109,29 @@ grub_cpu_is_tsc_supported (void)return 0 ;grub_uint32_t features; +#ifdef APPLE_CC __asm__ ("movl $1, %%eax\n\t" -"cpuid" +#ifdef __x86_64__ + "push %%rbx\n" +#else + "push %%ebx\n" +#endif + "cpuid\n" +#ifdef __x86_64__ + "pop %%rbx\n" +#else +"pop %%ebx\n" +#endif + :"=d" (features) + :/* No inputs. */ + :/* Clobbered: */ "%rax" ,"%rcx" ); +#else + __asm__ ("movl $1, %%eax\n\t" +"cpuid\n" :"=d" (features) :/* No inputs. */ :/* Clobbered: */ "%rax" ,"%rbx" ,"%rcx" ); +#endif return (features & (1 <<4 )) !=0 ; }
include/grub/list.h +11 -0
@@ -41,7 +41,18 @@ void EXPORT_FUNC(grub_list_insert) (grub_list_t *head, grub_list_t item,/* This function doesn't exist, so if assertion is false for some reason, the linker would fail. */ +#ifdef APPLE_CC +/* This approach fails with Apple's gcc. Use grub_abort. */ +#include <grub/misc.h> +static inline void * +grub_assert_fail (void ) +{ +grub_abort (); +return 0 ; +} +#else extern void *grub_assert_fail (void ); +#endif #define GRUB_FIELD_MATCH (ptr, type, field) \ ((char *) &(ptr)->field == (char *) &((type) (ptr))->field)
include/grub/misc.h +2 -0
@@ -40,8 +40,10 @@ char *EXPORT_FUNC(grub_strcat) (char *dest, const char *src);char *EXPORT_FUNC (grub_strncat ) (char *dest,const char *src,int c);/* Prototypes for aliases. */ +#if !defined (GRUB_UTIL ) || !defined (APPLE_CC )void *EXPORT_FUNC (memmove ) (void *dest,const void *src,grub_size_t n);void *EXPORT_FUNC (memcpy ) (void *dest,const void *src,grub_size_t n); +#endif int EXPORT_FUNC (grub_memcmp ) (const void *s1,const void *s2,grub_size_t n);int EXPORT_FUNC (grub_strcmp ) (const char *s1,const char *s2);
include/grub/symbol.h +4 -1
@@ -28,7 +28,10 @@# define EXT_C (sym) sym#endif -#if ! defined (__CYGWIN__) && ! defined (__MINGW32__) +#if defined (APPLE_CC ) +#define FUNCTION (x) .globl EXT_C(x) ; EXT_C(x): +#define VARIABLE (x) .globl EXT_C(x) ; EXT_C(x): +#elif ! defined (__CYGWIN__) && ! defined (__MINGW32__)#define FUNCTION (x) .globl EXT_C(x) ; .type EXT_C(x), "function" ; EXT_C(x):#define VARIABLE (x) .globl EXT_C(x) ; .type EXT_C(x), "object" ; EXT_C(x):#else
include/grub/term.h +1 -1
@@ -31,7 +31,7 @@#define GRUB_TERM_NPAGE 3#define GRUB_TERM_ESC '\e'#define GRUB_TERM_TAB '\t' -#define GRUB_TERM_BACKSPACE '\b' +#define GRUB_TERM_BACKSPACE 8#ifndef ASM_FILE
kern/efi/mm.c +4 -2
@@ -63,7 +63,9 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address,/* Limit the memory access to less than 4GB for 32-bit platforms. */ if (address >0xffffffff )return 0 ; +#endif +#if GRUB_TARGET_SIZEOF_VOID_P <8 || defined (MCMODEL_SMALL )if (address ==0 ) { type =GRUB_EFI_ALLOCATE_MAX_ADDRESS ;
@@ -218,7 +220,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) {if (desc->type ==GRUB_EFI_CONVENTIONAL_MEMORY -#if GRUB_TARGET_SIZEOF_VOID_P < 8 +#if GRUB_TARGET_SIZEOF_VOID_P < 8 || defined (MCMODEL_SMALL) && desc->physical_start <=0xffffffff #endif && desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000
@@ -234,7 +236,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, desc->physical_start =0x100000 ; } -#if GRUB_TARGET_SIZEOF_VOID_P <8 +#if GRUB_TARGET_SIZEOF_VOID_P <8 || defined (MCMODEL_SMALL )if (BYTES_TO_PAGES (filtered_desc->physical_start) + filtered_desc->num_pages >BYTES_TO_PAGES (0x100000000LL ))
kern/i386/pc/startup.S +48 -0
106 lines not on this page · raw message
kern/misc.c +35 -1
@@ -44,11 +44,23 @@ grub_memmove (void *dest, const void *src, grub_size_t n)return dest; } + +#ifndef APPLE_CC void *memmove (void *dest,const void *src,grub_size_t n) __attribute__ ((alias ("grub_memmove" )));/* GCC emits references to memcpy() for struct copies etc. */ void *memcpy (void *dest,const void *src,grub_size_t n) __attribute__ ((alias ("grub_memmove" ))); +#else +void *memcpy (void *dest,const void *src,grub_size_t n) +{ +return grub_memmove (dest, src, n); +} +void *memmove (void *dest,const void *src,grub_size_t n) +{ +return grub_memmove (dest, src, n); +} +#endif char *grub_strcpy (char *dest,const char *src)
@@ -134,7 +146,22 @@ grub_printf (const char *fmt, ...)return ret; } -#ifndef GRUB_UTIL +#if defined (APPLE_CC ) && ! defined (GRUB_UTIL ) +int +grub_err_printf (const char *fmt, ...) +{ +va_list ap; +int ret; + +va_start (ap, fmt); + ret =grub_vprintf (fmt, ap); +va_end (ap); + +return ret; +} +#endif + +#if ! defined (APPLE_CC ) && ! defined (GRUB_UTIL )int grub_err_printf (const char *fmt, ...) __attribute__ ((alias ("grub_printf" )));#endif
@@ -185,8 +212,10 @@ grub_memcmp (const void *s1, const void *s2, grub_size_t n)return 0 ; } +#ifndef APPLE_CC int memcmp (const void *s1,const void *s2,grub_size_t n) __attribute__ ((alias ("grub_memcmp" ))); +#endif int grub_strcmp (const char *s1,const char *s2)
@@ -534,8 +563,10 @@ grub_memset (void *s, int c, grub_size_t n)return s; } +#ifndef APPLE_CC void *memset (void *s,int c,grub_size_t n) __attribute__ ((alias ("grub_memset" ))); +#endif grub_size_t grub_strlen (const char *s)
@@ -1066,8 +1097,11 @@ grub_abort (void)grub_exit (); } + +#ifndef APPLE_CC /* GCC emits references to abort(). */ void abort (void ) __attribute__ ((alias ("grub_abort" ))); +#endif #ifdef NEED_ENABLE_EXECUTE_STACK /* Some gcc versions generate a call to this function
loader/i386/xnu.c +41 -1
62 lines not on this page · raw message
loader/i386/xnu_helper.S +18 -0
@@ -94,11 +94,28 @@ VARIABLE(grub_xnu_heap_size) movsl mov %rax, %rsi +#ifdef APPLE_CC + add $(cont0-base), %eax +#else add $(cont0-base), %rax +#endif jmp *%rax cont0: +#ifdef APPLE_CC + lea (cont1-base)(%esi, 1), %eax + mov %eax, (jump_vector-base)(%esi,1) + + lea (gdt-base)(%esi, 1), %eax + mov %eax, (gdt_addr-base)(%esi,1) + + /* Switch to compatibility mode. */ + lgdt (gdtdesc-base)(%esi,1) + + /* Update %cs. Thanks to David Miller for pointing this mistake out. */ + ljmp *(jump_vector-base)(%esi,1) +#else lea (cont1-base)(%rsi, 1), %rax mov %eax, (jump_vector-base)(%rsi,1)
@@ -111,6 +128,7 @@ cont0: /* Update %cs. Thanks to David Miller for pointing this mistake out. */ ljmp *(jump_vector-base)(%rsi,1) +#endif cont1: .code32
mmap/i386/pc/mmap_helper.S +32 -0
@@ -28,7 +28,12 @@ VARIABLE(grub_machine_mmaphook_int12) push %ds push %cs pop %ds +#ifdef APPLE_CC + grub_machine_mmaphook_kblow_rel = DS (EXT_C (grub_machine_mmaphook_kblow)) + movw (grub_machine_mmaphook_kblow_rel), %ax +#else movw DS (EXT_C (grub_machine_mmaphook_kblow)), %ax +#endif pop %ds iret
@@ -53,8 +58,15 @@ e801: push %ds push %cs pop %ds +#ifdef APPLE_CC + grub_machine_mmaphook_kbin16mb_rel = DS (EXT_C (grub_machine_mmaphook_kbin16mb)) + grub_machine_mmaphook_64kbin4gb_rel = DS (EXT_C (grub_machine_mmaphook_64kbin4gb)) + movw (grub_machine_mmaphook_kbin16mb_rel), %ax + movw (grub_machine_mmaphook_64kbin4gb_rel), %bx +#else movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax movw DS (EXT_C (grub_machine_mmaphook_64kbin4gb)), %bx +#endif movw %ax, %cx movw %bx, %dx pop %ds
@@ -66,26 +78,42 @@ h88: push %ds push %cs pop %ds +#ifdef APPLE_CC + movw (grub_machine_mmaphook_kbin16mb_rel), %ax +#else movw DS (EXT_C (grub_machine_mmaphook_kbin16mb)), %ax +#endif pop %ds clc iret e820: +#ifdef APPLE_CC + mmaphook_mmap_rel = DS(mmaphook_mmap) + mmaphook_mmap_num_rel = DS(EXT_C(grub_machine_mmaphook_mmap_num)) +#endif popf push %ds push %cs pop %ds cmpw $20, %cx jb errexit +#ifdef APPLE_CC + cmpw (mmaphook_mmap_num_rel), %bx +#else cmpw DS (EXT_C (grub_machine_mmaphook_mmap_num)), %bx +#endif jae errexit cmp $0x534d4150, %edx jne errexit push %si push %di movw $20, %cx +#ifdef APPLE_CC + movl $(mmaphook_mmap_rel), %esi +#else movw $(DS(mmaphook_mmap)), %si +#endif mov %bx, %ax imul $20, %ax add %ax, %si
@@ -94,7 +122,11 @@ e820: pop %si movl $20, %ecx inc %bx +#ifdef APPLE_CC + cmpw (mmaphook_mmap_num_rel), %bx +#else cmpw DS(EXT_C(grub_machine_mmaphook_mmap_num)), %bx +#endif jb noclean xor %bx, %bx noclean:
util/grub-macho2img.c new file +116 -0
116 lines not on this page · raw message
util/i386/efi/grub-mkimage.c +22 -7
@@ -88,7 +88,7 @@ align_pe32_section (Elf_Addr addr)/* Read the whole kernel image. Return the pointer to a read image, and store the size in bytes in *SIZE. */ static char * -read_kernel_module (const char *dir,char *prefix,size_t *size) +read_kernel_module (const char *dir,size_t *size) {char *kernel_image;char *kernel_path;
@@ -98,11 +98,6 @@ read_kernel_module (const char *dir, char *prefix, size_t *size) kernel_image =grub_util_read_image (kernel_path);free (kernel_path); -if (GRUB_KERNEL_MACHINE_PREFIX +strlen (prefix) +1 >GRUB_KERNEL_MACHINE_DATA_END ) -grub_util_error ("prefix too long" ); - -strcpy (kernel_image +sizeof (Elf_Ehdr) +GRUB_KERNEL_MACHINE_PREFIX , prefix); -return kernel_image; }
@@ -689,6 +684,8 @@ make_mods_section (FILE *out, Elf_Addr current_address,struct grub_module_info modinfo;Elf_Addr addr; +memset (&modinfo,0 ,sizeof (modinfo)); + path_list =grub_util_resolve_dependencies (dir,"moddep.lst" , mods); total_module_size =sizeof (struct grub_module_info );
@@ -713,6 +710,8 @@ make_mods_section (FILE *out, Elf_Addr current_address,size_t mod_size;char *mod_image; +memset (&header,0 ,sizeof (header)); +grub_util_info ("adding module %s" , p->name); mod_size =grub_util_get_image_size (p->name);
@@ -973,9 +972,11 @@ convert_elf (const char *dir, char *prefix, FILE *out, char *mods[])Elf_Addr start_address;Elf_Addr text_address, data_address, reloc_address, mods_address;Elf_Addr end_address; +Elf_Shdr *s; +int i;/* Get the kernel image and check the format. */ - kernel_image =read_kernel_module (dir, prefix, &kernel_size); + kernel_image =read_kernel_module (dir, &kernel_size); e = (Elf_Ehdr *) kernel_image;if (!check_elf_header (e, kernel_size))grub_util_error ("invalid ELF header" );
@@ -990,6 +991,20 @@ convert_elf (const char *dir, char *prefix, FILE *out, char *mods[]) sections = (Elf_Shdr *) (kernel_image + section_offset); strtab =find_strtab (e, sections, section_entsize); +for (i =0 , s = sections; + i < num_sections; + i++, s = (Elf_Shdr *) ((char *) s + section_entsize)) +if (is_text_section (s)) + { +Elf_Off offset =grub_le_to_cpu32 (s->sh_offset); + +if (GRUB_KERNEL_MACHINE_PREFIX +strlen (prefix) +1 >GRUB_KERNEL_MACHINE_DATA_END ) +grub_util_error ("prefix too long" ); + +strcpy (kernel_image + offset +GRUB_KERNEL_MACHINE_PREFIX , prefix); +break ; + } +/* Relocate sections then symbols in the virtual address space. */ section_addresses =locate_sections (sections, section_entsize, num_sections, strtab);
Patch on patch. Now it installs correctly and external module builds work too. For install script to work I had to simplify sed command. Does this new sed command poses any problems. Also agner (objconv author) accepted my patch but said that addend modification was incorrect. I've seen now that relocating behaviour differs between grub-mkimage and module loading. I made grub-mkimage to brehave the same way as grub2 module loading and this part of objconv patch isn't required anymore
Quoted 35 lines · Vladimir 'phcoder' Serbinenko
Ident fixes.
Quoted 20 lines · Vladimir 'phcoder' Serbinenko
Update
Quoted 4 lines · Vladimir 'phcoder' Serbinenko
Hello. With this patch you can compile grub2 using Apple's gcc. Only partially tested. You need objconv available from
http://www.agner.org/optimize/ licensed under GPL and additionally patched with attached patchQuoted 9 lines
Then you need to patch grub2 with attached patch. If you compile for i386-pcbefore you begin you need to compile execute:
gcc -o macho2imgutil/macho2img.c-Iinclude
Then just compile grub2 normally. I will look how to automatise the compilation of macho2img
--
Regards
Vladimir 'phcoder' SerbinenkoQuoted 4 lines
--
Regards
Vladimir 'phcoder' Serbinenko--
Regards
Vladimir 'phcoder' Serbinenko
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko