From: John Speth on
Hi folks-

I'm building a NIOS2 project which uses GCC tools and I'd like to write a C
function that needs to know the stack top and stack bottom pointers at
runtime.

What is the GCC method for getting the stack top and bottom pointers at
runtime?

Thanks, John Speth.



--- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Tim Wescott on
John Speth wrote:
> Hi folks-
>
> I'm building a NIOS2 project which uses GCC tools and I'd like to write a C
> function that needs to know the stack top and stack bottom pointers at
> runtime.
>
> What is the GCC method for getting the stack top and bottom pointers at
> runtime?
>
> Thanks, John Speth.

Different, depending on version and startup code.

The first place that I'd look would be the linker command file
(something_or_other.ld) -- if you're lucky they'll be called something
like __stack_top and __stack_bottom. Failing that, look in the map file
from your link for things called "stack". Failing that, grep.

--
Tim Wescott
Control system and signal processing consulting
www.wescottdesign.com
From: John Speth on
>> What is the GCC method for getting the stack top and bottom pointers at
>> runtime?

> The first place that I'd look would be the linker command file
> (something_or_other.ld) -- if you're lucky they'll be called something
> like __stack_top and __stack_bottom. Failing that, look in the map file
> from your link for things called "stack". Failing that, grep.

You're right but it needs to be a run time operation.

John Speth.



--- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Andrew Jackson on
> I'm building a NIOS2 project which uses GCC tools and I'd like to write a C
> function that needs to know the stack top and stack bottom pointers at
> runtime.
>
> What is the GCC method for getting the stack top and bottom pointers at
> runtime?

It's probably going to depend on what the crt0.s file you are linking
against does. (You could disassemble that with objdump to see what
symbols get used then write the appropriate code.)

Andrew

From: Grant Edwards on
On 2010-05-11, John Speth <johnspeth(a)yahoo.com> wrote:
>>> What is the GCC method for getting the stack top and bottom pointers at
>>> runtime?
>
>> The first place that I'd look would be the linker command file
>> (something_or_other.ld) -- if you're lucky they'll be called something
>> like __stack_top and __stack_bottom. Failing that, look in the map file
>> from your link for things called "stack". Failing that, grep.
>
> You're right but it needs to be a run time operation.

Oh for pete's sake:


extern char __stack_top, __stack_bottom;


[...]

printf("Stack top = %p, bottom = %p\n",&__stack_top,&__stack_bottom);

--
Grant Edwards grant.b.edwards Yow! I appoint you
at ambassador to Fantasy
gmail.com Island!!!