From e93cdc3db12f630eea47d0ffa163c012d1cb6cca Mon Sep 17 00:00:00 2001 From: phcoder Date: Thu, 4 Jun 2009 21:21:31 +0000 Subject: [PATCH] 2009-06-04 Vladimir Serbinenko Address in trampolines based on 32-bit registers when compiled with Apple's CC * loader/i386/xnu_helper.S [APPLE_CC]: use 32-bit registers for addresses * loader/i386/linux_trampoline.S [APPLE_CC]: likewise --- ChangeLog | 9 +++++++++ loader/i386/linux_trampoline.S | 17 +++++++++++++++++ loader/i386/xnu_helper.S | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/ChangeLog b/ChangeLog index 03b8f64c8..63ef8c2e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2009-06-04 Vladimir Serbinenko + + Address in trampolines based on 32-bit registers when compiled + with Apple's CC + + * loader/i386/xnu_helper.S [APPLE_CC]: use 32-bit registers + for addresses + * loader/i386/linux_trampoline.S [APPLE_CC]: likewise + 2009-06-04 Vladimir Serbinenko Avoid aliases when compiling with Apple's CC for PCBIOS machine diff --git a/loader/i386/linux_trampoline.S b/loader/i386/linux_trampoline.S index eddaaf28f..e2cd6ec27 100644 --- a/loader/i386/linux_trampoline.S +++ b/loader/i386/linux_trampoline.S @@ -30,7 +30,22 @@ VARIABLE(grub_linux_trampoline_start) call base base: pop %rsi + +#ifdef APPLE_CC + lea (cont1 - base) (%esi, 1), %rax + mov %eax, (jump_vector - base) (%esi, 1) + + lea (gdt - base) (%esi, 1), %rax + mov %rax, (gdtaddr - base) (%esi, 1) + /* Switch to compatibility mode. */ + + lidt (idtdesc - base) (%esi, 1) + 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) @@ -44,6 +59,8 @@ base: /* Update %cs. Thanks to David Miller for pointing this mistake out. */ ljmp *(jump_vector - base) (%rsi, 1) +#endif + cont1: .code32 diff --git a/loader/i386/xnu_helper.S b/loader/i386/xnu_helper.S index ad9c8f631..229c8fe43 100644 --- a/loader/i386/xnu_helper.S +++ b/loader/i386/xnu_helper.S @@ -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,8 @@ cont0: /* Update %cs. Thanks to David Miller for pointing this mistake out. */ ljmp *(jump_vector - base) (%rsi, 1) +#endif + cont1: .code32