[riscv-sw] RISC-V Stack frame layout

723 views
Skip to first unread message

Jeppe Græsdal Johansen

unread,
Aug 11, 2014, 11:49:07 AM8/11/14
to sw-...@lists.riscv.org
Is there any plan to document a standard stack frame layout in addition
to the other calling convention information?

Do anyone know what the stack frame layout used in the currently working
C compilers are?

Best Regards,
Jeppe

Yunsup Lee

unread,
Aug 11, 2014, 12:52:47 PM8/11/14
to Jeppe Græsdal Johansen, sw-...@lists.riscv.org
Please take a look at the description of the stack frame inside of our GCC compiler:

S Madhu

unread,
Aug 11, 2014, 1:06:14 PM8/11/14
to Yunsup Lee, sw-...@lists.riscv.org, Jeppe Græsdal Johansen

An official ABI is probaly needed soon. Does UCB plan to publish one or can so e of us volunteer to create one?

Andrew Waterman

unread,
Aug 11, 2014, 1:15:57 PM8/11/14
to S Madhu, Yunsup Lee, sw-...@lists.riscv.org, Jeppe Græsdal Johansen
We have an ABI; it's what our Linux toolchain generates :-).  But it needs to be formalized.  The calling convention part is already specified in the user ISA manual, but that is, of course, only a small fraction of the complexity.

I think it would be great if someone volunteered to write this up, but we'll need to iterate on it a bit.  I am sure in writing it up we'll find more cruft left over from the SGI ABI (which inspired the RISC-V ABI).

Baikal

unread,
May 30, 2018, 4:30:41 AM5/30/18
to RISC-V SW Dev, smadh...@gmail.com, yun...@eecs.berkeley.edu, sw-...@lists.riscv.org, je...@j-software.dk
Is there a new ABI document? I still could not find the stack frame layout.
I just find:
 caller_ra = *(callee_fp-4);
 caller_fp = *(callee_fp-8);
But I'm not sure. If you have the newest ABI document, please tell me how to download it, Thanks!

在 2014年8月12日星期二 UTC+8上午1:15:57,waterman写道:

Jim Wilson

unread,
May 30, 2018, 1:11:51 PM5/30/18
to Baikal, RISC-V SW Dev, smadh...@gmail.com, yun...@eecs.berkeley.edu, sw-...@lists.riscv.org, je...@j-software.dk
On Wed, May 30, 2018 at 1:30 AM, Baikal <dnd...@gmail.com> wrote:
> Is there a new ABI document? I still could not find the stack frame layout.
> I just find:
> caller_ra = *(callee_fp-4);
> caller_fp = *(callee_fp-8);
> But I'm not sure. If you have the newest ABI document, please tell me how to
> download it, Thanks!

https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md

You should not make any assumptions about stack frame layout. If you
need something from a stack frame, use a compiler builtin function if
available, or use the unwind info.

But, yes, assuming no compiler optimization, this is what gcc will do.
With compiler optimization, gcc may do something different, and there
is no guarantee that these values will be on the stack at those
locations at every point in the function. The builtin functions and
unwind info will work with compiler optimization.

Jim
Reply all
Reply to author
Forward
0 new messages