Fixed quad-word alignment issues, vTable layout problems.

This commit is contained in:
rogerl%netscape.com 1999-05-07 21:42:28 +00:00
Родитель 7e2d3e9deb
Коммит 221629a4f8
8 изменённых файлов: 55 добавлений и 321 удалений

Просмотреть файл

@ -25,8 +25,8 @@
*/
XPTC_InvokeByIndex:
save %sp,-(64 + 8),%sp ! room for the register window and
! struct pointer, rounded up to 0 % 8
save %sp,-(64 + 16),%sp ! room for the register window and
! struct pointer, rounded up to 0 % 16
mov %i2,%o0 ! paramCount
mov %i3,%o1 ! params
call invoke_count_words ! returns the required stack size in %o0
@ -44,9 +44,12 @@ XPTC_InvokeByIndex:
!
! calculate the target address from the vtable
!
sll %i1,2,%l0 ! index *= 4
sll %i1,3,%l0 ! index *= 8
add %l0,12,%l0 ! += 12 (there's 1 extra entry in the vTable)
! and we need the fn ptr which is the second
! half of the 8 byte vTable entry
ld [%i0],%l1 ! *that --> address of vtable
ld [%l0 + %l1],%l0 ! that->vtable[index * 4] --> target address
ld [%l0 + %l1],%l0 ! that->vtable[index * 8 + 12] --> target address
!
! set 'that' as the 'this' pointer and then load the next arguments
! into the outgoing registers

Просмотреть файл

@ -1,119 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Platform specific code to invoke XPCOM methods on native objects */
#include "xptcprivate.h"
#ifndef sparc
#error "This code is for Sparc only"
#endif
typedef unsigned nsXPCVariant;
extern "C" PRUint32
invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
{
PRUint32 result = 0;
for(PRUint32 i = 0; i < paramCount; i++, s++)
{
if(s->IsPtrData())
{
result++;
continue;
}
switch(s->type)
{
case nsXPTType::T_I8 :
case nsXPTType::T_I16 :
case nsXPTType::T_I32 :
result++;
break;
case nsXPTType::T_I64 :
result+=2;
break;
case nsXPTType::T_U8 :
case nsXPTType::T_U16 :
case nsXPTType::T_U32 :
result++;
break;
case nsXPTType::T_U64 :
result+=2;
break;
case nsXPTType::T_FLOAT :
result++;
break;
case nsXPTType::T_DOUBLE :
result+=2;
break;
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
result++;
break;
default:
// all the others are plain pointer types
result++;
break;
}
}
return result;
}
extern "C" void
invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s)
{
/*
We need to copy the parameters for this function to locals and use them
from there since the parameters occupy the same stack space as the stack
we're trying to populate.
*/
uint32 *l_d = d;
nsXPTCVariant *l_s = s;
uint32 l_paramCount = paramCount;
for(uint32 i = 0; i < l_paramCount; i++, l_d++, l_s++)
{
if(l_s->IsPtrData())
{
*((void**)l_d) = l_s->ptr;
continue;
}
switch(l_s->type)
{
case nsXPTType::T_I8 : *((int8*) l_d) = l_s->val.i8; break;
case nsXPTType::T_I16 : *((int16*) l_d) = l_s->val.i16; break;
case nsXPTType::T_I32 : *((int32*) l_d) = l_s->val.i32; break;
case nsXPTType::T_I64 : *((int64*) l_d) = l_s->val.i64; l_d++; break;
case nsXPTType::T_U8 : *((uint8*) l_d) = l_s->val.u8; break;
case nsXPTType::T_U16 : *((uint16*) l_d) = l_s->val.u16; break;
case nsXPTType::T_U32 : *((uint32*) l_d) = l_s->val.u32; break;
case nsXPTType::T_U64 : *((uint64*) l_d) = l_s->val.u64; l_d++; break;
case nsXPTType::T_FLOAT : *((float*) l_d) = l_s->val.f; break;
case nsXPTType::T_DOUBLE : *((double*) l_d) = l_s->val.d; l_d++; break;
case nsXPTType::T_BOOL : *((PRBool*) l_d) = l_s->val.b; break;
case nsXPTType::T_CHAR : *((char*) l_d) = l_s->val.c; break;
case nsXPTType::T_WCHAR : *((wchar_t*)l_d) = l_s->val.wc; break;
default:
// all the others are plain pointer types
*((void**)l_d) = l_s->val.p;
break;
}
}
}

Просмотреть файл

@ -1,58 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
.global SharedStub
/*
in the frame for the function that called SharedStub are the
rest of the parameters we need
*/
SharedStub:
! we don't create a new frame yet, but work within the frame of the calling
! function to give ourselves the other parameters we want
mov %o0, %o1 ! shuffle the index up to 2nd place
mov %i0, %o0 ! the original 'this'
add %fp, 72, %o2 ! previous stack top adjusted to the first argument slot (beyond 'this')
! save off the original incoming parameters that arrived in
! registers, the ABI guarantees the space for us to do this
st %i1, [%fp + 72]
st %i2, [%fp + 76]
st %i3, [%fp + 80]
st %i4, [%fp + 84]
st %i5, [%fp + 88]
! now we can build our own stack frame
save %sp,-(64 + 8),%sp ! room for the register window and
! struct pointer, rounded up to 0 % 8
! our function now appears to have been called
! as SharedStub(nsISupports* that, PRUint32 index, PRUint32* args)
! so we can just copy these through
mov %i0, %o0
mov %i1, %o1
mov %i2, %o2
call PrepareAndDispatch
nop
mov %o0,%i0 ! propogate return value
b .LL1
nop
.LL1:
ret
restore

Просмотреть файл

@ -1,116 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Implement shared vtbl methods. */
#include "xptcprivate.h"
#ifdef sparc
extern "C" nsresult
PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, uint32* args)
{
#define PARAM_BUFFER_COUNT 16
nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
nsXPTCMiniVariant* dispatchParams = NULL;
nsIInterfaceInfo* iface_info = NULL;
const nsXPTMethodInfo* info;
PRUint8 paramCount;
PRUint8 i;
nsresult result = NS_ERROR_FAILURE;
NS_ASSERTION(self,"no self");
self->GetInterfaceInfo(&iface_info);
NS_ASSERTION(iface_info,"no interface info");
iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
NS_ASSERTION(info,"no interface info");
paramCount = info->GetParamCount();
// setup variant array pointer
if(paramCount > PARAM_BUFFER_COUNT)
dispatchParams = new nsXPTCMiniVariant[paramCount];
else
dispatchParams = paramBuffer;
NS_ASSERTION(dispatchParams,"no place for params");
PRUint32* ap = args;
for(i = 0; i < paramCount; i++, ap++)
{
const nsXPTParamInfo& param = info->GetParam(i);
const nsXPTType& type = param.GetType();
nsXPTCMiniVariant* dp = &dispatchParams[i];
if(param.IsOut() || !type.IsArithmetic())
{
dp->val.p = (void*) *ap;
continue;
}
// else
switch(type)
{
case nsXPTType::T_I8 : dp->val.i8 = *((PRInt8*) ap); break;
case nsXPTType::T_I16 : dp->val.i16 = *((PRInt16*) ap); break;
case nsXPTType::T_I32 : dp->val.i32 = *((PRInt32*) ap); break;
case nsXPTType::T_I64 : dp->val.i64 = *((PRInt64*) ap); ap++; break;
case nsXPTType::T_U8 : dp->val.u8 = *((PRUint8*) ap); break;
case nsXPTType::T_U16 : dp->val.u16 = *((PRUint16*)ap); break;
case nsXPTType::T_U32 : dp->val.u32 = *((PRUint32*)ap); break;
case nsXPTType::T_U64 : dp->val.u64 = *((PRUint64*)ap); ap++; break;
case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break;
case nsXPTType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break;
case nsXPTType::T_BOOL : dp->val.b = *((PRBool*) ap); break;
case nsXPTType::T_CHAR : dp->val.c = *((char*) ap); break;
case nsXPTType::T_WCHAR : dp->val.wc = *((wchar_t*) ap); break;
default:
NS_ASSERTION(0, "bad type");
break;
}
}
result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
NS_RELEASE(iface_info);
if(dispatchParams != paramBuffer)
delete [] dispatchParams;
return result;
}
extern "C" int SharedStub(int);
#define STUB_ENTRY(n) \
nsresult nsXPTCStubBase::Stub##n() \
{ \
return SharedStub(n); \
} \
#define SENTINEL_ENTRY(n) \
nsresult nsXPTCStubBase::Sentinel##n() \
{ \
NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
return NS_ERROR_NOT_IMPLEMENTED; \
}
#include "xptcstubsdef.inc"
#endif

