Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: ARM Registers and Link Map

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    5

    ARM Registers and Link Map

    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

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,227
    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/co.../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.

  3. #3
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,428
    Note, you can get much better output with these tricks:
    https://github.com/TeensyUser/doc/wi...d-symbol-files

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,755
    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.

  5. #5
    Junior Member
    Join Date
    May 2014
    Posts
    5
    [QUOTE=PaulStoffregen;293933] 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

    *** Reading it now. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •