2006-04-05 12:45:45 +04:00
/ *
* Assembly L a n g u a g e F u n c t i o n s f o r M I P S M T S M T C s u p p o r t
* /
/ *
* This f i l e s h o u l d b e b u i l t i n t o t h e k e r n e l o n l y i f C O N F I G _ M I P S _ M T _ S M T C i s s e t . * /
# include < a s m / r e g d e f . h >
# include < a s m / a s m m a c r o . h >
# include < a s m / s t a c k f r a m e . h >
2006-08-16 17:05:11 +04:00
# include < a s m / i r q f l a g s . h >
2006-04-05 12:45:45 +04:00
/ *
* " Software I n t e r r u p t " l i n k a g e .
*
* This i s i n v o k e d w h e n a n " I n t e r r u p t " i s s e n t f r o m o n e T C t o a n o t h e r ,
* where t h e T C t o b e i n t e r r u p t e d i s h a l t e d , h a s i t ' s R e s t a r t a d d r e s s
* and S t a t u s v a l u e s s a v e d b y t h e " r e m o t e c o n t r o l " t h r e a d , t h e n m o d i f i e d
* to c a u s e e x e c u t i o n t o b e g i n h e r e , i n k e n e l m o d e . T h i s c o d e t h e n
* disguises t h e T C s t a t e a s t h a t o f a n e x c e p t i o n a n d t r a n s f e r s
* control t o t h e g e n e r a l e x c e p t i o n o r v e c t o r e d i n t e r r u p t h a n d l e r .
* /
.set noreorder
/ *
The _ _ s m t c _ i p i _ v e c t o r w o u l d u s e k 0 a n d k 1 a s t e m p o r a r i e s a n d
1 ) Set E X L ( t h i s i s p e r - V P E , s o t h i s c a n ' t b e d o n e b y p r o x y ! )
2 ) Restore t h e K / C U a n d I X M T b i t s t o t h e p r e " e x c e p t i o n " s t a t e
( EXL m e a n s n o i n t e r r u p t s a n d a c c e s s t o t h e k e r n e l m a p ) .
3 ) Set E P C t o b e t h e s a v e d v a l u e o f T C R e s t a r t .
4 ) Jump t o t h e e x c e p t i o n h a n d l e r e n t r y p o i n t p a s s e d b y t h e s e n d e r .
CAN W E P R O V E T H A T W E W O N ' T D O T H I S I F I N T S D I S A B L E D ? ?
* /
/ *
* Reviled a n d s l a n d e r e d v i s i o n : S e t E X L a n d r e s t o r e K / C U / I X M T
* state o f p r e - h a l t t h r e a d , t h e n s a v e e v e r y t h i n g a n d c a l l
* thought s o m e f u n c t i o n p o i n t e r t o i m a g i n a r y _ e x c e p t i o n , w h i c h
* will p a r s e a r e g i s t e r v a l u e o r m e m o r y m e s s a g e q u e u e t o
* deliver t h i n g s l i k e i n t e r p r o c e s s o r i n t e r r u p t s . O n r e t u r n
* from t h a t f u n c t i o n , j u m p t o t h e g l o b a l r e t _ f r o m _ i r q c o d e
* to i n v o k e t h e s c h e d u l e r a n d r e t u r n a s a p p r o p r i a t e .
* /
# define P T _ P A D S L O T 4 ( P T _ R 0 - 8 )
# define P T _ P A D S L O T 5 ( P T _ R 0 - 4 )
.text
.align 5
FEXPORT( _ _ s m t c _ i p i _ v e c t o r )
.set noat
/* Disable thread scheduling to make Status update atomic */
DMT 2 7 # d m t k 1
2006-06-04 01:40:15 +04:00
_ ehb
2006-04-05 12:45:45 +04:00
/* Set EXL */
mfc0 k 0 ,C P 0 _ S T A T U S
ori k 0 ,k 0 ,S T 0 _ E X L
mtc0 k 0 ,C P 0 _ S T A T U S
2006-06-04 01:40:15 +04:00
_ ehb
2006-04-05 12:45:45 +04:00
/* Thread scheduling now inhibited by EXL. Restore TE state. */
andi k 1 ,k 1 ,V P E C O N T R O L _ T E
beqz k 1 ,1 f
emt
1 :
/ *
* The I P I s e n d e r h a s p u t s o m e i n f o r m a t i o n o n t h e a n t i c i p a t e d
* kernel s t a c k f r a m e . I f w e w e r e i n u s e r m o d e , t h i s w i l l b e
* built a b o v e t h e s a v e d k e r n e l S P . I f w e w e r e a l r e a d y i n t h e
* kernel, i t w i l l b e b u i l t a b o v e t h e c u r r e n t C P U S P .
*
* Were w e i n k e r n e l m o d e , a s i n d i c a t e d b y C U 0 ?
* /
sll k 1 ,k 0 ,3
.set noreorder
bltz k 1 ,2 f
move k 1 ,s p
.set reorder
/ *
* If p r e v i o u s l y i n u s e r m o d e , s e t C U 0 a n d u s e k e r n e l s t a c k .
* /
li k 1 ,S T 0 _ C U 0
or k 1 ,k 1 ,k 0
mtc0 k 1 ,C P 0 _ S T A T U S
2006-06-04 01:40:15 +04:00
_ ehb
2006-04-05 12:45:45 +04:00
get_ s a v e d _ s p
/* Interrupting TC will have pre-set values in slots in the new frame */
2 : subu k 1 ,k 1 ,P T _ S I Z E
/* Load TCStatus Value */
lw k 0 ,P T _ T C S T A T U S ( k 1 )
/* Write it to TCStatus to restore CU/KSU/IXMT state */
mtc0 k 0 ,$ 2 ,1
2006-06-04 01:40:15 +04:00
_ ehb
2006-04-05 12:45:45 +04:00
lw k 0 ,P T _ E P C ( k 1 )
mtc0 k 0 ,C P 0 _ E P C
/* Save all will redundantly recompute the SP, but use it for now */
SAVE_ A L L
CLI
2006-07-07 17:07:18 +04:00
TRACE_ I R Q S _ O F F
2006-04-05 12:45:45 +04:00
/* Function to be invoked passed stack pad slot 5 */
lw t 0 ,P T _ P A D S L O T 5 ( s p )
/* Argument from sender passed in stack pad slot 4 */
2006-10-08 20:24:23 +04:00
lw a0 ,P T _ P A D S L O T 4 ( s p )
2006-11-01 01:49:04 +03:00
LONG_ L s0 , T I _ R E G S ( $ 2 8 )
LONG_ S s p , T I _ R E G S ( $ 2 8 )
PTR_ L A r a , r e t _ f r o m _ i r q
2006-10-08 20:24:23 +04:00
jr t 0
2006-04-05 12:45:45 +04:00
/ *
* Called f r o m i d l e l o o p t o p r o v o k e p r o c e s s i n g o f q u e u e d I P I s
* First I P I m e s s a g e i n q u e u e p a s s e d a s a r g u m e n t .
* /
LEAF( s e l f _ i p i )
/* Before anything else, block interrupts */
mfc0 t 0 ,C P 0 _ T C S T A T U S
ori t 1 ,t 0 ,T C S T A T U S _ I X M T
mtc0 t 1 ,C P 0 _ T C S T A T U S
2006-06-04 01:40:15 +04:00
_ ehb
2006-04-05 12:45:45 +04:00
/* We know we're in kernel mode, so prepare stack frame */
subu t 1 ,s p ,P T _ S I Z E
sw r a ,P T _ E P C ( t 1 )
sw a0 ,P T _ P A D S L O T 4 ( t 1 )
la t 2 ,i p i _ d e c o d e
sw t 2 ,P T _ P A D S L O T 5 ( t 1 )
/* Save pre-disable value of TCStatus */
sw t 0 ,P T _ T C S T A T U S ( t 1 )
j _ _ s m t c _ i p i _ v e c t o r
nop
END( s e l f _ i p i )