Direction of stack growth for s12xep100

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Direction of stack growth for s12xep100

3,010 Views
Xbot
Contributor II
hi,
does anyone know the direction of stack growth for s12xe and where it is mapped?
 
thanx.
Labels (1)
0 Kudos
Reply
6 Replies

1,166 Views
CrasyCat
Specialist III
Hello
 
I assume you did create your application using the project wizard.
 
Please check your application MAP file.
 
You will see a line looking as follows:
     .stack                           256   R/W     0x2000     0x20FF   RAM
 
That indicates that
   1- there is 256 bytes of memory reserved for the stack
   2- Stack pointer is initialized with 0x20FF at startup
   3- Stack is growing downward to 0x2000.
 
Also note that the HCS12XE CPU does not provide any mechanism to detect stack overflow on the hardware level.
 
CrasyCat
0 Kudos
Reply

1,166 Views
Xbot
Contributor II
Hi again,
 
is this true for xgate too?
 
also, any suggestion for software stack overflow checking?
 
thnx,


Message Edited by Xbot on 2008-05-05 03:10 PM
0 Kudos
Reply

1,166 Views
bigmac
Specialist III
Hello Xbot,


Xbot wrote:
also, any suggestion for software stack overflow checking?

One approach might be to locate a constant variable at a specific address immediately below the stack segment, and initialise to a known value.  Then periodically test whether the variable has a corrupted value caused by stack overflow.  Perhaps a long variable would lessen the probability of this particular value occurring within the stack usage.
 
Regards,
Mac
 
0 Kudos
Reply

1,166 Views
Xbot
Contributor II
Hi bigmac,
 

One approach might be to locate a constant variable at a specific address immediately below the stack segment, and initialise to a known value.  Then periodically test whether the variable has a corrupted value caused by stack overflow.  Perhaps a long variable would lessen the probability of this particular value occurring within the stack usage.

 
can this scheme (stack check) be applied to xgate too?
 
thnx,
 
 
0 Kudos
Reply

1,166 Views
CrasyCat
Specialist III
Hello
 
On the XGATE side, the way the stack start address is defined depends on the core you are using.
 
On XGATE V3 core, there are 2 stacks and stack start addresses are specified in registers XGISP31 & XGISP74. 
On earlier release of the XGATE, the stack start address is specified by option  -Cstv.
 
To check for stack overflow, I see 2 solutions:
  1- Fill the stack area with a specific pattern and run your application.
       After a while stop application and check how far the stack is growing.
  2- You may want to set a watchpoint on the  lowest byte of the stack.
      Then run your application and application will stop if you are accessing this memory cell.
 
This should be working on both XGATE or HCS12 side.
 
CrasyCat
0 Kudos
Reply

1,166 Views
Xbot
Contributor II
hi,
 
If i want to implement the solution 2, how do i know the address of the last byte of the stacks?
 
thnks,
0 Kudos
Reply