2010-05-29 07:09:12 +04:00
/ *
2012-03-29 23:48:23 +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 .
2010-05-29 07:09:12 +04:00
*
* 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 .
*
* copy n e w k e r n e l i n t o p l a c e a n d t h e n c a l l h v _ r e e x e c
*
* /
# include < l i n u x / l i n k a g e . h >
# include < a r c h / c h i p . h >
# include < a s m / p a g e . h >
# include < h v / h y p e r v i s o r . h >
# undef R E L O C A T E _ N E W _ K E R N E L _ V E R B O S E
STD_ E N T R Y ( r e l o c a t e _ n e w _ k e r n e l )
move r30 , r0 / * p a g e l i s t * /
move r31 , r1 / * a d d r e s s o f p a g e w e a r e o n * /
move r32 , r2 / * s t a r t a d d r e s s o f n e w k e r n e l * /
2012-03-29 23:48:23 +04:00
shrui r1 , r1 , P A G E _ S H I F T
2010-05-29 07:09:12 +04:00
addi r1 , r1 , 1
shli s p , r1 , P A G E _ S H I F T
addi s p , s p , - 8
/* we now have a stack (whether we need one or not) */
2013-09-03 22:13:31 +04:00
# ifdef R E L O C A T E _ N E W _ K E R N E L _ V E R B O S E
2012-03-29 23:48:23 +04:00
moveli r40 , h w2 _ l a s t ( h v _ c o n s o l e _ p u t c )
shl1 6 i n s l i r40 , r40 , h w1 ( h v _ c o n s o l e _ p u t c )
shl1 6 i n s l i r40 , r40 , h w0 ( h v _ c o n s o l e _ p u t c )
2010-05-29 07:09:12 +04:00
moveli r0 , ' r '
jalr r40
moveli r0 , ' _ '
jalr r40
moveli r0 , ' n '
jalr r40
moveli r0 , ' _ '
jalr r40
moveli r0 , ' k '
jalr r40
moveli r0 , ' \ n '
jalr r40
# endif
/ *
* Throughout t h i s c o d e r30 i s p o i n t e r t o t h e e l e m e n t o f p a g e
* list w e a r e w o r k i n g o n .
*
* Normally w e g e t t o t h e n e x t e l e m e n t o f t h e p a g e l i s t b y
2012-03-29 23:48:23 +04:00
* incrementing r30 b y e i g h t . T h e e x c e p t i o n i s i f t h e e l e m e n t
2010-05-29 07:09:12 +04:00
* on t h e p a g e l i s t i s a n I N D _ I N D I R E C T I O N i n w h i c h c a s e w e u s e
* the e l e m e n t w i t h t h e l o w b i t s m a s k e d o f f a s t h e n e w v a l u e
* of r30 .
*
* To g e t t h i s s t a r t e d , w e n e e d t h e v a l u e p a s s e d t o u s ( w h i c h
* will a l w a y s b e a n I N D _ I N D I R E C T I O N ) i n m e m o r y s o m e w h e r e w i t h
* r3 0 p o i n t i n g a t i t . T o d o t h a t , w e p u s h t h e v a l u e p a s s e d
* to u s o n t h e s t a c k a n d m a k e r30 p o i n t t o i t .
* /
2012-03-29 23:48:23 +04:00
st s p , r30
2010-05-29 07:09:12 +04:00
move r30 , s p
2012-03-29 23:48:23 +04:00
addi s p , s p , - 1 6
2010-05-29 07:09:12 +04:00
/ *
2012-03-29 23:48:23 +04:00
* On T I L E - G X , w e n e e d t o f l u s h a l l t i l e s ' c a c h e s , s i n c e w e m a y
2010-05-29 07:09:12 +04:00
* have b e e n d o i n g h a s h - f o r - h o m e c a c h i n g t h e r e . N o t e t h a t w e
* must d o t h i s _ a f t e r _ w e ' r e c o m p l e t e l y d o n e m o d i f y i n g a n y m e m o r y
* other t h a n o u r o u t p u t b u f f e r ( w h i c h w e k n o w i s l o c a l l y c a c h e d ) .
* We w a n t t h e c a c h e s t o b e f u l l y c l e a n w h e n w e d o t h e r e e x e c ,
* because t h e h y p e r v i s o r i s g o i n g t o d o t h i s f l u s h a g a i n a t t h a t
* point, a n d w e d o n ' t w a n t t h a t s e c o n d f l u s h t o o v e r w r i t e a n y m e m o r y .
* /
{
move r0 , z e r o / * c a c h e _ p a * /
2012-03-29 23:48:23 +04:00
moveli r1 , h w2 _ l a s t ( H V _ F L U S H _ E V I C T _ L 2 )
2010-05-29 07:09:12 +04:00
}
{
2012-03-29 23:48:23 +04:00
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 )
movei r2 , - 1 / * c a c h e _ c p u m a s k ; -1 means all client tiles */
2010-05-29 07:09:12 +04:00
}
{
2012-03-29 23:48:23 +04:00
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 ) / * c a c h e _ c o n t r o l * /
move r3 , z e r o / * t l b _ v a * /
2010-05-29 07:09:12 +04:00
}
{
2012-03-29 23:48:23 +04:00
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 * /
2010-05-29 07:09:12 +04:00
}
{
2012-03-29 23:48:23 +04:00
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 * /
2010-05-29 07:09:12 +04:00
}
{
2012-03-29 23:48:23 +04:00
moveli r20 , h w2 _ l a s t ( h v _ f l u s h _ r e m o t e )
move r8 , z e r o / * a s i d c o u n t * /
2010-05-29 07:09:12 +04:00
}
2012-03-29 23:48:23 +04:00
shl1 6 i n s l i r20 , r20 , h w1 ( h v _ f l u s h _ r e m o t e )
shl1 6 i n s l i r20 , r20 , h w0 ( h v _ f l u s h _ r e m o t e )
2010-05-29 07:09:12 +04:00
jalr r20
/* r33 is destination pointer, default to zero */
moveli r33 , 0
2012-03-29 23:48:23 +04:00
.Lloop : ld r10 , r30
2010-05-29 07:09:12 +04:00
andi r9 , r10 , 0 x f / * l o w 4 b i t s t e l l u s w h a t t y p e i t i s * /
xor r10 , r10 , r9 / * r10 i s n o w v a l u e w i t h l o w 4 b i t s s t r i p p e d * /
2012-03-29 23:48:23 +04:00
cmpeqi r0 , r9 , 0 x1 / * I N D _ D E S T I N A T I O N * /
beqzt r0 , . L t r y 2
2010-05-29 07:09:12 +04:00
move r33 , r10
# ifdef R E L O C A T E _ N E W _ K E R N E L _ V E R B O S E
moveli r0 , ' d '
jalr r40
# endif
2012-03-29 23:48:23 +04:00
addi r30 , r30 , 8
2010-05-29 07:09:12 +04:00
j . L l o o p
.Ltry2 :
2012-03-29 23:48:23 +04:00
cmpeqi r0 , r9 , 0 x2 / * I N D _ I N D I R E C T I O N * /
beqzt r0 , . L t r y 4
2010-05-29 07:09:12 +04:00
move r30 , r10
# ifdef R E L O C A T E _ N E W _ K E R N E L _ V E R B O S E
moveli r0 , ' i '
jalr r40
# endif
j . L l o o p
.Ltry4 :
2012-03-29 23:48:23 +04:00
cmpeqi r0 , r9 , 0 x4 / * I N D _ D O N E * /
beqzt r0 , . L t r y 8
2010-05-29 07:09:12 +04:00
mf
# ifdef R E L O C A T E _ N E W _ K E R N E L _ V E R B O S E
moveli r0 , ' D '
jalr r40
moveli r0 , ' \ n '
jalr r40
# endif
move r0 , r32
2012-03-29 23:48:23 +04:00
moveli r41 , h w2 _ l a s t ( h v _ r e e x e c )
shl1 6 i n s l i r41 , r41 , h w1 ( h v _ r e e x e c )
shl1 6 i n s l i r41 , r41 , h w0 ( h v _ r e e x e c )
2010-05-29 07:09:12 +04:00
jalr r41
/* we should not get here */
2013-09-03 22:13:31 +04:00
# ifdef R E L O C A T E _ N E W _ K E R N E L _ V E R B O S E
2010-05-29 07:09:12 +04:00
moveli r0 , ' ? '
jalr r40
moveli r0 , ' \ n '
jalr r40
2013-09-03 22:13:31 +04:00
# endif
2010-05-29 07:09:12 +04:00
j . L h a l t
2012-03-29 23:48:23 +04:00
.Ltry8 : cmpeqi r0 , r9 , 0 x8 / * I N D _ S O U R C E * /
beqz r0 , . L e r r / * u n k n o w n t y p e * /
2010-05-29 07:09:12 +04:00
/* copy page at r10 to page at r33 */
move r11 , r33
2012-03-29 23:48:23 +04:00
moveli r0 , h w2 _ l a s t ( P A G E _ S I Z E )
shl1 6 i n s l i r0 , r0 , h w1 ( P A G E _ S I Z E )
shl1 6 i n s l i r0 , r0 , h w0 ( P A G E _ S I Z E )
2010-05-29 07:09:12 +04:00
add r33 , r33 , r0
/* copy word at r10 to word at r11 until r11 equals r33 */
2012-03-29 23:48:23 +04:00
/ * We k n o w p a g e s i z e m u s t b e m u l t i p l e o f 8 , s o w e c a n u n r o l l
* 8 times s a f e l y w i t h o u t a n y e d g e c a s e c h e c k i n g .
2010-05-29 07:09:12 +04:00
*
2012-03-29 23:48:23 +04:00
* Issue a f l u s h o f t h e d e s t i n a t i o n e v e r y 8 w o r d s t o a v o i d
2010-05-29 07:09:12 +04:00
* incoherence w h e n s t a r t i n g t h e n e w k e r n e l . ( N o w t h i s i s
* just g o o d p a r a n o i a b e c a u s e t h e h v _ r e e x e c c a l l w i l l a l s o
* take c a r e o f t h i s . )
* /
1 :
2012-03-29 23:48:23 +04:00
{ ld r0 , r10 ; addi r10, r10, 8 }
{ st r11 , r0 ; addi r11, r11, 8 }
{ ld r0 , r10 ; addi r10, r10, 8 }
{ st r11 , r0 ; addi r11, r11, 8 }
{ ld r0 , r10 ; addi r10, r10, 8 }
{ st r11 , r0 ; addi r11, r11, 8 }
{ ld r0 , r10 ; addi r10, r10, 8 }
{ st r11 , r0 ; addi r11, r11, 8 }
{ ld r0 , r10 ; addi r10, r10, 8 }
{ st r11 , r0 ; addi r11, r11, 8 }
{ ld r0 , r10 ; addi r10, r10, 8 }
{ st r11 , r0 ; addi r11, r11, 8 }
{ ld r0 , r10 ; addi r10, r10, 8 }
{ st r11 , r0 ; addi r11, r11, 8 }
{ ld r0 , r10 ; addi r10, r10, 8 }
{ st r11 , r0 }
{ flush r11 ; addi r11, r11, 8 }
cmpeq r0 , r33 , r11
beqzt r0 , 1 b
2010-05-29 07:09:12 +04:00
# ifdef R E L O C A T E _ N E W _ K E R N E L _ V E R B O S E
moveli r0 , ' s '
jalr r40
# endif
2012-03-29 23:48:23 +04:00
addi r30 , r30 , 8
2010-05-29 07:09:12 +04:00
j . L l o o p
2013-09-03 22:13:31 +04:00
.Lerr :
# ifdef R E L O C A T E _ N E W _ K E R N E L _ V E R B O S E
moveli r0 , ' e '
2010-05-29 07:09:12 +04:00
jalr r40
moveli r0 , ' r '
jalr r40
moveli r0 , ' r '
jalr r40
moveli r0 , ' \ n '
jalr r40
2013-09-03 22:13:31 +04:00
# endif
2010-05-29 07:09:12 +04:00
.Lhalt :
2012-03-29 23:48:23 +04:00
moveli r41 , h w2 _ l a s t ( h v _ h a l t )
shl1 6 i n s l i r41 , r41 , h w1 ( h v _ h a l t )
shl1 6 i n s l i r41 , r41 , h w0 ( h v _ h a l t )
2010-05-29 07:09:12 +04:00
jalr r41
STD_ E N D P R O C ( r e l o c a t e _ n e w _ k e r n e l )
.section .rodata , " a"
.globl relocate_new_kernel_size
relocate_new_kernel_size :
.long .Lend_relocate_new_kernel - relocate_ n e w _ k e r n e l