ARM Registers and Link Map

Status
Not open for further replies.

jerryk

Member
Hello,

I'm starting up a project with a Teensy 4.1 and an ILI9341 display. Using the Arduino IDE. Have successfully done a "hello world" - the code uploads, the serial monitor works, and the display displays. Woo hoo!

I'd like to implement a stack canary - preload the end of the stack with a magic number and periodically check to see it's still there. Also check that the stack pointer is the same value every swing around the main loop.

I did this with the Arduino Nano by an external variable "SP" provided by the system. That doesn't seem to work on the Teensy. Anybody know how to access the SP and possibly other internal registers from C++? And how to view a link map?

Thanks in advance,

- jerryk
 
ARM does have a SP register, but it is a CPU register, not memory mapped like AVR. So to access it you need to use inline ASM. For an example, see the startup code.

https://github.com/PaulStoffregen/c...0ab61b22a30e0b70eee9a5c/teensy4/startup.c#L66

This code writes to SP, but reading works basically the same way. Inline ASM is needed. The other CPU registers can also be accessed this way.

Many details of the ARM stack are somewhat different from AVR. To really understand, you should get the Definitive Guide book.

https://www.amazon.com/dp/0124080820

In theory you could also find this info on ARM's website, but their reference material is pretty much unreadable if you don't already know how the ARM processor works. That book is the only source I've seen which is actually usable for learning.

The Arduino IDE compiles your code in a temporary folder. You may need to use "show verbose output" in File > Preferences to see the commands with the full pathnames to figure out its location. Inside that folder, a .sym file is created with the memory layout.
 
Not sure if exactly what you are looking for:

But if you look at the library st77t3 that ships with Teensyduino, at the example sketch uncannyeEyes_async_st7789

There is code at the start which fills most of the stack area with some known values...
And then at different times we call off to a function that looks at current stack area to guess how much of it that has been used, as a clue to how much of the stack has been changed...

Could post the code, but it is in the example at the end of the sketch.
 
Status
Not open for further replies.
Back
Top