UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Scholar ronnywebers
Scholar
371 Views
Registered: ‎10-10-2014

SDK -bare metal - verify actual stack usage and generate a stack overflow interrupt/error

Jump to solution

Is it possible to verify actual stack usage, to see how much margin there is left on the stack? 

Can an interrupt be generated, or some 'trap'  be put in code in case the stack 'overflows', so the complete call-chain can be checked in case of an overflow?

** kudo if the answer was helpful. Accept as solution if your question is answered **
0 Kudos
1 Solution

Accepted Solutions
Scholar ericv
Scholar
331 Views
Registered: ‎04-13-2015

Re: SDK -bare metal - verify actual stack usage and generate a stack overflow interrupt/error

Jump to solution

@ronnywebers 

Not realy unless you "instrument" your app, i.e. fill at start-up the stack with predefined data and then count how many is left on the TOS. As for the trapping in case of overflow, the only way I am aware is to put the stack in its own MMU page at the boundary of aniother page set as invalid so when the stack overflow it lands in the invalid page triggering an abort.

9 Replies
Scholar ericv
Scholar
332 Views
Registered: ‎04-13-2015

Re: SDK -bare metal - verify actual stack usage and generate a stack overflow interrupt/error

Jump to solution

@ronnywebers 

Not realy unless you "instrument" your app, i.e. fill at start-up the stack with predefined data and then count how many is left on the TOS. As for the trapping in case of overflow, the only way I am aware is to put the stack in its own MMU page at the boundary of aniother page set as invalid so when the stack overflow it lands in the invalid page triggering an abort.

Scholar ericv
Scholar
329 Views
Registered: ‎04-13-2015

Re: SDK -bare metal - verify actual stack usage and generate a stack overflow interrupt/error

Jump to solution

@ronnywebers 

For the trapping, if you run the app under SDK you can always enable a write watch point on the address past the TOS. This may not necessary trap a stack overflow because "C" functions reserve a space on the stack but depending on what code gets executed that address may not be accessed,

Scholar ronnywebers
Scholar
272 Views
Registered: ‎10-10-2014

Re: SDK -bare metal - verify actual stack usage and generate a stack overflow interrupt/error

Jump to solution

thanks @ericv, I'm trying to start with the first idea, to fill the stack with a pre-defined value.

I think this means altering the xil-crt0.S file? Or is there a way to tell the linker(script) to do this? 

I'm thinking of writing some (foreground) routine that periodically looks at the stack and keeps track of the 'deepest address' where the pre-defined value is overwritten, that would give me some idea of worsed case stack usage, while I further develop my application. Does that sound like a reasonable idea? 

** kudo if the answer was helpful. Accept as solution if your question is answered **
0 Kudos
Scholar ericv
Scholar
253 Views
Registered: ‎04-13-2015

Re: SDK -bare metal - verify actual stack usage and generate a stack overflow interrupt/error

Jump to solution

@ronnywebers 

You should be able do the filling with the linker script by using the FILL keyword on the memory section for the stack.

Scholar ronnywebers
Scholar
246 Views
Registered: ‎10-10-2014

Re: SDK -bare metal - verify actual stack usage and generate a stack overflow interrupt/error

Jump to solution

Thanks @ericv for that tip, I'm struggling to find the right syntax, and also wondering if this is possible since the stack section does not contain actual data (I think to understand this from this discussion on the web)

So I tried this first:

.stack (NOLOAD) : {
	FILL(0x12345678)
   . = ALIGN(16);
   _stack_end = .;
   . += _STACK_SIZE;
   . = ALIGN(16);
   _stack = .;
   __stack = _stack;
   . = ALIGN(16);
   _irq_stack_end = .;
   . += _IRQ_STACK_SIZE;
   . = ALIGN(16);
   __irq_stack = .;
   _supervisor_stack_end = .;
   . += _SUPERVISOR_STACK_SIZE;
   . = ALIGN(16);
   __supervisor_stack = .;
   _abort_stack_end = .;
   . += _ABORT_STACK_SIZE;
   . = ALIGN(16);
   __abort_stack = .;
   _fiq_stack_end = .;
   . += _FIQ_STACK_SIZE;
   . = ALIGN(16);
   __fiq_stack = .;
   _undef_stack_end = .;
   . += _UNDEF_STACK_SIZE;
   . = ALIGN(16);
   __undef_stack = .;
} > ps7_ddr_0

I also tried removing the '(NOLOAD)' but that didn't help much ...

 In the linux terminal window I can see : line 258:1 no viable alternative at input 'FILL'

I also tried to put it at the end :

.stack (NOLOAD) : {
   . = ALIGN(16);
   _stack_end = .;
   . += _STACK_SIZE;
   . = ALIGN(16);
   _stack = .;
   __stack = _stack;
   . = ALIGN(16);
   _irq_stack_end = .;
   . += _IRQ_STACK_SIZE;
   . = ALIGN(16);
   __irq_stack = .;
   _supervisor_stack_end = .;
   . += _SUPERVISOR_STACK_SIZE;
   . = ALIGN(16);
   __supervisor_stack = .;
   _abort_stack_end = .;
   . += _ABORT_STACK_SIZE;
   . = ALIGN(16);
   __abort_stack = .;
   _fiq_stack_end = .;
   . += _FIQ_STACK_SIZE;
   . = ALIGN(16);
   __fiq_stack = .;
   _undef_stack_end = .;
   . += _UNDEF_STACK_SIZE;
   . = ALIGN(16);
   __undef_stack = .;
} > ps7_ddr_0 = 0x12345678

so I'm a bit stuck on a syntax problem I think, do you happen to know the correct syntax? 

** kudo if the answer was helpful. Accept as solution if your question is answered **
0 Kudos
Scholar ericv
Scholar
237 Views
Registered: ‎04-13-2015

Re: SDK -bare metal - verify actual stack usage and generate a stack overflow interrupt/error

Jump to solution

@ronnywebers 

Removing the statement (NOLOAD) will help as this tells the linker to not put any pre-initalized data of that section.

 

0 Kudos
Scholar ronnywebers
Scholar
230 Views
Registered: ‎10-10-2014

Re: SDK -bare metal - verify actual stack usage and generate a stack overflow interrupt/error

Jump to solution

@ericv , I tried 2 things, but without success:

1) removed the (NOLOAD) and put a FILL before the section :

.stack : {
	FILL(0x12345678)
   . = ALIGN(16);
   _stack_end = .;
   . += _STACK_SIZE;
   . = ALIGN(16);
   _stack = .;
   __stack = _stack;
   . = ALIGN(16);
   _irq_stack_end = .;
   . += _IRQ_STACK_SIZE;
   . = ALIGN(16);
   __irq_stack = .;
   _supervisor_stack_end = .;
   . += _SUPERVISOR_STACK_SIZE;
   . = ALIGN(16);
   __supervisor_stack = .;
   _abort_stack_end = .;
   . += _ABORT_STACK_SIZE;
   . = ALIGN(16);
   __abort_stack = .;
   _fiq_stack_end = .;
   . += _FIQ_STACK_SIZE;
   . = ALIGN(16);
   __fiq_stack = .;
   _undef_stack_end = .;
   . += _UNDEF_STACK_SIZE;
   . = ALIGN(16);
   __undef_stack = .;
} > ps7_ddr_0

as soon as I hit safe, I can see in my linux terminal window 3 times this message :

line 258:1 no viable alternative at input 'FILL'

where line 258 corresponds to the FILL statement

2) removed the (NOLOAD) and put the value at the end :

.stack : {
   . = ALIGN(16);
   _stack_end = .;
   . += _STACK_SIZE;
   . = ALIGN(16);
   _stack = .;
   __stack = _stack;
   . = ALIGN(16);
   _irq_stack_end = .;
   . += _IRQ_STACK_SIZE;
   . = ALIGN(16);
   __irq_stack = .;
   _supervisor_stack_end = .;
   . += _SUPERVISOR_STACK_SIZE;
   . = ALIGN(16);
   __supervisor_stack = .;
   _abort_stack_end = .;
   . += _ABORT_STACK_SIZE;
   . = ALIGN(16);
   __abort_stack = .;
   _fiq_stack_end = .;
   . += _FIQ_STACK_SIZE;
   . = ALIGN(16);
   __fiq_stack = .;
   _undef_stack_end = .;
   . += _UNDEF_STACK_SIZE;
   . = ALIGN(16);
   __undef_stack = .;
} > ps7_ddr_0 = 0x12345678

that gives me the following in the linux terminal window :

line 285:14 mismatched input '=' expecting '}'

I tried also :

} = 0x12345678 > ps7_ddr_0 

and 

} 0x12345678 > ps7_ddr_0 

**bleep** syntax :-) I searched the web, but to my surprise didn't find a usable example ...

** kudo if the answer was helpful. Accept as solution if your question is answered **
0 Kudos
Highlighted
Scholar ericv
Scholar
225 Views
Registered: ‎04-13-2015

Re: SDK -bare metal - verify actual stack usage and generate a stack overflow interrupt/error

Jump to solution

@ronnywebers 

No sure but I think in the first case a semi-colon is required after the FILL() and for the second it's only byte filling.  Again, not sure.

Scholar ronnywebers
Scholar
197 Views
Registered: ‎10-10-2014

Re: SDK -bare metal - verify actual stack usage and generate a stack overflow interrupt/error

Jump to solution

thanks @ericv  for all your suggestions, I tried them but without success. I tried many variations too, but same errors. Therefore I created a new thread here, as it's also moving away from the original question. This might attract other forum users :-)

** kudo if the answer was helpful. Accept as solution if your question is answered **
0 Kudos