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