/* Catch branch to 0 in real mode */
        trap
 
-       /* Secondary processors spin on this value until it becomes nonzero.
-        * When it does it contains the real address of the descriptor
-        * of the function that the cpu should jump to to continue
-        * initialization.
+       /* Secondary processors spin on this value until it becomes non-zero.
+        * When non-zero, it contains the real address of the function the cpu
+        * should jump to.
         */
        .balign 8
        .globl  __secondary_hold_spinloop
 #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
 #ifdef CONFIG_PPC_BOOK3E
        tovirt(r12,r12)
-#endif
-#if !defined(_CALL_ELF) || _CALL_ELF != 2
-       ld      r12,0(r12)              /* deref function descriptor */
 #endif
        mtctr   r12
        mr      r3,r24
        /* See if we need to call a cpu state restore handler */
        LOAD_REG_ADDR(r23, cur_cpu_spec)
        ld      r23,0(r23)
-       ld      r23,CPU_SPEC_RESTORE(r23)
-       cmpdi   0,r23,0
+       ld      r12,CPU_SPEC_RESTORE(r23)
+       cmpdi   0,r12,0
        beq     3f
-       ld      r12,0(r23)
+#if !defined(_CALL_ELF) || _CALL_ELF != 2
+       ld      r12,0(r12)
+#endif
        mtctr   r12
        bctrl
 
 
 
        ptr  = (unsigned long *)((unsigned long)&__secondary_hold_spinloop
                        - PHYSICAL_START);
-       *ptr = __pa(generic_secondary_smp_init);
+       *ptr = ppc_function_entry(generic_secondary_smp_init);
 
        /* And wait a bit for them to catch up */
        for (i = 0; i < 100000; i++) {
 
 #include <asm/cacheflush.h>
 #include <asm/dbell.h>
 #include <asm/fsl_guts.h>
+#include <asm/code-patching.h>
 
 #include <sysdev/fsl_soc.h>
 #include <sysdev/mpic.h>
        flush_spin_table(spin_table);
        out_be32(&spin_table->pir, hw_cpu);
        out_be64((u64 *)(&spin_table->addr_h),
-         __pa((u64)*((unsigned long long *)generic_secondary_smp_init)));
+               __pa(ppc_function_entry(generic_secondary_smp_init)));
        flush_spin_table(spin_table);
 #endif
 
 
 #include <asm/firmware.h>
 #include <asm/rtas.h>
 #include <asm/cputhreads.h>
+#include <asm/code-patching.h>
 
 #include "interrupt.h"
 #include <asm/udbg.h>
 static inline int smp_startup_cpu(unsigned int lcpu)
 {
        int status;
-       unsigned long start_here = __pa((u32)*((unsigned long *)
-                                              generic_secondary_smp_init));
+       unsigned long start_here =
+                       __pa(ppc_function_entry(generic_secondary_smp_init));
        unsigned int pcpu;
        int start_cpu;
 
 
 #include <asm/cputhreads.h>
 #include <asm/xics.h>
 #include <asm/opal.h>
+#include <asm/code-patching.h>
 
 #include "powernv.h"
 
 int pnv_smp_kick_cpu(int nr)
 {
        unsigned int pcpu = get_hard_smp_processor_id(nr);
-       unsigned long start_here = __pa(*((unsigned long *)
-                                         generic_secondary_smp_init));
+       unsigned long start_here =
+                       __pa(ppc_function_entry(generic_secondary_smp_init));
        long rc;
 
        BUG_ON(nr < 0 || nr >= NR_CPUS);
 
 #include <asm/xics.h>
 #include <asm/dbell.h>
 #include <asm/plpar_wrappers.h>
+#include <asm/code-patching.h>
 
 #include "pseries.h"
 #include "offline_states.h"
 static inline int smp_startup_cpu(unsigned int lcpu)
 {
        int status;
-       unsigned long start_here = __pa((u32)*((unsigned long *)
-                                              generic_secondary_smp_init));
+       unsigned long start_here =
+                       __pa(ppc_function_entry(generic_secondary_smp_init));
        unsigned int pcpu;
        int start_cpu;
 
 
 #include <asm/reg_a2.h>
 #include <asm/scom.h>
 #include <asm/udbg.h>
+#include <asm/code-patching.h>
 
 #include "wsp.h"
 
                        goto fail;
        }
 
-       start_here = *(unsigned long *)(core_setup ? generic_secondary_smp_init
+       start_here = ppc_function_entry(core_setup ? generic_secondary_smp_init
                                        : generic_secondary_thread_init);
        pr_devel("CPU%d entry point at 0x%lx...\n", lcpu, start_here);