-->
Page 1 of 3

More than 5 function arguments not supported?

PostPosted: Thu Jan 08, 2015 2:49 pm
by MarekB
So I have a function
Code: Select allvoid drawArc(uint16 cx, uint16 cy, uint16 radius, uint16 thickness, uint16 start)

this one works fine. If I add one more argument
Code: Select allvoid drawArc(uint16 cx, uint16 cy, uint16 radius, uint16 thickness, uint16 start, uint16 end)

the code gets stuck at the end of the function which called drawArc. Changing it to
Code: Select alltypedef struct {
   uint16 cx;
   uint16 cy;
   uint16 radius;
   uint16 thickness;
   uint16 start;
   uint16 end;
} drawArcParams;

void drawArc(drawArcParams params)

works fine. And it's also probably the better way to pass in a lot of arguments.
But just wondering where does the limitation to 5 function arguments come from?

Re: More than 5 function arguments not supported?

PostPosted: Thu Jan 08, 2015 8:15 pm
by jcmvbkbc
MarekB wrote:So I have a function
Code: Select allvoid drawArc(uint16 cx, uint16 cy, uint16 radius, uint16 thickness, uint16 start)

this one works fine. If I add one more argument
Code: Select allvoid drawArc(uint16 cx, uint16 cy, uint16 radius, uint16 thickness, uint16 start, uint16 end)

the code gets stuck at the end of the function which called drawArc.

This was an issue with the initial call0 ABI implementation. I believe it's fixed in the current versions of https://github.com/jcmvbkbc/gcc-xtensa and https://github.com/jcmvbkbc/crosstool-NG , specifically with the commit https://github.com/jcmvbkbc/gcc-xtensa/ ... 8f842a8acc
Please let me know if you see it with the latest gcc: there must still be a problem there then.
MarekB wrote:But just wondering where does the limitation to 5 function arguments come from?

Comes from the fact that arguments passed in registers occupy at most six registers a2-a7, but a7 is a frame pointer in case of windowed ABI and the compiler treats it specially. The initial call0 port didn't change that, so strange things may happen with 6th argument.

Re: More than 5 function arguments not supported?

PostPosted: Fri Jan 09, 2015 1:57 pm
by MarekB
Thanks jcmvbkbc for the explanation.
I am on windows and I using a pre-built lx106 toolchain I downloaded from here: https://drive.google.com/folderview?id=0BzWyTGWIwcYQendHbWlsNUZpX0E&usp=drive_web#list. I guess it is quite an old build at this time so your latest toolchain probably works fine in this regard.
I am not sure if there is a newer pre-built toolchain somewhere or how hard would it be to compile it on windows. Don't really have time to play around with this at the moment. If anybody has a link to a newer toolchain I can use, please post a link. thanks

Re: More than 5 function arguments not supported?

PostPosted: Fri Jan 09, 2015 8:43 pm
by peteben
I have since recompiled the toolchain in 32bit mode, and updated my instructions. You will find everything in the new Wiki here.

Let me know if the 32bit compiler has the same problem. If it does, I will try to compile an updated version if I can find it.

Pete