2004-09-19 05:31:10 +02:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
2006-01-08 02:25:02 +01:00
|
|
|
* Copyright 2004 by Eric House (xwords@eehouse.org). All rights reserved.
|
2004-09-19 05:31:10 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <PceNativeCall.h>
|
|
|
|
#include "pnostate.h"
|
|
|
|
#include "pace_gen.h"
|
2004-10-02 05:57:36 +02:00
|
|
|
#include "pace_man.h" /* for the ExgSocketType flippers */
|
2004-09-24 03:21:42 +02:00
|
|
|
#include "palmmain.h"
|
2004-09-19 05:31:10 +02:00
|
|
|
|
2004-10-02 05:57:36 +02:00
|
|
|
typedef union ParamStub {
|
|
|
|
ExgAskParamType exgAskParamType;
|
|
|
|
ExgSocketType exgSocketType;
|
|
|
|
} ParamStub;
|
|
|
|
|
2004-09-28 03:06:14 +02:00
|
|
|
unsigned long
|
|
|
|
realArmletEntryPoint( const void *emulStateP,
|
|
|
|
void *userData68KP,
|
|
|
|
Call68KFuncType* call68KFuncP );
|
|
|
|
|
|
|
|
/* With arm-palmos-gcc, there can't be any .GOT references in the entry point
|
|
|
|
(since those values get put inline BEFORE the function rather than
|
|
|
|
after.) */
|
2004-09-19 05:31:10 +02:00
|
|
|
unsigned long
|
|
|
|
ArmletEntryPoint( const void *emulStateP,
|
|
|
|
void *userData68KP,
|
|
|
|
Call68KFuncType* call68KFuncP )
|
2004-09-28 03:06:14 +02:00
|
|
|
{
|
|
|
|
return realArmletEntryPoint( emulStateP,
|
|
|
|
userData68KP,
|
|
|
|
call68KFuncP );
|
|
|
|
}
|
|
|
|
|
2006-09-17 08:16:05 +02:00
|
|
|
#ifdef XWFEATURE_IR
|
2004-10-02 05:57:36 +02:00
|
|
|
static XP_Bool
|
|
|
|
convertParamToArm( UInt16 cmd, ParamStub* armParam, MemPtr parm68K )
|
|
|
|
{
|
|
|
|
XP_Bool revert;
|
|
|
|
|
|
|
|
if ( cmd == sysAppLaunchCmdExgAskUser ) {
|
|
|
|
/* We don't read the data, but we do write to one field. */
|
|
|
|
revert = XP_TRUE;
|
|
|
|
} else if ( cmd == sysAppLaunchCmdExgReceiveData ) {
|
|
|
|
flipEngSocketToArm( &armParam->exgSocketType,
|
|
|
|
(const unsigned char*)parm68K );
|
|
|
|
revert = XP_TRUE; /* just to be safe */
|
|
|
|
} else {
|
|
|
|
revert = XP_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return revert;
|
|
|
|
} /* convertParamToArm */
|
|
|
|
|
|
|
|
static void
|
|
|
|
convertParamFromArm( UInt16 cmd, MemPtr parm68K, ParamStub* armParam )
|
|
|
|
{
|
|
|
|
if ( cmd == sysAppLaunchCmdExgAskUser ) {
|
|
|
|
write_unaligned8( &((unsigned char*)parm68K)[4],
|
|
|
|
armParam->exgAskParamType.result );
|
|
|
|
} else if ( cmd == sysAppLaunchCmdExgReceiveData ) {
|
|
|
|
flipEngSocketFromArm( parm68K, &armParam->exgSocketType );
|
|
|
|
} else {
|
|
|
|
XP_ASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-28 03:06:14 +02:00
|
|
|
unsigned long
|
|
|
|
realArmletEntryPoint( const void *emulStateP,
|
|
|
|
void *userData68KP,
|
|
|
|
Call68KFuncType* call68KFuncP )
|
2004-09-19 05:31:10 +02:00
|
|
|
{
|
|
|
|
PNOState* loc;
|
|
|
|
PNOState state;
|
|
|
|
PnoletUserData* dataP;
|
|
|
|
unsigned long result;
|
|
|
|
unsigned long oldR10;
|
2004-10-02 05:57:36 +02:00
|
|
|
UInt16 cmd;
|
|
|
|
MemPtr cmdPBP;
|
|
|
|
MemPtr oldVal;
|
|
|
|
ParamStub ptrStorage;
|
|
|
|
XP_Bool mustRevert;
|
2004-09-19 05:31:10 +02:00
|
|
|
|
|
|
|
loc = getStorageLoc();
|
|
|
|
|
|
|
|
dataP = (PnoletUserData*)userData68KP;
|
|
|
|
dataP->stateSrc = (PNOState*)Byte_Swap32((unsigned long)&state);
|
|
|
|
dataP->stateDest = (PNOState*)Byte_Swap32((unsigned long)loc);
|
|
|
|
|
|
|
|
state.gotTable = (unsigned long*)
|
|
|
|
Byte_Swap32((unsigned long)dataP->gotTable);
|
|
|
|
|
2004-10-02 05:57:36 +02:00
|
|
|
if ( !dataP->recursive ) {
|
2004-09-21 07:00:57 +02:00
|
|
|
STACK_START(unsigned char, stack, 4 );
|
|
|
|
ADD_TO_STACK4(stack, userData68KP, 0);
|
|
|
|
STACK_END(stack);
|
2004-10-02 05:57:36 +02:00
|
|
|
|
|
|
|
state.emulStateP = emulStateP;
|
|
|
|
state.call68KFuncP = call68KFuncP;
|
|
|
|
|
2004-09-19 05:31:10 +02:00
|
|
|
(*call68KFuncP)( emulStateP,
|
|
|
|
Byte_Swap32((unsigned long)dataP->storageCallback),
|
2004-09-21 07:00:57 +02:00
|
|
|
stack, 4 );
|
2004-09-19 05:31:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
asm( "mov %0, r10" : "=r" (oldR10) );
|
|
|
|
asm( "mov r10, %0" : : "r" (state.gotTable) );
|
|
|
|
|
2004-10-02 05:57:36 +02:00
|
|
|
cmd = Byte_Swap16( dataP->cmd );
|
|
|
|
cmdPBP = (MemPtr)Byte_Swap32((unsigned long)dataP->cmdPBP);
|
2004-09-19 05:31:10 +02:00
|
|
|
|
2006-09-17 08:16:05 +02:00
|
|
|
#ifdef XWFEATURE_IR
|
2004-10-02 05:57:36 +02:00
|
|
|
/* if the cmd is sysAppLaunchCmdExgAskUser or
|
|
|
|
sysAppLaunchCmdExgReceiveData then we're going to be making use of the
|
|
|
|
cmdPBP value in PilotMain. Need to convert it here. */
|
|
|
|
mustRevert = convertParamToArm( cmd, &ptrStorage, cmdPBP );
|
|
|
|
#endif
|
2004-09-19 05:31:10 +02:00
|
|
|
|
2004-10-02 05:57:36 +02:00
|
|
|
oldVal = cmdPBP;
|
|
|
|
cmdPBP = &ptrStorage;
|
|
|
|
|
|
|
|
result = PM2(PilotMain)( cmd, cmdPBP, Byte_Swap16(dataP->launchFlags) );
|
|
|
|
|
2006-09-17 08:16:05 +02:00
|
|
|
#ifdef XWFEATURE_IR
|
2004-10-02 05:57:36 +02:00
|
|
|
if ( mustRevert ) {
|
|
|
|
convertParamFromArm( cmd, oldVal, &ptrStorage );
|
|
|
|
}
|
|
|
|
#endif
|
2004-09-19 05:31:10 +02:00
|
|
|
|
|
|
|
asm( "mov r10, %0" : : "r" (oldR10) );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
PNOState*
|
|
|
|
getStorageLoc()
|
|
|
|
{
|
2004-09-21 07:00:57 +02:00
|
|
|
asm( "adr r0,data" );
|
|
|
|
asm( "mov pc,lr" );
|
|
|
|
asm( "data:" );
|
2004-10-02 05:57:36 +02:00
|
|
|
/* we need sizeof(PNOState) worth of bytes after the data label. */
|
2004-09-19 05:31:10 +02:00
|
|
|
asm( "nop" );
|
|
|
|
asm( "nop" );
|
2004-10-02 05:57:36 +02:00
|
|
|
return (PNOState*)0L; /* shut up compiler; overwrite me!!!! */
|
2004-09-21 07:00:57 +02:00
|
|
|
/* The compiler's adding a "mov pc,lr" here too that we can overwrite. */
|
2004-09-19 05:31:10 +02:00
|
|
|
}
|
|
|
|
|