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: #if !defined(__aarch64__) michael@0: #error "This code is for Linux AArch64 only." michael@0: #endif michael@0: michael@0: michael@0: /* "Procedure Call Standard for the ARM 64-bit Architecture" document, sections michael@0: * "5.4 Parameter Passing" and "6.1.2 Procedure Calling" contain all the michael@0: * needed information. michael@0: * michael@0: * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf michael@0: */ michael@0: michael@0: #ifndef __AARCH64EL__ michael@0: #error "Only little endian compatibility was tested" michael@0: #endif michael@0: michael@0: /* michael@0: * Allocation of integer function arguments initially to registers r1-r7 michael@0: * and then to stack. Handling of 'that' argument which goes to register r0 michael@0: * is handled separately and does not belong here. michael@0: * michael@0: * 'ireg_args' - pointer to the current position in the buffer, michael@0: * corresponding to the register arguments michael@0: * 'stack_args' - pointer to the current position in the buffer, michael@0: * corresponding to the arguments on stack michael@0: * 'end' - pointer to the end of the registers argument michael@0: * buffer. michael@0: */ michael@0: static inline void alloc_word(uint64_t* &ireg_args, michael@0: uint64_t* &stack_args, michael@0: uint64_t* end, michael@0: uint64_t data) michael@0: { michael@0: if (ireg_args < end) { michael@0: *ireg_args = data; michael@0: ireg_args++; michael@0: } else { michael@0: *stack_args = data; michael@0: stack_args++; michael@0: } michael@0: } michael@0: michael@0: static inline void alloc_double(double* &freg_args, michael@0: uint64_t* &stack_args, michael@0: double* end, michael@0: double data) michael@0: { michael@0: if (freg_args < end) { michael@0: *freg_args = data; michael@0: freg_args++; michael@0: } else { michael@0: memcpy(stack_args, &data, sizeof(data)); michael@0: stack_args++; michael@0: } michael@0: } michael@0: michael@0: static inline void alloc_float(double* &freg_args, michael@0: uint64_t* &stack_args, michael@0: double* end, michael@0: float data) michael@0: { michael@0: if (freg_args < end) { michael@0: memcpy(freg_args, &data, sizeof(data)); michael@0: freg_args++; michael@0: } else { michael@0: memcpy(stack_args, &data, sizeof(data)); michael@0: stack_args++; michael@0: } michael@0: } michael@0: michael@0: michael@0: extern "C" void michael@0: invoke_copy_to_stack(uint64_t* stk, uint64_t *end, michael@0: uint32_t paramCount, nsXPTCVariant* s) michael@0: { michael@0: uint64_t *ireg_args = stk; michael@0: uint64_t *ireg_end = ireg_args + 8; michael@0: double *freg_args = (double *)ireg_end; michael@0: double *freg_end = freg_args + 8; michael@0: uint64_t *stack_args = (uint64_t *)freg_end; michael@0: michael@0: // leave room for 'that' argument in x0 michael@0: ++ireg_args; michael@0: michael@0: for (uint32_t i = 0; i < paramCount; i++, s++) { michael@0: if (s->IsPtrData()) { michael@0: alloc_word(ireg_args, stack_args, ireg_end, (uint64_t)s->ptr); michael@0: continue; michael@0: } michael@0: // According to the ABI, integral types that are smaller than 8 bytes michael@0: // are to be passed in 8-byte registers or 8-byte stack slots. michael@0: switch (s->type) { michael@0: case nsXPTType::T_FLOAT: michael@0: alloc_float(freg_args, stack_args, freg_end, s->val.f); michael@0: break; michael@0: case nsXPTType::T_DOUBLE: michael@0: alloc_double(freg_args, stack_args, freg_end, s->val.d); michael@0: break; michael@0: case nsXPTType::T_I8: alloc_word(ireg_args, stk, end, s->val.i8); break; michael@0: case nsXPTType::T_I16: alloc_word(ireg_args, stk, end, s->val.i16); break; michael@0: case nsXPTType::T_I32: alloc_word(ireg_args, stk, end, s->val.i32); break; michael@0: case nsXPTType::T_I64: alloc_word(ireg_args, stk, end, s->val.i64); break; michael@0: case nsXPTType::T_U8: alloc_word(ireg_args, stk, end, s->val.u8); break; michael@0: case nsXPTType::T_U16: alloc_word(ireg_args, stk, end, s->val.u16); break; michael@0: case nsXPTType::T_U32: alloc_word(ireg_args, stk, end, s->val.u32); break; michael@0: case nsXPTType::T_U64: alloc_word(ireg_args, stk, end, s->val.u64); break; michael@0: case nsXPTType::T_BOOL: alloc_word(ireg_args, stk, end, s->val.b); break; michael@0: case nsXPTType::T_CHAR: alloc_word(ireg_args, stk, end, s->val.c); break; michael@0: case nsXPTType::T_WCHAR: alloc_word(ireg_args, stk, end, s->val.wc); break; michael@0: default: michael@0: // all the others are plain pointer types michael@0: alloc_word(ireg_args, stack_args, ireg_end, michael@0: reinterpret_cast(s->val.p)); michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: michael@0: extern "C" nsresult _NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, michael@0: uint32_t paramCount, nsXPTCVariant* params); 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: return _NS_InvokeByIndex(that, methodIndex, paramCount, params); michael@0: }