How to obtain the correct Frame Pointer (FP) for DumpCallStack on S32K3 using the GHS compiler?

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

How to obtain the correct Frame Pointer (FP) for DumpCallStack on S32K3 using the GHS compiler?

120 Views
nitin_aher
Contributor I

Hi everyone,

I am working on an S32K3 MCU using the Green Hills Software (GHS) compiler, and I am implementing a DumpCallStack function.

To obtain the frame pointer (FP), I am using the following inline assembly:

__asm volatile ("mov %0, r7" : "=r" (locals.fp));
However, the value I get for locals.fp is 0x02B1, which does not appear to be a valid frame pointer. It is not aligned and does not point to a valid stack location, so the call stack cannot be unwound correctly.

My questions are:

What is the correct way to obtain the current frame pointer when using the GHS compiler on the S32K3 (Arm Cortex-M7)?
Does the GHS compiler always use R7 as the frame pointer, or can it omit the frame pointer or use another register depending on the optimization level?
Are there any compiler options that must be enabled to preserve the frame pointer for stack unwinding?
Is there a recommended GHS-specific API or intrinsic for retrieving the frame pointer instead of using inline assembly?
If anyone has implemented stack unwinding or a DumpCallStack function with the GHS compiler on S32K3, I would appreciate any guidance or examples.

Thank you!

0 Kudos
Reply
2 Replies

69 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

I would not assume that R7 is always used as the frame pointer. Depending on the GHS version, optimization level, and compiler options, the compiler may use a different register or omit the frame pointer entirely and use R7 as a general-purpose register. The value 0x02B1 suggests that R7 might not be acting as a frame pointer in your build. 

Please check the generated assembly and verify whether GHS is creating frame records at all. If frame pointers are enabled, you should see a consistent function prologue saving/restoring the frame pointer; otherwise stack unwinding based on R7/R11 will not be reliable.

Since this is primarily a compiler-specific question, I would also recommend contacting Green Hills Software support. They can advise on:

  • Whether GHS uses R7, R11, or another register as the frame pointer for your target/configuration.
  • Which compiler options preserve frame pointers.
  • Whether there is a recommended intrinsic or API for obtaining the current frame pointer.
  • Preferred methods for implementing call stack unwinding with GHS.

They are best positioned to provide guidance specific to your compiler version and settings.

BR, Petr

31 Views
nitin_aher
Contributor I
Sure
0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2402409%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EHow%20to%20obtain%20the%20correct%20Frame%20Pointer%20(FP)%20for%20DumpCallStack%20on%20S32K3%20using%20the%20GHS%20compiler%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2402409%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20everyone%2C%3C%2FP%3E%3CP%3EI%20am%20working%20on%20an%20S32K3%20MCU%20using%20the%20Green%20Hills%20Software%20(GHS)%20compiler%2C%20and%20I%20am%20implementing%20a%20DumpCallStack%20function.%3C%2FP%3E%3CP%3ETo%20obtain%20the%20frame%20pointer%20(FP)%2C%20I%20am%20using%20the%20following%20inline%20assembly%3A%3C%2FP%3E%3CP%3E__asm%20volatile%20(%22mov%20%250%2C%20r7%22%20%3A%20%22%3Dr%22%20(locals.fp))%3B%3CBR%20%2F%3EHowever%2C%20the%20value%20I%20get%20for%20locals.fp%20is%200x02B1%2C%20which%20does%20not%20appear%20to%20be%20a%20valid%20frame%20pointer.%20It%20is%20not%20aligned%20and%20does%20not%20point%20to%20a%20valid%20stack%20location%2C%20so%20the%20call%20stack%20cannot%20be%20unwound%20correctly.%3C%2FP%3E%3CP%3EMy%20questions%20are%3A%3C%2FP%3E%3CP%3EWhat%20is%20the%20correct%20way%20to%20obtain%20the%20current%20frame%20pointer%20when%20using%20the%20GHS%20compiler%20on%20the%20S32K3%20(Arm%20Cortex-M7)%3F%3CBR%20%2F%3EDoes%20the%20GHS%20compiler%20always%20use%20R7%20as%20the%20frame%20pointer%2C%20or%20can%20it%20omit%20the%20frame%20pointer%20or%20use%20another%20register%20depending%20on%20the%20optimization%20level%3F%3CBR%20%2F%3EAre%20there%20any%20compiler%20options%20that%20must%20be%20enabled%20to%20preserve%20the%20frame%20pointer%20for%20stack%20unwinding%3F%3CBR%20%2F%3EIs%20there%20a%20recommended%20GHS-specific%20API%20or%20intrinsic%20for%20retrieving%20the%20frame%20pointer%20instead%20of%20using%20inline%20assembly%3F%3CBR%20%2F%3EIf%20anyone%20has%20implemented%20stack%20unwinding%20or%20a%20DumpCallStack%20function%20with%20the%20GHS%20compiler%20on%20S32K3%2C%20I%20would%20appreciate%20any%20guidance%20or%20examples.%3C%2FP%3E%3CP%3EThank%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2402789%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20How%20to%20obtain%20the%20correct%20Frame%20Pointer%20(FP)%20for%20DumpCallStack%20on%20S32K3%20using%20the%20GHS%20compiler%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2402789%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CDIV%3E%0A%3CP%3EI%20would%20not%20assume%20that%20R7%20is%20always%20used%20as%20the%20frame%20pointer.%20Depending%20on%20the%20GHS%20version%2C%20optimization%20level%2C%20and%20compiler%20options%2C%20the%20compiler%20may%20use%20a%20different%20register%20or%20omit%20the%20frame%20pointer%20entirely%20and%20use%20R7%20as%20a%20general-purpose%20register.%20The%20value%200x02B1%20suggests%20that%20R7%20might%20not%20be%20acting%20as%20a%20frame%20pointer%20in%20your%20build.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20check%20the%20generated%20assembly%20and%20verify%20whether%20GHS%20is%20creating%20frame%20records%20at%20all.%20If%20frame%20pointers%20are%20enabled%2C%20you%20should%20see%20a%20consistent%20function%20prologue%20saving%2Frestoring%20the%20frame%20pointer%3B%20otherwise%20stack%20unwinding%20based%20on%20R7%2FR11%20will%20not%20be%20reliable.%3C%2FP%3E%0A%3CP%3ESince%20this%20is%20primarily%20a%20compiler-specific%20question%2C%20I%20would%20also%20recommend%20contacting%20Green%20Hills%20Software%20support.%20They%20can%20advise%20on%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EWhether%20GHS%20uses%20R7%2C%20R11%2C%20or%20another%20register%20as%20the%20frame%20pointer%20for%20your%20target%2Fconfiguration.%3C%2FLI%3E%0A%3CLI%3EWhich%20compiler%20options%20preserve%20frame%20pointers.%3C%2FLI%3E%0A%3CLI%3EWhether%20there%20is%20a%20recommended%20intrinsic%20or%20API%20for%20obtaining%20the%20current%20frame%20pointer.%3C%2FLI%3E%0A%3CLI%3EPreferred%20methods%20for%20implementing%20call%20stack%20unwinding%20with%20GHS.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThey%20are%20best%20positioned%20to%20provide%20guidance%20specific%20to%20your%20compiler%20version%20and%20settings.%3C%2FP%3E%0A%3CP%3EBR%2C%20Petr%3C%2FP%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2403177%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20How%20to%20obtain%20the%20correct%20Frame%20Pointer%20(FP)%20for%20DumpCallStack%20on%20S32K3%20using%20the%20GHS%20compiler%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2403177%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ESure%3C%2FLINGO-BODY%3E