xpcom/reflect/xptcall/src/md/unix/xptcinvoke_pa32.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1
michael@0 2 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 3 *
michael@0 4 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "xptcprivate.h"
michael@0 9
michael@0 10 #if _HPUX
michael@0 11 #error "This code is for HP-PA RISC 32 bit mode only"
michael@0 12 #endif
michael@0 13
michael@0 14 #include <alloca.h>
michael@0 15
michael@0 16 typedef unsigned nsXPCVariant;
michael@0 17
michael@0 18 extern "C" int32_t
michael@0 19 invoke_count_bytes(nsISupports* that, const uint32_t methodIndex,
michael@0 20 const uint32_t paramCount, const nsXPTCVariant* s)
michael@0 21 {
michael@0 22 int32_t result = 4; /* variant records do not include self pointer */
michael@0 23
michael@0 24 /* counts the number of bytes required by the argument stack,
michael@0 25 64 bit integer, and double requires 8 bytes. All else requires
michael@0 26 4 bytes.
michael@0 27 */
michael@0 28
michael@0 29 {
michael@0 30 uint32_t indx;
michael@0 31 for (indx = paramCount; indx > 0; --indx, ++s)
michael@0 32 {
michael@0 33 if (! s->IsPtrData())
michael@0 34 {
michael@0 35 if (s->type == nsXPTType::T_I64 || s->type == nsXPTType::T_U64 ||
michael@0 36 s->type == nsXPTType::T_DOUBLE)
michael@0 37 {
michael@0 38 /* 64 bit integer and double aligned on 8 byte boundaries */
michael@0 39 result += (result & 4) + 8;
michael@0 40 continue;
michael@0 41 }
michael@0 42 }
michael@0 43 result += 4; /* all other cases use 4 bytes */
michael@0 44 }
michael@0 45 }
michael@0 46 result -= 72; /* existing stack buffer is 72 bytes */
michael@0 47 if (result < 0)
michael@0 48 return 0;
michael@0 49 {
michael@0 50 /* round up to 64 bytes boundary */
michael@0 51 int32_t remainder = result & 63;
michael@0 52 return (remainder == 0) ? result : (result + 64 - remainder);
michael@0 53 }
michael@0 54 }
michael@0 55
michael@0 56 extern "C" uint32_t
michael@0 57 invoke_copy_to_stack(uint32_t* d,
michael@0 58 const uint32_t paramCount, nsXPTCVariant* s)
michael@0 59 {
michael@0 60
michael@0 61 typedef struct
michael@0 62 {
michael@0 63 uint32_t hi;
michael@0 64 uint32_t lo;
michael@0 65 } DU;
michael@0 66
michael@0 67 uint32_t* dest = d;
michael@0 68 nsXPTCVariant* source = s;
michael@0 69 /* we clobber param vars by copying stuff on stack, have to use local var */
michael@0 70
michael@0 71 uint32_t floatflags = 0;
michael@0 72 /* flag indicating which floating point registers to load */
michael@0 73
michael@0 74 uint32_t regwords = 1; /* register 26 is reserved for ptr to 'that' */
michael@0 75 uint32_t indx;
michael@0 76
michael@0 77 for (indx = paramCount; indx > 0; --indx, --dest, ++source)
michael@0 78 {
michael@0 79 if (source->IsPtrData())
michael@0 80 {
michael@0 81 *((void**) dest) = source->ptr;
michael@0 82 ++regwords;
michael@0 83 continue;
michael@0 84 }
michael@0 85 switch (source->type)
michael@0 86 {
michael@0 87 case nsXPTType::T_I8 : *((int32_t*) dest) = source->val.i8; break;
michael@0 88 case nsXPTType::T_I16 : *((int32_t*) dest) = source->val.i16; break;
michael@0 89 case nsXPTType::T_I32 : *((int32_t*) dest) = source->val.i32; break;
michael@0 90 case nsXPTType::T_I64 :
michael@0 91 case nsXPTType::T_U64 :
michael@0 92 if (regwords & 1)
michael@0 93 {
michael@0 94 /* align on double word boundary */
michael@0 95 --dest;
michael@0 96 ++regwords;
michael@0 97 }
michael@0 98 *((uint32_t*) dest) = ((DU *) source)->lo;
michael@0 99 *((uint32_t*) --dest) = ((DU *) source)->hi;
michael@0 100 /* big endian - hi word in low addr */
michael@0 101 regwords += 2;
michael@0 102 continue;
michael@0 103 case nsXPTType::T_DOUBLE :
michael@0 104 if (regwords & 1)
michael@0 105 {
michael@0 106 /* align on double word boundary */
michael@0 107 --dest;
michael@0 108 ++regwords;
michael@0 109 }
michael@0 110 switch (regwords) /* load double precision float register */
michael@0 111 {
michael@0 112 case 2:
michael@0 113 floatflags |= 1;
michael@0 114 }
michael@0 115 *((uint32_t*) dest) = ((DU *) source)->lo;
michael@0 116 *((uint32_t*) --dest) = ((DU *) source)->hi;
michael@0 117 /* big endian - hi word in low addr */
michael@0 118 regwords += 2;
michael@0 119 continue;
michael@0 120 case nsXPTType::T_FLOAT :
michael@0 121 switch (regwords) /* load single precision float register */
michael@0 122 {
michael@0 123 case 1:
michael@0 124 floatflags |= 2;
michael@0 125 break;
michael@0 126 case 2:
michael@0 127 floatflags |= 4;
michael@0 128 break;
michael@0 129 case 3:
michael@0 130 floatflags |= 8;
michael@0 131 }
michael@0 132 *((float*) dest) = source->val.f;
michael@0 133 break;
michael@0 134 case nsXPTType::T_U8 : *((uint32_t*) (dest)) = source->val.u8; break;
michael@0 135 case nsXPTType::T_U16 : *((uint32_t*) (dest)) = source->val.u16; break;
michael@0 136 case nsXPTType::T_U32 : *((uint32_t*) (dest)) = source->val.u32; break;
michael@0 137 case nsXPTType::T_BOOL : *((uint32_t*) (dest)) = source->val.b; break;
michael@0 138 case nsXPTType::T_CHAR : *((uint32_t*) (dest)) = source->val.c; break;
michael@0 139 case nsXPTType::T_WCHAR : *((int32_t*) (dest)) = source->val.wc; break;
michael@0 140
michael@0 141 default:
michael@0 142 // all the others are plain pointer types
michael@0 143 *((void**) dest) = source->val.p;
michael@0 144 }
michael@0 145 ++regwords;
michael@0 146 }
michael@0 147 return floatflags;
michael@0 148 }
michael@0 149

mercurial