2005-04-17 02:20:36 +04: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-14 09:06:59 +04: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-17 02:20:36 +04:00
_mcount :
2008-05-14 09:06:59 +04:00
mcount :
2005-04-17 02:20:36 +04: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
2008-08-12 13:03:49 +04:00
nop
2008-08-13 05:33:56 +04:00
lduh [ % g 6 + T I _ C P U ] , % g 1
sethi % h i ( h a r d i r q _ s t a c k ) , % g 3
or % g 3 , % l o ( h a r d i r q _ s t a c k ) , % g 3
sllx % g 1 , 3 , % g 1
ldx [ % g 3 + % g 1 ] , % g 7
sub % g 7 , S T A C K _ B I A S , % g 7
cmp % s p , % g 7
bleu,p t % x c c , 2 f
sethi % h i ( T H R E A D _ S I Z E ) , % g 3
add % g 7 , % g 3 , % g 7
cmp % s p , % g 7
blu,p n % x c c , 1 f
2 : sethi % h i ( s o f t i r q _ s t a c k ) , % g 3
or % g 3 , % l o ( s o f t i r q _ s t a c k ) , % g 3
ldx [ % g 3 + % g 1 ] , % g 7
2009-12-09 12:43:45 +03:00
sub % g 7 , S T A C K _ B I A S , % g 7
2008-08-13 05:33:56 +04:00
cmp % s p , % g 7
2009-12-09 12:43:45 +03:00
bleu,p t % x c c , 3 f
2008-08-13 05:33:56 +04:00
sethi % h i ( T H R E A D _ S I Z E ) , % g 3
add % g 7 , % g 3 , % g 7
cmp % s p , % g 7
blu,p n % x c c , 1 f
nop
2008-08-12 13:03:49 +04:00
/ * If w e a r e a l r e a d y o n o v s t a c k , d o n ' t h o p o n t o i t
* again, w e a r e a l r e a d y t r y i n g t o o u t p u t t h e s t a c k o v e r f l o w
* message.
* /
2009-12-09 12:43:45 +03:00
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
2005-04-17 02:20:36 +04:00
or % g 7 , % l o ( o v s t a c k ) , % g 7
2008-08-12 13:03:49 +04:00
add % g 7 , O V S T A C K S I Z E , % g 3
sub % g 3 , S T A C K _ B I A S + 1 9 2 , % g 3
2005-04-17 02:20:36 +04:00
sub % g 7 , S T A C K _ B I A S , % g 7
2008-08-12 13:03:49 +04:00
cmp % s p , % g 7
blu,p n % x c c , 2 f
cmp % s p , % g 3
bleu,p n % x c c , 1 f
nop
2 : mov % g 3 , % s p
sethi % h i ( p a n i c s t r i n g ) , % g 3
2005-04-17 02:20:36 +04:00
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-14 09:06:59 +04:00
1 :
# endif
2008-10-07 03:06:12 +04:00
# ifdef C O N F I G _ F U N C T I O N _ T R A C E R
2008-05-14 09:06:59 +04:00
# 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-17 02:20:36 +04:00
# endif
2008-05-14 09:06:59 +04:00
# endif
retl
2005-04-17 02:20:36 +04:00
nop
2008-05-14 09:06:59 +04:00
.size _ mcount,. - _ m c o u n t
.size mcount,. - m c o u n t
2008-10-07 03:06:12 +04:00
# ifdef C O N F I G _ F U N C T I O N _ T R A C E R
2008-05-14 09:06:59 +04:00
.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