2017-12-18 17:52:48 +08: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
addi s p , s p , - 1 6
2022-11-15 20:08:30 +00:00
REG_ S s0 , 0 * S Z R E G ( s p )
REG_ S r a , 1 * S Z R E G ( s p )
2017-12-18 17:52:48 +08:00
addi s0 , s p , 1 6
.endm
/ *
* The c a l l t o f t r a c e _ r e t u r n _ t o _ h a n d l e r w o u l d o v e r w r i t e t h e r e t u r n
* register i f a0 w a s n o t s a v e d .
* /
.macro SAVE_RET_ABI_STATE
2022-11-15 20:08:30 +00:00
addi s p , s p , - 4 * S Z R E G
REG_ S s0 , 2 * S Z R E G ( s p )
REG_ S r a , 3 * S Z R E G ( s p )
REG_ S a0 , 1 * S Z R E G ( s p )
2022-11-15 20:08:31 +00:00
REG_ S a1 , 0 * S Z R E G ( s p )
2022-11-15 20:08:30 +00:00
addi s0 , s p , 4 * S Z R E G
2017-12-18 17:52:48 +08:00
.endm
2018-02-13 13:13:17 +08:00
.macro RESTORE_ABI_STATE
2022-11-15 20:08:30 +00:00
REG_ L r a , 1 * S Z R E G ( s p )
REG_ L s0 , 0 * S Z R E G ( s p )
2017-12-18 17:52:48 +08:00
addi s p , s p , 1 6
.endm
2018-02-13 13:13:17 +08:00
.macro RESTORE_RET_ABI_STATE
2022-11-15 20:08:30 +00:00
REG_ L r a , 3 * S Z R E G ( s p )
REG_ L s0 , 2 * S Z R E G ( s p )
REG_ L a0 , 1 * S Z R E G ( s p )
2022-11-15 20:08:31 +00:00
REG_ L a1 , 0 * S Z R E G ( s p )
2022-11-15 20:08:30 +00:00
addi s p , s p , 4 * S Z R E G
2017-12-18 17:52:48 +08:00
.endm
ENTRY( f t r a c e _ s t u b )
2018-02-13 13:13:17 +08:00
# ifdef C O N F I G _ D Y N A M I C _ F T R A C E
2021-03-25 15:38:06 -07:00
.global MCOUNT_NAME
.set MCOUNT_ N A M E , f t r a c e _ s t u b
2018-02-13 13:13:17 +08:00
# endif
2017-12-18 17:52:48 +08:00
ret
ENDPROC( 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
ENTRY( r e t u r n _ t o _ h a n d l e r )
/ *
* On i m p l e m e n t i n g t h e f r a m e p o i n t t e s t , t h e i d e a l w a y i s t o c o m p a r e t h e
* s0 ( f r a m e p o i n t e r , i f e n a b l e d ) o n e n t r y a n d t h e s p ( s t a c k p o i n t e r ) o n r e t u r n .
* However, t h e p s A B I o f v a r i a b l e - l e n g t h - a r g u m e n t f u n c t i o n s d o e s n o t a l l o w t h i s .
*
* So a l t e r n a t i v e l y w e c h e c k t h e * o l d * f r a m e p o i n t e r p o s i t i o n , t h a t i s , t h e
* value s t o r e d i n - 1 6 ( s0 ) o n e n t r y , a n d t h e s0 o n r e t u r n .
* /
# ifdef H A V E _ F U N C T I O N _ G R A P H _ F P _ T E S T
mv t 6 , s0
# endif
SAVE_ R E T _ A B I _ S T A T E
# ifdef H A V E _ F U N C T I O N _ G R A P H _ F P _ T E S T
mv a0 , t 6
# endif
2018-02-13 13:13:17 +08:00
call f t r a c e _ r e t u r n _ t o _ h a n d l e r
2022-11-15 20:08:31 +00:00
mv a2 , a0
2018-02-13 13:13:17 +08:00
RESTORE_ R E T _ A B I _ S T A T E
2022-11-15 20:08:31 +00:00
jalr a2
2017-12-18 17:52:48 +08:00
ENDPROC( r e t u r n _ t o _ h a n d l e r )
# endif
2018-02-13 13:13:17 +08:00
# ifndef C O N F I G _ D Y N A M I C _ F T R A C E
2021-03-25 15:38:06 -07:00
ENTRY( M C O U N T _ N A M E )
2017-12-18 17:52:48 +08:00
la t 4 , 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
la t 0 , f t r a c e _ g r a p h _ r e t u r n
2022-11-15 20:08:29 +00:00
REG_ L t 1 , 0 ( t 0 )
2017-12-18 17:52:48 +08:00
bne t 1 , t 4 , d o _ f t r a c e _ g r a p h _ c a l l e r
la t 3 , f t r a c e _ g r a p h _ e n t r y
2022-11-15 20:08:29 +00:00
REG_ L t 2 , 0 ( t 3 )
2017-12-18 17:52:48 +08:00
la t 6 , f t r a c e _ g r a p h _ e n t r y _ s t u b
bne t 2 , t 6 , d o _ f t r a c e _ g r a p h _ c a l l e r
# endif
la t 3 , f t r a c e _ t r a c e _ f u n c t i o n
2022-11-15 20:08:29 +00:00
REG_ L t 5 , 0 ( t 3 )
2017-12-18 17:52:48 +08:00
bne t 5 , t 4 , d o _ t r a c e
ret
# 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
/ *
* A p s e u d o r e p r e s e n t a t i o n f o r t h e f u n c t i o n g r a p h t r a c e r :
* prepare_ t o _ r e t u r n ( & r a _ t o _ c a l l e r _ o f _ c a l l e r , r a _ t o _ c a l l e r )
* /
do_ftrace_graph_caller :
2022-11-15 20:08:30 +00:00
addi a0 , s0 , - S Z R E G
2017-12-18 17:52:48 +08:00
mv a1 , r a
# ifdef H A V E _ F U N C T I O N _ G R A P H _ F P _ T E S T
2022-11-15 20:08:30 +00:00
REG_ L a2 , - 2 * S Z R E G ( s0 )
2017-12-18 17:52:48 +08:00
# endif
SAVE_ A B I _ S T A T E
2018-02-13 13:13:17 +08:00
call p r e p a r e _ f t r a c e _ r e t u r n
RESTORE_ A B I _ S T A T E
2017-12-18 17:52:48 +08:00
ret
# endif
/ *
* A p s e u d o r e p r e s e n t a t i o n f o r t h e f u n c t i o n t r a c e r :
* ( * ftrace_ t r a c e _ f u n c t i o n ) ( r a _ t o _ c a l l e r , r a _ t o _ c a l l e r _ o f _ c a l l e r )
* /
do_trace :
2022-11-15 20:08:30 +00:00
REG_ L a1 , - S Z R E G ( s0 )
2017-12-18 17:52:48 +08:00
mv a0 , r a
SAVE_ A B I _ S T A T E
jalr t 5
2018-02-13 13:13:17 +08:00
RESTORE_ A B I _ S T A T E
2017-12-18 17:52:48 +08:00
ret
2021-03-25 15:38:06 -07:00
ENDPROC( M C O U N T _ N A M E )
2018-02-13 13:13:17 +08:00
# endif
2021-03-25 15:38:06 -07:00
EXPORT_ S Y M B O L ( M C O U N T _ N A M E )