Просмотреть файл

@ -25,8 +25,8 @@
*/
XPTC_InvokeByIndex:
save %sp,-(64 + 8),%sp ! room for the register window and
! struct pointer, rounded up to 0 % 8
save %sp,-(64 + 16),%sp ! room for the register window and
! struct pointer, rounded up to 0 % 16
mov %i2,%o0 ! paramCount
mov %i3,%o1 ! params
call invoke_count_words ! returns the required stack size in %o0
@ -44,9 +44,12 @@ XPTC_InvokeByIndex:
!
! calculate the target address from the vtable
!
sll %i1,2,%l0 ! index *= 4
sll %i1,3,%l0 ! index *= 8
add %l0,12,%l0 ! += 12 (there's 1 extra entry in the vTable)
! and we need the fn ptr which is the second
! half of the 8 byte vTable entry
ld [%i0],%l1 ! *that --> address of vtable
ld [%l0 + %l1],%l0 ! that->vtable[index * 4] --> target address
ld [%l0 + %l1],%l0 ! that->vtable[index * 8 + 12] --> target address
!
! set 'that' as the 'this' pointer and then load the next arguments
! into the outgoing registers

Просмотреть файл

@ -72,6 +72,9 @@ invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
break;
}
}
// nuts, I know there's a cooler way of doing this, but it's late
// now and it'll probably come to me in the morning.
if (result & 0x3) result += 4 - (result & 0x3); // ensure q-word alignment
return result;
}
@ -87,6 +90,12 @@ invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s)
nsXPTCVariant *l_s = s;
uint32 l_paramCount = paramCount;
typedef struct {
uint32 hi;
uint32 lo;
} DU; // have to move 64 bit entities as 32 bit halves since
// stack slots are not guaranteed 16 byte aligned
for(uint32 i = 0; i < l_paramCount; i++, l_d++, l_s++)
{
if(l_s->IsPtrData())
@ -96,19 +105,21 @@ invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s)
}
switch(l_s->type)
{
case nsXPTType::T_I8 : *((int8*) l_d) = l_s->val.i8; break;
case nsXPTType::T_I16 : *((int16*) l_d) = l_s->val.i16; break;
case nsXPTType::T_I8 : *((int32*) l_d) = l_s->val.i8; break;
case nsXPTType::T_I16 : *((int32*) l_d) = l_s->val.i16; break;
case nsXPTType::T_I32 : *((int32*) l_d) = l_s->val.i32; break;
case nsXPTType::T_I64 : *((int64*) l_d) = l_s->val.i64; l_d++; break;
case nsXPTType::T_U8 : *((uint8*) l_d) = l_s->val.u8; break;
case nsXPTType::T_U16 : *((uint16*) l_d) = l_s->val.u16; break;
case nsXPTType::T_I64 :
case nsXPTType::T_U64 :
case nsXPTType::T_DOUBLE : *((uint32*) l_d++) = ((DU *)l_s)->hi;
*((uint32*) l_d) = ((DU *)l_s)->lo;
break;
case nsXPTType::T_U8 : *((uint32*) l_d) = l_s->val.u8; break;
case nsXPTType::T_U16 : *((uint32*) l_d) = l_s->val.u16; break;
case nsXPTType::T_U32 : *((uint32*) l_d) = l_s->val.u32; break;
case nsXPTType::T_U64 : *((uint64*) l_d) = l_s->val.u64; l_d++; break;
case nsXPTType::T_FLOAT : *((float*) l_d) = l_s->val.f; break;
case nsXPTType::T_DOUBLE : *((double*) l_d) = l_s->val.d; l_d++; break;
case nsXPTType::T_BOOL : *((PRBool*) l_d) = l_s->val.b; break;
case nsXPTType::T_CHAR : *((char*) l_d) = l_s->val.c; break;
case nsXPTType::T_WCHAR : *((wchar_t*)l_d) = l_s->val.wc; break;
case nsXPTType::T_CHAR : *((uint32*) l_d) = l_s->val.c; break;
case nsXPTType::T_WCHAR : *((int32*)l_d) = l_s->val.wc; break;
default:
// all the others are plain pointer types
*((void**)l_d) = l_s->val.p;

Просмотреть файл

@ -39,8 +39,8 @@ SharedStub:
st %i4, [%fp + 84]
st %i5, [%fp + 88]
! now we can build our own stack frame
save %sp,-(64 + 8),%sp ! room for the register window and
! struct pointer, rounded up to 0 % 8
save %sp,-(64 + 16),%sp ! room for the register window and
! struct pointer, rounded up to 0 % 16
! our function now appears to have been called
! as SharedStub(nsISupports* that, PRUint32 index, PRUint32* args)
! so we can just copy these through

Просмотреть файл

@ -25,6 +25,13 @@
extern "C" nsresult
PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, uint32* args)
{
typedef struct {
uint32 hi;
uint32 lo;
} DU; // have to move 64 bit entities as 32 bit halves since
// stack slots are not guaranteed 16 byte aligned
#define PARAM_BUFFER_COUNT 16
nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
@ -67,19 +74,22 @@ PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, uint32* args)
// else
switch(type)
{
case nsXPTType::T_I8 : dp->val.i8 = *((PRInt8*) ap); break;
case nsXPTType::T_I16 : dp->val.i16 = *((PRInt16*) ap); break;
case nsXPTType::T_I8 : dp->val.i8 = *((PRInt32*) ap); break;
case nsXPTType::T_I16 : dp->val.i16 = *((PRInt32*) ap); break;
case nsXPTType::T_I32 : dp->val.i32 = *((PRInt32*) ap); break;
case nsXPTType::T_I64 : dp->val.i64 = *((PRInt64*) ap); ap++; break;
case nsXPTType::T_U8 : dp->val.u8 = *((PRUint8*) ap); break;
case nsXPTType::T_U16 : dp->val.u16 = *((PRUint16*)ap); break;
case nsXPTType::T_DOUBLE :
case nsXPTType::T_U64 :
case nsXPTType::T_I64 : ((DU *)dp)->hi = ((DU *)ap)->hi;
((DU *)dp)->lo = ((DU *)ap)->lo;
ap++;
break;
case nsXPTType::T_U8 : dp->val.u8 = *((PRUint32*) ap); break;
case nsXPTType::T_U16 : dp->val.u16 = *((PRUint32*)ap); break;
case nsXPTType::T_U32 : dp->val.u32 = *((PRUint32*)ap); break;
case nsXPTType::T_U64 : dp->val.u64 = *((PRUint64*)ap); ap++; break;
case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break;
case nsXPTType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break;
case nsXPTType::T_BOOL : dp->val.b = *((PRBool*) ap); break;
case nsXPTType::T_CHAR : dp->val.c = *((char*) ap); break;
case nsXPTType::T_WCHAR : dp->val.wc = *((wchar_t*) ap); break;
case nsXPTType::T_CHAR : dp->val.c = *((PRUint32*) ap); break;
case nsXPTType::T_WCHAR : dp->val.wc = *((PRInt32*) ap); break;
default:
NS_ASSERTION(0, "bad type");
break;