2010-04-05 00:19:02 +04:00
/* 1. Find the index of the entry we're executing in */
bl i n v s t r / * F i n d o u r a d d r e s s * /
invstr : mflr r6 / * M a k e i t a c c e s s i b l e * /
mfmsr r7
rlwinm r4 ,r7 ,2 7 ,3 1 ,3 1 / * e x t r a c t M S R [ I S ] * /
mfspr r7 , S P R N _ P I D 0
slwi r7 ,r7 ,1 6
or r7 ,r7 ,r4
mtspr S P R N _ M A S 6 ,r7
tlbsx 0 ,r6 / * s e a r c h M S R [ I S ] , S P I D =PID0 * /
mfspr r7 ,S P R N _ M A S 1
andis. r7 ,r7 ,M A S 1 _ V A L I D @h
bne m a t c h _ T L B
mfspr r7 ,S P R N _ M M U C F G
rlwinm r7 ,r7 ,2 1 ,2 8 ,3 1 / * e x t r a c t M M U C F G [ N P I D S ] * /
cmpwi r7 ,3
bne m a t c h _ T L B / * s k i p i f N P I D S ! = 3 * /
mfspr r7 ,S P R N _ P I D 1
slwi r7 ,r7 ,1 6
or r7 ,r7 ,r4
mtspr S P R N _ M A S 6 ,r7
tlbsx 0 ,r6 / * s e a r c h M S R [ I S ] , S P I D =PID1 * /
mfspr r7 ,S P R N _ M A S 1
andis. r7 ,r7 ,M A S 1 _ V A L I D @h
bne m a t c h _ T L B
mfspr r7 , S P R N _ P I D 2
slwi r7 ,r7 ,1 6
or r7 ,r7 ,r4
mtspr S P R N _ M A S 6 ,r7
tlbsx 0 ,r6 / * F a l l t h r o u g h , w e h a d t o m a t c h * /
match_TLB :
mfspr r7 ,S P R N _ M A S 0
rlwinm r3 ,r7 ,1 6 ,2 0 ,3 1 / * E x t r a c t M A S 0 ( E n t r y ) * /
mfspr r7 ,S P R N _ M A S 1 / * I n s u r e I P R O T s e t * /
oris r7 ,r7 ,M A S 1 _ I P R O T @h
mtspr S P R N _ M A S 1 ,r7
tlbwe
/* 2. Invalidate all entries except the entry we're executing in */
mfspr r9 ,S P R N _ T L B 1 C F G
andi. r9 ,r9 ,0 x f f f
li r6 ,0 / * S e t E n t r y c o u n t e r t o 0 * /
1 : lis r7 ,0 x10 0 0 / * S e t M A S 0 ( T L B S E L ) = 1 * /
rlwimi r7 ,r6 ,1 6 ,4 ,1 5 / * S e t u p M A S 0 = T L B S E L | E S E L ( r6 ) * /
mtspr S P R N _ M A S 0 ,r7
tlbre
mfspr r7 ,S P R N _ M A S 1
rlwinm r7 ,r7 ,0 ,2 ,3 1 / * C l e a r M A S 1 V a l i d a n d I P R O T * /
cmpw r3 ,r6
beq s k p i n v / * D o n t u p d a t e t h e c u r r e n t e x e c u t i o n T L B * /
mtspr S P R N _ M A S 1 ,r7
tlbwe
isync
skpinv : addi r6 ,r6 ,1 / * I n c r e m e n t * /
cmpw r6 ,r9 / * A r e w e d o n e ? * /
bne 1 b / * I f n o t , r e p e a t * /
/* Invalidate TLB0 */
li r6 ,0 x04
tlbivax 0 ,r6
TLBSYNC
/* Invalidate TLB1 */
li r6 ,0 x0 c
tlbivax 0 ,r6
TLBSYNC
/* 3. Setup a temp mapping and jump to it */
andi. r5 , r3 , 0 x1 / * F i n d a n e n t r y n o t u s e d a n d i s n o n - z e r o * /
addi r5 , r5 , 0 x1
lis r7 ,0 x10 0 0 / * S e t M A S 0 ( T L B S E L ) = 1 * /
rlwimi r7 ,r3 ,1 6 ,4 ,1 5 / * S e t u p M A S 0 = T L B S E L | E S E L ( r3 ) * /
mtspr S P R N _ M A S 0 ,r7
tlbre
/* grab and fixup the RPN */
mfspr r6 ,S P R N _ M A S 1 / * e x t r a c t M A S 1 [ S I Z E ] * /
rlwinm r6 ,r6 ,2 5 ,2 7 ,3 1
li r8 ,- 1
addi r6 ,r6 ,1 0
slw r6 ,r8 ,r6 / * c o n v e r t t o m a s k * /
bl 1 f / * F i n d o u r a d d r e s s * /
1 : mflr r7
mfspr r8 ,S P R N _ M A S 3
# ifdef C O N F I G _ P H Y S _ 6 4 B I T
mfspr r23 ,S P R N _ M A S 7
# endif
and r8 ,r6 ,r8
subfic r9 ,r6 ,- 4 0 9 6
and r9 ,r9 ,r7
or r25 ,r8 ,r9
ori r8 ,r25 ,( M A S 3 _ S X | M A S 3 _ S W | M A S 3 _ S R )
/* Just modify the entry ID and EPN for the temp mapping */
lis r7 ,0 x10 0 0 / * S e t M A S 0 ( T L B S E L ) = 1 * /
rlwimi r7 ,r5 ,1 6 ,4 ,1 5 / * S e t u p M A S 0 = T L B S E L | E S E L ( r5 ) * /
mtspr S P R N _ M A S 0 ,r7
xori r6 ,r4 ,1 / * S e t u p T M P m a p p i n g i n t h e o t h e r A d d r e s s s p a c e * /
slwi r6 ,r6 ,1 2
oris r6 ,r6 ,( M A S 1 _ V A L I D | M A S 1 _ I P R O T ) @h
ori r6 ,r6 ,( M A S 1 _ T S I Z E ( B O O K 3 E _ P A G E S Z _ 4 K ) ) @l
mtspr S P R N _ M A S 1 ,r6
mfspr r6 ,S P R N _ M A S 2
li r7 ,0 / * t e m p E P N = 0 * /
rlwimi r7 ,r6 ,0 ,2 0 ,3 1
mtspr S P R N _ M A S 2 ,r7
mtspr S P R N _ M A S 3 ,r8
tlbwe
xori r6 ,r4 ,1
slwi r6 ,r6 ,5 / * s e t u p n e w c o n t e x t w i t h o t h e r a d d r e s s s p a c e * /
bl 1 f / * F i n d o u r a d d r e s s * /
1 : mflr r9
rlwimi r7 ,r9 ,0 ,2 0 ,3 1
addi r7 ,r7 ,( 2 f - 1 b )
mtspr S P R N _ S R R 0 ,r7
mtspr S P R N _ S R R 1 ,r6
rfi
2 :
/* 4. Clear out PIDs & Search info */
li r6 ,0
mtspr S P R N _ M A S 6 ,r6
mtspr S P R N _ P I D 0 ,r6
mfspr r7 ,S P R N _ M M U C F G
rlwinm r7 ,r7 ,2 1 ,2 8 ,3 1 / * e x t r a c t M M U C F G [ N P I D S ] * /
cmpwi r7 ,3
bne 2 f / * s k i p i f N P I D S ! = 3 * /
mtspr S P R N _ P I D 1 ,r6
mtspr S P R N _ P I D 2 ,r6
/* 5. Invalidate mapping we started in */
2 :
lis r7 ,0 x10 0 0 / * S e t M A S 0 ( T L B S E L ) = 1 * /
rlwimi r7 ,r3 ,1 6 ,4 ,1 5 / * S e t u p M A S 0 = T L B S E L | E S E L ( r3 ) * /
mtspr S P R N _ M A S 0 ,r7
tlbre
mfspr r6 ,S P R N _ M A S 1
rlwinm r6 ,r6 ,0 ,2 ,0 / * c l e a r I P R O T * /
mtspr S P R N _ M A S 1 ,r6
tlbwe
/* Invalidate TLB1 */
li r9 ,0 x0 c
tlbivax 0 ,r9
TLBSYNC
/* The mapping only needs to be cache-coherent on SMP */
# ifdef C O N F I G _ S M P
# define M _ I F _ S M P M A S 2 _ M
# else
# define M _ I F _ S M P 0
# endif
2010-04-05 00:19:03 +04:00
# if d e f i n e d ( E N T R Y _ M A P P I N G _ B O O T _ S E T U P )
2010-04-05 00:19:02 +04:00
/* 6. Setup KERNELBASE mapping in TLB1[0] */
lis r6 ,0 x10 0 0 / * S e t M A S 0 ( T L B S E L ) = T L B 1 ( 1 ) , E S E L = 0 * /
mtspr S P R N _ M A S 0 ,r6
lis r6 ,( M A S 1 _ V A L I D | M A S 1 _ I P R O T ) @h
ori r6 ,r6 ,( M A S 1 _ T S I Z E ( B O O K 3 E _ P A G E S Z _ 6 4 M ) ) @l
mtspr S P R N _ M A S 1 ,r6
lis r6 ,M A S 2 _ V A L ( P A G E _ O F F S E T , B O O K 3 E _ P A G E S Z _ 6 4 M , M _ I F _ S M P ) @h
ori r6 ,r6 ,M A S 2 _ V A L ( P A G E _ O F F S E T , B O O K 3 E _ P A G E S Z _ 6 4 M , M _ I F _ S M P ) @l
mtspr S P R N _ M A S 2 ,r6
mtspr S P R N _ M A S 3 ,r8
tlbwe
/* 7. Jump to KERNELBASE mapping */
lis r6 ,( K E R N E L B A S E & ~ 0 x f f f ) @h
ori r6 ,r6 ,( K E R N E L B A S E & ~ 0 x f f f ) @l
2010-04-05 00:19:03 +04:00
# elif d e f i n e d ( E N T R Y _ M A P P I N G _ K E X E C _ S E T U P )
/ *
* 6 . Setup a 1 : 1 m a p p i n g i n T L B 1 . E s e l 0 i s u n s u e d , 1 o r 2 c o n t a i n s t h e t m p
* mapping s o w e s t a r t a t 3 . W e s e t u p 8 m a p p i n g s , e a c h 2 5 6 M i B i n s i z e . T h i s
* will c o v e r t h e f i r s t 2 G i B o f m e m o r y .
* /
lis r10 , ( M A S 1 _ V A L I D | M A S 1 _ I P R O T ) @h
ori r10 ,r10 , ( M A S 1 _ T S I Z E ( B O O K 3 E _ P A G E S Z _ 2 5 6 M ) ) @l
li r11 , 0
li r0 , 8
mtctr r0
next_tlb_setup :
addi r0 , r11 , 3
rlwinm r0 , r0 , 1 6 , 4 , 1 5 / / C o m p u t e e s e l
rlwinm r9 , r11 , 2 8 , 0 , 3 / / C o m p u t e [ E R ] P N
oris r0 , r0 , ( M A S 0 _ T L B S E L ( 1 ) ) @h
mtspr S P R N _ M A S 0 ,r0
mtspr S P R N _ M A S 1 ,r10
mtspr S P R N _ M A S 2 ,r9
ori r9 , r9 , ( M A S 3 _ S X | M A S 3 _ S W | M A S 3 _ S R )
mtspr S P R N _ M A S 3 ,r9
tlbwe
addi r11 , r11 , 1
bdnz+ n e x t _ t l b _ s e t u p
/* 7. Jump to our 1:1 mapping */
2010-06-29 23:42:07 +04:00
mr r6 , r25
2010-04-05 00:19:03 +04:00
# else
# error Y o u n e e d t o s p e c i f y t h e m a p p i n g o r n o t u s e t h i s a t a l l .
# endif
2010-04-05 00:19:02 +04:00
lis r7 ,M S R _ K E R N E L @h
ori r7 ,r7 ,M S R _ K E R N E L @l
bl 1 f / * F i n d o u r a d d r e s s * /
1 : mflr r9
rlwimi r6 ,r9 ,0 ,2 0 ,3 1
addi r6 ,r6 ,( 2 f - 1 b )
mtspr S P R N _ S R R 0 ,r6
mtspr S P R N _ S R R 1 ,r7
rfi / * s t a r t e x e c u t i o n o u t o f T L B 1 [ 0 ] e n t r y * /
/* 8. Clear out the temp mapping */
2 : lis r7 ,0 x10 0 0 / * S e t M A S 0 ( T L B S E L ) = 1 * /
rlwimi r7 ,r5 ,1 6 ,4 ,1 5 / * S e t u p M A S 0 = T L B S E L | E S E L ( r5 ) * /
mtspr S P R N _ M A S 0 ,r7
tlbre
mfspr r8 ,S P R N _ M A S 1
rlwinm r8 ,r8 ,0 ,2 ,0 / * c l e a r I P R O T * /
mtspr S P R N _ M A S 1 ,r8
tlbwe
/* Invalidate TLB1 */
li r9 ,0 x0 c
tlbivax 0 ,r9
TLBSYNC