mozilla-xpcom-ppc64le.patch
changeset 710 5341dc98d26c
parent 709 7ce157f366c9
child 711 012a5adf5c74
equal deleted inserted replaced
709:7ce157f366c9 710:5341dc98d26c
     1 # HG changeset patch
       
     2 # Parent c5c0f80f1967fd1921e85b443ee87d097e4baf19
       
     3 # User Ulrich Weigand <uweigand@de.ibm.com>
       
     4 PPC64 LE support for XPCOM
       
     5 
       
     6 diff --git a/xpcom/reflect/xptcall/src/md/unix/moz.build b/xpcom/reflect/xptcall/src/md/unix/moz.build
       
     7 --- a/xpcom/reflect/xptcall/src/md/unix/moz.build
       
     8 +++ b/xpcom/reflect/xptcall/src/md/unix/moz.build
       
     9 @@ -228,16 +228,23 @@ if CONFIG['OS_TEST'] == 'powerpc64':
       
    10      if CONFIG['OS_ARCH'] in ('Linux', 'FreeBSD'):
       
    11            SOURCES += [
       
    12                'xptcinvoke_asm_ppc64_linux.s',
       
    13                'xptcinvoke_ppc64_linux.cpp',
       
    14                'xptcstubs_asm_ppc64_linux.s',
       
    15                'xptcstubs_ppc64_linux.cpp',
       
    16            ]
       
    17  
       
    18 +if CONFIG['OS_TEST'] == 'powerpc64le':
       
    19 +    if CONFIG['OS_ARCH'] == 'Linux':
       
    20 +          CPP_SOURCES += [
       
    21 +              'xptcinvoke_ppc64_linux.cpp',
       
    22 +              'xptcstubs_ppc64_linux.cpp',
       
    23 +          ]
       
    24 +
       
    25  if CONFIG['OS_TEST'] in ('macppc', 'bebox', 'ofppc', 'prep', 'amigappc'):
       
    26      if CONFIG['OS_ARCH'] == 'NetBSD':
       
    27          SOURCES += [
       
    28              'xptcinvoke_asm_ppc_netbsd.s',
       
    29              'xptcinvoke_ppc_netbsd.cpp',
       
    30              'xptcstubs_asm_ppc_netbsd.s',
       
    31              'xptcstubs_ppc_netbsd.cpp',
       
    32          ]
       
    33 diff --git a/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_asm_ppc64_linux.s b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_asm_ppc64_linux.s
       
    34 --- a/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_asm_ppc64_linux.s
       
    35 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_asm_ppc64_linux.s
       
    36 @@ -12,33 +12,51 @@
       
    37  .set f0,0; .set f1,1; .set f2,2; .set f3,3; .set f4,4
       
    38  .set f5,5; .set f6,6; .set f7,7; .set f8,8; .set f9,9
       
    39  .set f10,10; .set f11,11; .set f12,12; .set f13,13; .set f14,14
       
    40  .set f15,15; .set f16,16; .set f17,17; .set f18,18; .set f19,19
       
    41  .set f20,20; .set f21,21; .set f22,22; .set f23,23; .set f24,24
       
    42  .set f25,25; .set f26,26; .set f27,27; .set f28,28; .set f29,29
       
    43  .set f30,30; .set f31,31
       
    44  
       
    45 +#if _CALL_ELF == 2
       
    46 +#define STACK_TOC      28
       
    47 +#define STACK_PARAMS   96
       
    48 +#else
       
    49 +#define STACK_TOC      40
       
    50 +#define STACK_PARAMS   112
       
    51 +#endif
       
    52  
       
    53  #
       
    54  # NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex,
       
    55  #                    uint32_t paramCount, nsXPTCVariant* params)
       
    56  #
       
    57  
       
    58 +#if _CALL_ELF == 2
       
    59 +        .section ".text"
       
    60 +        .type   NS_InvokeByIndex,@function
       
    61 +        .globl  NS_InvokeByIndex
       
    62 +        .align 2
       
    63 +NS_InvokeByIndex:
       
    64 +0:      addis 2,12,(.TOC.-0b)@ha
       
    65 +        addi 2,2,(.TOC.-0b)@l
       
    66 +        .localentry NS_InvokeByIndex,.-NS_InvokeByIndex
       
    67 +#else
       
    68          .section ".toc","aw"
       
    69          .section ".text"
       
    70          .align 2
       
    71          .globl  NS_InvokeByIndex
       
    72          .section ".opd","aw"
       
    73          .align 3
       
    74  NS_InvokeByIndex:
       
    75          .quad   .NS_InvokeByIndex,.TOC.@tocbase
       
    76          .previous
       
    77          .type   NS_InvokeByIndex,@function
       
    78  .NS_InvokeByIndex:
       
    79 +#endif
       
    80          mflr    0
       
    81          std     0,16(r1)
       
    82  
       
    83          std     r29,-24(r1)
       
    84          std     r30,-16(r1)
       
    85          std     r31,-8(r1)
       
    86  
       
    87          mr      r29,r3                  # Save 'that' in r29
       
    88 @@ -51,51 +69,55 @@ NS_InvokeByIndex:
       
    89          # that the stack remains 16-byte aligned.
       
    90          #
       
    91          #  | ..128-byte stack frame.. |     | 7 GP | 13 FP | 3 NV |
       
    92          #  |               |(params)........| regs | regs  | regs |
       
    93          # (r1)...........(+112)....(+128)
       
    94          #                               (-23*8).(-16*8).(-3*8)..(r31)
       
    95  
       
    96          # +stack frame, -unused stack params, +regs storage, +1 for alignment
       
    97 -        addi    r7,r5,((112/8)-7+7+13+3+1)
       
    98 +        addi    r7,r5,((STACK_PARAMS/8)-7+7+13+3+1)
       
    99          rldicr  r7,r7,3,59              # multiply by 8 and mask with ~15
       
   100          neg     r7,r7
       
   101          stdux   r1,r1,r7
       
   102  
       
   103  
       
   104          # Call invoke_copy_to_stack(uint64_t* gpregs, double* fpregs,
       
   105          #                           uint32_t paramCount, nsXPTCVariant* s, 
       
   106          #                           uint64_t* d))
       
   107  
       
   108          # r5, r6 are passed through intact (paramCount, params)
       
   109          # r7 (d) has to be r1+112 -- where parameters are passed on the stack.
       
   110          # r3, r4 are above that, easier to address from r31 than from r1
       
   111  
       
   112          subi    r3,r31,(23*8)           # r3 --> GPRS
       
   113          subi    r4,r31,(16*8)           # r4 --> FPRS
       
   114 -        addi    r7,r1,112               # r7 --> params
       
   115 +        addi    r7,r1,STACK_PARAMS      # r7 --> params
       
   116          bl      invoke_copy_to_stack
       
   117          nop
       
   118  
       
   119          # Set up to invoke function
       
   120  
       
   121          ld      r9,0(r29)               # vtable (r29 is 'that')
       
   122          mr      r3,r29                  # self is first arg, obviously
       
   123  
       
   124          sldi    r30,r30,3               # Find function descriptor 
       
   125          add     r9,r9,r30
       
   126 -        ld      r9,0(r9)
       
   127 +        ld      r12,0(r9)
       
   128  
       
   129 -        ld      r0,0(r9)                # Actual address from fd.
       
   130 -        std     r2,40(r1)               # Save r2 (TOC pointer)
       
   131 +        std     r2,STACK_TOC(r1)        # Save r2 (TOC pointer)
       
   132  
       
   133 +#if _CALL_ELF == 2
       
   134 +        mtctr   r12
       
   135 +#else
       
   136 +        ld      r0,0(r12)               # Actual address from fd.
       
   137          mtctr   0
       
   138 -        ld      r11,16(r9)              # Environment pointer from fd.
       
   139 -        ld      r2,8(r9)                # TOC pointer from fd.
       
   140 +        ld      r11,16(r12)             # Environment pointer from fd.
       
   141 +        ld      r2,8(r12)               # TOC pointer from fd.
       
   142 +#endif
       
   143  
       
   144          # Load FP and GP registers as required
       
   145          ld      r4, -(23*8)(r31) 
       
   146          ld      r5, -(22*8)(r31) 
       
   147          ld      r6, -(21*8)(r31) 
       
   148          ld      r7, -(20*8)(r31) 
       
   149          ld      r8, -(19*8)(r31) 
       
   150          ld      r9, -(18*8)(r31) 
       
   151 @@ -112,21 +134,25 @@ NS_InvokeByIndex:
       
   152          lfd     f9, -(8*8)(r31)
       
   153          lfd     f10, -(7*8)(r31)
       
   154          lfd     f11, -(6*8)(r31)
       
   155          lfd     f12, -(5*8)(r31)
       
   156          lfd     f13, -(4*8)(r31)
       
   157  
       
   158          bctrl                           # Do it
       
   159  
       
   160 -        ld      r2,40(r1)               # Load our own TOC pointer
       
   161 +        ld      r2,STACK_TOC(r1)        # Load our own TOC pointer
       
   162          ld      r1,0(r1)                # Revert stack frame
       
   163          ld      0,16(r1)                # Reload lr
       
   164          ld      29,-24(r1)              # Restore NVGPRS
       
   165          ld      30,-16(r1)
       
   166          ld      31,-8(r1)
       
   167          mtlr    0
       
   168          blr
       
   169  
       
   170 +#if _CALL_ELF == 2
       
   171 +        .size   NS_InvokeByIndex,.-NS_InvokeByIndex
       
   172 +#else
       
   173          .size   NS_InvokeByIndex,.-.NS_InvokeByIndex
       
   174 +#endif
       
   175  
       
   176          # Magic indicating no need for an executable stack
       
   177          .section .note.GNU-stack, "", @progbits ; .previous
       
   178 diff --git a/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ppc64_linux.cpp b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ppc64_linux.cpp
       
   179 --- a/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ppc64_linux.cpp
       
   180 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ppc64_linux.cpp
       
   181 @@ -69,17 +69,19 @@ invoke_copy_to_stack(uint64_t* gpregs,
       
   182              else
       
   183                  *(double *)d = s->val.d;
       
   184          }
       
   185          else if (!s->IsPtrData() && s->type == nsXPTType::T_FLOAT) {
       
   186              if (i < FPR_COUNT) {
       
   187                  fpregs[i]   = s->val.f; // if passed in registers, floats are promoted to doubles
       
   188              } else {
       
   189                  float *p = (float *)d;
       
   190 +#ifndef __LITTLE_ENDIAN__
       
   191                  p++;
       
   192 +#endif
       
   193                  *p = s->val.f;
       
   194              }
       
   195          }
       
   196          else {
       
   197              if (i < GPR_COUNT)
       
   198                  gpregs[i] = tempu64;
       
   199              else
       
   200                  *d = tempu64;
       
   201 diff --git a/xpcom/reflect/xptcall/src/md/unix/xptcstubs_asm_ppc64_linux.s b/xpcom/reflect/xptcall/src/md/unix/xptcstubs_asm_ppc64_linux.s
       
   202 --- a/xpcom/reflect/xptcall/src/md/unix/xptcstubs_asm_ppc64_linux.s
       
   203 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcstubs_asm_ppc64_linux.s
       
   204 @@ -12,28 +12,50 @@
       
   205  .set f0,0; .set f1,1; .set f2,2; .set f3,3; .set f4,4
       
   206  .set f5,5; .set f6,6; .set f7,7; .set f8,8; .set f9,9
       
   207  .set f10,10; .set f11,11; .set f12,12; .set f13,13; .set f14,14
       
   208  .set f15,15; .set f16,16; .set f17,17; .set f18,18; .set f19,19
       
   209  .set f20,20; .set f21,21; .set f22,22; .set f23,23; .set f24,24
       
   210  .set f25,25; .set f26,26; .set f27,27; .set f28,28; .set f29,29
       
   211  .set f30,30; .set f31,31
       
   212  
       
   213 +#if _CALL_ELF == 2
       
   214 +#define STACK_PARAMS   96
       
   215 +#else
       
   216 +#define STACK_PARAMS   112
       
   217 +#endif
       
   218 +
       
   219 +#if _CALL_ELF == 2
       
   220 +        .section ".text"
       
   221 +        .type   SharedStub,@function
       
   222 +        .globl  SharedStub
       
   223 +        # Make the symbol hidden so that the branch from the stub does
       
   224 +        # not go via a PLT.  This is not only better for performance,
       
   225 +        # but may be necessary to avoid linker errors since there is
       
   226 +        # no place to restore the TOC register in a sibling call.
       
   227 +        .hidden SharedStub
       
   228 +        .align 2
       
   229 +SharedStub:
       
   230 +0:      addis 2,12,(.TOC.-0b)@ha
       
   231 +        addi 2,2,(.TOC.-0b)@l
       
   232 +        .localentry SharedStub,.-SharedStub
       
   233 +#else
       
   234          .section ".text"
       
   235          .align 2
       
   236          .globl SharedStub
       
   237          .section ".opd","aw"
       
   238          .align 3
       
   239  
       
   240  SharedStub:
       
   241          .quad   .SharedStub,.TOC.@tocbase
       
   242          .previous
       
   243          .type   SharedStub,@function
       
   244  
       
   245  .SharedStub:
       
   246 +#endif
       
   247          mflr    r0
       
   248  
       
   249          std     r4, -56(r1)                     # Save all GPRS
       
   250          std     r5, -48(r1)
       
   251          std     r6, -40(r1)
       
   252          std     r7, -32(r1)
       
   253          std     r8, -24(r1)
       
   254          std     r9, -16(r1)
       
   255 @@ -50,17 +72,17 @@ SharedStub:
       
   256          stfd    f5, -128(r1)
       
   257          stfd    f4, -136(r1)
       
   258          stfd    f3, -144(r1)
       
   259          stfd    f2, -152(r1)
       
   260          stfd    f1, -160(r1)
       
   261  
       
   262          subi    r6,r1,56                        # r6 --> gprData
       
   263          subi    r7,r1,160                       # r7 --> fprData
       
   264 -        addi    r5,r1,112                       # r5 --> extra stack args
       
   265 +        addi    r5,r1,STACK_PARAMS              # r5 --> extra stack args
       
   266  
       
   267          std     r0, 16(r1)
       
   268  	
       
   269          stdu    r1,-288(r1)
       
   270                                                  # r3 has the 'self' pointer
       
   271                                                  # already
       
   272  
       
   273          mr      r4,r11                          # r4 is methodIndex selector,
       
   274 @@ -70,12 +92,16 @@ SharedStub:
       
   275          bl      PrepareAndDispatch
       
   276          nop
       
   277  
       
   278          ld      1,0(r1)                         # restore stack
       
   279          ld      r0,16(r1)                       # restore LR
       
   280          mtlr    r0
       
   281          blr
       
   282  
       
   283 +#if _CALL_ELF == 2
       
   284 +        .size   SharedStub,.-SharedStub
       
   285 +#else
       
   286          .size   SharedStub,.-.SharedStub
       
   287 +#endif
       
   288  
       
   289          # Magic indicating no need for an executable stack
       
   290          .section .note.GNU-stack, "", @progbits ; .previous
       
   291 diff --git a/xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc64_linux.cpp b/xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc64_linux.cpp
       
   292 --- a/xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc64_linux.cpp
       
   293 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc64_linux.cpp
       
   294 @@ -78,17 +78,19 @@ PrepareAndDispatch(nsXPTCStubBase* self,
       
   295                  dp->val.d = fprData[i];
       
   296              else
       
   297                  dp->val.d = *(double*) ap;
       
   298          } else if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
       
   299              if (i < FPR_COUNT)
       
   300                  dp->val.f = (float) fprData[i]; // in registers floats are passed as doubles
       
   301              else {
       
   302                  float *p = (float *)ap;
       
   303 +#ifndef __LITTLE_ENDIAN__
       
   304                  p++;
       
   305 +#endif
       
   306                  dp->val.f = *p;
       
   307              }
       
   308          } else { /* integer type or pointer */
       
   309              if (i < GPR_COUNT)
       
   310                  tempu64 = gprData[i];
       
   311              else
       
   312                  tempu64 = *ap;
       
   313  
       
   314 @@ -148,16 +150,53 @@ PrepareAndDispatch(nsXPTCStubBase* self,
       
   315  // Create names would be like:
       
   316  // _ZN14nsXPTCStubBase5Stub1Ev
       
   317  // _ZN14nsXPTCStubBase6Stub12Ev
       
   318  // _ZN14nsXPTCStubBase7Stub123Ev
       
   319  // _ZN14nsXPTCStubBase8Stub1234Ev
       
   320  // etc.
       
   321  // Use assembler directives to get the names right...
       
   322  
       
   323 +#if _CALL_ELF == 2
       
   324 +# define STUB_ENTRY(n)                                                  \
       
   325 +__asm__ (                                                               \
       
   326 +        ".section \".text\" \n\t"                                       \
       
   327 +        ".align 2 \n\t"                                                 \
       
   328 +        ".if "#n" < 10 \n\t"                                            \
       
   329 +        ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t"                    \
       
   330 +        ".type  _ZN14nsXPTCStubBase5Stub"#n"Ev,@function \n\n"          \
       
   331 +"_ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t"                                  \
       
   332 +        "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
       
   333 +        "addi     2,2,.TOC.-0b@l \n\t"                                  \
       
   334 +        ".localentry _ZN14nsXPTCStubBase5Stub"#n"Ev,.-_ZN14nsXPTCStubBase5Stub"#n"Ev \n\t" \
       
   335 +                                                                        \
       
   336 +        ".elseif "#n" < 100 \n\t"                                       \
       
   337 +        ".globl _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t"                    \
       
   338 +        ".type  _ZN14nsXPTCStubBase6Stub"#n"Ev,@function \n\n"          \
       
   339 +"_ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t"                                  \
       
   340 +        "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
       
   341 +        "addi     2,2,.TOC.-0b@l \n\t"                                  \
       
   342 +        ".localentry _ZN14nsXPTCStubBase6Stub"#n"Ev,.-_ZN14nsXPTCStubBase6Stub"#n"Ev \n\t" \
       
   343 +                                                                        \
       
   344 +        ".elseif "#n" < 1000 \n\t"                                      \
       
   345 +        ".globl _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t"                    \
       
   346 +        ".type  _ZN14nsXPTCStubBase7Stub"#n"Ev,@function \n\n"          \
       
   347 +"_ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t"                                  \
       
   348 +        "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
       
   349 +        "addi     2,2,.TOC.-0b@l \n\t"                                  \
       
   350 +        ".localentry _ZN14nsXPTCStubBase7Stub"#n"Ev,.-_ZN14nsXPTCStubBase7Stub"#n"Ev \n\t" \
       
   351 +                                                                        \
       
   352 +        ".else  \n\t"                                                   \
       
   353 +        ".err   \"stub number "#n" >= 1000 not yet supported\"\n"       \
       
   354 +        ".endif \n\t"                                                   \
       
   355 +                                                                        \
       
   356 +        "li     11,"#n" \n\t"                                           \
       
   357 +        "b      SharedStub \n"                                          \
       
   358 +);
       
   359 +#else
       
   360  # define STUB_ENTRY(n)                                                  \
       
   361  __asm__ (                                                               \
       
   362          ".section \".toc\",\"aw\" \n\t"                                 \
       
   363          ".section \".text\" \n\t"                                       \
       
   364          ".align 2 \n\t"                                                 \
       
   365          ".if "#n" < 10 \n\t"                                            \
       
   366          ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t"                    \
       
   367          ".section \".opd\",\"aw\" \n\t"                                 \
       
   368 @@ -190,16 +229,17 @@ PrepareAndDispatch(nsXPTCStubBase* self,
       
   369                                                                          \
       
   370          ".else  \n\t"                                                   \
       
   371          ".err   \"stub number "#n" >= 1000 not yet supported\"\n"       \
       
   372          ".endif \n\t"                                                   \
       
   373                                                                          \
       
   374          "li     11,"#n" \n\t"                                           \
       
   375          "b      SharedStub \n"                                          \
       
   376  );
       
   377 +#endif
       
   378  
       
   379  #define SENTINEL_ENTRY(n)                                               \
       
   380  nsresult nsXPTCStubBase::Sentinel##n()                                  \
       
   381  {                                                                       \
       
   382      NS_ERROR("nsXPTCStubBase::Sentinel called");                  \
       
   383      return NS_ERROR_NOT_IMPLEMENTED;                                    \
       
   384  }
       
   385