public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] Save/restore global data pointer on API boundary
@ 2012-08-07 17:02 Leif Lindholm
  2012-08-07 18:30 ` Wolfgang Denk
  0 siblings, 1 reply; 3+ messages in thread
From: Leif Lindholm @ 2012-08-07 17:02 UTC (permalink / raw)
  To: u-boot

Most architectures keep the global data pointer (gd) in a register.
When using the external app API, because they are calling us rather
than we calling them, this register can be corrupted.

The attached (trivial) patch saves the gd pointer at api_init(),
and restores it on every entry to syscall(). This may want to be
put behind an ifdef for those architectures that don't use a
dedicated register.

Signed-off-by: Leif Lindholm <leif.lindholm@arm.com>
---
diff --git a/api/api.c b/api/api.c
index a3bf60a..b911270 100644
--- a/api/api.c
+++ b/api/api.c
@@ -33,6 +33,8 @@

  #include "api_private.h"

+DECLARE_GLOBAL_DATA_PTR;
+
  #define DEBUG
  #undef DEBUG

@@ -600,6 +602,13 @@ static int API_display_clear(va_list ap)
  static cfp_t calls_table[API_MAXCALL] = { NULL, };

  /*
+ * The global data pointer is held in a register on most if not all
+ * architectures. Its value is not retained across the API boundary,
+ * so must be manually restored.
+ */
+static void volatile *gd_backup;
+
+/*
   * The main syscall entry point - this is not reentrant, only one call is
   * serviced until finished.
   *
@@ -620,6 +629,8 @@ int syscall(int call, int *retval, ...)
         va_list ap;
         int rv;

+       gd = gd_backup;
+
         if (call < 0 || call >= calls_no) {
                 debugf("invalid call #%d\n", call);
                 return 0;
@@ -686,6 +697,7 @@ void api_init(void)
         sig->checksum = crc32(0, (unsigned char *)sig,
                               sizeof(struct api_signature));
         debugf("syscall entry: 0x%08x\n", sig->syscall);
+       gd_backup = gd;
  }

  void platform_set_mr(struct sys_info *si, unsigned long start, unsigned long size,

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-08-08  9:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox