ARM: PIE: Add macro for generating PIE resume trampoline
authorRuss Dill <Russ.Dill@ti.com>
Tue, 17 Sep 2013 09:48:24 +0000 (02:48 -0700)
committer黄涛 <huangtao@rock-chips.com>
Thu, 21 Nov 2013 05:39:22 +0000 (13:39 +0800)
Add a helper that generates a short snippet of code that updates PIE
relocations, loads the stack pointer and calls a C (or asm) function.
The code gets placed into a PIE section.

Signed-off-by: Russ Dill <Russ.Dill@ti.com>
arch/arm/include/asm/suspend.h

index 1c0a551ae375490c8f81c589ae92511d509f0bb0..a9c350556a5f57acec7445aea01c5d2e085269d0 100644 (file)
@@ -1,7 +1,32 @@
 #ifndef __ASM_ARM_SUSPEND_H
 #define __ASM_ARM_SUSPEND_H
 
+#include <asm/pie.h>
+
 extern void cpu_resume(void);
 extern int cpu_suspend(unsigned long, int (*)(unsigned long));
 
+/**
+ * ARM_PIE_RESUME - generate a PIE trampoline for resume
+ * @proc:      SoC, should match argument used with PIE_OVERLAY_SECTION()
+ * @func:      C or asm function to call at resume
+ * @stack:     stack to use before calling func
+ */
+#define ARM_PIE_RESUME(proc, func, stack)                              \
+static void __naked __noreturn __pie(proc) proc##_resume_trampoline2(void) \
+{                                                                      \
+       __asm__ __volatile__(                                           \
+       "       mov     sp, %0\n"                                       \
+       : : "r"((stack)) : "sp");                                       \
+                                                                       \
+       func();                                                         \
+}                                                                      \
+                                                                       \
+void __naked __noreturn __pie(proc) proc##_resume_trampoline(void)     \
+{                                                                      \
+       pie_relocate_from_pie();                                        \
+       proc##_resume_trampoline2();                                    \
+}                                                                      \
+EXPORT_PIE_SYMBOL(proc##_resume_trampoline)
+
 #endif