Skip to content

Commit 2fab064

Browse files
authored
Merge pull request #369 from ilovepi/frame-pointers
Specify the stack slot the frame pointer points to
2 parents d0e8164 + e353f99 commit 2fab064

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

riscv-cc.adoc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,42 @@ endif::[]
2828
In the standard ABI, procedures should not modify the integer registers tp and
2929
gp, because signal handlers may rely upon their values.
3030

31+
=== Frame Pointer Convention
32+
3133
The presence of a frame pointer is optional. If a frame pointer exists,
3234
it must reside in x8 (s0); the register remains callee-saved.
3335

36+
Code that uses a frame pointer will construct a linked list of stack frames,
37+
where each frame links to its caller using a "frame record". A frame record
38+
consists of two XLEN values on the stack; the return address and the link to
39+
the next frame record. The frame pointer register will point to the innermost
40+
frame, thereby starting the linked list. By convention, the lowest XLEN value
41+
shall point to the previous frame, while the next XLEN value shall be the
42+
return address. The end of the frame record chain is indicated by the address
43+
zero appearing as the next link in the chain.
44+
45+
After the prologue, the frame pointer register will point to the Canonical
46+
Frame Address or CFA, which is the stack pointer value on entry to the current
47+
procedure. The previous frame pointer and return address pair will reside just
48+
prior to the current stack address held in `fp`. This puts the return address
49+
at `fp - XLEN/8`, and the previous frame pointer at `fp - 2 * XLEN/8`.
50+
51+
It is left to the platform to determine the level of conformance with this
52+
convention. A platform may choose:
53+
54+
- not to maintain a frame chain and use the frame pointer register as a general
55+
purpose callee-saved register.
56+
57+
- to allow the frame pointer register be used as a general purpose callee-saved
58+
register, but provide a platform specific mechanism to reliably detect this
59+
condition.
60+
61+
- to use a frame pointer to address a valid frame record at all times, but
62+
allow any procedure to choose to forgo creating a frame record.
63+
64+
- to use the frame pointer to address a valid frame record at all times, except
65+
leaf functions, who may elect to forgo creating a frame record.
66+
3467
=== Floating-point Register Convention
3568

3669
.Floating-point register convention

0 commit comments

Comments
 (0)