2019-05-27 08:55:01 +02:00
/* SPDX-License-Identifier: GPL-2.0-or-later */
2005-10-10 22:36:14 +10:00
/ *
* PowerPC v e r s i o n
* Copyright ( C ) 1 9 9 5 - 1 9 9 6 G a r y T h o m a s ( g d t @linuxppc.org)
* Rewritten b y C o r t D o u g a n ( c o r t @fsmlabs.com) for PReP
* Copyright ( C ) 1 9 9 6 C o r t D o u g a n < c o r t @fsmlabs.com>
* Adapted f o r P o w e r M a c i n t o s h b y P a u l M a c k e r r a s .
* Low- l e v e l e x c e p t i o n h a n d l e r s a n d M M U s u p p o r t
* rewritten b y P a u l M a c k e r r a s .
* Copyright ( C ) 1 9 9 6 P a u l M a c k e r r a s .
* MPC8 x x m o d i f i c a t i o n s C o p y r i g h t ( C ) 1 9 9 7 D a n M a l e k ( d m a l e k @jlc.net).
*
* This f i l e c o n t a i n s t h e s y s t e m c a l l e n t r y c o d e , c o n t e x t s w i t c h
* code, a n d e x c e p t i o n / i n t e r r u p t r e t u r n c o d e f o r P o w e r P C .
* /
# include < l i n u x / e r r n o . h >
powerpc/kernel: Switch to using MAX_ERRNO
Currently on powerpc we have our own #define for the highest (negative)
errno value, called _LAST_ERRNO. This is defined to be 516, for reasons
which are not clear.
The generic code, and x86, use MAX_ERRNO, which is defined to be 4095.
In particular seccomp uses MAX_ERRNO to restrict the value that a
seccomp filter can return.
Currently with the mismatch between _LAST_ERRNO and MAX_ERRNO, a seccomp
tracer wanting to return 600, expecting it to be seen as an error, would
instead find on powerpc that userspace sees a successful syscall with a
return value of 600.
To avoid this inconsistency, switch powerpc to use MAX_ERRNO.
We are somewhat confident that generic syscalls that can return a
non-error value above negative MAX_ERRNO have already been updated to
use force_successful_syscall_return().
I have also checked all the powerpc specific syscalls, and believe that
none of them expect to return a non-error value between -MAX_ERRNO and
-516. So this change should be safe ...
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Kees Cook <keescook@chromium.org>
2015-07-23 20:21:01 +10:00
# include < l i n u x / e r r . h >
2005-10-10 22:36:14 +10:00
# include < l i n u x / s y s . h >
# include < l i n u x / t h r e a d s . h >
# include < a s m / r e g . h >
# include < a s m / p a g e . h >
# include < a s m / m m u . h >
# include < a s m / c p u t a b l e . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / p p c _ a s m . h >
# include < a s m / a s m - o f f s e t s . h >
# include < a s m / u n i s t d . h >
2010-11-18 15:06:17 +00:00
# include < a s m / p t r a c e . h >
2016-01-13 23:33:46 -05:00
# include < a s m / e x p o r t . h >
2018-07-05 16:25:01 +00:00
# include < a s m / f e a t u r e - f i x u p s . h >
2018-07-28 09:06:38 +10:00
# include < a s m / b a r r i e r . h >
2019-03-11 08:30:31 +00:00
# include < a s m / k u p . h >
2019-04-30 12:39:01 +00:00
# include < a s m / b u g . h >
2005-10-10 22:36:14 +10:00
2019-04-30 12:38:51 +00:00
# include " h e a d _ 3 2 . h "
2005-10-10 22:36:14 +10:00
2020-07-16 11:35:22 +10:00
/ *
* powerpc r e l i e s o n r e t u r n f r o m i n t e r r u p t / s y s c a l l b e i n g c o n t e x t s y n c h r o n i s i n g
* ( which r f i i s ) t o s u p p o r t A R C H _ H A S _ M E M B A R R I E R _ S Y N C _ C O R E w i t h o u t a d d i t i o n a l
* synchronisation i n s t r u c t i o n s .
* /
2017-07-12 12:08:49 +02:00
/ *
* Align t o 4 k i n o r d e r t o e n s u r e t h a t a l l f u n c t i o n s m o d y f i n g s r r0 / s r r1
* fit i n t o o n e p a g e i n o r d e r t o n o t e n c o u n t e r a T L B m i s s b e t w e e n t h e
* modification o f s r r0 / s r r1 a n d t h e a s s o c i a t e d r f i .
* /
.align 12
2005-10-10 22:36:14 +10:00
# ifdef C O N F I G _ B O O K E
.globl mcheck_transfer_to_handler
mcheck_transfer_to_handler :
2008-04-30 05:23:21 -05:00
/* fall through */
2020-03-31 16:03:45 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( m c h e c k _ t r a n s f e r _ t o _ h a n d l e r )
2005-10-10 22:36:14 +10:00
.globl debug_transfer_to_handler
debug_transfer_to_handler :
2008-04-30 05:23:21 -05:00
/* fall through */
2020-03-31 16:03:45 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( d e b u g _ t r a n s f e r _ t o _ h a n d l e r )
2005-10-10 22:36:14 +10:00
.globl crit_transfer_to_handler
crit_transfer_to_handler :
/* fall through */
2020-03-31 16:03:45 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( c r i t _ t r a n s f e r _ t o _ h a n d l e r )
2005-10-10 22:36:14 +10:00
# endif
# ifdef C O N F I G _ 4 0 x
.globl crit_transfer_to_handler
crit_transfer_to_handler :
/* fall through */
2020-03-31 16:03:45 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( c r i t _ t r a n s f e r _ t o _ h a n d l e r )
2005-10-10 22:36:14 +10:00
# endif
/ *
* This c o d e f i n i s h e s s a v i n g t h e r e g i s t e r s t o t h e e x c e p t i o n f r a m e
* and j u m p s t o t h e a p p r o p r i a t e h a n d l e r f o r t h e e x c e p t i o n , t u r n i n g
* on a d d r e s s t r a n s l a t i o n .
* Note t h a t w e r e l y o n t h e c a l l e r h a v i n g s e t c r0 . e q i f f t h e e x c e p t i o n
* occurred i n k e r n e l m o d e ( i . e . M S R : P R = 0 ) .
* /
.globl transfer_to_handler_full
transfer_to_handler_full :
SAVE_ N V G P R S ( r11 )
2020-03-31 16:03:45 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( t r a n s f e r _ t o _ h a n d l e r _ f u l l )
2005-10-10 22:36:14 +10:00
/* fall through */
.globl transfer_to_handler
transfer_to_handler :
stw r2 ,G P R 2 ( r11 )
stw r12 ,_ N I P ( r11 )
stw r9 ,_ M S R ( r11 )
andi. r2 ,r9 ,M S R _ P R
mfctr r12
mfspr r2 ,S P R N _ X E R
stw r12 ,_ C T R ( r11 )
stw r2 ,_ X E R ( r11 )
2009-07-14 20:52:54 +00:00
mfspr r12 ,S P R N _ S P R G _ T H R E A D
2021-03-12 12:50:22 +00:00
tovirt( r12 , r12 )
2005-10-10 22:36:14 +10:00
beq 2 f / * i f f r o m u s e r , f i x u p T H R E A D . r e g s * /
2019-03-11 08:30:31 +00:00
addi r2 , r12 , - T H R E A D
2005-10-10 22:36:14 +10:00
addi r11 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
stw r11 ,P T _ R E G S ( r12 )
2019-03-11 08:30:35 +00:00
# ifdef C O N F I G _ P P C _ B O O K 3 S _ 3 2
kuep_ l o c k r11 , r12
# endif
2005-10-10 22:36:14 +10:00
b 3 f
2006-04-18 21:49:11 +10:00
2021-03-12 12:50:21 +00:00
/* if from kernel, check interrupted DOZE/NAP mode */
2 :
2020-01-27 10:42:04 +00:00
kuap_ s a v e _ a n d _ l o c k r11 , r12 , r9 , r2 , r6
2019-03-11 08:30:31 +00:00
addi r2 , r12 , - T H R E A D
2018-11-17 10:24:56 +00:00
# if d e f i n e d ( C O N F I G _ P P C _ B O O K 3 S _ 3 2 ) | | d e f i n e d ( C O N F I G _ E 5 0 0 )
2019-01-31 10:09:04 +00:00
lwz r12 ,T I _ L O C A L _ F L A G S ( r2 )
2006-04-18 21:49:11 +10:00
mtcrf 0 x01 ,r12
bt- 3 1 - T L F _ N A P P I N G ,4 f
2008-05-14 14:30:48 +10:00
bt- 3 1 - T L F _ S L E E P I N G ,7 f
2018-11-17 10:24:56 +00:00
# endif / * C O N F I G _ P P C _ B O O K 3 S _ 3 2 | | C O N F I G _ E 5 0 0 * /
2005-10-10 22:36:14 +10:00
.globl transfer_to_handler_cont
transfer_to_handler_cont :
3 :
mflr r9
lwz r11 ,0 ( r9 ) / * v i r t u a l a d d r e s s o f h a n d l e r * /
lwz r9 ,4 ( r9 ) / * w h e r e t o g o w h e n d o n e * /
2021-03-12 12:50:24 +00:00
mtctr r11
2019-04-30 12:39:01 +00:00
mtlr r9
2021-03-12 12:50:24 +00:00
bctr / * j u m p t o h a n d l e r * /
2019-04-30 12:39:01 +00:00
2020-03-31 16:03:45 +00:00
# if d e f i n e d ( C O N F I G _ P P C _ B O O K 3 S _ 3 2 ) | | d e f i n e d ( C O N F I G _ E 5 0 0 )
4 : rlwinm r12 ,r12 ,0 ,~ _ T L F _ N A P P I N G
stw r12 ,T I _ L O C A L _ F L A G S ( r2 )
b p o w e r _ s a v e _ p p c32 _ r e s t o r e
7 : rlwinm r12 ,r12 ,0 ,~ _ T L F _ S L E E P I N G
stw r12 ,T I _ L O C A L _ F L A G S ( r2 )
lwz r9 ,_ M S R ( r11 ) / * i f s l e e p i n g , c l e a r M S R . E E * /
rlwinm r9 ,r9 ,0 ,~ M S R _ E E
lwz r12 ,_ L I N K ( r11 ) / * a n d r e t u r n t o a d d r e s s i n L R * /
kuap_ r e s t o r e r11 , r2 , r3 , r4 , r5
lwz r2 , G P R 2 ( r11 )
b f a s t _ e x c e p t i o n _ r e t u r n
# endif
_ ASM_ N O K P R O B E _ S Y M B O L ( t r a n s f e r _ t o _ h a n d l e r )
_ ASM_ N O K P R O B E _ S Y M B O L ( t r a n s f e r _ t o _ h a n d l e r _ c o n t )
2019-04-30 12:39:02 +00:00
.globl transfer_to_syscall
transfer_to_syscall :
2021-02-08 15:10:32 +00:00
SAVE_ N V G P R S ( r1 )
2021-02-08 15:10:20 +00:00
# ifdef C O N F I G _ P P C _ B O O K 3 S _ 3 2
kuep_ l o c k r11 , r12
# endif
2019-04-30 12:39:02 +00:00
2021-02-08 15:10:33 +00:00
/* Calling convention has r9 = orig r0, r10 = regs */
addi r10 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
mr r9 ,r0
stw r10 ,T H R E A D + P T _ R E G S ( r2 )
bl s y s t e m _ c a l l _ e x c e p t i o n
2018-07-28 09:06:38 +10:00
2005-10-10 22:36:14 +10:00
ret_from_syscall :
2021-02-08 15:10:33 +00:00
addi r4 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
li r5 ,0
bl s y s c a l l _ e x i t _ p r e p a r e
2020-10-18 17:25:18 +00:00
# ifdef C O N F I G _ P P C _ 4 7 x
2007-10-31 16:42:19 +11:00
lis r4 ,i c a c h e _ 4 4 x _ n e e d _ f l u s h @ha
lwz r5 ,i c a c h e _ 4 4 x _ n e e d _ f l u s h @l(r4)
cmplwi c r0 ,r5 ,0
bne- 2 f
2020-10-18 17:25:18 +00:00
# endif / * C O N F I G _ P P C _ 4 7 x * /
2019-03-11 08:30:35 +00:00
# ifdef C O N F I G _ P P C _ B O O K 3 S _ 3 2
kuep_ u n l o c k r5 , r7
# endif
2019-03-11 08:30:31 +00:00
kuap_ c h e c k r2 , r4
2005-10-10 22:36:14 +10:00
lwz r4 ,_ L I N K ( r1 )
lwz r5 ,_ C C R ( r1 )
mtlr r4
lwz r7 ,_ N I P ( r1 )
2021-02-08 15:10:33 +00:00
lwz r8 ,_ M S R ( r1 )
cmpwi r3 ,0
lwz r3 ,G P R 3 ( r1 )
2020-03-31 16:03:46 +00:00
syscall_exit_finish :
2005-10-10 22:36:14 +10:00
mtspr S P R N _ S R R 0 ,r7
mtspr S P R N _ S R R 1 ,r8
2021-02-08 15:10:33 +00:00
bne 3 f
mtcr r5
1 : lwz r2 ,G P R 2 ( r1 )
lwz r1 ,G P R 1 ( r1 )
2020-11-08 16:57:37 +00:00
rfi
# ifdef C O N F I G _ 4 0 x
b . / * P r e v e n t p r e f e t c h p a s t r f i * /
# endif
2021-02-08 15:10:33 +00:00
3 : mtcr r5
lwz r4 ,_ C T R ( r1 )
lwz r5 ,_ X E R ( r1 )
REST_ N V G P R S ( r1 )
mtctr r4
mtxer r5
lwz r0 ,G P R 0 ( r1 )
lwz r3 ,G P R 3 ( r1 )
REST_ 8 G P R S ( 4 ,r1 )
lwz r12 ,G P R 1 2 ( r1 )
b 1 b
2007-10-31 16:42:19 +11:00
# ifdef C O N F I G _ 4 4 x
2 : li r7 ,0
iccci r0 ,r0
stw r7 ,i c a c h e _ 4 4 x _ n e e d _ f l u s h @l(r4)
b 1 b
# endif / * C O N F I G _ 4 4 x * /
2005-10-10 22:36:14 +10:00
.globl ret_from_fork
ret_from_fork :
REST_ N V G P R S ( r1 )
bl s c h e d u l e _ t a i l
li r3 ,0
b r e t _ f r o m _ s y s c a l l
2012-09-12 18:32:42 -04:00
.globl ret_from_kernel_thread
ret_from_kernel_thread :
REST_ N V G P R S ( r1 )
bl s c h e d u l e _ t a i l
mtlr r14
mr r3 ,r15
PPC4 4 0 E P _ E R R 4 2
blrl
li r3 ,0
2012-08-31 15:48:05 -04:00
b r e t _ f r o m _ s y s c a l l
2005-10-10 22:36:14 +10:00
/ *
* Top- l e v e l p a g e f a u l t h a n d l i n g .
* This i s i n a s s e m b l e r b e c a u s e i f d o _ p a g e _ f a u l t t e l l s u s t h a t
* it i s a b a d k e r n e l p a g e f a u l t , w e w a n t t o s a v e t h e n o n - v o l a t i l e
* registers b e f o r e c a l l i n g b a d _ p a g e _ f a u l t .
* /
.globl handle_page_fault
handle_page_fault :
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2017-08-08 08:37:24 +02:00
bl d o _ p a g e _ f a u l t
2005-10-10 22:36:14 +10:00
cmpwi r3 ,0
beq+ r e t _ f r o m _ e x c e p t
SAVE_ N V G P R S ( r1 )
2005-10-28 22:45:25 +10:00
lwz r0 ,_ T R A P ( r1 )
2005-10-10 22:36:14 +10:00
clrrwi r0 ,r0 ,1
2005-10-28 22:45:25 +10:00
stw r0 ,_ T R A P ( r1 )
2021-01-30 23:08:21 +10:00
mr r4 ,r3 / * e r r a r g f o r b a d _ p a g e _ f a u l t * /
2005-10-10 22:36:14 +10:00
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2020-12-09 05:29:25 +00:00
bl _ _ b a d _ p a g e _ f a u l t
2005-10-10 22:36:14 +10:00
b r e t _ f r o m _ e x c e p t _ f u l l
/ *
* This r o u t i n e s w i t c h e s b e t w e e n t w o d i f f e r e n t t a s k s . T h e p r o c e s s
* state o f o n e i s s a v e d o n i t s k e r n e l s t a c k . T h e n t h e s t a t e
* of t h e o t h e r i s r e s t o r e d f r o m i t s k e r n e l s t a c k . T h e m e m o r y
* management h a r d w a r e i s u p d a t e d t o t h e s e c o n d p r o c e s s ' s s t a t e .
* Finally, w e c a n r e t u r n t o t h e s e c o n d p r o c e s s .
* On e n t r y , r3 p o i n t s t o t h e T H R E A D f o r t h e c u r r e n t t a s k , r4
* points t o t h e T H R E A D f o r t h e n e w t a s k .
*
* This r o u t i n e i s a l w a y s c a l l e d w i t h i n t e r r u p t s d i s a b l e d .
*
* Note : there a r e t w o w a y s t o g e t t o t h e " g o i n g o u t " p o r t i o n
* of t h i s c o d e ; either by coming in via the entry (_switch)
* or v i a " f o r k " w h i c h m u s t s e t u p a n e n v i r o n m e n t e q u i v a l e n t
* to t h e " _ s w i t c h " p a t h . I f y o u c h a n g e t h i s , y o u ' l l h a v e t o
* change t h e f o r k c o d e a l s o .
*
* The c o d e w h i c h c r e a t e s t h e n e w t a s k c o n t e x t i s i n ' c o p y _ t h r e a d '
* in a r c h / p p c / k e r n e l / p r o c e s s . c
* /
_ GLOBAL( _ s w i t c h )
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 )
/* r3-r12 are caller saved -- Cort */
SAVE_ N V G P R S ( r1 )
stw r0 ,_ N I P ( r1 ) / * R e t u r n t o s w i t c h c a l l e r * /
mfmsr r11
li r0 ,M S R _ F P / * D i s a b l e f l o a t i n g - p o i n t * /
# ifdef C O N F I G _ A L T I V E C
BEGIN_ F T R _ S E C T I O N
oris r0 ,r0 ,M S R _ V E C @h /* Disable altivec */
mfspr r12 ,S P R N _ V R S A V E / * s a v e v r s a v e r e g i s t e r v a l u e * /
stw r12 ,T H R E A D + T H R E A D _ V R S A V E ( r2 )
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ A L T I V E C )
# endif / * C O N F I G _ A L T I V E C * /
# ifdef C O N F I G _ S P E
2007-09-13 01:44:20 -05:00
BEGIN_ F T R _ S E C T I O N
2005-10-10 22:36:14 +10:00
oris r0 ,r0 ,M S R _ S P E @h /* Disable SPE */
mfspr r12 ,S P R N _ S P E F S C R / * s a v e s p e f s c r r e g i s t e r v a l u e * /
stw r12 ,T H R E A D + T H R E A D _ S P E F S C R ( r2 )
2007-09-13 01:44:20 -05:00
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ S P E )
2005-10-10 22:36:14 +10:00
# endif / * C O N F I G _ S P E * /
and. r0 ,r0 ,r11 / * F P o r a l t i v e c o r S P E e n a b l e d ? * /
beq+ 1 f
andc r11 ,r11 ,r0
2019-12-21 08:32:22 +00:00
mtmsr r11
2005-10-10 22:36:14 +10:00
isync
1 : stw r11 ,_ M S R ( r1 )
mfcr r10
stw r10 ,_ C C R ( r1 )
stw r1 ,K S P ( r3 ) / * S e t o l d s t a c k p o i n t e r * /
2020-04-17 11:58:36 +00:00
kuap_ c h e c k r2 , r0
2005-10-10 22:36:14 +10:00
# ifdef C O N F I G _ S M P
/ * We n e e d a s y n c s o m e w h e r e h e r e t o m a k e s u r e t h a t i f t h e
* previous t a s k g e t s r e s c h e d u l e d o n a n o t h e r C P U , i t s e e s a l l
* stores i t h a s p e r f o r m e d o n t h i s o n e .
* /
sync
# endif / * C O N F I G _ S M P * /
tophys( r0 ,r4 )
2009-07-14 20:52:54 +00:00
mtspr S P R N _ S P R G _ T H R E A D ,r0 / * U p d a t e c u r r e n t T H R E A D p h y s a d d r * /
2005-10-10 22:36:14 +10:00
lwz r1 ,K S P ( r4 ) / * L o a d n e w s t a c k p o i n t e r * /
/* save the old current 'last' for return value */
mr r3 ,r2
addi r2 ,r4 ,- T H R E A D / * U p d a t e c u r r e n t * /
# ifdef C O N F I G _ A L T I V E C
BEGIN_ F T R _ S E C T I O N
lwz r0 ,T H R E A D + T H R E A D _ V R S A V E ( r2 )
mtspr S P R N _ V R S A V E ,r0 / * i f G 4 , r e s t o r e V R S A V E r e g * /
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ A L T I V E C )
# endif / * C O N F I G _ A L T I V E C * /
# ifdef C O N F I G _ S P E
2007-09-13 01:44:20 -05:00
BEGIN_ F T R _ S E C T I O N
2005-10-10 22:36:14 +10:00
lwz r0 ,T H R E A D + T H R E A D _ S P E F S C R ( r2 )
mtspr S P R N _ S P E F S C R ,r0 / * r e s t o r e S P E F S C R r e g * /
2007-09-13 01:44:20 -05:00
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ S P E )
2005-10-10 22:36:14 +10:00
# endif / * C O N F I G _ S P E * /
2017-01-24 21:37:20 +11:00
2005-10-10 22:36:14 +10:00
lwz r0 ,_ C C R ( r1 )
mtcrf 0 x F F ,r0
/* r3-r12 are destroyed -- Cort */
REST_ N V G P R S ( r1 )
lwz r4 ,_ N I P ( r1 ) / * R e t u r n t o _ s w i t c h c a l l e r i n n e w t a s k * /
mtlr r4
addi r1 ,r1 ,I N T _ F R A M E _ S I Z E
blr
.globl fast_exception_return
fast_exception_return :
# if ! ( d e f i n e d ( C O N F I G _ 4 x x ) | | d e f i n e d ( C O N F I G _ B O O K E ) )
andi. r10 ,r9 ,M S R _ R I / * c h e c k f o r r e c o v e r a b l e i n t e r r u p t * /
beq 1 f / * i f n o t , w e ' v e g o t p r o b l e m s * /
# endif
2 : REST_ 4 G P R S ( 3 , r11 )
lwz r10 ,_ C C R ( r11 )
REST_ G P R ( 1 , r11 )
mtcr r10
lwz r10 ,_ L I N K ( r11 )
mtlr r10
2019-02-27 11:45:30 +00:00
/* Clear the exception_marker on the stack to avoid confusing stacktrace */
li r10 , 0
stw r10 , 8 ( r11 )
2005-10-10 22:36:14 +10:00
REST_ G P R ( 1 0 , r11 )
2018-01-12 13:45:23 +01:00
# if d e f i n e d ( C O N F I G _ P P C _ 8 x x ) & & d e f i n e d ( C O N F I G _ P E R F _ E V E N T S )
powerpc/8xx: Perf events on PPC 8xx
This patch has been reworked since RFC version. In the RFC, this patch
was preceded by a patch clearing MSR RI for all PPC32 at all time at
exception prologs. Now MSR RI clearing is done only when this 8xx perf
events functionality is compiled in, it is therefore limited to 8xx
and merged inside this patch.
Other main changes have been to take into account detailed review from
Peter Zijlstra. The instructions counter has been reworked to behave
as a free running counter like the three other counters.
The 8xx has no PMU, however some events can be emulated by other means.
This patch implements the following events (as reported by 'perf list'):
cpu-cycles OR cycles [Hardware event]
instructions [Hardware event]
dTLB-load-misses [Hardware cache event]
iTLB-load-misses [Hardware cache event]
'cycles' event is implemented using the timebase clock. Timebase clock
corresponds to CPU clock divided by 16, so number of cycles is
approximatly 16 times the number of TB ticks
On the 8xx, TLB misses are handled by software. It is therefore
easy to count all TLB misses each time the TLB miss exception is
called.
'instructions' is calculated by using instruction watchpoint counter.
This patch sets counter A to count instructions at address greater
than 0, hence we count all instructions executed while MSR RI bit is
set. The counter is set to the maximum which is 0xffff. Every 65535
instructions, debug instruction breakpoint exception fires. The
exception handler increments a counter in memory which then
represent the upper part of the instruction counter. We therefore
end up with a 48 bits counter. In order to avoid unnecessary overhead
while no perf event is active, this counter is started when the first
event referring to this counter is added, and the counter is stopped
when the last event referring to it is deleted. In order to properly
support breakpoint exceptions, MSR RI bit has to be unset in exception
epilogs in order to avoid breakpoint exceptions during critical
sections during changes to SRR0 and SRR1 would be problematic.
All counters are handled as free running counters.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <oss@buserror.net>
2016-12-15 13:42:18 +01:00
mtspr S P R N _ N R I , r0
# endif
2005-10-10 22:36:14 +10:00
mtspr S P R N _ S R R 1 ,r9
mtspr S P R N _ S R R 0 ,r12
REST_ G P R ( 9 , r11 )
REST_ G P R ( 1 2 , r11 )
lwz r11 ,G P R 1 1 ( r11 )
2020-11-08 16:57:37 +00:00
rfi
# ifdef C O N F I G _ 4 0 x
b . / * P r e v e n t p r e f e t c h p a s t r f i * /
# endif
2020-03-31 16:03:47 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( f a s t _ e x c e p t i o n _ r e t u r n )
2005-10-10 22:36:14 +10:00
# if ! ( d e f i n e d ( C O N F I G _ 4 x x ) | | d e f i n e d ( C O N F I G _ B O O K E ) )
/* check if the exception happened in a restartable section */
1 : lis r3 ,e x c _ e x i t _ r e s t a r t _ e n d @ha
addi r3 ,r3 ,e x c _ e x i t _ r e s t a r t _ e n d @l
cmplw r12 ,r3
bge 3 f
lis r4 ,e x c _ e x i t _ r e s t a r t @ha
addi r4 ,r4 ,e x c _ e x i t _ r e s t a r t @l
cmplw r12 ,r4
blt 3 f
lis r3 ,f e e _ r e s t a r t s @ha
tophys( r3 ,r3 )
lwz r5 ,f e e _ r e s t a r t s @l(r3)
addi r5 ,r5 ,1
stw r5 ,f e e _ r e s t a r t s @l(r3)
mr r12 ,r4 / * r e s t a r t a t e x c _ e x i t _ r e s t a r t * /
b 2 b
2007-05-14 17:11:58 -05:00
.section .bss
.align 2
fee_restarts :
.space 4
.previous
2005-10-10 22:36:14 +10:00
/* aargh, a nonrecoverable interrupt, panic */
/* aargh, we don't know which trap this is */
3 :
li r10 ,- 1
2005-10-28 22:45:25 +10:00
stw r10 ,_ T R A P ( r11 )
2005-10-10 22:36:14 +10:00
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl t r a n s f e r _ t o _ h a n d l e r _ f u l l
2018-09-25 14:10:04 +00:00
.long unrecoverable_exception
2005-10-10 22:36:14 +10:00
.long ret_from_except
# endif
.globl ret_from_except_full
ret_from_except_full :
REST_ N V G P R S ( r1 )
/* fall through */
.globl ret_from_except
ret_from_except :
/ * Hard- d i s a b l e i n t e r r u p t s s o t h a t c u r r e n t _ t h r e a d _ i n f o ( ) - > f l a g s
* can' t c h a n g e b e t w e e n w h e n w e t e s t i t a n d w h e n w e r e t u r n
* from t h e i n t e r r u p t . * /
2009-06-17 17:43:59 +00:00
/* Note: We don't bother telling lockdep about it */
2019-08-20 14:34:13 +00:00
LOAD_ R E G _ I M M E D I A T E ( r10 ,M S R _ K E R N E L )
2019-12-21 08:32:22 +00:00
mtmsr r10 / * d i s a b l e i n t e r r u p t s * /
2005-10-10 22:36:14 +10:00
lwz r3 ,_ M S R ( r1 ) / * R e t u r n i n g t o u s e r m o d e ? * /
andi. r0 ,r3 ,M S R _ P R
beq r e s u m e _ k e r n e l
user_exc_return : /* r10 contains MSR_KERNEL here */
/* Check current_thread_info()->flags */
2019-01-31 10:09:04 +00:00
lwz r9 ,T I _ F L A G S ( r2 )
2008-04-28 17:30:37 +10:00
andi. r0 ,r9 ,_ T I F _ U S E R _ W O R K _ M A S K
2005-10-10 22:36:14 +10:00
bne d o _ w o r k
restore_user :
# if d e f i n e d ( C O N F I G _ 4 x x ) | | d e f i n e d ( C O N F I G _ B O O K E )
2008-04-09 16:15:40 -05:00
/ * Check w h e t h e r t h i s p r o c e s s h a s i t s o w n D B C R 0 v a l u e . T h e i n t e r n a l
debug m o d e b i t t e l l s u s t h a t d b c r0 s h o u l d b e l o a d e d . * /
2005-10-10 22:36:14 +10:00
lwz r0 ,T H R E A D + T H R E A D _ D B C R 0 ( r2 )
2008-07-26 05:27:33 +10:00
andis. r10 ,r0 ,D B C R 0 _ I D M @h
2005-10-10 22:36:14 +10:00
bnel- l o a d _ d b c r0
# endif
2019-01-31 10:09:04 +00:00
ACCOUNT_ C P U _ U S E R _ E X I T ( r2 , r10 , r11 )
2019-03-11 08:30:35 +00:00
# ifdef C O N F I G _ P P C _ B O O K 3 S _ 3 2
kuep_ u n l o c k r10 , r11
# endif
2005-10-10 22:36:14 +10:00
b r e s t o r e
/* N.B. the only way to get here is from the beq following ret_from_except. */
resume_kernel :
2012-09-16 23:54:30 +00:00
/* check current_thread_info, _TIF_EMULATE_STACK_STORE */
2019-01-31 10:09:04 +00:00
lwz r8 ,T I _ F L A G S ( r2 )
2013-05-31 01:20:02 +00:00
andis. r0 ,r8 ,_ T I F _ E M U L A T E _ S T A C K _ S T O R E @h
2012-09-16 23:54:30 +00:00
beq+ 1 f
addi r8 ,r1 ,I N T _ F R A M E _ S I Z E / * G e t t h e k p r o b e d f u n c t i o n e n t r y * /
lwz r3 ,G P R 1 ( r1 )
subi r3 ,r3 ,I N T _ F R A M E _ S I Z E / * d s t : A l l o c a t e a t r a m p o l i n e e x c e p t i o n f r a m e * /
mr r4 ,r1 / * s r c : c u r r e n t e x c e p t i o n f r a m e * /
mr r1 ,r3 / * R e r o u t e t h e t r a m p o l i n e f r a m e t o r1 * /
/* Copy from the original to the trampoline. */
li r5 ,I N T _ F R A M E _ S I Z E / 4 / * s i z e : I N T _ F R A M E _ S I Z E * /
li r6 ,0 / * s t a r t o f f s e t : 0 * /
mtctr r5
2 : lwzx r0 ,r6 ,r4
stwx r0 ,r6 ,r3
addi r6 ,r6 ,4
bdnz 2 b
/* Do real store operation to complete stwu */
lwz r5 ,G P R 1 ( r1 )
stw r8 ,0 ( r5 )
/* Clear _TIF_EMULATE_STACK_STORE flag */
lis r11 ,_ T I F _ E M U L A T E _ S T A C K _ S T O R E @h
2019-01-31 10:09:04 +00:00
addi r5 ,r2 ,T I _ F L A G S
2012-09-16 23:54:30 +00:00
0 : lwarx r8 ,0 ,r5
andc r8 ,r8 ,r11
stwcx. r8 ,0 ,r5
bne- 0 b
1 :
2019-10-24 18:04:58 +02:00
# ifdef C O N F I G _ P R E E M P T I O N
2012-09-16 23:54:30 +00:00
/* check current_thread_info->preempt_count */
2019-01-31 10:09:04 +00:00
lwz r0 ,T I _ P R E E M P T ( r2 )
2005-10-10 22:36:14 +10:00
cmpwi 0 ,r0 ,0 / * i f n o n - z e r o , j u s t r e s t o r e r e g s a n d r e t u r n * /
2019-03-11 08:30:31 +00:00
bne r e s t o r e _ k u a p
2012-09-16 23:54:30 +00:00
andi. r8 ,r8 ,_ T I F _ N E E D _ R E S C H E D
2019-03-11 08:30:31 +00:00
beq+ r e s t o r e _ k u a p
2012-09-16 23:54:30 +00:00
lwz r3 ,_ M S R ( r1 )
2005-10-10 22:36:14 +10:00
andi. r0 ,r3 ,M S R _ E E / * i n t e r r u p t s o f f ? * /
2019-03-11 08:30:31 +00:00
beq r e s t o r e _ k u a p / * d o n ' t s c h e d u l e i f s o * /
2009-06-17 17:43:59 +00:00
# ifdef C O N F I G _ T R A C E _ I R Q F L A G S
/ * Lockdep t h i n k s i r q s a r e e n a b l e d , w e n e e d t o c a l l
* preempt_ s c h e d u l e _ i r q w i t h I R Q s o f f , s o w e i n f o r m l o c k d e p
* now t h a t w e - d i d - t u r n t h e m o f f a l r e a d y
* /
bl t r a c e _ h a r d i r q s _ o f f
# endif
2019-03-11 22:47:46 +00:00
bl p r e e m p t _ s c h e d u l e _ i r q
2009-06-17 17:43:59 +00:00
# ifdef C O N F I G _ T R A C E _ I R Q F L A G S
/ * And n o w , t o p r o p e r l y r e b a l a n c e t h e a b o v e , w e t e l l l o c k d e p t h e y
* are b e i n g t u r n e d b a c k o n , w h i c h w i l l h a p p e n w h e n w e r e t u r n
* /
bl t r a c e _ h a r d i r q s _ o n
# endif
2019-10-24 18:04:58 +02:00
# endif / * C O N F I G _ P R E E M P T I O N * /
2019-03-11 08:30:31 +00:00
restore_kuap :
kuap_ r e s t o r e r1 , r2 , r9 , r10 , r0
2005-10-10 22:36:14 +10:00
/* interrupts are hard-disabled at this point */
restore :
2020-10-18 17:25:18 +00:00
# if d e f i n e d ( C O N F I G _ 4 4 x ) & & ! d e f i n e d ( C O N F I G _ P P C _ 4 7 x )
2007-10-31 16:42:19 +11:00
lis r4 ,i c a c h e _ 4 4 x _ n e e d _ f l u s h @ha
lwz r5 ,i c a c h e _ 4 4 x _ n e e d _ f l u s h @l(r4)
cmplwi c r0 ,r5 ,0
beq+ 1 f
li r6 ,0
iccci r0 ,r0
stw r6 ,i c a c h e _ 4 4 x _ n e e d _ f l u s h @l(r4)
1 :
# endif / * C O N F I G _ 4 4 x * /
2009-06-17 17:43:59 +00:00
lwz r9 ,_ M S R ( r1 )
# ifdef C O N F I G _ T R A C E _ I R Q F L A G S
/ * Lockdep d o e s n ' t k n o w a b o u t t h e f a c t t h a t I R Q s a r e t e m p o r a r i l y t u r n e d
* off i n t h i s a s s e m b l y c o d e w h i l e p e e k i n g a t T I _ F L A G S ( ) a n d s u c h . H o w e v e r
* we n e e d t o i n f o r m i t i f t h e e x c e p t i o n t u r n e d i n t e r r u p t s o f f , a n d w e
* are a b o u t t o t r u n t h e m b a c k o n .
* /
andi. r10 ,r9 ,M S R _ E E
beq 1 f
2010-12-22 16:42:56 +00:00
stwu r1 ,- 3 2 ( r1 )
mflr r0
stw r0 ,4 ( r1 )
2009-06-17 17:43:59 +00:00
bl t r a c e _ h a r d i r q s _ o n
2019-04-30 12:39:05 +00:00
addi r1 , r1 , 3 2
2009-06-17 17:43:59 +00:00
lwz r9 ,_ M S R ( r1 )
1 :
# endif / * C O N F I G _ T R A C E _ I R Q F L A G S * /
2005-10-10 22:36:14 +10:00
lwz r0 ,G P R 0 ( r1 )
lwz r2 ,G P R 2 ( r1 )
REST_ 4 G P R S ( 3 , r1 )
REST_ 2 G P R S ( 7 , r1 )
lwz r10 ,_ X E R ( r1 )
lwz r11 ,_ C T R ( r1 )
mtspr S P R N _ X E R ,r10
mtctr r11
2007-11-10 09:17:49 +11:00
BEGIN_ F T R _ S E C T I O N
lwarx r11 ,0 ,r1
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ N E E D _ P A I R E D _ S T W C X )
2005-10-10 22:36:14 +10:00
stwcx. r0 ,0 ,r1 / * t o c l e a r t h e r e s e r v a t i o n * /
# if ! ( d e f i n e d ( C O N F I G _ 4 x x ) | | d e f i n e d ( C O N F I G _ B O O K E ) )
andi. r10 ,r9 ,M S R _ R I / * c h e c k i f t h i s e x c e p t i o n o c c u r r e d * /
beql n o n r e c o v e r a b l e / * a t a b a d p l a c e ( M S R : R I = 0 ) * /
lwz r10 ,_ C C R ( r1 )
lwz r11 ,_ L I N K ( r1 )
mtcrf 0 x F F ,r10
mtlr r11
2019-02-27 11:45:30 +00:00
/* Clear the exception_marker on the stack to avoid confusing stacktrace */
li r10 , 0
stw r10 , 8 ( r1 )
2005-10-10 22:36:14 +10:00
/ *
* Once w e p u t v a l u e s i n S R R 0 a n d S R R 1 , w e a r e i n a s t a t e
* where e x c e p t i o n s a r e n o t r e c o v e r a b l e , s i n c e t a k i n g a n
* exception w i l l t r a s h S R R 0 a n d S R R 1 . T h e r e f o r e w e c l e a r t h e
* MSR : RI b i t t o i n d i c a t e t h i s . I f w e d o t a k e a n e x c e p t i o n ,
* we c a n ' t r e t u r n t o t h e p o i n t o f t h e e x c e p t i o n b u t w e
* can r e s t a r t t h e e x c e p t i o n e x i t p a t h a t t h e l a b e l
* exc_ e x i t _ r e s t a r t b e l o w . - - p a u l u s
* /
2019-08-20 14:34:13 +00:00
LOAD_ R E G _ I M M E D I A T E ( r10 ,M S R _ K E R N E L & ~ M S R _ R I )
2019-12-21 08:32:22 +00:00
mtmsr r10 / * c l e a r t h e R I b i t * /
2005-10-10 22:36:14 +10:00
.globl exc_exit_restart
exc_exit_restart :
lwz r12 ,_ N I P ( r1 )
mtspr S P R N _ S R R 0 ,r12
mtspr S P R N _ S R R 1 ,r9
REST_ 4 G P R S ( 9 , r1 )
lwz r1 ,G P R 1 ( r1 )
.globl exc_exit_restart_end
exc_exit_restart_end :
2020-11-08 16:57:36 +00:00
rfi
2020-03-31 16:03:47 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( e x c _ e x i t _ r e s t a r t )
_ ASM_ N O K P R O B E _ S Y M B O L ( e x c _ e x i t _ r e s t a r t _ e n d )
2005-10-10 22:36:14 +10:00
# else / * ! ( C O N F I G _ 4 x x | | C O N F I G _ B O O K E ) * /
/ *
* This i s a b i t d i f f e r e n t o n 4 x x / B o o k - E b e c a u s e i t d o e s n ' t h a v e
* the R I b i t i n t h e M S R .
* The T L B m i s s h a n d l e r c h e c k s i f w e h a v e i n t e r r u p t e d
* the e x c e p t i o n e x i t p a t h a n d r e s t a r t s i t i f s o
* ( well m a y b e o n e d a y i t w i l l . . . : ) .
* /
lwz r11 ,_ L I N K ( r1 )
mtlr r11
lwz r10 ,_ C C R ( r1 )
mtcrf 0 x f f ,r10
2019-02-27 11:45:30 +00:00
/* Clear the exception_marker on the stack to avoid confusing stacktrace */
li r10 , 0
stw r10 , 8 ( r1 )
2005-10-10 22:36:14 +10:00
REST_ 2 G P R S ( 9 , r1 )
.globl exc_exit_restart
exc_exit_restart :
lwz r11 ,_ N I P ( r1 )
lwz r12 ,_ M S R ( r1 )
mtspr S P R N _ S R R 0 ,r11
mtspr S P R N _ S R R 1 ,r12
REST_ 2 G P R S ( 1 1 , r1 )
lwz r1 ,G P R 1 ( r1 )
.globl exc_exit_restart_end
exc_exit_restart_end :
rfi
b . / * p r e v e n t p r e f e t c h p a s t r f i * /
2020-03-31 16:03:47 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( e x c _ e x i t _ r e s t a r t )
2005-10-10 22:36:14 +10:00
/ *
* Returning f r o m a c r i t i c a l i n t e r r u p t i n u s e r m o d e d o e s n ' t n e e d
* to b e a n y d i f f e r e n t f r o m a n o r m a l e x c e p t i o n . F o r a c r i t i c a l
* interrupt i n t h e k e r n e l , w e j u s t r e t u r n ( w i t h o u t c h e c k i n g f o r
* preemption) s i n c e t h e i n t e r r u p t m a y h a v e h a p p e n e d a t s o m e c r u c i a l
* place ( e . g . i n s i d e t h e T L B m i s s h a n d l e r ) , a n d b e c a u s e w e w i l l b e
* running w i t h r1 p o i n t i n g i n t o c r i t i c a l _ s t a c k , n o t t h e c u r r e n t
* process' s k e r n e l s t a c k ( a n d t h e r e f o r e c u r r e n t _ t h r e a d _ i n f o ( ) w i l l
* give t h e w r o n g a n s w e r ) .
* We h a v e t o r e s t o r e v a r i o u s S P R s t h a t m a y h a v e b e e n i n u s e a t t h e
* time o f t h e c r i t i c a l i n t e r r u p t .
*
* /
# ifdef C O N F I G _ 4 0 x
# define P P C _ 4 0 x _ T U R N _ O F F _ M S R _ D R \
/ * avoid a n y p o s s i b l e T L B m i s s e s h e r e b y t u r n i n g o f f M S R . D R , w e \
* assume t h e i n s t r u c t i o n s h e r e a r e m a p p e d b y a p i n n e d T L B e n t r y * / \
li r10 ,M S R _ I R ; \
mtmsr r10 ; \
isync; \
tophys( r1 , r1 ) ;
# else
# define P P C _ 4 0 x _ T U R N _ O F F _ M S R _ D R
# endif
# define R E T _ F R O M _ E X C _ L E V E L ( e x c _ l v l _ s r r0 , e x c _ l v l _ s r r1 , e x c _ l v l _ r f i ) \
REST_ N V G P R S ( r1 ) ; \
lwz r3 ,_ M S R ( r1 ) ; \
andi. r3 ,r3 ,M S R _ P R ; \
2019-08-20 14:34:13 +00:00
LOAD_ R E G _ I M M E D I A T E ( r10 ,M S R _ K E R N E L ) ; \
2005-10-10 22:36:14 +10:00
bne u s e r _ e x c _ r e t u r n ; \
lwz r0 ,G P R 0 ( r1 ) ; \
lwz r2 ,G P R 2 ( r1 ) ; \
REST_ 4 G P R S ( 3 , r1 ) ; \
REST_ 2 G P R S ( 7 , r1 ) ; \
lwz r10 ,_ X E R ( r1 ) ; \
lwz r11 ,_ C T R ( r1 ) ; \
mtspr S P R N _ X E R ,r10 ; \
mtctr r11 ; \
stwcx. r0 ,0 ,r1 ; /* to clear the reservation */ \
lwz r11 ,_ L I N K ( r1 ) ; \
mtlr r11 ; \
lwz r10 ,_ C C R ( r1 ) ; \
mtcrf 0 x f f ,r10 ; \
PPC_ 4 0 x _ T U R N _ O F F _ M S R _ D R ; \
lwz r9 ,_ D E A R ( r1 ) ; \
lwz r10 ,_ E S R ( r1 ) ; \
mtspr S P R N _ D E A R ,r9 ; \
mtspr S P R N _ E S R ,r10 ; \
lwz r11 ,_ N I P ( r1 ) ; \
lwz r12 ,_ M S R ( r1 ) ; \
mtspr e x c _ l v l _ s r r0 ,r11 ; \
mtspr e x c _ l v l _ s r r1 ,r12 ; \
lwz r9 ,G P R 9 ( r1 ) ; \
lwz r12 ,G P R 1 2 ( r1 ) ; \
lwz r10 ,G P R 1 0 ( r1 ) ; \
lwz r11 ,G P R 1 1 ( r1 ) ; \
lwz r1 ,G P R 1 ( r1 ) ; \
exc_ l v l _ r f i ; \
b . ; /* prevent prefetch past exc_lvl_rfi */
2008-04-30 05:23:21 -05:00
# define R E S T O R E _ x S R R ( e x c _ l v l _ s r r0 , e x c _ l v l _ s r r1 ) \
lwz r9 ,_ ## e x c _ l v l _ s r r 0 ( r1 ) ; \
lwz r10 ,_ ## e x c _ l v l _ s r r 1 ( r1 ) ; \
mtspr S P R N _ ## e x c _ l v l _ s r r 0 ,r9 ; \
mtspr S P R N _ ## e x c _ l v l _ s r r 1 ,r10 ;
2009-02-12 16:12:40 -06:00
# if d e f i n e d ( C O N F I G _ P P C _ B O O K 3 E _ M M U )
2008-04-30 05:23:21 -05:00
# ifdef C O N F I G _ P H Y S _ 6 4 B I T
# define R E S T O R E _ M A S 7 \
lwz r11 ,M A S 7 ( r1 ) ; \
mtspr S P R N _ M A S 7 ,r11 ;
# else
# define R E S T O R E _ M A S 7
# endif / * C O N F I G _ P H Y S _ 6 4 B I T * /
# define R E S T O R E _ M M U _ R E G S \
lwz r9 ,M A S 0 ( r1 ) ; \
lwz r10 ,M A S 1 ( r1 ) ; \
lwz r11 ,M A S 2 ( r1 ) ; \
mtspr S P R N _ M A S 0 ,r9 ; \
lwz r9 ,M A S 3 ( r1 ) ; \
mtspr S P R N _ M A S 1 ,r10 ; \
lwz r10 ,M A S 6 ( r1 ) ; \
mtspr S P R N _ M A S 2 ,r11 ; \
mtspr S P R N _ M A S 3 ,r9 ; \
mtspr S P R N _ M A S 6 ,r10 ; \
RESTORE_ M A S 7 ;
# elif d e f i n e d ( C O N F I G _ 4 4 x )
# define R E S T O R E _ M M U _ R E G S \
lwz r9 ,M M U C R ( r1 ) ; \
mtspr S P R N _ M M U C R ,r9 ;
# else
# define R E S T O R E _ M M U _ R E G S
# endif
# ifdef C O N F I G _ 4 0 x
2005-10-10 22:36:14 +10:00
.globl ret_from_crit_exc
ret_from_crit_exc :
2008-04-30 05:23:21 -05:00
lis r9 ,c r i t _ s r r0 @ha;
lwz r9 ,c r i t _ s r r0 @l(r9);
lis r10 ,c r i t _ s r r1 @ha;
lwz r10 ,c r i t _ s r r1 @l(r10);
mtspr S P R N _ S R R 0 ,r9 ;
mtspr S P R N _ S R R 1 ,r10 ;
2009-02-10 20:10:44 +00:00
RET_ F R O M _ E X C _ L E V E L ( S P R N _ C S R R 0 , S P R N _ C S R R 1 , P P C _ R F C I )
2020-03-31 16:03:47 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( r e t _ f r o m _ c r i t _ e x c )
2008-04-30 05:23:21 -05:00
# endif / * C O N F I G _ 4 0 x * /
2005-10-10 22:36:14 +10:00
# ifdef C O N F I G _ B O O K E
2008-04-30 05:23:21 -05:00
.globl ret_from_crit_exc
ret_from_crit_exc :
RESTORE_ x S R R ( S R R 0 ,S R R 1 ) ;
RESTORE_ M M U _ R E G S ;
2009-02-10 20:10:44 +00:00
RET_ F R O M _ E X C _ L E V E L ( S P R N _ C S R R 0 , S P R N _ C S R R 1 , P P C _ R F C I )
2020-03-31 16:03:47 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( r e t _ f r o m _ c r i t _ e x c )
2008-04-30 05:23:21 -05:00
2005-10-10 22:36:14 +10:00
.globl ret_from_debug_exc
ret_from_debug_exc :
2008-04-30 05:23:21 -05:00
RESTORE_ x S R R ( S R R 0 ,S R R 1 ) ;
RESTORE_ x S R R ( C S R R 0 ,C S R R 1 ) ;
RESTORE_ M M U _ R E G S ;
2009-02-10 20:10:44 +00:00
RET_ F R O M _ E X C _ L E V E L ( S P R N _ D S R R 0 , S P R N _ D S R R 1 , P P C _ R F D I )
2020-03-31 16:03:47 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( r e t _ f r o m _ d e b u g _ e x c )
2005-10-10 22:36:14 +10:00
.globl ret_from_mcheck_exc
ret_from_mcheck_exc :
2008-04-30 05:23:21 -05:00
RESTORE_ x S R R ( S R R 0 ,S R R 1 ) ;
RESTORE_ x S R R ( C S R R 0 ,C S R R 1 ) ;
RESTORE_ x S R R ( D S R R 0 ,D S R R 1 ) ;
RESTORE_ M M U _ R E G S ;
2009-02-10 20:10:44 +00:00
RET_ F R O M _ E X C _ L E V E L ( S P R N _ M C S R R 0 , S P R N _ M C S R R 1 , P P C _ R F M C I )
2020-03-31 16:03:47 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( r e t _ f r o m _ m c h e c k _ e x c )
2005-10-10 22:36:14 +10:00
# endif / * C O N F I G _ B O O K E * /
/ *
* Load t h e D B C R 0 v a l u e f o r a t a s k t h a t i s b e i n g p t r a c e d ,
* having f i r s t s a v e d a w a y t h e g l o b a l D B C R 0 . N o t e t h a t r0
* has t h e d b c r0 v a l u e t o s e t u p o n e n t r y t o t h i s .
* /
load_dbcr0 :
mfmsr r10 / * f i r s t d i s a b l e d e b u g e x c e p t i o n s * /
rlwinm r10 ,r10 ,0 ,~ M S R _ D E
mtmsr r10
isync
mfspr r10 ,S P R N _ D B C R 0
lis r11 ,g l o b a l _ d b c r0 @ha
addi r11 ,r11 ,g l o b a l _ d b c r0 @l
2008-04-09 16:15:40 -05:00
# ifdef C O N F I G _ S M P
2019-01-31 10:09:04 +00:00
lwz r9 ,T A S K _ C P U ( r2 )
2021-02-08 15:10:41 +00:00
slwi r9 ,r9 ,2
2008-04-09 16:15:40 -05:00
add r11 ,r11 ,r9
# endif
2005-10-10 22:36:14 +10:00
stw r10 ,0 ( r11 )
mtspr S P R N _ D B C R 0 ,r0
li r11 ,- 1
mtspr S P R N _ D B S R ,r11 / * c l e a r a l l p e n d i n g d e b u g e v e n t s * /
blr
2007-05-14 17:11:58 -05:00
.section .bss
.align 4
2019-04-30 12:39:02 +00:00
.global global_dbcr0
2007-05-14 17:11:58 -05:00
global_dbcr0 :
2021-02-08 15:10:41 +00:00
.space 4 * NR_ C P U S
2007-05-14 17:11:58 -05:00
.previous
2005-10-10 22:36:14 +10:00
# endif / * ! ( C O N F I G _ 4 x x | | C O N F I G _ B O O K E ) * /
do_work : /* r10 contains MSR_KERNEL here */
andi. r0 ,r9 ,_ T I F _ N E E D _ R E S C H E D
beq d o _ u s e r _ s i g n a l
do_resched : /* r10 contains MSR_KERNEL here */
2019-04-30 12:39:01 +00:00
# ifdef C O N F I G _ T R A C E _ I R Q F L A G S
bl t r a c e _ h a r d i r q s _ o n
mfmsr r10
# endif
2005-10-10 22:36:14 +10:00
ori r10 ,r10 ,M S R _ E E
2019-12-21 08:32:22 +00:00
mtmsr r10 / * h a r d - e n a b l e i n t e r r u p t s * /
2005-10-10 22:36:14 +10:00
bl s c h e d u l e
recheck :
2009-06-17 17:43:59 +00:00
/ * Note : And w e d o n ' t t e l l i t w e a r e d i s a b l i n g t h e m a g a i n
* neither. T h o s e d i s a b l e / e n a b l e c y c l e s u s e d t o p e e k a t
* TI_ F L A G S a r e n ' t a d v e r t i s e d .
* /
2019-08-20 14:34:13 +00:00
LOAD_ R E G _ I M M E D I A T E ( r10 ,M S R _ K E R N E L )
2019-12-21 08:32:22 +00:00
mtmsr r10 / * d i s a b l e i n t e r r u p t s * /
2019-01-31 10:09:04 +00:00
lwz r9 ,T I _ F L A G S ( r2 )
2005-10-10 22:36:14 +10:00
andi. r0 ,r9 ,_ T I F _ N E E D _ R E S C H E D
bne- d o _ r e s c h e d
2008-04-28 17:30:37 +10:00
andi. r0 ,r9 ,_ T I F _ U S E R _ W O R K _ M A S K
2005-10-10 22:36:14 +10:00
beq r e s t o r e _ u s e r
do_user_signal : /* r10 contains MSR_KERNEL here */
ori r10 ,r10 ,M S R _ E E
2019-12-21 08:32:22 +00:00
mtmsr r10 / * h a r d - e n a b l e i n t e r r u p t s * /
2005-10-10 22:36:14 +10:00
/* save r13-r31 in the exception frame, if not already done */
2005-10-28 22:45:25 +10:00
lwz r3 ,_ T R A P ( r1 )
2005-10-10 22:36:14 +10:00
andi. r0 ,r3 ,1
beq 2 f
SAVE_ N V G P R S ( r1 )
rlwinm r3 ,r3 ,0 ,0 ,3 0
2005-10-28 22:45:25 +10:00
stw r3 ,_ T R A P ( r1 )
2008-07-27 16:52:52 +10:00
2 : addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
mr r4 ,r9
2012-02-22 16:48:32 +11:00
bl d o _ n o t i f y _ r e s u m e
2005-10-10 22:36:14 +10:00
REST_ N V G P R S ( r1 )
b r e c h e c k
/ *
* We c o m e h e r e w h e n w e a r e a t t h e e n d o f h a n d l i n g a n e x c e p t i o n
* that o c c u r r e d a t a p l a c e w h e r e t a k i n g a n e x c e p t i o n w i l l l o s e
* state i n f o r m a t i o n , s u c h a s t h e c o n t e n t s o f S R R 0 a n d S R R 1 .
* /
nonrecoverable :
lis r10 ,e x c _ e x i t _ r e s t a r t _ e n d @ha
addi r10 ,r10 ,e x c _ e x i t _ r e s t a r t _ e n d @l
cmplw r12 ,r10
bge 3 f
lis r11 ,e x c _ e x i t _ r e s t a r t @ha
addi r11 ,r11 ,e x c _ e x i t _ r e s t a r t @l
cmplw r12 ,r11
blt 3 f
lis r10 ,e e _ r e s t a r t s @ha
lwz r12 ,e e _ r e s t a r t s @l(r10)
addi r12 ,r12 ,1
stw r12 ,e e _ r e s t a r t s @l(r10)
mr r12 ,r11 / * r e s t a r t a t e x c _ e x i t _ r e s t a r t * /
blr
3 : /* OK, we can't recover, kill this process */
2005-10-28 22:45:25 +10:00
lwz r3 ,_ T R A P ( r1 )
2005-10-10 22:36:14 +10:00
andi. r0 ,r3 ,1
2019-01-31 10:08:58 +00:00
beq 5 f
2005-10-10 22:36:14 +10:00
SAVE_ N V G P R S ( r1 )
rlwinm r3 ,r3 ,0 ,0 ,3 0
2005-10-28 22:45:25 +10:00
stw r3 ,_ T R A P ( r1 )
2019-01-31 10:08:58 +00:00
5 : mfspr r2 ,S P R N _ S P R G _ T H R E A D
addi r2 ,r2 ,- T H R E A D
tovirt( r2 ,r2 ) / * s e t b a c k r2 t o c u r r e n t * /
2005-10-10 22:36:14 +10:00
4 : addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2018-09-25 14:10:04 +00:00
bl u n r e c o v e r a b l e _ e x c e p t i o n
2005-10-10 22:36:14 +10:00
/* shouldn't return */
b 4 b
2020-03-31 16:03:44 +00:00
_ ASM_ N O K P R O B E _ S Y M B O L ( n o n r e c o v e r a b l e )
2005-10-10 22:36:14 +10:00
2007-05-14 17:11:58 -05:00
.section .bss
.align 2
ee_restarts :
.space 4
.previous
2005-10-10 22:36:14 +10:00
/ *
* PROM c o d e f o r s p e c i f i c m a c h i n e s f o l l o w s . P u t i t
* here s o i t ' s e a s y t o a d d a r c h - s p e c i f i c s e c t i o n s l a t e r .
* - - Cort
* /
2005-10-26 17:05:24 +10:00
# ifdef C O N F I G _ P P C _ R T A S
2005-10-10 22:36:14 +10:00
/ *
* On C H R P , t h e R u n - T i m e A b s t r a c t i o n S e r v i c e s ( R T A S ) h a v e t o b e
* called w i t h t h e M M U o f f .
* /
_ 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 )
2006-01-13 14:56:25 +11:00
LOAD_ R E G _ A D D R ( r4 , r t a s )
2005-10-10 22:36:14 +10:00
lis r6 ,1 f @ha /* physical return address for rtas */
addi r6 ,r6 ,1 f @l
tophys( r6 ,r6 )
2005-10-26 17:05:24 +10:00
lwz r8 ,R T A S E N T R Y ( r4 )
lwz r4 ,R T A S B A S E ( r4 )
2005-10-10 22:36:14 +10:00
mfmsr r9
stw r9 ,8 ( r1 )
2019-08-20 14:34:13 +00:00
LOAD_ R E G _ I M M E D I A T E ( r0 ,M S R _ K E R N E L )
2020-09-29 06:48:34 +00:00
mtmsr r0 / * d i s a b l e i n t e r r u p t s s o S R R 0 / 1 d o n ' t g e t t r a s h e d * /
2005-10-10 22:36:14 +10:00
li r9 ,M S R _ K E R N E L & ~ ( M S R _ I R | M S R _ D R )
mtlr r6
2021-03-12 12:50:22 +00:00
stw r1 , T H R E A D + R T A S _ S P ( r2 )
2005-10-10 22:36:14 +10:00
mtspr S P R N _ S R R 0 ,r8
mtspr S P R N _ S R R 1 ,r9
2020-11-08 16:57:36 +00:00
rfi
2021-03-12 12:50:22 +00:00
1 :
2021-03-12 12:50:24 +00:00
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 :
2021-03-12 12:50:22 +00:00
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 * /
2005-10-10 22:36:14 +10:00
addi r1 ,r1 ,I N T _ F R A M E _ S I Z E
li r0 ,0
2021-03-12 12:50:22 +00:00
stw r0 , T H R E A D + R T A S _ S P ( r2 )
2021-03-12 12:50:24 +00:00
mtlr r8
mtmsr r9
blr / * r e t u r n t o c a l l e r * /
2020-03-31 16:03:44 +00: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 )
2005-10-26 17:05:24 +10:00
# endif / * C O N F I G _ P P C _ R T A S * /