mozilla-ppc64le-xpcom.patch
changeset 718 6cb1ac7cd223
parent 716 cef565f1c325
child 719 8d80a56bb0a8
equal deleted inserted replaced
716:cef565f1c325 718:6cb1ac7cd223
     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 Index: mozilla/xpcom/reflect/xptcall/src/md/unix/moz.build
       
     7 ===================================================================
       
     8 --- mozilla.orig/xpcom/reflect/xptcall/src/md/unix/moz.build
       
     9 +++ mozilla/xpcom/reflect/xptcall/src/md/unix/moz.build
       
    10 @@ -224,12 +224,12 @@ if CONFIG['OS_TEST'] == 'powerpc':
       
    11              'xptcstubs_ppc_linux.cpp',
       
    12          ]
       
    13  
       
    14 -if CONFIG['OS_TEST'] == 'powerpc64':
       
    15 +if CONFIG['OS_TEST'] in ('powerpc64', 'powerpc64le'):
       
    16      if CONFIG['OS_ARCH'] in ('Linux', 'FreeBSD'):
       
    17            SOURCES += [
       
    18 -              'xptcinvoke_asm_ppc64_linux.s',
       
    19 +              'xptcinvoke_asm_ppc64_linux.S',
       
    20                'xptcinvoke_ppc64_linux.cpp',
       
    21 -              'xptcstubs_asm_ppc64_linux.s',
       
    22 +              'xptcstubs_asm_ppc64_linux.S',
       
    23                'xptcstubs_ppc64_linux.cpp',
       
    24            ]
       
    25  
       
    26 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
       
    27 rename from xpcom/reflect/xptcall/src/md/unix/xptcinvoke_asm_ppc64_linux.s
       
    28 rename to xpcom/reflect/xptcall/src/md/unix/xptcinvoke_asm_ppc64_linux.S
       
    29 --- a/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_asm_ppc64_linux.s
       
    30 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_asm_ppc64_linux.S
       
    31 @@ -17,12 +17,38 @@
       
    32  .set f25,25; .set f26,26; .set f27,27; .set f28,28; .set f29,29
       
    33  .set f30,30; .set f31,31
       
    34  
       
    35 +# The ABI defines a fixed stack frame area of 4 doublewords (ELFv2)
       
    36 +# or 6 doublewords (ELFv1); the last of these doublewords is used
       
    37 +# as TOC pointer save area.  The fixed area is followed by a parameter
       
    38 +# save area of 8 doublewords (used for vararg routines), followed
       
    39 +# by space for parameters passed on the stack.
       
    40 +#
       
    41 +# We set STACK_TOC to the offset of the TOC pointer save area, and
       
    42 +# STACK_PARAMS to the offset of the first on-stack parameter.
       
    43 +
       
    44 +#if _CALL_ELF == 2
       
    45 +#define STACK_TOC      24
       
    46 +#define STACK_PARAMS   96
       
    47 +#else
       
    48 +#define STACK_TOC      40
       
    49 +#define STACK_PARAMS   112
       
    50 +#endif
       
    51  
       
    52  #
       
    53  # NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex,
       
    54  #                    uint32_t paramCount, nsXPTCVariant* params)
       
    55  #
       
    56  
       
    57 +#if _CALL_ELF == 2
       
    58 +        .section ".text"
       
    59 +        .type   NS_InvokeByIndex,@function
       
    60 +        .globl  NS_InvokeByIndex
       
    61 +        .align 2
       
    62 +NS_InvokeByIndex:
       
    63 +0:      addis 2,12,(.TOC.-0b)@ha
       
    64 +        addi 2,2,(.TOC.-0b)@l
       
    65 +        .localentry NS_InvokeByIndex,.-NS_InvokeByIndex
       
    66 +#else
       
    67          .section ".toc","aw"
       
    68          .section ".text"
       
    69          .align 2
       
    70 @@ -34,6 +60,7 @@ NS_InvokeByIndex:
       
    71          .previous
       
    72          .type   NS_InvokeByIndex,@function
       
    73  .NS_InvokeByIndex:
       
    74 +#endif
       
    75          mflr    0
       
    76          std     0,16(r1)
       
    77  
       
    78 @@ -50,13 +77,12 @@ NS_InvokeByIndex:
       
    79          # we don't actually need stack space for those. We must ensure
       
    80          # that the stack remains 16-byte aligned.
       
    81          #
       
    82 -        #  | ..128-byte stack frame.. |     | 7 GP | 13 FP | 3 NV |
       
    83 -        #  |               |(params)........| regs | regs  | regs |
       
    84 -        # (r1)...........(+112)....(+128)
       
    85 -        #                               (-23*8).(-16*8).(-3*8)..(r31)
       
    86 +        #  | (fixed area + |                | 7 GP | 13 FP | 3 NV |
       
    87 +        #  |  param. save) |(params)........| regs | regs  | regs |
       
    88 +        # (r1)......(+STACK_PARAMS)...  (-23*8).(-16*8).(-3*8)..(r31)
       
    89  
       
    90          # +stack frame, -unused stack params, +regs storage, +1 for alignment
       
    91 -        addi    r7,r5,((112/8)-7+7+13+3+1)
       
    92 +        addi    r7,r5,((STACK_PARAMS/8)-7+7+13+3+1)
       
    93          rldicr  r7,r7,3,59              # multiply by 8 and mask with ~15
       
    94          neg     r7,r7
       
    95          stdux   r1,r1,r7
       
    96 @@ -67,12 +93,13 @@ NS_InvokeByIndex:
       
    97          #                           uint64_t* d))
       
    98  
       
    99          # r5, r6 are passed through intact (paramCount, params)
       
   100 -        # r7 (d) has to be r1+112 -- where parameters are passed on the stack.
       
   101 +        # r7 (d) has to be r1+STACK_PARAMS
       
   102 +        #        -- where parameters are passed on the stack.
       
   103          # r3, r4 are above that, easier to address from r31 than from r1
       
   104  
       
   105          subi    r3,r31,(23*8)           # r3 --> GPRS
       
   106          subi    r4,r31,(16*8)           # r4 --> FPRS
       
   107 -        addi    r7,r1,112               # r7 --> params
       
   108 +        addi    r7,r1,STACK_PARAMS      # r7 --> params
       
   109          bl      invoke_copy_to_stack
       
   110          nop
       
   111  
       
   112 @@ -83,14 +110,18 @@ NS_InvokeByIndex:
       
   113  
       
   114          sldi    r30,r30,3               # Find function descriptor 
       
   115          add     r9,r9,r30
       
   116 -        ld      r9,0(r9)
       
   117 +        ld      r12,0(r9)
       
   118  
       
   119 -        ld      r0,0(r9)                # Actual address from fd.
       
   120 -        std     r2,40(r1)               # Save r2 (TOC pointer)
       
   121 +        std     r2,STACK_TOC(r1)        # Save r2 (TOC pointer)
       
   122  
       
   123 +#if _CALL_ELF == 2
       
   124 +        mtctr   r12
       
   125 +#else
       
   126 +        ld      r0,0(r12)               # Actual address from fd.
       
   127          mtctr   0
       
   128 -        ld      r11,16(r9)              # Environment pointer from fd.
       
   129 -        ld      r2,8(r9)                # TOC pointer from fd.
       
   130 +        ld      r11,16(r12)             # Environment pointer from fd.
       
   131 +        ld      r2,8(r12)               # TOC pointer from fd.
       
   132 +#endif
       
   133  
       
   134          # Load FP and GP registers as required
       
   135          ld      r4, -(23*8)(r31) 
       
   136 @@ -117,7 +148,7 @@ NS_InvokeByIndex:
       
   137  
       
   138          bctrl                           # Do it
       
   139  
       
   140 -        ld      r2,40(r1)               # Load our own TOC pointer
       
   141 +        ld      r2,STACK_TOC(r1)        # Load our own TOC pointer
       
   142          ld      r1,0(r1)                # Revert stack frame
       
   143          ld      0,16(r1)                # Reload lr
       
   144          ld      29,-24(r1)              # Restore NVGPRS
       
   145 @@ -126,7 +157,11 @@ NS_InvokeByIndex:
       
   146          mtlr    0
       
   147          blr
       
   148  
       
   149 +#if _CALL_ELF == 2
       
   150 +        .size   NS_InvokeByIndex,.-NS_InvokeByIndex
       
   151 +#else
       
   152          .size   NS_InvokeByIndex,.-.NS_InvokeByIndex
       
   153 +#endif
       
   154  
       
   155          # Magic indicating no need for an executable stack
       
   156          .section .note.GNU-stack, "", @progbits ; .previous
       
   157 Index: mozilla/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ppc64_linux.cpp
       
   158 ===================================================================
       
   159 --- mozilla.orig/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ppc64_linux.cpp
       
   160 +++ mozilla/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ppc64_linux.cpp
       
   161 @@ -74,7 +74,9 @@ invoke_copy_to_stack(uint64_t* gpregs,
       
   162                  fpregs[i]   = s->val.f; // if passed in registers, floats are promoted to doubles
       
   163              } else {
       
   164                  float *p = (float *)d;
       
   165 +#ifndef __LITTLE_ENDIAN__
       
   166                  p++;
       
   167 +#endif
       
   168                  *p = s->val.f;
       
   169              }
       
   170          }
       
   171 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
       
   172 rename from xpcom/reflect/xptcall/src/md/unix/xptcstubs_asm_ppc64_linux.s
       
   173 rename to xpcom/reflect/xptcall/src/md/unix/xptcstubs_asm_ppc64_linux.S
       
   174 --- a/xpcom/reflect/xptcall/src/md/unix/xptcstubs_asm_ppc64_linux.s
       
   175 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcstubs_asm_ppc64_linux.S
       
   176 @@ -17,6 +17,27 @@
       
   177  .set f25,25; .set f26,26; .set f27,27; .set f28,28; .set f29,29
       
   178  .set f30,30; .set f31,31
       
   179  
       
   180 +#if _CALL_ELF == 2
       
   181 +#define STACK_PARAMS   96
       
   182 +#else
       
   183 +#define STACK_PARAMS   112
       
   184 +#endif
       
   185 +
       
   186 +#if _CALL_ELF == 2
       
   187 +        .section ".text"
       
   188 +        .type   SharedStub,@function
       
   189 +        .globl  SharedStub
       
   190 +        # Make the symbol hidden so that the branch from the stub does
       
   191 +        # not go via a PLT.  This is not only better for performance,
       
   192 +        # but may be necessary to avoid linker errors since there is
       
   193 +        # no place to restore the TOC register in a sibling call.
       
   194 +        .hidden SharedStub
       
   195 +        .align 2
       
   196 +SharedStub:
       
   197 +0:      addis 2,12,(.TOC.-0b)@ha
       
   198 +        addi 2,2,(.TOC.-0b)@l
       
   199 +        .localentry SharedStub,.-SharedStub
       
   200 +#else
       
   201          .section ".text"
       
   202          .align 2
       
   203          .globl SharedStub
       
   204 @@ -29,6 +50,7 @@ SharedStub:
       
   205          .type   SharedStub,@function
       
   206  
       
   207  .SharedStub:
       
   208 +#endif
       
   209          mflr    r0
       
   210  
       
   211          std     r4, -56(r1)                     # Save all GPRS
       
   212 @@ -55,7 +77,7 @@ SharedStub:
       
   213  
       
   214          subi    r6,r1,56                        # r6 --> gprData
       
   215          subi    r7,r1,160                       # r7 --> fprData
       
   216 -        addi    r5,r1,112                       # r5 --> extra stack args
       
   217 +        addi    r5,r1,STACK_PARAMS              # r5 --> extra stack args
       
   218  
       
   219          std     r0, 16(r1)
       
   220  	
       
   221 @@ -75,7 +97,11 @@ SharedStub:
       
   222          mtlr    r0
       
   223          blr
       
   224  
       
   225 +#if _CALL_ELF == 2
       
   226 +        .size   SharedStub,.-SharedStub
       
   227 +#else
       
   228          .size   SharedStub,.-.SharedStub
       
   229 +#endif
       
   230  
       
   231          # Magic indicating no need for an executable stack
       
   232          .section .note.GNU-stack, "", @progbits ; .previous
       
   233 Index: mozilla/xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc64_linux.cpp
       
   234 ===================================================================
       
   235 --- mozilla.orig/xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc64_linux.cpp
       
   236 +++ mozilla/xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc64_linux.cpp
       
   237 @@ -83,7 +83,9 @@ PrepareAndDispatch(nsXPTCStubBase* self,
       
   238                  dp->val.f = (float) fprData[i]; // in registers floats are passed as doubles
       
   239              else {
       
   240                  float *p = (float *)ap;
       
   241 +#ifndef __LITTLE_ENDIAN__
       
   242                  p++;
       
   243 +#endif
       
   244                  dp->val.f = *p;
       
   245              }
       
   246          } else { /* integer type or pointer */
       
   247 @@ -153,6 +155,43 @@ PrepareAndDispatch(nsXPTCStubBase* self,
       
   248  // etc.
       
   249  // Use assembler directives to get the names right...
       
   250  
       
   251 +#if _CALL_ELF == 2
       
   252 +# define STUB_ENTRY(n)                                                  \
       
   253 +__asm__ (                                                               \
       
   254 +        ".section \".text\" \n\t"                                       \
       
   255 +        ".align 2 \n\t"                                                 \
       
   256 +        ".if "#n" < 10 \n\t"                                            \
       
   257 +        ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t"                    \
       
   258 +        ".type  _ZN14nsXPTCStubBase5Stub"#n"Ev,@function \n\n"          \
       
   259 +"_ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t"                                  \
       
   260 +        "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
       
   261 +        "addi     2,2,.TOC.-0b@l \n\t"                                  \
       
   262 +        ".localentry _ZN14nsXPTCStubBase5Stub"#n"Ev,.-_ZN14nsXPTCStubBase5Stub"#n"Ev \n\t" \
       
   263 +                                                                        \
       
   264 +        ".elseif "#n" < 100 \n\t"                                       \
       
   265 +        ".globl _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t"                    \
       
   266 +        ".type  _ZN14nsXPTCStubBase6Stub"#n"Ev,@function \n\n"          \
       
   267 +"_ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t"                                  \
       
   268 +        "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
       
   269 +        "addi     2,2,.TOC.-0b@l \n\t"                                  \
       
   270 +        ".localentry _ZN14nsXPTCStubBase6Stub"#n"Ev,.-_ZN14nsXPTCStubBase6Stub"#n"Ev \n\t" \
       
   271 +                                                                        \
       
   272 +        ".elseif "#n" < 1000 \n\t"                                      \
       
   273 +        ".globl _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t"                    \
       
   274 +        ".type  _ZN14nsXPTCStubBase7Stub"#n"Ev,@function \n\n"          \
       
   275 +"_ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t"                                  \
       
   276 +        "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
       
   277 +        "addi     2,2,.TOC.-0b@l \n\t"                                  \
       
   278 +        ".localentry _ZN14nsXPTCStubBase7Stub"#n"Ev,.-_ZN14nsXPTCStubBase7Stub"#n"Ev \n\t" \
       
   279 +                                                                        \
       
   280 +        ".else  \n\t"                                                   \
       
   281 +        ".err   \"stub number "#n" >= 1000 not yet supported\"\n"       \
       
   282 +        ".endif \n\t"                                                   \
       
   283 +                                                                        \
       
   284 +        "li     11,"#n" \n\t"                                           \
       
   285 +        "b      SharedStub \n"                                          \
       
   286 +);
       
   287 +#else
       
   288  # define STUB_ENTRY(n)                                                  \
       
   289  __asm__ (                                                               \
       
   290          ".section \".toc\",\"aw\" \n\t"                                 \
       
   291 @@ -195,6 +234,7 @@ __asm__ (
       
   292          "li     11,"#n" \n\t"                                           \
       
   293          "b      SharedStub \n"                                          \
       
   294  );
       
   295 +#endif
       
   296  
       
   297  #define SENTINEL_ENTRY(n)                                               \
       
   298  nsresult nsXPTCStubBase::Sentinel##n()                                  \