[U-Boot] [PATCH] Save/restore global data pointer on API boundary

Leif Lindholm leif.lindholm at arm.com
Tue Aug 7 19:02:48 CEST 2012


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 at 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,



More information about the U-Boot mailing list