Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support clobber_abi in AVR inline assembly #131323

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Commits on Nov 28, 2024

  1. Support clobber_abi for AVR inline assembly

    This commit adds the relevant registers to the list of clobbered regis-
    ters (part of rust-lang#93335). This follows the [ABI documentation] of AVR-GCC:
    
    > The [...] call-clobbered general purpose registers (GPRs) are
    > registers that might be destroyed (clobbered) by a function call.
    >
    > - **R18–R27, R30, R31**
    >
    >   These GPRs are call clobbered. An ordinary function may use them
    >   without restoring the contents. [...]
    >
    > - **R0, T-Flag**
    >
    >   The temporary register and the T-flag in SREG are also call-
    >   clobbered, but this knowledge is not exposed explicitly to the
    >   compiler (R0 is a fixed register).
    
    Therefore this commit lists the aforementioned registers `r18–r27`,
    `r30` and `r31` as clobbered registers. Since the `r0` register (listed
    above as well) is not available in inline assembly at all (potentially
    because the AVR-GCC considers it a fixed register causing the register
    to never be used in register allocation and LLVM adopting this), there
    is no need to list it in the clobber list (the `r0`-variant is not even
    available). A comment was added to ensure, that the `r0` gets added to
    the clobber-list once the register gets usable in inline ASM.
    Since the SREG is normally considered clobbered anyways (unless the user
    supplies the `preserve_flags`-option), there is no need to explicitly
    list a bit in this register (which is not possible to list anyways).
    
    Note, that this commit completely ignores the case of interrupts (that
    are described in the ABI-specification), since every register touched in
    an ISR need to be saved anyways.
    
    [ABI documentation]: https://gcc.gnu.org/wiki/avr-gcc#Call-Used_Registers
    jfrimmel committed Nov 28, 2024
    Configuration menu
    Copy the full SHA
    ba73166 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    d7e0a3e View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    2bd3bbb View commit details
    Browse the repository at this point in the history
  4. Reword error message of reserved AVR registers

    Those are reserved as per the GCC (and thus LLVM) ABI, which is distinct from an
    issue. The rewording was requested in this [review].
    
    [review]: rust-lang#131323 (comment)
    jfrimmel committed Nov 28, 2024
    Configuration menu
    Copy the full SHA
    67d2f3f View commit details
    Browse the repository at this point in the history