2018-12-09 09:29:59 +03:00
/* SPDX-License-Identifier: GPL-2.0 */
/ / Copyright ( C ) 2 0 1 8 H a n g z h o u C - S K Y M i c r o s y s t e m s c o . ,l t d .
# include < l i n u x / l i n k a g e . h >
2018-12-15 16:04:27 +03:00
# include < a s m / f t r a c e . h >
2020-02-18 15:27:39 +03:00
# include < a b i / e n t r y . h >
# include < a s m / a s m - o f f s e t s . h >
2018-12-09 09:29:59 +03:00
2018-12-15 16:04:27 +03:00
/ *
* csky- g c c w i t h - p g w i l l p u t t h e f o l l o w i n g a s m a f t e r p r o l o g u e :
* push r15
* jsri _ m c o u n t
*
* stack l a y o u t a f t e r m c o u n t _ e n t e r i n _ m c o u n t ( ) :
*
* current s p = > 0 : + - - - - - - - +
* | a0 - a3 | - > m u s t s a v e a l l a r g u m e n t r e g s
* + 16 : + - - - - - - - +
* | lr | - > _ m c o u n t l r ( i n s t r u m e n t e f u n c t i o n ' s p c )
* + 20 : + - - - - - - - +
* | fp=r8 | - > i n s t r u m e n t e d f u n c t i o n f p
* + 24 : + - - - - - - - +
* | plr | - > i n s t r u m e n t e d f u n c t i o n l r ( p a r e n t ' s p c )
* + - - - - - - - +
* /
.macro mcount_enter
subi s p , 2 4
2018-12-09 09:29:59 +03:00
stw a0 , ( s p , 0 )
stw a1 , ( s p , 4 )
stw a2 , ( s p , 8 )
stw a3 , ( s p , 1 2 )
stw l r , ( s p , 1 6 )
2018-12-15 16:04:27 +03:00
stw r8 , ( s p , 2 0 )
.endm
.macro mcount_exit
2018-12-09 09:29:59 +03:00
ldw a0 , ( s p , 0 )
ldw a1 , ( s p , 4 )
ldw a2 , ( s p , 8 )
ldw a3 , ( s p , 1 2 )
ldw t 1 , ( s p , 1 6 )
2018-12-15 16:04:27 +03:00
ldw r8 , ( s p , 2 0 )
ldw l r , ( s p , 2 4 )
addi s p , 2 8
2018-12-09 09:29:59 +03:00
jmp t 1
2018-12-15 16:04:27 +03:00
.endm
2020-02-18 15:27:39 +03:00
.macro mcount_enter_regs
subi s p , 8
stw l r , ( s p , 0 )
stw r8 , ( s p , 4 )
SAVE_ R E G S _ F T R A C E
.endm
.macro mcount_exit_regs
RESTORE_ R E G S _ F T R A C E
2020-07-28 19:25:23 +03:00
subi s p , 1 5 2
ldw t 1 , ( s p , 4 )
addi s p , 1 5 2
2020-02-18 15:27:39 +03:00
ldw r8 , ( s p , 4 )
ldw l r , ( s p , 8 )
addi s p , 1 2
jmp t 1
.endm
2018-12-15 16:04:27 +03:00
.macro save_return_regs
subi s p , 1 6
stw a0 , ( s p , 0 )
stw a1 , ( s p , 4 )
stw a2 , ( s p , 8 )
stw a3 , ( s p , 1 2 )
.endm
.macro restore_return_regs
mov l r , a0
ldw a0 , ( s p , 0 )
ldw a1 , ( s p , 4 )
ldw a2 , ( s p , 8 )
ldw a3 , ( s p , 1 2 )
addi s p , 1 6
.endm
2019-03-01 03:50:36 +03:00
.macro nop32_stub
nop3 2
nop3 2
nop3 2
.endm
2018-12-15 16:04:27 +03:00
ENTRY( f t r a c e _ s t u b )
jmp l r
END( f t r a c e _ s t u b )
2019-03-01 03:50:36 +03:00
# ifndef C O N F I G _ D Y N A M I C _ F T R A C E
2018-12-15 16:04:27 +03:00
ENTRY( _ m c o u n t )
mcount_ e n t e r
/* r26 is link register, only used with jsri translation */
lrw r26 , f t r a c e _ t r a c e _ f u n c t i o n
ldw r26 , ( r26 , 0 )
lrw a1 , f t r a c e _ s t u b
cmpne r26 , a1
bf s k i p _ f t r a c e
mov a0 , l r
2019-03-01 03:50:36 +03:00
subi a0 , 4
2018-12-15 16:04:27 +03:00
ldw a1 , ( s p , 2 4 )
2020-04-08 12:47:33 +03:00
lrw a2 , f u n c t i o n _ t r a c e _ o p
ldw a2 , ( a2 , 0 )
2018-12-15 16:04:27 +03:00
jsr r26
# ifndef 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
skip_ftrace :
mcount_ e x i t
# else
skip_ftrace :
lrw a0 , f t r a c e _ g r a p h _ r e t u r n
ldw a0 , ( a0 , 0 )
lrw a1 , f t r a c e _ s t u b
cmpne a0 , a1
bt f t r a c e _ g r a p h _ c a l l e r
lrw a0 , f t r a c e _ g r a p h _ e n t r y
ldw a0 , ( a0 , 0 )
lrw a1 , f t r a c e _ g r a p h _ e n t r y _ s t u b
cmpne a0 , a1
bt f t r a c e _ g r a p h _ c a l l e r
mcount_ e x i t
# endif
END( _ m c o u n t )
2019-03-01 03:50:36 +03:00
# else / * C O N F I G _ D Y N A M I C _ F T R A C E * /
ENTRY( _ m c o u n t )
mov t 1 , l r
ldw l r , ( s p , 0 )
addi s p , 4
jmp t 1
ENDPROC( _ m c o u n t )
ENTRY( f t r a c e _ c a l l e r )
mcount_ e n t e r
ldw a0 , ( s p , 1 6 )
subi a0 , 4
ldw a1 , ( s p , 2 4 )
2020-02-18 15:27:39 +03:00
lrw a2 , f u n c t i o n _ t r a c e _ o p
ldw a2 , ( a2 , 0 )
2019-03-01 03:50:36 +03:00
nop
GLOBAL( f t r a c e _ c a l l )
nop3 2 _ 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
nop
GLOBAL( f t r a c e _ g r a p h _ c a l l )
nop3 2 _ s t u b
# endif
mcount_ e x i t
ENDPROC( f t r a c e _ 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 * /
2018-12-15 16:04:27 +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
ENTRY( f t r a c e _ g r a p h _ c a l l e r )
mov a0 , s p
addi a0 , 2 4
ldw a1 , ( s p , 1 6 )
2019-03-01 03:50:36 +03:00
subi a1 , 4
2018-12-15 16:04:27 +03:00
mov a2 , r8
lrw r26 , p r e p a r e _ f t r a c e _ r e t u r n
jsr r26
mcount_ e x i t
END( f t r a c e _ g r a p h _ c a l l e r )
ENTRY( r e t u r n _ t o _ h a n d l e r )
save_ r e t u r n _ r e g s
mov a0 , r8
jsri f t r a c e _ r e t u r n _ t o _ h a n d l e r
restore_ r e t u r n _ r e g s
jmp l r
END( r e t u r n _ t o _ h a n d l e r )
# endif
2020-02-18 15:27:39 +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
ENTRY( f t r a c e _ r e g s _ c a l l e r )
mcount_ e n t e r _ r e g s
lrw t 1 , P T _ F R A M E _ S I Z E
add t 1 , s p
ldw a0 , ( t 1 , 0 )
subi a0 , 4
ldw a1 , ( t 1 , 8 )
lrw a2 , f u n c t i o n _ t r a c e _ o p
ldw a2 , ( a2 , 0 )
mov a3 , s p
nop
GLOBAL( f t r a c e _ r e g s _ c a l l )
nop3 2 _ 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
nop
GLOBAL( f t r a c e _ g r a p h _ r e g s _ c a l l )
nop3 2 _ s t u b
# endif
mcount_ e x i t _ r e g s
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 * /