Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Mac AngelScript
Pecan:
@Anders
Here is the suggested PPC template from the AngelScript forum:
--- Code: ---
Here is how the code *could* look, like a rough draft or so (not yet complete, but)
// Loads all data into the correct places and calls the function.
// intArgSize is the size in bytes for how much data to put in int registers
// floatArgSize is the size in bytes for how much data to put in float registers
// stackArgSize is the size in bytes for how much data to put on the callstack
extern "C" asQWORD ppcFunc(int intArgSize, int floatArgSize, int stackArgSize, asDWORD func)
{
asQWORD result;
asDWORD *args = ppcArgs;
__asm__ (
"\tmr r27,%1\n" // intArgSize
"\tmr r28,%2\n" // floatArgSize
"\tmr r29,%3\n" // stackArgSize
"\tmr r30,%4\n" // args pointer
"\tmr r31,%5\n" // func pointer
#define LOAD_WORD(_reg,_off) "\tcmpwi r27,"#_off"\n" "\tble L"#_reg"\n" "\tlwz "#_reg","#_off"(r30)\n" "L"#_reg":\n"
LOAD_WORD(r3,0)
LOAD_WORD(r4,4)
LOAD_WORD(r5,8)
LOAD_WORD(r6,12)
LOAD_WORD(r7,16)
LOAD_WORD(r8,20)
LOAD_WORD(r9,24)
LOAD_WORD(r10,28)
"\taddi r30,r30,32\n"
#define LOAD_DOUBLE(_reg,_off) "\tcmpwi r28,"#_off"\n" "\tble L"#_reg"\n" "\tlfd "#_reg",0(r30)\n" "L"#_reg":\n"
LOAD_DOUBLE(f0,0)
LOAD_DOUBLE(f1,8)
LOAD_DOUBLE(f2,16)
LOAD_DOUBLE(f3,24)
LOAD_DOUBLE(f4,32)
LOAD_DOUBLE(f5,40)
LOAD_DOUBLE(f6,48)
LOAD_DOUBLE(f7,52)
LOAD_DOUBLE(f8,60)
LOAD_DOUBLE(f9,68)
LOAD_DOUBLE(f10,76)
LOAD_DOUBLE(f11,84)
LOAD_DOUBLE(f12,92)
LOAD_DOUBLE(f13,100)
LOAD_DOUBLE(f14,108)
"\taddi r30,r30,96\n"
// TODO: set up stack frame
// TODO: load r29 bytes from r30
-"\tbl r31\n"
+"\tmtctr r31\n"
+\tbctr\n"
"\tmr %0,r3\n"
// TODO: take down stack frame
/* outputs: */ : "=&r" (result)
/* inputs: */ : "r" (intArgSize), "r" (floatArgSize), "r" (stackArgSize), "r" (args), "r" (func)
/* clobbers: */ : "memory");
return result;
/*
* "=&r" (result) means: 'result' is written on (the '='), it's any GP
* register (the 'r'), and it must not be the same as
* any of the input registers (the '&').
* "r" (func) means: 'func' is any GP reg
*
* "memory" in the 'clobbers' section means that gcc will make
* sure that anything that should be in memory IS there
* before calling this routine.
*/
--- End code ---
Could you help me understand how this is going to work.
"According to the Mac OS X ABI Function Call Guide: 32-bit PowerPC Function Calling Conventions" (url below), for each floating point register used, a GPR register is skipped.
For example, if a routine such as "void foo(int parm1, double parm2 , int parm 3)" is called, the parameters would be passed as GPR3=parm1, FPR1=parm2, GPR6=parm3, because for each FPR used, a GPR is skipped. Since parm2 is a double, GPR4 & GPR5 are skipped.
It appears to me that the template above would pass parm3 in GPR4, which would not be understood by the foo routine.
What am I misunderstanding ?
thanks
pecan
http://developer.apple.com/documentation/DeveloperTools/Conceptual/LowLevelABI/Articles/32bitPowerPC.html#//apple_ref/doc/uid/TP40002438-SW20
cf., "foo(...)" example almost at bottom of page.
Pecan:
This message is for documentation only. Just so others will know what I'm up to.
I've sent the following message to Andreas Jonsson. (Author of AngelScript)
because his forum is down right now
--- Code: ---2006/05/29
The forum is down, so I'll try email for now.
I'm trying to translate the as_callfunc_sh4.cpp for use with ppc.
I downloaded the zip file provided on AngelScript.com containing the lines:
#define ANGELSCRIPT_VERSION 20600
#define ANGELSCRIPT_VERSION_MAJOR 2
#define ANGELSCRIPT_VERSION_MINOR 6
#define ANGELSCRIPT_VERSION_BUILD 0
#define ANGELSCRIPT_VERSION_STRING "2.6.0"
In attempting to compile the code with AS_SH4 defined, I get the following errors:
..\..\source\as_callfunc_ppc.cpp:671: error: 'class asCContext' has no member named 'returnVal'
..\..\source\as_callfunc_ppc.cpp:673: error: 'class asCContext' has no member named 'returnVal'
..\..\source\as_callfunc_ppc.cpp:676: error: 'class asCContext' has no member named 'returnVal'
..\..\source\as_callfunc_ppc.cpp:678: error: 'class asCContext' has no member named 'returnVal'
in this section of the code:
------------------- code ---------------------------------------------------
else
{
// Store value in returnVal register
if( sysFunc->hostReturnFloat )
{
if( sysFunc->hostReturnSize == 1 )
*(asDWORD*)&context->returnVal = GetReturnedFloat();
else
context->returnVal = GetReturnedDouble();
}
else if( sysFunc->hostReturnSize == 1 )
*(asDWORD*)&context->returnVal = (asDWORD)retQW;
else
context->returnVal = retQW;
}
------------------------ end code section -------------------------------------
The message is very right. There is no "returnVal" in asCContext.
Has this code ever worked? I feel uneasy that I may be wasting time if it is just example code.
If it's working code, could you point me in a direction to correct it?
I realize the assembly code will get errors, I'm just trying to understand and get the C++ code
correct.
I'm using
Windowx XP, minGW 3.4.4 under CodeBlocks svn
In advance, Thank you for your time, and help.
pecan
--- End code ---
Pecan:
--- Quote from: Pecan on May 30, 2006, 04:53:22 am ---
I've sent the following message to Andreas Jonsson. (Author of AngelScript)
because his forum is down right now...
--- End quote ---
And got back an almost immediate reply.
--- Quote from: Andreas Jonsson ---Hi Pecan,
I suggest you download the latest version from SVN. There is already a
working port for PPC in it. The port may not be fully complete as the
developer didn't have time to finish his tests, but should work a lot
better as a starting point than the sh4 code. :) Please let me know if
you find any problems with the code.
The sh4 code was working once, but since I do not have a sh4 system to
test it on it has fallen behind and obviously has a few errors in it.
I'll fix the problem you pointed out for the next version. Thanks for
letting me know about it.
Regards,
Andreas
--- End quote ---
tiger683:
These two patches for making c::b use current angelscript from svn:
30_all_angelscript-2.7-svn20060522.patch
31_all_angelscript-vs-svn-changes.patch
I've been having as from svn in my c::b overlay for gentoo since a while now,
and many users already run it without problems (x86,x86_64,ppc), although i don't know if any other builds
besides x86 actually use it?
mandrav:
--- Quote from: tiger683 on May 30, 2006, 09:36:10 am ---and many users already run it without problems (x86,x86_64,ppc)
--- End quote ---
Surely a typo because AS doesn't work on 64bit yet.
Navigation
[0] Message Index
[#] Next page
Go to full version