* [PATCH 7/18] Don't clobber ebx/rbx in inline assembly when compiling with Apple's CC
@ 2009-05-30 14:49 Vladimir 'phcoder' Serbinenko
2009-06-16 1:32 ` Pavel Roskin
0 siblings, 1 reply; 3+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-05-30 14:49 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 149 bytes --]
Unfortunately Apple's CC doesn't accept ebx to be clobbered. This
patch makes inline assembly restore ebx
--
Regards
Vladimir 'phcoder' Serbinenko
[-- Attachment #2: 07_bx.diff --]
[-- Type: text/x-patch, Size: 3497 bytes --]
diff --git a/efiemu/runtime/efiemu.c b/efiemu/runtime/efiemu.c
index 5887c48..f73f843 100644
--- a/efiemu/runtime/efiemu.c
+++ b/efiemu/runtime/efiemu.c
@@ -162,8 +162,8 @@ static inline void
write_cmos (grub_uint8_t addr, grub_uint8_t val)
{
__asm__ __volatile__ ("outb %%al,$0x70\n"
- "mov %%bl, %%al\n"
- "outb %%al,$0x71": :"a" (addr), "b" (val));
+ "mov %%cl, %%al\n"
+ "outb %%al,$0x71": :"a" (addr), "c" (val));
}
static inline grub_uint8_t
diff --git a/include/grub/i386/tsc.h b/include/grub/i386/tsc.h
index 9633701..aa40145 100644
--- a/include/grub/i386/tsc.h
+++ b/include/grub/i386/tsc.h
@@ -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;
}
diff --git a/loader/i386/xnu.c b/loader/i386/xnu.c
index 0860160..2fb490d 100644
--- a/loader/i386/xnu.c
+++ b/loader/i386/xnu.c
@@ -125,6 +125,28 @@ guessfsb (void)
if (! grub_cpu_is_cpuid_supported ())
return sane_value;
+
+#ifdef APPLE_CC
+ asm volatile ("movl $0, %%eax\n"
+#ifdef __x86_64__
+ "push %%rbx\n"
+#else
+ "push %%ebx\n"
+#endif
+ "cpuid\n"
+#ifdef __x86_64__
+ "pop %%rbx\n"
+#else
+ "pop %%ebx\n"
+#endif
+ : "=a" (max_cpuid),
+ "=d" (manufacturer[1]), "=c" (manufacturer[2]));
+
+ /* Only Intel for now is done. */
+ if (grub_memcmp (manufacturer+1, "ineIntel", 12) != 0)
+ return sane_value;
+
+#else
asm volatile ("movl $0, %%eax\n"
"cpuid"
: "=a" (max_cpuid), "=b" (manufacturer[0]),
@@ -133,15 +155,33 @@ guessfsb (void)
/* Only Intel for now is done. */
if (grub_memcmp (manufacturer, "GenuineIntel", 12) != 0)
return sane_value;
+#endif
/* Check Speedstep. */
if (max_cpuid < 1)
return sane_value;
+#ifdef APPLE_CC
+ asm volatile ("movl $1, %%eax\n"
+#ifdef __x86_64__
+ "push %%rbx\n"
+#else
+ "push %%ebx\n"
+#endif
+ "cpuid\n"
+#ifdef __x86_64__
+ "pop %%rbx\n"
+#else
+ "pop %%ebx\n"
+#endif
+ : "=c" (capabilities):
+ : "%rax", "%rdx");
+#else
asm volatile ("movl $1, %%eax\n"
"cpuid"
: "=c" (capabilities):
- : "%eax", "%ebx", "%edx");
+ : "%rax", "%rbx", "%rdx");
+#endif
if (! (capabilities & (1 << 7)))
return sane_value;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 7/18] Don't clobber ebx/rbx in inline assembly when compiling with Apple's CC
2009-05-30 14:49 [PATCH 7/18] Don't clobber ebx/rbx in inline assembly when compiling with Apple's CC Vladimir 'phcoder' Serbinenko
@ 2009-06-16 1:32 ` Pavel Roskin
2009-06-16 10:50 ` Vladimir 'phcoder' Serbinenko
0 siblings, 1 reply; 3+ messages in thread
From: Pavel Roskin @ 2009-06-16 1:32 UTC (permalink / raw)
To: The development of GRUB 2
On Sat, 2009-05-30 at 16:49 +0200, Vladimir 'phcoder' Serbinenko wrote:
> +#ifdef APPLE_CC
> __asm__ __volatile__ ("xorl %%eax, %%eax\n\t"
> - "cpuid":::"%rax", "%rbx", "%rcx", "%rdx");
Why do we need preprocessor conditionals here? What are we winning? I
think it's more important to have reusable, well tested and well
maintained code that to save two assembly instructions.
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 7/18] Don't clobber ebx/rbx in inline assembly when compiling with Apple's CC
2009-06-16 1:32 ` Pavel Roskin
@ 2009-06-16 10:50 ` Vladimir 'phcoder' Serbinenko
0 siblings, 0 replies; 3+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-06-16 10:50 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 827 bytes --]
On Tue, Jun 16, 2009 at 3:32 AM, Pavel Roskin <proski@gnu.org> wrote:
> On Sat, 2009-05-30 at 16:49 +0200, Vladimir 'phcoder' Serbinenko wrote:
> > +#ifdef APPLE_CC
> > __asm__ __volatile__ ("xorl %%eax, %%eax\n\t"
> > - "cpuid":::"%rax", "%rbx", "%rcx", "%rdx");
>
> Why do we need preprocessor conditionals here? What are we winning? I
> think it's more important to have reusable, well tested and well
> maintained code that to save two assembly instructions.
>
You're right. Just when doing this thing I was concerned to affect generic
code as less as possible
>
> --
> Regards,
> Pavel Roskin
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
--
Regards
Vladimir 'phcoder' Serbinenko
[-- Attachment #2: Type: text/html, Size: 1533 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-06-16 10:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-30 14:49 [PATCH 7/18] Don't clobber ebx/rbx in inline assembly when compiling with Apple's CC Vladimir 'phcoder' Serbinenko
2009-06-16 1:32 ` Pavel Roskin
2009-06-16 10:50 ` Vladimir 'phcoder' Serbinenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.