2005-04-16 15:20:36 -07:00
/ * $ Id : rtrap. S ,v 1 . 5 8 2 0 0 2 / 0 1 / 3 1 0 3 : 3 0 : 0 5 d a v e m E x p $
* rtrap. S : R e t u r n f r o m S p a r c t r a p l o w - l e v e l c o d e .
*
* Copyright ( C ) 1 9 9 5 D a v i d S . M i l l e r ( d a v e m @caip.rutgers.edu)
* /
# include < a s m / p a g e . h >
# include < a s m / p t r a c e . h >
# include < a s m / p s r . h >
# include < a s m / a s i . h >
# include < a s m / s m p . h >
# include < a s m / c o n t r e g s . h >
# include < a s m / w i n m a c r o . h >
# include < a s m / a s m m a c r o . h >
# include < a s m / t h r e a d _ i n f o . h >
# define t _ p s r l 0
# define t _ p c l 1
# define t _ n p c l 2
# define t _ w i m l 3
# define t w i n _ t m p1 l 4
# define g l o b _ t m p g 4
# define c u r p t r g 6
/* 7 WINDOW SPARC PATCH INSTRUCTIONS */
.globl rtrap_ 7 w i n _ p a t c h1 , r t r a p _ 7 w i n _ p a t c h2 , r t r a p _ 7 w i n _ p a t c h3
.globl rtrap_ 7 w i n _ p a t c h4 , r t r a p _ 7 w i n _ p a t c h5
rtrap_7win_patch1 : srl % t _ w i m , 0 x6 , % g l o b _ t m p
rtrap_7win_patch2 : and % g l o b _ t m p , 0 x7 f , % g l o b _ t m p
rtrap_7win_patch3 : srl % g 1 , 7 , % g 2
rtrap_7win_patch4 : srl % g 2 , 6 , % g 2
rtrap_7win_patch5 : and % g 1 , 0 x7 f , % g 1
/* END OF PATCH INSTRUCTIONS */
/ * We n e e d t o c h e c k f o r a f e w t h i n g s w h i c h a r e :
* 1 ) The n e e d t o c a l l s c h e d u l e ( ) b e c a u s e t h i s
* processes q u a n t u m i s u p .
* 2 ) Pending s i g n a l s f o r t h i s p r o c e s s , i f a n y
* exist w e n e e d t o c a l l d o _ s i g n a l ( ) t o d o
* the n e e d y .
*
* Else w e j u s t c h e c k i f t h e r e t t w o u l d l a n d u s
* in a n i n v a l i d w i n d o w , i f s o w e n e e d t o g r a b
* it o f f t h e u s e r / k e r n e l s t a c k f i r s t .
* /
.globl ret_ t r a p _ e n t r y , r t r a p _ p a t c h1 , r t r a p _ p a t c h2
.globl rtrap_ p a t c h3 , r t r a p _ p a t c h4 , r t r a p _ p a t c h5
.globl ret_trap_lockless_ipi
ret_trap_entry :
ret_trap_lockless_ipi :
andcc % t _ p s r , P S R _ P S , % g 0
be 1 f
nop
wr % t _ p s r , 0 x0 , % p s r
b r e t _ t r a p _ k e r n e l
nop
1 :
ld [ % c u r p t r + T I _ F L A G S ] , % g 2
andcc % g 2 , ( _ T I F _ N E E D _ R E S C H E D ) , % g 0
be s i g n a l _ p
nop
call s c h e d u l e
nop
ld [ % c u r p t r + T I _ F L A G S ] , % g 2
signal_p :
2006-01-19 02:42:49 -08:00
andcc % g 2 , ( _ T I F _ S I G P E N D I N G | _ T I F _ R E S T O R E _ S I G M A S K ) , % g 0
2005-04-16 15:20:36 -07:00
bz,a r e t _ t r a p _ c o n t i n u e
ld [ % s p + S T A C K F R A M E _ S Z + P T _ P S R ] , % t _ p s r
2006-01-19 02:42:49 -08:00
mov % l 5 , % o 1
mov % l 6 , % o 2
2005-04-16 15:20:36 -07:00
call d o _ s i g n a l
2006-01-19 02:42:49 -08:00
add % s p , S T A C K F R A M E _ S Z , % o 0 ! p t _ r e g s p t r
2005-04-16 15:20:36 -07:00
/* Fall through. */
ld [ % s p + S T A C K F R A M E _ S Z + P T _ P S R ] , % t _ p s r
clr % l 6
ret_trap_continue :
wr % t _ p s r , 0 x0 , % p s r
WRITE_ P A U S E
ld [ % c u r p t r + T I _ W _ S A V E D ] , % t w i n _ t m p1
orcc % g 0 , % t w i n _ t m p1 , % g 0
be r e t _ t r a p _ n o b u f w i n s
nop
wr % t _ p s r , P S R _ E T , % p s r
WRITE_ P A U S E
mov 1 , % o 1
call t r y _ t o _ c l e a r _ w i n d o w _ b u f f e r
add % s p , S T A C K F R A M E _ S Z , % o 0
b s i g n a l _ p
ld [ % c u r p t r + T I _ F L A G S ] , % g 2
ret_trap_nobufwins :
/ * Load u p t h e u s e r ' s o u t r e g i s t e r s s o w e c a n p u l l
* a w i n d o w f r o m t h e s t a c k , i f n e c e s s a r y .
* /
LOAD_ P T _ I N S ( s p )
/ * If t h e r e a r e a l r e a d y l i v e u s e r w i n d o w s i n t h e
* set w e c a n r e t u r n f r o m t r a p s a f e l y .
* /
ld [ % c u r p t r + T I _ U W I N M A S K ] , % t w i n _ t m p1
orcc % g 0 , % t w i n _ t m p1 , % g 0
bne r e t _ t r a p _ u s e r w i n s _ o k
nop
/ * Calculate n e w % w i m , w e h a v e t o p u l l a r e g i s t e r
* window f r o m t h e u s e r s s t a c k .
* /
ret_trap_pull_one_window :
rd % w i m , % t _ w i m
sll % t _ w i m , 0 x1 , % t w i n _ t m p1
rtrap_patch1 : srl % t _ w i m , 0 x7 , % g l o b _ t m p
or % g l o b _ t m p , % t w i n _ t m p1 , % g l o b _ t m p
rtrap_patch2 : and % g l o b _ t m p , 0 x f f , % g l o b _ t m p
wr % g l o b _ t m p , 0 x0 , % w i m
/ * Here c o m e s t h e a r c h i t e c t u r e s p e c i f i c
* branch t o t h e u s e r s t a c k c h e c k i n g r o u t i n e
* for r e t u r n f r o m t r a p s .
* /
.globl rtrap_mmu_patchme
rtrap_mmu_patchme : b s u n 4 c _ r e t t _ s t a c k c h k
andcc % f p , 0 x7 , % g 0
ret_trap_userwins_ok :
LOAD_ P T _ P R I V ( s p , t _ p s r , t _ p c , t _ n p c )
or % t _ p c , % t _ n p c , % g 2
andcc % g 2 , 0 x3 , % g 0
be 1 f
nop
b r e t _ t r a p _ u n a l i g n e d _ p c
add % s p , S T A C K F R A M E _ S Z , % o 0
1 :
LOAD_ P T _ Y R E G ( s p , g 1 )
LOAD_ P T _ G L O B A L S ( s p )
wr % t _ p s r , 0 x0 , % p s r
WRITE_ P A U S E
jmp % t _ p c
rett % t _ n p c
ret_trap_unaligned_pc :
ld [ % s p + S T A C K F R A M E _ S Z + P T _ P C ] , % o 1
ld [ % s p + S T A C K F R A M E _ S Z + P T _ N P C ] , % o 2
ld [ % s p + S T A C K F R A M E _ S Z + P T _ P S R ] , % o 3
wr % t _ w i m , 0 x0 , % w i m ! o r e l s e . . .
wr % t _ p s r , P S R _ E T , % p s r
WRITE_ P A U S E
call d o _ m e m a c c e s s _ u n a l i g n e d
nop
b s i g n a l _ p
ld [ % c u r p t r + T I _ F L A G S ] , % g 2
ret_trap_kernel :
/* Will the rett land us in the invalid window? */
mov 2 , % g 1
sll % g 1 , % t _ p s r , % g 1
rtrap_patch3 : srl % g 1 , 8 , % g 2
or % g 1 , % g 2 , % g 1
rd % w i m , % g 2
andcc % g 2 , % g 1 , % g 0
be 1 f ! N o p e , j u s t r e t u r n f r o m t h e t r a p
sll % g 2 , 0 x1 , % g 1
/* We have to grab a window before returning. */
rtrap_patch4 : srl % g 2 , 7 , % g 2
or % g 1 , % g 2 , % g 1
rtrap_patch5 : and % g 1 , 0 x f f , % g 1
wr % g 1 , 0 x0 , % w i m
/* Grrr, make sure we load from the right %sp... */
LOAD_ P T _ A L L ( s p , t _ p s r , t _ p c , t _ n p c , g 1 )
restore % g 0 , % g 0 , % g 0
LOAD_ W I N D O W ( s p )
b 2 f
save % g 0 , % g 0 , % g 0
/ * Reload t h e e n t i r e f r a m e i n c a s e t h i s i s f r o m a
* kernel s y s t e m c a l l o r w h a t e v e r . . .
* /
1 :
LOAD_ P T _ A L L ( s p , t _ p s r , t _ p c , t _ n p c , g 1 )
2 :
wr % t _ p s r , 0 x0 , % p s r
WRITE_ P A U S E
jmp % t _ p c
rett % t _ n p c
ret_trap_user_stack_is_bolixed :
wr % t _ w i m , 0 x0 , % w i m
wr % t _ p s r , P S R _ E T , % p s r
WRITE_ P A U S E
call w i n d o w _ r e t _ f a u l t
add % s p , S T A C K F R A M E _ S Z , % o 0
b s i g n a l _ p
ld [ % c u r p t r + T I _ F L A G S ] , % g 2
.globl sun4c_rett_stackchk
sun4c_rett_stackchk :
be 1 f
and % f p , 0 x f f f , % g 1 ! d e l a y s l o t
b r e t _ t r a p _ u s e r _ s t a c k _ i s _ b o l i x e d + 0 x4
wr % t _ w i m , 0 x0 , % w i m
/* See if we have to check the sanity of one page or two */
1 :
add % g 1 , 0 x38 , % g 1
sra % f p , 2 9 , % g 2
add % g 2 , 0 x1 , % g 2
andncc % g 2 , 0 x1 , % g 0
be 1 f
andncc % g 1 , 0 x f f8 , % g 0
/* %sp is in vma hole, yuck */
b r e t _ t r a p _ u s e r _ s t a c k _ i s _ b o l i x e d + 0 x4
wr % t _ w i m , 0 x0 , % w i m
1 :
be s u n 4 c _ r e t t _ o n e p a g e / * O n l y o n e p a g e t o c h e c k * /
lda [ % f p ] A S I _ P T E , % g 2
sun4c_rett_twopages :
add % f p , 0 x38 , % g 1
sra % g 1 , 2 9 , % g 2
add % g 2 , 0 x1 , % g 2
andncc % g 2 , 0 x1 , % g 0
be 1 f
lda [ % g 1 ] A S I _ P T E , % g 2
/* Second page is in vma hole */
b r e t _ t r a p _ u s e r _ s t a c k _ i s _ b o l i x e d + 0 x4
wr % t _ w i m , 0 x0 , % w i m
1 :
srl % g 2 , 2 9 , % g 2
andcc % g 2 , 0 x4 , % g 0
bne s u n 4 c _ r e t t _ o n e p a g e
lda [ % f p ] A S I _ P T E , % g 2
/* Second page has bad perms */
b r e t _ t r a p _ u s e r _ s t a c k _ i s _ b o l i x e d + 0 x4
wr % t _ w i m , 0 x0 , % w i m
sun4c_rett_onepage :
srl % g 2 , 2 9 , % g 2
andcc % g 2 , 0 x4 , % g 0
bne,a 1 f
restore % g 0 , % g 0 , % g 0
/* A page had bad page permissions, losing... */
b r e t _ t r a p _ u s e r _ s t a c k _ i s _ b o l i x e d + 0 x4
wr % t _ w i m , 0 x0 , % w i m
/* Whee, things are ok, load the window and continue. */
1 :
LOAD_ W I N D O W ( s p )
b r e t _ t r a p _ u s e r w i n s _ o k
save % g 0 , % g 0 , % g 0
.globl srmmu_rett_stackchk
srmmu_rett_stackchk :
bne r e t _ t r a p _ u s e r _ s t a c k _ i s _ b o l i x e d
sethi % h i ( P A G E _ O F F S E T ) , % g 1
cmp % g 1 , % f p
bleu r e t _ t r a p _ u s e r _ s t a c k _ i s _ b o l i x e d
mov A C _ M _ S F S R , % g 1
lda [ % g 1 ] A S I _ M _ M M U R E G S , % g 0
lda [ % g 0 ] A S I _ M _ M M U R E G S , % g 1
or % g 1 , 0 x2 , % g 1
sta % g 1 , [ % g 0 ] A S I _ M _ M M U R E G S
restore % g 0 , % g 0 , % g 0
LOAD_ W I N D O W ( s p )
save % g 0 , % g 0 , % g 0
andn % g 1 , 0 x2 , % g 1
sta % g 1 , [ % g 0 ] A S I _ M _ M M U R E G S
mov A C _ M _ S F A R , % g 2
lda [ % g 2 ] A S I _ M _ M M U R E G S , % g 2
mov A C _ M _ S F S R , % g 1
lda [ % g 1 ] A S I _ M _ M M U R E G S , % g 1
andcc % g 1 , 0 x2 , % g 0
be r e t _ t r a p _ u s e r w i n s _ o k
nop
b,a r e t _ t r a p _ u s e r _ s t a c k _ i s _ b o l i x e d