1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_netbsd_m68k.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,143 @@ 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 +// Remember that these 'words' are 32bit DWORDS 1.14 + 1.15 +#if !defined(__NetBSD__) || !defined(__m68k__) 1.16 +#error This code is for NetBSD/m68k only 1.17 +#endif 1.18 + 1.19 +extern "C" { 1.20 + static uint32_t 1.21 + invoke_count_words(uint32_t paramCount, nsXPTCVariant* s) 1.22 + { 1.23 + uint32_t result = 0; 1.24 + for(uint32_t i = 0; i < paramCount; i++, s++) 1.25 + { 1.26 + if(s->IsPtrData()) 1.27 + { 1.28 + result++; 1.29 + continue; 1.30 + } 1.31 + switch(s->type) 1.32 + { 1.33 + case nsXPTType::T_I8 : 1.34 + case nsXPTType::T_I16 : 1.35 + case nsXPTType::T_I32 : 1.36 + result++; 1.37 + break; 1.38 + case nsXPTType::T_I64 : 1.39 + result+=2; 1.40 + break; 1.41 + case nsXPTType::T_U8 : 1.42 + case nsXPTType::T_U16 : 1.43 + case nsXPTType::T_U32 : 1.44 + result++; 1.45 + break; 1.46 + case nsXPTType::T_U64 : 1.47 + result+=2; 1.48 + break; 1.49 + case nsXPTType::T_FLOAT : 1.50 + result++; 1.51 + break; 1.52 + case nsXPTType::T_DOUBLE : 1.53 + result+=2; 1.54 + break; 1.55 + case nsXPTType::T_BOOL : 1.56 + case nsXPTType::T_CHAR : 1.57 + case nsXPTType::T_WCHAR : 1.58 + result++; 1.59 + break; 1.60 + default: 1.61 + // all the others are plain pointer types 1.62 + result++; 1.63 + break; 1.64 + } 1.65 + } 1.66 + return result; 1.67 + } 1.68 + 1.69 + static void 1.70 + invoke_copy_to_stack(uint32_t* d, uint32_t paramCount, nsXPTCVariant* s) 1.71 + { 1.72 + for(uint32_t i = 0; i < paramCount; i++, d++, s++) 1.73 + { 1.74 + if(s->IsPtrData()) 1.75 + { 1.76 + *((void**)d) = s->ptr; 1.77 + continue; 1.78 + } 1.79 + switch(s->type) 1.80 + { 1.81 + // 8 and 16 bit types should be promoted to 32 bits when copying 1.82 + // onto the stack. 1.83 + case nsXPTType::T_I8 : *((uint32_t*)d) = s->val.i8; break; 1.84 + case nsXPTType::T_I16 : *((uint32_t*)d) = s->val.i16; break; 1.85 + case nsXPTType::T_I32 : *((int32_t*) d) = s->val.i32; break; 1.86 + case nsXPTType::T_I64 : *((int64_t*) d) = s->val.i64; d++; break; 1.87 + case nsXPTType::T_U8 : *((uint32_t*)d) = s->val.u8; break; 1.88 + case nsXPTType::T_U16 : *((uint32_t*)d) = s->val.u16; break; 1.89 + case nsXPTType::T_U32 : *((uint32_t*)d) = s->val.u32; break; 1.90 + case nsXPTType::T_U64 : *((uint64_t*)d) = s->val.u64; d++; break; 1.91 + case nsXPTType::T_FLOAT : *((float*) d) = s->val.f; break; 1.92 + case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++; break; 1.93 + case nsXPTType::T_BOOL : *((uint32_t*)d) = s->val.b; break; 1.94 + case nsXPTType::T_CHAR : *((uint32_t*)d) = s->val.c; break; 1.95 + // wchar_t is an int (32 bits) on NetBSD 1.96 + case nsXPTType::T_WCHAR : *((wchar_t*) d) = s->val.wc; break; 1.97 + default: 1.98 + // all the others are plain pointer types 1.99 + *((void**)d) = s->val.p; 1.100 + break; 1.101 + } 1.102 + } 1.103 + } 1.104 +} 1.105 + 1.106 +XPTC_PUBLIC_API(nsresult) 1.107 +XPTC_InvokeByIndex(nsISupports* that, uint32_t methodIndex, 1.108 + uint32_t paramCount, nsXPTCVariant* params) 1.109 +{ 1.110 + uint32_t result; 1.111 + 1.112 + __asm__ __volatile__( 1.113 + "movl %4, sp@-\n\t" 1.114 + "movl %3, sp@-\n\t" 1.115 + "jbsr _invoke_count_words\n\t" /* count words */ 1.116 + "addql #8, sp\n\t" 1.117 + "lsll #2, d0\n\t" /* *= 4 */ 1.118 + "movl sp, a2\n\t" /* save original sp */ 1.119 + "subl d0, sp\n\t" /* make room for params */ 1.120 + "movl sp, a0\n\t" 1.121 + "movl %4, sp@-\n\t" 1.122 + "movl %3, sp@-\n\t" 1.123 + "movl a0, sp@-\n\t" 1.124 + "jbsr _invoke_copy_to_stack\n\t" /* copy params */ 1.125 + "addl #12, sp\n\t" 1.126 + "movl %1, a0\n\t" 1.127 + "movl a0@, a1\n\t" 1.128 + "movl %2, d0\n\t" /* function index */ 1.129 + "movl a0, d1\n\t" 1.130 + "movw a1@(8,d0:l:8), a0\n\t" 1.131 + "addl a0, d1\n\t" 1.132 + "movl a1@(12,d0:l:8), a1\n\t" 1.133 + "movl d1, sp@-\n\t" 1.134 + "jbsr a1@\n\t" 1.135 + "movl a2, sp\n\t" /* restore original sp */ 1.136 + "movl d0, %0\n\t" 1.137 + : "=g" (result) /* %0 */ 1.138 + : "g" (that), /* %1 */ 1.139 + "g" (methodIndex), /* %2 */ 1.140 + "g" (paramCount), /* %3 */ 1.141 + "g" (params) /* %4 */ 1.142 + : "a0", "a1", "a2", "d0", "d1", "memory" 1.143 + ); 1.144 + 1.145 + return result; 1.146 +}