2018-02-13 08:13:17 +03:00
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (C) 2017 Andes Technology Corporation */
# include < l i n u x / i n i t . h >
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s m . h >
# include < a s m / c s r . h >
# include < a s m / u n i s t d . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / a s m - o f f s e t s . h >
# include < a s m - g e n e r i c / e x p o r t . h >
# include < a s m / f t r a c e . h >
.text
.macro SAVE_ABI_STATE
2018-02-13 08:13:18 +03:00
# ifdef C O N F I G _ F U N C T I O N _ G R A P H _ T R A C E R
addi s p , s p , - 4 8
sd s0 , 3 2 ( s p )
sd r a , 4 0 ( s p )
addi s0 , s p , 4 8
sd t 0 , 2 4 ( s p )
sd t 1 , 1 6 ( s p )
# ifdef H A V E _ F U N C T I O N _ G R A P H _ F P _ T E S T
sd t 2 , 8 ( s p )
# endif
# else
2018-02-13 08:13:17 +03:00
addi s p , s p , - 1 6
sd s0 , 0 ( s p )
sd r a , 8 ( s p )
addi s0 , s p , 1 6
2018-02-13 08:13:18 +03:00
# endif
2018-02-13 08:13:17 +03:00
.endm
.macro RESTORE_ABI_STATE
2018-02-13 08:13:18 +03:00
# ifdef C O N F I G _ F U N C T I O N _ G R A P H _ T R A C E R
ld s0 , 3 2 ( s p )
ld r a , 4 0 ( s p )
addi s p , s p , 4 8
# else
2018-02-13 08:13:17 +03:00
ld r a , 8 ( s p )
ld s0 , 0 ( s p )
addi s p , s p , 1 6
2018-02-13 08:13:18 +03:00
# endif
2018-02-13 08:13:17 +03:00
.endm
2018-02-13 08:13:18 +03:00
.macro RESTORE_GRAPH_ARGS
ld a0 , 2 4 ( s p )
ld a1 , 1 6 ( s p )
# ifdef H A V E _ F U N C T I O N _ G R A P H _ F P _ T E S T
ld a2 , 8 ( s p )
# endif
.endm
ENTRY( f t r a c e _ g r a p h _ c a l l e r )
addi s p , s p , - 1 6
sd s0 , 0 ( s p )
sd r a , 8 ( s p )
addi s0 , s p , 1 6
ftrace_graph_call :
.global ftrace_graph_call
/ *
* Calling f t r a c e _ e n a b l e / d i s a b l e _ f t r a c e _ g r a p h _ c a l l e r w o u l d o v e r w r i t e t h e
* call b e l o w . C h e c k f t r a c e _ m o d i f y _ a l l _ c o d e f o r d e t a i l s .
* /
call f t r a c e _ s t u b
ld r a , 8 ( s p )
ld s0 , 0 ( s p )
addi s p , s p , 1 6
ret
ENDPROC( f t r a c e _ g r a p h _ c a l l e r )
2018-02-13 08:13:17 +03:00
ENTRY( f t r a c e _ c a l l e r )
/ *
* a0 : the a d d r e s s i n t h e c a l l e r w h e n c a l l i n g f t r a c e _ c a l l e r
* a1 : the c a l l e r ' s r e t u r n a d d r e s s
2018-02-13 08:13:19 +03:00
* a2 : the a d d r e s s o f g l o b a l v a r i a b l e f u n c t i o n _ t r a c e _ o p
2018-02-13 08:13:17 +03:00
* /
ld a1 , - 8 ( s0 )
addi a0 , r a , - M C O U N T _ I N S N _ S I Z E
2018-02-13 08:13:19 +03:00
la t 5 , f u n c t i o n _ t r a c e _ o p
ld a2 , 0 ( t 5 )
2018-02-13 08:13:18 +03:00
# ifdef C O N F I G _ F U N C T I O N _ G R A P H _ T R A C E R
/ *
* the g r a p h t r a c e r ( s p e c i f i c a l l y , p r e p a r e _ f t r a c e _ r e t u r n ) n e e d s t h e s e
* arguments b u t f o r n o w t h e f u n c t i o n t r a c e r o c c u p i e s t h e r e g s , s o w e
* save t h e m i n t e m p o r a r y r e g s t o r e c o v e r l a t e r .
* /
addi t 0 , s0 , - 8
mv t 1 , a0
# ifdef H A V E _ F U N C T I O N _ G R A P H _ F P _ T E S T
ld t 2 , - 1 6 ( s0 )
# endif
# endif
2018-02-13 08:13:17 +03:00
SAVE_ A B I _ S T A T E
ftrace_call :
.global ftrace_call
/ *
* For t h e d y n a m i c f t r a c e t o w o r k , h e r e w e s h o u l d r e s e r v e a t l e a s t
* 8 bytes f o r a f u n c t i o n a l a u i p c - j a l r p a i r . T h e f o l l o w i n g c a l l
* serves t h i s p u r p o s e .
*
* Calling f t r a c e _ u p d a t e _ f t r a c e _ f u n c w o u l d o v e r w r i t e t h e n o p s b e l o w .
* Check f t r a c e _ m o d i f y _ a l l _ c o d e f o r d e t a i l s .
* /
call f t r a c e _ s t u b
2018-02-13 08:13:18 +03:00
# ifdef C O N F I G _ F U N C T I O N _ G R A P H _ T R A C E R
RESTORE_ G R A P H _ A R G S
call f t r a c e _ g r a p h _ c a l l e r
# endif
2018-02-13 08:13:17 +03:00
RESTORE_ A B I _ S T A T E
ret
ENDPROC( f t r a c e _ c a l l e r )
2018-02-13 08:13:20 +03:00
# ifdef C O N F I G _ D Y N A M I C _ F T R A C E _ W I T H _ R E G S
.macro SAVE_ALL
addi s p , s p , - ( P T _ S I Z E _ O N _ S T A C K + 1 6 )
sd s0 , ( P T _ S I Z E _ O N _ S T A C K ) ( s p )
sd r a , ( P T _ S I Z E _ O N _ S T A C K + 8 ) ( s p )
addi s0 , s p , ( P T _ S I Z E _ O N _ S T A C K + 1 6 )
sd x1 , P T _ R A ( s p )
sd x2 , P T _ S P ( s p )
sd x3 , P T _ G P ( s p )
sd x4 , P T _ T P ( s p )
sd x5 , P T _ T 0 ( s p )
sd x6 , P T _ T 1 ( s p )
sd x7 , P T _ T 2 ( s p )
sd x8 , P T _ S 0 ( s p )
sd x9 , P T _ S 1 ( s p )
sd x10 , P T _ A 0 ( s p )
sd x11 , P T _ A 1 ( s p )
sd x12 , P T _ A 2 ( s p )
sd x13 , P T _ A 3 ( s p )
sd x14 , P T _ A 4 ( s p )
sd x15 , P T _ A 5 ( s p )
sd x16 , P T _ A 6 ( s p )
sd x17 , P T _ A 7 ( s p )
sd x18 , P T _ S 2 ( s p )
sd x19 , P T _ S 3 ( s p )
sd x20 , P T _ S 4 ( s p )
sd x21 , P T _ S 5 ( s p )
sd x22 , P T _ S 6 ( s p )
sd x23 , P T _ S 7 ( s p )
sd x24 , P T _ S 8 ( s p )
sd x25 , P T _ S 9 ( s p )
sd x26 , P T _ S 1 0 ( s p )
sd x27 , P T _ S 1 1 ( s p )
sd x28 , P T _ T 3 ( s p )
sd x29 , P T _ T 4 ( s p )
sd x30 , P T _ T 5 ( s p )
sd x31 , P T _ T 6 ( s p )
.endm
.macro RESTORE_ALL
ld x1 , P T _ R A ( s p )
ld x2 , P T _ S P ( s p )
ld x3 , P T _ G P ( s p )
ld x4 , P T _ T P ( s p )
ld x5 , P T _ T 0 ( s p )
ld x6 , P T _ T 1 ( s p )
ld x7 , P T _ T 2 ( s p )
ld x8 , P T _ S 0 ( s p )
ld x9 , P T _ S 1 ( s p )
ld x10 , P T _ A 0 ( s p )
ld x11 , P T _ A 1 ( s p )
ld x12 , P T _ A 2 ( s p )
ld x13 , P T _ A 3 ( s p )
ld x14 , P T _ A 4 ( s p )
ld x15 , P T _ A 5 ( s p )
ld x16 , P T _ A 6 ( s p )
ld x17 , P T _ A 7 ( s p )
ld x18 , P T _ S 2 ( s p )
ld x19 , P T _ S 3 ( s p )
ld x20 , P T _ S 4 ( s p )
ld x21 , P T _ S 5 ( s p )
ld x22 , P T _ S 6 ( s p )
ld x23 , P T _ S 7 ( s p )
ld x24 , P T _ S 8 ( s p )
ld x25 , P T _ S 9 ( s p )
ld x26 , P T _ S 1 0 ( s p )
ld x27 , P T _ S 1 1 ( s p )
ld x28 , P T _ T 3 ( s p )
ld x29 , P T _ T 4 ( s p )
ld x30 , P T _ T 5 ( s p )
ld x31 , P T _ T 6 ( s p )
ld s0 , ( P T _ S I Z E _ O N _ S T A C K ) ( s p )
ld r a , ( P T _ S I Z E _ O N _ S T A C K + 8 ) ( s p )
addi s p , s p , ( P T _ S I Z E _ O N _ S T A C K + 1 6 )
.endm
.macro RESTORE_GRAPH_REG_ARGS
ld a0 , P T _ T 0 ( s p )
ld a1 , P T _ T 1 ( s p )
# ifdef H A V E _ F U N C T I O N _ G R A P H _ F P _ T E S T
ld a2 , P T _ T 2 ( s p )
# endif
.endm
/ *
* Most o f t h e c o n t e n t s a r e t h e s a m e a s f t r a c e _ c a l l e r .
* /
ENTRY( f t r a c e _ r e g s _ c a l l e r )
/ *
* a3 : the a d d r e s s o f a l l r e g i s t e r s i n t h e s t a c k
* /
ld a1 , - 8 ( s0 )
addi a0 , r a , - M C O U N T _ I N S N _ S I Z E
la t 5 , f u n c t i o n _ t r a c e _ o p
ld a2 , 0 ( t 5 )
addi a3 , s p , - ( P T _ S I Z E _ O N _ S T A C K + 1 6 )
# ifdef C O N F I G _ F U N C T I O N _ G R A P H _ T R A C E R
addi t 0 , s0 , - 8
mv t 1 , a0
# ifdef H A V E _ F U N C T I O N _ G R A P H _ F P _ T E S T
ld t 2 , - 1 6 ( s0 )
# endif
# endif
SAVE_ A L L
ftrace_regs_call :
.global ftrace_regs_call
call f t r a c e _ s t u b
# ifdef C O N F I G _ F U N C T I O N _ G R A P H _ T R A C E R
RESTORE_ G R A P H _ R E G _ A R G S
call f t r a c e _ g r a p h _ c a l l e r
# endif
RESTORE_ A L L
ret
ENDPROC( f t r a c e _ r e g s _ c a l l e r )
# endif / * C O N F I G _ D Y N A M I C _ F T R A C E _ W I T H _ R E G S * /