michael@0: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * 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: #include "xptcprivate.h" michael@0: #include "xptiprivate.h" michael@0: michael@0: /* michael@0: * This is for Windows 64 bit (x86_64) using GCC syntax michael@0: * Code was copied from the MSVC version. michael@0: */ michael@0: michael@0: #if !defined(_AMD64_) || !defined(__GNUC__) michael@0: # error xptcstubs_x86_64_gnu.cpp being used unexpectedly michael@0: #endif michael@0: michael@0: extern "C" nsresult __attribute__((__used__)) michael@0: PrepareAndDispatch(nsXPTCStubBase * self, uint32_t methodIndex, michael@0: uint64_t * args, uint64_t * gprData, double *fprData) michael@0: { michael@0: #define PARAM_BUFFER_COUNT 16 michael@0: // michael@0: // "this" pointer is first parameter, so parameter count is 3. michael@0: // michael@0: #define PARAM_GPR_COUNT 3 michael@0: #define PARAM_FPR_COUNT 3 michael@0: michael@0: nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; michael@0: nsXPTCMiniVariant* dispatchParams = nullptr; michael@0: const nsXPTMethodInfo* info = nullptr; michael@0: uint8_t paramCount; michael@0: uint8_t i; michael@0: nsresult result = NS_ERROR_FAILURE; michael@0: michael@0: NS_ASSERTION(self, "no self"); michael@0: michael@0: self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); michael@0: NS_ASSERTION(info, "no method info"); michael@0: michael@0: paramCount = info->GetParamCount(); michael@0: michael@0: // michael@0: // setup variant array pointer michael@0: // michael@0: michael@0: if(paramCount > PARAM_BUFFER_COUNT) michael@0: dispatchParams = new nsXPTCMiniVariant[paramCount]; michael@0: else michael@0: dispatchParams = paramBuffer; michael@0: michael@0: NS_ASSERTION(dispatchParams,"no place for params"); michael@0: michael@0: uint64_t* ap = args; michael@0: uint32_t iCount = 0; michael@0: michael@0: for(i = 0; i < paramCount; i++) michael@0: { michael@0: const nsXPTParamInfo& param = info->GetParam(i); michael@0: const nsXPTType& type = param.GetType(); michael@0: nsXPTCMiniVariant* dp = &dispatchParams[i]; michael@0: michael@0: if(param.IsOut() || !type.IsArithmetic()) michael@0: { michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.p = (void*)gprData[iCount++]; michael@0: else michael@0: dp->val.p = (void*)*ap++; michael@0: michael@0: continue; michael@0: } michael@0: // else michael@0: switch(type) michael@0: { michael@0: case nsXPTType::T_I8: michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.i8 = (int8_t)gprData[iCount++]; michael@0: else michael@0: dp->val.i8 = *((int8_t*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_I16: michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.i16 = (int16_t)gprData[iCount++]; michael@0: else michael@0: dp->val.i16 = *((int16_t*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_I32: michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.i32 = (int32_t)gprData[iCount++]; michael@0: else michael@0: dp->val.i32 = *((int32_t*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_I64: michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.i64 = (int64_t)gprData[iCount++]; michael@0: else michael@0: dp->val.i64 = *((int64_t*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_U8: michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.u8 = (uint8_t)gprData[iCount++]; michael@0: else michael@0: dp->val.u8 = *((uint8_t*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_U16: michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.u16 = (uint16_t)gprData[iCount++]; michael@0: else michael@0: dp->val.u16 = *((uint16_t*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_U32: michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.u32 = (uint32_t)gprData[iCount++]; michael@0: else michael@0: dp->val.u32 = *((uint32_t*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_U64: michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.u64 = (uint64_t)gprData[iCount++]; michael@0: else michael@0: dp->val.u64 = *((uint64_t*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_FLOAT: michael@0: if (iCount < PARAM_FPR_COUNT) michael@0: dp->val.f = (float)fprData[iCount++]; michael@0: else michael@0: dp->val.f = *((float*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_DOUBLE: michael@0: if (iCount < PARAM_FPR_COUNT) michael@0: dp->val.d = (double)fprData[iCount++]; michael@0: else michael@0: dp->val.d = *((double*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_BOOL: michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.b = (bool)gprData[iCount++]; michael@0: else michael@0: dp->val.b = *((bool*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_CHAR: michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.c = (char)gprData[iCount++]; michael@0: else michael@0: dp->val.c = *((char*)ap++); michael@0: break; michael@0: michael@0: case nsXPTType::T_WCHAR: michael@0: if (iCount < PARAM_GPR_COUNT) michael@0: dp->val.wc = (wchar_t)gprData[iCount++]; michael@0: else michael@0: dp->val.wc = *((wchar_t*)ap++); michael@0: break; michael@0: michael@0: default: michael@0: NS_ASSERTION(0, "bad type"); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams); michael@0: michael@0: if(dispatchParams != paramBuffer) michael@0: delete [] dispatchParams; michael@0: michael@0: return result; michael@0: } michael@0: michael@0: __asm__ ( michael@0: ".text\n" michael@0: ".intel_syntax noprefix\n" /* switch to Intel syntax to look like the MSVC assembly */ michael@0: ".globl SharedStub\n" michael@0: ".def SharedStub ; .scl 3 ; .type 46 ; .endef \n" michael@0: "SharedStub:\n" michael@0: "sub rsp, 104\n" michael@0: michael@0: /* rcx is this pointer. Need backup for optimized build */ michael@0: michael@0: "mov qword ptr [rsp+88], rcx\n" michael@0: michael@0: /* michael@0: * fist 4 parameters (1st is "this" pointer) are passed in registers. michael@0: */ michael@0: michael@0: /* for floating value */ michael@0: michael@0: "movsd qword ptr [rsp+64], xmm1\n" michael@0: "movsd qword ptr [rsp+72], xmm2\n" michael@0: "movsd qword ptr [rsp+80], xmm3\n" michael@0: michael@0: /* for integer value */ michael@0: michael@0: "mov qword ptr [rsp+40], rdx\n" michael@0: "mov qword ptr [rsp+48], r8\n" michael@0: "mov qword ptr [rsp+56], r9\n" michael@0: michael@0: /* michael@0: * Call PrepareAndDispatch function michael@0: */ michael@0: michael@0: /* 5th parameter (floating parameters) of PrepareAndDispatch */ michael@0: michael@0: "lea r9, qword ptr [rsp+64]\n" michael@0: "mov qword ptr [rsp+32], r9\n" michael@0: michael@0: /* 4th parameter (normal parameters) of PrepareAndDispatch */ michael@0: michael@0: "lea r9, qword ptr [rsp+40]\n" michael@0: michael@0: /* 3rd parameter (pointer to args on stack) */ michael@0: michael@0: "lea r8, qword ptr [rsp+40+104]\n" michael@0: michael@0: /* 2nd parameter (vtbl_index) */ michael@0: michael@0: "mov rdx, r11\n" michael@0: michael@0: /* 1st parameter (this) (rcx) */ michael@0: michael@0: "call PrepareAndDispatch\n" michael@0: michael@0: /* restore rcx */ michael@0: michael@0: "mov rcx, qword ptr [rsp+88]\n" michael@0: michael@0: /* michael@0: * clean up register michael@0: */ michael@0: michael@0: "add rsp, 104+8\n" michael@0: michael@0: /* set return address */ michael@0: michael@0: "mov rdx, qword ptr [rsp-8]\n" michael@0: michael@0: /* simulate __stdcall return */ michael@0: michael@0: "jmp rdx\n" michael@0: michael@0: /* back to AT&T syntax */ michael@0: ".att_syntax\n" michael@0: ); michael@0: michael@0: #define STUB_ENTRY(n) \ michael@0: asm(".intel_syntax noprefix\n" /* this is in intel syntax */ \ michael@0: ".text\n" \ michael@0: ".align 2\n" \ michael@0: ".if " #n " < 10\n" \ michael@0: ".globl _ZN14nsXPTCStubBase5Stub" #n "Ev@4\n" \ michael@0: ".def _ZN14nsXPTCStubBase5Stub" #n "Ev@4\n" \ michael@0: ".scl 3\n" /* private */ \ michael@0: ".type 46\n" /* function returning unsigned int */ \ michael@0: ".endef\n" \ michael@0: "_ZN14nsXPTCStubBase5Stub" #n "Ev@4:\n" \ michael@0: ".elseif " #n " < 100\n" \ michael@0: ".globl _ZN14nsXPTCStubBase6Stub" #n "Ev@4\n" \ michael@0: ".def _ZN14nsXPTCStubBase6Stub" #n "Ev@4\n" \ michael@0: ".scl 3\n" /* private */\ michael@0: ".type 46\n" /* function returning unsigned int */ \ michael@0: ".endef\n" \ michael@0: "_ZN14nsXPTCStubBase6Stub" #n "Ev@4:\n" \ michael@0: ".elseif " #n " < 1000\n" \ michael@0: ".globl _ZN14nsXPTCStubBase7Stub" #n "Ev@4\n" \ michael@0: ".def _ZN14nsXPTCStubBase7Stub" #n "Ev@4\n" \ michael@0: ".scl 3\n" /* private */ \ michael@0: ".type 46\n" /* function returning unsigned int */ \ michael@0: ".endef\n" \ michael@0: "_ZN14nsXPTCStubBase7Stub" #n "Ev@4:\n" \ michael@0: ".else\n" \ michael@0: ".err \"stub number " #n " >= 1000 not yet supported\"\n" \ michael@0: ".endif\n" \ michael@0: "mov r11, " #n "\n" \ michael@0: "jmp SharedStub\n" \ michael@0: ".att_syntax\n" /* back to AT&T syntax */ \ michael@0: ""); michael@0: michael@0: #define SENTINEL_ENTRY(n) \ michael@0: nsresult nsXPTCStubBase::Sentinel##n() \ michael@0: { \ michael@0: NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \ michael@0: return NS_ERROR_NOT_IMPLEMENTED; \ michael@0: } michael@0: michael@0: #include "xptcstubsdef.inc" michael@0: