Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* Platform specific code to invoke XPCOM methods on native objects */ |
michael@0 | 7 | |
michael@0 | 8 | #include "xptcprivate.h" |
michael@0 | 9 | |
michael@0 | 10 | /* Prototype specifies unmangled function name and disables unused warning */ |
michael@0 | 11 | static void |
michael@0 | 12 | invoke_copy_to_stack(uint64_t* d, uint32_t paramCount, nsXPTCVariant* s) |
michael@0 | 13 | __asm__("invoke_copy_to_stack") __attribute__((used)); |
michael@0 | 14 | |
michael@0 | 15 | static void |
michael@0 | 16 | invoke_copy_to_stack(uint64_t* d, uint32_t paramCount, nsXPTCVariant* s) |
michael@0 | 17 | { |
michael@0 | 18 | const uint8_t NUM_ARG_REGS = 6-1; // -1 for "this" pointer |
michael@0 | 19 | |
michael@0 | 20 | for(uint32_t i = 0; i < paramCount; i++, d++, s++) |
michael@0 | 21 | { |
michael@0 | 22 | if(s->IsPtrData()) |
michael@0 | 23 | { |
michael@0 | 24 | *d = (uint64_t)s->ptr; |
michael@0 | 25 | continue; |
michael@0 | 26 | } |
michael@0 | 27 | switch(s->type) |
michael@0 | 28 | { |
michael@0 | 29 | case nsXPTType::T_I8 : *d = (uint64_t)s->val.i8; break; |
michael@0 | 30 | case nsXPTType::T_I16 : *d = (uint64_t)s->val.i16; break; |
michael@0 | 31 | case nsXPTType::T_I32 : *d = (uint64_t)s->val.i32; break; |
michael@0 | 32 | case nsXPTType::T_I64 : *d = (uint64_t)s->val.i64; break; |
michael@0 | 33 | case nsXPTType::T_U8 : *d = (uint64_t)s->val.u8; break; |
michael@0 | 34 | case nsXPTType::T_U16 : *d = (uint64_t)s->val.u16; break; |
michael@0 | 35 | case nsXPTType::T_U32 : *d = (uint64_t)s->val.u32; break; |
michael@0 | 36 | case nsXPTType::T_U64 : *d = (uint64_t)s->val.u64; break; |
michael@0 | 37 | case nsXPTType::T_FLOAT : |
michael@0 | 38 | if(i < NUM_ARG_REGS) |
michael@0 | 39 | { |
michael@0 | 40 | // convert floats to doubles if they are to be passed |
michael@0 | 41 | // via registers so we can just deal with doubles later |
michael@0 | 42 | union { uint64_t u64; double d; } t; |
michael@0 | 43 | t.d = (double)s->val.f; |
michael@0 | 44 | *d = t.u64; |
michael@0 | 45 | } |
michael@0 | 46 | else |
michael@0 | 47 | // otherwise copy to stack normally |
michael@0 | 48 | *d = (uint64_t)s->val.u32; |
michael@0 | 49 | break; |
michael@0 | 50 | case nsXPTType::T_DOUBLE : *d = (uint64_t)s->val.u64; break; |
michael@0 | 51 | case nsXPTType::T_BOOL : *d = (uint64_t)s->val.b; break; |
michael@0 | 52 | case nsXPTType::T_CHAR : *d = (uint64_t)s->val.c; break; |
michael@0 | 53 | case nsXPTType::T_WCHAR : *d = (uint64_t)s->val.wc; break; |
michael@0 | 54 | default: |
michael@0 | 55 | // all the others are plain pointer types |
michael@0 | 56 | *d = (uint64_t)s->val.p; |
michael@0 | 57 | break; |
michael@0 | 58 | } |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | /* |
michael@0 | 63 | * EXPORT_XPCOM_API(nsresult) |
michael@0 | 64 | * NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, |
michael@0 | 65 | * uint32_t paramCount, nsXPTCVariant* params) |
michael@0 | 66 | */ |
michael@0 | 67 | __asm__( |
michael@0 | 68 | "#### NS_InvokeByIndex ####\n" |
michael@0 | 69 | ".text\n\t" |
michael@0 | 70 | ".align 5\n\t" |
michael@0 | 71 | ".globl NS_InvokeByIndex\n\t" |
michael@0 | 72 | ".ent NS_InvokeByIndex\n" |
michael@0 | 73 | "NS_InvokeByIndex:\n\t" |
michael@0 | 74 | ".frame $15,32,$26,0\n\t" |
michael@0 | 75 | ".mask 0x4008000,-32\n\t" |
michael@0 | 76 | "ldgp $29,0($27)\n" |
michael@0 | 77 | "$NS_InvokeByIndex..ng:\n\t" |
michael@0 | 78 | "subq $30,32,$30\n\t" |
michael@0 | 79 | "stq $26,0($30)\n\t" |
michael@0 | 80 | "stq $15,8($30)\n\t" |
michael@0 | 81 | "bis $30,$30,$15\n\t" |
michael@0 | 82 | ".prologue 1\n\t" |
michael@0 | 83 | |
michael@0 | 84 | /* |
michael@0 | 85 | * Allocate enough stack space to hold the greater of 6 or "paramCount"+1 |
michael@0 | 86 | * parameters. (+1 for "this" pointer) Room for at least 6 parameters |
michael@0 | 87 | * is required for storage of those passed via registers. |
michael@0 | 88 | */ |
michael@0 | 89 | |
michael@0 | 90 | "bis $31,5,$2\n\t" /* count = MAX(5, "paramCount") */ |
michael@0 | 91 | "cmplt $2,$18,$1\n\t" |
michael@0 | 92 | "cmovne $1,$18,$2\n\t" |
michael@0 | 93 | "s8addq $2,16,$1\n\t" /* room for count+1 params (8 bytes each) */ |
michael@0 | 94 | "bic $1,15,$1\n\t" /* stack space is rounded up to 0 % 16 */ |
michael@0 | 95 | "subq $30,$1,$30\n\t" |
michael@0 | 96 | |
michael@0 | 97 | "stq $16,0($30)\n\t" /* save "that" (as "this" pointer) */ |
michael@0 | 98 | "stq $17,16($15)\n\t" /* save "methodIndex" */ |
michael@0 | 99 | |
michael@0 | 100 | "addq $30,8,$16\n\t" /* pass stack pointer */ |
michael@0 | 101 | "bis $18,$18,$17\n\t" /* pass "paramCount" */ |
michael@0 | 102 | "bis $19,$19,$18\n\t" /* pass "params" */ |
michael@0 | 103 | "bsr $26,$invoke_copy_to_stack..ng\n\t" /* call invoke_copy_to_stack */ |
michael@0 | 104 | |
michael@0 | 105 | /* |
michael@0 | 106 | * Copy the first 6 parameters to registers and remove from stack frame. |
michael@0 | 107 | * Both the integer and floating point registers are set for each parameter |
michael@0 | 108 | * except the first which is the "this" pointer. (integer only) |
michael@0 | 109 | * The floating point registers are all set as doubles since the |
michael@0 | 110 | * invoke_copy_to_stack function should have converted the floats. |
michael@0 | 111 | */ |
michael@0 | 112 | "ldq $16,0($30)\n\t" /* integer registers */ |
michael@0 | 113 | "ldq $17,8($30)\n\t" |
michael@0 | 114 | "ldq $18,16($30)\n\t" |
michael@0 | 115 | "ldq $19,24($30)\n\t" |
michael@0 | 116 | "ldq $20,32($30)\n\t" |
michael@0 | 117 | "ldq $21,40($30)\n\t" |
michael@0 | 118 | "ldt $f17,8($30)\n\t" /* floating point registers */ |
michael@0 | 119 | "ldt $f18,16($30)\n\t" |
michael@0 | 120 | "ldt $f19,24($30)\n\t" |
michael@0 | 121 | "ldt $f20,32($30)\n\t" |
michael@0 | 122 | "ldt $f21,40($30)\n\t" |
michael@0 | 123 | |
michael@0 | 124 | "addq $30,48,$30\n\t" /* remove params from stack */ |
michael@0 | 125 | |
michael@0 | 126 | /* |
michael@0 | 127 | * Call the virtual function with the constructed stack frame. |
michael@0 | 128 | */ |
michael@0 | 129 | "bis $16,$16,$1\n\t" /* load "this" */ |
michael@0 | 130 | "ldq $2,16($15)\n\t" /* load "methodIndex" */ |
michael@0 | 131 | "ldq $1,0($1)\n\t" /* load vtable */ |
michael@0 | 132 | "s8addq $2,$31,$2\n\t" /* vtable index = "methodIndex" * 8 */ |
michael@0 | 133 | "addq $1,$2,$1\n\t" |
michael@0 | 134 | "ldq $27,0($1)\n\t" /* load address of function */ |
michael@0 | 135 | "jsr $26,($27),0\n\t" /* call virtual function */ |
michael@0 | 136 | "ldgp $29,0($26)\n\t" |
michael@0 | 137 | |
michael@0 | 138 | "bis $15,$15,$30\n\t" |
michael@0 | 139 | "ldq $26,0($30)\n\t" |
michael@0 | 140 | "ldq $15,8($30)\n\t" |
michael@0 | 141 | "addq $30,32,$30\n\t" |
michael@0 | 142 | "ret $31,($26),1\n\t" |
michael@0 | 143 | ".end NS_InvokeByIndex" |
michael@0 | 144 | ); |