1 /* SPDX-License-Identifier: GPL-2.0-only */
5 * Based on code taken from kexec-tools and kexec-lite.
7 * Copyright (C) 2004 - 2005, Milton D Miller II, IBM Corporation
8 * Copyright (C) 2006, Mohan Kumar M, IBM Corporation
9 * Copyright (C) 2013, Anton Blanchard, IBM Corporation
12 #include <asm/asm-compat.h>
13 #include <asm/crashdump-ppc64.h>
17 .globl purgatory_start
21 /* ABI: possible run_at_load flag at 0x5c */
22 .org purgatory_start + 0x5c
26 .size run_at_load, . - run_at_load
28 /* ABI: slaves start at 60 with r3=phys */
29 .org purgatory_start + 0x60
32 /* ABI: end of copied region */
33 .org purgatory_start + 0x100
34 .size purgatory_start, . - purgatory_start
37 * The above 0x100 bytes at purgatory_start are replaced with the
38 * code from the kernel (or next stage) by setup_purgatory().
42 or %r1,%r1,%r1 /* low priority to let other threads catchup */
44 mr %r17,%r3 /* save cpu id to r17 */
45 mr %r15,%r4 /* save physical address in reg15 */
47 /* Work out where we're running */
52 * Copy BACKUP_SRC_SIZE bytes from BACKUP_SRC_START to
53 * backup_start 8 bytes at a time.
55 * Use r3 = dest, r4 = src, r5 = size, r6 = count
57 ld %r3, (backup_start - 0b)(%r18)
59 beq .Lskip_copy /* skip if there is no backup region */
60 lis %r5, BACKUP_SRC_SIZE@h
61 ori %r5, %r5, BACKUP_SRC_SIZE@l
63 beq .Lskip_copy /* skip if copy size is zero */
64 lis %r4, BACKUP_SRC_START@h
65 ori %r4, %r4, BACKUP_SRC_START@l
75 or %r3,%r3,%r3 /* ok now to high priority, lets boot */
77 mtctr %r6 /* delay a bit for slaves to catch up */
78 bdnz . /* before we overwrite 0-100 again */
80 /* load device-tree address */
81 ld %r3, (dt_offset - 0b)(%r18)
82 mr %r16,%r3 /* save dt address in reg16 */
84 LWZX_BE %r6,%r3,%r4 /* fetch __be32 version number at byte 20 */
85 cmpwi %cr0,%r6,2 /* v2 or later? */
88 STWX_BE %r17,%r3,%r4 /* Store my cpu as __be32 at byte 28 */
90 /* Load opal base and entry values in r8 & r9 respectively */
91 ld %r8,(opal_base - 0b)(%r18)
92 ld %r9,(opal_entry - 0b)(%r18)
94 /* load the kernel address */
95 ld %r4,(kernel - 0b)(%r18)
97 /* load the run_at_load flag */
98 /* possibly patched by kexec */
99 ld %r6,(run_at_load - 0b)(%r18)
100 /* and patch it into the kernel */
103 mr %r3,%r16 /* restore dt address */
105 li %r5,0 /* r5 will be 0 for kernel */
108 andi. %r10,%r11,1 /* test MSR_LE */
111 mtctr %r4 /* prepare branch to */
112 bctr /* start kernel */
115 mtsrr0 %r4 /* prepare branch to */
117 clrrdi %r11,%r11,1 /* clear MSR_LE */
120 rfid /* update MSR and start kernel */
126 .size kernel, . - kernel
132 .size dt_offset, . - dt_offset
138 .size backup_start, . - backup_start
144 .size opal_base, . - opal_base
150 .size opal_entry, . - opal_entry
154 .globl purgatory_sha256_digest
155 purgatory_sha256_digest:
157 .size purgatory_sha256_digest, . - purgatory_sha256_digest
160 .globl purgatory_sha_regions
161 purgatory_sha_regions:
163 .size purgatory_sha_regions, . - purgatory_sha_regions