diff mbox

[1/3] TCG: Mac OS X support for ppc64 target

Message ID 1260075477-76209-2-git-send-email-andreas.faerber@web.de
State New
Headers show

Commit Message

Andreas Färber Dec. 6, 2009, 4:57 a.m. UTC
Darwin/ppc64 does not use function descriptors,
adapt prologue and tcg_out_call accordingly.
GPR2 is available for general use, so let's use it.

http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/LowLevelABI/110-64-bit_PowerPC_Function_Calling_Conventions/64bitPowerPC.html

Signed-off-by: Andreas Faerber <andreas.faerber@web.de>
Cc: malc <av1474@comtv.ru>
---
 tcg/ppc64/tcg-target.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

Comments

malc Dec. 6, 2009, 5:13 a.m. UTC | #1
On Sun, 6 Dec 2009, Andreas Faerber wrote:

> Darwin/ppc64 does not use function descriptors,
> adapt prologue and tcg_out_call accordingly.
> GPR2 is available for general use, so let's use it.
> 
> http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/LowLevelABI/110-64-bit_PowerPC_Function_Calling_Conventions/64bitPowerPC.html
> 
> Signed-off-by: Andreas Faerber <andreas.faerber@web.de>
> Cc: malc <av1474@comtv.ru>
> ---
>  tcg/ppc64/tcg-target.c |   30 ++++++++++++++++++++++++++++++
>  1 files changed, 30 insertions(+), 0 deletions(-)
> 
> diff --git a/tcg/ppc64/tcg-target.c b/tcg/ppc64/tcg-target.c
> index a612e10..bf9b7d9 100644
> --- a/tcg/ppc64/tcg-target.c
> +++ b/tcg/ppc64/tcg-target.c
> @@ -104,6 +104,9 @@ static const int tcg_target_reg_alloc_order[] = {
>      TCG_REG_R29,
>      TCG_REG_R30,
>      TCG_REG_R31,
> +#ifdef __APPLE__
> +    TCG_REG_R2,
> +#endif
>      TCG_REG_R3,
>      TCG_REG_R4,
>      TCG_REG_R5,
> @@ -112,7 +115,9 @@ static const int tcg_target_reg_alloc_order[] = {
>      TCG_REG_R8,
>      TCG_REG_R9,
>      TCG_REG_R10,
> +#ifndef __APPLE__
>      TCG_REG_R11,
> +#endif
>      TCG_REG_R12,
>      TCG_REG_R24,
>      TCG_REG_R25,
> @@ -136,6 +141,10 @@ static const int tcg_target_call_oarg_regs[2] = {
>  };
>  
>  static const int tcg_target_callee_save_regs[] = {
> +#ifdef __APPLE__
> +    TCG_REG_R11,
> +    TCG_REG_R13,
> +#endif

No need to add R13, it's reserved anyhow.

>      TCG_REG_R14,
>      TCG_REG_R15,
>      TCG_REG_R16,
> @@ -477,8 +486,21 @@ static void tcg_out_movi (TCGContext *s, TCGType type,
>      }
>  }
>  
> +#ifdef __APPLE__
> +static void tcg_out_b (TCGContext *s, int mask, tcg_target_long target);
> +#endif
> +
>  static void tcg_out_call (TCGContext *s, tcg_target_long arg, int const_arg)
>  {
> +#ifdef __APPLE__
> +    if (const_arg) {
> +        tcg_out_b (s, LK, arg);
> +    }
> +    else {
> +        tcg_out32 (s, MTSPR | RS (arg) | LR);
> +        tcg_out32 (s, BCLR | BO_ALWAYS | LK);
> +    }
> +#else
>      int reg;
>  
>      if (const_arg) {
> @@ -492,6 +514,7 @@ static void tcg_out_call (TCGContext *s, tcg_target_long arg, int const_arg)
>      tcg_out32 (s, LD | RT (11) | RA (reg) | 16);
>      tcg_out32 (s, LD | RT (2) | RA (reg) | 8);
>      tcg_out32 (s, BCCTR | BO_ALWAYS | LK);
> +#endif
>  }
>  
>  static void tcg_out_ldst (TCGContext *s, int ret, int addr,
> @@ -859,10 +882,12 @@ void tcg_target_qemu_prologue (TCGContext *s)
>          ;
>      frame_size = (frame_size + 15) & ~15;
>  
> +#ifndef __APPLE__
>      /* First emit adhoc function descriptor */
>      addr = (uint64_t) s->code_ptr + 24;
>      tcg_out32 (s, addr >> 32); tcg_out32 (s, addr); /* entry point */
>      s->code_ptr += 16;          /* skip TOC and environment pointer */
> +#endif
>  
>      /* Prologue */
>      tcg_out32 (s, MFSPR | RT (0) | LR);

The frame format is different to that of PPC-elf64abi, shouldn't really
make a difference here, then again i don't have access to PPC64 Mac OSX,
so can't really verify that.

> @@ -1516,6 +1541,9 @@ void tcg_target_init (TCGContext *s)
>      tcg_regset_set32 (tcg_target_available_regs[TCG_TYPE_I64], 0, 0xffffffff);
>      tcg_regset_set32 (tcg_target_call_clobber_regs, 0,
>                       (1 << TCG_REG_R0) |
> +#ifdef __APPLE__
> +                     (1 << TCG_REG_R2) |
> +#endif
>                       (1 << TCG_REG_R3) |
>                       (1 << TCG_REG_R4) |
>                       (1 << TCG_REG_R5) |
> @@ -1531,7 +1559,9 @@ void tcg_target_init (TCGContext *s)
>      tcg_regset_clear (s->reserved_regs);
>      tcg_regset_set_reg (s->reserved_regs, TCG_REG_R0);
>      tcg_regset_set_reg (s->reserved_regs, TCG_REG_R1);
> +#ifndef __APPLE__
>      tcg_regset_set_reg (s->reserved_regs, TCG_REG_R2);
> +#endif
>      tcg_regset_set_reg (s->reserved_regs, TCG_REG_R13);
>  
>  #ifdef CONFIG_USE_GUEST_BASE
> 

Otherwise looks good.. Should i commit it with R13 fixed?
Andreas Färber Dec. 6, 2009, 5:25 a.m. UTC | #2
Am 06.12.2009 um 06:13 schrieb malc:

> On Sun, 6 Dec 2009, Andreas Faerber wrote:
>
>> Darwin/ppc64 does not use function descriptors,
>> adapt prologue and tcg_out_call accordingly.
>> GPR2 is available for general use, so let's use it.
>>
>> http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/LowLevelABI/110-64-bit_PowerPC_Function_Calling_Conventions/64bitPowerPC.html
>>
>> Signed-off-by: Andreas Faerber <andreas.faerber@web.de>
>> Cc: malc <av1474@comtv.ru>
>> ---
>> tcg/ppc64/tcg-target.c |   30 ++++++++++++++++++++++++++++++
>> 1 files changed, 30 insertions(+), 0 deletions(-)
>>
>> diff --git a/tcg/ppc64/tcg-target.c b/tcg/ppc64/tcg-target.c
>> index a612e10..bf9b7d9 100644
>> --- a/tcg/ppc64/tcg-target.c
>> +++ b/tcg/ppc64/tcg-target.c

>> @@ -859,10 +882,12 @@ void tcg_target_qemu_prologue (TCGContext *s)
>>         ;
>>     frame_size = (frame_size + 15) & ~15;
>>
>> +#ifndef __APPLE__
>>     /* First emit adhoc function descriptor */
>>     addr = (uint64_t) s->code_ptr + 24;
>>     tcg_out32 (s, addr >> 32); tcg_out32 (s, addr); /* entry point */
>>     s->code_ptr += 16;          /* skip TOC and environment pointer  
>> */
>> +#endif
>>
>>     /* Prologue */
>>     tcg_out32 (s, MFSPR | RT (0) | LR);
>
> The frame format is different to that of PPC-elf64abi, shouldn't  
> really
> make a difference here, then again i don't have access to PPC64 Mac  
> OSX,
> so can't really verify that.

I checked that the linkage area is 48, too, the LR offset is 16, too.
The parameter area was depicted as 64 < 128.
So I guess we're good there.

> Otherwise looks good.. Should i commit it with R13 fixed?

About the callee-save stuff I was less certain. Feel free to make  
modifications (e.g., moving tcg_out_call up?) or have me resubmit.

Thanks,
Andreas
malc Dec. 6, 2009, 6:28 a.m. UTC | #3
On Sun, 6 Dec 2009, Andreas F?rber wrote:

> 
> Am 06.12.2009 um 06:13 schrieb malc:
> 
> > On Sun, 6 Dec 2009, Andreas Faerber wrote:
> > 
> > > Darwin/ppc64 does not use function descriptors,
> > > adapt prologue and tcg_out_call accordingly.
> > > GPR2 is available for general use, so let's use it.
> > > 
> > > http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/LowLevelABI/110-64-bit_PowerPC_Function_Calling_Conventions/64bitPowerPC.html
> > > 
> > > Signed-off-by: Andreas Faerber <andreas.faerber@web.de>
> > > Cc: malc <av1474@comtv.ru>
> > > ---
> > > tcg/ppc64/tcg-target.c |   30 ++++++++++++++++++++++++++++++
> > > 1 files changed, 30 insertions(+), 0 deletions(-)
> > > 
> > > diff --git a/tcg/ppc64/tcg-target.c b/tcg/ppc64/tcg-target.c
> > > index a612e10..bf9b7d9 100644
> > > --- a/tcg/ppc64/tcg-target.c
> > > +++ b/tcg/ppc64/tcg-target.c
> 
> > > @@ -859,10 +882,12 @@ void tcg_target_qemu_prologue (TCGContext *s)
> > >        ;
> > >    frame_size = (frame_size + 15) & ~15;
> > > 
> > > +#ifndef __APPLE__
> > >    /* First emit adhoc function descriptor */
> > >    addr = (uint64_t) s->code_ptr + 24;
> > >    tcg_out32 (s, addr >> 32); tcg_out32 (s, addr); /* entry point */
> > >    s->code_ptr += 16;          /* skip TOC and environment pointer */
> > > +#endif
> > > 
> > >    /* Prologue */
> > >    tcg_out32 (s, MFSPR | RT (0) | LR);
> > 
> > The frame format is different to that of PPC-elf64abi, shouldn't really
> > make a difference here, then again i don't have access to PPC64 Mac OSX,
> > so can't really verify that.
> 
> I checked that the linkage area is 48, too, the LR offset is 16, too.
> The parameter area was depicted as 64 < 128.
> So I guess we're good there.
> 
> > Otherwise looks good.. Should i commit it with R13 fixed?
> 
> About the callee-save stuff I was less certain. Feel free to make
> modifications (e.g., moving tcg_out_call up?) or have me resubmit.

Sorry, i don't get this part, i was just thinking of removing R13 from
the list. Moving tcg_out_call?
Andreas Färber Dec. 6, 2009, 1:08 p.m. UTC | #4
Am 06.12.2009 um 07:28 schrieb malc:

> On Sun, 6 Dec 2009, Andreas F?rber wrote:
>
>>
>> Am 06.12.2009 um 06:13 schrieb malc:
>>
>>> On Sun, 6 Dec 2009, Andreas Faerber wrote:
>>>
>>>> Darwin/ppc64 does not use function descriptors,
>>>> adapt prologue and tcg_out_call accordingly.
>>>> GPR2 is available for general use, so let's use it.
>>>>
>>>> http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/LowLevelABI/110-64-bit_PowerPC_Function_Calling_Conventions/64bitPowerPC.html
>>>>
>>>> Signed-off-by: Andreas Faerber <andreas.faerber@web.de>
>>>> Cc: malc <av1474@comtv.ru>
>>>> ---
>>>> tcg/ppc64/tcg-target.c |   30 ++++++++++++++++++++++++++++++
>>>> 1 files changed, 30 insertions(+), 0 deletions(-)
>>>>
>>>> diff --git a/tcg/ppc64/tcg-target.c b/tcg/ppc64/tcg-target.c
>>>> index a612e10..bf9b7d9 100644
>>>> --- a/tcg/ppc64/tcg-target.c
>>>> +++ b/tcg/ppc64/tcg-target.c

>>> Otherwise looks good.. Should i commit it with R13 fixed?
>>
>> About the callee-save stuff I was less certain. Feel free to make
>> modifications (e.g., moving tcg_out_call up?) or have me resubmit.
>
> Sorry, i don't get this part, i was just thinking of removing R13 from
> the list. Moving tcg_out_call?

Sorry, I meant tcg_out_b. Just declaring it was the least intrusive  
patch.

I've sent a v2 series, doing the above plus silencing a warning.
They are also available for pulling from git://repo.or.cz/qemu/ 
afaerber.git, branch tcg-osx-ppc64.

Andreas
diff mbox

Patch

diff --git a/tcg/ppc64/tcg-target.c b/tcg/ppc64/tcg-target.c
index a612e10..bf9b7d9 100644
--- a/tcg/ppc64/tcg-target.c
+++ b/tcg/ppc64/tcg-target.c
@@ -104,6 +104,9 @@  static const int tcg_target_reg_alloc_order[] = {
     TCG_REG_R29,
     TCG_REG_R30,
     TCG_REG_R31,
+#ifdef __APPLE__
+    TCG_REG_R2,
+#endif
     TCG_REG_R3,
     TCG_REG_R4,
     TCG_REG_R5,
@@ -112,7 +115,9 @@  static const int tcg_target_reg_alloc_order[] = {
     TCG_REG_R8,
     TCG_REG_R9,
     TCG_REG_R10,
+#ifndef __APPLE__
     TCG_REG_R11,
+#endif
     TCG_REG_R12,
     TCG_REG_R24,
     TCG_REG_R25,
@@ -136,6 +141,10 @@  static const int tcg_target_call_oarg_regs[2] = {
 };
 
 static const int tcg_target_callee_save_regs[] = {
+#ifdef __APPLE__
+    TCG_REG_R11,
+    TCG_REG_R13,
+#endif
     TCG_REG_R14,
     TCG_REG_R15,
     TCG_REG_R16,
@@ -477,8 +486,21 @@  static void tcg_out_movi (TCGContext *s, TCGType type,
     }
 }
 
+#ifdef __APPLE__
+static void tcg_out_b (TCGContext *s, int mask, tcg_target_long target);
+#endif
+
 static void tcg_out_call (TCGContext *s, tcg_target_long arg, int const_arg)
 {
+#ifdef __APPLE__
+    if (const_arg) {
+        tcg_out_b (s, LK, arg);
+    }
+    else {
+        tcg_out32 (s, MTSPR | RS (arg) | LR);
+        tcg_out32 (s, BCLR | BO_ALWAYS | LK);
+    }
+#else
     int reg;
 
     if (const_arg) {
@@ -492,6 +514,7 @@  static void tcg_out_call (TCGContext *s, tcg_target_long arg, int const_arg)
     tcg_out32 (s, LD | RT (11) | RA (reg) | 16);
     tcg_out32 (s, LD | RT (2) | RA (reg) | 8);
     tcg_out32 (s, BCCTR | BO_ALWAYS | LK);
+#endif
 }
 
 static void tcg_out_ldst (TCGContext *s, int ret, int addr,
@@ -859,10 +882,12 @@  void tcg_target_qemu_prologue (TCGContext *s)
         ;
     frame_size = (frame_size + 15) & ~15;
 
+#ifndef __APPLE__
     /* First emit adhoc function descriptor */
     addr = (uint64_t) s->code_ptr + 24;
     tcg_out32 (s, addr >> 32); tcg_out32 (s, addr); /* entry point */
     s->code_ptr += 16;          /* skip TOC and environment pointer */
+#endif
 
     /* Prologue */
     tcg_out32 (s, MFSPR | RT (0) | LR);
@@ -1516,6 +1541,9 @@  void tcg_target_init (TCGContext *s)
     tcg_regset_set32 (tcg_target_available_regs[TCG_TYPE_I64], 0, 0xffffffff);
     tcg_regset_set32 (tcg_target_call_clobber_regs, 0,
                      (1 << TCG_REG_R0) |
+#ifdef __APPLE__
+                     (1 << TCG_REG_R2) |
+#endif
                      (1 << TCG_REG_R3) |
                      (1 << TCG_REG_R4) |
                      (1 << TCG_REG_R5) |
@@ -1531,7 +1559,9 @@  void tcg_target_init (TCGContext *s)
     tcg_regset_clear (s->reserved_regs);
     tcg_regset_set_reg (s->reserved_regs, TCG_REG_R0);
     tcg_regset_set_reg (s->reserved_regs, TCG_REG_R1);
+#ifndef __APPLE__
     tcg_regset_set_reg (s->reserved_regs, TCG_REG_R2);
+#endif
     tcg_regset_set_reg (s->reserved_regs, TCG_REG_R13);
 
 #ifdef CONFIG_USE_GUEST_BASE