2022-03-08 23:50:34 +10:00
/* SPDX-License-Identifier: GPL-2.0-or-later */
# include < a s m / a s m - o f f s e t s . h >
# include < a s m / b u g . h >
# include < a s m / p a g e . h >
# include < a s m / p p c _ a s m . h >
/ *
* RTAS i s c a l l e d w i t h M S R I R , D R , E E d i s a b l e d , a n d L R i n t h e r e t u r n a d d r e s s .
*
* Note : r3 i s a n i n p u t p a r a m e t e r t o r t a s , s o d o n ' t t r a s h i t . . .
* /
# ifdef C O N F I G _ P P C 3 2
_ GLOBAL( e n t e r _ r t a s )
stwu r1 ,- I N T _ F R A M E _ S I Z E ( r1 )
mflr r0
stw r0 ,I N T _ F R A M E _ S I Z E + 4 ( r1 )
LOAD_ R E G _ A D D R ( r4 , r t a s )
lis r6 ,1 f @ha /* physical return address for rtas */
addi r6 ,r6 ,1 f @l
tophys( r6 ,r6 )
lwz r8 ,R T A S E N T R Y ( r4 )
lwz r4 ,R T A S B A S E ( r4 )
mfmsr r9
stw r9 ,8 ( r1 )
li r9 ,M S R _ K E R N E L & ~ ( M S R _ I R | M S R _ D R )
mtlr r6
stw r1 , T H R E A D + R T A S _ S P ( r2 )
mtspr S P R N _ S R R 0 ,r8
mtspr S P R N _ S R R 1 ,r9
rfi
1 :
lis r8 , 1 f @h
ori r8 , r8 , 1 f @l
LOAD_ R E G _ I M M E D I A T E ( r9 ,M S R _ K E R N E L )
mtspr S P R N _ S R R 0 ,r8
mtspr S P R N _ S R R 1 ,r9
rfi / * R e a c t i v a t e M M U t r a n s l a t i o n * /
1 :
lwz r8 ,I N T _ F R A M E _ S I Z E + 4 ( r1 ) / * g e t r e t u r n a d d r e s s * /
lwz r9 ,8 ( r1 ) / * o r i g i n a l m s r v a l u e * /
addi r1 ,r1 ,I N T _ F R A M E _ S I Z E
li r0 ,0
stw r0 , T H R E A D + R T A S _ S P ( r2 )
mtlr r8
mtmsr r9
blr / * r e t u r n t o c a l l e r * /
_ ASM_ N O K P R O B E _ S Y M B O L ( e n t e r _ r t a s )
# else / * C O N F I G _ P P C 3 2 * /
# include < a s m / e x c e p t i o n - 6 4 s . h >
/ *
* 3 2 - bit r t a s o n 6 4 - b i t m a c h i n e s h a s t h e a d d i t i o n a l p r o b l e m t h a t R T A S m a y
* not p r e s e r v e t h e u p p e r p a r t s o f r e g i s t e r s i t u s e s .
* /
_ GLOBAL( e n t e r _ r t a s )
mflr r0
std r0 ,1 6 ( r1 )
2022-03-08 23:50:36 +10:00
stdu r1 ,- S W I T C H _ F R A M E _ S I Z E ( r1 ) / * S a v e S P a n d c r e a t e s t a c k s p a c e . * /
2022-03-08 23:50:34 +10:00
/ * Because R T A S i s r u n n i n g i n 3 2 b m o d e , i t c l o b b e r s t h e h i g h o r d e r h a l f
* of a l l r e g i s t e r s t h a t i t s a v e s . W e t h e r e f o r e s a v e t h o s e r e g i s t e r s
2022-03-08 23:50:40 +10:00
* RTAS m i g h t t o u c h t o t h e s t a c k . ( r0 , r3 - r12 a r e c a l l e r s a v e d )
2022-03-08 23:50:36 +10:00
* /
2022-03-08 23:50:34 +10:00
SAVE_ G P R ( 2 , r1 ) / * S a v e t h e T O C * /
SAVE_ N V G P R S ( r1 ) / * S a v e t h e n o n - v o l a t i l e s * /
mfcr r4
std r4 ,_ C C R ( r1 )
mfctr r5
std r5 ,_ C T R ( r1 )
mfspr r6 ,S P R N _ X E R
std r6 ,_ X E R ( r1 )
mfdar r7
std r7 ,_ D A R ( r1 )
mfdsisr r8
std r8 ,_ D S I S R ( r1 )
/ * Temporary w o r k a r o u n d t o c l e a r C R u n t i l R T A S c a n b e m o d i f i e d t o
* ignore a l l b i t s .
* /
li r0 ,0
mtcr r0
mfmsr r6
/ * Unfortunately, t h e s t a c k p o i n t e r a n d t h e M S R a r e a l s o c l o b b e r e d ,
* so t h e y a r e s a v e d i n t h e P A C A w h i c h a l l o w s u s t o r e s t o r e
* our o r i g i n a l s t a t e a f t e r R T A S r e t u r n s .
2022-03-08 23:50:36 +10:00
* /
2022-03-08 23:50:34 +10:00
std r1 ,P A C A R 1 ( r13 )
2022-03-08 23:50:36 +10:00
std r6 ,P A C A S A V E D M S R ( r13 )
2022-03-08 23:50:34 +10:00
2022-03-08 23:50:36 +10:00
/* Setup our real return addr */
2022-03-08 23:50:34 +10:00
LOAD_ R E G _ A D D R ( r4 ,r t a s _ r e t u r n _ l o c )
clrldi r4 ,r4 ,2 / * c o n v e r t t o r e a l m o d e a d d r e s s * /
2022-03-08 23:50:36 +10:00
mtlr r4
2022-03-08 23:50:34 +10:00
__enter_rtas :
LOAD_ R E G _ A D D R ( r4 , r t a s )
ld r5 ,R T A S E N T R Y ( r4 ) / * g e t t h e r t a s - > e n t r y v a l u e * /
ld r4 ,R T A S B A S E ( r4 ) / * g e t t h e r t a s - > b a s e v a l u e * /
/ *
* RTAS r u n s i n 3 2 - b i t b i g e n d i a n r e a l m o d e , b u t l e a v e M S R [ R I ] o n a s w e
* may h i t N M I ( S R E S E T o r M C E ) w h i l e i n R T A S . R T A S s h o u l d d i s a b l e R I i n
* its c r i t i c a l r e g i o n s ( a s s p e c i f i e d i n P A P R + s e c t i o n 7 . 2 . 1 ) . M S R [ S ]
* is n o t i m p a c t e d b y R F I _ T O _ K E R N E L ( o n l y u r f i d c a n u n s e t i t ) . S o i f
* MSR[ S ] i s s e t , i t w i l l r e m a i n w h e n e n t e r i n g R T A S .
2022-08-23 21:59:52 +10:00
* If w e ' r e i n H V m o d e , R T A S m u s t a l s o r u n i n H V m o d e , s o e x t r a c t M S R _ H V
* from t h e s a v e d M S R v a l u e a n d i n s e r t i n t o t h e v a l u e R T A S w i l l u s e .
2022-03-08 23:50:34 +10:00
* /
2022-08-23 21:59:52 +10:00
extrdi r0 , r6 , 1 , 6 3 - M S R _ H V _ L G
2022-03-08 23:50:34 +10:00
LOAD_ R E G _ I M M E D I A T E ( r6 , M S R _ M E | M S R _ R I )
2022-08-23 21:59:52 +10:00
insrdi r6 , r0 , 1 , 6 3 - M S R _ H V _ L G
2022-03-08 23:50:34 +10:00
li r0 ,0
mtmsrd r0 ,1 / * d i s a b l e R I b e f o r e u s i n g S R R 0 / 1 * /
mtspr S P R N _ S R R 0 ,r5
mtspr S P R N _ S R R 1 ,r6
RFI_ T O _ K E R N E L
b . / * p r e v e n t s p e c u l a t i v e e x e c u t i o n * /
rtas_return_loc :
FIXUP_ E N D I A N
2022-03-08 23:50:42 +10:00
/* Set SF before anything. */
LOAD_ R E G _ I M M E D I A T E ( r6 , M S R _ K E R N E L & ~ ( M S R _ I R | M S R _ D R ) )
2022-03-08 23:50:36 +10:00
mtmsrd r6
2022-03-08 23:50:34 +10:00
/* relocation is off at this point */
2022-03-08 23:50:40 +10:00
GET_ P A C A ( r13 )
2022-03-08 23:50:34 +10:00
bcl 2 0 ,3 1 ,$ + 4
0 : mflr r3
ld r3 ,( 1 f - 0 b ) ( r3 ) / * g e t & r t a s _ r e s t o r e _ r e g s * /
2022-03-08 23:50:40 +10:00
ld r1 ,P A C A R 1 ( r13 ) / * R e s t o r e o u r S P * /
ld r4 ,P A C A S A V E D M S R ( r13 ) / * R e s t o r e o u r M S R * /
2022-03-08 23:50:34 +10:00
mtspr S P R N _ S R R 0 ,r3
mtspr S P R N _ S R R 1 ,r4
RFI_ T O _ K E R N E L
b . / * p r e v e n t s p e c u l a t i v e e x e c u t i o n * /
2022-03-08 23:50:35 +10:00
_ ASM_ N O K P R O B E _ S Y M B O L ( e n t e r _ r t a s )
2022-03-08 23:50:34 +10:00
_ ASM_ N O K P R O B E _ S Y M B O L ( _ _ e n t e r _ r t a s )
_ ASM_ N O K P R O B E _ S Y M B O L ( r t a s _ r e t u r n _ l o c )
.align 3
1 : .8byte r t a s _ r e s t o r e _ r e g s
rtas_restore_regs :
/* relocation is on at this point */
REST_ G P R ( 2 , r1 ) / * R e s t o r e t h e T O C * /
REST_ N V G P R S ( r1 ) / * R e s t o r e t h e n o n - v o l a t i l e s * /
ld r4 ,_ C C R ( r1 )
mtcr r4
ld r5 ,_ C T R ( r1 )
mtctr r5
ld r6 ,_ X E R ( r1 )
mtspr S P R N _ X E R ,r6
ld r7 ,_ D A R ( r1 )
mtdar r7
ld r8 ,_ D S I S R ( r1 )
mtdsisr r8
2022-03-08 23:50:36 +10:00
addi r1 ,r1 ,S W I T C H _ F R A M E _ S I Z E / * U n s t a c k o u r f r a m e * /
2022-03-08 23:50:34 +10:00
ld r0 ,1 6 ( r1 ) / * g e t r e t u r n a d d r e s s * /
2022-03-08 23:50:36 +10:00
mtlr r0
blr / * r e t u r n t o c a l l e r * /
2022-03-08 23:50:34 +10:00
# endif / * C O N F I G _ P P C 3 2 * /