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 .
*
* Copyright ( C ) 1 9 9 5 - 2 0 0 0 , 2 0 0 1 b y R a l f B a e c h l e
* Copyright ( C ) 1 9 9 9 , 2 0 0 0 S i l i c o n G r a p h i c s , I n c .
* 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
*
* Hairy, t h e u s e r s p a c e a p p l i c a t i o n u s e s a d i f f e r e n t a r g u m e n t p a s s i n g
* convention t h a n t h e k e r n e l , s o w e h a v e t o t r a n s l a t e t h i n g s f r o m o 3 2
2013-01-22 12:59:30 +01:00
* to A B I 6 4 c a l l i n g c o n v e n t i o n . 6 4 - b i t s y s c a l l s a r e a l s o p r o c e s s e d
2005-04-16 15:20:36 -07:00
* here f o r n o w .
* /
# 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 / 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 / s y s m i p s . h >
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
ld 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
dsubu t 0 , 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 , t 0 , _ _ N R _ O 3 2 _ L i n u x _ s y s c a l l s
2005-04-16 15:20:36 -07:00
daddiu t 1 , 4 # s k i p t o n e x t i n s t r u c t i o n
sd t 1 , P T _ E P C ( s p )
beqz t 0 , n o t _ o 3 2 _ s c a l l
# if 0
SAVE_ A L L
move a1 , v0
2020-05-07 17:49:18 +08:00
ASM_ P R I N T ( " S c a l l % l d \ n " )
2005-04-16 15:20:36 -07:00
RESTORE_ A L L
# endif
/ * We d o n ' t w a n t t o s t u m b l e o v e r b r o k e n s i g n e x t e n s i o n s f r o m
userland. O 3 2 d o e s n e v e r u s e t h e u p p e r h a l f . * /
sll a0 , a0 , 0
sll a1 , a1 , 0
sll a2 , a2 , 0
sll a3 , a3 , 0
sd 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
/ *
* 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 ) .
*
* 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 .
* /
ld 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
daddu t 1 , t 0 , 3 2
bltz t 1 , b a d _ s t a c k
2015-07-08 04:49:10 +02:00
load_a4 : lw a4 , 1 6 ( t 0 ) # a r g u m e n t # 5 f r o m u s p
load_a5 : lw a5 , 2 0 ( t 0 ) # a r g u m e n t # 6 f r o m u s p
load_a6 : lw a6 , 2 4 ( t 0 ) # a r g u m e n t # 7 f r o m u s p
load_a7 : lw a7 , 2 8 ( t 0 ) # a r g u m e n t # 8 f r o m u s p
loads_done :
2005-04-16 15:20:36 -07:00
.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
2005-04-16 15:20:36 -07:00
.previous
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
LONG_ L 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 ?
and t 0 , t 1 , t 0
bnez t 0 , t r a c e _ a _ s y s c a l l
2015-09-25 08:17:42 +01:00
syscall_common :
2016-03-29 09:35:31 +01:00
dsll t 0 , v0 , 3 # o f f s e t i n t o t a b l e
ld t 2 , ( s y s32 _ c a l l _ t a b l e - ( _ _ N R _ O 3 2 _ L i n u x * 8 ) ) ( t 0 )
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
sd 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
ld 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
dnegu v0 # e r r o r
2010-09-28 18:50:37 +01:00
sd 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 : sd 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
/* ------------------------------------------------------------------------ */
trace_a_syscall :
SAVE_ S T A T I C
sd a4 , P T _ R 8 ( s p ) # S a v e a r g u m e n t r e g i s t e r s
sd a5 , P T _ R 9 ( s p )
sd a6 , P T _ R 1 0 ( s p )
sd a7 , P T _ R 1 1 ( s p ) # F o r i n d i r e c t s y s c a l l s
move a0 , s p
2014-01-22 14:40:03 +00:00
/ *
2014-07-24 12:10:02 +01:00
* absolute s y s c a l l 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 _ ## # )
2014-01-22 14:40:03 +00:00
* 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
* note : NR_ s y s c a l l i s t h e f i r s t O 3 2 s y s c a l l b u t t h e m a c r o i s
* only d e f i n e d w h e n c o m p i l i n g w i t h - m a b i =32 ( C O N F I G _ 3 2 B I T )
* therefore _ _ N R _ O 3 2 _ L i n u x i s u s e d ( 4 0 0 0 )
* /
2014-07-24 12:10:02 +01:00
.set push
.set reorder
subu t 1 , v0 , _ _ N R _ O 3 2 _ L i n u x
move a1 , v0
bnez t 1 , 1 f / * _ _ N R _ s y s c a l l a t o f f s e t 0 * /
2019-04-09 16:53:55 +02:00
ld a1 , P T _ R 4 ( s p ) / * A r g 1 f o r _ _ N R _ s y s c a l l c a s e * /
2014-07-24 12:10:02 +01:00
.set pop
2014-01-22 14:40:03 +00:00
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
2014-01-22 14:40:02 +00:00
2005-11-30 16:24:57 +00:00
RESTORE_ S T A T I C
2016-03-29 09:35:31 +01:00
ld 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
ld 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
ld a1 , P T _ R 5 ( s p )
ld a2 , P T _ R 6 ( s p )
ld a3 , P T _ R 7 ( s p )
ld a4 , P T _ R 8 ( s p )
ld a5 , P T _ R 9 ( s p )
ld a6 , P T _ R 1 0 ( s p )
ld a7 , P T _ R 1 1 ( s p ) # F o r i n d i r e c t s y s c a l l s
2016-03-29 09:35:31 +01:00
dsubu t 0 , v0 , _ _ N R _ O 3 2 _ L i n u x # c h e c k ( n e w ) s y s c a l l n u m b e r
2018-12-13 14:37:36 +05:30
sltiu t 0 , t 0 , _ _ N R _ O 3 2 _ L i n u x _ s y s c a l l s
2016-03-29 09:35:31 +01:00
beqz t 0 , n o t _ o 3 2 _ s c a l l
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
/* ------------------------------------------------------------------------ */
/ *
* The s t a c k p o i n t e r f o r a c a l l w i t h m o r e t h a n 4 a r g u m e n t s i s b a d .
* /
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
sd v0 , P T _ R 2 ( s p )
li t 0 , 1 # s e t e r r o r f l a g
sd 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 a4 , 0
b l o a d _ a5
bad_stack_a5 :
li a5 , 0
b l o a d _ a6
bad_stack_a6 :
li a6 , 0
b l o a d _ a7
bad_stack_a7 :
li a7 , 0
b l o a d s _ d o n e
2005-04-16 15:20:36 -07:00
not_o32_scall :
/ *
* This i s n o t a n o 3 2 c o m p a t i b i l i t y s y s c a l l , p a s s i t o n
* to t h e 6 4 - b i t s y s c a l l h a n d l e r s .
* /
# ifdef C O N F I G _ M I P S 3 2 _ N 3 2
j h a n d l e _ s y s n 3 2
# else
j h a n d l e _ s y s64
# endif
END( h a n d l e _ s y s )
LEAF( s y s32 _ s y s c a l l )
2008-11-18 15:05:46 -08:00
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
dsll t 1 , t 0 , 3
2005-04-16 15:20:36 -07:00
beqz v0 , e i n v a l
2012-07-12 14:01:31 +02:00
ld t 2 , s y s32 _ 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
2005-04-16 15:20:36 -07:00
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
move a3 , a4
move a4 , a5
move a5 , a6
move a6 , a7
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 s32 _ s y s c a l l )
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
2005-04-16 15:20:36 -07:00
.align 3
2012-07-12 14:01:31 +02:00
.type sys3 2 _ c a l l _ t a b l e ,@object
EXPORT( s y s32 _ 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 _ 6 4 _ o 3 2 . h >
# undef _ _ S Y S C A L L