9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@swtch.com>
To: 9fans@9fans.net
Subject: Re: [9fans] getcallerpc on arm7
Date: Mon, 31 Mar 2008 09:24:44 -0700	[thread overview]
Message-ID: <20080331162530.C70ED1E8C3A@holo.morphisms.net> (raw)
In-Reply-To: <47EB760E.30804@wmipf.in-berlin.de>

> Although I know that the Plan9 compilers and gcc organize
> function calls differently, I thought it would be helpful to
> understand what /sys/src/libc/arm/getcallerpc.s does -
> after having a look at A Manual for the Plan 9 assembler:
>
> 	MOVW	0(R13), R0
> 	RET
>
> Does this mean that it is just returning the contents of the
> first word on the Stack (R13) - and not interpreting &firstarg
> at all?

This appears to be wrong, but I don't have time to dig in.

The pointer is intended to be used on architectures like the x86
that automatically push the return address on the stack.

On architectures that don't push the return address on the
stack during the call instruction, the caller of getcallerpc
will have saved the desired return address somewhere in
its stack frame, and getcallerpc must root it out.

vc (the MIPS compiler) saves the return PC in the very last
word of the stack frame, so that /sys/src/libc/mips/getcallerpc.s:

	TEXT	getcallerpc(SB), $0
		MOVW	0(SP), R1
		RET

is correct.

It appears that 5c (the ARM compiler) saves the return PC
as the first word of the stack frame, which may be somewhat
hard to locate.

Russ



  reply	other threads:[~2008-03-31 16:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-27 10:25 Michael Teichgräber
2008-03-31 16:24 ` Russ Cox [this message]
2008-03-31 17:23   ` Michael Teichgräber
2008-03-31 19:09   ` Charles Forsyth
2008-03-31 22:34     ` Michael Teichgräber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080331162530.C70ED1E8C3A@holo.morphisms.net \
    --to=rsc@swtch.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).