Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

mandate stack alignment throughout entire program life #13

Open
jnk0le opened this issue Aug 6, 2022 · 3 comments
Open

mandate stack alignment throughout entire program life #13

jnk0le opened this issue Aug 6, 2022 · 3 comments

Comments

@jnk0le
Copy link

jnk0le commented Aug 6, 2022

the rationale is to allow the CLIC, inline handlers, or custom hw stacking to assume that the stack is always properly aligned on entry.

There are also no usefull scenarios for allowing unaligned stack within functions - no jit, no post/pre indexed load/stores and Zcmp[e] push/pop encode stack adjustment separately from reglist.

currently psabi mandates stack alignmet like:

In the standard ABI, the stack pointer must remain aligned throughout procedure execution. Non-
standard ABI code must realign the stack pointer prior to invoking standard ABI procedures. The
operating system must realign the stack pointer prior to invoking a signal handler; hence, POSIX
signal handlers need not realign the stack pointer. In systems that service interrupts using the
interruptee’s stack, the interrupt service routine must realign the stack pointer if linked with any
code that uses a non-standard stack-alignment discipline, but need not realign the stack pointer if
all code adheres to the standard ABI.

which means that interrupt handlers have to assume the stack will be unaligned.

@asb
Copy link

asb commented Aug 15, 2022

What kind of statement were you imagining here? The standard ABI already mandates that the stack must be properly aligned at all times (but notes that code that doesn't comply with the standard ABI might not do this).

@jnk0le
Copy link
Author

jnk0le commented Aug 15, 2022

but notes that code that doesn't comply with the standard ABI might not do this

and because of that, interrupt handling can't assume aligned stack, the intent is to forbid non-compliant stacking.

Also the EABI definition is currently quite empty, noting only the alignment amount

The stack alignment for XLEN=32 systems is 8 bytes.

which could be understood as alignment only on function calls.

@asb
Copy link

asb commented Aug 16, 2022

I suppose it's more a point about what the ABI can reasonably mandate, especially around code that chooses not to comply with the ABI.

Practically, perhaps it would make sense to add something like "Code generators targeting the EABI must not create functions with a non-standard ABI that do not comply with the EABI rules on stack pointer alignment."

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants