Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to create stack overflow/underflow exception ?

Status
Not open for further replies.

jani12

Advanced Member level 4
Full Member level 1
Joined
Oct 30, 2014
Messages
108
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,298
Activity points
2,536
I'm programming Infineon TC29x Aurix Tricore Microcontroller based embedded system in 'C' language.

Consider stack starting address 0x5000 0000. The stack size is 0x2000.

If I take current stack pointer minus 0x2000, will that create stack exception? If yes, what might be 'C' or assembly language code that will achieve this?

My thought is if I subtract negative 0x2000 from current stack pointer or add 0x2000 to current stack pointer, I'll be outside stack and stack exception will occur ?

I need to set program counter to illegal address, i.e. 0x00FF FFFC. Can this be done with assembly language instructions?
If yes, please instrument assembly language instruction that would set program counter to 0x00FF FFFC while code is running.

- - - Updated - - -

Please disregard following text from my original post:

"I need to set program counter to illegal address, i.e. 0x00FF FFFC. Can this be done with assembly language instructions?
If yes, please instrument assembly language instruction that would set program counter to 0x00FF FFFC while code is running."
 

I am not sure about infineon but generally if stack size is increased beyond the limit it will simply continue writing into the next ram locations corrupting the data and behavior will be unpredictable . If you really want to test stack you can probably decrease the stack size in your linker file to some 50, and in any of the functions you can declare a local variable of size more than 50 and see what happens. There are chances you may get linker error or compilation error but not sure. You can write small test code.
 
  • Like
Reactions: jani12

    jani12

    Points: 2
    Helpful Answer Positive Rating
platform? C:

Code:
alloca(1000000000);
 

When testing my exception handling code for ARM controllers, I just built a test case with an (almost) infinte loop of recursively calling a function with a couple variables in it.
I'd check my loop counter value when I entered my exception handler to see if the stack error occurred when I expected it to.
 
  • Like
Reactions: jani12

    jani12

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top