2011-06-04 12:05:39 +04:00
/ *
* OpenRISC e n t r y . S
*
* Linux a r c h i t e c t u r a l p o r t b o r r o w i n g l i b e r a l l y f r o m s i m i l a r w o r k s o f
* others. A l l o r i g i n a l c o p y r i g h t s a p p l y a s p e r t h e o r i g i n a l s o u r c e
* declaration.
*
* Modifications f o r t h e O p e n R I S C a r c h i t e c t u r e :
* Copyright ( C ) 2 0 0 3 M a t j a z B r e s k v a r < p h o e n i x @bsemi.com>
* Copyright ( C ) 2 0 0 5 G y o r g y J e n e y < n o g @bsemi.com>
* Copyright ( C ) 2 0 1 0 - 2 0 1 1 J o n a s B o n n < j o n a s @southpole.se>
*
* 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 .
* /
# include < l i n u x / l i n k a g e . h >
# include < a s m / p r o c e s s o r . h >
# include < a s m / u n i s t d . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / e r r n o . h >
# include < a s m / s p r _ d e f s . h >
# 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 / a s m - o f f s e t s . h >
# define D I S A B L E _ I N T E R R U P T S ( t 1 ,t 2 ) \
l. m f s p r t 2 ,r0 ,S P R _ S R ;\
l. m o v h i t 1 ,h i ( ~ ( S P R _ S R _ I E E | S P R _ S R _ T E E ) ) ;\
l. o r i t 1 ,t 1 ,l o ( ~ ( S P R _ S R _ I E E | S P R _ S R _ T E E ) ) ;\
l. a n d t 2 ,t 2 ,t 1 ;\
l. m t s p r r0 ,t 2 ,S P R _ S R
# define E N A B L E _ I N T E R R U P T S ( t 1 ) \
l. m f s p r t 1 ,r0 ,S P R _ S R ;\
l. o r i t 1 ,t 1 ,l o ( S P R _ S R _ I E E | S P R _ S R _ T E E ) ;\
l. m t s p r r0 ,t 1 ,S P R _ S R
/* =========================================================[ macros ]=== */
/ *
* We n e e d t o d i s a b l e i n t e r r u p t s a t b e g i n n i n g o f R E S T O R E _ A L L
* since i n t e r r u p t m i g h t c o m e i n a f t e r w e ' v e l o a d e d E P C r e t u r n a d d r e s s
* and o v e r w r i t e E P C w i t h a d d r e s s s o m e w h e r e i n R E S T O R E _ A L L
* which i s o f c o u r s e w r o n g !
* /
# define R E S T O R E _ A L L \
DISABLE_ I N T E R R U P T S ( r3 ,r4 ) ;\
l. l w z r3 ,P T _ P C ( r1 ) ;\
l. m t s p r r0 ,r3 ,S P R _ E P C R _ B A S E ;\
l. l w z r3 ,P T _ S R ( r1 ) ;\
l. m t s p r r0 ,r3 ,S P R _ E S R _ B A S E ;\
l. l w z r2 ,P T _ G P R 2 ( r1 ) ;\
l. l w z r3 ,P T _ G P R 3 ( r1 ) ;\
l. l w z r4 ,P T _ G P R 4 ( r1 ) ;\
l. l w z r5 ,P T _ G P R 5 ( r1 ) ;\
l. l w z r6 ,P T _ G P R 6 ( r1 ) ;\
l. l w z r7 ,P T _ G P R 7 ( r1 ) ;\
l. l w z r8 ,P T _ G P R 8 ( r1 ) ;\
l. l w z r9 ,P T _ G P R 9 ( r1 ) ;\
l. l w z r10 ,P T _ G P R 1 0 ( r1 ) ;\
l. l w z r11 ,P T _ G P R 1 1 ( r1 ) ;\
l. l w z r12 ,P T _ G P R 1 2 ( r1 ) ;\
l. l w z r13 ,P T _ G P R 1 3 ( r1 ) ;\
l. l w z r14 ,P T _ G P R 1 4 ( r1 ) ;\
l. l w z r15 ,P T _ G P R 1 5 ( r1 ) ;\
l. l w z r16 ,P T _ G P R 1 6 ( r1 ) ;\
l. l w z r17 ,P T _ G P R 1 7 ( r1 ) ;\
l. l w z r18 ,P T _ G P R 1 8 ( r1 ) ;\
l. l w z r19 ,P T _ G P R 1 9 ( r1 ) ;\
l. l w z r20 ,P T _ G P R 2 0 ( r1 ) ;\
l. l w z r21 ,P T _ G P R 2 1 ( r1 ) ;\
l. l w z r22 ,P T _ G P R 2 2 ( r1 ) ;\
l. l w z r23 ,P T _ G P R 2 3 ( r1 ) ;\
l. l w z r24 ,P T _ G P R 2 4 ( r1 ) ;\
l. l w z r25 ,P T _ G P R 2 5 ( r1 ) ;\
l. l w z r26 ,P T _ G P R 2 6 ( r1 ) ;\
l. l w z r27 ,P T _ G P R 2 7 ( r1 ) ;\
l. l w z r28 ,P T _ G P R 2 8 ( r1 ) ;\
l. l w z r29 ,P T _ G P R 2 9 ( r1 ) ;\
l. l w z r30 ,P T _ G P R 3 0 ( r1 ) ;\
l. l w z r31 ,P T _ G P R 3 1 ( r1 ) ;\
l. l w z r1 ,P T _ S P ( r1 ) ;\
l. r f e
# define E X C E P T I O N _ E N T R Y ( h a n d l e r ) \
.global handler ;\
handler : ;\
/* r1, EPCR, ESR a already saved */ ;\
l. s w P T _ G P R 2 ( r1 ) ,r2 ;\
l. s w P T _ G P R 3 ( r1 ) ,r3 ;\
/* r4 already save */ ;\
l. s w P T _ G P R 5 ( r1 ) ,r5 ;\
l. s w P T _ G P R 6 ( r1 ) ,r6 ;\
l. s w P T _ G P R 7 ( r1 ) ,r7 ;\
l. s w P T _ G P R 8 ( r1 ) ,r8 ;\
l. s w P T _ G P R 9 ( r1 ) ,r9 ;\
/* r10 already saved */ ;\
l. s w P T _ G P R 1 1 ( r1 ) ,r11 ;\
/* r12 already saved */ ;\
l. s w P T _ G P R 1 3 ( r1 ) ,r13 ;\
l. s w P T _ G P R 1 4 ( r1 ) ,r14 ;\
l. s w P T _ G P R 1 5 ( r1 ) ,r15 ;\
l. s w P T _ G P R 1 6 ( r1 ) ,r16 ;\
l. s w P T _ G P R 1 7 ( r1 ) ,r17 ;\
l. s w P T _ G P R 1 8 ( r1 ) ,r18 ;\
l. s w P T _ G P R 1 9 ( r1 ) ,r19 ;\
l. s w P T _ G P R 2 0 ( r1 ) ,r20 ;\
l. s w P T _ G P R 2 1 ( r1 ) ,r21 ;\
l. s w P T _ G P R 2 2 ( r1 ) ,r22 ;\
l. s w P T _ G P R 2 3 ( r1 ) ,r23 ;\
l. s w P T _ G P R 2 4 ( r1 ) ,r24 ;\
l. s w P T _ G P R 2 5 ( r1 ) ,r25 ;\
l. s w P T _ G P R 2 6 ( r1 ) ,r26 ;\
l. s w P T _ G P R 2 7 ( r1 ) ,r27 ;\
l. s w P T _ G P R 2 8 ( r1 ) ,r28 ;\
l. s w P T _ G P R 2 9 ( r1 ) ,r29 ;\
/* r30 already save */ ;\
/* l.sw PT_GPR30(r1),r30*/ ;\
l. s w P T _ G P R 3 1 ( r1 ) ,r31 ;\
2012-03-02 13:05:24 +04:00
/* Store -1 in orig_gpr11 for non-syscall exceptions */ ;\
l. a d d i r30 ,r0 ,- 1 ;\
l. s w P T _ O R I G _ G P R 1 1 ( r1 ) ,r30
2011-06-04 12:05:39 +04:00
# define U N H A N D L E D _ E X C E P T I O N ( h a n d l e r ,v e c t o r ) \
.global handler ;\
handler : ;\
/* r1, EPCR, ESR already saved */ ;\
l. s w P T _ G P R 2 ( r1 ) ,r2 ;\
l. s w P T _ G P R 3 ( r1 ) ,r3 ;\
l. s w P T _ G P R 5 ( r1 ) ,r5 ;\
l. s w P T _ G P R 6 ( r1 ) ,r6 ;\
l. s w P T _ G P R 7 ( r1 ) ,r7 ;\
l. s w P T _ G P R 8 ( r1 ) ,r8 ;\
l. s w P T _ G P R 9 ( r1 ) ,r9 ;\
/* r10 already saved */ ;\
l. s w P T _ G P R 1 1 ( r1 ) ,r11 ;\
/* r12 already saved */ ;\
l. s w P T _ G P R 1 3 ( r1 ) ,r13 ;\
l. s w P T _ G P R 1 4 ( r1 ) ,r14 ;\
l. s w P T _ G P R 1 5 ( r1 ) ,r15 ;\
l. s w P T _ G P R 1 6 ( r1 ) ,r16 ;\
l. s w P T _ G P R 1 7 ( r1 ) ,r17 ;\
l. s w P T _ G P R 1 8 ( r1 ) ,r18 ;\
l. s w P T _ G P R 1 9 ( r1 ) ,r19 ;\
l. s w P T _ G P R 2 0 ( r1 ) ,r20 ;\
l. s w P T _ G P R 2 1 ( r1 ) ,r21 ;\
l. s w P T _ G P R 2 2 ( r1 ) ,r22 ;\
l. s w P T _ G P R 2 3 ( r1 ) ,r23 ;\
l. s w P T _ G P R 2 4 ( r1 ) ,r24 ;\
l. s w P T _ G P R 2 5 ( r1 ) ,r25 ;\
l. s w P T _ G P R 2 6 ( r1 ) ,r26 ;\
l. s w P T _ G P R 2 7 ( r1 ) ,r27 ;\
l. s w P T _ G P R 2 8 ( r1 ) ,r28 ;\
l. s w P T _ G P R 2 9 ( r1 ) ,r29 ;\
/* r31 already saved */ ;\
l. s w P T _ G P R 3 0 ( r1 ) ,r30 ;\
/* l.sw PT_GPR31(r1),r31 */ ;\
2012-03-02 13:05:24 +04:00
/* Store -1 in orig_gpr11 for non-syscall exceptions */ ;\
l. a d d i r30 ,r0 ,- 1 ;\
l. s w P T _ O R I G _ G P R 1 1 ( r1 ) ,r30 ;\
2011-06-04 12:05:39 +04:00
l. a d d i r3 ,r1 ,0 ;\
/* r4 is exception EA */ ;\
l. a d d i r5 ,r0 ,v e c t o r ;\
l. j a l u n h a n d l e d _ e x c e p t i o n ;\
l. n o p ;\
l. j _ r e t _ f r o m _ e x c e p t i o n ;\
l. n o p
2014-11-03 15:28:14 +03:00
/* clobbers 'reg' */
# define C L E A R _ L W A _ F L A G ( r e g ) \
l. m o v h i r e g ,h i ( l w a _ f l a g ) ;\
l. o r i r e g ,r e g ,l o ( l w a _ f l a g ) ;\
l. s w 0 ( r e g ) ,r0
2011-06-04 12:05:39 +04:00
/ *
* NOTE : one s h o u l d n e v e r a s s u m e t h a t S P R _ E P C , S P R _ E S R , S P R _ E E A R
* contain t h e s a m e v a l u e s a s w h e n e x c e p t i o n w e ' r e h a n d l i n g
* occured. i n f a c t t h e y n e v e r d o . i f y o u n e e d t h e m u s e
* values s a v e d o n s t a c k ( f o r S P R _ E P C , S P R _ E S R ) o r c o n t e n t
* of r4 ( f o r S P R _ E E A R ) . f o r d e t a i l s l o o k a t E X C E P T I O N _ H A N D L E ( )
* in ' a r c h / o r32 / k e r n e l / h e a d . S '
* /
/* =====================================================[ exceptions] === */
/* ---[ 0x100: RESET exception ]----------------------------------------- */
EXCEPTION_ E N T R Y ( _ t n g _ k e r n e l _ s t a r t )
l. j a l _ s t a r t
l. a n d i r0 ,r0 ,0
/* ---[ 0x200: BUS exception ]------------------------------------------- */
EXCEPTION_ E N T R Y ( _ b u s _ f a u l t _ h a n d l e r )
2014-11-03 15:28:14 +03:00
CLEAR_ L W A _ F L A G ( r3 )
2011-06-04 12:05:39 +04:00
/* r4: EA of fault (set by EXCEPTION_HANDLE) */
l. j a l d o _ b u s _ f a u l t
l. a d d i r3 ,r1 ,0 / * p t _ r e g s * /
l. j _ r e t _ f r o m _ e x c e p t i o n
l. n o p
/* ---[ 0x300: Data Page Fault exception ]------------------------------- */
2013-02-14 19:16:49 +04:00
EXCEPTION_ E N T R Y ( _ d t l b _ m i s s _ p a g e _ f a u l t _ h a n d l e r )
2014-11-03 15:28:14 +03:00
CLEAR_ L W A _ F L A G ( r3 )
2013-02-14 19:16:49 +04:00
l. a n d r5 ,r5 ,r0
l. j 1 f
l. n o p
2011-06-04 12:05:39 +04:00
EXCEPTION_ E N T R Y ( _ d a t a _ p a g e _ f a u l t _ h a n d l e r )
2014-11-03 15:28:14 +03:00
CLEAR_ L W A _ F L A G ( r3 )
2011-06-04 12:05:39 +04:00
/* set up parameters for do_page_fault */
2013-02-14 19:16:49 +04:00
l. o r i r5 ,r0 ,0 x30 0 / / e x c e p t i o n v e c t o r
1 :
2011-06-04 12:05:39 +04:00
l. a d d i r3 ,r1 ,0 / / p t _ r e g s
/* r4 set be EXCEPTION_HANDLE */ / / effective a d d r e s s o f f a u l t
/ *
* __PHX__ : TODO
*
* all t h i s c a n b e w r i t t e n m u c h s i m p l e r . l o o k a t
* DTLB m i s s h a n d l e r i n t h e C O N F I G _ G U A R D _ P R O T E C T E D _ C O R E p a r t
* /
# ifdef C O N F I G _ O P E N R I S C _ N O _ S P R _ S R _ D S X
2017-01-10 17:13:45 +03:00
l. l w z r6 ,P T _ P C ( r3 ) / / a d d r e s s o f a n o f f e n d i n g i n s n
2011-06-04 12:05:39 +04:00
l. l w z r6 ,0 ( r6 ) / / i n s t r u c t i o n t h a t c a u s e d p f
l. s r l i r6 ,r6 ,2 6 / / c h e c k o p c o d e f o r j u m p i n s n
l. s f e q i r6 ,0 / / l . j
l. b f 8 f
l. s f e q i r6 ,1 / / l . j a l
l. b f 8 f
l. s f e q i r6 ,3 / / l . b n f
l. b f 8 f
l. s f e q i r6 ,4 / / l . b f
l. b f 8 f
l. s f e q i r6 ,0 x11 / / l . j r
l. b f 8 f
l. s f e q i r6 ,0 x12 / / l . j a l r
l. b f 8 f
2017-01-10 17:13:45 +03:00
l. n o p
2011-06-04 12:05:39 +04:00
l. j 9 f
2017-01-10 17:13:45 +03:00
l. n o p
2011-06-04 12:05:39 +04:00
2017-01-10 17:13:45 +03:00
8 : / / offending i n s n i s i n d e l a y s l o t
l. l w z r6 ,P T _ P C ( r3 ) / / a d d r e s s o f a n o f f e n d i n g i n s n
2011-06-04 12:05:39 +04:00
l. a d d i r6 ,r6 ,4
l. l w z r6 ,0 ( r6 ) / / i n s t r u c t i o n t h a t c a u s e d p f
l. s r l i r6 ,r6 ,2 6 / / g e t o p c o d e
2017-01-10 17:13:45 +03:00
9 : / / offending i n s t r u c t i o n o p c o d e l o a d e d i n r6
2011-06-04 12:05:39 +04:00
# else
2017-01-10 17:30:23 +03:00
l. l w z r6 ,P T _ S R ( r3 ) / / S R
2017-01-10 17:13:45 +03:00
l. a n d i r6 ,r6 ,S P R _ S R _ D S X / / c h e c k f o r d e l a y s l o t e x c e p t i o n
2017-01-10 17:30:23 +03:00
l. s f n e r6 ,r0 / / e x c e p t i o n h a p p e n e d i n d e l a y s l o t
2017-01-10 17:13:45 +03:00
l. b n f 7 f
l. l w z r6 ,P T _ P C ( r3 ) / / a d d r e s s o f a n o f f e n d i n g i n s n
2011-06-04 12:05:39 +04:00
2017-01-10 17:13:45 +03:00
l. a d d i r6 ,r6 ,4 / / o f f e n d i n g i n s n i s i n d e l a y s l o t
2011-06-04 12:05:39 +04:00
7 :
l. l w z r6 ,0 ( r6 ) / / i n s t r u c t i o n t h a t c a u s e d p f
l. s r l i r6 ,r6 ,2 6 / / c h e c k o p c o d e f o r w r i t e a c c e s s
# endif
2017-01-10 17:13:45 +03:00
l. s f g e u i r6 ,0 x33 / / c h e c k o p c o d e f o r w r i t e a c c e s s
2011-06-04 12:05:39 +04:00
l. b n f 1 f
l. s f l e u i r6 ,0 x37
l. b n f 1 f
l. o r i r6 ,r0 ,0 x1 / / w r i t e a c c e s s
l. j 2 f
2017-01-10 17:13:45 +03:00
l. n o p
2011-06-04 12:05:39 +04:00
1 : l. o r i r6 ,r0 ,0 x0 / / ! w r i t e a c c e s s
2 :
/* call fault.c handler in or32/mm/fault.c */
l. j a l d o _ p a g e _ f a u l t
2017-01-10 17:13:45 +03:00
l. n o p
2011-06-04 12:05:39 +04:00
l. j _ r e t _ f r o m _ e x c e p t i o n
2017-01-10 17:13:45 +03:00
l. n o p
2011-06-04 12:05:39 +04:00
/* ---[ 0x400: Insn Page Fault exception ]------------------------------- */
2013-02-14 19:16:49 +04:00
EXCEPTION_ E N T R Y ( _ i t l b _ m i s s _ p a g e _ f a u l t _ h a n d l e r )
2014-11-03 15:28:14 +03:00
CLEAR_ L W A _ F L A G ( r3 )
2013-02-14 19:16:49 +04:00
l. a n d r5 ,r5 ,r0
l. j 1 f
l. n o p
2011-06-04 12:05:39 +04:00
EXCEPTION_ E N T R Y ( _ i n s n _ p a g e _ f a u l t _ h a n d l e r )
2014-11-03 15:28:14 +03:00
CLEAR_ L W A _ F L A G ( r3 )
2011-06-04 12:05:39 +04:00
/* set up parameters for do_page_fault */
2013-02-14 19:16:49 +04:00
l. o r i r5 ,r0 ,0 x40 0 / / e x c e p t i o n v e c t o r
1 :
2011-06-04 12:05:39 +04:00
l. a d d i r3 ,r1 ,0 / / p t _ r e g s
/* r4 set be EXCEPTION_HANDLE */ / / effective a d d r e s s o f f a u l t
l. o r i r6 ,r0 ,0 x0 / / ! w r i t e a c c e s s
/* call fault.c handler in or32/mm/fault.c */
l. j a l d o _ p a g e _ f a u l t
2017-01-10 17:13:45 +03:00
l. n o p
2011-06-04 12:05:39 +04:00
l. j _ r e t _ f r o m _ e x c e p t i o n
2017-01-10 17:13:45 +03:00
l. n o p
2011-06-04 12:05:39 +04:00
/* ---[ 0x500: Timer exception ]----------------------------------------- */
EXCEPTION_ E N T R Y ( _ t i m e r _ h a n d l e r )
2014-11-03 15:28:14 +03:00
CLEAR_ L W A _ F L A G ( r3 )
2011-06-04 12:05:39 +04:00
l. j a l t i m e r _ i n t e r r u p t
l. a d d i r3 ,r1 ,0 / * p t _ r e g s * /
l. j _ r e t _ f r o m _ i n t r
l. n o p
2017-02-28 01:28:58 +03:00
/* ---[ 0x600: Alignment exception ]-------------------------------------- */
2011-06-04 12:05:39 +04:00
EXCEPTION_ E N T R Y ( _ a l i g n m e n t _ h a n d l e r )
2014-11-03 15:28:14 +03:00
CLEAR_ L W A _ F L A G ( r3 )
2011-06-04 12:05:39 +04:00
/* r4: EA of fault (set by EXCEPTION_HANDLE) */
l. j a l d o _ u n a l i g n e d _ a c c e s s
l. a d d i r3 ,r1 ,0 / * p t _ r e g s * /
l. j _ r e t _ f r o m _ e x c e p t i o n
l. n o p
# if 0
2017-02-28 01:28:58 +03:00
EXCEPTION_ E N T R Y ( _ a l i g n m e n t _ h a n d l e r )
2017-02-28 01:29:03 +03:00
/ / l. m f s p r r2 ,r0 ,S P R _ E E A R _ B A S E / * L o a d t h e e f f e c t i v e a d d r e s s * /
2011-06-04 12:05:39 +04:00
l. a d d i r2 ,r4 ,0
/ / l. m f s p r r5 ,r0 ,S P R _ E P C R _ B A S E / * L o a d t h e i n s n a d d r e s s * /
l. l w z r5 ,P T _ P C ( r1 )
l. l w z r3 ,0 ( r5 ) / * L o a d i n s n * /
l. s r l i r4 ,r3 ,2 6 / * S h i f t l e f t t o g e t t h e i n s n o p c o d e * /
l. s f e q i r4 ,0 x00 / * C h e c k i f t h e l o a d / s t o r e i n s n i s i n d e l a y s l o t * /
l. b f j m p
l. s f e q i r4 ,0 x01
l. b f j m p
l. s f e q i r4 ,0 x03
l. b f j m p
l. s f e q i r4 ,0 x04
l. b f j m p
l. s f e q i r4 ,0 x11
l. b f j r
l. s f e q i r4 ,0 x12
l. b f j r
l. n o p
l. j 1 f
l. a d d i r5 ,r5 ,4 / * I n c r e m e n t P C t o g e t r e t u r n i n s n a d d r e s s * /
jmp :
l. s l l i r4 ,r3 ,6 / * G e t t h e s i g n e d e x t e n d e d j u m p l e n g t h * /
l. s r a i r4 ,r4 ,4
l. l w z r3 ,4 ( r5 ) / * L o a d t h e r e a l l o a d / s t o r e i n s n * /
l. a d d r5 ,r5 ,r4 / * C a l c u l a t e j u m p t a r g e t a d d r e s s * /
l. j 1 f
l. s r l i r4 ,r3 ,2 6 / * S h i f t l e f t t o g e t t h e i n s n o p c o d e * /
jr :
l. s l l i r4 ,r3 ,9 / * S h i f t t o g e t t h e r e g n b * /
l. a n d i r4 ,r4 ,0 x7 c
l. l w z r3 ,4 ( r5 ) / * L o a d t h e r e a l l o a d / s t o r e i n s n * /
l. a d d r4 ,r4 ,r1 / * L o a d t h e j u m p r e g i s t e r v a l u e f r o m t h e s t a c k * /
l. l w z r5 ,0 ( r4 )
l. s r l i r4 ,r3 ,2 6 / * S h i f t l e f t t o g e t t h e i n s n o p c o d e * /
1 :
/ / l. m t s p r r0 ,r5 ,S P R _ E P C R _ B A S E
l. s w P T _ P C ( r1 ) ,r5
l. s f e q i r4 ,0 x26
l. b f l h s
l. s f e q i r4 ,0 x25
l. b f l h z
l. s f e q i r4 ,0 x22
l. b f l w s
l. s f e q i r4 ,0 x21
l. b f l w z
l. s f e q i r4 ,0 x37
l. b f s h
l. s f e q i r4 ,0 x35
l. b f s w
l. n o p
1 : l. j 1 b / * I d o n ' t k n o w w h a t t o d o * /
l. n o p
lhs : l. l b s r5 ,0 ( r2 )
l. s l l i r5 ,r5 ,8
l. l b z r6 ,1 ( r2 )
l. o r r5 ,r5 ,r6
l. s r l i r4 ,r3 ,1 9
l. a n d i r4 ,r4 ,0 x7 c
l. a d d r4 ,r4 ,r1
l. j a l i g n _ e n d
l. s w 0 ( r4 ) ,r5
lhz : l. l b z r5 ,0 ( r2 )
l. s l l i r5 ,r5 ,8
l. l b z r6 ,1 ( r2 )
l. o r r5 ,r5 ,r6
l. s r l i r4 ,r3 ,1 9
l. a n d i r4 ,r4 ,0 x7 c
l. a d d r4 ,r4 ,r1
l. j a l i g n _ e n d
l. s w 0 ( r4 ) ,r5
lws : l. l b s r5 ,0 ( r2 )
l. s l l i r5 ,r5 ,2 4
l. l b z r6 ,1 ( r2 )
l. s l l i r6 ,r6 ,1 6
l. o r r5 ,r5 ,r6
l. l b z r6 ,2 ( r2 )
l. s l l i r6 ,r6 ,8
l. o r r5 ,r5 ,r6
l. l b z r6 ,3 ( r2 )
l. o r r5 ,r5 ,r6
l. s r l i r4 ,r3 ,1 9
l. a n d i r4 ,r4 ,0 x7 c
l. a d d r4 ,r4 ,r1
l. j a l i g n _ e n d
l. s w 0 ( r4 ) ,r5
lwz : l. l b z r5 ,0 ( r2 )
l. s l l i r5 ,r5 ,2 4
l. l b z r6 ,1 ( r2 )
l. s l l i r6 ,r6 ,1 6
l. o r r5 ,r5 ,r6
l. l b z r6 ,2 ( r2 )
l. s l l i r6 ,r6 ,8
l. o r r5 ,r5 ,r6
l. l b z r6 ,3 ( r2 )
l. o r r5 ,r5 ,r6
l. s r l i r4 ,r3 ,1 9
l. a n d i r4 ,r4 ,0 x7 c
l. a d d r4 ,r4 ,r1
l. j a l i g n _ e n d
l. s w 0 ( r4 ) ,r5
sh :
l. s r l i r4 ,r3 ,9
l. a n d i r4 ,r4 ,0 x7 c
l. a d d r4 ,r4 ,r1
l. l w z r5 ,0 ( r4 )
l. s b 1 ( r2 ) ,r5
l. s r l i r5 ,r5 ,8
l. j a l i g n _ e n d
l. s b 0 ( r2 ) ,r5
sw :
l. s r l i r4 ,r3 ,9
l. a n d i r4 ,r4 ,0 x7 c
l. a d d r4 ,r4 ,r1
l. l w z r5 ,0 ( r4 )
l. s b 3 ( r2 ) ,r5
l. s r l i r5 ,r5 ,8
l. s b 2 ( r2 ) ,r5
l. s r l i r5 ,r5 ,8
l. s b 1 ( r2 ) ,r5
l. s r l i r5 ,r5 ,8
l. j a l i g n _ e n d
l. s b 0 ( r2 ) ,r5
align_end :
l. j _ r e t _ f r o m _ i n t r
l. n o p
# endif
/* ---[ 0x700: Illegal insn exception ]---------------------------------- */
EXCEPTION_ E N T R Y ( _ i l l e g a l _ i n s t r u c t i o n _ h a n d l e r )
/* r4: EA of fault (set by EXCEPTION_HANDLE) */
l. j a l d o _ i l l e g a l _ i n s t r u c t i o n
l. a d d i r3 ,r1 ,0 / * p t _ r e g s * /
l. j _ r e t _ f r o m _ e x c e p t i o n
l. n o p
/* ---[ 0x800: External interrupt exception ]---------------------------- */
EXCEPTION_ E N T R Y ( _ e x t e r n a l _ i r q _ h a n d l e r )
# ifdef C O N F I G _ O P E N R I S C _ E S R _ E X C E P T I O N _ B U G _ C H E C K
l. l w z r4 ,P T _ S R ( r1 ) / / w e r e i n t e r r u p t s e n a b l e d ?
l. a n d i r4 ,r4 ,S P R _ S R _ I E E
l. s f e q i r4 ,0
l. b n f 1 f / / e x t i r q e n a b l e d , a l l o k .
l. n o p
l. a d d i r1 ,r1 ,- 0 x8
l. m o v h i r3 ,h i ( 4 2 f )
l. o r i r3 ,r3 ,l o ( 4 2 f )
l. s w 0 x0 ( r1 ) ,r3
l. j a l p r i n t k
l. s w 0 x4 ( r1 ) ,r4
l. a d d i r1 ,r1 ,0 x8
.section .rodata , " a"
42 :
.string " \ n\ r E S R i n t e r r u p t b u g : i n _ e x t e r n a l _ i r q _ h a n d l e r ( E S R % x ) \ n \ r "
.align 4
.previous
l. o r i r4 ,r4 ,S P R _ S R _ I E E / / f i x t h e b u g
/ / l. s w P T _ S R ( r1 ) ,r4
1 :
# endif
2014-11-03 15:28:14 +03:00
CLEAR_ L W A _ F L A G ( r3 )
2011-06-04 12:05:39 +04:00
l. a d d i r3 ,r1 ,0
l. m o v h i r8 ,h i ( d o _ I R Q )
l. o r i r8 ,r8 ,l o ( d o _ I R Q )
l. j a l r r8
l. n o p
l. j _ r e t _ f r o m _ i n t r
l. n o p
/* ---[ 0x900: DTLB miss exception ]------------------------------------- */
/* ---[ 0xa00: ITLB miss exception ]------------------------------------- */
/* ---[ 0xb00: Range exception ]----------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x b00 ,0 x b00 )
/* ---[ 0xc00: Syscall exception ]--------------------------------------- */
/ *
* Syscalls a r e a s p e c i a l t y p e o f e x c e p t i o n i n t h a t t h e y a r e
* _ explicitly_ i n v o k e d b y u s e r s p a c e a n d c a n t h e r e f o r e b e
* held t o c o n f o r m t o t h e s a m e A B I a s n o r m a l f u n c t i o n s w i t h
* respect t o w h e t h e r r e g i s t e r s a r e p r e s e r v e d a c r o s s t h e c a l l
* or n o t .
* /
/ * Upon s y s c a l l e n t r y w e j u s t s a v e t h e c a l l e e - s a v e d r e g i s t e r s
* and n o t t h e c a l l - c l o b b e r e d o n e s .
* /
_string_syscall_return :
.string " syscall r e t u r n % l d \ n \ r \ 0 "
.align 4
ENTRY( _ s y s _ c a l l _ h a n d l e r )
/* syscalls run with interrupts enabled */
ENABLE_ I N T E R R U P T S ( r29 ) / / e n a b l e i n t e r r u p t s , r29 i s t e m p
/* r1, EPCR, ESR a already saved */
l. s w P T _ G P R 2 ( r1 ) ,r2
/ * r3 - r8 m u s t b e s a v e d b e c a u s e s y s c a l l r e s t a r t r e l i e s
* on u s b e i n g a b l e t o r e s t a r t t h e s y s c a l l a r g s . . . t e c h n i c a l l y
* they s h o u l d b e c l o b b e r e d , o t h e r w i s e
* /
l. s w P T _ G P R 3 ( r1 ) ,r3
2014-11-03 15:28:14 +03:00
/ *
* r4 a l r e a d y s a v e d
* r4 h o l d s t h e E E A R a d d r e s s o f t h e f a u l t , u s e i t a s s c r e a t c h r e g a n d
* then l o a d t h e o r i g i n a l r4
* /
CLEAR_ L W A _ F L A G ( r4 )
2011-06-04 12:05:39 +04:00
l. l w z r4 ,P T _ G P R 4 ( r1 )
l. s w P T _ G P R 5 ( r1 ) ,r5
l. s w P T _ G P R 6 ( r1 ) ,r6
l. s w P T _ G P R 7 ( r1 ) ,r7
l. s w P T _ G P R 8 ( r1 ) ,r8
l. s w P T _ G P R 9 ( r1 ) ,r9
/* r10 already saved */
l. s w P T _ G P R 1 1 ( r1 ) ,r11
2012-03-02 13:05:24 +04:00
/* orig_gpr11 must be set for syscalls */
2011-06-04 12:05:39 +04:00
l. s w P T _ O R I G _ G P R 1 1 ( r1 ) ,r11
/* r12,r13 already saved */
/ * r1 4 - r28 ( e v e n ) a r e n ' t t o u c h e d b y t h e s y s c a l l f a s t p a t h b e l o w
* so w e d o n ' t n e e d t o s a v e t h e m . H o w e v e r , t h e f u n c t i o n s t h a t r e t u r n
* to u s e r s p a c e v i a a c a l l t o s w i t c h ( ) D O n e e d t o s a v e t h e s e b e c a u s e
* switch( ) e f f e c t i v e l y c l o b b e r s t h e m . . . s a v i n g t h e s e r e g i s t e r s f o r
* such f u n c t i o n s i s h a n d l e d i n t h e i r s y s c a l l w r a p p e r s ( s e e f o r k , v f o r k ,
* and c l o n e , b e l o w ) .
/* r30 is the only register we clobber in the fast path */
/* r30 already saved */
/* l.sw PT_GPR30(r1),r30 */
_syscall_check_trace_enter :
/* If TIF_SYSCALL_TRACE is set, then we want to do syscall tracing */
l. l w z r30 ,T I _ F L A G S ( r10 )
l. a n d i r30 ,r30 ,_ T I F _ S Y S C A L L _ T R A C E
l. s f n e r30 ,r0
l. b f _ s y s c a l l _ t r a c e _ e n t e r
l. n o p
_syscall_check :
/* Ensure that the syscall number is reasonable */
l. s f g e u i r11 ,_ _ N R _ s y s c a l l s
l. b f _ s y s c a l l _ b a d s y s
l. n o p
_syscall_call :
l. m o v h i r29 ,h i ( s y s _ c a l l _ t a b l e )
l. o r i r29 ,r29 ,l o ( s y s _ c a l l _ t a b l e )
l. s l l i r11 ,r11 ,2
l. a d d r29 ,r29 ,r11
l. l w z r29 ,0 ( r29 )
l. j a l r r29
l. n o p
_syscall_return :
/ * All s y s c a l l s r e t u r n h e r e . . . j u s t p a y a t t e n t i o n t o r e t _ f r o m _ f o r k
* which d o e s i t i n a r o u n d - a b o u t w a y .
* /
l. s w P T _ G P R 1 1 ( r1 ) ,r11 / / s a v e r e t u r n v a l u e
# if 0
_syscall_debug :
l. m o v h i r3 ,h i ( _ s t r i n g _ s y s c a l l _ r e t u r n )
l. o r i r3 ,r3 ,l o ( _ s t r i n g _ s y s c a l l _ r e t u r n )
l. o r i r27 ,r0 ,1
l. s w - 4 ( r1 ) ,r27
l. s w - 8 ( r1 ) ,r11
l. a d d i r1 ,r1 ,- 8
l. m o v h i r27 ,h i ( p r i n t k )
l. o r i r27 ,r27 ,l o ( p r i n t k )
l. j a l r r27
l. n o p
l. a d d i r1 ,r1 ,8
# endif
_syscall_check_trace_leave :
/ * r3 0 i s a c a l l e e - s a v e d r e g i s t e r s o t h i s s h o u l d s t i l l h o l d t h e
* _ TIF_ S Y S C A L L _ T R A C E f l a g f r o m _ s y s c a l l _ c h e c k _ t r a c e _ e n t e r a b o v e . . .
* _ syscall_ t r a c e _ l e a v e e x p e c t s s y s c a l l r e s u l t t o b e i n p t _ r e g s - > r11 .
* /
l. s f n e r30 ,r0
l. b f _ s y s c a l l _ t r a c e _ l e a v e
l. n o p
/ * This i s w h e r e t h e e x c e p t i o n - r e t u r n c o d e b e g i n s . . . i n t e r r u p t s n e e d t o b e
* disabled t h e r e s t o f t h e w a y h e r e b e c a u s e w e c a n ' t a f f o r d t o m i s s a n y
* interrupts t h a t s e t N E E D _ R E S C H E D o r S I G N A L P E N D I N G . . . r e a l l y t r u e ? * /
_syscall_check_work :
/* Here we need to disable interrupts */
DISABLE_ I N T E R R U P T S ( r27 ,r29 )
l. l w z r30 ,T I _ F L A G S ( r10 )
l. a n d i r30 ,r30 ,_ T I F _ W O R K _ M A S K
l. s f n e r30 ,r0
l. b n f _ s y s c a l l _ r e s u m e _ u s e r s p a c e
l. n o p
/ * Work p e n d i n g f o l l o w s a d i f f e r e n t r e t u r n p a t h , s o w e n e e d t o
* make s u r e t h a t a l l t h e c a l l - s a v e d r e g i s t e r s g e t i n t o p t _ r e g s
* before b r a n c h i n g . . .
* /
l. s w P T _ G P R 1 4 ( r1 ) ,r14
l. s w P T _ G P R 1 6 ( r1 ) ,r16
l. s w P T _ G P R 1 8 ( r1 ) ,r18
l. s w P T _ G P R 2 0 ( r1 ) ,r20
l. s w P T _ G P R 2 2 ( r1 ) ,r22
l. s w P T _ G P R 2 4 ( r1 ) ,r24
l. s w P T _ G P R 2 6 ( r1 ) ,r26
l. s w P T _ G P R 2 8 ( r1 ) ,r28
/* _work_pending needs to be called with interrupts disabled */
l. j _ w o r k _ p e n d i n g
l. n o p
_syscall_resume_userspace :
/ / ENABLE_ I N T E R R U P T S ( r29 )
/ * This i s t h e h o t p a t h f o r r e t u r n i n g t o u s e r s p a c e f r o m a s y s c a l l . I f t h e r e ' s
* work t o b e d o n e a n d t h e b r a n c h t o _ w o r k _ p e n d i n g w a s t a k e n a b o v e , t h e n t h e
* return t o u s e r s p a c e w i l l b e d o n e v i a t h e n o r m a l e x c e p t i o n r e t u r n p a t h . . .
* that p a t h r e s t o r e s _ a l l _ r e g i s t e r s a n d w i l l o v e r w r i t e t h e " c l o b b e r e d "
* registers w i t h w h a t e v e r g a r b a g e i s i n p t _ r e g s - - t h a t ' s O K b e c a u s e t h o s e
* registers a r e c l o b b e r e d a n y w a y a n d b e c a u s e t h e e x t r a w o r k i s i n s i g n i f i c a n t
* in t h e c o n t e x t o f t h e e x t r a w o r k t h a t _ w o r k _ p e n d i n g i s d o i n g .
/ * Once a g a i n , s y s c a l l s a r e s p e c i a l a n d o n l y g u a r a n t e e t o p r e s e r v e t h e
* same r e g i s t e r s a s a n o r m a l f u n c t i o n c a l l * /
/ * The a s s u m p t i o n h e r e i s t h a t t h e r e g i s t e r s r14 - r28 ( e v e n ) a r e u n t o u c h e d a n d
* don' t n e e d t o b e r e s t o r e d . . . b e s u r e t h a t t h a t ' s r e a l l y t h e c a s e !
* /
/ * This i s s t i l l t o o m u c h . . . w e s h o u l d o n l y b e r e s t o r i n g w h a t w e a c t u a l l y
* clobbered. . . w e s h o u l d e v e n b e u s i n g ' s c r a t c h ' ( o d d ) r e g s a b o v e s o t h a t
* we d o n ' t n e e d t o r e s t o r e a n y t h i n g , h a r d l y . . .
* /
l. l w z r2 ,P T _ G P R 2 ( r1 )
/* Restore args */
/ * r3 - r8 a r e t e c h n i c a l l y c l o b b e r e d , b u t s y s c a l l r e s t a r t n e e d s t h e s e
* to b e r e s t o r e d . . .
* /
l. l w z r3 ,P T _ G P R 3 ( r1 )
l. l w z r4 ,P T _ G P R 4 ( r1 )
l. l w z r5 ,P T _ G P R 5 ( r1 )
l. l w z r6 ,P T _ G P R 6 ( r1 )
l. l w z r7 ,P T _ G P R 7 ( r1 )
l. l w z r8 ,P T _ G P R 8 ( r1 )
l. l w z r9 ,P T _ G P R 9 ( r1 )
l. l w z r10 ,P T _ G P R 1 0 ( r1 )
l. l w z r11 ,P T _ G P R 1 1 ( r1 )
/* r30 is the only register we clobber in the fast path */
l. l w z r30 ,P T _ G P R 3 0 ( r1 )
/* Here we use r13-r19 (odd) as scratch regs */
l. l w z r13 ,P T _ P C ( r1 )
l. l w z r15 ,P T _ S R ( r1 )
l. l w z r1 ,P T _ S P ( r1 )
/ * Interrupts n e e d t o b e d i s a b l e d f o r s e t t i n g E P C R a n d E S R
* so t h a t a n o t h e r i n t e r r u p t d o e s n ' t c o m e i n h e r e a n d c l o b b e r
* them b e f o r e w e c a n u s e t h e m f o r o u r l . r f e * /
DISABLE_ I N T E R R U P T S ( r17 ,r19 )
l. m t s p r r0 ,r13 ,S P R _ E P C R _ B A S E
l. m t s p r r0 ,r15 ,S P R _ E S R _ B A S E
l. r f e
/ * End o f h o t p a t h !
* Keep t h e b e l o w t r a c i n g a n d e r r o r h a n d l i n g o u t o f t h e h o t p a t h . . .
* /
_syscall_trace_enter :
/ * Here w e p a s s p t _ r e g s t o d o _ s y s c a l l _ t r a c e _ e n t e r . M a k e s u r e
* that f u n c t i o n i s r e a l l y g e t t i n g a l l t h e i n f o i t n e e d s a s
* pt_ r e g s i s n ' t a c o m p l e t e s e t o f u s e r s p a c e r e g s , j u s t t h e
* ones r e l e v a n t t o t h e s y s c a l l . . .
*
* Note u s e o f d e l a y s l o t f o r s e t t i n g a r g u m e n t .
* /
l. j a l d o _ s y s c a l l _ t r a c e _ e n t e r
l. a d d i r3 ,r1 ,0
/ * Restore a r g u m e n t s ( n o t p r e s e r v e d a c r o s s d o _ s y s c a l l _ t r a c e _ e n t e r )
* so t h a t w e c a n d o t h e s y s c a l l f o r r e a l a n d r e t u r n t o t h e s y s c a l l
* hot p a t h .
* /
2012-03-02 13:05:24 +04:00
l. l w z r11 ,P T _ G P R 1 1 ( r1 )
2011-06-04 12:05:39 +04:00
l. l w z r3 ,P T _ G P R 3 ( r1 )
l. l w z r4 ,P T _ G P R 4 ( r1 )
l. l w z r5 ,P T _ G P R 5 ( r1 )
l. l w z r6 ,P T _ G P R 6 ( r1 )
l. l w z r7 ,P T _ G P R 7 ( r1 )
l. j _ s y s c a l l _ c h e c k
l. l w z r8 ,P T _ G P R 8 ( r1 )
_syscall_trace_leave :
l. j a l d o _ s y s c a l l _ t r a c e _ l e a v e
l. a d d i r3 ,r1 ,0
l. j _ s y s c a l l _ c h e c k _ w o r k
l. n o p
_syscall_badsys :
/ * Here w e e f f e c t i v e l y p r e t e n d t o h a v e e x e c u t e d a n i m a g i n a r y
* syscall t h a t r e t u r n s - E N O S Y S a n d t h e n r e t u r n t o t h e r e g u l a r
* syscall h o t p a t h .
* Note t h a t " r e t u r n v a l u e " i s s e t i n t h e d e l a y s l o t . . .
* /
l. j _ s y s c a l l _ r e t u r n
l. a d d i r11 ,r0 ,- E N O S Y S
/******* END SYSCALL HANDLING *******/
/* ---[ 0xd00: Trap exception ]------------------------------------------ */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x d00 ,0 x d00 )
/* ---[ 0xe00: Trap exception ]------------------------------------------ */
EXCEPTION_ E N T R Y ( _ t r a p _ h a n d l e r )
2014-11-03 15:28:14 +03:00
CLEAR_ L W A _ F L A G ( r3 )
2011-06-04 12:05:39 +04:00
/* r4: EA of fault (set by EXCEPTION_HANDLE) */
l. j a l d o _ t r a p
l. a d d i r3 ,r1 ,0 / * p t _ r e g s * /
l. j _ r e t _ f r o m _ e x c e p t i o n
l. n o p
/* ---[ 0xf00: Reserved exception ]-------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x f00 ,0 x f00 )
/* ---[ 0x1000: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x10 0 0 ,0 x10 0 0 )
/* ---[ 0x1100: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x11 0 0 ,0 x11 0 0 )
/* ---[ 0x1200: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x12 0 0 ,0 x12 0 0 )
/* ---[ 0x1300: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x13 0 0 ,0 x13 0 0 )
/* ---[ 0x1400: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x14 0 0 ,0 x14 0 0 )
/* ---[ 0x1500: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x15 0 0 ,0 x15 0 0 )
/* ---[ 0x1600: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x16 0 0 ,0 x16 0 0 )
/* ---[ 0x1700: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x17 0 0 ,0 x17 0 0 )
/* ---[ 0x1800: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x18 0 0 ,0 x18 0 0 )
/* ---[ 0x1900: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x19 0 0 ,0 x19 0 0 )
/* ---[ 0x1a00: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x1 a00 ,0 x1 a00 )
/* ---[ 0x1b00: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x1 b00 ,0 x1 b00 )
/* ---[ 0x1c00: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x1 c00 ,0 x1 c00 )
/* ---[ 0x1d00: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x1 d00 ,0 x1 d00 )
/* ---[ 0x1e00: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x1 e 0 0 ,0 x1 e 0 0 )
/* ---[ 0x1f00: Reserved exception ]------------------------------------- */
UNHANDLED_ E X C E P T I O N ( _ v e c t o r _ 0 x1 f00 ,0 x1 f00 )
/* ========================================================[ return ] === */
2012-02-19 20:36:53 +04:00
_resume_userspace :
DISABLE_ I N T E R R U P T S ( r3 ,r4 )
l. l w z r4 ,T I _ F L A G S ( r10 )
l. a n d i r13 ,r4 ,_ T I F _ W O R K _ M A S K
l. s f e q i r13 ,0
l. b f _ r e s t o r e _ a l l
l. n o p
2011-06-04 12:05:39 +04:00
_work_pending :
2012-02-19 20:36:53 +04:00
l. l w z r5 ,P T _ O R I G _ G P R 1 1 ( r1 )
l. s f l t s i r5 ,0
l. b n f 1 f
2011-06-04 12:05:39 +04:00
l. n o p
2012-02-19 20:36:53 +04:00
l. a n d i r5 ,r5 ,0
1 :
l. j a l d o _ w o r k _ p e n d i n g
l. o r i r3 ,r1 ,0 / * p t _ r e g s * /
l. s f e q i r11 ,0
l. b f _ r e s t o r e _ a l l
2011-06-04 12:05:39 +04:00
l. n o p
2012-02-19 20:36:53 +04:00
l. s f l t s i r11 ,0
l. b n f 1 f
2011-06-04 12:05:39 +04:00
l. n o p
2012-02-19 20:36:53 +04:00
l. a n d r11 ,r11 ,r0
l. o r i r11 ,r11 ,_ _ N R _ r e s t a r t _ s y s c a l l
l. j _ s y s c a l l _ c h e c k _ t r a c e _ e n t e r
2011-06-04 12:05:39 +04:00
l. n o p
2012-02-19 20:36:53 +04:00
1 :
l. l w z r11 ,P T _ O R I G _ G P R 1 1 ( r1 )
/* Restore arg registers */
l. l w z r3 ,P T _ G P R 3 ( r1 )
l. l w z r4 ,P T _ G P R 4 ( r1 )
l. l w z r5 ,P T _ G P R 5 ( r1 )
l. l w z r6 ,P T _ G P R 6 ( r1 )
l. l w z r7 ,P T _ G P R 7 ( r1 )
l. j _ s y s c a l l _ c h e c k _ t r a c e _ e n t e r
l. l w z r8 ,P T _ G P R 8 ( r1 )
2011-06-04 12:05:39 +04:00
_restore_all :
RESTORE_ A L L
/* This returns to userspace code */
ENTRY( _ r e t _ f r o m _ i n t r )
ENTRY( _ r e t _ f r o m _ e x c e p t i o n )
l. l w z r4 ,P T _ S R ( r1 )
l. a n d i r3 ,r4 ,S P R _ S R _ S M
l. s f e q i r3 ,0
l. b n f _ r e s t o r e _ a l l
l. n o p
l. j _ r e s u m e _ u s e r s p a c e
l. n o p
ENTRY( r e t _ f r o m _ f o r k )
l. j a l s c h e d u l e _ t a i l
l. n o p
2012-10-19 20:07:44 +04:00
/* Check if we are a kernel thread */
l. s f e q i r20 ,0
l. b f 1 f
l. n o p
/* ...we are a kernel thread so invoke the requested callback */
l. j a l r r20
l. o r r3 ,r22 ,r0
1 :
2011-06-04 12:05:39 +04:00
/* _syscall_returns expect r11 to contain return value */
l. l w z r11 ,P T _ G P R 1 1 ( r1 )
/ * The s y s c a l l f a s t p a t h r e t u r n e x p e c t s c a l l - s a v e d r e g i s t e r s
* r1 2 - r28 t o b e u n t o u c h e d , s o w e r e s t o r e t h e m h e r e a s t h e y
* will h a v e b e e n e f f e c t i v e l y c l o b b e r e d w h e n a r r i v i n g h e r e
* via t h e c a l l t o s w i t c h ( )
* /
l. l w z r12 ,P T _ G P R 1 2 ( r1 )
l. l w z r14 ,P T _ G P R 1 4 ( r1 )
l. l w z r16 ,P T _ G P R 1 6 ( r1 )
l. l w z r18 ,P T _ G P R 1 8 ( r1 )
l. l w z r20 ,P T _ G P R 2 0 ( r1 )
l. l w z r22 ,P T _ G P R 2 2 ( r1 )
l. l w z r24 ,P T _ G P R 2 4 ( r1 )
l. l w z r26 ,P T _ G P R 2 6 ( r1 )
l. l w z r28 ,P T _ G P R 2 8 ( r1 )
l. j _ s y s c a l l _ r e t u r n
l. n o p
/* ========================================================[ switch ] === */
/ *
* This r o u t i n e s w i t c h e s b e t w e e n t w o d i f f e r e n t t a s k s . T h e p r o c e s s
* state o f o n e i s s a v e d o n i t s k e r n e l s t a c k . T h e n t h e s t a t e
* of t h e o t h e r i s r e s t o r e d f r o m i t s k e r n e l s t a c k . T h e m e m o r y
* management h a r d w a r e i s u p d a t e d t o t h e s e c o n d p r o c e s s ' s s t a t e .
* Finally, w e c a n r e t u r n t o t h e s e c o n d p r o c e s s , v i a t h e ' r e t u r n ' .
*
* Note : there a r e t w o w a y s t o g e t t o t h e " g o i n g o u t " p o r t i o n
* of t h i s c o d e ; either by coming in via the entry (_switch)
* or v i a " f o r k " w h i c h m u s t s e t u p a n e n v i r o n m e n t e q u i v a l e n t
* to t h e " _ s w i t c h " p a t h . I f y o u c h a n g e t h i s ( o r i n p a r t i c u l a r , t h e
* SAVE_ R E G S m a c r o ) , y o u ' l l h a v e t o c h a n g e t h e f o r k c o d e a l s o .
* /
/ * _ switch M U S T n e v e r l a y o n p a g e b o u n d r y , c a u s e i t r u n s f r o m
* effective a d d r e s s e s a n d b e e i n g i n t e r r u p t e d b y i T L B m i s s w o u l d k i l l i t .
* dTLB m i s s s e a m s t o n e v e r a c c o u r i n t h e b a d p l a c e s i n c e d a t a a c c e s s e s
* are f r o m t a s k s t r u c t u r e s w h i c h a r e a l w a y s p a g e a l i g n e d .
*
* The p r o b l e m h a p p e n s i n R E S T O R E _ A L L _ N O _ R 1 1 w h e r e w e f i r s t s e t t h e E P C R
* register, t h e n l o a d t h e p r e v i o u s r e g i s t e r v a l u e s a n d o n l y a t t h e e n d c a l l
* the l . r f e i n s t r u c t i o n . I f g e t T L B m i s s i n b e e t w e n t h e E P C R r e g i s t e r g e t s
* garbled a n d w e e n d u p c a l l i n g l . r f e w i t h t h e w r o n g E P C R . ( s a m e p r o b a b l y
* holds f o r E S R )
*
* To a v o i d t h i s p r o b l e m s i t i s s u f f i c i e n t t o a l i g n _ s w i t c h t o
* some n i c e r o u n d n u m b e r s m a l l e r t h a n i t ' s s i z e . . .
* /
/ * ABI r u l e s a p p l y h e r e . . . w e e i t h e r e n t e r _ s w i t c h v i a s c h e d u l e ( ) o r v i a
* an i m a g i n a r y c a l l t o w h i c h w e s h a l l r e t u r n a t r e t u r n _ f r o m _ f o r k . E i t h e r
* way, w e a r e a f u n c t i o n c a l l a n d o n l y n e e d t o p r e s e r v e t h e c a l l e e - s a v e d
* registers w h e n w e r e t u r n . A s s u c h , w e d o n ' t n e e d t o s a v e t h e r e g i s t e r s
* on t h e s t a c k t h a t w e w o n ' t b e r e t u r n i n g a s t h e y w e r e . . .
* /
.align 0x400
ENTRY( _ s w i t c h )
/ * We d o n ' t s t o r e S R a s _ s w i t c h o n l y g e t s c a l l e d i n a c o n t e x t w h e r e
* the S R w i l l b e t h e s a m e g o i n g i n a n d c o m i n g o u t . . . * /
/* Set up new pt_regs struct for saving task state */
l. a d d i r1 ,r1 ,- ( I N T _ F R A M E _ S I Z E )
/* No need to store r1/PT_SP as it goes into KSP below */
l. s w P T _ G P R 2 ( r1 ) ,r2
l. s w P T _ G P R 9 ( r1 ) ,r9
/ * This i s w r o n g , r12 s h o u l d n ' t b e h e r e . . . b u t G C C i s b r o k e n f o r t h e t i m e b e i n g
* and e x p e c t s r12 t o b e c a l l e e - s a v e d . . . * /
l. s w P T _ G P R 1 2 ( r1 ) ,r12
l. s w P T _ G P R 1 4 ( r1 ) ,r14
l. s w P T _ G P R 1 6 ( r1 ) ,r16
l. s w P T _ G P R 1 8 ( r1 ) ,r18
l. s w P T _ G P R 2 0 ( r1 ) ,r20
l. s w P T _ G P R 2 2 ( r1 ) ,r22
l. s w P T _ G P R 2 4 ( r1 ) ,r24
l. s w P T _ G P R 2 6 ( r1 ) ,r26
l. s w P T _ G P R 2 8 ( r1 ) ,r28
l. s w P T _ G P R 3 0 ( r1 ) ,r30
l. a d d i r11 ,r10 ,0 / * S a v e o l d ' c u r r e n t ' t o ' l a s t ' r e t u r n v a l u e * /
/ * We u s e t h r e a d _ i n f o - > k s p f o r s t o r i n g t h e a d d r e s s o f t h e a b o v e
* structure s o t h a t w e c a n g e t b a c k t o i t l a t e r . . . w e d o n ' t w a n t
* to l o s e t h e v a l u e o f t h r e a d _ i n f o - > k s p , t h o u g h , s o s t o r e i t a s
* pt_ r e g s - > s p s o t h a t w e c a n e a s i l y r e s t o r e i t w h e n w e a r e m a d e
* live a g a i n . . .
* /
/* Save the old value of thread_info->ksp as pt_regs->sp */
l. l w z r29 ,T I _ K S P ( r10 )
l. s w P T _ S P ( r1 ) ,r29
/* Swap kernel stack pointers */
l. s w T I _ K S P ( r10 ) ,r1 / * S a v e o l d s t a c k p o i n t e r * /
l. o r r10 ,r4 ,r0 / * S e t u p n e w c u r r e n t _ t h r e a d _ i n f o * /
l. l w z r1 ,T I _ K S P ( r10 ) / * L o a d n e w s t a c k p o i n t e r * /
/* Restore the old value of thread_info->ksp */
l. l w z r29 ,P T _ S P ( r1 )
l. s w T I _ K S P ( r10 ) ,r29
/ * . . .and restore the r e g i s t e r s , e x c e p t r11 b e c a u s e t h e r e t u r n v a l u e
* has a l r e a d y b e e n s e t a b o v e .
* /
l. l w z r2 ,P T _ G P R 2 ( r1 )
l. l w z r9 ,P T _ G P R 9 ( r1 )
/* No need to restore r10 */
/* ...and do not restore r11 */
/ * This i s w r o n g , r12 s h o u l d n ' t b e h e r e . . . b u t G C C i s b r o k e n f o r t h e t i m e b e i n g
* and e x p e c t s r12 t o b e c a l l e e - s a v e d . . . * /
l. l w z r12 ,P T _ G P R 1 2 ( r1 )
l. l w z r14 ,P T _ G P R 1 4 ( r1 )
l. l w z r16 ,P T _ G P R 1 6 ( r1 )
l. l w z r18 ,P T _ G P R 1 8 ( r1 )
l. l w z r20 ,P T _ G P R 2 0 ( r1 )
l. l w z r22 ,P T _ G P R 2 2 ( r1 )
l. l w z r24 ,P T _ G P R 2 4 ( r1 )
l. l w z r26 ,P T _ G P R 2 6 ( r1 )
l. l w z r28 ,P T _ G P R 2 8 ( r1 )
l. l w z r30 ,P T _ G P R 3 0 ( r1 )
/* Unwind stack to pre-switch state */
l. a d d i r1 ,r1 ,( I N T _ F R A M E _ S I Z E )
2012-10-14 18:19:52 +04:00
/ * Return v i a t h e l i n k - r e g i s t e r b a c k t o w h e r e w e ' c a m e f r o m ' , w h e r e
* that m a y b e e i t h e r s c h e d u l e ( ) , r e t _ f r o m _ f o r k ( ) , o r
* ret_ f r o m _ k e r n e l _ t h r e a d ( ) . I f w e a r e r e t u r n i n g t o a n e w t h r e a d ,
* we a r e e x p e c t e d t o h a v e s e t u p t h e a r g t o s c h e d u l e _ t a i l a l r e a d y ,
* hence w e d o s o h e r e u n c o n d i t i o n a l l y :
* /
2013-02-15 20:07:17 +04:00
l. l w z r3 ,T I _ T A S K ( r3 ) / * L o a d ' p r e v ' a s s c h e d u l e _ t a i l a r g * /
2011-06-04 12:05:39 +04:00
l. j r r9
l. n o p
/* ==================================================================== */
/ * These a l l u s e t h e d e l a y s l o t f o r s e t t i n g t h e a r g u m e n t r e g i s t e r , s o t h e
* jump i s a l w a y s h a p p e n i n g a f t e r t h e l . a d d i i n s t r u c t i o n .
*
* These a r e a l l j u s t w r a p p e r s t h a t d o n ' t t o u c h t h e l i n k - r e g i s t e r r9 , s o t h e
* return f r o m t h e " r e a l " s y s c a l l f u n c t i o n w i l l r e t u r n b a c k t o t h e s y s c a l l
* code t h a t d i d t h e l . j a l t h a t b r o u g h t u s h e r e .
* /
/ * fork r e q u i r e s t h a t w e s a v e a l l t h e c a l l e e - s a v e d r e g i s t e r s b e c a u s e t h e y
* are a l l e f f e c t i v e l y c l o b b e r e d b y t h e c a l l t o _ s w i t c h . H e r e w e s t o r e
* all t h e r e g i s t e r s t h a t a r e n ' t t o u c h e d b y t h e s y s c a l l f a s t p a t h a n d t h u s
* weren' t s a v e d t h e r e .
* /
_fork_save_extra_regs_and_call :
l. s w P T _ G P R 1 4 ( r1 ) ,r14
l. s w P T _ G P R 1 6 ( r1 ) ,r16
l. s w P T _ G P R 1 8 ( r1 ) ,r18
l. s w P T _ G P R 2 0 ( r1 ) ,r20
l. s w P T _ G P R 2 2 ( r1 ) ,r22
l. s w P T _ G P R 2 4 ( r1 ) ,r24
l. s w P T _ G P R 2 6 ( r1 ) ,r26
l. j r r29
l. s w P T _ G P R 2 8 ( r1 ) ,r28
2012-10-27 03:37:49 +04:00
ENTRY( _ _ s y s _ c l o n e )
l. m o v h i r29 ,h i ( s y s _ c l o n e )
l. o r i r29 ,r29 ,l o ( s y s _ c l o n e )
2011-06-04 12:05:39 +04:00
l. j _ f o r k _ s a v e _ e x t r a _ r e g s _ a n d _ c a l l
l. a d d i r7 ,r1 ,0
2012-10-27 03:37:49 +04:00
ENTRY( _ _ s y s _ f o r k )
l. m o v h i r29 ,h i ( s y s _ f o r k )
l. o r i r29 ,r29 ,l o ( s y s _ f o r k )
2011-06-04 12:05:39 +04:00
l. j _ f o r k _ s a v e _ e x t r a _ r e g s _ a n d _ c a l l
l. a d d i r3 ,r1 ,0
ENTRY( s y s _ r t _ s i g r e t u r n )
2013-09-23 14:04:20 +04:00
l. j a l _ s y s _ r t _ s i g r e t u r n
2011-06-04 12:05:39 +04:00
l. a d d i r3 ,r1 ,0
2013-09-23 14:04:20 +04:00
l. s f n e r30 ,r0
l. b n f _ n o _ s y s c a l l _ t r a c e
l. n o p
l. j a l d o _ s y s c a l l _ t r a c e _ l e a v e
l. a d d i r3 ,r1 ,0
_no_syscall_trace :
l. j _ r e s u m e _ u s e r s p a c e
l. n o p
2011-06-04 12:05:39 +04:00
/ * This i s a c a t c h - a l l s y s c a l l f o r a t o m i c i n s t r u c t i o n s f o r t h e O p e n R I S C 1 0 0 0 .
* The f u n c t i o n s t a k e s a v a r i a b l e n u m b e r o f p a r a m e t e r s d e p e n d i n g o n w h i c h
* particular f l a v o u r o f a t o m i c y o u w a n t . . . p a r a m e t e r 1 i s a f l a g i d e n t i f y i n g
* the a t o m i c i n q u e s t i o n . C u r r e n t l y , t h i s f u n c t i o n i m p l e m e n t s t h e
* following v a r i a n t s :
*
* XCHG :
* @flag: 1
* @ptr1:
* @ptr2:
* Atomically e x c h a n g e t h e v a l u e s i n p o i n t e r s 1 a n d 2 .
*
* /
ENTRY( s y s _ o r1 k _ a t o m i c )
/* FIXME: This ignores r3 and always does an XCHG */
DISABLE_ I N T E R R U P T S ( r17 ,r19 )
2012-04-18 14:23:39 +04:00
l. l w z r29 ,0 ( r4 )
l. l w z r27 ,0 ( r5 )
l. s w 0 ( r4 ) ,r27
l. s w 0 ( r5 ) ,r29
2011-06-04 12:05:39 +04:00
ENABLE_ I N T E R R U P T S ( r17 )
l. j r r9
l. o r r11 ,r0 ,r0
/* ============================================================[ EOF ]=== */