2005-04-16 15:20:36 -07:00
/ *
* This f i l e i s s u b j e c t t o t h e t e r m s a n d c o n d i t i o n s o f t h e G N U G e n e r a l P u b l i c
* License. S e e t h e f i l e " C O P Y I N G " i n t h e m a i n d i r e c t o r y o f t h i s a r c h i v e
* for m o r e d e t a i l s .
*
2006-07-07 14:07:18 +01:00
* Copyright ( C ) 1 9 9 5 - 9 9 , 2 0 0 0 - 0 2 , 0 6 R a l f B a e c h l e < r a l f @linux-mips.org>
2005-04-16 15:20:36 -07:00
* Copyright ( C ) 2 0 0 1 M I P S T e c h n o l o g i e s , I n c .
* Copyright ( C ) 2 0 0 4 T h i e m o S e u f e r
2013-12-04 14:35:28 +00:00
* Copyright ( C ) 2 0 1 4 I m a g i n a t i o n T e c h n o l o g i e s L t d .
2005-04-16 15:20:36 -07:00
* /
# include < l i n u x / e r r n o . h >
# include < a s m / a s m . h >
# include < a s m / a s m m a c r o . h >
2006-07-07 14:07:18 +01:00
# include < a s m / i r q f l a g s . h >
2005-04-16 15:20:36 -07:00
# include < a s m / m i p s r e g s . h >
# include < a s m / r e g d e f . h >
# include < a s m / s t a c k f r a m e . h >
# include < a s m / i s a d e p . h >
# include < a s m / s y s m i p s . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / u n i s t d . h >
# include < a s m / w a r . h >
2005-09-09 22:32:31 +02:00
# include < a s m / a s m - o f f s e t s . h >
2005-04-16 15:20:36 -07:00
2013-01-22 12:59:30 +01:00
.align 5
2005-04-16 15:20:36 -07:00
NESTED( h a n d l e _ s y s , P T _ S I Z E , s p )
.set noat
SAVE_ S O M E
2006-09-26 23:43:40 +09:00
TRACE_ I R Q S _ O N _ R E L O A D
2005-04-16 15:20:36 -07:00
STI
.set at
lw t 1 , P T _ E P C ( s p ) # s k i p s y s c a l l o n r e t u r n
addiu t 1 , 4 # s k i p t o n e x t i n s t r u c t i o n
sw t 1 , P T _ E P C ( s p )
sw a3 , P T _ R 2 6 ( s p ) # s a v e a 3 f o r s y s c a l l r e s t a r t i n g
2012-07-14 09:22:05 +02:00
/ *
* More t h a n f o u r a r g u m e n t s . T r y t o d e a l w i t h i t b y c o p y i n g t h e
* stack a r g u m e n t s f r o m t h e u s e r s t a c k t o t h e k e r n e l s t a c k .
* This S u c k s ( T M ) .
* /
lw t 0 , P T _ R 2 9 ( s p ) # g e t o l d u s e r s t a c k p o i n t e r
/ *
* We i n t e n t i o n a l l y k e e p t h e k e r n e l s t a c k a l i t t l e b e l o w t h e t o p o f
* userspace s o w e d o n ' t h a v e t o d o a s l o w e r b y t e a c c u r a t e c h e c k h e r e .
* /
lw t 5 , T I _ A D D R _ L I M I T ( $ 2 8 )
addu t 4 , t 0 , 3 2
and t 5 , t 4
bltz t 5 , b a d _ s t a c k # - > s p i s b a d
/ *
* Ok, c o p y t h e a r g s f r o m t h e l u s e r s t a c k t o t h e k e r n e l s t a c k .
* /
.set push
.set noreorder
.set nomacro
2015-07-08 04:49:10 +02:00
load_a4 : user_ l w ( t 5 , 1 6 ( t 0 ) ) # a r g u m e n t # 5 f r o m u s p
load_a5 : user_ l w ( t 6 , 2 0 ( t 0 ) ) # a r g u m e n t # 6 f r o m u s p
load_a6 : user_ l w ( t 7 , 2 4 ( t 0 ) ) # a r g u m e n t # 7 f r o m u s p
load_a7 : user_ l w ( t 8 , 2 8 ( t 0 ) ) # a r g u m e n t # 8 f r o m u s p
loads_done :
2012-07-14 09:22:05 +02:00
sw t 5 , 1 6 ( s p ) # a r g u m e n t # 5 t o k s p
sw t 6 , 2 0 ( s p ) # a r g u m e n t # 6 t o k s p
sw t 7 , 2 4 ( s p ) # a r g u m e n t # 7 t o k s p
sw t 8 , 2 8 ( s p ) # a r g u m e n t # 8 t o k s p
.set pop
.section _ _ ex_ t a b l e ," a "
2015-07-08 04:49:10 +02:00
PTR l o a d _ a4 , b a d _ s t a c k _ a4
PTR l o a d _ a5 , b a d _ s t a c k _ a5
PTR l o a d _ a6 , b a d _ s t a c k _ a6
PTR l o a d _ a7 , b a d _ s t a c k _ a7
2012-07-14 09:22:05 +02:00
.previous
2005-04-16 15:20:36 -07:00
lw t 0 , T I _ F L A G S ( $ 2 8 ) # s y s c a l l t r a c i n g e n a b l e d ?
2013-05-29 01:02:18 +02:00
li t 1 , _ T I F _ W O R K _ S Y S C A L L _ E N T R Y
2005-04-16 15:20:36 -07:00
and t 0 , t 1
2013-01-22 12:59:30 +01:00
bnez t 0 , s y s c a l l _ t r a c e _ e n t r y # - > y e s
2015-09-25 08:17:42 +01:00
syscall_common :
2016-03-29 09:35:31 +01:00
subu v0 , v0 , _ _ N R _ O 3 2 _ L i n u x # c h e c k s y s c a l l n u m b e r
2018-12-13 14:37:36 +05:30
sltiu t 0 , v0 , _ _ N R _ O 3 2 _ L i n u x _ s y s c a l l s
2015-09-25 08:17:42 +01:00
beqz t 0 , i l l e g a l _ s y s c a l l
sll t 0 , v0 , 2
la t 1 , s y s _ c a l l _ t a b l e
addu t 1 , t 0
lw t 2 , ( t 1 ) # s y s c a l l r o u t i n e
beqz t 2 , i l l e g a l _ s y s c a l l
2005-04-16 15:20:36 -07:00
jalr t 2 # D o T h e R e a l T h i n g ( T M )
li t 0 , - E M A X E R R N O - 1 # e r r o r ?
sltu t 0 , t 0 , v0
sw t 0 , P T _ R 7 ( s p ) # s e t e r r o r f l a g
beqz t 0 , 1 f
2010-09-28 18:50:37 +01:00
lw t 1 , P T _ R 2 ( s p ) # s y s c a l l n u m b e r
2005-04-16 15:20:36 -07:00
negu v0 # e r r o r
2010-09-28 18:50:37 +01:00
sw t 1 , P T _ R 0 ( s p ) # s a v e i t f o r s y s c a l l r e s t a r t i n g
2005-04-16 15:20:36 -07:00
1 : sw v0 , P T _ R 2 ( s p ) # r e s u l t
o32_syscall_exit :
2012-05-05 16:11:35 -04:00
j s y s c a l l _ e x i t _ p a r t i a l
2005-04-16 15:20:36 -07:00
/* ------------------------------------------------------------------------ */
syscall_trace_entry :
SAVE_ S T A T I C
move a0 , s p
2014-01-22 14:40:03 +00:00
/ *
* syscall n u m b e r i s i n v0 u n l e s s w e c a l l e d s y s c a l l ( _ _ N R _ ## # )
* where t h e r e a l s y s c a l l n u m b e r i s i n a0
* /
2016-03-29 09:35:31 +01:00
move a1 , v0
subu t 2 , v0 , _ _ N R _ O 3 2 _ L i n u x
bnez t 2 , 1 f / * _ _ N R _ s y s c a l l a t o f f s e t 0 * /
2014-01-22 14:40:03 +00:00
lw a1 , P T _ R 4 ( s p )
1 : jal s y s c a l l _ t r a c e _ e n t e r
2005-04-16 15:20:36 -07:00
2015-09-25 08:17:42 +01:00
bltz v0 , 1 f # s e c c o m p f a i l e d ? S k i p s y s c a l l
2005-11-30 16:24:57 +00:00
RESTORE_ S T A T I C
2016-03-29 09:35:31 +01:00
lw v0 , P T _ R 2 ( s p ) # R e s t o r e s y s c a l l ( m a y b e m o d i f i e d )
2005-04-16 15:20:36 -07:00
lw a0 , P T _ R 4 ( s p ) # R e s t o r e a r g u m e n t r e g i s t e r s
lw a1 , P T _ R 5 ( s p )
lw a2 , P T _ R 6 ( s p )
lw a3 , P T _ R 7 ( s p )
2015-09-25 08:17:42 +01:00
j s y s c a l l _ c o m m o n
2005-04-16 15:20:36 -07:00
2015-09-25 08:17:42 +01:00
1 : j s y s c a l l _ e x i t
2005-04-16 15:20:36 -07:00
/* ------------------------------------------------------------------------ */
/ *
2015-07-08 04:49:10 +02:00
* Our o p e n - c o d e d a c c e s s a r e a s a n i t y t e s t f o r t h e s t a c k p o i n t e r
* failed. W e p r o b a b l y s h o u l d h a n d l e t h i s c a s e a b i t m o r e d r a s t i c .
2005-04-16 15:20:36 -07:00
* /
bad_stack :
2010-09-28 18:50:47 +01:00
li v0 , E F A U L T
2005-04-16 15:20:36 -07:00
sw v0 , P T _ R 2 ( s p )
li t 0 , 1 # s e t e r r o r f l a g
sw t 0 , P T _ R 7 ( s p )
j o 3 2 _ s y s c a l l _ e x i t
2015-07-08 04:49:10 +02:00
bad_stack_a4 :
li t 5 , 0
b l o a d _ a5
bad_stack_a5 :
li t 6 , 0
b l o a d _ a6
bad_stack_a6 :
li t 7 , 0
b l o a d _ a7
bad_stack_a7 :
li t 8 , 0
b l o a d s _ d o n e
2005-04-16 15:20:36 -07:00
/ *
* The s y s t e m c a l l d o e s n o t e x i s t i n t h i s k e r n e l
* /
illegal_syscall :
2008-10-25 01:17:22 +09:00
li v0 , E N O S Y S # e r r o r
2005-04-16 15:20:36 -07:00
sw v0 , P T _ R 2 ( s p )
li t 0 , 1 # s e t e r r o r f l a g
sw t 0 , P T _ R 7 ( s p )
j o 3 2 _ s y s c a l l _ e x i t
END( h a n d l e _ s y s )
LEAF( s y s _ s y s c a l l )
subu t 0 , a0 , _ _ N R _ O 3 2 _ L i n u x # c h e c k s y s c a l l n u m b e r
2018-12-13 14:37:36 +05:30
sltiu v0 , t 0 , _ _ N R _ O 3 2 _ L i n u x _ s y s c a l l s
2008-11-18 15:05:46 -08:00
beqz t 0 , e i n v a l # d o n o t r e c u r s e
2012-07-14 09:22:05 +02:00
sll t 1 , t 0 , 2
2005-04-16 15:20:36 -07:00
beqz v0 , e i n v a l
lw t 2 , s y s _ c a l l _ t a b l e ( t 1 ) # s y s c a l l r o u t i n e
move a0 , a1 # s h i f t a r g u m e n t r e g i s t e r s
move a1 , a2
move a2 , a3
lw a3 , 1 6 ( s p )
lw t 4 , 2 0 ( s p )
lw t 5 , 2 4 ( s p )
lw t 6 , 2 8 ( s p )
sw t 4 , 1 6 ( s p )
sw t 5 , 2 0 ( s p )
sw t 6 , 2 4 ( s p )
jr t 2
/* Unreached */
2013-01-22 12:59:30 +01:00
einval : li v0 , - E N O S Y S
2005-04-16 15:20:36 -07:00
jr r a
END( s y s _ s y s c a l l )
2018-12-13 14:37:37 +05:30
# ifdef C O N F I G _ M I P S _ M T _ F P A F F
/ *
* For F P U a f f i n i t y s c h e d u l i n g o n M I P S M T p r o c e s s o r s , w e n e e d t o
* intercept s y s _ s c h e d _ x x x a f f i n i t y ( ) c a l l s u n t i l w e g e t a p r o p e r h o o k
* in k e r n e l / s c h e d / c o r e . c . C o n s i d e r e d o n l y t e m p o r a r y w e o n l y s u p p o r t
* these h o o k s f o r t h e 3 2 - b i t k e r n e l - t h e r e i s n o M I P S 6 4 M T p r o c e s s o r
* atm.
* /
# define s y s _ s c h e d _ s e t a f f i n i t y m i p s m t _ s y s _ s c h e d _ s e t a f f i n i t y
# define s y s _ s c h e d _ g e t a f f i n i t y m i p s m t _ s y s _ s c h e d _ g e t a f f i n i t y
# endif / * C O N F I G _ M I P S _ M T _ F P A F F * /
2019-01-02 20:26:17 +05:30
# define _ _ S Y S C A L L ( n r , e n t r y ) P T R e n t r y
2012-07-14 09:22:05 +02:00
.align 2
.type sys_ c a l l _ t a b l e , @object
EXPORT( s y s _ c a l l _ t a b l e )
2018-12-13 14:37:39 +05:30
# include < a s m / s y s c a l l _ t a b l e _ 3 2 _ o 3 2 . h >
# undef _ _ S Y S C A L L