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 | #include "xptcprivate.h" |
michael@0 | 7 | #include "xptiprivate.h" |
michael@0 | 8 | |
michael@0 | 9 | #ifndef __AARCH64EL__ |
michael@0 | 10 | #error "Only little endian compatibility was tested" |
michael@0 | 11 | #endif |
michael@0 | 12 | |
michael@0 | 13 | /* |
michael@0 | 14 | * This is for AArch64 ABI |
michael@0 | 15 | * |
michael@0 | 16 | * When we're called, the "gp" registers are stored in gprData and |
michael@0 | 17 | * the "fp" registers are stored in fprData. Each array has 8 regs |
michael@0 | 18 | * but first reg in gprData is a placeholder for 'self'. |
michael@0 | 19 | */ |
michael@0 | 20 | extern "C" nsresult |
michael@0 | 21 | PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint64_t* args, |
michael@0 | 22 | uint64_t *gprData, double *fprData) |
michael@0 | 23 | { |
michael@0 | 24 | #define PARAM_BUFFER_COUNT 16 |
michael@0 | 25 | #define PARAM_GPR_COUNT 8 |
michael@0 | 26 | #define PARAM_FPR_COUNT 8 |
michael@0 | 27 | |
michael@0 | 28 | nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; |
michael@0 | 29 | nsXPTCMiniVariant* dispatchParams = NULL; |
michael@0 | 30 | const nsXPTMethodInfo* info; |
michael@0 | 31 | nsresult result = NS_ERROR_FAILURE; |
michael@0 | 32 | |
michael@0 | 33 | NS_ASSERTION(self,"no self"); |
michael@0 | 34 | |
michael@0 | 35 | self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); |
michael@0 | 36 | NS_ASSERTION(info,"no method info"); |
michael@0 | 37 | |
michael@0 | 38 | uint32_t paramCount = info->GetParamCount(); |
michael@0 | 39 | |
michael@0 | 40 | // setup variant array pointer |
michael@0 | 41 | if (paramCount > PARAM_BUFFER_COUNT) { |
michael@0 | 42 | dispatchParams = new nsXPTCMiniVariant[paramCount]; |
michael@0 | 43 | } else { |
michael@0 | 44 | dispatchParams = paramBuffer; |
michael@0 | 45 | } |
michael@0 | 46 | NS_ASSERTION(dispatchParams,"no place for params"); |
michael@0 | 47 | |
michael@0 | 48 | uint64_t* ap = args; |
michael@0 | 49 | uint32_t next_gpr = 1; // skip first arg which is 'self' |
michael@0 | 50 | uint32_t next_fpr = 0; |
michael@0 | 51 | for (uint32_t i = 0; i < paramCount; i++) { |
michael@0 | 52 | const nsXPTParamInfo& param = info->GetParam(i); |
michael@0 | 53 | const nsXPTType& type = param.GetType(); |
michael@0 | 54 | nsXPTCMiniVariant* dp = &dispatchParams[i]; |
michael@0 | 55 | |
michael@0 | 56 | if (param.IsOut() || !type.IsArithmetic()) { |
michael@0 | 57 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 58 | dp->val.p = (void*)gprData[next_gpr++]; |
michael@0 | 59 | } else { |
michael@0 | 60 | dp->val.p = (void*)*ap++; |
michael@0 | 61 | } |
michael@0 | 62 | continue; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | switch (type) { |
michael@0 | 66 | case nsXPTType::T_I8: |
michael@0 | 67 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 68 | dp->val.i8 = (int8_t)gprData[next_gpr++]; |
michael@0 | 69 | } else { |
michael@0 | 70 | dp->val.i8 = (int8_t)*ap++; |
michael@0 | 71 | } |
michael@0 | 72 | break; |
michael@0 | 73 | |
michael@0 | 74 | case nsXPTType::T_I16: |
michael@0 | 75 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 76 | dp->val.i16 = (int16_t)gprData[next_gpr++]; |
michael@0 | 77 | } else { |
michael@0 | 78 | dp->val.i16 = (int16_t)*ap++; |
michael@0 | 79 | } |
michael@0 | 80 | break; |
michael@0 | 81 | |
michael@0 | 82 | case nsXPTType::T_I32: |
michael@0 | 83 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 84 | dp->val.i32 = (int32_t)gprData[next_gpr++]; |
michael@0 | 85 | } else { |
michael@0 | 86 | dp->val.i32 = (int32_t)*ap++; |
michael@0 | 87 | } |
michael@0 | 88 | break; |
michael@0 | 89 | |
michael@0 | 90 | case nsXPTType::T_I64: |
michael@0 | 91 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 92 | dp->val.i64 = (int64_t)gprData[next_gpr++]; |
michael@0 | 93 | } else { |
michael@0 | 94 | dp->val.i64 = (int64_t)*ap++; |
michael@0 | 95 | } |
michael@0 | 96 | break; |
michael@0 | 97 | |
michael@0 | 98 | case nsXPTType::T_U8: |
michael@0 | 99 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 100 | dp->val.u8 = (uint8_t)gprData[next_gpr++]; |
michael@0 | 101 | } else { |
michael@0 | 102 | dp->val.u8 = (uint8_t)*ap++; |
michael@0 | 103 | } |
michael@0 | 104 | break; |
michael@0 | 105 | |
michael@0 | 106 | case nsXPTType::T_U16: |
michael@0 | 107 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 108 | dp->val.u16 = (uint16_t)gprData[next_gpr++]; |
michael@0 | 109 | } else { |
michael@0 | 110 | dp->val.u16 = (uint16_t)*ap++; |
michael@0 | 111 | } |
michael@0 | 112 | break; |
michael@0 | 113 | |
michael@0 | 114 | case nsXPTType::T_U32: |
michael@0 | 115 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 116 | dp->val.u32 = (uint32_t)gprData[next_gpr++]; |
michael@0 | 117 | } else { |
michael@0 | 118 | dp->val.u32 = (uint32_t)*ap++; |
michael@0 | 119 | } |
michael@0 | 120 | break; |
michael@0 | 121 | |
michael@0 | 122 | case nsXPTType::T_U64: |
michael@0 | 123 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 124 | dp->val.u64 = (uint64_t)gprData[next_gpr++]; |
michael@0 | 125 | } else { |
michael@0 | 126 | dp->val.u64 = (uint64_t)*ap++; |
michael@0 | 127 | } |
michael@0 | 128 | break; |
michael@0 | 129 | |
michael@0 | 130 | case nsXPTType::T_FLOAT: |
michael@0 | 131 | if (next_fpr < PARAM_FPR_COUNT) { |
michael@0 | 132 | memcpy(&dp->val.f, &fprData[next_fpr++], sizeof(dp->val.f)); |
michael@0 | 133 | } else { |
michael@0 | 134 | memcpy(&dp->val.f, ap++, sizeof(dp->val.f)); |
michael@0 | 135 | } |
michael@0 | 136 | break; |
michael@0 | 137 | |
michael@0 | 138 | case nsXPTType::T_DOUBLE: |
michael@0 | 139 | if (next_fpr < PARAM_FPR_COUNT) { |
michael@0 | 140 | memcpy(&dp->val.d, &fprData[next_fpr++], sizeof(dp->val.d)); |
michael@0 | 141 | } else { |
michael@0 | 142 | memcpy(&dp->val.d, ap++, sizeof(dp->val.d)); |
michael@0 | 143 | } |
michael@0 | 144 | break; |
michael@0 | 145 | |
michael@0 | 146 | case nsXPTType::T_BOOL: |
michael@0 | 147 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 148 | dp->val.b = (bool)gprData[next_gpr++]; |
michael@0 | 149 | } else { |
michael@0 | 150 | dp->val.b = (bool)*ap++; |
michael@0 | 151 | } |
michael@0 | 152 | break; |
michael@0 | 153 | |
michael@0 | 154 | case nsXPTType::T_CHAR: |
michael@0 | 155 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 156 | dp->val.c = (char)gprData[next_gpr++]; |
michael@0 | 157 | } else { |
michael@0 | 158 | dp->val.c = (char)*ap++; |
michael@0 | 159 | } |
michael@0 | 160 | break; |
michael@0 | 161 | |
michael@0 | 162 | case nsXPTType::T_WCHAR: |
michael@0 | 163 | if (next_gpr < PARAM_GPR_COUNT) { |
michael@0 | 164 | dp->val.wc = (wchar_t)gprData[next_gpr++]; |
michael@0 | 165 | } else { |
michael@0 | 166 | dp->val.wc = (wchar_t)*ap++; |
michael@0 | 167 | } |
michael@0 | 168 | break; |
michael@0 | 169 | |
michael@0 | 170 | default: |
michael@0 | 171 | NS_ASSERTION(0, "bad type"); |
michael@0 | 172 | break; |
michael@0 | 173 | } |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams); |
michael@0 | 177 | |
michael@0 | 178 | if (dispatchParams != paramBuffer) { |
michael@0 | 179 | delete [] dispatchParams; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | return result; |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | // Load w17 with the constant 'n' and branch to SharedStub(). |
michael@0 | 186 | # define STUB_ENTRY(n) \ |
michael@0 | 187 | __asm__ ( \ |
michael@0 | 188 | ".section \".text\" \n\t" \ |
michael@0 | 189 | ".align 2\n\t" \ |
michael@0 | 190 | ".if "#n" < 10 \n\t" \ |
michael@0 | 191 | ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t" \ |
michael@0 | 192 | ".hidden _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t" \ |
michael@0 | 193 | ".type _ZN14nsXPTCStubBase5Stub"#n"Ev,@function \n\n" \ |
michael@0 | 194 | "_ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t" \ |
michael@0 | 195 | ".elseif "#n" < 100 \n\t" \ |
michael@0 | 196 | ".globl _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t" \ |
michael@0 | 197 | ".hidden _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t" \ |
michael@0 | 198 | ".type _ZN14nsXPTCStubBase6Stub"#n"Ev,@function \n\n" \ |
michael@0 | 199 | "_ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t" \ |
michael@0 | 200 | ".elseif "#n" < 1000 \n\t" \ |
michael@0 | 201 | ".globl _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t" \ |
michael@0 | 202 | ".hidden _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t" \ |
michael@0 | 203 | ".type _ZN14nsXPTCStubBase7Stub"#n"Ev,@function \n\n" \ |
michael@0 | 204 | "_ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t" \ |
michael@0 | 205 | ".else \n\t" \ |
michael@0 | 206 | ".err \"stub number "#n" >= 1000 not yet supported\"\n" \ |
michael@0 | 207 | ".endif \n\t" \ |
michael@0 | 208 | "mov w17,#"#n" \n\t" \ |
michael@0 | 209 | "b SharedStub \n" \ |
michael@0 | 210 | ); |
michael@0 | 211 | |
michael@0 | 212 | #define SENTINEL_ENTRY(n) \ |
michael@0 | 213 | nsresult nsXPTCStubBase::Sentinel##n() \ |
michael@0 | 214 | { \ |
michael@0 | 215 | NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \ |
michael@0 | 216 | return NS_ERROR_NOT_IMPLEMENTED; \ |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | #include "xptcstubsdef.inc" |