2019-06-01 11:08:55 +03:00
/* SPDX-License-Identifier: GPL-2.0-only */
2016-11-29 15:45:52 +03:00
/ *
* kexec t r a m p o l i n e
*
* Based o n c o d e t a k e n f r o m k e x e c - t o o l s a n d k e x e c - l i t e .
*
* Copyright ( C ) 2 0 0 4 - 2 0 0 5 , M i l t o n D M i l l e r I I , I B M C o r p o r a t i o n
* Copyright ( C ) 2 0 0 6 , M o h a n K u m a r M , I B M C o r p o r a t i o n
* Copyright ( C ) 2 0 1 3 , A n t o n B l a n c h a r d , I B M C o r p o r a t i o n
* /
2018-07-05 19:24:57 +03:00
# include < a s m / a s m - c o m p a t . h >
2020-07-29 14:42:58 +03:00
# include < a s m / c r a s h d u m p - p p c64 . h >
2016-11-29 15:45:52 +03:00
.machine ppc64
.balign 256
.globl purgatory_start
purgatory_start :
b m a s t e r
/* ABI: possible run_at_load flag at 0x5c */
.org purgatory_start + 0 x5 c
.globl run_at_load
run_at_load :
.long 0
.size run_ a t _ l o a d , . - r u n _ a t _ l o a d
/* ABI: slaves start at 60 with r3=phys */
.org purgatory_start + 0 x6 0
slave :
b .
/* ABI: end of copied region */
.org purgatory_start + 0 x1 0 0
.size purgatory_ s t a r t , . - p u r g a t o r y _ s t a r t
/ *
* The a b o v e 0 x10 0 b y t e s a t p u r g a t o r y _ s t a r t a r e r e p l a c e d w i t h t h e
* code f r o m t h e k e r n e l ( o r n e x t s t a g e ) b y s e t u p _ p u r g a t o r y ( ) .
* /
master :
or % r1 ,% r1 ,% r1 / * l o w p r i o r i t y t o l e t o t h e r t h r e a d s c a t c h u p * /
isync
mr % r17 ,% r3 / * s a v e c p u i d t o r17 * /
mr % r15 ,% r4 / * s a v e p h y s i c a l a d d r e s s i n r e g 1 5 * /
2020-07-29 14:42:58 +03:00
/* Work out where we're running */
bcl 2 0 , 3 1 , 0 f
0 : mflr % r18
/ *
* Copy B A C K U P _ S R C _ S I Z E b y t e s f r o m B A C K U P _ S R C _ S T A R T t o
* backup_ s t a r t 8 b y t e s a t a t i m e .
*
* Use r3 = d e s t , r4 = s r c , r5 = s i z e , r6 = c o u n t
* /
ld % r3 , ( b a c k u p _ s t a r t - 0 b ) ( % r18 )
cmpdi % c r0 , % r3 , 0
beq . L s k i p _ c o p y / * s k i p i f t h e r e i s n o b a c k u p r e g i o n * /
lis % r5 , B A C K U P _ S R C _ S I Z E @h
ori % r5 , % r5 , B A C K U P _ S R C _ S I Z E @l
cmpdi % c r0 , % r5 , 0
beq . L s k i p _ c o p y / * s k i p i f c o p y s i z e i s z e r o * /
lis % r4 , B A C K U P _ S R C _ S T A R T @h
ori % r4 , % r4 , B A C K U P _ S R C _ S T A R T @l
li % r6 , 0
.Lcopy_loop :
ldx % r0 , % r6 , % r4
stdx % r0 , % r6 , % r3
addi % r6 , % r6 , 8
cmpld % c r0 , % r6 , % r5
blt . L c o p y _ l o o p
.Lskip_copy :
2016-11-29 15:45:52 +03:00
or % r3 ,% r3 ,% r3 / * o k n o w t o h i g h p r i o r i t y , l e t s b o o t * /
lis % r6 ,0 x1
mtctr % r6 / * d e l a y a b i t f o r s l a v e s t o c a t c h u p * /
bdnz . / * b e f o r e w e o v e r w r i t e 0 - 1 0 0 a g a i n * /
/* load device-tree address */
ld % r3 , ( d t _ o f f s e t - 0 b ) ( % r18 )
mr % r16 ,% r3 / * s a v e d t a d d r e s s i n r e g 1 6 * /
li % r4 ,2 0
LWZX_ B E % r6 ,% r3 ,% r4 / * f e t c h _ _ b e 3 2 v e r s i o n n u m b e r a t b y t e 2 0 * /
2017-08-05 20:55:11 +03:00
cmpwi % c r0 ,% r6 ,2 / * v2 o r l a t e r ? * /
2016-11-29 15:45:52 +03:00
blt 1 f
li % r4 ,2 8
STWX_ B E % r17 ,% r3 ,% r4 / * S t o r e m y c p u a s _ _ b e 3 2 a t b y t e 2 8 * /
1 :
2020-07-29 14:44:06 +03:00
/* Load opal base and entry values in r8 & r9 respectively */
ld % r8 ,( o p a l _ b a s e - 0 b ) ( % r18 )
ld % r9 ,( o p a l _ e n t r y - 0 b ) ( % r18 )
2016-11-29 15:45:52 +03:00
/* load the kernel address */
ld % r4 ,( k e r n e l - 0 b ) ( % r18 )
/* load the run_at_load flag */
/* possibly patched by kexec */
ld % r6 ,( r u n _ a t _ l o a d - 0 b ) ( % r18 )
/* and patch it into the kernel */
stw % r6 ,( 0 x5 c ) ( % r4 )
mr % r3 ,% r16 / * r e s t o r e d t a d d r e s s * /
li % r5 ,0 / * r5 w i l l b e 0 f o r k e r n e l * /
mfmsr % r11
andi. % r10 ,% r11 ,1 / * t e s t M S R _ L E * /
bne . L i t t l e _ e n d i a n
mtctr % r4 / * p r e p a r e b r a n c h t o * /
bctr / * s t a r t k e r n e l * /
.Little_endian :
mtsrr0 % r4 / * p r e p a r e b r a n c h t o * /
clrrdi % r11 ,% r11 ,1 / * c l e a r M S R _ L E * /
mtsrr1 % r11
rfid / * u p d a t e M S R a n d s t a r t k e r n e l * /
.balign 8
.globl kernel
kernel :
2017-03-09 08:42:12 +03:00
.8byte 0x0
2016-11-29 15:45:52 +03:00
.size kernel, . - k e r n e l
.balign 8
.globl dt_offset
dt_offset :
2017-03-09 08:42:12 +03:00
.8byte 0x0
2016-11-29 15:45:52 +03:00
.size dt_ o f f s e t , . - d t _ o f f s e t
2020-07-29 14:42:58 +03:00
.balign 8
.globl backup_start
backup_start :
.8byte 0x0
.size backup_ s t a r t , . - b a c k u p _ s t a r t
2016-11-29 15:45:52 +03:00
2020-07-29 14:44:06 +03:00
.balign 8
.globl opal_base
opal_base :
.8byte 0x0
.size opal_ b a s e , . - o p a l _ b a s e
.balign 8
.globl opal_entry
opal_entry :
.8byte 0x0
.size opal_ e n t r y , . - o p a l _ e n t r y
2016-11-29 15:45:52 +03:00
.data
.balign 8
2017-03-10 15:17:18 +03:00
.globl purgatory_sha256_digest
purgatory_sha256_digest :
2016-11-29 15:45:52 +03:00
.skip 32
2017-03-10 15:17:18 +03:00
.size purgatory_ s h a25 6 _ d i g e s t , . - p u r g a t o r y _ s h a25 6 _ d i g e s t
2016-11-29 15:45:52 +03:00
.balign 8
2017-03-10 15:17:18 +03:00
.globl purgatory_sha_regions
purgatory_sha_regions :
2016-11-29 15:45:52 +03:00
.skip 8 * 2 * 1 6
2017-03-10 15:17:18 +03:00
.size purgatory_ s h a _ r e g i o n s , . - p u r g a t o r y _ s h a _ r e g i o n s