Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * kexec trampoline
0004  *
0005  * Based on code taken from kexec-tools and kexec-lite.
0006  *
0007  * Copyright (C) 2004 - 2005, Milton D Miller II, IBM Corporation
0008  * Copyright (C) 2006, Mohan Kumar M, IBM Corporation
0009  * Copyright (C) 2013, Anton Blanchard, IBM Corporation
0010  */
0011 
0012 #include <asm/asm-compat.h>
0013 #include <asm/crashdump-ppc64.h>
0014 
0015     .balign 256
0016     .globl purgatory_start
0017 purgatory_start:
0018     b   master
0019 
0020     /* ABI: possible run_at_load flag at 0x5c */
0021     .org purgatory_start + 0x5c
0022     .globl run_at_load
0023 run_at_load:
0024     .long 0
0025     .size run_at_load, . - run_at_load
0026 
0027     /* ABI: slaves start at 60 with r3=phys */
0028     .org purgatory_start + 0x60
0029 slave:
0030     b .
0031     /* ABI: end of copied region */
0032     .org purgatory_start + 0x100
0033     .size purgatory_start, . - purgatory_start
0034 
0035 /*
0036  * The above 0x100 bytes at purgatory_start are replaced with the
0037  * code from the kernel (or next stage) by setup_purgatory().
0038  */
0039 
0040 master:
0041     or  %r1,%r1,%r1 /* low priority to let other threads catchup */
0042     isync
0043     mr  %r17,%r3    /* save cpu id to r17 */
0044     mr  %r15,%r4    /* save physical address in reg15 */
0045 
0046     /* Work out where we're running */
0047     bcl 20, 31, 0f
0048 0:  mflr    %r18
0049 
0050     /*
0051      * Copy BACKUP_SRC_SIZE bytes from BACKUP_SRC_START to
0052      * backup_start 8 bytes at a time.
0053      *
0054      * Use r3 = dest, r4 = src, r5 = size, r6 = count
0055      */
0056     ld  %r3, (backup_start - 0b)(%r18)
0057     cmpdi   %cr0, %r3, 0
0058     beq .Lskip_copy /* skip if there is no backup region */
0059     lis %r5, BACKUP_SRC_SIZE@h
0060     ori %r5, %r5, BACKUP_SRC_SIZE@l
0061     cmpdi   %cr0, %r5, 0
0062     beq .Lskip_copy /* skip if copy size is zero */
0063     lis %r4, BACKUP_SRC_START@h
0064     ori %r4, %r4, BACKUP_SRC_START@l
0065     li  %r6, 0
0066 .Lcopy_loop:
0067     ldx %r0, %r6, %r4
0068     stdx    %r0, %r6, %r3
0069     addi    %r6, %r6, 8
0070     cmpld   %cr0, %r6, %r5
0071     blt .Lcopy_loop
0072 
0073 .Lskip_copy:
0074     or  %r3,%r3,%r3 /* ok now to high priority, lets boot */
0075     lis %r6,0x1
0076     mtctr   %r6     /* delay a bit for slaves to catch up */
0077     bdnz    .       /* before we overwrite 0-100 again */
0078 
0079     /* load device-tree address */
0080     ld  %r3, (dt_offset - 0b)(%r18)
0081     mr  %r16,%r3    /* save dt address in reg16 */
0082     li  %r4,20
0083     LWZX_BE %r6,%r3,%r4 /* fetch __be32 version number at byte 20 */
0084     cmpwi   %cr0,%r6,2  /* v2 or later? */
0085     blt 1f
0086     li  %r4,28
0087     STWX_BE %r17,%r3,%r4    /* Store my cpu as __be32 at byte 28 */
0088 1:
0089     /* Load opal base and entry values in r8 & r9 respectively */
0090     ld  %r8,(opal_base - 0b)(%r18)
0091     ld  %r9,(opal_entry - 0b)(%r18)
0092 
0093     /* load the kernel address */
0094     ld  %r4,(kernel - 0b)(%r18)
0095 
0096     /* load the run_at_load flag */
0097     /* possibly patched by kexec */
0098     ld  %r6,(run_at_load - 0b)(%r18)
0099     /* and patch it into the kernel */
0100     stw %r6,(0x5c)(%r4)
0101 
0102     mr  %r3,%r16    /* restore dt address */
0103 
0104     li  %r5,0       /* r5 will be 0 for kernel */
0105 
0106     mfmsr   %r11
0107     andi.   %r10,%r11,1 /* test MSR_LE */
0108     bne .Little_endian
0109 
0110     mtctr   %r4     /* prepare branch to */
0111     bctr            /* start kernel */
0112 
0113 .Little_endian:
0114     mtsrr0  %r4     /* prepare branch to */
0115 
0116     clrrdi  %r11,%r11,1 /* clear MSR_LE */
0117     mtsrr1  %r11
0118 
0119     rfid            /* update MSR and start kernel */
0120 
0121     .balign 8
0122     .globl kernel
0123 kernel:
0124     .8byte  0x0
0125     .size kernel, . - kernel
0126 
0127     .balign 8
0128     .globl dt_offset
0129 dt_offset:
0130     .8byte  0x0
0131     .size dt_offset, . - dt_offset
0132 
0133     .balign 8
0134     .globl backup_start
0135 backup_start:
0136     .8byte  0x0
0137     .size backup_start, . - backup_start
0138 
0139     .balign 8
0140     .globl opal_base
0141 opal_base:
0142     .8byte  0x0
0143     .size opal_base, . - opal_base
0144 
0145     .balign 8
0146     .globl opal_entry
0147 opal_entry:
0148     .8byte  0x0
0149     .size opal_entry, . - opal_entry
0150 
0151     .data
0152     .balign 8
0153 .globl purgatory_sha256_digest
0154 purgatory_sha256_digest:
0155     .skip   32
0156     .size purgatory_sha256_digest, . - purgatory_sha256_digest
0157 
0158     .balign 8
0159 .globl purgatory_sha_regions
0160 purgatory_sha_regions:
0161     .skip   8 * 2 * 16
0162     .size purgatory_sha_regions, . - purgatory_sha_regions