2008-11-12 14:11:47 +03:00
/ *
* arch/ s h / l i b / m c o u n t . S
*
2009-07-11 16:06:53 +04:00
* Copyright ( C ) 2 0 0 8 , 2 0 0 9 P a u l M u n d t
2009-06-28 17:05:44 +04:00
* Copyright ( C ) 2 0 0 8 , 2 0 0 9 M a t t F l e m i n g
2008-11-12 14:11:47 +03:00
*
* This f i l e i s s u b j e c t t o t h e t e r m s a n d c o n d i t i o n s o f t h e G N U G e n e r a l P u b l i c
* License. S e e t h e f i l e " C O P Y I N G " i n t h e m a i n d i r e c t o r y o f t h i s a r c h i v e
* for m o r e d e t a i l s .
* /
# include < a s m / f t r a c e . h >
2009-07-11 05:00:23 +04:00
# 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 >
2008-11-12 14:11:47 +03:00
# define M C O U N T _ E N T E R ( ) \
mov. l r4 , @-r15; \
mov. l r5 , @-r15; \
mov. l r6 , @-r15; \
mov. l r7 , @-r15; \
sts. l p r , @-r15; \
\
mov. l @(20,r15),r4; \
sts p r , r5
# define M C O U N T _ L E A V E ( ) \
lds. l @r15+, pr; \
mov. l @r15+, r7; \
mov. l @r15+, r6; \
mov. l @r15+, r5; \
rts; \
mov. l @r15+, r4
2009-07-11 05:00:23 +04:00
# ifdef C O N F I G _ S T A C K _ D E B U G
/ *
* Perform d i a g n o s t i c c h e c k s o n t h e s t a t e o f t h e k e r n e l s t a c k .
*
* Check f o r s t a c k o v e r f l o w . I f t h e r e i s l e s s t h a n 1 K B f r e e
* then i t h a s o v e r f l o w e d .
*
* Make s u r e t h e s t a c k p o i n t e r c o n t a i n s a v a l i d a d d r e s s . V a l i d
* addresses f o r k e r n e l s t a c k s a r e a n y w h e r e a f t e r t h e b s s
2012-06-01 00:39:21 +04:00
* ( after _ _ b s s _ s t o p ) a n d a n y w h e r e i n i n i t _ t h r e a d _ u n i o n ( i n i t _ s t a c k ) .
2009-07-11 05:00:23 +04:00
* /
# define S T A C K _ C H E C K ( ) \
mov #( T H R E A D _ S I Z E > > 10 ) , r0 ; \
shll8 r0 ; \
shll2 r0 ; \
\
/* r1 = sp & (THREAD_SIZE - 1) */ \
mov #- 1 , r1 ; \
add r0 , r1 ; \
and r15 , r1 ; \
\
mov #T I _ S I Z E , r 3 ; \
mov #( S T A C K _ W A R N > > 8 ) , r2 ; \
shll8 r2 ; \
add r3 , r2 ; \
\
/* Is the stack overflowing? */ \
cmp/ h i r2 , r1 ; \
bf s t a c k _ p a n i c ; \
\
2012-06-01 00:39:21 +04:00
/* If sp > __bss_stop then we're OK. */ \
2009-07-11 05:00:23 +04:00
mov. l . L _ e b s s , r1 ; \
cmp/ h i r1 , r15 ; \
bt 1 f ; \
\
/* If sp < init_stack, we're not OK. */ \
mov. l . L _ i n i t _ t h r e a d _ u n i o n , r1 ; \
cmp/ h s r1 , r15 ; \
bf s t a c k _ p a n i c ; \
\
2012-06-01 00:39:21 +04:00
/* If sp > init_stack && sp < __bss_stop, not OK. */ \
2009-07-11 05:00:23 +04:00
add r0 , r1 ; \
cmp/ h s r1 , r15 ; \
bt s t a c k _ p a n i c ; \
1 :
# else
# define S T A C K _ C H E C K ( )
# endif / * C O N F I G _ S T A C K _ D E B U G * /
2008-11-12 14:11:47 +03:00
.align 2
.globl _mcount
.type _ mcount,@function
.globl mcount
.type mcount,@function
_mcount :
mcount :
2009-07-11 16:06:53 +04:00
STACK_ C H E C K ( )
# ifndef C O N F I G _ F U N C T I O N _ T R A C E R
rts
nop
# else
2008-11-12 14:11:47 +03:00
MCOUNT_ E N T E R ( )
# ifdef C O N F I G _ D Y N A M I C _ F T R A C E
.globl mcount_call
mcount_call :
mov. l . L f t r a c e _ s t u b , r6
# else
mov. l . L f t r a c e _ t r a c e _ f u n c t i o n , r6
mov. l f t r a c e _ s t u b , r7
cmp/ e q r6 , r7
bt s k i p _ t r a c e
mov. l @r6, r6
# endif
jsr @r6
nop
2009-07-11 04:29:03 +04: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
mov. l . L f t r a c e _ g r a p h _ r e t u r n , r6
mov. l . L f t r a c e _ s t u b , r7
cmp/ e q r6 , r7
bt 1 f
mov. l . L f t r a c e _ g r a p h _ c a l l e r , r0
jmp @r0
nop
1 :
mov. l . L f t r a c e _ g r a p h _ e n t r y , r6
mov. l . L f t r a c e _ g r a p h _ e n t r y _ s t u b , r7
cmp/ e q r6 , r7
bt s k i p _ t r a c e
mov. l . L f t r a c e _ g r a p h _ c a l l e r , r0
jmp @r0
nop
.align 2
.Lftrace_graph_return :
.long ftrace_graph_return
.Lftrace_graph_entry :
.long ftrace_graph_entry
.Lftrace_graph_entry_stub :
.long ftrace_graph_entry_stub
.Lftrace_graph_caller :
.long ftrace_graph_caller
# endif / * 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 * /
.globl skip_trace
2008-11-12 14:11:47 +03:00
skip_trace :
MCOUNT_ L E A V E ( )
.align 2
.Lftrace_trace_function :
2009-07-11 04:29:03 +04:00
.long ftrace_trace_function
2008-11-12 14:11:47 +03:00
# ifdef C O N F I G _ D Y N A M I C _ F T R A C E
2009-07-11 04:29:03 +04: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
/ *
* NOTE : Do n o t m o v e e i t h e r f t r a c e _ g r a p h _ c a l l o r f t r a c e _ c a l l e r
* as t h i s w i l l a f f e c t t h e c a l c u l a t i o n o f G R A P H _ I N S N _ O F F S E T .
* /
.globl ftrace_graph_call
ftrace_graph_call :
mov. l . L s k i p _ t r a c e , r0
jmp @r0
nop
.align 2
.Lskip_trace :
.long skip_trace
# endif / * 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 * /
2008-11-12 14:11:47 +03:00
.globl ftrace_caller
ftrace_caller :
MCOUNT_ E N T E R ( )
.globl ftrace_call
ftrace_call :
mov. l . L f t r a c e _ s t u b , r6
jsr @r6
nop
2009-07-11 04:29:03 +04: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
bra f t r a c e _ g r a p h _ c a l l
nop
# else
2008-11-12 14:11:47 +03:00
MCOUNT_ L E A V E ( )
2009-07-11 04:29:03 +04:00
# endif / * 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 * /
2008-11-12 14:11:47 +03:00
# endif / * C O N F I G _ D Y N A M I C _ F T R A C E * /
2009-07-11 15:33:34 +04:00
.align 2
2008-11-12 14:11:47 +03:00
/ *
* NOTE : From h e r e o n t h e l o c a t i o n s o f t h e . L f t r a c e _ s t u b l a b e l a n d
* ftrace_ s t u b i t s e l f a r e f i x e d . A d d i n g a d d i t i o n a l d a t a h e r e w i l l s k e w
* the d i s p l a c e m e n t f o r t h e m e m o r y t a b l e a n d b r e a k t h e b l o c k r e p l a c e m e n t .
* Place n e w l a b e l s e i t h e r a f t e r t h e f t r a c e _ s t u b b o d y , o r b e f o r e
* ftrace_ c a l l e r . Y o u h a v e b e e n w a r n e d .
* /
.Lftrace_stub :
.long ftrace_stub
.globl ftrace_stub
ftrace_stub :
rts
nop
2009-06-28 17:05:44 +04:00
2009-07-11 04:29:03 +04: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
.globl ftrace_graph_caller
ftrace_graph_caller :
2014-06-25 20:27:42 +04:00
mov. l 2 f , r1
2009-07-11 04:29:03 +04:00
jmp @r1
nop
1 :
/ *
* MCOUNT_ E N T E R ( ) p u s h e d 5 r e g i s t e r s o n t o t h e s t a c k , s o
* the s t a c k a d d r e s s c o n t a i n i n g o u r r e t u r n a d d r e s s i s
* r1 5 + 2 0 .
* /
mov #20 , r0
add r15 , r0
mov r0 , r4
mov. l . L p r e p a r e _ f t r a c e _ r e t u r n , r0
jsr @r0
nop
MCOUNT_ L E A V E ( )
.align 2
2014-06-25 20:27:42 +04:00
2 : .long s k i p _ t r a c e
2009-07-11 04:29:03 +04:00
.Lprepare_ftrace_return :
.long prepare_ftrace_return
.globl return_to_handler
return_to_handler :
/ *
* Save t h e r e t u r n v a l u e s .
* /
mov. l r0 , @-r15
mov. l r1 , @-r15
mov #0 , r4
mov. l . L f t r a c e _ r e t u r n _ t o _ h a n d l e r , r0
jsr @r0
nop
/ *
* The r e t u r n v a l u e f r o m f t r a c e _ r e t u r n _ h a n d l e r h a s t h e r e a l
* address t h a t w e s h o u l d r e t u r n t o .
* /
lds r0 , p r
mov. l @r15+, r1
rts
mov. l @r15+, r0
.align 2
.Lftrace_return_to_handler :
.long ftrace_return_to_handler
# endif / * 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 * /
2009-07-11 16:06:53 +04:00
# endif / * C O N F I G _ F U N C T I O N _ T R A C E R * /
# ifdef C O N F I G _ S T A C K _ D E B U G
.globl stack_panic
stack_panic :
mov. l . L d u m p _ s t a c k , r0
jsr @r0
nop
mov. l . L p a n i c , r0
jsr @r0
mov. l . L p a n i c _ s , r4
rts
nop
.align 2
.L_init_thread_union :
.long init_thread_union
2013-01-14 13:07:36 +04:00
.L_ebss :
.long __bss_stop
2009-07-11 16:06:53 +04:00
.Lpanic :
.long panic
.Lpanic_s :
.long .Lpanic_str
.Ldump_stack :
.long dump_stack
.section .rodata
.align 2
.Lpanic_str :
.string " Stack e r r o r "
# endif / * C O N F I G _ S T A C K _ D E B U G * /