2005-04-17 02:20:36 +04:00
/ * $ Id : rtrap. S ,v 1 . 6 1 2 0 0 2 / 0 2 / 0 9 1 9 : 4 9 : 3 1 d a v e m E x p $
* rtrap. S : P r e p a r i n g f o r r e t u r n f r o m t r a p o n S p a r c V 9 .
*
* Copyright ( C ) 1 9 9 7 ,1 9 9 8 J a k u b J e l i n e k ( j j @sunsite.mff.cuni.cz)
* Copyright ( C ) 1 9 9 7 D a v i d S . M i l l e r ( d a v e m @caip.rutgers.edu)
* /
# include < l i n u x / c o n f i g . h >
# include < a s m / a s i . h >
# include < a s m / p s t a t e . h >
# include < a s m / p t r a c e . h >
# include < a s m / s p i t f i r e . h >
# include < a s m / h e a d . h >
# include < a s m / v i s a s m . h >
# include < a s m / p r o c e s s o r . h >
# define R T R A P _ P S T A T E ( P S T A T E _ R M O | P S T A T E _ P E F | P S T A T E _ P R I V | P S T A T E _ I E )
# define R T R A P _ P S T A T E _ I R Q O F F ( P S T A T E _ R M O | P S T A T E _ P E F | P S T A T E _ P R I V )
# define R T R A P _ P S T A T E _ A G _ I R Q O F F ( P S T A T E _ R M O | P S T A T E _ P E F | P S T A T E _ P R I V | P S T A T E _ A G )
/ * Register % l 6 k e e p s t r a c k o f w h e t h e r w e a r e r e t u r n i n g
* from a s y s t e m c a l l o r n o t . I t i s c l e a r e d i f w e c a l l
* do_ n o t i f y _ r e s u m e , a n d i t m u s t n o t b e o t h e r w i s e m o d i f i e d
* until w e f u l l y c o m m i t t o r e t u r n i n g t o u s e r s p a c e .
* /
.text
.align 32
__handle_softirq :
call d o _ s o f t i r q
nop
ba,a ,p t % x c c , _ _ h a n d l e _ s o f t i r q _ c o n t i n u e
nop
__handle_preemption :
call s c h e d u l e
wrpr % g 0 , R T R A P _ P S T A T E , % p s t a t e
ba,p t % x c c , _ _ h a n d l e _ p r e e m p t i o n _ c o n t i n u e
wrpr % g 0 , R T R A P _ P S T A T E _ I R Q O F F , % p s t a t e
__handle_user_windows :
call f a u l t _ i n _ u s e r _ w i n d o w s
wrpr % g 0 , R T R A P _ P S T A T E , % p s t a t e
wrpr % g 0 , R T R A P _ P S T A T E _ I R Q O F F , % p s t a t e
/* Redo sched+sig checks */
ldx [ % g 6 + T I _ F L A G S ] , % l 0
andcc % l 0 , _ T I F _ N E E D _ R E S C H E D , % g 0
be,p t % x c c , 1 f
nop
call s c h e d u l e
wrpr % g 0 , R T R A P _ P S T A T E , % p s t a t e
wrpr % g 0 , R T R A P _ P S T A T E _ I R Q O F F , % p s t a t e
ldx [ % g 6 + T I _ F L A G S ] , % l 0
2006-01-19 13:42:49 +03:00
1 : andcc % l 0 , ( _ T I F _ S I G P E N D I N G | _ T I F _ R E S T O R E _ S I G M A S K ) , % g 0
2005-04-17 02:20:36 +04:00
be,p t % x c c , _ _ h a n d l e _ u s e r _ w i n d o w s _ c o n t i n u e
nop
2006-01-19 13:42:49 +03:00
mov % l 5 , % o 1
mov % l 6 , % o 2
add % s p , P T R E G S _ O F F , % o 0
mov % l 0 , % o 3
2005-04-17 02:20:36 +04:00
call d o _ n o t i f y _ r e s u m e
wrpr % g 0 , R T R A P _ P S T A T E , % p s t a t e
wrpr % g 0 , R T R A P _ P S T A T E _ I R Q O F F , % p s t a t e
clr % l 6
/ * Signal d e l i v e r y c a n m o d i f y p t _ r e g s t s t a t e , s o w e m u s t
* reload i t .
* /
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ T S T A T E ] , % l 1
sethi % h i ( 0 x f < < 2 0 ) , % l 4
and % l 1 , % l 4 , % l 4
ba,p t % x c c , _ _ h a n d l e _ u s e r _ w i n d o w s _ c o n t i n u e
andn % l 1 , % l 4 , % l 1
__handle_perfctrs :
call u p d a t e _ p e r f c t r s
wrpr % g 0 , R T R A P _ P S T A T E , % p s t a t e
wrpr % g 0 , R T R A P _ P S T A T E _ I R Q O F F , % p s t a t e
ldub [ % g 6 + T I _ W S A V E D ] , % o 2
brz,p t % o 2 , 1 f
nop
/* Redo userwin+sched+sig checks */
call f a u l t _ i n _ u s e r _ w i n d o w s
wrpr % g 0 , R T R A P _ P S T A T E , % p s t a t e
wrpr % g 0 , R T R A P _ P S T A T E _ I R Q O F F , % p s t a t e
ldx [ % g 6 + T I _ F L A G S ] , % l 0
andcc % l 0 , _ T I F _ N E E D _ R E S C H E D , % g 0
be,p t % x c c , 1 f
nop
call s c h e d u l e
wrpr % g 0 , R T R A P _ P S T A T E , % p s t a t e
wrpr % g 0 , R T R A P _ P S T A T E _ I R Q O F F , % p s t a t e
ldx [ % g 6 + T I _ F L A G S ] , % l 0
2006-01-19 13:42:49 +03:00
1 : andcc % l 0 , ( _ T I F _ S I G P E N D I N G | _ T I F _ R E S T O R E _ S I G M A S K ) , % g 0
2005-04-17 02:20:36 +04:00
be,p t % x c c , _ _ h a n d l e _ p e r f c t r s _ c o n t i n u e
sethi % h i ( T S T A T E _ P E F ) , % o 0
2006-01-19 13:42:49 +03:00
mov % l 5 , % o 1
mov % l 6 , % o 2
add % s p , P T R E G S _ O F F , % o 0
mov % l 0 , % o 3
2005-04-17 02:20:36 +04:00
call d o _ n o t i f y _ r e s u m e
wrpr % g 0 , R T R A P _ P S T A T E , % p s t a t e
wrpr % g 0 , R T R A P _ P S T A T E _ I R Q O F F , % p s t a t e
clr % l 6
/ * Signal d e l i v e r y c a n m o d i f y p t _ r e g s t s t a t e , s o w e m u s t
* reload i t .
* /
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ T S T A T E ] , % l 1
sethi % h i ( 0 x f < < 2 0 ) , % l 4
and % l 1 , % l 4 , % l 4
andn % l 1 , % l 4 , % l 1
ba,p t % x c c , _ _ h a n d l e _ p e r f c t r s _ c o n t i n u e
sethi % h i ( T S T A T E _ P E F ) , % o 0
__handle_userfpu :
rd % f p r s , % l 5
andcc % l 5 , F P R S _ F E F , % g 0
sethi % h i ( T S T A T E _ P E F ) , % o 0
be,a ,p n % i c c , _ _ h a n d l e _ u s e r f p u _ c o n t i n u e
andn % l 1 , % o 0 , % l 1
ba,a ,p t % x c c , _ _ h a n d l e _ u s e r f p u _ c o n t i n u e
__handle_signal :
2006-01-19 13:42:49 +03:00
mov % l 5 , % o 1
mov % l 6 , % o 2
add % s p , P T R E G S _ O F F , % o 0
mov % l 0 , % o 3
2005-04-17 02:20:36 +04:00
call d o _ n o t i f y _ r e s u m e
wrpr % g 0 , R T R A P _ P S T A T E , % p s t a t e
wrpr % g 0 , R T R A P _ P S T A T E _ I R Q O F F , % p s t a t e
clr % l 6
/ * Signal d e l i v e r y c a n m o d i f y p t _ r e g s t s t a t e , s o w e m u s t
* reload i t .
* /
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ T S T A T E ] , % l 1
sethi % h i ( 0 x f < < 2 0 ) , % l 4
and % l 1 , % l 4 , % l 4
ba,p t % x c c , _ _ h a n d l e _ s i g n a l _ c o n t i n u e
andn % l 1 , % l 4 , % l 1
.align 64
.globl rtrap_ i r q , r t r a p _ c l r _ l 6 , r t r a p , i r q s z _ p a t c h m e , r t r a p _ x c a l l
rtrap_irq :
rtrap_clr_l6 : clr % l 6
rtrap :
2005-08-30 09:46:43 +04:00
# ifndef C O N F I G _ S M P
sethi % h i ( p e r _ c p u _ _ _ _ c p u _ d a t a ) , % l 0
lduw [ % l 0 + % l o ( p e r _ c p u _ _ _ _ c p u _ d a t a ) ] , % l 1
# else
sethi % h i ( p e r _ c p u _ _ _ _ c p u _ d a t a ) , % l 0
or % l 0 , % l o ( p e r _ c p u _ _ _ _ c p u _ d a t a ) , % l 0
lduw [ % l 0 + % g 5 ] , % l 1
# endif
2005-04-17 02:20:36 +04:00
cmp % l 1 , 0
/* mm/ultra.S:xcall_report_regs KNOWS about this load. */
bne,p n % i c c , _ _ h a n d l e _ s o f t i r q
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ T S T A T E ] , % l 1
__handle_softirq_continue :
rtrap_xcall :
sethi % h i ( 0 x f < < 2 0 ) , % l 4
andcc % l 1 , T S T A T E _ P R I V , % l 3
and % l 1 , % l 4 , % l 4
bne,p n % i c c , t o _ k e r n e l
andn % l 1 , % l 4 , % l 1
/ * We m u s t h o l d I R Q s o f f a n d a t o m i c a l l y t e s t s c h e d u l e + s i g n a l
* state, t h e n h o l d t h e m o f f a l l t h e w a y b a c k t o u s e r s p a c e .
* If w e a r e r e t u r n i n g t o k e r n e l , n o n e o f t h i s m a t t e r s .
*
* If w e d o n o t d o t h i s , t h e r e i s a w i n d o w w h e r e w e w o u l d d o
* the t e s t s , l a t e r t h e s i g n a l / r e s c h e d e v e n t a r r i v e s b u t w e d o
* not p r o c e s s i t s i n c e w e a r e s t i l l i n k e r n e l m o d e . I t w o u l d
* take u n t i l t h e n e x t l o c a l I R Q b e f o r e t h e s i g n a l / r e s c h e d
* event w o u l d b e h a n d l e d .
*
* This a l s o m e a n s t h a t i f w e h a v e t o d e a l w i t h p e r f o r m a n c e
* counters o r u s e r w i n d o w s , w e h a v e t o r e d o a l l o f t h e s e
* sched+ s i g n a l c h e c k s w i t h I R Q s d i s a b l e d .
* /
to_user : wrpr % g 0 , R T R A P _ P S T A T E _ I R Q O F F , % p s t a t e
wrpr 0 , % p i l
__handle_preemption_continue :
ldx [ % g 6 + T I _ F L A G S ] , % l 0
sethi % h i ( _ T I F _ U S E R _ W O R K _ M A S K ) , % o 0
or % o 0 , % l o ( _ T I F _ U S E R _ W O R K _ M A S K ) , % o 0
andcc % l 0 , % o 0 , % g 0
sethi % h i ( T S T A T E _ P E F ) , % o 0
be,p t % x c c , u s e r _ n o w o r k
andcc % l 1 , % o 0 , % g 0
andcc % l 0 , _ T I F _ N E E D _ R E S C H E D , % g 0
bne,p n % x c c , _ _ h a n d l e _ p r e e m p t i o n
2006-01-19 13:42:49 +03:00
andcc % l 0 , ( _ T I F _ S I G P E N D I N G | _ T I F _ R E S T O R E _ S I G M A S K ) , % g 0
2005-04-17 02:20:36 +04:00
bne,p n % x c c , _ _ h a n d l e _ s i g n a l
__handle_signal_continue :
ldub [ % g 6 + T I _ W S A V E D ] , % o 2
brnz,p n % o 2 , _ _ h a n d l e _ u s e r _ w i n d o w s
nop
__handle_user_windows_continue :
ldx [ % g 6 + T I _ F L A G S ] , % l 5
andcc % l 5 , _ T I F _ P E R F C T R , % g 0
sethi % h i ( T S T A T E _ P E F ) , % o 0
bne,p n % x c c , _ _ h a n d l e _ p e r f c t r s
__handle_perfctrs_continue :
andcc % l 1 , % o 0 , % g 0
/* This fpdepth clear is necessary for non-syscall rtraps only */
user_nowork :
bne,p n % x c c , _ _ h a n d l e _ u s e r f p u
stb % g 0 , [ % g 6 + T I _ F P D E P T H ]
__handle_userfpu_continue :
rt_continue : ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ G 1 ] , % g 1
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ G 2 ] , % g 2
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ G 3 ] , % g 3
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ G 4 ] , % g 4
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ G 5 ] , % g 5
2006-02-27 10:24:22 +03:00
brz,p t % l 3 , 1 f
2006-02-06 08:59:03 +03:00
mov % g 6 , % l 2
2006-02-27 10:24:22 +03:00
/* Must do this before thread reg is clobbered below. */
2006-02-03 08:55:10 +03:00
LOAD_ P E R _ C P U _ B A S E ( % g 5 , % g 6 , % i 0 , % i 1 , % i 2 )
2006-02-01 05:29:18 +03:00
1 :
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ G 6 ] , % g 6
2005-04-17 02:20:36 +04:00
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ G 7 ] , % g 7
2006-02-06 08:29:28 +03:00
/* Normal globals are restored, go to trap globals. */
661 : wrpr % g 0 , R T R A P _ P S T A T E _ A G _ I R Q O F F , % p s t a t e
.section .gl_1insn_patch , " ax"
.word 661b
SET_ G L ( 1 )
.previous
2006-02-06 08:59:03 +03:00
mov % l 2 , % g 6
2005-04-17 02:20:36 +04:00
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 0 ] , % i 0
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 1 ] , % i 1
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 2 ] , % i 2
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 3 ] , % i 3
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 4 ] , % i 4
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 5 ] , % i 5
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 6 ] , % i 6
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 7 ] , % i 7
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ T P C ] , % l 2
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ T N P C ] , % o 2
ld [ % s p + P T R E G S _ O F F + P T _ V 9 _ Y ] , % o 3
wr % o 3 , % g 0 , % y
srl % l 4 , 2 0 , % l 4
wrpr % l 4 , 0 x0 , % p i l
wrpr % g 0 , 0 x1 , % t l
wrpr % l 1 , % g 0 , % t s t a t e
wrpr % l 2 , % g 0 , % t p c
wrpr % o 2 , % g 0 , % t n p c
brnz,p n % l 3 , k e r n _ r t t
mov P R I M A R Y _ C O N T E X T , % l 7
ldxa [ % l 7 + % l 7 ] A S I _ D M M U , % l 0
2005-10-05 02:23:20 +04:00
sethi % h i ( s p a r c64 _ k e r n _ p r i _ n u c _ b i t s ) , % l 1
ldx [ % l 1 + % l o ( s p a r c64 _ k e r n _ p r i _ n u c _ b i t s ) ] , % l 1
2005-04-17 02:20:36 +04:00
or % l 0 , % l 1 , % l 0
stxa % l 0 , [ % l 7 ] A S I _ D M M U
2006-02-01 05:33:00 +03:00
sethi % h i ( K E R N B A S E ) , % l 7
flush % l 7
2005-04-17 02:20:36 +04:00
rdpr % w s t a t e , % l 1
rdpr % o t h e r w i n , % l 2
srl % l 1 , 3 , % l 1
wrpr % l 2 , % g 0 , % c a n r e s t o r e
wrpr % l 1 , % g 0 , % w s t a t e
2006-02-04 11:10:01 +03:00
brnz,p t % l 2 , u s e r _ r t t _ r e s t o r e
wrpr % g 0 , % g 0 , % o t h e r w i n
ldx [ % g 6 + T I _ F L A G S ] , % g 3
wr % g 0 , A S I _ A I U P , % a s i
rdpr % c w p , % g 1
andcc % g 3 , _ T I F _ 3 2 B I T , % g 0
sub % g 1 , 1 , % g 1
bne,p t % x c c , u s e r _ r t t _ f i l l _ 3 2 b i t
wrpr % g 1 , % c w p
ba,a ,p t % x c c , u s e r _ r t t _ f i l l _ 6 4 b i t
user_rtt_fill_fixup :
rdpr % c w p , % g 1
add % g 1 , 1 , % g 1
wrpr % g 1 , 0 x0 , % c w p
rdpr % w s t a t e , % g 2
sll % g 2 , 3 , % g 2
wrpr % g 2 , 0 x0 , % w s t a t e
/* We know %canrestore and %otherwin are both zero. */
sethi % h i ( s p a r c64 _ k e r n _ p r i _ c o n t e x t ) , % g 2
ldx [ % g 2 + % l o ( s p a r c64 _ k e r n _ p r i _ c o n t e x t ) ] , % g 2
mov P R I M A R Y _ C O N T E X T , % g 1
stxa % g 2 , [ % g 1 ] A S I _ D M M U
sethi % h i ( K E R N B A S E ) , % g 1
flush % g 1
or % g 4 , F A U L T _ C O D E _ W I N F I X U P , % g 4
stb % g 4 , [ % g 6 + T I _ F A U L T _ C O D E ]
stx % g 5 , [ % g 6 + T I _ F A U L T _ A D D R ]
mov % g 6 , % l 1
wrpr % g 0 , 0 x0 , % t l
wrpr % g 0 , R T R A P _ P S T A T E , % p s t a t e
2006-02-06 08:29:28 +03:00
661 : nop
.section .gl_1insn_patch , " ax"
.word 661b
SET_ G L ( 0 )
.previous
2006-02-04 11:10:01 +03:00
mov % l 1 , % g 6
ldx [ % g 6 + T I _ T A S K ] , % g 4
LOAD_ P E R _ C P U _ B A S E ( % g 5 , % g 6 , % g 1 , % g 2 , % g 3 )
call d o _ s p a r c64 _ f a u l t
add % s p , P T R E G S _ O F F , % o 0
ba,p t % x c c , r t r a p
nop
user_rtt_pre_restore :
add % g 1 , 1 , % g 1
wrpr % g 1 , 0 x0 , % c w p
user_rtt_restore :
2005-04-17 02:20:36 +04:00
restore
rdpr % c a n r e s t o r e , % g 1
wrpr % g 1 , 0 x0 , % c l e a n w i n
retry
nop
2006-02-04 11:10:01 +03:00
kern_rtt : rdpr % c a n r e s t o r e , % g 1
brz,p n % g 1 , k e r n _ r t t _ f i l l
nop
kern_rtt_restore :
restore
2005-04-17 02:20:36 +04:00
retry
2006-02-04 11:10:01 +03:00
2005-04-17 02:20:36 +04:00
to_kernel :
# ifdef C O N F I G _ P R E E M P T
ldsw [ % g 6 + T I _ P R E _ C O U N T ] , % l 5
brnz % l 5 , k e r n _ f p u c h e c k
ldx [ % g 6 + T I _ F L A G S ] , % l 5
andcc % l 5 , _ T I F _ N E E D _ R E S C H E D , % g 0
be,p t % x c c , k e r n _ f p u c h e c k
srl % l 4 , 2 0 , % l 5
cmp % l 5 , 0
bne,p n % x c c , k e r n _ f p u c h e c k
sethi % h i ( P R E E M P T _ A C T I V E ) , % l 6
stw % l 6 , [ % g 6 + T I _ P R E _ C O U N T ]
call s c h e d u l e
nop
ba,p t % x c c , r t r a p
stw % g 0 , [ % g 6 + T I _ P R E _ C O U N T ]
# endif
kern_fpucheck : ldub [ % g 6 + T I _ F P D E P T H ] , % l 5
brz,p t % l 5 , r t _ c o n t i n u e
srl % l 5 , 1 , % o 0
add % g 6 , T I _ F P S A V E D , % l 6
ldub [ % l 6 + % o 0 ] , % l 2
sub % l 5 , 2 , % l 5
add % g 6 , T I _ G S R , % o 1
andcc % l 2 , ( F P R S _ F E F | F P R S _ D U ) , % g 0
be,p t % i c c , 2 f
and % l 2 , F P R S _ D L , % l 6
andcc % l 2 , F P R S _ F E F , % g 0
be,p n % i c c , 5 f
sll % o 0 , 3 , % o 5
rd % f p r s , % g 1
wr % g 1 , F P R S _ F E F , % f p r s
ldx [ % o 1 + % o 5 ] , % g 1
add % g 6 , T I _ X F S R , % o 1
sll % o 0 , 8 , % o 2
add % g 6 , T I _ F P R E G S , % o 3
brz,p n % l 6 , 1 f
add % g 6 , T I _ F P R E G S + 0 x40 , % o 4
2005-10-08 00:30:49 +04:00
membar #S y n c
2005-04-17 02:20:36 +04:00
ldda [ % o 3 + % o 2 ] A S I _ B L K _ P , % f0
ldda [ % o 4 + % o 2 ] A S I _ B L K _ P , % f16
2005-10-08 00:30:49 +04:00
membar #S y n c
2005-04-17 02:20:36 +04:00
1 : andcc % l 2 , F P R S _ D U , % g 0
be,p n % i c c , 1 f
wr % g 1 , 0 , % g s r
add % o 2 , 0 x80 , % o 2
2005-10-08 00:30:49 +04:00
membar #S y n c
2005-04-17 02:20:36 +04:00
ldda [ % o 3 + % o 2 ] A S I _ B L K _ P , % f32
ldda [ % o 4 + % o 2 ] A S I _ B L K _ P , % f48
1 : membar #S y n c
ldx [ % o 1 + % o 5 ] , % f s r
2 : stb % l 5 , [ % g 6 + T I _ F P D E P T H ]
ba,p t % x c c , r t _ c o n t i n u e
nop
5 : wr % g 0 , F P R S _ F E F , % f p r s
sll % o 0 , 8 , % o 2
add % g 6 , T I _ F P R E G S + 0 x80 , % o 3
add % g 6 , T I _ F P R E G S + 0 x c0 , % o 4
2005-10-08 00:30:49 +04:00
membar #S y n c
2005-04-17 02:20:36 +04:00
ldda [ % o 3 + % o 2 ] A S I _ B L K _ P , % f32
ldda [ % o 4 + % o 2 ] A S I _ B L K _ P , % f48
membar #S y n c
wr % g 0 , F P R S _ D U , % f p r s
ba,p t % x c c , r t _ c o n t i n u e
stb % l 5 , [ % g 6 + T I _ F P D E P T H ]