2008-04-28 11:47:20 +04:00
/ * SunOS' s e x e c v ( ) c a l l o n l y s p e c i f i e s t h e a r g v a r g u m e n t , t h e
* environment s e t t i n g s a r e t h e s a m e a s t h e c a l l i n g p r o c e s s e s .
* /
sys_execve :
sethi % h i ( s p a r c _ e x e c v e ) , % g 1
ba,p t % x c c , e x e c v e _ m e r g e
or % g 1 , % l o ( s p a r c _ e x e c v e ) , % g 1
# ifdef C O N F I G _ C O M P A T
sunos_execv :
stx % g 0 , [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 2 ]
sys32_execve :
sethi % h i ( s p a r c32 _ e x e c v e ) , % g 1
or % g 1 , % l o ( s p a r c32 _ e x e c v e ) , % g 1
# endif
execve_merge :
flushw
jmpl % g 1 , % g 0
add % s p , P T R E G S _ O F F , % o 0
.align 32
2009-01-14 16:13:56 +03:00
sys_sparc_pipe :
2009-01-20 08:11:27 +03:00
ba,p t % x c c , s y s _ s p a r c _ p i p e _ r e a l
2008-04-28 11:47:20 +04:00
add % s p , P T R E G S _ O F F , % o 0
sys_nis_syscall :
ba,p t % x c c , c _ s y s _ n i s _ s y s c a l l
add % s p , P T R E G S _ O F F , % o 0
sys_memory_ordering :
ba,p t % x c c , s p a r c _ m e m o r y _ o r d e r i n g
add % s p , P T R E G S _ O F F , % o 1
sys_sigaltstack :
ba,p t % x c c , d o _ s i g a l t s t a c k
add % i 6 , S T A C K _ B I A S , % o 2
# ifdef C O N F I G _ C O M P A T
sys32_sigstack :
ba,p t % x c c , d o _ s y s32 _ s i g s t a c k
mov % i 6 , % o 2
sys32_sigaltstack :
ba,p t % x c c , d o _ s y s32 _ s i g a l t s t a c k
mov % i 6 , % o 2
# endif
.align 32
# ifdef C O N F I G _ C O M P A T
sys32_sigreturn :
add % s p , P T R E G S _ O F F , % o 0
call d o _ s i g r e t u r n 3 2
add % o 7 , 1 f - . - 4 , % o 7
nop
# endif
sys_rt_sigreturn :
add % s p , P T R E G S _ O F F , % o 0
call d o _ r t _ s i g r e t u r n
add % o 7 , 1 f - . - 4 , % o 7
nop
# ifdef C O N F I G _ C O M P A T
sys32_rt_sigreturn :
add % s p , P T R E G S _ O F F , % o 0
call d o _ r t _ s i g r e t u r n 3 2
add % o 7 , 1 f - . - 4 , % o 7
nop
# endif
.align 32
1 : ldx [ % g 6 + T I _ F L A G S ] , % l 5
andcc % l 5 , ( _ T I F _ S Y S C A L L _ T R A C E | _ T I F _ S E C C O M P | _ T I F _ S Y S C A L L _ A U D I T ) , % g 0
be,p t % i c c , r t r a p
nop
2008-08-25 07:10:23 +04:00
call s y s c a l l _ t r a c e _ l e a v e
add % s p , P T R E G S _ O F F , % o 0
2008-04-28 11:47:20 +04:00
ba,p t % x c c , r t r a p
nop
/ * This i s h o w f o r k ( ) w a s m e a n t t o b e d o n e , 8 i n s t r u c t i o n e n t r y .
*
* I q u e s t i o n e d t h e f o l l o w i n g c o d e b r i e f l y , l e t m e c l e a r t h i n g s
* up s o y o u m u s t n o t r e a s o n o n i t l i k e I d i d .
*
* Know t h e f o r k _ k p s r e t c . w e u s e i n t h e s p a r c32 p o r t ? W e d o n ' t
* need i t h e r e b e c a u s e t h e o n l y p i e c e o f w i n d o w s t a t e w e c o p y t o
* the c h i l d i s t h e C W P r e g i s t e r . E v e n i f t h e p a r e n t s l e e p s ,
* we a r e s a f e b e c a u s e w e s t u c k i t i n t o p t _ r e g s o f t h e p a r e n t
* so i t w i l l n o t c h a n g e .
*
* XXX T h i s r a i s e s t h e q u e s t i o n , w h e t h e r w e c a n d o t h e s a m e o n
* XXX s p a r c32 t o g e t r i d o f f o r k _ k p s r _ a n d _ f o r k _ k w i m . T h e
* XXX a n s w e r i s y e s . W e s t i c k f o r k _ k p s r i n U R E G _ G 0 a n d
* XXX f o r k _ k w i m i n U R E G _ G 1 ( g l o b a l r e g i s t e r s a r e c o n s i d e r e d
* XXX v o l a t i l e a c r o s s a s y s t e m c a l l i n t h e s p a r c A B I I t h i n k
* XXX i f i t i s n ' t w e c a n u s e r e g s - > y i n s t e a d , a n y o n e w h o d e p e n d s
* XXX u p o n t h e Y r e g i s t e r b e i n g p r e s e r v e d a c r o s s a f o r k d e s e r v e s
* XXX t o l o s e ) .
*
* In f a c t w e s h o u l d t a k e a d v a n t a g e o f t h a t f a c t f o r o t h e r t h i n g s
* during s y s t e m c a l l s . . .
* /
.align 32
sys_vfork : /* Under Linux, vfork and fork are just special cases of clone. */
sethi % h i ( 0 x40 0 0 | 0 x01 0 0 | S I G C H L D ) , % o 0
or % o 0 , % l o ( 0 x40 0 0 | 0 x01 0 0 | S I G C H L D ) , % o 0
ba,p t % x c c , s y s _ c l o n e
sys_fork :
clr % o 1
mov S I G C H L D , % o 0
sys_clone :
flushw
movrz % o 1 , % f p , % o 1
mov 0 , % o 3
ba,p t % x c c , s p a r c _ d o _ f o r k
add % s p , P T R E G S _ O F F , % o 2
.globl ret_from_syscall
ret_from_syscall :
/ * Clear c u r r e n t _ t h r e a d _ i n f o ( ) - > n e w _ c h i l d , a n d
* check p e r f o r m a n c e c o u n t e r s t u f f t o o .
* /
stb % g 0 , [ % g 6 + T I _ N E W _ C H I L D ]
ldx [ % g 6 + T I _ F L A G S ] , % l 0
call s c h e d u l e _ t a i l
mov % g 7 , % o 0
andcc % l 0 , _ T I F _ P E R F C T R , % g 0
be,p t % i c c , 1 f
nop
ldx [ % g 6 + T I _ P C R ] , % o 7
wr % g 0 , % o 7 , % p c r
/ * Blackbird e r r a t a w o r k a r o u n d . S e e c o m m e n t a r y i n
* smp. c : s m p _ p e r c p u _ t i m e r _ i n t e r r u p t ( ) f o r m o r e
* information.
* /
ba,p t % x c c , 9 9 f
nop
.align 64
99 : wr % g 0 , % g 0 , % p i c
rd % p i c , % g 0
1 : ba,p t % x c c , r e t _ s y s _ c a l l
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 0 ] , % o 0
.globl sparc_exit
.type sparc_ e x i t ,#f u n c t i o n
sparc_exit :
rdpr % p s t a t e , % g 2
wrpr % g 2 , P S T A T E _ I E , % p s t a t e
rdpr % o t h e r w i n , % g 1
rdpr % c a n s a v e , % g 3
add % g 3 , % g 1 , % g 3
wrpr % g 3 , 0 x0 , % c a n s a v e
wrpr % g 0 , 0 x0 , % o t h e r w i n
wrpr % g 2 , 0 x0 , % p s t a t e
ba,p t % x c c , s y s _ e x i t
stb % g 0 , [ % g 6 + T I _ W S A V E D ]
.size sparc_ e x i t ,. - s p a r c _ e x i t
linux_sparc_ni_syscall :
sethi % h i ( s y s _ n i _ s y s c a l l ) , % l 7
ba,p t % x c c , 4 f
or % l 7 , % l o ( s y s _ n i _ s y s c a l l ) , % l 7
linux_syscall_trace32 :
2008-08-25 07:10:23 +04:00
call s y s c a l l _ t r a c e _ e n t e r
add % s p , P T R E G S _ O F F , % o 0
2008-07-27 11:30:50 +04:00
brnz,p n % o 0 , 3 f
mov - E N O S Y S , % o 0
2008-04-28 11:47:20 +04:00
srl % i 0 , 0 , % o 0
srl % i 4 , 0 , % o 4
srl % i 1 , 0 , % o 1
srl % i 2 , 0 , % o 2
ba,p t % x c c , 2 f
srl % i 3 , 0 , % o 3
linux_syscall_trace :
2008-08-25 07:10:23 +04:00
call s y s c a l l _ t r a c e _ e n t e r
add % s p , P T R E G S _ O F F , % o 0
2008-07-27 11:30:50 +04:00
brnz,p n % o 0 , 3 f
mov - E N O S Y S , % o 0
2008-04-28 11:47:20 +04:00
mov % i 0 , % o 0
mov % i 1 , % o 1
mov % i 2 , % o 2
mov % i 3 , % o 3
b,p t % x c c , 2 f
mov % i 4 , % o 4
/* Linux 32-bit system calls enter here... */
.align 32
.globl linux_sparc_syscall32
linux_sparc_syscall32 :
/* Direct access to user regs, much faster. */
cmp % g 1 , N R _ S Y S C A L L S ! I E U 1 G r o u p
bgeu,p n % x c c , l i n u x _ s p a r c _ n i _ s y s c a l l ! C T I
srl % i 0 , 0 , % o 0 ! I E U 0
sll % g 1 , 2 , % l 4 ! I E U 0 G r o u p
srl % i 4 , 0 , % o 4 ! I E U 1
lduw [ % l 7 + % l 4 ] , % l 7 ! L o a d
srl % i 1 , 0 , % o 1 ! I E U 0 G r o u p
ldx [ % g 6 + T I _ F L A G S ] , % l 0 ! L o a d
srl % i 5 , 0 , % o 5 ! I E U 1
srl % i 2 , 0 , % o 2 ! I E U 0 G r o u p
andcc % l 0 , ( _ T I F _ S Y S C A L L _ T R A C E | _ T I F _ S E C C O M P | _ T I F _ S Y S C A L L _ A U D I T ) , % g 0
bne,p n % i c c , l i n u x _ s y s c a l l _ t r a c e 3 2 ! C T I
mov % i 0 , % l 5 ! I E U 1
call % l 7 ! C T I G r o u p b r k f o r c e d
srl % i 3 , 0 , % o 3 ! I E U 0
ba,a ,p t % x c c , 3 f
/* Linux native system calls enter here... */
.align 32
.globl linux_sparc_syscall
linux_sparc_syscall :
/* Direct access to user regs, much faster. */
cmp % g 1 , N R _ S Y S C A L L S ! I E U 1 G r o u p
bgeu,p n % x c c , l i n u x _ s p a r c _ n i _ s y s c a l l ! C T I
mov % i 0 , % o 0 ! I E U 0
sll % g 1 , 2 , % l 4 ! I E U 0 G r o u p
mov % i 1 , % o 1 ! I E U 1
lduw [ % l 7 + % l 4 ] , % l 7 ! L o a d
4 : mov % i 2 , % o 2 ! I E U 0 G r o u p
ldx [ % g 6 + T I _ F L A G S ] , % l 0 ! L o a d
mov % i 3 , % o 3 ! I E U 1
mov % i 4 , % o 4 ! I E U 0 G r o u p
andcc % l 0 , ( _ T I F _ S Y S C A L L _ T R A C E | _ T I F _ S E C C O M P | _ T I F _ S Y S C A L L _ A U D I T ) , % g 0
bne,p n % i c c , l i n u x _ s y s c a l l _ t r a c e ! C T I G r o u p
mov % i 0 , % l 5 ! I E U 0
2 : call % l 7 ! C T I G r o u p b r k f o r c e d
mov % i 5 , % o 5 ! I E U 0
nop
3 : stx % o 0 , [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 0 ]
ret_sys_call :
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ T S T A T E ] , % g 3
ldx [ % s p + P T R E G S _ O F F + P T _ V 9 _ T N P C ] , % l 1 ! p c = n p c
sra % o 0 , 0 , % o 0
mov % u l o ( T S T A T E _ X C A R R Y | T S T A T E _ I C A R R Y ) , % g 2
sllx % g 2 , 3 2 , % g 2
/ * Check i f f o r c e _ s u c c e s s f u l _ s y s c a l l _ r e t u r n ( )
* was i n v o k e d .
* /
ldub [ % g 6 + T I _ S Y S _ N O E R R O R ] , % l 2
brnz,a ,p n % l 2 , 8 0 f
stb % g 0 , [ % g 6 + T I _ S Y S _ N O E R R O R ]
cmp % o 0 , - E R E S T A R T _ R E S T A R T B L O C K
bgeu,p n % x c c , 1 f
andcc % l 0 , ( _ T I F _ S Y S C A L L _ T R A C E | _ T I F _ S E C C O M P | _ T I F _ S Y S C A L L _ A U D I T ) , % l 6
80 :
/* System call success, clear Carry condition code. */
andn % g 3 , % g 2 , % g 3
stx % g 3 , [ % s p + P T R E G S _ O F F + P T _ V 9 _ T S T A T E ]
bne,p n % i c c , l i n u x _ s y s c a l l _ t r a c e 2
add % l 1 , 0 x4 , % l 2 ! n p c = n p c + 4
stx % l 1 , [ % s p + P T R E G S _ O F F + P T _ V 9 _ T P C ]
ba,p t % x c c , r t r a p
stx % l 2 , [ % s p + P T R E G S _ O F F + P T _ V 9 _ T N P C ]
1 :
/ * System c a l l f a i l u r e , s e t C a r r y c o n d i t i o n c o d e .
* Also, g e t a b s ( e r r n o ) t o r e t u r n t o t h e p r o c e s s .
* /
andcc % l 0 , ( _ T I F _ S Y S C A L L _ T R A C E | _ T I F _ S E C C O M P | _ T I F _ S Y S C A L L _ A U D I T ) , % l 6
sub % g 0 , % o 0 , % o 0
or % g 3 , % g 2 , % g 3
stx % o 0 , [ % s p + P T R E G S _ O F F + P T _ V 9 _ I 0 ]
stx % g 3 , [ % s p + P T R E G S _ O F F + P T _ V 9 _ T S T A T E ]
bne,p n % i c c , l i n u x _ s y s c a l l _ t r a c e 2
add % l 1 , 0 x4 , % l 2 ! n p c = n p c + 4
stx % l 1 , [ % s p + P T R E G S _ O F F + P T _ V 9 _ T P C ]
b,p t % x c c , r t r a p
stx % l 2 , [ % s p + P T R E G S _ O F F + P T _ V 9 _ T N P C ]
linux_syscall_trace2 :
2008-08-25 07:10:23 +04:00
call s y s c a l l _ t r a c e _ l e a v e
add % s p , P T R E G S _ O F F , % o 0
2008-04-28 11:47:20 +04:00
stx % l 1 , [ % s p + P T R E G S _ O F F + P T _ V 9 _ T P C ]
ba,p t % x c c , r t r a p
stx % l 2 , [ % s p + P T R E G S _ O F F + P T _ V 9 _ T N P C ]