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
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or modify it under
* the t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e a s p u b l i s h e d b y t h e F r e e
* Software F o u n d a t i o n ( v e r s i o n 2 o f t h e L i c e n s e ) .
* /
# if d e f i n e d ( _ _ L I T T L E _ E N D I A N _ _ )
# define S T W X _ B E s t w b r x
# define L W Z X _ B E l w b r x
# elif d e f i n e d ( _ _ B I G _ E N D I A N _ _ )
# define S T W X _ B E s t w x
# define L W Z X _ B E l w z x
# else
# error n o e n d i a n n e s s d e f i n e d !
# endif
.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 * /
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 * /
bl 0 f / * W o r k o u t w h e r e w e ' r e r u n n i n g * /
0 : mflr % r18
/* 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 :
/* 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
.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