michael@0: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* Platform specific code to invoke XPCOM methods on native objects */ michael@0: michael@0: #include "xptcprivate.h" michael@0: michael@0: /* Prototype specifies unmangled function name and disables unused warning */ michael@0: static void michael@0: invoke_copy_to_stack(uint64_t* d, uint32_t paramCount, nsXPTCVariant* s) michael@0: __asm__("invoke_copy_to_stack") __attribute__((used)); michael@0: michael@0: static void michael@0: invoke_copy_to_stack(uint64_t* d, uint32_t paramCount, nsXPTCVariant* s) michael@0: { michael@0: const uint8_t NUM_ARG_REGS = 6-1; // -1 for "this" pointer michael@0: michael@0: for(uint32_t i = 0; i < paramCount; i++, d++, s++) michael@0: { michael@0: if(s->IsPtrData()) michael@0: { michael@0: *d = (uint64_t)s->ptr; michael@0: continue; michael@0: } michael@0: switch(s->type) michael@0: { michael@0: case nsXPTType::T_I8 : *d = (uint64_t)s->val.i8; break; michael@0: case nsXPTType::T_I16 : *d = (uint64_t)s->val.i16; break; michael@0: case nsXPTType::T_I32 : *d = (uint64_t)s->val.i32; break; michael@0: case nsXPTType::T_I64 : *d = (uint64_t)s->val.i64; break; michael@0: case nsXPTType::T_U8 : *d = (uint64_t)s->val.u8; break; michael@0: case nsXPTType::T_U16 : *d = (uint64_t)s->val.u16; break; michael@0: case nsXPTType::T_U32 : *d = (uint64_t)s->val.u32; break; michael@0: case nsXPTType::T_U64 : *d = (uint64_t)s->val.u64; break; michael@0: case nsXPTType::T_FLOAT : michael@0: if(i < NUM_ARG_REGS) michael@0: { michael@0: // convert floats to doubles if they are to be passed michael@0: // via registers so we can just deal with doubles later michael@0: union { uint64_t u64; double d; } t; michael@0: t.d = (double)s->val.f; michael@0: *d = t.u64; michael@0: } michael@0: else michael@0: // otherwise copy to stack normally michael@0: *d = (uint64_t)s->val.u32; michael@0: break; michael@0: case nsXPTType::T_DOUBLE : *d = (uint64_t)s->val.u64; break; michael@0: case nsXPTType::T_BOOL : *d = (uint64_t)s->val.b; break; michael@0: case nsXPTType::T_CHAR : *d = (uint64_t)s->val.c; break; michael@0: case nsXPTType::T_WCHAR : *d = (uint64_t)s->val.wc; break; michael@0: default: michael@0: // all the others are plain pointer types michael@0: *d = (uint64_t)s->val.p; michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: michael@0: /* michael@0: * EXPORT_XPCOM_API(nsresult) michael@0: * NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, michael@0: * uint32_t paramCount, nsXPTCVariant* params) michael@0: */ michael@0: __asm__( michael@0: "#### NS_InvokeByIndex ####\n" michael@0: ".text\n\t" michael@0: ".align 5\n\t" michael@0: ".globl NS_InvokeByIndex\n\t" michael@0: ".ent NS_InvokeByIndex\n" michael@0: "NS_InvokeByIndex:\n\t" michael@0: ".frame $15,32,$26,0\n\t" michael@0: ".mask 0x4008000,-32\n\t" michael@0: "ldgp $29,0($27)\n" michael@0: "$NS_InvokeByIndex..ng:\n\t" michael@0: "subq $30,32,$30\n\t" michael@0: "stq $26,0($30)\n\t" michael@0: "stq $15,8($30)\n\t" michael@0: "bis $30,$30,$15\n\t" michael@0: ".prologue 1\n\t" michael@0: michael@0: /* michael@0: * Allocate enough stack space to hold the greater of 6 or "paramCount"+1 michael@0: * parameters. (+1 for "this" pointer) Room for at least 6 parameters michael@0: * is required for storage of those passed via registers. michael@0: */ michael@0: michael@0: "bis $31,5,$2\n\t" /* count = MAX(5, "paramCount") */ michael@0: "cmplt $2,$18,$1\n\t" michael@0: "cmovne $1,$18,$2\n\t" michael@0: "s8addq $2,16,$1\n\t" /* room for count+1 params (8 bytes each) */ michael@0: "bic $1,15,$1\n\t" /* stack space is rounded up to 0 % 16 */ michael@0: "subq $30,$1,$30\n\t" michael@0: michael@0: "stq $16,0($30)\n\t" /* save "that" (as "this" pointer) */ michael@0: "stq $17,16($15)\n\t" /* save "methodIndex" */ michael@0: michael@0: "addq $30,8,$16\n\t" /* pass stack pointer */ michael@0: "bis $18,$18,$17\n\t" /* pass "paramCount" */ michael@0: "bis $19,$19,$18\n\t" /* pass "params" */ michael@0: "bsr $26,$invoke_copy_to_stack..ng\n\t" /* call invoke_copy_to_stack */ michael@0: michael@0: /* michael@0: * Copy the first 6 parameters to registers and remove from stack frame. michael@0: * Both the integer and floating point registers are set for each parameter michael@0: * except the first which is the "this" pointer. (integer only) michael@0: * The floating point registers are all set as doubles since the michael@0: * invoke_copy_to_stack function should have converted the floats. michael@0: */ michael@0: "ldq $16,0($30)\n\t" /* integer registers */ michael@0: "ldq $17,8($30)\n\t" michael@0: "ldq $18,16($30)\n\t" michael@0: "ldq $19,24($30)\n\t" michael@0: "ldq $20,32($30)\n\t" michael@0: "ldq $21,40($30)\n\t" michael@0: "ldt $f17,8($30)\n\t" /* floating point registers */ michael@0: "ldt $f18,16($30)\n\t" michael@0: "ldt $f19,24($30)\n\t" michael@0: "ldt $f20,32($30)\n\t" michael@0: "ldt $f21,40($30)\n\t" michael@0: michael@0: "addq $30,48,$30\n\t" /* remove params from stack */ michael@0: michael@0: /* michael@0: * Call the virtual function with the constructed stack frame. michael@0: */ michael@0: "bis $16,$16,$1\n\t" /* load "this" */ michael@0: "ldq $2,16($15)\n\t" /* load "methodIndex" */ michael@0: "ldq $1,0($1)\n\t" /* load vtable */ michael@0: "s8addq $2,$31,$2\n\t" /* vtable index = "methodIndex" * 8 */ michael@0: "addq $1,$2,$1\n\t" michael@0: "ldq $27,0($1)\n\t" /* load address of function */ michael@0: "jsr $26,($27),0\n\t" /* call virtual function */ michael@0: "ldgp $29,0($26)\n\t" michael@0: michael@0: "bis $15,$15,$30\n\t" michael@0: "ldq $26,0($30)\n\t" michael@0: "ldq $15,8($30)\n\t" michael@0: "addq $30,32,$30\n\t" michael@0: "ret $31,($26),1\n\t" michael@0: ".end NS_InvokeByIndex" michael@0: );