[PATCH 9/10] powerpc: Add helper functions for synthesising instructions at runtime
Michael Ellerman
michael at ellerman.id.au
Thu Oct 13 18:42:25 EST 2005
There's a few places already, and soon will be more, where we synthesise
branch instructions at runtime. Rather than doing it by hand in each case,
it would make sense to have one implementation.
Signed-off-by: Michael Ellerman <michael at ellerman.id.au>
---
include/asm-powerpc/system.h | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+)
Index: kexec/include/asm-powerpc/system.h
===================================================================
--- kexec.orig/include/asm-powerpc/system.h
+++ kexec/include/asm-powerpc/system.h
@@ -356,5 +356,42 @@ extern void reloc_got2(unsigned long);
#define PTRRELOC(x) ((typeof(x)) add_reloc_offset((unsigned long)(x)))
+static inline void make_instruction(unsigned long addr, unsigned int instr)
+{
+ unsigned int *p;
+ p = (unsigned int *)addr;
+ *p = instr;
+ asm ("dcbst 0, %0; sync; icbi 0,%0; isync" : : "r" (p));
+}
+
+static inline void make_branch(unsigned long addr, unsigned long target,
+ int link, int absolute)
+{
+ unsigned int instruction;
+
+ instruction = 0x48000000;
+ instruction |= link & 0x01;
+ instruction |= (absolute & 0x01) << 1;
+
+ if (link)
+ target = target - addr;
+
+ instruction |= target & 0x03fffffC;
+
+ make_instruction(addr, instruction);
+}
+
+static inline void make_function_call(unsigned long addr, void * func)
+{
+ unsigned long func_addr;
+
+#ifdef CONFIG_PPC64
+ func_addr = *(unsigned long *)func;
+#else
+ func_addr = (unsigned long)func;
+#endif
+ make_branch(addr, func_addr, 1, 0);
+}
+
#endif /* __KERNEL__ */
#endif /* _ASM_POWERPC_SYSTEM_H */
More information about the Linuxppc64-dev
mailing list