sparklewhiskers
sparklewhiskers

Reputation: 910

Use absolute value of linker command file variable in 'C' code

I have a linker command file that assigns the top address of the stack into a variable

_stack = . + 0x80000;  

I want to use this address in a 'c' program - I want to copy the stack to another location and then update the stack pointer to point to the new location before doing a destructive memory test on the orginal bank of RAM.

I'm finding that if I do something like

extern u32 *_stack;  
myFunction(_stack);

Then the function seems to get passed the value stored at the stack location

lwz r3,0(r8)

Rather than the address of the stack itself. Can anyone help?

Upvotes: 1

Views: 1517

Answers (3)

Tall Jeff
Tall Jeff

Reputation: 9994

I believe the most natural [ie: correct] way to declare this is based on the notion of thinking of the stack as an array in memory with the stack pointer being a location within that array:

extern U32 _stack[];
U32 *stackPtr;
stackPtr = _stack;

Upvotes: 1

Mark Ransom
Mark Ransom

Reputation: 308206

Try

extern u32 _stack;
U32 * stackPtr;
stackPtr = &_stack;

Upvotes: 5

Paul Nathan
Paul Nathan

Reputation: 40319

myFunction(&_stack); should pass myFunction the address of the variable * _stack*. Else, it will pass the value contained in the variable _stack.

Upvotes: 0

Related Questions