Author Topic: Mac AngelScript  (Read 9420 times)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2874
Mac AngelScript
« on: May 28, 2006, 04:46:31 pm »
@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.
   */

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.

« Last Edit: May 28, 2006, 07:20:16 pm by Pecan »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2874
Re: Mac AngelScript
« Reply #1 on: May 30, 2006, 04:53:22 am »
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


Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2874
Re: Mac AngelScript
« Reply #2 on: May 30, 2006, 06:24:24 am »

I've sent the following message to Andreas Jonsson. (Author of AngelScript)
because his forum is down right now...

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

Offline tiger683

  • Multiple posting newcomer
  • *
  • Posts: 20
  • o_0
Re: Mac AngelScript
« Reply #3 on: May 30, 2006, 09:36:10 am »
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?
« Last Edit: May 30, 2006, 09:39:59 am by tiger683 »
Where I work :P

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Mac AngelScript
« Reply #4 on: May 30, 2006, 09:48:48 am »
and many users already run it without problems (x86,x86_64,ppc)

Surely a typo because AS doesn't work on 64bit yet.
Be patient!
This bug will be fixed soon...

Offline tiger683

  • Multiple posting newcomer
  • *
  • Posts: 20
  • o_0
Re: Mac AngelScript
« Reply #5 on: May 30, 2006, 11:06:29 am »
and many users already run it without problems (x86,x86_64,ppc)

Surely a typo because AS doesn't work on 64bit yet.

I'd have a little question:
Could it be that AS is simply not being built/used for 64bit platforms when building c::b there?
Or is c::b in current state supposed to fail building/working on 64bit systems because of AS?
The sentence you quoted meant people on these platforms use current svn version of c::b with above patches,
my question still applies :S
My confusion is caused by comments on gentoo forums regarding my overlay, like:
Quote from: OnDraash
fixed! at least it works for me on amd64. it just overwrote my syntax highlighting settings
again, but that is not your problem. thanks for the patch :-)
And this with VERY recent svn checkouts and the above patches i posted here ::confused::
I'd be happy about a quick response.

PS: the thread can be reached by following the link in my sig.
« Last Edit: May 30, 2006, 11:40:48 am by tiger683 »
Where I work :P

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Mac AngelScript
« Reply #6 on: May 30, 2006, 01:46:32 pm »
I am the one trying to port AS to 64bits so when I say it doesn't work, trust me, I know what I 'm saying ;).
What is happening though is that it compiles cleanly in 64bits and C::B disables scripting for these platforms so it can be built without trouble.
Be patient!
This bug will be fixed soon...

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2874
Re: Mac AngelScript
« Reply #7 on: May 30, 2006, 02:38:26 pm »
and many users already run it without problems (x86,x86_64,ppc)

Surely a typo because AS doesn't work on 64bit yet.

Yes, a typo. AngelScript doesn't work for CodeBlocks ppc either.

But soon...

Offline tiger683

  • Multiple posting newcomer
  • *
  • Posts: 20
  • o_0
Re: Mac AngelScript
« Reply #8 on: May 30, 2006, 03:14:53 pm »
Ahh, I see. Thanks. But all three do use C::B, so not entirely typo,
just a stupid wrong assumption  :oops:
« Last Edit: May 30, 2006, 03:24:32 pm by tiger683 »
Where I work :P

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2874
Re: Mac AngelScript
« Reply #9 on: June 08, 2006, 02:46:24 pm »
... AngelScript doesn't work for CodeBlocks ppc either.

But soon...


Just an update...

I've finished and clean compiled/assembled the assembler code and
C++ code for native AngelScript calls on the PPC (as_callfunc_ppc.cpp).

Now it's just a matter of spending a year or two in GDB. :~}


thanks
pecan
« Last Edit: June 08, 2006, 02:48:15 pm by Pecan »