@ -1,15 +1,88 @@
# define A R G U M E N T _ S P I L L _ S I Z E ( 8 * 1 0 + 8 * 1 6 )
.macro MSGSEND receiver, s e l
.cfi_startproc
cbz \ r e c e i v e r , 4 f / / S k i p e v e r y t h i n g i f t h e r e c e i v e r i s n i l
/ * Windows A R M 6 4 E x c e p t i o n H a n d l i n g
*
* Structured E x c e p t i o n H a n d l i n g ( S E H ) o n W i n d o w s A R M 6 4 d i f f e r s f r o m t h e x64
* implementation. F u n c t i o n s c o n s i s t o f a s i n g l e p r o l o g u e a n d z e r o o r m o r e
* epilogues. I n s t e a d o f u s i n g o f f s e t s f o r t h e . s e h * d i r e c t i v e s t o m a n i p u l a t e t h e
* stack f r a m e , e a c h d i r e c t i v e c o r r e s p o n d s t o a s i n g l e i n s t r u c t i o n .
*
* This p r e s e n t s a c h a l l e n g e f o r o u r o b j c _ m s g S e n d f u n c t i o n , w h i c h o n l y m o d i f i e s
* the s t a c k w h e n a s l o w l o o k u p i s n e e d e d ( s e e l a b e l " 5 " ) .
*
* To a d d r e s s t h i s , w e m o v e t h e d i r e c t i v e m a r k i n g t h e s t a r t o f a f u n c t i o n d e e p
* into t h e m s g S e n d b o d y t o p r e v e n t m a r k i n g e v e r y i n s t r u c t i o n a s " . s e h _ n o p . "
*
* For W i n d o w s :
* - EH_ S T A R T ( x ) : S t a r t o f f u n c t i o n ( n o e f f e c t o n W i n d o w s )
* - EH_ E N D ( x ) : E n d o f f u n c t i o n ( n o e f f e c t o n W i n d o w s )
* - EH_ S T A R T _ A T _ O F F S E T ( x ) : M a r k S t a r t o f f u n c t i o n ( D e l a y e d )
* - EH_ E N D _ A T _ O F F S E T ( x ) : M a r k E n d o f f u n c t i o n ( D e l a y e d )
* - EH_END_PROLOGUE : End o f f u n c t i o n p r o l o g u e
* - EH_START_EPILOGUE : Start o f f u n c t i o n e p i l o g u e
* - EH_END_EPILOGUE : End o f f u n c t i o n e p i l o g u e
* - EH_ S A V E _ F P _ L R ( x ) : S a v e F r a m e P o i n t e r a n d L i n k R e g i s t e r
* - EH_ S T A C K _ A L L O C ( x ) : S t a c k a l l o c a t i o n ( i n s i d e p r o l o g u e )
* - EH_ A D D _ F P ( x ) : A d d t o F r a m e P o i n t e r
* - EH_NOP : Mark i n s t r u c t i o n w i t h n o u n w i n d i n g r e l e v a n c e
*
* For n o n - 6 4 - b i t W i n d o w s s y s t e m s o r o t h e r p l a t f o r m s , t h e s e m a c r o s h a v e n o e f f e c t a n d c a n b e u s e d w i t h o u t c a u s i n g i s s u e s .
* /
# ifdef _ W I N 3 2
# define E H _ S T A R T
# define E H _ E N D
# define E H _ S T A R T _ A T _ O F F S E T . s e h _ p r o c o b j c _ m s g S e n d
# define E H _ E N D _ A T _ O F F S E T . s e h _ e n d p r o c o b j c _ m s g S e n d
# define E H _ E N D _ P R O L O G U E . s e h _ e n d p r o l o g u e
# define E H _ S T A R T _ E P I L O G U E . s e h _ s t a r t e p i l o g u e
# define E H _ E N D _ E P I L O G U E . s e h _ e n d e p i l o g u e
# define E H _ S A V E _ F P _ L R ( x ) . s e h _ s a v e _ f p l r x
# define E H _ S T A C K _ A L L O C ( x ) . s e h _ s t a c k a l l o c x
# define E H _ A D D _ F P ( x ) . s e h _ a d d _ f p x
# define E H _ N O P . s e h _ n o p
# else
/ / Marks t h e r e a l s t a r t a n d e n d o f t h e f u n c t i o n
# define E H _ S T A R T . c f i _ s t a r t p r o c
# define E H _ E N D . c f i _ e n d p r o c
/ / The f o l l o w i n g d i r e c t i v e s a r e e i t h e r n o t
/ / needed o r n o t a v a i l a b l e w i t h C F I
# define E H _ S T A R T _ A T _ O F F S E T
# define E H _ E N D _ A T _ O F F S E T
# define E H _ E N D _ P R O L O G U E
# define E H _ S T A R T _ E P I L O G U E
# define E H _ E N D _ E P I L O G U E
# define E H _ S A V E _ F P _ L R ( x )
# define E H _ S T A C K _ A L L O C ( x )
# define E H _ A D D _ F P ( x )
# define E H _ N O P
# endif
.globl CDECL( o b j c _ m s g S e n d _ f p r e t )
TYPE_ D I R E C T I V E ( C D E C L ( o b j c _ m s g S e n d _ f p r e t ) , % f u n c t i o n )
.globl CDECL( o b j c _ m s g S e n d )
TYPE_ D I R E C T I V E ( C D E C L ( o b j c _ m s g S e n d ) , % f u n c t i o n )
.globl CDECL( o b j c _ m s g S e n d _ s t r e t )
TYPE_ D I R E C T I V E ( C D E C L ( o b j c _ m s g S e n d _ s t r e t ) , % f u n c t i o n )
CDECL( o b j c _ m s g S e n d ) :
CDECL( o b j c _ m s g S e n d _ f p r e t ) :
CDECL( o b j c _ m s g S e n d _ s t r e t ) :
EH_ S T A R T
cbz x0 , 4 f / / S k i p e v e r y t h i n g i f t h e r e c e i v e r i s n i l
/ / Jump t o 6 : i f t h i s i s a s m a l l o b j e c t
ubfx x9 , \ r e c e i v e r , #0 , #S M A L L O B J _ B I T S
ubfx x9 , x0 , #0 , #S M A L L O B J _ B I T S
cbnz x9 , 6 f
ldr x9 , [ \ r e c e i v e r ] / / L o a d c l a s s t o x9 i f n o t a s m a l l i n t
ldr x9 , [ x0 ] / / L o a d c l a s s t o x9 i f n o t a s m a l l i n t
1 :
ldr x9 , [ x9 , #D T A B L E _ O F F S E T ] / / D t a b l e - > x 9
ldr w10 , [ \ s e l ] / / s e l e c t o r - > i n d e x - > x10
ldr w10 , [ x1 ] / / s e l e c t o r - > i n d e x - > x10
ldr w11 , [ x9 , #S H I F T _ O F F S E T ] / / d t a b l e - > s h i f t - > x 11
cmp x11 , #8 / / I f t h i s i s a s m a l l d t a b l e , j u m p t o t h e
@ -41,59 +114,114 @@
mov v0 . d [ 1 ] , x0
br l r
5 : / / Slow l o o k u p
EH_ S T A R T _ A T _ O F F S E T
/ / Save a n y t h i n g t h a t w i l l b e c l o b b e r e d b y
/ / the c a l l
/ / the c a l l .
/ / Note t h a t w e p r e - i n d e x ( s e e " ! " ) , m e a n i n g
/ / that w e a d j u s t t h e s p b e f o r e s t o r i n g t h e p a i r
/ / of r e g i s t e r s .
stp x0 , x1 , [ s p , #- ( A R G U M E N T _ S P I L L _ S I Z E ) ] !
stp x2 , x3 , [ s p , #16 ] / / T h e o r d e r i s a r b i t r a r y , e x c e p t t h a t
stp x4 , x5 , [ s p , #32 ] / / f p a n d l r m u s t b e s p i l l e d t o g e t h e r a n d
stp x6 , x7 , [ s p , #48 ] / / i t ' s c o n v e n i e n t i f \ r e c e i v e r i s s p i l l e d a t s p
EH_ S T A C K _ A L L O C ( ( A R G U M E N T _ S P I L L _ S I Z E ) )
stp x2 , x3 , [ s p , #16 ]
EH_ N O P / / T h e f o l l o w i n g i n s t r u c t i o n s c a n b e i g n o r e d b y S E H
stp x4 , x5 , [ s p , #32 ]
EH_ N O P
stp x6 , x7 , [ s p , #48 ]
EH_ N O P
stp q0 , q1 , [ s p , #64 ]
EH_ N O P
stp q2 , q3 , [ s p , #96 ]
EH_ N O P
stp q4 , q5 , [ s p , #128 ]
EH_ N O P
stp q6 , q7 , [ s p , #160 ]
stp f p , l r , [ s p , #192 ]
add f p , s p , 1 9 2
stp \ r e c e i v e r , x8 , [ s p , #- 16 ] !
EH_ N O P
stp f p , l r , [ s p , #192 ] / / T h e o r d e r i s a r b i t r a r y , e x c e p t t h a t
EH_ S A V E _ F P _ L R ( 1 9 2 ) / / f p a n d l r m u s t b e s p i l l e d t o g e t h e r
add f p , s p , 1 9 2 / / A d j u s t f r a m e p o i n t e r
EH_ A D D _ F P ( 1 9 2 )
stp x0 , x8 , [ s p , #- 16 ] ! / / i t ' s c o n v e n i e n t i f x0 i s s p i l l e d a t s p
EH_ S T A C K _ A L L O C ( 1 6 ) / / s t p p e r f o r m e d p r e - i n d e x i n g b y s p - 1 6
EH_ E N D _ P R O L O G U E
# ifndef _ W I N 3 2
.cfi_def_cfa fp, 1 6
.cfi_offset fp, - 1 6
.cfi_offset lr, - 8
# endif
/ / We n o w h a v e a l l a r g u m e n t r e g i s t e r s , t h e l i n k
/ / register a n d t h e r e c e i v e r s p i l l e d o n t h e
/ / stack, w i t h s p c o n t a i n i n g
/ / the a d d r e s s o f t h e r e c e i v e r
mov x0 , s p / / & s e l f , _ c m d i n a r g u m e n t s
mov x1 , \ s e l
bl C D E C L ( s l o w M s g L o o k u p ) / / T h i s i s t h e o n l y p l a c e w h e r e t h e CF I d i r e c t i v e s
mov x1 , x1
bl C D E C L ( s l o w M s g L o o k u p ) / / T h i s i s t h e o n l y p l a c e w h e r e t h e EH d i r e c t i v e s
/ / have t o b e a c c u r a t e . . .
mov x9 , x0 / / I M P - > x9
EH_ S T A R T _ E P I L O G U E
ldp x0 , x1 , [ s p , #16 ] / / R e l o a d s p i l l e d a r g u m e n t r e g i s t e r s
EH_ N O P
ldp x2 , x3 , [ s p , #32 ]
EH_ N O P
ldp x4 , x5 , [ s p , #64 ]
EH_ N O P
ldp x6 , x7 , [ s p , #64 ]
EH_ N O P
ldp q0 , q1 , [ s p , #80 ]
EH_ N O P
ldp q2 , q3 , [ s p , #112 ]
EH_ N O P
ldp q4 , q5 , [ s p , #144 ]
EH_ N O P
ldp q6 , q7 , [ s p , #176 ]
EH_ N O P
ldp f p , l r , [ s p , #208 ]
ldp \ r e c e i v e r , x8 , [ s p ] , #( A R G U M E N T _ S P I L L _ S I Z E + 16 )
EH_ S A V E _ F P _ L R ( 2 0 8 )
/ / Post- i n c r e m e n t s p + = A R G U M E N T _ S P I L L _ S I Z E + 1 6
ldp x0 , x8 , [ s p ] , #( A R G U M E N T _ S P I L L _ S I Z E + 16 )
EH_ S T A C K _ A L L O C ( ( A R G U M E N T _ S P I L L _ S I Z E + 1 6 ) )
EH_ E N D _ E P I L O G U E
EH_ E N D _ A T _ O F F S E T
br x9
6 :
adrp x10 , : g o t : S m a l l O b j e c t C l a s s e s
ldr x10 , [ x10 , : g o t _ l o 1 2 : S m a l l O b j e c t C l a s s e s ]
/ / Load 6 3 : 1 2 o f S m a l l O b j e c t C l a s s e s a d d r e s s
/ / We u s e t h e C D E C L m a c r o a s W i n d o w s p r e f i x e s
/ / cdecl c o n f o r m i n g s y m b o l s w i t h " _ " .
adrp x10 , C D E C L ( S m a l l O b j e c t C l a s s e s ) / / T h e m a c r o h a n d l e s t h i s t r a n s p a r e n t l y .
/ / Add l o w e r 1 2 - b i t s o f S m a l l O b j e c t C l a s s e s a d d r e s s t o x10
add x10 , x10 , : l o 1 2 : C D E C L ( S m a l l O b j e c t C l a s s e s )
ldr x9 , [ x10 , x9 , l s l #3 ]
b 1 b
.cfi_endproc
.endm
EH_ E N D
.globl CDECL( o b j c _ m s g S e n d _ f p r e t )
TYPE_ D I R E C T I V E ( C D E C L ( o b j c _ m s g S e n d _ f p r e t ) , % f u n c t i o n )
.globl CDECL( o b j c _ m s g S e n d )
TYPE_ D I R E C T I V E ( C D E C L ( o b j c _ m s g S e n d ) , % f u n c t i o n )
.globl CDECL( o b j c _ m s g S e n d _ s t r e t )
TYPE_ D I R E C T I V E ( C D E C L ( o b j c _ m s g S e n d _ s t r e t ) , % f u n c t i o n )
CDECL( o b j c _ m s g S e n d ) :
CDECL( o b j c _ m s g S e n d _ f p r e t ) :
CDECL( o b j c _ m s g S e n d _ s t r e t ) :
MSGSEND x0 , x1
# ifdef _ W I N 3 2
.text
.def objc_ m s g S e n d ;
.scl 2 ;
.type 3 2 ;
.endef
.def objc_ m s g S e n d _ f p r e t ;
.scl 2 ;
.type 3 2 ;
.endef
.def objc_ m s g S e n d _ s t r e t ;
.scl 2 ;
.type 3 2 ;
.endef
.section .drectve , " yn"
.ascii " / EXPORT : objc_ m s g S e n d "
.ascii " / EXPORT : objc_ m s g S e n d _ f p r e t "
.ascii " / EXPORT : objc_ m s g S e n d _ s t r e t "
# endif