2012-04-16 07:06:27 +04:00
# include < a s m / p t r a c e . h >
# include " b p f _ j i t . h "
# ifdef C O N F I G _ S P A R C 6 4
# define S A V E _ S Z 1 7 6
# define S C R A T C H _ O F F S T A C K _ B I A S + 1 2 8
# define B E _ P T R ( l a b e l ) b e ,p n % x c c , l a b e l
# else
# define S A V E _ S Z 9 6
# define S C R A T C H _ O F F 7 2
# define B E _ P T R ( l a b e l ) b e l a b e l
# endif
# define S K F _ M A X _ N E G _ O F F ( - 0 x20 0 0 0 0 ) / * S K F _ L L _ O F F f r o m f i l t e r . h * /
.text
.globl bpf_jit_load_word
bpf_jit_load_word :
cmp r _ O F F , 0
bl b p f _ s l o w _ p a t h _ w o r d _ n e g
nop
.globl bpf_jit_load_word_positive_offset
bpf_jit_load_word_positive_offset :
sub r _ H E A D L E N , r _ O F F , r _ T M P
cmp r _ T M P , 3
ble b p f _ s l o w _ p a t h _ w o r d
add r _ S K B _ D A T A , r _ O F F , r _ T M P
andcc r _ T M P , 3 , % g 0
bne l o a d _ w o r d _ u n a l i g n e d
nop
retl
2012-04-18 00:08:29 +04:00
ld [ r _ T M P ] , r _ A
2012-04-16 07:06:27 +04:00
load_word_unaligned :
ldub [ r _ T M P + 0 x0 ] , r _ O F F
ldub [ r _ T M P + 0 x1 ] , r _ T M P 2
sll r _ O F F , 8 , r _ O F F
or r _ O F F , r _ T M P 2 , r _ O F F
ldub [ r _ T M P + 0 x2 ] , r _ T M P 2
sll r _ O F F , 8 , r _ O F F
or r _ O F F , r _ T M P 2 , r _ O F F
ldub [ r _ T M P + 0 x3 ] , r _ T M P 2
sll r _ O F F , 8 , r _ O F F
retl
or r _ O F F , r _ T M P 2 , r _ A
.globl bpf_jit_load_half
bpf_jit_load_half :
cmp r _ O F F , 0
bl b p f _ s l o w _ p a t h _ h a l f _ n e g
nop
.globl bpf_jit_load_half_positive_offset
bpf_jit_load_half_positive_offset :
sub r _ H E A D L E N , r _ O F F , r _ T M P
cmp r _ T M P , 1
ble b p f _ s l o w _ p a t h _ h a l f
add r _ S K B _ D A T A , r _ O F F , r _ T M P
andcc r _ T M P , 1 , % g 0
bne l o a d _ h a l f _ u n a l i g n e d
nop
retl
2012-04-18 00:08:29 +04:00
lduh [ r _ T M P ] , r _ A
2012-04-16 07:06:27 +04:00
load_half_unaligned :
ldub [ r _ T M P + 0 x0 ] , r _ O F F
ldub [ r _ T M P + 0 x1 ] , r _ T M P 2
sll r _ O F F , 8 , r _ O F F
retl
or r _ O F F , r _ T M P 2 , r _ A
.globl bpf_jit_load_byte
bpf_jit_load_byte :
cmp r _ O F F , 0
bl b p f _ s l o w _ p a t h _ b y t e _ n e g
nop
.globl bpf_jit_load_byte_positive_offset
bpf_jit_load_byte_positive_offset :
cmp r _ O F F , r _ H E A D L E N
bge b p f _ s l o w _ p a t h _ b y t e
nop
retl
ldub [ r _ S K B _ D A T A + r _ O F F ] , r _ A
.globl bpf_jit_load_byte_msh
bpf_jit_load_byte_msh :
cmp r _ O F F , 0
bl b p f _ s l o w _ p a t h _ b y t e _ m s h _ n e g
nop
.globl bpf_jit_load_byte_msh_positive_offset
bpf_jit_load_byte_msh_positive_offset :
cmp r _ O F F , r _ H E A D L E N
bge b p f _ s l o w _ p a t h _ b y t e _ m s h
nop
ldub [ r _ S K B _ D A T A + r _ O F F ] , r _ O F F
and r _ O F F , 0 x f , r _ O F F
retl
sll r _ O F F , 2 , r _ X
# define b p f _ s l o w _ p a t h _ c o m m o n ( L E N ) \
save % s p , - S A V E _ S Z , % s p ; \
mov % i 0 , % o 0 ; \
mov r _ O F F , % o 1 ; \
add % f p , S C R A T C H _ O F F , % o 2 ; \
call s k b _ c o p y _ b i t s ; \
mov ( L E N ) , % o 3 ; \
cmp % o 0 , 0 ; \
restore;
bpf_slow_path_word :
bpf_ s l o w _ p a t h _ c o m m o n ( 4 )
bl b p f _ e r r o r
ld [ % s p + S C R A T C H _ O F F ] , r _ A
retl
nop
bpf_slow_path_half :
bpf_ s l o w _ p a t h _ c o m m o n ( 2 )
bl b p f _ e r r o r
lduh [ % s p + S C R A T C H _ O F F ] , r _ A
retl
nop
bpf_slow_path_byte :
bpf_ s l o w _ p a t h _ c o m m o n ( 1 )
bl b p f _ e r r o r
ldub [ % s p + S C R A T C H _ O F F ] , r _ A
retl
nop
bpf_slow_path_byte_msh :
bpf_ s l o w _ p a t h _ c o m m o n ( 1 )
bl b p f _ e r r o r
ldub [ % s p + S C R A T C H _ O F F ] , r _ A
and r _ O F F , 0 x f , r _ O F F
retl
sll r _ O F F , 2 , r _ X
# define b p f _ n e g a t i v e _ c o m m o n ( L E N ) \
save % s p , - S A V E _ S Z , % s p ; \
mov % i 0 , % o 0 ; \
mov r _ O F F , % o 1 ; \
call b p f _ i n t e r n a l _ l o a d _ p o i n t e r _ n e g _ h e l p e r ; \
mov ( L E N ) , % o 2 ; \
mov % o 0 , r _ T M P ; \
cmp % o 0 , 0 ; \
BE_ P T R ( b p f _ e r r o r ) ; \
restore;
bpf_slow_path_word_neg :
sethi % h i ( S K F _ M A X _ N E G _ O F F ) , r _ T M P
cmp r _ O F F , r _ T M P
bl b p f _ e r r o r
nop
.globl bpf_jit_load_word_negative_offset
bpf_jit_load_word_negative_offset :
bpf_ n e g a t i v e _ c o m m o n ( 4 )
andcc r _ T M P , 3 , % g 0
bne l o a d _ w o r d _ u n a l i g n e d
nop
retl
ld [ r _ T M P ] , r _ A
bpf_slow_path_half_neg :
sethi % h i ( S K F _ M A X _ N E G _ O F F ) , r _ T M P
cmp r _ O F F , r _ T M P
bl b p f _ e r r o r
nop
.globl bpf_jit_load_half_negative_offset
bpf_jit_load_half_negative_offset :
bpf_ n e g a t i v e _ c o m m o n ( 2 )
andcc r _ T M P , 1 , % g 0
bne l o a d _ h a l f _ u n a l i g n e d
nop
retl
lduh [ r _ T M P ] , r _ A
bpf_slow_path_byte_neg :
sethi % h i ( S K F _ M A X _ N E G _ O F F ) , r _ T M P
cmp r _ O F F , r _ T M P
bl b p f _ e r r o r
nop
.globl bpf_jit_load_byte_negative_offset
bpf_jit_load_byte_negative_offset :
bpf_ n e g a t i v e _ c o m m o n ( 1 )
retl
ldub [ r _ T M P ] , r _ A
bpf_slow_path_byte_msh_neg :
sethi % h i ( S K F _ M A X _ N E G _ O F F ) , r _ T M P
cmp r _ O F F , r _ T M P
bl b p f _ e r r o r
nop
.globl bpf_jit_load_byte_msh_negative_offset
bpf_jit_load_byte_msh_negative_offset :
bpf_ n e g a t i v e _ c o m m o n ( 1 )
ldub [ r _ T M P ] , r _ O F F
and r _ O F F , 0 x f , r _ O F F
retl
sll r _ O F F , 2 , r _ X
bpf_error :
2012-04-18 00:38:16 +04:00
/ * Make t h e J I T p r o g r a m r e t u r n z e r o . T h e J I T e p i l o g u e
* stores a w a y t h e o r i g i n a l % o 7 i n t o r _ s a v e d _ O 7 . T h e
* normal l e a f f u n c t i o n r e t u r n i s t o u s e " r e t l " w h i c h
* would e v a l u t e t o " j m p l % o 7 + 8 , % g 0 " b u t w e w a n t t o
* use t h e s a v e d v a l u e t h u s t h e s e q u e n c e y o u s e e h e r e .
* /
2012-04-16 07:06:27 +04:00
jmpl r _ s a v e d _ O 7 + 8 , % g 0
clr % o 0