1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_pa32.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,149 @@ 1.4 + 1.5 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.6 + * 1.7 + * This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "xptcprivate.h" 1.12 + 1.13 +#if _HPUX 1.14 +#error "This code is for HP-PA RISC 32 bit mode only" 1.15 +#endif 1.16 + 1.17 +#include <alloca.h> 1.18 + 1.19 +typedef unsigned nsXPCVariant; 1.20 + 1.21 +extern "C" int32_t 1.22 +invoke_count_bytes(nsISupports* that, const uint32_t methodIndex, 1.23 + const uint32_t paramCount, const nsXPTCVariant* s) 1.24 +{ 1.25 + int32_t result = 4; /* variant records do not include self pointer */ 1.26 + 1.27 + /* counts the number of bytes required by the argument stack, 1.28 + 64 bit integer, and double requires 8 bytes. All else requires 1.29 + 4 bytes. 1.30 + */ 1.31 + 1.32 + { 1.33 + uint32_t indx; 1.34 + for (indx = paramCount; indx > 0; --indx, ++s) 1.35 + { 1.36 + if (! s->IsPtrData()) 1.37 + { 1.38 + if (s->type == nsXPTType::T_I64 || s->type == nsXPTType::T_U64 || 1.39 + s->type == nsXPTType::T_DOUBLE) 1.40 + { 1.41 + /* 64 bit integer and double aligned on 8 byte boundaries */ 1.42 + result += (result & 4) + 8; 1.43 + continue; 1.44 + } 1.45 + } 1.46 + result += 4; /* all other cases use 4 bytes */ 1.47 + } 1.48 + } 1.49 + result -= 72; /* existing stack buffer is 72 bytes */ 1.50 + if (result < 0) 1.51 + return 0; 1.52 + { 1.53 + /* round up to 64 bytes boundary */ 1.54 + int32_t remainder = result & 63; 1.55 + return (remainder == 0) ? result : (result + 64 - remainder); 1.56 + } 1.57 +} 1.58 + 1.59 +extern "C" uint32_t 1.60 +invoke_copy_to_stack(uint32_t* d, 1.61 + const uint32_t paramCount, nsXPTCVariant* s) 1.62 +{ 1.63 + 1.64 + typedef struct 1.65 + { 1.66 + uint32_t hi; 1.67 + uint32_t lo; 1.68 + } DU; 1.69 + 1.70 + uint32_t* dest = d; 1.71 + nsXPTCVariant* source = s; 1.72 + /* we clobber param vars by copying stuff on stack, have to use local var */ 1.73 + 1.74 + uint32_t floatflags = 0; 1.75 + /* flag indicating which floating point registers to load */ 1.76 + 1.77 + uint32_t regwords = 1; /* register 26 is reserved for ptr to 'that' */ 1.78 + uint32_t indx; 1.79 + 1.80 + for (indx = paramCount; indx > 0; --indx, --dest, ++source) 1.81 + { 1.82 + if (source->IsPtrData()) 1.83 + { 1.84 + *((void**) dest) = source->ptr; 1.85 + ++regwords; 1.86 + continue; 1.87 + } 1.88 + switch (source->type) 1.89 + { 1.90 + case nsXPTType::T_I8 : *((int32_t*) dest) = source->val.i8; break; 1.91 + case nsXPTType::T_I16 : *((int32_t*) dest) = source->val.i16; break; 1.92 + case nsXPTType::T_I32 : *((int32_t*) dest) = source->val.i32; break; 1.93 + case nsXPTType::T_I64 : 1.94 + case nsXPTType::T_U64 : 1.95 + if (regwords & 1) 1.96 + { 1.97 + /* align on double word boundary */ 1.98 + --dest; 1.99 + ++regwords; 1.100 + } 1.101 + *((uint32_t*) dest) = ((DU *) source)->lo; 1.102 + *((uint32_t*) --dest) = ((DU *) source)->hi; 1.103 + /* big endian - hi word in low addr */ 1.104 + regwords += 2; 1.105 + continue; 1.106 + case nsXPTType::T_DOUBLE : 1.107 + if (regwords & 1) 1.108 + { 1.109 + /* align on double word boundary */ 1.110 + --dest; 1.111 + ++regwords; 1.112 + } 1.113 + switch (regwords) /* load double precision float register */ 1.114 + { 1.115 + case 2: 1.116 + floatflags |= 1; 1.117 + } 1.118 + *((uint32_t*) dest) = ((DU *) source)->lo; 1.119 + *((uint32_t*) --dest) = ((DU *) source)->hi; 1.120 + /* big endian - hi word in low addr */ 1.121 + regwords += 2; 1.122 + continue; 1.123 + case nsXPTType::T_FLOAT : 1.124 + switch (regwords) /* load single precision float register */ 1.125 + { 1.126 + case 1: 1.127 + floatflags |= 2; 1.128 + break; 1.129 + case 2: 1.130 + floatflags |= 4; 1.131 + break; 1.132 + case 3: 1.133 + floatflags |= 8; 1.134 + } 1.135 + *((float*) dest) = source->val.f; 1.136 + break; 1.137 + case nsXPTType::T_U8 : *((uint32_t*) (dest)) = source->val.u8; break; 1.138 + case nsXPTType::T_U16 : *((uint32_t*) (dest)) = source->val.u16; break; 1.139 + case nsXPTType::T_U32 : *((uint32_t*) (dest)) = source->val.u32; break; 1.140 + case nsXPTType::T_BOOL : *((uint32_t*) (dest)) = source->val.b; break; 1.141 + case nsXPTType::T_CHAR : *((uint32_t*) (dest)) = source->val.c; break; 1.142 + case nsXPTType::T_WCHAR : *((int32_t*) (dest)) = source->val.wc; break; 1.143 + 1.144 + default: 1.145 + // all the others are plain pointer types 1.146 + *((void**) dest) = source->val.p; 1.147 + } 1.148 + ++regwords; 1.149 + } 1.150 + return floatflags; 1.151 +} 1.152 +