What does the instruction entry sp, 32 at the start of every windowed function do?
It completes the call. It rotates the register window by the amount the call instruction requested, copies the caller's stack pointer into the callee's sp, and subtracts 32 bytes from it to allocate the callee's stack frame.
The surprise is that call8 does not move the window itself. It only stores the requested shift (8) in a status field and jumps. entry, the first instruction of the callee, does the rest in three steps:
- Rotate the window by the amount the call recorded.
- Copy the stack pointer from the caller's
a1into the callee's newa1. - Allocate the frame by subtracting the immediate, here 32 bytes, from that new stack pointer. The stack grows downward, so subtracting reserves space.
Splitting the work lets one function serve all three call sizes: the same entry rotates by 4, 8 or 12 depending on which call reached it.
Even a function that uses no stack, such as int callee(int u, int v) { return u * v; }, asks for 32 bytes: GCC gives every windowed function this minimum frame.
The frame size is encoded in units of 8 bytes, so it must be a multiple of 8, at most 32760.
Go deeper:
Xtensa ISA Reference Manual, ENTRY (§6, PDF) — the instruction's exact operation.