DSPRelated.com
Forums

Parameter passed incorrectly

Started by Philip Coveney September 15, 2006
Hello,

I have recently taken over a F2812 DSP project from a colleague who has
recently left for another job, and I am stumbling right out of the gate. I
am hopeful someone will have an insight into the issue I am encountering.
I have an SWI that is making a function call during initialization. The
function takes two parameters. When I step into the called function, I can
see that the actual parameters passed are not received correctly.
The code looks (something) like this:

extern IBF3NET_Handle netFxns; // a struct of fxn pointers

void Init_SWI()
{
foo(0, netFxns); // pass a literal NULL for the first arg
}

void foo(IBF3NETAPP_Handle appHandle, void* fxns)
{
IBF3NET_Handle localVar = fxns;
}

If I build a version of this project copied from the last functional
version, the program does not work correctly. Although I pass 0 as the
appHandle and an actual variable as the 2d param, inside foo() I see that
appHandle is pointing to nextFxns and fxns is zero. But, if I build my
former colleague's version of the project, this does not occur--the
argument's are not reversed, and the code works as expected.
If I view the mixed ASM for foo(), I can see that (for both the working
and non-working versions), the arguments are retrieved like so:

ADDB SP,#4
MOVL *-SP[4],XAR5
MOVL *-SP[2],XAR4

That is, space is made on the local stack and the values passed are
copied out of registers.

The behavior is different on the calling side. The functional version
passes the parameters correctly:

MOVB XAR4,#0 ; here's my literal 0
MOVW DP,#0x2D97
MOVL XAR5,@40 ; here's the reference to netFxns
LCR Foo

The non-functional version passes the parameters so:

MOVW DP,#0x2D9E
MOVL XAR5,@46
MOVB AL,#0 ; this time, the null gets passed in AL
LCR Foo

Two critical differences: the arguments get pushed into registers in
different order, and AL is used instead of XAR4. Because the code for foo()
always pops out of XAR4 and XAR5, you can see why this code does not work.

I have spent considerable effort trying to track down the difference
between the two projects that would cause the compiler to emit different
code, but have been unsuccessful. Obvious things, like compiler and linker
settings and the memory map are unchanged. (There are a coupl of new
variables, but no the ones in question here.) I thought I would take the
opposite tack and see if I could see why the compiler does or does not put
function arguments into registers.

Any thoughts?

Phil Coveney