2011-05-04 14:38:26 -04:00
/ *
* Copyright 2 0 1 1 T i l e r a C o r p o r a t i o n . A l l R i g h t s R e s e r v e d .
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or
* modify i t u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* as p u b l i s h e d b y t h e F r e e S o f t w a r e F o u n d a t i o n , v e r s i o n 2 .
*
* This p r o g r a m i s d i s t r i b u t e d i n t h e h o p e t h a t i t w i l l b e u s e f u l , b u t
* WITHOUT A N Y W A R R A N T Y ; without even the implied warranty of
* MERCHANTABILITY O R F I T N E S S F O R A P A R T I C U L A R P U R P O S E , G O O D T I T L E o r
* NON I N F R I N G E M E N T . S e e t h e G N U G e n e r a l P u b l i c L i c e n s e f o r
* more d e t a i l s .
*
* This r o u t i n e i s a h e l p e r f o r m i g r a t i n g t h e h o m e o f a s e t o f p a g e s t o
* a n e w c p u . S e e t h e d o c u m e n t a t i o n i n h o m e c a c h e . c f o r m o r e i n f o r m a t i o n .
* /
# include < l i n u x / l i n k a g e . h >
# include < l i n u x / t h r e a d s . h >
# include < a s m / p a g e . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / t y p e s . h >
# include < a s m / a s m - o f f s e t s . h >
# include < h v / h y p e r v i s o r . h >
.text
/ *
* First, s o m e d e f i n i t i o n s t h a t a p p l y t o a l l t h e c o d e i n t h e f i l e .
* /
/* Locals (caller-save) */
# define r _ t m p r10
# define r _ s a v e _ s p r11
/* What we save where in the stack frame; must include all callee-saves. */
# define F R A M E _ S P 8
# define F R A M E _ R 3 0 1 6
# define F R A M E _ R 3 1 2 4
# define F R A M E _ R 3 2 3 2
2012-03-27 15:40:20 -04:00
# define F R A M E _ S I Z E 4 0
2011-05-04 14:38:26 -04:00
/ *
* On e n t r y :
*
* r0 t h e n e w c o n t e x t P A t o i n s t a l l ( m o v e d t o r _ c o n t e x t )
* r1 P T E t o u s e f o r c o n t e x t a c c e s s ( m o v e d t o r _ a c c e s s )
* r2 A S I D t o u s e f o r n e w c o n t e x t ( m o v e d t o r _ a s i d )
* r3 p o i n t e r t o c p u m a s k w i t h j u s t t h i s c p u s e t i n i t ( r _ m y _ c p u m a s k )
* /
/* Arguments (caller-save) */
# define r _ c o n t e x t _ i n r0
# define r _ a c c e s s _ i n r1
# define r _ a s i d _ i n r2
# define r _ m y _ c p u m a s k r3
/* Locals (callee-save); must not be more than FRAME_xxx above. */
2012-03-27 15:40:20 -04:00
# define r _ c o n t e x t r30
# define r _ a c c e s s r31
# define r _ a s i d r32
2011-05-04 14:38:26 -04:00
/ *
* Caller- s a v e l o c a l s a n d f r a m e c o n s t a n t s a r e t h e s a m e a s
* for h o m e c a c h e _ m i g r a t e _ s t a c k _ a n d _ f l u s h .
* /
STD_ E N T R Y ( f l u s h _ a n d _ i n s t a l l _ c o n t e x t )
/ *
* Create a s t a c k f r a m e ; we can't touch it once we flush the
* cache u n t i l w e i n s t a l l t h e n e w p a g e t a b l e a n d f l u s h t h e T L B .
* /
{
move r _ s a v e _ s p , s p
st s p , l r
addi s p , s p , - F R A M E _ S I Z E
}
addi r _ t m p , s p , F R A M E _ S P
{
st r _ t m p , r _ s a v e _ s p
addi r _ t m p , s p , F R A M E _ R 3 0
}
{
st r _ t m p , r30
addi r _ t m p , s p , F R A M E _ R 3 1
}
{
st r _ t m p , r31
addi r _ t m p , s p , F R A M E _ R 3 2
}
2012-03-27 15:40:20 -04:00
st r _ t m p , r32
2011-05-04 14:38:26 -04:00
/* Move some arguments to callee-save registers. */
{
move r _ c o n t e x t , r _ c o n t e x t _ i n
move r _ a c c e s s , r _ a c c e s s _ i n
}
move r _ a s i d , r _ a s i d _ i n
/* First, flush our L2 cache. */
{
move r0 , z e r o / * c a c h e _ p a * /
moveli r1 , h w2 _ l a s t ( H V _ F L U S H _ E V I C T _ L 2 ) / * c a c h e _ c o n t r o l * /
}
{
shl1 6 i n s l i r1 , r1 , h w1 ( H V _ F L U S H _ E V I C T _ L 2 )
move r2 , r _ m y _ c p u m a s k / * c a c h e _ c p u m a s k * /
}
{
shl1 6 i n s l i r1 , r1 , h w0 ( H V _ F L U S H _ E V I C T _ L 2 )
move r3 , z e r o / * t l b _ v a * /
}
{
move r4 , z e r o / * t l b _ l e n g t h * /
move r5 , z e r o / * t l b _ p g s i z e * /
}
{
move r6 , z e r o / * t l b _ c p u m a s k * /
move r7 , z e r o / * a s i d s * /
}
{
move r8 , z e r o / * a s i d c o u n t * /
2013-08-07 16:03:08 -04:00
jal _ h v _ f l u s h _ r e m o t e
2011-05-04 14:38:26 -04:00
}
bnez r0 , 1 f
/* Now install the new page table. */
{
move r0 , r _ c o n t e x t
move r1 , r _ a c c e s s
}
{
move r2 , r _ a s i d
2012-03-27 15:40:20 -04:00
moveli r3 , H V _ C T X _ D I R E C T I O | C T X _ P A G E _ F L A G
2011-05-04 14:38:26 -04:00
}
2013-08-07 16:03:08 -04:00
jal _ h v _ i n s t a l l _ c o n t e x t
2011-05-04 14:38:26 -04:00
bnez r0 , 1 f
/* Finally, flush the TLB. */
{
movei r0 , 0 / * p r e s e r v e _ g l o b a l * /
jal h v _ f l u s h _ a l l
}
2012-03-27 15:40:20 -04:00
1 : /* Restore the callee-saved registers and return. */
2011-05-04 14:38:26 -04:00
addli l r , s p , F R A M E _ S I Z E
{
ld l r , l r
addli r _ t m p , s p , F R A M E _ R 3 0
}
{
ld r30 , r _ t m p
addli r _ t m p , s p , F R A M E _ R 3 1
}
{
ld r31 , r _ t m p
addli r _ t m p , s p , F R A M E _ R 3 2
}
{
ld r32 , r _ t m p
addi s p , s p , F R A M E _ S I Z E
}
jrp l r
STD_ E N D P R O C ( f l u s h _ a n d _ i n s t a l l _ c o n t e x t )