All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@arm.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Save/restore global data pointer on API boundary
Date: Wed, 08 Aug 2012 10:44:46 +0100	[thread overview]
Message-ID: <5022350E.4050509@arm.com> (raw)
In-Reply-To: <20120807183021.B52BD204016@gemini.denx.de>

On 08/07/12 19:30, Wolfgang Denk wrote:
>> Most architectures keep the global data pointer (gd) in a register.
>
> This may, or may not be.  You should not make any assumptions on how
> gd is implemented.

The comment did, the code didn't, as long as gd was a pointer (which
should be a safe assumption). But that's irrelevant as I seem to have
gotten the wrong end of the stick.

>> When using the external app API, because they are calling us rather
>> than we calling them, this register can be corrupted.
>
> How can this be?  The caller should always use the same register
> convention as we do - otherwise we are in a much deeper trouble.
> It is up to the caller to make sure it uses the published API (resp.
> ABI).

Hmm, ok - this was not clear to me from the docs and example.

Indeed, the example does not reserve r8 (on ARM) or r2 (on PPC). Nor
does it save/restore it on entry/syscall. I don't know the exact ABI
semantics of r2 for PPC, but on ARM this is an error.

This could be worked around by something like:

diff --git a/examples/api/crt0.S b/examples/api/crt0.S
index 6daf127..5f956e4 100644
--- a/examples/api/crt0.S
+++ b/examples/api/crt0.S
@@ -49,13 +49,21 @@ syscall:
  _start:
         ldr     ip, =search_hint
         str     sp, [ip]
+       ldr     ip, =gd_backup
+       str     r8, [ip]
         b       main


         .globl syscall
  syscall:
+       push    {r6-r8, lr}
+       ldr     r6, =gd_backup
+       ldr     r8, [r6]
         ldr     ip, =syscall_ptr
+       mov     lr, pc
         ldr     pc, [ip]
+       str     r8, [r6]
+       pop     {r6-r8, pc}

  #else
  #error No support for this arch!
@@ -69,3 +77,7 @@ syscall_ptr:
         .globl search_hint
  search_hint:
         .long   0
+
+       .globl gd_backup
+gd_backup:
+       .long   0


An alternative would be to mandate DECLARE_GLOBAL_DATA_PTR for all API
applications, but I'd frankly prefer not providing direct access to gd.

Best Regards,

Leif

      reply	other threads:[~2012-08-08  9:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-07 17:02 [U-Boot] [PATCH] Save/restore global data pointer on API boundary Leif Lindholm
2012-08-07 18:30 ` Wolfgang Denk
2012-08-08  9:44   ` Leif Lindholm [this message]

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=5022350E.4050509@arm.com \
    --to=leif.lindholm@arm.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.