Path: blob/master/arch/powerpc/purgatory/trampoline_64.S
26424 views
/* SPDX-License-Identifier: GPL-2.0-only */1/*2* kexec trampoline3*4* Based on code taken from kexec-tools and kexec-lite.5*6* Copyright (C) 2004 - 2005, Milton D Miller II, IBM Corporation7* Copyright (C) 2006, Mohan Kumar M, IBM Corporation8* Copyright (C) 2013, Anton Blanchard, IBM Corporation9*/1011#include <asm/asm-compat.h>12#include <asm/crashdump-ppc64.h>1314.balign 25615.globl purgatory_start16purgatory_start:17b master1819/* ABI: possible run_at_load flag at 0x5c */20.org purgatory_start + 0x5c21.globl run_at_load22run_at_load:23.long 024.size run_at_load, . - run_at_load2526/* ABI: slaves start at 60 with r3=phys */27.org purgatory_start + 0x6028slave:29b .30/* ABI: end of copied region */31.org purgatory_start + 0x10032.size purgatory_start, . - purgatory_start3334/*35* The above 0x100 bytes at purgatory_start are replaced with the36* code from the kernel (or next stage) by setup_purgatory().37*/3839master:40or %r1,%r1,%r1 /* low priority to let other threads catchup */41isync42mr %r17,%r3 /* save cpu id to r17 */43mr %r15,%r4 /* save physical address in reg15 */4445/* Work out where we're running */46bcl 20, 31, 0f470: mflr %r184849/*50* Copy BACKUP_SRC_SIZE bytes from BACKUP_SRC_START to51* backup_start 8 bytes at a time.52*53* Use r3 = dest, r4 = src, r5 = size, r6 = count54*/55ld %r3, (backup_start - 0b)(%r18)56cmpdi %cr0, %r3, 057beq .Lskip_copy /* skip if there is no backup region */58lis %r5, BACKUP_SRC_SIZE@h59ori %r5, %r5, BACKUP_SRC_SIZE@l60cmpdi %cr0, %r5, 061beq .Lskip_copy /* skip if copy size is zero */62lis %r4, BACKUP_SRC_START@h63ori %r4, %r4, BACKUP_SRC_START@l64li %r6, 065.Lcopy_loop:66ldx %r0, %r6, %r467stdx %r0, %r6, %r368addi %r6, %r6, 869cmpld %cr0, %r6, %r570blt .Lcopy_loop7172.Lskip_copy:73or %r3,%r3,%r3 /* ok now to high priority, lets boot */74lis %r6,0x175mtctr %r6 /* delay a bit for slaves to catch up */76bdnz . /* before we overwrite 0-100 again */7778/* load device-tree address */79ld %r3, (dt_offset - 0b)(%r18)80mr %r16,%r3 /* save dt address in reg16 */81li %r4,2082LWZX_BE %r6,%r3,%r4 /* fetch __be32 version number at byte 20 */83cmpwi %cr0,%r6,2 /* v2 or later? */84blt 1f85li %r4,2886STWX_BE %r17,%r3,%r4 /* Store my cpu as __be32 at byte 28 */871:88/* Load opal base and entry values in r8 & r9 respectively */89ld %r8,(opal_base - 0b)(%r18)90ld %r9,(opal_entry - 0b)(%r18)9192/* load the kernel address */93ld %r4,(kernel - 0b)(%r18)9495/* load the run_at_load flag */96/* possibly patched by kexec */97ld %r6,(run_at_load - 0b)(%r18)98/* and patch it into the kernel */99stw %r6,(0x5c)(%r4)100101mr %r3,%r16 /* restore dt address */102103li %r5,0 /* r5 will be 0 for kernel */104105mfmsr %r11106andi. %r10,%r11,1 /* test MSR_LE */107bne .Little_endian108109mtctr %r4 /* prepare branch to */110bctr /* start kernel */111112.Little_endian:113mtsrr0 %r4 /* prepare branch to */114115clrrdi %r11,%r11,1 /* clear MSR_LE */116mtsrr1 %r11117118rfid /* update MSR and start kernel */119120.balign 8121.globl kernel122kernel:123.8byte 0x0124.size kernel, . - kernel125126.balign 8127.globl dt_offset128dt_offset:129.8byte 0x0130.size dt_offset, . - dt_offset131132.balign 8133.globl backup_start134backup_start:135.8byte 0x0136.size backup_start, . - backup_start137138.balign 8139.globl opal_base140opal_base:141.8byte 0x0142.size opal_base, . - opal_base143144.balign 8145.globl opal_entry146opal_entry:147.8byte 0x0148.size opal_entry, . - opal_entry149150.data151.balign 8152.globl purgatory_sha256_digest153purgatory_sha256_digest:154.skip 32155.size purgatory_sha256_digest, . - purgatory_sha256_digest156157.balign 8158.globl purgatory_sha_regions159purgatory_sha_regions:160.skip 8 * 2 * 16161.size purgatory_sha_regions, . - purgatory_sha_regions162163164