2018-12-09 14:29:59 +08: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 21:04:27 +08:00
# include < a s m / f t r a c e . h >
2018-12-09 14:29:59 +08:00
2018-12-15 21:04:27 +08: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 14:29:59 +08: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 21:04:27 +08:00
stw r8 , ( s p , 2 0 )
.endm
.macro mcount_exit
2018-12-09 14:29:59 +08: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 21:04:27 +08:00
ldw r8 , ( s p , 2 0 )
ldw l r , ( s p , 2 4 )
addi s p , 2 8
2018-12-09 14:29:59 +08:00
jmp t 1
2018-12-15 21:04:27 +08:00
.endm
.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
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 )
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
subi a0 , M C O U N T _ I N S N _ S I Z E
ldw a1 , ( s p , 2 4 )
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 )
# 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 )
subi a1 , M C O U N T _ I N S N _ S I Z E
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