Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | // Implement shared vtbl methods. |
michael@0 | 7 | |
michael@0 | 8 | #include "xptcprivate.h" |
michael@0 | 9 | |
michael@0 | 10 | // The Linux/PPC ABI (aka PPC/SYSV ABI) passes the first 8 integral |
michael@0 | 11 | // parameters and the first 8 floating point parameters in registers |
michael@0 | 12 | // (r3-r10 and f1-f8), no stack space is allocated for these by the |
michael@0 | 13 | // caller. The rest of the parameters are passed in the callers stack |
michael@0 | 14 | // area. The stack pointer has to retain 16-byte alignment, longlongs |
michael@0 | 15 | // and doubles are aligned on 8-byte boundaries. |
michael@0 | 16 | |
michael@0 | 17 | #define PARAM_BUFFER_COUNT 16 |
michael@0 | 18 | #define GPR_COUNT 8 |
michael@0 | 19 | #define FPR_COUNT 8 |
michael@0 | 20 | |
michael@0 | 21 | // PrepareAndDispatch() is called by SharedStub() and calls the actual method. |
michael@0 | 22 | // |
michael@0 | 23 | // - 'args[]' contains the arguments passed on stack |
michael@0 | 24 | // - 'gprData[]' contains the arguments passed in integer registers |
michael@0 | 25 | // - 'fprData[]' contains the arguments passed in floating point registers |
michael@0 | 26 | // |
michael@0 | 27 | // The parameters are mapped into an array of type 'nsXPTCMiniVariant' |
michael@0 | 28 | // and then the method gets called. |
michael@0 | 29 | |
michael@0 | 30 | extern "C" nsresult ATTRIBUTE_USED |
michael@0 | 31 | PrepareAndDispatch(nsXPTCStubBase* self, |
michael@0 | 32 | uint32_t methodIndex, |
michael@0 | 33 | uint32_t* args, |
michael@0 | 34 | uint32_t *gprData, |
michael@0 | 35 | double *fprData) |
michael@0 | 36 | { |
michael@0 | 37 | nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; |
michael@0 | 38 | nsXPTCMiniVariant* dispatchParams = nullptr; |
michael@0 | 39 | nsIInterfaceInfo* iface_info = nullptr; |
michael@0 | 40 | const nsXPTMethodInfo* info; |
michael@0 | 41 | uint32_t paramCount; |
michael@0 | 42 | uint32_t i; |
michael@0 | 43 | nsresult result = NS_ERROR_FAILURE; |
michael@0 | 44 | |
michael@0 | 45 | NS_ASSERTION(self,"no self"); |
michael@0 | 46 | |
michael@0 | 47 | self->GetInterfaceInfo(&iface_info); |
michael@0 | 48 | NS_ASSERTION(iface_info,"no interface info"); |
michael@0 | 49 | if (! iface_info) |
michael@0 | 50 | return NS_ERROR_UNEXPECTED; |
michael@0 | 51 | |
michael@0 | 52 | iface_info->GetMethodInfo(uint16_t(methodIndex), &info); |
michael@0 | 53 | NS_ASSERTION(info,"no method info"); |
michael@0 | 54 | if (! info) |
michael@0 | 55 | return NS_ERROR_UNEXPECTED; |
michael@0 | 56 | |
michael@0 | 57 | paramCount = info->GetParamCount(); |
michael@0 | 58 | |
michael@0 | 59 | // setup variant array pointer |
michael@0 | 60 | if(paramCount > PARAM_BUFFER_COUNT) |
michael@0 | 61 | dispatchParams = new nsXPTCMiniVariant[paramCount]; |
michael@0 | 62 | else |
michael@0 | 63 | dispatchParams = paramBuffer; |
michael@0 | 64 | |
michael@0 | 65 | NS_ASSERTION(dispatchParams,"no place for params"); |
michael@0 | 66 | if (! dispatchParams) |
michael@0 | 67 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 68 | |
michael@0 | 69 | uint32_t* ap = args; |
michael@0 | 70 | uint32_t gpr = 1; // skip one GPR register |
michael@0 | 71 | uint32_t fpr = 0; |
michael@0 | 72 | uint32_t tempu32; |
michael@0 | 73 | uint64_t tempu64; |
michael@0 | 74 | |
michael@0 | 75 | for(i = 0; i < paramCount; i++) { |
michael@0 | 76 | const nsXPTParamInfo& param = info->GetParam(i); |
michael@0 | 77 | const nsXPTType& type = param.GetType(); |
michael@0 | 78 | nsXPTCMiniVariant* dp = &dispatchParams[i]; |
michael@0 | 79 | |
michael@0 | 80 | if (!param.IsOut() && type == nsXPTType::T_DOUBLE) { |
michael@0 | 81 | if (fpr < FPR_COUNT) |
michael@0 | 82 | dp->val.d = fprData[fpr++]; |
michael@0 | 83 | else { |
michael@0 | 84 | if ((uint32_t) ap & 4) ap++; // doubles are 8-byte aligned on stack |
michael@0 | 85 | dp->val.d = *(double*) ap; |
michael@0 | 86 | ap += 2; |
michael@0 | 87 | if (gpr < GPR_COUNT) |
michael@0 | 88 | gpr += 2; |
michael@0 | 89 | } |
michael@0 | 90 | continue; |
michael@0 | 91 | } |
michael@0 | 92 | else if (!param.IsOut() && type == nsXPTType::T_FLOAT) { |
michael@0 | 93 | if (fpr < FPR_COUNT) |
michael@0 | 94 | dp->val.f = (float) fprData[fpr++]; // in registers floats are passed as doubles |
michael@0 | 95 | else { |
michael@0 | 96 | dp->val.f = *(float*) ap; |
michael@0 | 97 | ap += 1; |
michael@0 | 98 | if (gpr < GPR_COUNT) |
michael@0 | 99 | gpr += 1; |
michael@0 | 100 | } |
michael@0 | 101 | continue; |
michael@0 | 102 | } |
michael@0 | 103 | else if (!param.IsOut() && (type == nsXPTType::T_I64 |
michael@0 | 104 | || type == nsXPTType::T_U64)) { |
michael@0 | 105 | if (gpr & 1) gpr++; // longlongs are aligned in odd/even register pairs, eg. r5/r6 |
michael@0 | 106 | if ((gpr + 1) < GPR_COUNT) { |
michael@0 | 107 | tempu64 = *(uint64_t*) &gprData[gpr]; |
michael@0 | 108 | gpr += 2; |
michael@0 | 109 | } |
michael@0 | 110 | else { |
michael@0 | 111 | if ((uint32_t) ap & 4) ap++; // longlongs are 8-byte aligned on stack |
michael@0 | 112 | tempu64 = *(uint64_t*) ap; |
michael@0 | 113 | ap += 2; |
michael@0 | 114 | } |
michael@0 | 115 | } |
michael@0 | 116 | else { |
michael@0 | 117 | if (gpr < GPR_COUNT) |
michael@0 | 118 | tempu32 = gprData[gpr++]; |
michael@0 | 119 | else |
michael@0 | 120 | tempu32 = *ap++; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | if(param.IsOut() || !type.IsArithmetic()) { |
michael@0 | 124 | dp->val.p = (void*) tempu32; |
michael@0 | 125 | continue; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | switch(type) { |
michael@0 | 129 | case nsXPTType::T_I8: dp->val.i8 = (int8_t) tempu32; break; |
michael@0 | 130 | case nsXPTType::T_I16: dp->val.i16 = (int16_t) tempu32; break; |
michael@0 | 131 | case nsXPTType::T_I32: dp->val.i32 = (int32_t) tempu32; break; |
michael@0 | 132 | case nsXPTType::T_I64: dp->val.i64 = (int64_t) tempu64; break; |
michael@0 | 133 | case nsXPTType::T_U8: dp->val.u8 = (uint8_t) tempu32; break; |
michael@0 | 134 | case nsXPTType::T_U16: dp->val.u16 = (uint16_t) tempu32; break; |
michael@0 | 135 | case nsXPTType::T_U32: dp->val.u32 = (uint32_t) tempu32; break; |
michael@0 | 136 | case nsXPTType::T_U64: dp->val.u64 = (uint64_t) tempu64; break; |
michael@0 | 137 | case nsXPTType::T_BOOL: dp->val.b = (bool) tempu32; break; |
michael@0 | 138 | case nsXPTType::T_CHAR: dp->val.c = (char) tempu32; break; |
michael@0 | 139 | case nsXPTType::T_WCHAR: dp->val.wc = (wchar_t) tempu32; break; |
michael@0 | 140 | |
michael@0 | 141 | default: |
michael@0 | 142 | NS_ERROR("bad type"); |
michael@0 | 143 | break; |
michael@0 | 144 | } |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | result = self->CallMethod((uint16_t) methodIndex, info, dispatchParams); |
michael@0 | 148 | |
michael@0 | 149 | NS_RELEASE(iface_info); |
michael@0 | 150 | |
michael@0 | 151 | if (dispatchParams != paramBuffer) |
michael@0 | 152 | delete [] dispatchParams; |
michael@0 | 153 | |
michael@0 | 154 | return result; |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | // Load r11 with the constant 'n' and branch to SharedStub(). |
michael@0 | 158 | // |
michael@0 | 159 | // XXX Yes, it's ugly that we're relying on gcc's name-mangling here; |
michael@0 | 160 | // however, it's quick, dirty, and'll break when the ABI changes on |
michael@0 | 161 | // us, which is what we want ;-). |
michael@0 | 162 | |
michael@0 | 163 | #define STUB_ENTRY(n) \ |
michael@0 | 164 | __asm__ ( \ |
michael@0 | 165 | ".section \".text\" \n\t" \ |
michael@0 | 166 | ".align 2 \n\t" \ |
michael@0 | 167 | ".globl Stub"#n"__14nsXPTCStubBase \n\t" \ |
michael@0 | 168 | ".type Stub"#n"__14nsXPTCStubBase,@function \n\n" \ |
michael@0 | 169 | \ |
michael@0 | 170 | "Stub"#n"__14nsXPTCStubBase: \n\t" \ |
michael@0 | 171 | "li 11,"#n" \n\t" \ |
michael@0 | 172 | "b SharedStub@local \n" \ |
michael@0 | 173 | ); |
michael@0 | 174 | |
michael@0 | 175 | #define SENTINEL_ENTRY(n) \ |
michael@0 | 176 | nsresult nsXPTCStubBase::Sentinel##n() \ |
michael@0 | 177 | { \ |
michael@0 | 178 | NS_ERROR("nsXPTCStubBase::Sentinel called"); \ |
michael@0 | 179 | return NS_ERROR_NOT_IMPLEMENTED; \ |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | #include "xptcstubsdef.inc" |