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: /* Implement shared vtbl methods. */ michael@0: michael@0: #include "xptcprivate.h" michael@0: michael@0: #if !defined(__NetBSD__) || !defined(__m68k__) michael@0: #error This code is for NetBSD/m68k only michael@0: #endif michael@0: michael@0: extern "C" { michael@0: static nsresult ATTRIBUTE_USED michael@0: PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint32_t* args) michael@0: { michael@0: #define PARAM_BUFFER_COUNT 16 michael@0: michael@0: nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; michael@0: nsXPTCMiniVariant* dispatchParams = nullptr; michael@0: nsIInterfaceInfo* iface_info = nullptr; michael@0: const nsXPTMethodInfo* info; 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->GetInterfaceInfo(&iface_info); michael@0: NS_ASSERTION(iface_info,"no interface info"); michael@0: michael@0: iface_info->GetMethodInfo(uint16_t(methodIndex), &info); michael@0: NS_ASSERTION(info,"no interface info"); michael@0: michael@0: paramCount = info->GetParamCount(); michael@0: michael@0: // setup variant array pointer michael@0: if(paramCount > PARAM_BUFFER_COUNT) michael@0: dispatchParams = new nsXPTCMiniVariant[paramCount]; michael@0: else michael@0: dispatchParams = paramBuffer; michael@0: NS_ASSERTION(dispatchParams,"no place for params"); michael@0: michael@0: uint32_t* ap = args; michael@0: for(i = 0; i < paramCount; i++, ap++) 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: dp->val.p = (void*) *ap; michael@0: continue; michael@0: } michael@0: michael@0: switch(type) michael@0: { michael@0: // the 8 and 16 bit types will have been promoted to 32 bits before michael@0: // being pushed onto the stack. Since the 68k is big endian, we michael@0: // need to skip over the leading high order bytes. michael@0: case nsXPTType::T_I8 : dp->val.i8 = *(((int8_t*) ap) + 3); break; michael@0: case nsXPTType::T_I16 : dp->val.i16 = *(((int16_t*) ap) + 1); break; michael@0: case nsXPTType::T_I32 : dp->val.i32 = *((int32_t*) ap); break; michael@0: case nsXPTType::T_I64 : dp->val.i64 = *((int64_t*) ap); ap++; break; michael@0: case nsXPTType::T_U8 : dp->val.u8 = *(((uint8_t*) ap) + 3); break; michael@0: case nsXPTType::T_U16 : dp->val.u16 = *(((uint16_t*)ap) + 1); break; michael@0: case nsXPTType::T_U32 : dp->val.u32 = *((uint32_t*)ap); break; michael@0: case nsXPTType::T_U64 : dp->val.u64 = *((uint64_t*)ap); ap++; break; michael@0: case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break; michael@0: case nsXPTType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break; michael@0: case nsXPTType::T_BOOL : dp->val.b = *(((char*) ap) + 3); break; michael@0: case nsXPTType::T_CHAR : dp->val.c = *(((char*) ap) + 3); break; michael@0: // wchar_t is an int (32 bits) on NetBSD michael@0: case nsXPTType::T_WCHAR : dp->val.wc = *((wchar_t*) ap); break; michael@0: default: michael@0: NS_ERROR("bad type"); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: result = self->CallMethod((uint16_t)methodIndex, info, dispatchParams); michael@0: michael@0: NS_RELEASE(iface_info); michael@0: michael@0: if(dispatchParams != paramBuffer) michael@0: delete [] dispatchParams; michael@0: michael@0: return result; michael@0: } michael@0: } michael@0: michael@0: #define STUB_ENTRY(n) \ michael@0: __asm__( \ michael@0: ".global _Stub"#n"__14nsXPTCStubBase\n\t" \ michael@0: "_Stub"#n"__14nsXPTCStubBase:\n\t" \ michael@0: "link a6,#0 \n\t" \ michael@0: "lea a6@(12), a0 \n\t" /* pointer to args */ \ michael@0: "movl a0, sp@- \n\t" \ michael@0: "movl #"#n", sp@- \n\t" /* method index */ \ michael@0: "movl a6@(8), sp@- \n\t" /* this */ \ michael@0: "jbsr _PrepareAndDispatch \n\t" \ michael@0: "unlk a6 \n\t" \ michael@0: "rts \n\t" \ michael@0: ); michael@0: michael@0: #define SENTINEL_ENTRY(n) \ michael@0: nsresult nsXPTCStubBase::Sentinel##n() \ michael@0: { \ michael@0: NS_ERROR("nsXPTCStubBase::Sentinel called"); \ michael@0: return NS_ERROR_NOT_IMPLEMENTED; \ michael@0: } michael@0: michael@0: #include "xptcstubsdef.inc"