1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_aarch64.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,136 @@ 1.4 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* Platform specific code to invoke XPCOM methods on native objects */ 1.10 + 1.11 +#include "xptcprivate.h" 1.12 + 1.13 +#if !defined(__aarch64__) 1.14 +#error "This code is for Linux AArch64 only." 1.15 +#endif 1.16 + 1.17 + 1.18 +/* "Procedure Call Standard for the ARM 64-bit Architecture" document, sections 1.19 + * "5.4 Parameter Passing" and "6.1.2 Procedure Calling" contain all the 1.20 + * needed information. 1.21 + * 1.22 + * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf 1.23 + */ 1.24 + 1.25 +#ifndef __AARCH64EL__ 1.26 +#error "Only little endian compatibility was tested" 1.27 +#endif 1.28 + 1.29 +/* 1.30 + * Allocation of integer function arguments initially to registers r1-r7 1.31 + * and then to stack. Handling of 'that' argument which goes to register r0 1.32 + * is handled separately and does not belong here. 1.33 + * 1.34 + * 'ireg_args' - pointer to the current position in the buffer, 1.35 + * corresponding to the register arguments 1.36 + * 'stack_args' - pointer to the current position in the buffer, 1.37 + * corresponding to the arguments on stack 1.38 + * 'end' - pointer to the end of the registers argument 1.39 + * buffer. 1.40 + */ 1.41 +static inline void alloc_word(uint64_t* &ireg_args, 1.42 + uint64_t* &stack_args, 1.43 + uint64_t* end, 1.44 + uint64_t data) 1.45 +{ 1.46 + if (ireg_args < end) { 1.47 + *ireg_args = data; 1.48 + ireg_args++; 1.49 + } else { 1.50 + *stack_args = data; 1.51 + stack_args++; 1.52 + } 1.53 +} 1.54 + 1.55 +static inline void alloc_double(double* &freg_args, 1.56 + uint64_t* &stack_args, 1.57 + double* end, 1.58 + double data) 1.59 +{ 1.60 + if (freg_args < end) { 1.61 + *freg_args = data; 1.62 + freg_args++; 1.63 + } else { 1.64 + memcpy(stack_args, &data, sizeof(data)); 1.65 + stack_args++; 1.66 + } 1.67 +} 1.68 + 1.69 +static inline void alloc_float(double* &freg_args, 1.70 + uint64_t* &stack_args, 1.71 + double* end, 1.72 + float data) 1.73 +{ 1.74 + if (freg_args < end) { 1.75 + memcpy(freg_args, &data, sizeof(data)); 1.76 + freg_args++; 1.77 + } else { 1.78 + memcpy(stack_args, &data, sizeof(data)); 1.79 + stack_args++; 1.80 + } 1.81 +} 1.82 + 1.83 + 1.84 +extern "C" void 1.85 +invoke_copy_to_stack(uint64_t* stk, uint64_t *end, 1.86 + uint32_t paramCount, nsXPTCVariant* s) 1.87 +{ 1.88 + uint64_t *ireg_args = stk; 1.89 + uint64_t *ireg_end = ireg_args + 8; 1.90 + double *freg_args = (double *)ireg_end; 1.91 + double *freg_end = freg_args + 8; 1.92 + uint64_t *stack_args = (uint64_t *)freg_end; 1.93 + 1.94 + // leave room for 'that' argument in x0 1.95 + ++ireg_args; 1.96 + 1.97 + for (uint32_t i = 0; i < paramCount; i++, s++) { 1.98 + if (s->IsPtrData()) { 1.99 + alloc_word(ireg_args, stack_args, ireg_end, (uint64_t)s->ptr); 1.100 + continue; 1.101 + } 1.102 + // According to the ABI, integral types that are smaller than 8 bytes 1.103 + // are to be passed in 8-byte registers or 8-byte stack slots. 1.104 + switch (s->type) { 1.105 + case nsXPTType::T_FLOAT: 1.106 + alloc_float(freg_args, stack_args, freg_end, s->val.f); 1.107 + break; 1.108 + case nsXPTType::T_DOUBLE: 1.109 + alloc_double(freg_args, stack_args, freg_end, s->val.d); 1.110 + break; 1.111 + case nsXPTType::T_I8: alloc_word(ireg_args, stk, end, s->val.i8); break; 1.112 + case nsXPTType::T_I16: alloc_word(ireg_args, stk, end, s->val.i16); break; 1.113 + case nsXPTType::T_I32: alloc_word(ireg_args, stk, end, s->val.i32); break; 1.114 + case nsXPTType::T_I64: alloc_word(ireg_args, stk, end, s->val.i64); break; 1.115 + case nsXPTType::T_U8: alloc_word(ireg_args, stk, end, s->val.u8); break; 1.116 + case nsXPTType::T_U16: alloc_word(ireg_args, stk, end, s->val.u16); break; 1.117 + case nsXPTType::T_U32: alloc_word(ireg_args, stk, end, s->val.u32); break; 1.118 + case nsXPTType::T_U64: alloc_word(ireg_args, stk, end, s->val.u64); break; 1.119 + case nsXPTType::T_BOOL: alloc_word(ireg_args, stk, end, s->val.b); break; 1.120 + case nsXPTType::T_CHAR: alloc_word(ireg_args, stk, end, s->val.c); break; 1.121 + case nsXPTType::T_WCHAR: alloc_word(ireg_args, stk, end, s->val.wc); break; 1.122 + default: 1.123 + // all the others are plain pointer types 1.124 + alloc_word(ireg_args, stack_args, ireg_end, 1.125 + reinterpret_cast<uint64_t>(s->val.p)); 1.126 + break; 1.127 + } 1.128 + } 1.129 +} 1.130 + 1.131 +extern "C" nsresult _NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, 1.132 + uint32_t paramCount, nsXPTCVariant* params); 1.133 + 1.134 +EXPORT_XPCOM_API(nsresult) 1.135 +NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, 1.136 + uint32_t paramCount, nsXPTCVariant* params) 1.137 +{ 1.138 + return _NS_InvokeByIndex(that, methodIndex, paramCount, params); 1.139 +}