Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

__alt_stack_pointer misbehaving (linker bug?)

I am using Nios II 6.1 and 6.1 IDE. I use the following command (as recommended in another thread) to set the __alt_stack_pointer:

-wl,-defsym -wl,'__alt_stack_pointer=0x300000'

I specify this command as a linker flag inside the IDE.

The linker script has a comment for that symbol saying:

" * the next two symbols define the location of the default stack. you can

* override them to move the stack to a different memory."

where the other symbol is __alt_stack_limit, which effectively points to the beginning of the heap (as far as I can tell from the linker script),

and should always contain a lower value than the __alt_stack_pointer, because the stack grows from higher to lower addresses.

System description:

I have three processors in the system, all running code from an 8MB SDRAM:

Processor 1:

Reset Address = 0x00000000

Exception Address = 0x00000020

Processor 2:

Reset Address = 0x00100000

Exception Address = 0x00100020

Processor 3:

Reset Address = 0x00200000

Exception Address = 0x00200020

As can be seen, the first 2 processors have 1MB of memory each for their code and data.

I would like to limit the memory occupied by the third processor to 1MB, so that I can use the remaining memory to store some data.

Considering that, I thought it would make sense to put the initial stack pointer to 0x300000. However, when I do that, the linker reports:

"info: 5120 kbytes free for stack + heap."

This didn't make any sense, so I tried to work out the relationship between the __alt_stack_pointer value I set, and the amount of stack space the linker reports.

Here's what I got:

__alt_stack_pointer, free for stack + heap.

0x300000, 5120KBytes

0x400000, 4096KBytes

0x500000, 3072KBytes

0x600000, 2048KBytes

0x700000, 1024KBytes

0x800000, 6090KBytes

This doesn't make any sense to me. The stack space is reduced as I set the initial stack pointer higher and higher?

Is this a bug (linker calculating the stack space incorrectly), or am I missing something?

Thanks!
No RepliesBe the first to reply