Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

Add force-setting of stack pointer in startup code #254

Closed

Description

@korken89

During experimenting with new unsafe code I realized that the stack pointer can easily be corrupted, and this can propagate and stick after a system reset while having a debugger connected.
This causes preinit to automatically hardfault if using the stack and the zeroing/init of RAM under no optimization also directly hardfaults.

I propose we add the code to always hard-load the stack pointer from the vector table.
It will cost a few bytes, but I argue that it is a price worth to pay to have stable debug/implementation runs.
Currently it is trivial to get into a very hard to debug state.

Activity

  1. jonas-schievink commented on Mar 20, 2020

    @jonas-schievink
    Contributor

    How/Why does this situation happen, exactly? I wouldn't want to work around issues we don't fully understand in cmrt.

  2. adamgreig commented on Mar 20, 2020

    @adamgreig
    Member

    The architecture reference manuals seem pretty explicit that SP is always initialised from the vector table on any power-on or reset, with no mention of exceptions, so something definitely seems wrong here. Do you have a short reproducible example?

  3. korken89 commented on Mar 20, 2020

    @korken89
    ContributorAuthor

    Sadly I'm far gone from this issue right now, but I'll look into reproducing it.
    The issue is not on the Cortex-M core or the reset itself though, it's the debuggers. It seems some do not implement reset correctly, for example the stlinkv2, which after reset mon reset halt had the old stack pointer in some cases (especially after HardFault).

  4. jonas-schievink commented on Jan 8, 2021

    @jonas-schievink
    Contributor

    I believe we discussed this at some point (or a similar issue) and concluded that this is a bug in the debugger that we don't really want to work around at this point, so closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions