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