Sakura-IT / SonnetAmiga

Reimplementation of WarpOS supporting Sonnet Crescendo 7200 and other PowerPC PCI cards (mirror of CVS development repository).
MIT License
39 stars 3 forks source link

NARG in macros vs vasmppc_std #28

Closed rkujawa closed 8 years ago

rkujawa commented 8 years ago

Now that we have C compiler producing mostly good executables for Sonnet, I'm slowly working on integrating wosdb into our build system (issue #9).

I've ran into a problem with macro while assembling PPC parts of wosdb. There's a CALLWOS macro in wosdb/warpos_lvo.i (similar to our CALLPOWERPC) that uses NARG variable to extract the number of parameters passed to the macro. However, it seems that NARG is not supported for std syntax in vasm (orignally wosdb used pasm).

This results in the following error:

error 10 in line 1 of "CALLWOS": number or identifier expected
    called from line 64 of "asmdebugger.s"
>   .ifgt   $NARG-1

Any ideas with what this NARG construct can be replaced? In worst case I can just split this macro into two separate macros but I feel that would be less elegant.

DvdBoon commented 8 years ago

.macro CALLWOS .ifne \2="" mr r3,\2 .endif lwz r0,\1+2(r3) mtlr r0 blrl .endm

DvdBoon commented 8 years ago

But the latest vasm does not handle this correctly anymore (it borks on stuff like /1. /2 ... /9 at least here), so maybe

.macro CALLWOS function, register .ifne \register="" mr r3,\register .endif lwz r0,\function+2(r3) mtlr r0 blrl .endm

rkujawa commented 8 years ago

I was thinking about something very similar, but it does not seem to work:

error 10 in line 1 of "CALLWOS": number or identifier expected
    called from line 217 of "exchandler.s"
>   .ifne \register=""

It seems like \register does not exist at all if the marco is called with one argument.

Maybe I'll have to ask Frank to add NARGS to std syntax module.

DvdBoon commented 8 years ago

I know there is also a problem with " What if you use ' ?

rkujawa commented 8 years ago

I tried that. The result is exactly the same, in my opinion it's a problem with \register in this situation, it's not that it is empty, it just does not exist when marco is called with one argument. So the macro syntax does not parse correctly because it became: .ifne ="".

DvdBoon commented 8 years ago

It used to work with \1 and \2 (look at the old versions of the sonnet macros) I still think something broke during an code update/change.

How about .ifne \register (so without the ="")

rkujawa commented 8 years ago

Tried that too ;). I wrote to Frank asking him what would be the correct way to solve this.

DvdBoon commented 8 years ago

The thing is that every call of CALLWOS has a second parameter as far as I can see. Especially at line 64 of asmdebugger.s.

Sooo, strange thought but maybe use CALLWOS function,'r31' instead of CALLWOS function,r31. So use the macro as described above (my second post) and adjust the .s files where the CALLWOS macro is being executed.

I had the same error when trying to pass parameters using "parameter" or parameter, but it worked using 'parameter'. Again, it was less strict with version of end 2014.

rkujawa commented 8 years ago

Frank suggested using .ifnb to check for emptiness and indeed it was the correct solution.

rkujawa commented 8 years ago

Fxied in 45fedb515bf04577366316d413cce4103f2cc539.

DvdBoon commented 8 years ago

Did you check whether /1 /2 etc works? It's easier to read the way it is now, but it would confirm a bug if it doesn't work.

2016-02-03 13:01 GMT+01:00 Radosław Kujawa notifications@github.com:

Closed #28 https://github.com/Sakura-IT/SonnetAmiga/issues/28.

— Reply to this email directly or view it on GitHub https://github.com/Sakura-IT/SonnetAmiga/issues/28#event-537429988.

rkujawa commented 8 years ago

Made a separate issue #29 for this.