2005-04-16 15:20:36 -07:00
/ *
* Copyright ( C ) 2 0 0 0 A n t o n B l a n c h a r d ( a n t o n @linuxcare.com)
*
* This f i l e i m p l e m e n t s m c o u n t ( ) , w h i c h i s u s e d t o c o l l e c t p r o f i l i n g d a t a .
* This c a n a l s o b e t w e a k e d f o r k e r n e l s t a c k o v e r f l o w d e t e c t i o n .
* /
# include < l i n u x / l i n k a g e . h >
# include < a s m / p t r a c e . h >
# include < a s m / t h r e a d _ i n f o . h >
/ *
* This i s t h e m a i n v a r i a n t a n d i s c a l l e d b y C c o d e . G C C ' s - p g o p t i o n
* automatically i n s t r u m e n t s e v e r y C f u n c t i o n w i t h a c a l l t o t h i s .
* /
# ifdef C O N F I G _ S T A C K _ D E B U G
# define O V S T A C K S I Z E 4 0 9 6 / * l e t s h o p e t h i s i s e n o u g h * /
.data
.align 8
panicstring :
.asciz " Stack o v e r f l o w \ n "
.align 8
ovstack :
.skip OVSTACKSIZE
# endif
.text
2008-05-13 22:06:59 -07:00
.align 32
.globl _mcount
.type _ mcount,#f u n c t i o n
.globl mcount
.type mcount,#f u n c t i o n
2005-04-16 15:20:36 -07:00
_mcount :
2008-05-13 22:06:59 -07:00
mcount :
2005-04-16 15:20:36 -07:00
# ifdef C O N F I G _ S T A C K _ D E B U G
/ *
* Check w h e t h e r % s p i s d a n g e r o u s l y l o w .
* /
ldub [ % g 6 + T I _ F P D E P T H ] , % g 1
srl % g 1 , 1 , % g 3
add % g 3 , 1 , % g 3
sllx % g 3 , 8 , % g 3 ! e a c h f p r e g s f r a m e i s 2 5 6 b
add % g 3 , 1 9 2 , % g 3
add % g 6 , % g 3 , % g 3 ! w h e r e d o e s t a s k _ s t r u c t + f r a m e e n d ?
sub % g 3 , S T A C K _ B I A S , % g 3
cmp % s p , % g 3
bg,p t % x c c , 1 f
sethi % h i ( p a n i c s t r i n g ) , % g 3
sethi % h i ( o v s t a c k ) , % g 7 ! c a n t m o v e t o p a n i c s t a c k f a s t e n o u g h
or % g 7 , % l o ( o v s t a c k ) , % g 7
add % g 7 , O V S T A C K S I Z E , % g 7
sub % g 7 , S T A C K _ B I A S , % g 7
mov % g 7 , % s p
call p r o m _ p r i n t f
or % g 3 , % l o ( p a n i c s t r i n g ) , % o 0
call p r o m _ h a l t
nop
2008-05-13 22:06:59 -07:00
1 :
# endif
# ifdef C O N F I G _ F T R A C E
# ifdef C O N F I G _ D Y N A M I C _ F T R A C E
mov % o 7 , % o 0
.globl mcount_call
mcount_call :
call f t r a c e _ s t u b
mov % o 0 , % o 7
# else
sethi % h i ( f t r a c e _ t r a c e _ f u n c t i o n ) , % g 1
sethi % h i ( f t r a c e _ s t u b ) , % g 2
ldx [ % g 1 + % l o ( f t r a c e _ t r a c e _ f u n c t i o n ) ] , % g 1
or % g 2 , % l o ( f t r a c e _ s t u b ) , % g 2
cmp % g 1 , % g 2
be,p n % i c c , 1 f
mov % i 7 , % o 1
jmpl % g 1 , % g 0
mov % o 7 , % o 0
/* not reached */
1 :
2005-04-16 15:20:36 -07:00
# endif
2008-05-13 22:06:59 -07:00
# endif
retl
2005-04-16 15:20:36 -07:00
nop
2008-05-13 22:06:59 -07:00
.size _ mcount,. - _ m c o u n t
.size mcount,. - m c o u n t
# ifdef C O N F I G _ F T R A C E
.globl ftrace_stub
.type ftrace_ s t u b ,#f u n c t i o n
ftrace_stub :
retl
nop
.size ftrace_ s t u b ,. - f t r a c e _ s t u b
# ifdef C O N F I G _ D Y N A M I C _ F T R A C E
.globl ftrace_caller
.type ftrace_ c a l l e r ,#f u n c t i o n
ftrace_caller :
mov % i 7 , % o 1
mov % o 7 , % o 0
.globl ftrace_call
ftrace_call :
call f t r a c e _ s t u b
mov % o 0 , % o 7
retl
nop
.size ftrace_ c a l l e r ,. - f t r a c e _ c a l l e r
# endif
# endif