2005-09-26 10:04:21 +04:00
/ *
* PowerPC v e r s i o n
* Copyright ( C ) 1 9 9 5 - 1 9 9 6 G a r y T h o m a s ( g d t @linuxppc.org)
*
* Rewritten b y C o r t D o u g a n ( c o r t @cs.nmt.edu) for PReP
* Copyright ( C ) 1 9 9 6 C o r t D o u g a n < c o r t @cs.nmt.edu>
* Adapted f o r P o w e r M a c i n t o s h b y P a u l M a c k e r r a s .
* Low- l e v e l e x c e p t i o n h a n d l e r s a n d M M U s u p p o r t
* rewritten b y P a u l M a c k e r r a s .
* Copyright ( C ) 1 9 9 6 P a u l M a c k e r r a s .
* MPC8 x x m o d i f i c a t i o n s C o p y r i g h t ( C ) 1 9 9 7 D a n M a l e k ( d m a l e k @jlc.net).
* Amiga/ A P U S c h a n g e s b y J e s p e r S k o v ( j s k o v @cygnus.co.uk).
*
* This f i l e c o n t a i n s t h e l o w - l e v e l s u p p o r t a n d s e t u p f o r t h e
* PowerPC p l a t f o r m , i n c l u d i n g t r a p a n d i n t e r r u p t d i s p a t c h .
* ( The P P C 8 x x e m b e d d e d C P U s u s e h e a d _ 8 x x . S i n s t e a 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 ; either version
* 2 of t h e L i c e n s e , o r ( a t y o u r o p t i o n ) a n y l a t e r v e r s i o n .
*
* /
2005-10-10 16:20:10 +04:00
# include < a s m / r e g . h >
2005-09-26 10:04:21 +04:00
# include < a s m / p a g e . h >
# include < a s m / m m u . h >
# include < a s m / p g t a b l e . h >
# include < a s m / c p u t a b l e . h >
# include < a s m / c a c h e . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / p p c _ a s m . h >
# include < a s m / a s m - o f f s e t s . h >
# ifdef C O N F I G _ A P U S
# include < a s m / a m i g a p p c . h >
# endif
/* 601 only have IBAT; cr0.eq is set on 601 when using this macro */
# define L O A D _ B A T ( n , r e g , R A , R B ) \
/* see the comment for clear_bats() -- Cort */ \
li R A ,0 ; \
mtspr S P R N _ I B A T ## n # # U , R A ; \
mtspr S P R N _ D B A T ## n # # U , R A ; \
lwz R A ,( n * 1 6 ) + 0 ( r e g ) ; \
lwz R B ,( n * 1 6 ) + 4 ( r e g ) ; \
mtspr S P R N _ I B A T ## n # # U , R A ; \
mtspr S P R N _ I B A T ## n # # L , R B ; \
beq 1 f ; \
lwz R A ,( n * 1 6 ) + 8 ( r e g ) ; \
lwz R B ,( n * 1 6 ) + 1 2 ( r e g ) ; \
mtspr S P R N _ D B A T ## n # # U , R A ; \
mtspr S P R N _ D B A T ## n # # L , R B ; \
1 :
.text
2005-10-10 16:20:10 +04:00
.stabs " arch/ p o w e r p c / k e r n e l / " ,N _ S O ,0 ,0 ,0 f
.stabs " head_ 3 2 . S " ,N _ S O ,0 ,0 ,0 f
2005-09-26 10:04:21 +04:00
0 :
.globl _stext
_stext :
/ *
* _ start i s d e f i n e d t h i s w a y b e c a u s e t h e X C O F F l o a d e r i n t h e O p e n F i r m w a r e
* on t h e p o w e r m a c e x p e c t s t h e e n t r y p o i n t t o b e a p r o c e d u r e d e s c r i p t o r .
* /
.text
.globl _start
_start :
/ *
* These a r e h e r e f o r l e g a c y r e a s o n s , t h e k e r n e l u s e d t o
* need t o l o o k l i k e a c o f f f u n c t i o n e n t r y f o r t h e p m a c
* but w e ' r e a l w a y s s t a r t e d b y s o m e k i n d o f b o o t l o a d e r n o w .
* - - Cort
* /
nop / * u s e d b y _ _ s e c o n d a r y _ h o l d o n p r e p ( m t x ) a n d c h r p s m p * /
nop / * u s e d b y _ _ s e c o n d a r y _ h o l d o n p r e p ( m t x ) a n d c h r p s m p * /
nop
/ * PMAC
* Enter h e r e w i t h t h e k e r n e l t e x t , d a t a a n d b s s l o a d e d s t a r t i n g a t
* 0 , running w i t h v i r t u a l = = p h y s i c a l m a p p i n g .
* r5 p o i n t s t o t h e p r o m e n t r y p o i n t ( t h e c l i e n t i n t e r f a c e h a n d l e r
* address) . A d d r e s s t r a n s l a t i o n i s t u r n e d o n , w i t h t h e p r o m
* managing t h e h a s h t a b l e . I n t e r r u p t s a r e d i s a b l e d . T h e s t a c k
* pointer ( r1 ) p o i n t s t o j u s t b e l o w t h e e n d o f t h e h a l f - m e g r e g i o n
* from 0 x38 0 0 0 0 - 0 x40 0 0 0 0 , w h i c h i s m a p p e d i n a l r e a d y .
*
* If w e a r e b o o t e d f r o m M a c O S v i a B o o t X , w e e n t e r w i t h t h e k e r n e l
* image l o a d e d s o m e w h e r e , a n d t h e f o l l o w i n g v a l u e s i n r e g i s t e r s :
* r3 : ' BooX' ( 0 x42 6 f6 f58 )
* r4 : virtual a d d r e s s o f b o o t _ i n f o s _ t
* r5 : 0
*
* APUS
* r3 : ' APUS'
* r4 : physical a d d r e s s o f m e m o r y b a s e
* Linux/ m 6 8 k s t y l e B o o t I n f o s t r u c t u r e a t & _ e n d .
*
* PREP
* This i s j u m p e d t o o n p r e p s y s t e m s r i g h t a f t e r t h e k e r n e l i s r e l o c a t e d
* to i t s p r o p e r p l a c e i n m e m o r y b y t h e b o o t l o a d e r . T h e e x p e c t e d l a y o u t
* of t h e r e g s i s :
* r3 : ptr t o r e s i d u a l d a t a
* r4 : initrd_ s t a r t o r i f n o i n i t r d t h e n 0
* r5 : initrd_ e n d - u n u s e d i f r4 i s 0
* r6 : Start o f c o m m a n d l i n e s t r i n g
* r7 : End o f c o m m a n d l i n e s t r i n g
*
* This j u s t g e t s a m i n i m a l m m u e n v i r o n m e n t s e t u p s o w e c a n c a l l
* start_ h e r e ( ) t o d o t h e r e a l w o r k .
* - - Cort
* /
.globl __start
__start :
/ *
* We h a v e t o d o a n y O F c a l l s b e f o r e w e m a p o u r s e l v e s t o K E R N E L B A S E ,
* because O F m a y h a v e I / O d e v i c e s m a p p e d i n t o t h a t a r e a
* ( particularly o n C H R P ) .
* /
2006-01-09 12:17:01 +03:00
# ifdef C O N F I G _ P P C _ M U L T I P L A T F O R M
2005-10-06 06:06:20 +04:00
cmpwi 0 ,r5 ,0
beq 1 f
bl p r o m _ i n i t
trap
2006-01-09 12:17:01 +03:00
# endif
2005-10-06 06:06:20 +04:00
2005-11-23 09:58:13 +03:00
/ *
* Check f o r B o o t X s i g n a t u r e w h e n s u p p o r t i n g P o w e r M a c a n d b r a n c h t o
* appropriate t r a m p o l i n e i f i t ' s p r e s e n t
* /
# ifdef C O N F I G _ P P C _ P M A C
1 : lis r31 ,0 x42 6 f
ori r31 ,r31 ,0 x6 f58
cmpw 0 ,r3 ,r31
bne 1 f
bl b o o t x _ i n i t
trap
# endif / * C O N F I G _ P P C _ P M A C * /
2005-10-06 06:06:20 +04:00
1 : mr r31 ,r3 / * s a v e p a r a m e t e r s * /
2005-09-26 10:04:21 +04:00
mr r30 ,r4
li r24 ,0 / * c p u # * /
/ *
* early_ i n i t ( ) d o e s t h e e a r l y m a c h i n e i d e n t i f i c a t i o n a n d d o e s
* the n e c e s s a r y l o w - l e v e l s e t u p a n d c l e a r s t h e B S S
* - - Cort < c o r t @fsmlabs.com>
* /
bl e a r l y _ i n i t
# ifdef C O N F I G _ A P U S
/ * On A P U S t h e _ _ v a / _ _ p a c o n s t a n t s n e e d t o b e s e t t o t h e c o r r e c t
* values b e f o r e c o n t i n u i n g .
* /
mr r4 ,r30
bl f i x _ m e m _ c o n s t a n t s
# endif / * C O N F I G _ A P U S * /
/ * Switch M M U o f f , c l e a r B A T s a n d f l u s h T L B . A t t h i s p o i n t , r3 c o n t a i n s
* the p h y s i c a l a d d r e s s w e a r e r u n n i n g a t , r e t u r n e d b y e a r l y _ i n i t ( )
* /
bl m m u _ o f f
__after_mmu_off :
bl c l e a r _ b a t s
bl f l u s h _ t l b s
bl i n i t i a l _ b a t s
2005-11-23 09:57:25 +03:00
# if ! d e f i n e d ( C O N F I G _ A P U S ) & & d e f i n e d ( C O N F I G _ B O O T X _ T E X T )
bl s e t u p _ d i s p _ b a t
# endif
2005-09-26 10:04:21 +04:00
/ *
* Call s e t u p _ c p u f o r C P U 0 a n d i n i t i a l i z e 6 x x I d l e
* /
bl r e l o c _ o f f s e t
li r24 ,0 / * c p u # * /
bl c a l l _ s e t u p _ c p u / * C a l l s e t u p _ c p u f o r t h i s C P U * /
# ifdef C O N F I G _ 6 x x
bl r e l o c _ o f f s e t
bl i n i t _ i d l e _ 6 x x
# endif / * C O N F I G _ 6 x x * /
# ifndef C O N F I G _ A P U S
/ *
* We n e e d t o r u n w i t h _ s t a r t a t p h y s i c a l a d d r e s s 0 .
* On C H R P , w e a r e l o a d e d a t 0 x10 0 0 0 s i n c e O F o n C H R P u s e s
* the e x c e p t i o n v e c t o r s a t 0 ( a n d t h e r e f o r e t h i s c o p y
* overwrites O F ' s e x c e p t i o n v e c t o r s w i t h o u r o w n ) .
2005-10-06 06:06:20 +04:00
* The M M U i s o f f a t t h i s p o i n t .
2005-09-26 10:04:21 +04:00
* /
bl r e l o c _ o f f s e t
mr r26 ,r3
addis r4 ,r3 ,K E R N E L B A S E @h /* current address of _start */
cmpwi 0 ,r4 ,0 / * a r e w e a l r e a d y r u n n i n g a t 0 ? * /
bne r e l o c a t e _ k e r n e l
# endif / * C O N F I G _ A P U S * /
/ *
* we n o w h a v e t h e 1 s t 1 6 M o f r a m m a p p e d w i t h t h e b a t s .
* prep n e e d s t h e m m u t o b e t u r n e d o n h e r e , b u t p m a c a l r e a d y h a s i t o n .
* this s h o u l d n ' t b o t h e r t h e p m a c s i n c e i t j u s t g e t s t u r n e d o n a g a i n
* as w e j u m p t o o u r c o d e a t K E R N E L B A S E . - - C o r t
* Actually n o , p m a c d o e s n ' t h a v e i t o n a n y m o r e . B o o t X e n t e r s w i t h M M U
* off, a n d i n o t h e r c a s e s , w e n o w t u r n i t o f f b e f o r e c h a n g i n g B A T s a b o v e .
* /
turn_on_mmu :
mfmsr r0
ori r0 ,r0 ,M S R _ D R | M S R _ I R
mtspr S P R N _ S R R 1 ,r0
lis r0 ,s t a r t _ h e r e @h
ori r0 ,r0 ,s t a r t _ h e r e @l
mtspr S P R N _ S R R 0 ,r0
SYNC
RFI / * e n a b l e s M M U * /
/ *
* We n e e d _ _ s e c o n d a r y _ h o l d a s a p l a c e t o h o l d t h e o t h e r c p u s o n
* an S M P m a c h i n e , e v e n w h e n w e a r e r u n n i n g a U P k e r n e l .
* /
. = 0 xc0 / * f o r p r e p b o o t l o a d e r * /
li r3 ,1 / * M T X o n l y h a s 1 c p u * /
.globl __secondary_hold
__secondary_hold :
/* tell the master we're here */
2005-10-26 15:45:56 +04:00
stw r3 ,_ _ s e c o n d a r y _ h o l d _ a c k n o w l e d g e @l(0)
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ S M P
100 : lwz r4 ,0 ( 0 )
/* wait until we're told to start */
cmpw 0 ,r4 ,r3
bne 1 0 0 b
/* our cpu # was at addr 0 - go */
mr r24 ,r3 / * c p u # * /
b _ _ s e c o n d a r y _ s t a r t
# else
b .
# endif / * C O N F I G _ S M P * /
2005-10-26 15:45:56 +04:00
.globl __secondary_hold_spinloop
__secondary_hold_spinloop :
.long 0
.globl __secondary_hold_acknowledge
__secondary_hold_acknowledge :
.long - 1
2005-09-26 10:04:21 +04:00
/ *
* Exception e n t r y c o d e . T h i s c o d e r u n s w i t h a d d r e s s t r a n s l a t i o n
* turned o f f , i . e . u s i n g p h y s i c a l a d d r e s s e s .
* We a s s u m e s p r g 3 h a s t h e p h y s i c a l a d d r e s s o f t h e c u r r e n t
* task' s t h r e a d _ s t r u c t .
* /
# define E X C E P T I O N _ P R O L O G \
mtspr S P R N _ S P R G 0 ,r10 ; \
mtspr S P R N _ S P R G 1 ,r11 ; \
mfcr r10 ; \
EXCEPTION_ P R O L O G _ 1 ; \
EXCEPTION_ P R O L O G _ 2
# define E X C E P T I O N _ P R O L O G _ 1 \
mfspr r11 ,S P R N _ S R R 1 ; /* check whether user or kernel */ \
andi. r11 ,r11 ,M S R _ P R ; \
tophys( r11 ,r1 ) ; /* use tophys(r1) if kernel */ \
beq 1 f ; \
mfspr r11 ,S P R N _ S P R G 3 ; \
lwz r11 ,T H R E A D _ I N F O - T H R E A D ( r11 ) ; \
addi r11 ,r11 ,T H R E A D _ S I Z E ; \
tophys( r11 ,r11 ) ; \
1 : subi r11 ,r11 ,I N T _ F R A M E _ S I Z E / * a l l o c e x c . f r a m e * /
# define E X C E P T I O N _ P R O L O G _ 2 \
CLR_ T O P 3 2 ( r11 ) ; \
stw r10 ,_ C C R ( r11 ) ; /* save registers */ \
stw r12 ,G P R 1 2 ( r11 ) ; \
stw r9 ,G P R 9 ( r11 ) ; \
mfspr r10 ,S P R N _ S P R G 0 ; \
stw r10 ,G P R 1 0 ( r11 ) ; \
mfspr r12 ,S P R N _ S P R G 1 ; \
stw r12 ,G P R 1 1 ( r11 ) ; \
mflr r10 ; \
stw r10 ,_ L I N K ( r11 ) ; \
mfspr r12 ,S P R N _ S R R 0 ; \
mfspr r9 ,S P R N _ S R R 1 ; \
stw r1 ,G P R 1 ( r11 ) ; \
stw r1 ,0 ( r11 ) ; \
tovirt( r1 ,r11 ) ; /* set new kernel sp */ \
li r10 ,M S R _ K E R N E L & ~ ( M S R _ I R | M S R _ D R ) ; /* can take exceptions */ \
MTMSRD( r10 ) ; /* (except for mach check in rtas) */ \
stw r0 ,G P R 0 ( r11 ) ; \
2005-10-28 16:53:37 +04:00
lis r10 ,0 x72 6 5 ; /* put exception frame marker */ \
addi r10 ,r10 ,0 x67 7 3 ; \
stw r10 ,8 ( r11 ) ; \
2005-09-26 10:04:21 +04:00
SAVE_ 4 G P R S ( 3 , r11 ) ; \
SAVE_ 2 G P R S ( 7 , r11 )
/ *
* Note : code w h i c h f o l l o w s t h i s u s e s c r0 . e q ( s e t i f f r o m k e r n e l ) ,
* r1 1 , r12 ( S R R 0 ) , a n d r9 ( S R R 1 ) .
*
* Note2 : once w e h a v e s e t r1 w e a r e i n a p o s i t i o n t o t a k e e x c e p t i o n s
* again, a n d w e c o u l d t h u s s e t M S R : R I a t t h a t p o i n t .
* /
/ *
* Exception v e c t o r s .
* /
# define E X C E P T I O N ( n , l a b e l , h d l r , x f e r ) \
. = n; \
label : \
EXCEPTION_ P R O L O G ; \
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D ; \
xfer( n , h d l r )
# define E X C _ X F E R _ T E M P L A T E ( n , h d l r , t r a p , c o p y e e , t f e r , r e t ) \
li r10 ,t r a p ; \
2005-10-28 16:45:25 +04:00
stw r10 ,_ T R A P ( r11 ) ; \
2005-09-26 10:04:21 +04:00
li r10 ,M S R _ K E R N E L ; \
copyee( r10 , r9 ) ; \
bl t f e r ; \
i## n : \
.long hdlr; \
.long ret
# define C O P Y _ E E ( d , s ) r l w i m i d ,s ,0 ,1 6 ,1 6
# define N O C O P Y ( d , s )
# define E X C _ X F E R _ S T D ( n , h d l r ) \
EXC_ X F E R _ T E M P L A T E ( n , h d l r , n , N O C O P Y , t r a n s f e r _ t o _ h a n d l e r _ f u l l , \
ret_ f r o m _ e x c e p t _ f u l l )
# define E X C _ X F E R _ L I T E ( n , h d l r ) \
EXC_ X F E R _ T E M P L A T E ( n , h d l r , n + 1 , N O C O P Y , t r a n s f e r _ t o _ h a n d l e r , \
ret_ f r o m _ e x c e p t )
# define E X C _ X F E R _ E E ( n , h d l r ) \
EXC_ X F E R _ T E M P L A T E ( n , h d l r , n , C O P Y _ E E , t r a n s f e r _ t o _ h a n d l e r _ f u l l , \
ret_ f r o m _ e x c e p t _ f u l l )
# define E X C _ X F E R _ E E _ L I T E ( n , h d l r ) \
EXC_ X F E R _ T E M P L A T E ( n , h d l r , n + 1 , C O P Y _ E E , t r a n s f e r _ t o _ h a n d l e r , \
ret_ f r o m _ e x c e p t )
/* System reset */
/ * core9 9 p m a c s t a r t s t h e s e c o n a r y h e r e b y c h a n g i n g t h e v e c t o r , a n d
2005-10-01 12:43:42 +04:00
putting i t b a c k t o w h a t i t w a s ( u n k n o w n _ e x c e p t i o n ) w h e n d o n e . * /
2005-09-26 10:04:21 +04:00
# if d e f i n e d ( C O N F I G _ G E M I N I ) & & d e f i n e d ( C O N F I G _ S M P )
. = 0 x1 0 0
b _ _ s e c o n d a r y _ s t a r t _ g e m i n i
# else
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x10 0 , R e s e t , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ S T D )
2005-09-26 10:04:21 +04:00
# endif
/* Machine check */
/ *
* On C H R P , t h i s i s c o m p l i c a t e d b y t h e f a c t t h a t w e c o u l d g e t a
* machine c h e c k i n s i d e R T A S , a n d w e h a v e n o g u a r a n t e e t h a t c e r t a i n
* critical r e g i s t e r s w i l l h a v e t h e v a l u e s w e e x p e c t . T h e s e t o f
* registers t h a t m i g h t h a v e b a d v a l u e s i n c l u d e s a l l t h e G P R s
* and a l l t h e B A T s . W e i n d i c a t e t h a t w e a r e i n R T A S b y p u t t i n g
* a n o n - z e r o v a l u e , t h e a d d r e s s o f t h e e x c e p t i o n f r a m e t o u s e ,
* in S P R G 2 . T h e m a c h i n e c h e c k h a n d l e r c h e c k s S P R G 2 a n d u s e s i t s
* value i f i t i s n o n - z e r o . I f w e e v e r n e e d e d t o f r e e u p S P R G 2 ,
* we c o u l d u s e a f i e l d i n t h e t h r e a d _ i n f o o r t h r e a d _ s t r u c t i n s t e a d .
* ( Other e x c e p t i o n h a n d l e r s a s s u m e t h a t r1 i s a v a l i d k e r n e l s t a c k
* pointer w h e n w e t a k e a n e x c e p t i o n f r o m s u p e r v i s o r m o d e . )
* - - paulus.
* /
. = 0 x2 0 0
mtspr S P R N _ S P R G 0 ,r10
mtspr S P R N _ S P R G 1 ,r11
mfcr r10
# ifdef C O N F I G _ P P C _ C H R P
mfspr r11 ,S P R N _ S P R G 2
cmpwi 0 ,r11 ,0
bne 7 f
# endif / * C O N F I G _ P P C _ C H R P * /
EXCEPTION_ P R O L O G _ 1
7 : EXCEPTION_ P R O L O G _ 2
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
# ifdef C O N F I G _ P P C _ C H R P
mfspr r4 ,S P R N _ S P R G 2
cmpwi c r1 ,r4 ,0
bne c r1 ,1 f
# endif
2005-10-01 12:43:42 +04:00
EXC_ X F E R _ S T D ( 0 x20 0 , m a c h i n e _ c h e c k _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ P P C _ C H R P
1 : b m a c h i n e _ c h e c k _ i n _ r t a s
# endif
/* Data access exception. */
. = 0 x3 0 0
DataAccess :
EXCEPTION_ P R O L O G
mfspr r10 ,S P R N _ D S I S R
andis. r0 ,r10 ,0 x a47 0 / * w e i r d e r r o r ? * /
bne 1 f / * i f n o t , t r y t o p u t a P T E * /
mfspr r4 ,S P R N _ D A R / * i n t o t h e h a s h t a b l e * /
rlwinm r3 ,r10 ,3 2 - 1 5 ,2 1 ,2 1 / * D S I S R _ S T O R E - > _ P A G E _ R W * /
bl h a s h _ p a g e
1 : stw r10 ,_ D S I S R ( r11 )
mr r5 ,r10
mfspr r4 ,S P R N _ D A R
EXC_ X F E R _ E E _ L I T E ( 0 x30 0 , h a n d l e _ p a g e _ f a u l t )
/* Instruction access exception. */
. = 0 x4 0 0
InstructionAccess :
EXCEPTION_ P R O L O G
andis. r0 ,r9 ,0 x40 0 0 / * n o p t e f o u n d ? * /
beq 1 f / * i f s o , t r y t o p u t a P T E * /
li r3 ,0 / * i n t o t h e h a s h t a b l e * /
mr r4 ,r12 / * S R R 0 i s f a u l t a d d r e s s * /
bl h a s h _ p a g e
1 : mr r4 ,r12
mr r5 ,r9
EXC_ X F E R _ E E _ L I T E ( 0 x40 0 , h a n d l e _ p a g e _ f a u l t )
/* External interrupt */
EXCEPTION( 0 x50 0 , H a r d w a r e I n t e r r u p t , d o _ I R Q , E X C _ X F E R _ L I T E )
/* Alignment exception */
. = 0 x6 0 0
Alignment :
EXCEPTION_ P R O L O G
mfspr r4 ,S P R N _ D A R
stw r4 ,_ D A R ( r11 )
mfspr r5 ,S P R N _ D S I S R
stw r5 ,_ D S I S R ( r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2005-10-01 12:43:42 +04:00
EXC_ X F E R _ E E ( 0 x60 0 , a l i g n m e n t _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
/* Program check exception */
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x70 0 , P r o g r a m C h e c k , p r o g r a m _ c h e c k _ e x c e p t i o n , E X C _ X F E R _ S T D )
2005-09-26 10:04:21 +04:00
/* Floating-point unavailable */
. = 0 x8 0 0
FPUnavailable :
2006-12-08 11:43:30 +03:00
BEGIN_ F T R _ S E C T I O N
/ *
* Certain F r e e s c a l e c o r e s d o n ' t h a v e a F P U a n d t r e a t f p i n s t r u c t i o n s
* as a F P U n a v a i l a b l e e x c e p t i o n . R e d i r e c t t o i l l e g a l / e m u l a t i o n h a n d l i n g .
* /
b P r o g r a m C h e c k
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ F P U _ U N A V A I L A B L E )
2005-09-26 10:04:21 +04:00
EXCEPTION_ P R O L O G
bne l o a d _ u p _ f p u / * i f f r o m u s e r , j u s t l o a d i t u p * /
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2005-10-06 07:27:05 +04:00
EXC_ X F E R _ E E _ L I T E ( 0 x80 0 , k e r n e l _ f p _ u n a v a i l a b l e _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
/* Decrementer */
EXCEPTION( 0 x90 0 , D e c r e m e n t e r , t i m e r _ i n t e r r u p t , E X C _ X F E R _ L I T E )
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x a00 , T r a p _ 0 a , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x b00 , T r a p _ 0 b , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
/* System call */
. = 0 xc0 0
SystemCall :
EXCEPTION_ P R O L O G
EXC_ X F E R _ E E _ L I T E ( 0 x c00 , D o S y s c a l l )
/* Single step - not used on 601 */
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x d00 , S i n g l e S t e p , s i n g l e _ s t e p _ e x c e p t i o n , E X C _ X F E R _ S T D )
EXCEPTION( 0 x e 0 0 , T r a p _ 0 e , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
/ *
* The A l t i v e c u n a v a i l a b l e t r a p i s a t 0 x0 f20 . F o o .
* We e f f e c t i v e l y r e m a p i t t o 0 x30 0 0 .
* We i n c l u d e a n a l t i v e c u n a v a i l a b l e e x c e p t i o n v e c t o r e v e n i f
* not c o n f i g u r e d f o r A l t i v e c , s o t h a t y o u c a n ' t p a n i c a
* non- a l t i v e c k e r n e l r u n n i n g o n a m a c h i n e w i t h a l t i v e c j u s t
* by e x e c u t i n g a n a l t i v e c i n s t r u c t i o n .
* /
. = 0 xf0 0
2005-12-16 05:02:04 +03:00
b P e r f o r m a n c e M o n i t o r
2005-09-26 10:04:21 +04:00
. = 0 xf2 0
b A l t i V e c U n a v a i l a b l e
/ *
* Handle T L B m i s s f o r i n s t r u c t i o n o n 6 0 3 / 6 0 3 e .
* Note : we g e t a n a l t e r n a t e s e t o f r0 - r3 t o u s e a u t o m a t i c a l l y .
* /
. = 0 x1 0 0 0
InstructionTLBMiss :
/ *
* r0 : stored c t r
* r1 : linux s t y l e p t e ( l a t e r b e c o m e s p p c h a r d w a r e p t e )
* r2 : ptr t o l i n u x - s t y l e p t e
* r3 : scratch
* /
mfctr r0
/* Get PTE (linux-style) and check access */
mfspr r3 ,S P R N _ I M I S S
lis r1 ,K E R N E L B A S E @h /* check if kernel address */
cmplw 0 ,r3 ,r1
mfspr r2 ,S P R N _ S P R G 3
li r1 ,_ P A G E _ U S E R | _ P A G E _ P R E S E N T / * l o w a d d r e s s e s t e s t e d a s u s e r * /
lwz r2 ,P G D I R ( r2 )
blt+ 1 1 2 f
lis r2 ,s w a p p e r _ p g _ d i r @ha /* if kernel address, use */
addi r2 ,r2 ,s w a p p e r _ p g _ d i r @l /* kernel page table */
mfspr r1 ,S P R N _ S R R 1 / * a n d M S R _ P R b i t f r o m S R R 1 * /
rlwinm r1 ,r1 ,3 2 - 1 2 ,2 9 ,2 9 / * s h i f t M S R _ P R t o _ P A G E _ U S E R p o s n * /
112 : tophys( r2 ,r2 )
rlwimi r2 ,r3 ,1 2 ,2 0 ,2 9 / * i n s e r t t o p 1 0 b i t s o f a d d r e s s * /
lwz r2 ,0 ( r2 ) / * g e t p m d e n t r y * /
rlwinm. r2 ,r2 ,0 ,0 ,1 9 / * e x t r a c t a d d r e s s o f p t e p a g e * /
beq- I n s t r u c t i o n A d d r e s s I n v a l i d / * r e t u r n i f n o m a p p i n g * /
rlwimi r2 ,r3 ,2 2 ,2 0 ,2 9 / * i n s e r t n e x t 1 0 b i t s o f a d d r e s s * /
lwz r3 ,0 ( r2 ) / * g e t l i n u x - s t y l e p t e * /
andc. r1 ,r1 ,r3 / * c h e c k a c c e s s & ~ p e r m i s s i o n * /
bne- I n s t r u c t i o n A d d r e s s I n v a l i d / * r e t u r n i f a c c e s s n o t p e r m i t t e d * /
ori r3 ,r3 ,_ P A G E _ A C C E S S E D / * s e t _ P A G E _ A C C E S S E D i n p t e * /
/ *
* NOTE! W e a r e a s s u m i n g t h i s i s n o t a n S M P s y s t e m , o t h e r w i s e
* we w o u l d n e e d t o u p d a t e t h e p t e a t o m i c a l l y w i t h l w a r x / s t w c x .
* /
stw r3 ,0 ( r2 ) / * u p d a t e P T E ( a c c e s s e d b i t ) * /
/* Convert linux-style PTE to low word of PPC-style PTE */
rlwinm r1 ,r3 ,3 2 - 1 0 ,3 1 ,3 1 / * _ P A G E _ R W - > P P l s b * /
rlwinm r2 ,r3 ,3 2 - 7 ,3 1 ,3 1 / * _ P A G E _ D I R T Y - > P P l s b * /
and r1 ,r1 ,r2 / * w r i t a b l e i f _ R W a n d _ D I R T Y * /
rlwimi r3 ,r3 ,3 2 - 1 ,3 0 ,3 0 / * _ P A G E _ U S E R - > P P m s b * /
rlwimi r3 ,r3 ,3 2 - 1 ,3 1 ,3 1 / * _ P A G E _ U S E R - > P P l s b * /
ori r1 ,r1 ,0 x e 1 4 / * c l e a r o u t r e s e r v e d b i t s a n d M * /
andc r1 ,r3 ,r1 / * P P = u s e r ? ( r w & d i r t y ? 2 : 3 ) : 0 * /
mtspr S P R N _ R P A ,r1
mfspr r3 ,S P R N _ I M I S S
tlbli r3
mfspr r3 ,S P R N _ S R R 1 / * N e e d t o r e s t o r e C R 0 * /
mtcrf 0 x80 ,r3
rfi
InstructionAddressInvalid :
mfspr r3 ,S P R N _ S R R 1
rlwinm r1 ,r3 ,9 ,6 ,6 / * G e t l o a d / s t o r e b i t * /
addis r1 ,r1 ,0 x20 0 0
mtspr S P R N _ D S I S R ,r1 / * ( s h o u l d n ' t b e n e e d e d ) * /
mtctr r0 / * R e s t o r e C T R * /
andi. r2 ,r3 ,0 x F F F F / * C l e a r u p p e r b i t s o f S R R 1 * /
or r2 ,r2 ,r1
mtspr S P R N _ S R R 1 ,r2
mfspr r1 ,S P R N _ I M I S S / * G e t f a i l i n g a d d r e s s * /
rlwinm. r2 ,r2 ,0 ,3 1 ,3 1 / * C h e c k f o r l i t t l e e n d i a n a c c e s s * /
rlwimi r2 ,r2 ,1 ,3 0 ,3 0 / * c h a n g e 1 - > 3 * /
xor r1 ,r1 ,r2
mtspr S P R N _ D A R ,r1 / * S e t f a u l t a d d r e s s * /
mfmsr r0 / * R e s t o r e " n o r m a l " r e g i s t e r s * /
xoris r0 ,r0 ,M S R _ T G P R > > 1 6
mtcrf 0 x80 ,r3 / * R e s t o r e C R 0 * /
mtmsr r0
b I n s t r u c t i o n A c c e s s
/ *
* Handle T L B m i s s f o r D A T A L o a d o p e r a t i o n o n 6 0 3 / 6 0 3 e
* /
. = 0 x1 1 0 0
DataLoadTLBMiss :
/ *
* r0 : stored c t r
* r1 : linux s t y l e p t e ( l a t e r b e c o m e s p p c h a r d w a r e p t e )
* r2 : ptr t o l i n u x - s t y l e p t e
* r3 : scratch
* /
mfctr r0
/* Get PTE (linux-style) and check access */
mfspr r3 ,S P R N _ D M I S S
lis r1 ,K E R N E L B A S E @h /* check if kernel address */
cmplw 0 ,r3 ,r1
mfspr r2 ,S P R N _ S P R G 3
li r1 ,_ P A G E _ U S E R | _ P A G E _ P R E S E N T / * l o w a d d r e s s e s t e s t e d a s u s e r * /
lwz r2 ,P G D I R ( r2 )
blt+ 1 1 2 f
lis r2 ,s w a p p e r _ p g _ d i r @ha /* if kernel address, use */
addi r2 ,r2 ,s w a p p e r _ p g _ d i r @l /* kernel page table */
mfspr r1 ,S P R N _ S R R 1 / * a n d M S R _ P R b i t f r o m S R R 1 * /
rlwinm r1 ,r1 ,3 2 - 1 2 ,2 9 ,2 9 / * s h i f t M S R _ P R t o _ P A G E _ U S E R p o s n * /
112 : tophys( r2 ,r2 )
rlwimi r2 ,r3 ,1 2 ,2 0 ,2 9 / * i n s e r t t o p 1 0 b i t s o f a d d r e s s * /
lwz r2 ,0 ( r2 ) / * g e t p m d e n t r y * /
rlwinm. r2 ,r2 ,0 ,0 ,1 9 / * e x t r a c t a d d r e s s o f p t e p a g e * /
beq- D a t a A d d r e s s I n v a l i d / * r e t u r n i f n o m a p p i n g * /
rlwimi r2 ,r3 ,2 2 ,2 0 ,2 9 / * i n s e r t n e x t 1 0 b i t s o f a d d r e s s * /
lwz r3 ,0 ( r2 ) / * g e t l i n u x - s t y l e p t e * /
andc. r1 ,r1 ,r3 / * c h e c k a c c e s s & ~ p e r m i s s i o n * /
bne- D a t a A d d r e s s I n v a l i d / * r e t u r n i f a c c e s s n o t p e r m i t t e d * /
ori r3 ,r3 ,_ P A G E _ A C C E S S E D / * s e t _ P A G E _ A C C E S S E D i n p t e * /
/ *
* NOTE! W e a r e a s s u m i n g t h i s i s n o t a n S M P s y s t e m , o t h e r w i s e
* we w o u l d n e e d t o u p d a t e t h e p t e a t o m i c a l l y w i t h l w a r x / s t w c x .
* /
stw r3 ,0 ( r2 ) / * u p d a t e P T E ( a c c e s s e d b i t ) * /
/* Convert linux-style PTE to low word of PPC-style PTE */
rlwinm r1 ,r3 ,3 2 - 1 0 ,3 1 ,3 1 / * _ P A G E _ R W - > P P l s b * /
rlwinm r2 ,r3 ,3 2 - 7 ,3 1 ,3 1 / * _ P A G E _ D I R T Y - > P P l s b * /
and r1 ,r1 ,r2 / * w r i t a b l e i f _ R W a n d _ D I R T Y * /
rlwimi r3 ,r3 ,3 2 - 1 ,3 0 ,3 0 / * _ P A G E _ U S E R - > P P m s b * /
rlwimi r3 ,r3 ,3 2 - 1 ,3 1 ,3 1 / * _ P A G E _ U S E R - > P P l s b * /
ori r1 ,r1 ,0 x e 1 4 / * c l e a r o u t r e s e r v e d b i t s a n d M * /
andc r1 ,r3 ,r1 / * P P = u s e r ? ( r w & d i r t y ? 2 : 3 ) : 0 * /
mtspr S P R N _ R P A ,r1
mfspr r3 ,S P R N _ D M I S S
tlbld r3
mfspr r3 ,S P R N _ S R R 1 / * N e e d t o r e s t o r e C R 0 * /
mtcrf 0 x80 ,r3
rfi
DataAddressInvalid :
mfspr r3 ,S P R N _ S R R 1
rlwinm r1 ,r3 ,9 ,6 ,6 / * G e t l o a d / s t o r e b i t * /
addis r1 ,r1 ,0 x20 0 0
mtspr S P R N _ D S I S R ,r1
mtctr r0 / * R e s t o r e C T R * /
andi. r2 ,r3 ,0 x F F F F / * C l e a r u p p e r b i t s o f S R R 1 * /
mtspr S P R N _ S R R 1 ,r2
mfspr r1 ,S P R N _ D M I S S / * G e t f a i l i n g a d d r e s s * /
rlwinm. r2 ,r2 ,0 ,3 1 ,3 1 / * C h e c k f o r l i t t l e e n d i a n a c c e s s * /
beq 2 0 f / * J u m p i f b i g e n d i a n * /
xori r1 ,r1 ,3
20 : mtspr S P R N _ D A R ,r1 / * S e t f a u l t a d d r e s s * /
mfmsr r0 / * R e s t o r e " n o r m a l " r e g i s t e r s * /
xoris r0 ,r0 ,M S R _ T G P R > > 1 6
mtcrf 0 x80 ,r3 / * R e s t o r e C R 0 * /
mtmsr r0
b D a t a A c c e s s
/ *
* Handle T L B m i s s f o r D A T A S t o r e o n 6 0 3 / 6 0 3 e
* /
. = 0 x1 2 0 0
DataStoreTLBMiss :
/ *
* r0 : stored c t r
* r1 : linux s t y l e p t e ( l a t e r b e c o m e s p p c h a r d w a r e p t e )
* r2 : ptr t o l i n u x - s t y l e p t e
* r3 : scratch
* /
mfctr r0
/* Get PTE (linux-style) and check access */
mfspr r3 ,S P R N _ D M I S S
lis r1 ,K E R N E L B A S E @h /* check if kernel address */
cmplw 0 ,r3 ,r1
mfspr r2 ,S P R N _ S P R G 3
li r1 ,_ P A G E _ R W | _ P A G E _ U S E R | _ P A G E _ P R E S E N T / * a c c e s s f l a g s * /
lwz r2 ,P G D I R ( r2 )
blt+ 1 1 2 f
lis r2 ,s w a p p e r _ p g _ d i r @ha /* if kernel address, use */
addi r2 ,r2 ,s w a p p e r _ p g _ d i r @l /* kernel page table */
mfspr r1 ,S P R N _ S R R 1 / * a n d M S R _ P R b i t f r o m S R R 1 * /
rlwinm r1 ,r1 ,3 2 - 1 2 ,2 9 ,2 9 / * s h i f t M S R _ P R t o _ P A G E _ U S E R p o s n * /
112 : tophys( r2 ,r2 )
rlwimi r2 ,r3 ,1 2 ,2 0 ,2 9 / * i n s e r t t o p 1 0 b i t s o f a d d r e s s * /
lwz r2 ,0 ( r2 ) / * g e t p m d e n t r y * /
rlwinm. r2 ,r2 ,0 ,0 ,1 9 / * e x t r a c t a d d r e s s o f p t e p a g e * /
beq- D a t a A d d r e s s I n v a l i d / * r e t u r n i f n o m a p p i n g * /
rlwimi r2 ,r3 ,2 2 ,2 0 ,2 9 / * i n s e r t n e x t 1 0 b i t s o f a d d r e s s * /
lwz r3 ,0 ( r2 ) / * g e t l i n u x - s t y l e p t e * /
andc. r1 ,r1 ,r3 / * c h e c k a c c e s s & ~ p e r m i s s i o n * /
bne- D a t a A d d r e s s I n v a l i d / * r e t u r n i f a c c e s s n o t p e r m i t t e d * /
ori r3 ,r3 ,_ P A G E _ A C C E S S E D | _ P A G E _ D I R T Y
/ *
* NOTE! W e a r e a s s u m i n g t h i s i s n o t a n S M P s y s t e m , o t h e r w i s e
* we w o u l d n e e d t o u p d a t e t h e p t e a t o m i c a l l y w i t h l w a r x / s t w c x .
* /
stw r3 ,0 ( r2 ) / * u p d a t e P T E ( a c c e s s e d / d i r t y b i t s ) * /
/* Convert linux-style PTE to low word of PPC-style PTE */
rlwimi r3 ,r3 ,3 2 - 1 ,3 0 ,3 0 / * _ P A G E _ U S E R - > P P m s b * /
li r1 ,0 x e 1 5 / * c l e a r o u t r e s e r v e d b i t s a n d M * /
andc r1 ,r3 ,r1 / * P P = u s e r ? 2 : 0 * /
mtspr S P R N _ R P A ,r1
mfspr r3 ,S P R N _ D M I S S
tlbld r3
mfspr r3 ,S P R N _ S R R 1 / * N e e d t o r e s t o r e C R 0 * /
mtcrf 0 x80 ,r3
rfi
# ifndef C O N F I G _ A L T I V E C
2005-10-01 12:43:42 +04:00
# define a l t i v e c _ a s s i s t _ e x c e p t i o n u n k n o w n _ e x c e p t i o n
2005-09-26 10:04:21 +04:00
# endif
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x13 0 0 , T r a p _ 1 3 , i n s t r u c t i o n _ b r e a k p o i n t _ e x c e p t i o n , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
EXCEPTION( 0 x14 0 0 , S M I , S M I E x c e p t i o n , E X C _ X F E R _ E E )
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x15 0 0 , T r a p _ 1 5 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x16 0 0 , T r a p _ 1 6 , a l t i v e c _ a s s i s t _ e x c e p t i o n , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
EXCEPTION( 0 x17 0 0 , T r a p _ 1 7 , T A U E x c e p t i o n , E X C _ X F E R _ S T D )
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x18 0 0 , T r a p _ 1 8 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x19 0 0 , T r a p _ 1 9 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 a00 , T r a p _ 1 a , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 b00 , T r a p _ 1 b , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 c00 , T r a p _ 1 c , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 d00 , T r a p _ 1 d , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 e 0 0 , T r a p _ 1 e , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 f00 , T r a p _ 1 f , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
EXCEPTION( 0 x20 0 0 , R u n M o d e , R u n M o d e E x c e p t i o n , E X C _ X F E R _ E E )
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x21 0 0 , T r a p _ 2 1 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x22 0 0 , T r a p _ 2 2 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x23 0 0 , T r a p _ 2 3 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x24 0 0 , T r a p _ 2 4 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x25 0 0 , T r a p _ 2 5 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x26 0 0 , T r a p _ 2 6 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x27 0 0 , T r a p _ 2 7 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x28 0 0 , T r a p _ 2 8 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x29 0 0 , T r a p _ 2 9 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x2 a00 , T r a p _ 2 a , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x2 b00 , T r a p _ 2 b , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x2 c00 , T r a p _ 2 c , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x2 d00 , T r a p _ 2 d , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x2 e 0 0 , T r a p _ 2 e , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x2 f00 , M O L T r a m p o l i n e , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E _ L I T E )
2005-09-26 10:04:21 +04:00
.globl mol_trampoline
.set mol_ t r a m p o l i n e , i 0 x2 f00
. = 0 x3 0 0 0
AltiVecUnavailable :
EXCEPTION_ P R O L O G
# ifdef C O N F I G _ A L T I V E C
bne l o a d _ u p _ a l t i v e c / * i f f r o m u s e r , j u s t l o a d i t u p * /
# endif / * C O N F I G _ A L T I V E C * /
2006-02-22 09:42:37 +03:00
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2005-10-01 12:43:42 +04:00
EXC_ X F E R _ E E _ L I T E ( 0 x f20 , a l t i v e c _ u n a v a i l a b l e _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
2005-12-16 05:02:04 +03:00
PerformanceMonitor :
EXCEPTION_ P R O L O G
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
EXC_ X F E R _ S T D ( 0 x f00 , p e r f o r m a n c e _ m o n i t o r _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ A L T I V E C
/ * Note t h a t t h e A l t i V e c s u p p o r t i s c l o s e l y m o d e l e d a f t e r t h e F P
* support. C h a n g e s t o o n e a r e l i k e l y t o b e a p p l i c a b l e t o t h e
* other! * /
load_up_altivec :
/ *
* Disable A l t i V e c f o r t h e t a s k w h i c h h a d A l t i V e c p r e v i o u s l y ,
* and s a v e i t s A l t i V e c r e g i s t e r s i n i t s t h r e a d _ s t r u c t .
* Enables A l t i V e c f o r u s e i n t h e k e r n e l o n r e t u r n .
* On S M P w e k n o w t h e A l t i V e c u n i t s a r e f r e e , s i n c e w e g i v e i t u p e v e r y
* switch. - - K u m a r
* /
mfmsr r5
oris r5 ,r5 ,M S R _ V E C @h
MTMSRD( r5 ) / * e n a b l e u s e o f A l t i V e c n o w * /
isync
/ *
* For S M P , w e d o n ' t d o l a z y A l t i V e c s w i t c h i n g b e c a u s e i t j u s t g e t s t o o
* horrendously c o m p l e x , e s p e c i a l l y w h e n a t a s k s w i t c h e s f r o m o n e C P U
* to a n o t h e r . I n s t e a d w e c a l l g i v e u p _ a l t i v e c i n s w i t c h _ t o .
* /
# ifndef C O N F I G _ S M P
tophys( r6 ,0 )
addis r3 ,r6 ,l a s t _ t a s k _ u s e d _ a l t i v e c @ha
lwz r4 ,l a s t _ t a s k _ u s e d _ a l t i v e c @l(r3)
cmpwi 0 ,r4 ,0
beq 1 f
add r4 ,r4 ,r6
addi r4 ,r4 ,T H R E A D / * w a n t T H R E A D o f l a s t _ t a s k _ u s e d _ a l t i v e c * /
SAVE_ 3 2 V R S ( 0 ,r10 ,r4 )
mfvscr v r0
li r10 ,T H R E A D _ V S C R
stvx v r0 ,r10 ,r4
lwz r5 ,P T _ R E G S ( r4 )
add r5 ,r5 ,r6
lwz r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
lis r10 ,M S R _ V E C @h
andc r4 ,r4 ,r10 / * d i s a b l e a l t i v e c f o r p r e v i o u s t a s k * /
stw r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
1 :
# endif / * C O N F I G _ S M P * /
/* enable use of AltiVec after return */
oris r9 ,r9 ,M S R _ V E C @h
mfspr r5 ,S P R N _ S P R G 3 / * c u r r e n t t a s k ' s T H R E A D ( p h y s ) * /
li r4 ,1
li r10 ,T H R E A D _ V S C R
stw r4 ,T H R E A D _ U S E D _ V R ( r5 )
lvx v r0 ,r10 ,r5
mtvscr v r0
REST_ 3 2 V R S ( 0 ,r10 ,r5 )
# ifndef C O N F I G _ S M P
subi r4 ,r5 ,T H R E A D
sub r4 ,r4 ,r6
stw r4 ,l a s t _ t a s k _ u s e d _ a l t i v e c @l(r3)
# endif / * C O N F I G _ S M P * /
/* restore registers and return */
/* we haven't used ctr or xer or lr */
b f a s t _ e x c e p t i o n _ r e t u r n
/ *
* AltiVec u n a v a i l a b l e t r a p f r o m k e r n e l - p r i n t a m e s s a g e , b u t l e t
* the t a s k u s e A l t i V e c i n t h e k e r n e l u n t i l i t r e t u r n s t o u s e r m o d e .
* /
KernelAltiVec :
lwz r3 ,_ M S R ( r1 )
oris r3 ,r3 ,M S R _ V E C @h
stw r3 ,_ M S R ( r1 ) / * e n a b l e u s e o f A l t i V e c a f t e r r e t u r n * /
lis r3 ,8 7 f @h
ori r3 ,r3 ,8 7 f @l
mr r4 ,r2 / * c u r r e n t * /
lwz r5 ,_ N I P ( r1 )
bl p r i n t k
b r e t _ f r o m _ e x c e p t
87 : .string " AltiVec used in kernel (task=%p, pc=%x) \n "
.align 4 , 0
/ *
* giveup_ a l t i v e c ( t s k )
* Disable A l t i V e c f o r t h e t a s k g i v e n a s t h e a r g u m e n t ,
* and s a v e t h e A l t i V e c r e g i s t e r s i n i t s t h r e a d _ s t r u c t .
* Enables A l t i V e c f o r u s e i n t h e k e r n e l o n r e t u r n .
* /
.globl giveup_altivec
giveup_altivec :
mfmsr r5
oris r5 ,r5 ,M S R _ V E C @h
SYNC
MTMSRD( r5 ) / * e n a b l e u s e o f A l t i V e c n o w * /
isync
cmpwi 0 ,r3 ,0
beqlr- / * i f n o p r e v i o u s o w n e r , d o n e * /
addi r3 ,r3 ,T H R E A D / * w a n t T H R E A D o f t a s k * /
lwz r5 ,P T _ R E G S ( r3 )
cmpwi 0 ,r5 ,0
SAVE_ 3 2 V R S ( 0 , r4 , r3 )
mfvscr v r0
li r4 ,T H R E A D _ V S C R
stvx v r0 ,r4 ,r3
beq 1 f
lwz r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
lis r3 ,M S R _ V E C @h
andc r4 ,r4 ,r3 / * d i s a b l e A l t i V e c f o r p r e v i o u s t a s k * /
stw r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
1 :
# ifndef C O N F I G _ S M P
li r5 ,0
lis r4 ,l a s t _ t a s k _ u s e d _ a l t i v e c @ha
stw r5 ,l a s t _ t a s k _ u s e d _ a l t i v e c @l(r4)
# endif / * C O N F I G _ S M P * /
blr
# endif / * C O N F I G _ A L T I V E C * /
/ *
* This c o d e i s j u m p e d t o f r o m t h e s t a r t u p c o d e t o c o p y
* the k e r n e l i m a g e t o p h y s i c a l a d d r e s s 0 .
* /
relocate_kernel :
addis r9 ,r26 ,k l i m i t @ha /* fetch klimit */
lwz r25 ,k l i m i t @l(r9)
addis r25 ,r25 ,- K E R N E L B A S E @h
li r3 ,0 / * D e s t i n a t i o n b a s e a d d r e s s * /
li r6 ,0 / * D e s t i n a t i o n o f f s e t * /
li r5 ,0 x40 0 0 / * # b y t e s o f m e m o r y t o c o p y * /
bl c o p y _ a n d _ f l u s h / * c o p y t h e f i r s t 0 x40 0 0 b y t e s * /
addi r0 ,r3 ,4 f @l /* jump to the address of 4f */
mtctr r0 / * i n c o p y a n d d o t h e r e s t . * /
bctr / * j u m p t o t h e c o p y * /
4 : mr r5 ,r25
bl c o p y _ a n d _ f l u s h / * c o p y t h e r e s t * /
b t u r n _ o n _ m m u
/ *
* Copy r o u t i n e u s e d t o c o p y t h e k e r n e l t o s t a r t a t p h y s i c a l a d d r e s s 0
* and f l u s h a n d i n v a l i d a t e t h e c a c h e s a s n e e d e d .
* r3 = d e s t a d d r , r4 = s o u r c e a d d r , r5 = c o p y l i m i t , r6 = s t a r t o f f s e t
* on e x i t , r3 , r4 , r5 a r e u n c h a n g e d , r6 i s u p d a t e d t o b e > = r5 .
* /
2005-10-18 08:19:41 +04:00
_ GLOBAL( c o p y _ a n d _ f l u s h )
2005-09-26 10:04:21 +04:00
addi r5 ,r5 ,- 4
addi r6 ,r6 ,- 4
2005-10-17 05:50:32 +04:00
4 : li r0 ,L 1 _ C A C H E _ B Y T E S / 4
2005-09-26 10:04:21 +04:00
mtctr r0
3 : addi r6 ,r6 ,4 / * c o p y a c a c h e l i n e * /
lwzx r0 ,r6 ,r4
stwx r0 ,r6 ,r3
bdnz 3 b
dcbst r6 ,r3 / * w r i t e i t t o m e m o r y * /
sync
icbi r6 ,r3 / * f l u s h t h e i c a c h e l i n e * /
cmplw 0 ,r6 ,r5
blt 4 b
sync / * a d d i t i o n a l s y n c n e e d e d o n g 4 * /
isync
addi r5 ,r5 ,4
addi r6 ,r6 ,4
blr
# ifdef C O N F I G _ A P U S
/ *
* On A P U S t h e p h y s i c a l b a s e a d d r e s s o f t h e k e r n e l i s n o t k n o w n a t c o m p i l e
* time, w h i c h m e a n s t h e _ _ p a / _ _ v a c o n s t a n t s u s e d a r e i n c o r r e c t . I n t h e
* _ _ init s e c t i o n i s r e c o r d e d t h e v i r t u a l a d d r e s s e s o f i n s t r u c t i o n s u s i n g
* these c o n s t a n t s , s o a l l t h a t h a s t o b e d o n e i s f i x t h e s e b e f o r e
* continuing t h e k e r n e l b o o t .
*
* r4 = T h e p h y s i c a l a d d r e s s o f t h e k e r n e l b a s e .
* /
fix_mem_constants :
mr r10 ,r4
addis r10 ,r10 ,- K E R N E L B A S E @h /* virt_to_phys constant */
neg r11 ,r10 / * p h y s _ t o _ v i r t c o n s t a n t * /
lis r12 ,_ _ v t o p _ t a b l e _ b e g i n @h
ori r12 ,r12 ,_ _ v t o p _ t a b l e _ b e g i n @l
add r12 ,r12 ,r10 / * t a b l e b e g i n p h y s a d d r e s s * /
lis r13 ,_ _ v t o p _ t a b l e _ e n d @h
ori r13 ,r13 ,_ _ v t o p _ t a b l e _ e n d @l
add r13 ,r13 ,r10 / * t a b l e e n d p h y s a d d r e s s * /
subi r12 ,r12 ,4
subi r13 ,r13 ,4
1 : lwzu r14 ,4 ( r12 ) / * v i r t a d d r e s s o f i n s t r u c t i o n * /
add r14 ,r14 ,r10 / * p h y s a d d r e s s o f i n s t r u c t i o n * /
lwz r15 ,0 ( r14 ) / * i n s t r u c t i o n , n o w i n s e r t t o p * /
rlwimi r15 ,r10 ,1 6 ,1 6 ,3 1 / * h a l f o f v p c o n s t i n l o w h a l f * /
stw r15 ,0 ( r14 ) / * o f i n s t r u c t i o n a n d r e s t o r e . * /
dcbst r0 ,r14 / * w r i t e i t t o m e m o r y * /
sync
icbi r0 ,r14 / * f l u s h t h e i c a c h e l i n e * /
cmpw r12 ,r13
bne 1 b
sync / * a d d i t i o n a l s y n c n e e d e d o n g 4 * /
isync
/ *
* Map t h e m e m o r y w h e r e t h e e x c e p t i o n h a n d l e r s w i l l
* be c o p i e d t o w h e n h a s h c o n s t a n t s h a v e b e e n p a t c h e d .
* /
# ifdef C O N F I G _ A P U S _ F A S T _ E X C E P T
lis r8 ,0 x f f f0
# else
lis r8 ,0
# endif
ori r8 ,r8 ,0 x2 / * 1 2 8 K B , s u p e r v i s o r * /
mtspr S P R N _ D B A T 3 U ,r8
mtspr S P R N _ D B A T 3 L ,r8
lis r12 ,_ _ p t o v _ t a b l e _ b e g i n @h
ori r12 ,r12 ,_ _ p t o v _ t a b l e _ b e g i n @l
add r12 ,r12 ,r10 / * t a b l e b e g i n p h y s a d d r e s s * /
lis r13 ,_ _ p t o v _ t a b l e _ e n d @h
ori r13 ,r13 ,_ _ p t o v _ t a b l e _ e n d @l
add r13 ,r13 ,r10 / * t a b l e e n d p h y s a d d r e s s * /
subi r12 ,r12 ,4
subi r13 ,r13 ,4
1 : lwzu r14 ,4 ( r12 ) / * v i r t a d d r e s s o f i n s t r u c t i o n * /
add r14 ,r14 ,r10 / * p h y s a d d r e s s o f i n s t r u c t i o n * /
lwz r15 ,0 ( r14 ) / * i n s t r u c t i o n , n o w i n s e r t t o p * /
rlwimi r15 ,r11 ,1 6 ,1 6 ,3 1 / * h a l f o f p v c o n s t i n l o w h a l f * /
stw r15 ,0 ( r14 ) / * o f i n s t r u c t i o n a n d r e s t o r e . * /
dcbst r0 ,r14 / * w r i t e i t t o m e m o r y * /
sync
icbi r0 ,r14 / * f l u s h t h e i c a c h e l i n e * /
cmpw r12 ,r13
bne 1 b
sync / * a d d i t i o n a l s y n c n e e d e d o n g 4 * /
isync / * N o s p e c u l a t i v e l o a d i n g u n t i l n o w * /
blr
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Please n o t e t h a t o n A P U S t h e e x c e p t i o n h a n d l e r s a r e l o c a t e d a t t h e
* physical a d d r e s s 0 x f f f00 0 0 . F o r t h i s r e a s o n , t h e e x c e p t i o n h a n d l e r s
* cannot u s e r e l a t i v e b r a n c h e s t o a c c e s s t h e c o d e b e l o w .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
# endif / * C O N F I G _ A P U S * /
# ifdef C O N F I G _ S M P
# ifdef C O N F I G _ G E M I N I
.globl __secondary_start_gemini
__secondary_start_gemini :
mfspr r4 ,S P R N _ H I D 0
ori r4 ,r4 ,H I D 0 _ I C F I
li r3 ,0
ori r3 ,r3 ,H I D 0 _ I C E
andc r4 ,r4 ,r3
mtspr S P R N _ H I D 0 ,r4
sync
b _ _ s e c o n d a r y _ s t a r t
# endif / * C O N F I G _ G E M I N I * /
2006-06-18 02:52:44 +04:00
.globl __secondary_start_mpc86xx
__secondary_start_mpc86xx :
mfspr r3 , S P R N _ P I R
stw r3 , _ _ s e c o n d a r y _ h o l d _ a c k n o w l e d g e @l(0)
mr r24 , r3 / * c p u # * /
b _ _ s e c o n d a r y _ s t a r t
2005-09-26 10:04:21 +04:00
.globl __secondary_start_pmac_0
__secondary_start_pmac_0 :
/* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
li r24 ,0
b 1 f
li r24 ,1
b 1 f
li r24 ,2
b 1 f
li r24 ,3
1 :
/ * on p o w e r s u r g e , w e c o m e i n h e r e w i t h I R =0 a n d D R =1 , a n d D B A T 0
set t o m a p t h e 0 x f00 0 0 0 0 0 - 0 x f f f f f f f f r e g i o n * /
mfmsr r0
rlwinm r0 ,r0 ,0 ,2 8 ,2 6 / * c l e a r D R ( 0 x10 ) * /
SYNC
mtmsr r0
isync
.globl __secondary_start
__secondary_start :
/* Copy some CPU settings from CPU 0 */
bl _ _ r e s t o r e _ c p u _ s e t u p
lis r3 ,- K E R N E L B A S E @h
mr r4 ,r24
bl c a l l _ s e t u p _ c p u / * C a l l s e t u p _ c p u f o r t h i s C P U * /
# ifdef C O N F I G _ 6 x x
lis r3 ,- K E R N E L B A S E @h
bl i n i t _ i d l e _ 6 x x
# endif / * C O N F I G _ 6 x x * /
/* get current_thread_info and current */
lis r1 ,s e c o n d a r y _ t i @ha
tophys( r1 ,r1 )
lwz r1 ,s e c o n d a r y _ t i @l(r1)
tophys( r2 ,r1 )
lwz r2 ,T I _ T A S K ( r2 )
/* stack */
addi r1 ,r1 ,T H R E A D _ S I Z E - S T A C K _ F R A M E _ O V E R H E A D
li r0 ,0
tophys( r3 ,r1 )
stw r0 ,0 ( r3 )
/* load up the MMU */
bl l o a d _ u p _ m m u
/* ptr to phys current thread */
tophys( r4 ,r2 )
addi r4 ,r4 ,T H R E A D / * p h y s a d d r e s s o f o u r t h r e a d _ s t r u c t * /
CLR_ T O P 3 2 ( r4 )
mtspr S P R N _ S P R G 3 ,r4
li r3 ,0
mtspr S P R N _ S P R G 2 ,r3 / * 0 = > n o t i n R T A S * /
/* enable MMU and jump to start_secondary */
li r4 ,M S R _ K E R N E L
FIX_ S R R 1 ( r4 ,r5 )
lis r3 ,s t a r t _ s e c o n d a r y @h
ori r3 ,r3 ,s t a r t _ s e c o n d a r y @l
mtspr S P R N _ S R R 0 ,r3
mtspr S P R N _ S R R 1 ,r4
SYNC
RFI
# endif / * C O N F I G _ S M P * /
/ *
* Those g e n e r i c d u m m y f u n c t i o n s a r e k e p t f o r C P U s n o t
* included i n C O N F I G _ 6 x x
* /
2005-10-06 06:49:05 +04:00
# if ! d e f i n e d ( C O N F I G _ 6 x x )
2005-09-26 10:04:21 +04:00
_ GLOBAL( _ _ s a v e _ c p u _ s e t u p )
blr
_ GLOBAL( _ _ r e s t o r e _ c p u _ s e t u p )
blr
2005-10-06 06:49:05 +04:00
# endif / * ! d e f i n e d ( C O N F I G _ 6 x x ) * /
2005-09-26 10:04:21 +04:00
/ *
* Load s t u f f i n t o t h e M M U . I n t e n d e d t o b e c a l l e d w i t h
* IR=0 a n d D R =0 .
* /
load_up_mmu :
sync / * F o r c e a l l P T E u p d a t e s t o f i n i s h * /
isync
tlbia / * C l e a r a l l T L B e n t r i e s * /
sync / * w a i t f o r t l b i a / t l b i e t o f i n i s h * /
TLBSYNC / * . . . o n a l l C P U s * /
/* Load the SDR1 register (hash table base & size) */
lis r6 ,_ S D R 1 @ha
tophys( r6 ,r6 )
lwz r6 ,_ S D R 1 @l(r6)
mtspr S P R N _ S D R 1 ,r6
li r0 ,1 6 / * l o a d u p s e g m e n t r e g i s t e r v a l u e s * /
mtctr r0 / * f o r c o n t e x t 0 * /
lis r3 ,0 x20 0 0 / * K u = 1 , V S I D = 0 * /
li r4 ,0
3 : mtsrin r3 ,r4
addi r3 ,r3 ,0 x11 1 / * i n c r e m e n t V S I D * /
addis r4 ,r4 ,0 x10 0 0 / * a d d r e s s o f n e x t s e g m e n t * /
bdnz 3 b
2005-10-06 06:49:05 +04:00
2005-09-26 10:04:21 +04:00
/ * Load t h e B A T r e g i s t e r s w i t h t h e v a l u e s s e t u p b y M M U _ i n i t .
MMU_ i n i t t a k e s c a r e o f w h e t h e r w e ' r e o n a 6 0 1 o r n o t . * /
mfpvr r3
srwi r3 ,r3 ,1 6
cmpwi r3 ,1
lis r3 ,B A T S @ha
addi r3 ,r3 ,B A T S @l
tophys( r3 ,r3 )
LOAD_ B A T ( 0 ,r3 ,r4 ,r5 )
LOAD_ B A T ( 1 ,r3 ,r4 ,r5 )
LOAD_ B A T ( 2 ,r3 ,r4 ,r5 )
LOAD_ B A T ( 3 ,r3 ,r4 ,r5 )
2006-06-18 02:52:44 +04:00
BEGIN_ F T R _ S E C T I O N
LOAD_ B A T ( 4 ,r3 ,r4 ,r5 )
LOAD_ B A T ( 5 ,r3 ,r4 ,r5 )
LOAD_ B A T ( 6 ,r3 ,r4 ,r5 )
LOAD_ B A T ( 7 ,r3 ,r4 ,r5 )
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ H A S _ H I G H _ B A T S )
2005-09-26 10:04:21 +04:00
blr
/ *
* This i s w h e r e t h e m a i n k e r n e l c o d e s t a r t s .
* /
start_here :
/* ptr to current */
lis r2 ,i n i t _ t a s k @h
ori r2 ,r2 ,i n i t _ t a s k @l
/* Set up for using our exception vectors */
/* ptr to phys current thread */
tophys( r4 ,r2 )
addi r4 ,r4 ,T H R E A D / * i n i t t a s k ' s T H R E A D * /
CLR_ T O P 3 2 ( r4 )
mtspr S P R N _ S P R G 3 ,r4
li r3 ,0
mtspr S P R N _ S P R G 2 ,r3 / * 0 = > n o t i n R T A S * /
/* stack */
lis r1 ,i n i t _ t h r e a d _ u n i o n @ha
addi r1 ,r1 ,i n i t _ t h r e a d _ u n i o n @l
li r0 ,0
stwu r0 ,T H R E A D _ S I Z E - S T A C K _ F R A M E _ O V E R H E A D ( r1 )
/ *
2005-10-06 06:49:05 +04:00
* Do e a r l y p l a t f o r m - s p e c i f i c i n i t i a l i z a t i o n ,
2005-09-26 10:04:21 +04:00
* and s e t u p t h e M M U .
* /
mr r3 ,r31
mr r4 ,r30
bl m a c h i n e _ i n i t
2005-11-11 14:34:43 +03:00
bl _ _ s a v e _ c p u _ s e t u p
2005-09-26 10:04:21 +04:00
bl M M U _ i n i t
# ifdef C O N F I G _ A P U S
/* Copy exception code to exception vector base on APUS. */
lis r4 ,K E R N E L B A S E @h
# ifdef C O N F I G _ A P U S _ F A S T _ E X C E P T
lis r3 ,0 x f f f0 / * C o p y t o 0 x f f f00 0 0 0 * /
# else
lis r3 ,0 / * C o p y t o 0 x00 0 0 0 0 0 0 * /
# endif
li r5 ,0 x40 0 0 / * # b y t e s o f m e m o r y t o c o p y * /
li r6 ,0
bl c o p y _ a n d _ f l u s h / * c o p y t h e f i r s t 0 x40 0 0 b y t e s * /
# endif / * C O N F I G _ A P U S * /
/ *
* Go b a c k t o r u n n i n g u n m a p p e d s o w e c a n l o a d u p n e w v a l u e s
* for S D R 1 ( h a s h t a b l e p o i n t e r ) a n d t h e s e g m e n t r e g i s t e r s
* and c h a n g e t o u s i n g o u r e x c e p t i o n v e c t o r s .
* /
lis r4 ,2 f @h
ori r4 ,r4 ,2 f @l
tophys( r4 ,r4 )
li r3 ,M S R _ K E R N E L & ~ ( M S R _ I R | M S R _ D R )
FIX_ S R R 1 ( r3 ,r5 )
mtspr S P R N _ S R R 0 ,r4
mtspr S P R N _ S R R 1 ,r3
SYNC
RFI
/* Load up the kernel context */
2 : bl l o a d _ u p _ m m u
# ifdef C O N F I G _ B D I _ S W I T C H
/ * Add h e l p e r i n f o r m a t i o n f o r t h e A b a t r o n b d i G D B d e b u g g e r .
* We d o t h i s h e r e b e c a u s e w e k n o w t h e m m u i s d i s a b l e d , a n d
* will b e e n a b l e d f o r r e a l i n j u s t a f e w i n s t r u c t i o n s .
* /
lis r5 , a b a t r o n _ p t e p t r s @h
ori r5 , r5 , a b a t r o n _ p t e p t r s @l
stw r5 , 0 x f0 ( r0 ) / * T h i s m u c h m a t c h y o u r A b a t r o n c o n f i g * /
lis r6 , s w a p p e r _ p g _ d i r @h
ori r6 , r6 , s w a p p e r _ p g _ d i r @l
tophys( r5 , r5 )
stw r6 , 0 ( r5 )
# endif / * C O N F I G _ B D I _ S W I T C H * /
/* Now turn on the MMU for real! */
li r4 ,M S R _ K E R N E L
FIX_ S R R 1 ( r4 ,r5 )
lis r3 ,s t a r t _ k e r n e l @h
ori r3 ,r3 ,s t a r t _ k e r n e l @l
mtspr S P R N _ S R R 0 ,r3
mtspr S P R N _ S R R 1 ,r4
SYNC
RFI
/ *
* Set u p t h e s e g m e n t r e g i s t e r s f o r a n e w c o n t e x t .
* /
_ GLOBAL( s e t _ c o n t e x t )
mulli r3 ,r3 ,8 9 7 / * m u l t i p l y c o n t e x t b y s k e w f a c t o r * /
rlwinm r3 ,r3 ,4 ,8 ,2 7 / * V S I D = ( c o n t e x t & 0 x f f f f f ) < < 4 * /
addis r3 ,r3 ,0 x60 0 0 / * S e t K s , K u b i t s * /
li r0 ,N U M _ U S E R _ S E G M E N T S
mtctr r0
# ifdef C O N F I G _ B D I _ S W I T C H
/ * Context s w i t c h t h e P T E p o i n t e r f o r t h e A b a t r o n B D I 2 0 0 0 .
* The P G D I R i s p a s s e d a s s e c o n d a r g u m e n t .
* /
lis r5 , K E R N E L B A S E @h
lwz r5 , 0 x f0 ( r5 )
stw r4 , 0 x4 ( r5 )
# endif
li r4 ,0
isync
3 :
mtsrin r3 ,r4
addi r3 ,r3 ,0 x11 1 / * n e x t V S I D * /
rlwinm r3 ,r3 ,0 ,8 ,3 / * c l e a r o u t a n y o v e r f l o w f r o m V S I D f i e l d * /
addis r4 ,r4 ,0 x10 0 0 / * a d d r e s s o f n e x t s e g m e n t * /
bdnz 3 b
sync
isync
blr
/ *
* An u n d o c u m e n t e d " f e a t u r e " o f 6 0 4 e r e q u i r e s t h a t t h e v b i t
* be c l e a r e d b e f o r e c h a n g i n g B A T v a l u e s .
*
* Also, n e w e r I B M f i r m w a r e d o e s n o t c l e a r b a t 3 a n d 4 s o
* this m a k e s s u r e i t ' s d o n e .
* - - Cort
* /
clear_bats :
li r10 ,0
mfspr r9 ,S P R N _ P V R
rlwinm r9 ,r9 ,1 6 ,1 6 ,3 1 / * r9 = 1 f o r 6 0 1 , 4 f o r 6 0 4 * /
cmpwi r9 , 1
beq 1 f
mtspr S P R N _ D B A T 0 U ,r10
mtspr S P R N _ D B A T 0 L ,r10
mtspr S P R N _ D B A T 1 U ,r10
mtspr S P R N _ D B A T 1 L ,r10
mtspr S P R N _ D B A T 2 U ,r10
mtspr S P R N _ D B A T 2 L ,r10
mtspr S P R N _ D B A T 3 U ,r10
mtspr S P R N _ D B A T 3 L ,r10
1 :
mtspr S P R N _ I B A T 0 U ,r10
mtspr S P R N _ I B A T 0 L ,r10
mtspr S P R N _ I B A T 1 U ,r10
mtspr S P R N _ I B A T 1 L ,r10
mtspr S P R N _ I B A T 2 U ,r10
mtspr S P R N _ I B A T 2 L ,r10
mtspr S P R N _ I B A T 3 U ,r10
mtspr S P R N _ I B A T 3 L ,r10
BEGIN_ F T R _ S E C T I O N
/ * Here' s a t w e a k : a t t h i s p o i n t , C P U s e t u p h a v e
* not b e e n c a l l e d y e t , s o H I G H _ B A T _ E N m a y n o t b e
* set i n H I D 0 f o r t h e 7 4 5 x p r o c e s s o r s . H o w e v e r , i t
* seems t h a t d o e s n ' t a f f e c t o u r a b i l i t y t o a c t u a l l y
* write t o t h e s e S P R s .
* /
mtspr S P R N _ D B A T 4 U ,r10
mtspr S P R N _ D B A T 4 L ,r10
mtspr S P R N _ D B A T 5 U ,r10
mtspr S P R N _ D B A T 5 L ,r10
mtspr S P R N _ D B A T 6 U ,r10
mtspr S P R N _ D B A T 6 L ,r10
mtspr S P R N _ D B A T 7 U ,r10
mtspr S P R N _ D B A T 7 L ,r10
mtspr S P R N _ I B A T 4 U ,r10
mtspr S P R N _ I B A T 4 L ,r10
mtspr S P R N _ I B A T 5 U ,r10
mtspr S P R N _ I B A T 5 L ,r10
mtspr S P R N _ I B A T 6 U ,r10
mtspr S P R N _ I B A T 6 L ,r10
mtspr S P R N _ I B A T 7 U ,r10
mtspr S P R N _ I B A T 7 L ,r10
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ H A S _ H I G H _ B A T S )
blr
flush_tlbs :
lis r10 , 0 x40
1 : addic. r10 , r10 , - 0 x10 0 0
tlbie r10
blt 1 b
sync
blr
mmu_off :
addi r4 , r3 , _ _ a f t e r _ m m u _ o f f - _ s t a r t
mfmsr r3
andi. r0 ,r3 ,M S R _ D R | M S R _ I R / * M M U e n a b l e d ? * /
beqlr
andc r3 ,r3 ,r0
mtspr S P R N _ S R R 0 ,r4
mtspr S P R N _ S R R 1 ,r3
sync
RFI
/ *
* Use t h e f i r s t p a i r o f B A T r e g i s t e r s t o m a p t h e 1 s t 1 6 M B
* of R A M t o K E R N E L B A S E . F r o m t h i s p o i n t o n w e c a n ' t s a f e l y
* call O F a n y m o r e .
* /
initial_bats :
lis r11 ,K E R N E L B A S E @h
mfspr r9 ,S P R N _ P V R
rlwinm r9 ,r9 ,1 6 ,1 6 ,3 1 / * r9 = 1 f o r 6 0 1 , 4 f o r 6 0 4 * /
cmpwi 0 ,r9 ,1
bne 4 f
ori r11 ,r11 ,4 / * s e t u p B A T r e g i s t e r s f o r 6 0 1 * /
li r8 ,0 x7 f / * v a l i d , b l o c k l e n g t h = 8 M B * /
oris r9 ,r11 ,0 x80 0 0 0 0 @h /* set up BAT reg for 2nd 8M */
oris r10 ,r8 ,0 x80 0 0 0 0 @h /* set up BAT reg for 2nd 8M */
mtspr S P R N _ I B A T 0 U ,r11 / * N . B . 6 0 1 h a s v a l i d b i t i n * /
mtspr S P R N _ I B A T 0 L ,r8 / * l o w e r B A T r e g i s t e r * /
mtspr S P R N _ I B A T 1 U ,r9
mtspr S P R N _ I B A T 1 L ,r10
isync
blr
4 : tophys( r8 ,r11 )
# ifdef C O N F I G _ S M P
ori r8 ,r8 ,0 x12 / * R / W a c c e s s , M =1 * /
# else
ori r8 ,r8 ,2 / * R / W a c c e s s * /
# endif / * C O N F I G _ S M P * /
# ifdef C O N F I G _ A P U S
ori r11 ,r11 ,B L _ 8 M < < 2 | 0 x2 / * s e t u p 8 M B B A T r e g i s t e r s f o r 6 0 4 * /
# else
ori r11 ,r11 ,B L _ 2 5 6 M < < 2 | 0 x2 / * s e t u p B A T r e g i s t e r s f o r 6 0 4 * /
# endif / * C O N F I G _ A P U S * /
mtspr S P R N _ D B A T 0 L ,r8 / * N . B . 6 x x ( n o t 6 0 1 ) h a v e v a l i d * /
mtspr S P R N _ D B A T 0 U ,r11 / * b i t i n u p p e r B A T r e g i s t e r * /
mtspr S P R N _ I B A T 0 L ,r8
mtspr S P R N _ I B A T 0 U ,r11
isync
blr
2005-11-23 09:57:25 +03:00
# if ! d e f i n e d ( C O N F I G _ A P U S ) & & d e f i n e d ( C O N F I G _ B O O T X _ T E X T )
setup_disp_bat :
/ *
* setup t h e d i s p l a y b a t p r e p a r e d f o r u s i n p r o m . c
* /
mflr r8
bl r e l o c _ o f f s e t
mtlr r8
addis r8 ,r3 ,d i s p _ B A T @ha
addi r8 ,r8 ,d i s p _ B A T @l
cmpwi c r0 ,r8 ,0
beqlr
lwz r11 ,0 ( r8 )
lwz r8 ,4 ( r8 )
mfspr r9 ,S P R N _ P V R
rlwinm r9 ,r9 ,1 6 ,1 6 ,3 1 / * r9 = 1 f o r 6 0 1 , 4 f o r 6 0 4 * /
cmpwi 0 ,r9 ,1
beq 1 f
mtspr S P R N _ D B A T 3 L ,r8
mtspr S P R N _ D B A T 3 U ,r11
blr
1 : mtspr S P R N _ I B A T 3 L ,r8
mtspr S P R N _ I B A T 3 U ,r11
blr
# endif / * ! d e f i n e d ( C O N F I G _ A P U S ) & & d e f i n e d ( C O N F I G _ B O O T X _ T E X T ) * /
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ 8 2 6 0
/ * Jump i n t o t h e s y s t e m r e s e t f o r t h e r o m .
* We f i r s t d i s a b l e t h e M M U , a n d t h e n j u m p t o t h e R O M r e s e t a d d r e s s .
*
* r3 i s t h e b o a r d i n f o s t r u c t u r e , r4 i s t h e l o c a t i o n f o r s t a r t i n g .
* I u s e t h i s f o r b u i l d i n g a s m a l l k e r n e l t h a t c a n l o a d o t h e r k e r n e l s ,
* rather t h a n t r y i n g t o w r i t e o r r e l y o n a r o m m o n i t o r t h a t c a n t f t p l o a d .
* /
.globl m8260_gorom
m8260_gorom :
mfmsr r0
rlwinm r0 ,r0 ,0 ,1 7 ,1 5 / * c l e a r M S R _ E E i n r0 * /
sync
mtmsr r0
sync
mfspr r11 , S P R N _ H I D 0
lis r10 , 0
ori r10 ,r10 ,H I D 0 _ I C E | H I D 0 _ D C E
andc r11 , r11 , r10
mtspr S P R N _ H I D 0 , r11
isync
li r5 , M S R _ M E | M S R _ R I
lis r6 ,2 f @h
addis r6 ,r6 ,- K E R N E L B A S E @h
ori r6 ,r6 ,2 f @l
mtspr S P R N _ S R R 0 ,r6
mtspr S P R N _ S R R 1 ,r5
isync
sync
rfi
2 :
mtlr r4
blr
# endif
/ *
* We p u t a f e w t h i n g s h e r e t h a t h a v e t o b e p a g e - a l i g n e d .
* This s t u f f g o e s a t t h e b e g i n n i n g o f t h e d a t a s e g m e n t ,
* which i s p a g e - a l i g n e d .
* /
.data
.globl sdata
sdata :
.globl empty_zero_page
empty_zero_page :
.space 4096
.globl swapper_pg_dir
swapper_pg_dir :
.space 4096
/ *
* This s p a c e g e t s a c o p y o f o p t i o n a l i n f o p a s s e d t o u s b y t h e b o o t s t r a p
* Used t o p a s s p a r a m e t e r s i n t o t h e k e r n e l l i k e r o o t = / d e v / s d a1 , e t c .
* /
.globl cmd_line
cmd_line :
.space 512
.globl intercept_table
intercept_table :
.long 0 , 0 , i0 x20 0 , i 0 x30 0 , i 0 x40 0 , 0 , i 0 x60 0 , i 0 x70 0
.long i0 x80 0 , 0 , 0 , 0 , 0 , i 0 x d00 , 0 , 0
.long 0 , 0 , 0 , i0 x13 0 0 , 0 , 0 , 0 , 0
.long 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
.long 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
.long 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
/ * Room f o r t w o P T E p o i n t e r s , u s u a l l y t h e k e r n e l a n d c u r r e n t u s e r p o i n t e r s
* to t h e i r r e s p e c t i v e r o o t p a g e t a b l e .
* /
abatron_pteptrs :
.space 8