2 * Copyright (c) 1999-2007 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <TargetConditionals.h>
25 #if defined(__i386__) && !TARGET_IPHONE_SIMULATOR
27 /********************************************************************
28 ********************************************************************
30 ** objc-msg-i386.s - i386 code to support objc messaging.
32 ********************************************************************
33 ********************************************************************/
36 #include "objc-config.h"
39 /********************************************************************
40 * Data used by the ObjC runtime.
42 ********************************************************************/
45 // Substitute receiver for messages sent to nil (usually also nil)
46 // id _objc_nilReceiver
48 .private_extern __objc_nilReceiver
52 // _objc_entryPoints and _objc_exitPoints are used by objc
53 // to get the critical regions for which method caches
54 // cannot be garbage collected.
56 .private_extern _objc_entryPoints
59 .long __cache_getMethod
61 .long _objc_msgSend_fpret
62 .long _objc_msgSend_stret
63 .long _objc_msgSendSuper
64 .long _objc_msgSendSuper_stret
67 .private_extern _objc_exitPoints
72 .long LMsgSendFpretExit
73 .long LMsgSendStretExit
74 .long LMsgSendSuperExit
75 .long LMsgSendSuperStretExit
79 /********************************************************************
80 * List every exit insn from every messenger for debugger use.
83 * 1 word instruction's address
84 * 1 word type (ENTER or FAST_EXIT or SLOW_EXIT or NIL_EXIT)
88 * ENTER is the start of a dispatcher
89 * FAST_EXIT is method dispatch
90 * SLOW_EXIT is uncached method lookup
91 * NIL_EXIT is returning zero from a message sent to nil
92 * These must match objc-gdb.h.
93 ********************************************************************/
100 .section __DATA,__objc_msg_break
101 .globl _gdb_objc_messenger_breakpoints
102 _gdb_objc_messenger_breakpoints:
103 // contents populated by the macros below
105 .macro MESSENGER_START
107 .section __DATA,__objc_msg_break
112 .macro MESSENGER_END_FAST
114 .section __DATA,__objc_msg_break
119 .macro MESSENGER_END_SLOW
121 .section __DATA,__objc_msg_break
126 .macro MESSENGER_END_NIL
128 .section __DATA,__objc_msg_break
135 /********************************************************************
139 ********************************************************************/
157 /********************************************************************
159 * Structure definitions.
161 ********************************************************************/
163 // objc_super parameter to sendSuper
167 // Selected field offsets in class structure
178 buckets = 8 // variable length array
180 #if defined(OBJC_INSTRUMENTED)
181 // Cache instrumentation data, follows buckets
183 hitProbes = hitCount + 4
184 maxHitProbes = hitProbes + 4
185 missCount = maxHitProbes + 4
186 missProbes = missCount + 4
187 maxMissProbes = missProbes + 4
188 flushCount = maxMissProbes + 4
189 flushedEntries = flushCount + 4
191 // Buckets in CacheHitHistogram and CacheMissHistogram
192 CACHE_HISTOGRAM_SIZE = 512
196 //////////////////////////////////////////////////////////////////////
198 // LOAD_STATIC_WORD targetReg, symbolName, LOCAL_SYMBOL | EXTERNAL_SYMBOL
200 // Load the value of the named static data word.
202 // Takes: targetReg - the register, other than r0, to load
203 // symbolName - the name of the symbol
204 // LOCAL_SYMBOL - symbol name used as-is
205 // EXTERNAL_SYMBOL - symbol name gets nonlazy treatment
207 // Eats: edx and targetReg
208 //////////////////////////////////////////////////////////////////////
210 // Values to specify whether the symbol is plain or nonlazy
214 .macro LOAD_STATIC_WORD
216 #if defined(__DYNAMIC__)
219 .if $2 == EXTERNAL_SYMBOL
222 .elseif $2 == LOCAL_SYMBOL
225 !!! Unknown symbol type !!!
233 //////////////////////////////////////////////////////////////////////
235 // LEA_STATIC_DATA targetReg, symbolName, LOCAL_SYMBOL | EXTERNAL_SYMBOL
237 // Load the address of the named static data.
239 // Takes: targetReg - the register, other than edx, to load
240 // symbolName - the name of the symbol
241 // LOCAL_SYMBOL - symbol is local to this module
242 // EXTERNAL_SYMBOL - symbol is imported from another module
244 // Eats: edx and targetReg
245 //////////////////////////////////////////////////////////////////////
247 .macro LEA_STATIC_DATA
248 #if defined(__DYNAMIC__)
251 .if $2 == EXTERNAL_SYMBOL
253 .elseif $2 == LOCAL_SYMBOL
256 !!! Unknown symbol type !!!
264 //////////////////////////////////////////////////////////////////////
266 // ENTRY functionName
268 // Assembly directives to begin an exported function.
270 // Takes: functionName - name of the exported function
271 //////////////////////////////////////////////////////////////////////
287 //////////////////////////////////////////////////////////////////////
289 // END_ENTRY functionName
291 // Assembly directives to end an exported function. Just a placeholder,
292 // a close-parenthesis for ENTRY, until it is needed for something.
294 // Takes: functionName - name of the exported function
295 //////////////////////////////////////////////////////////////////////
300 //////////////////////////////////////////////////////////////////////
304 // Calls mcount() profiling routine. Must be called immediately on
305 // function entry, before any prologue executes.
307 //////////////////////////////////////////////////////////////////////
311 // Current stack contents: ret
315 // Current stack contents: ret, ebp, pad, pad
323 /////////////////////////////////////////////////////////////////////
326 // CacheLookup WORD_RETURN | STRUCT_RETURN, MSG_SEND | MSG_SENDSUPER | CACHE_GET, cacheMissLabel
328 // Locate the implementation for a selector in a class method cache.
330 // Takes: WORD_RETURN (first parameter is at sp+4)
331 // STRUCT_RETURN (struct address is at sp+4, first parameter at sp+8)
332 // MSG_SEND (first parameter is receiver)
333 // MSG_SENDSUPER (first parameter is address of objc_super structure)
334 // CACHE_GET (first parameter is class; return method triplet)
336 // class to search in %edx
338 // cacheMissLabel = label to branch to iff method is not cached
340 // On exit: (found) MSG_SEND and MSG_SENDSUPER: return imp in eax
341 // (found) CACHE_GET: return method triplet in eax
342 // (not found) jumps to cacheMissLabel
344 /////////////////////////////////////////////////////////////////////
347 // Values to specify to method lookup macros whether the return type of
348 // the method is word or structure.
352 // Values to specify to method lookup macros whether the first argument
353 // is an object/class reference or a 'objc_super' structure.
354 MSG_SEND = 0 // first argument is receiver, search the isa
355 MSG_SENDSUPER = 1 // first argument is objc_super, search the class
356 CACHE_GET = 2 // first argument is class, search that class
360 // load variables and save caller registers.
362 pushl %edi // save scratch register
363 movl cache(%edx), %edi // cache = class->cache
364 pushl %esi // save scratch register
366 #if defined(OBJC_INSTRUMENTED)
367 pushl %ebx // save non-volatile register
368 pushl %eax // save cache pointer
369 xorl %ebx, %ebx // probeCount = 0
371 movl mask(%edi), %esi // mask = cache->mask
372 movl %ecx, %edx // index = selector
373 shrl $$2, %edx // index = selector >> 2
375 // search the receiver's cache
380 // eax = method (soon)
381 LMsgSendProbeCache_$0_$1_$2:
382 #if defined(OBJC_INSTRUMENTED)
383 addl $$1, %ebx // probeCount += 1
385 andl %esi, %edx // index &= mask
386 movl buckets(%edi, %edx, 4), %eax // meth = cache->buckets[index]
388 testl %eax, %eax // check for end of bucket
389 je LMsgSendCacheMiss_$0_$1_$2 // go to cache miss code
390 cmpl method_name(%eax), %ecx // check for method name match
391 je LMsgSendCacheHit_$0_$1_$2 // go handle cache hit
392 addl $$1, %edx // bump index ...
393 jmp LMsgSendProbeCache_$0_$1_$2 // ... and loop
395 // not found in cache: restore state and go to callers handler
396 LMsgSendCacheMiss_$0_$1_$2:
397 #if defined(OBJC_INSTRUMENTED)
398 popl %edx // retrieve cache pointer
399 movl mask(%edx), %esi // mask = cache->mask
400 testl %esi, %esi // a mask of zero is only for the...
401 je LMsgSendMissInstrumentDone_$0_$1_$2 // ... emptyCache, do not record anything
403 // locate and update the CacheInstrumentation structure
404 addl $$1, %esi // entryCount = mask + 1
405 shll $$2, %esi // tableSize = entryCount * sizeof(entry)
406 addl $buckets, %esi // offset = buckets + tableSize
407 addl %edx, %esi // cacheData = &cache->buckets[mask+1]
409 movl missCount(%esi), %edi //
411 movl %edi, missCount(%esi) // cacheData->missCount += 1
412 movl missProbes(%esi), %edi //
414 movl %edi, missProbes(%esi) // cacheData->missProbes += probeCount
415 movl maxMissProbes(%esi), %edi// if (cacheData->maxMissProbes < probeCount)
417 jge LMsgSendMaxMissProbeOK_$0_$1_$2 //
418 movl %ebx, maxMissProbes(%esi)// cacheData->maxMissProbes = probeCount
419 LMsgSendMaxMissProbeOK_$0_$1_$2:
421 // update cache miss probe histogram
422 cmpl $CACHE_HISTOGRAM_SIZE, %ebx // pin probeCount to max index
423 jl LMsgSendMissHistoIndexSet_$0_$1_$2
424 movl $(CACHE_HISTOGRAM_SIZE-1), %ebx
425 LMsgSendMissHistoIndexSet_$0_$1_$2:
426 LEA_STATIC_DATA %esi, _CacheMissHistogram, EXTERNAL_SYMBOL
427 shll $$2, %ebx // convert probeCount to histogram index
428 addl %ebx, %esi // calculate &CacheMissHistogram[probeCount<<2]
429 movl 0(%esi), %edi // get current tally
431 movl %edi, 0(%esi) // tally += 1
432 LMsgSendMissInstrumentDone_$0_$1_$2:
433 popl %ebx // restore non-volatile register
436 .if $0 == WORD_RETURN // Regular word return
437 .if $1 == MSG_SEND // MSG_SEND
438 popl %esi // restore callers register
439 popl %edi // restore callers register
440 movl self(%esp), %edx // get messaged object
441 movl isa(%edx), %eax // get objects class
442 .elseif $1 == MSG_SENDSUPER // MSG_SENDSUPER
443 // replace "super" arg with "receiver"
444 movl super+8(%esp), %edi // get super structure
445 movl receiver(%edi), %edx // get messaged object
446 movl %edx, super+8(%esp) // make it the first argument
447 movl class(%edi), %eax // get messaged class
448 popl %esi // restore callers register
449 popl %edi // restore callers register
451 popl %esi // restore callers register
452 popl %edi // restore callers register
454 .else // Struct return
455 .if $1 == MSG_SEND // MSG_SEND (stret)
456 popl %esi // restore callers register
457 popl %edi // restore callers register
458 movl self_stret(%esp), %edx // get messaged object
459 movl isa(%edx), %eax // get objects class
460 .elseif $1 == MSG_SENDSUPER // MSG_SENDSUPER (stret)
461 // replace "super" arg with "receiver"
462 movl super_stret+8(%esp), %edi// get super structure
463 movl receiver(%edi), %edx // get messaged object
464 movl %edx, super_stret+8(%esp)// make it the first argument
465 movl class(%edi), %eax // get messaged class
466 popl %esi // restore callers register
467 popl %edi // restore callers register
469 !! This should not happen.
476 jmp $2 // go to callers handler
478 // eax points to matching cache entry
480 LMsgSendCacheHit_$0_$1_$2:
481 #if defined(OBJC_INSTRUMENTED)
482 popl %edx // retrieve cache pointer
483 movl mask(%edx), %esi // mask = cache->mask
484 testl %esi, %esi // a mask of zero is only for the...
485 je LMsgSendHitInstrumentDone_$0_$1_$2 // ... emptyCache, do not record anything
487 // locate and update the CacheInstrumentation structure
488 addl $$1, %esi // entryCount = mask + 1
489 shll $$2, %esi // tableSize = entryCount * sizeof(entry)
490 addl $buckets, %esi // offset = buckets + tableSize
491 addl %edx, %esi // cacheData = &cache->buckets[mask+1]
493 movl hitCount(%esi), %edi
495 movl %edi, hitCount(%esi) // cacheData->hitCount += 1
496 movl hitProbes(%esi), %edi
498 movl %edi, hitProbes(%esi) // cacheData->hitProbes += probeCount
499 movl maxHitProbes(%esi), %edi// if (cacheData->maxHitProbes < probeCount)
501 jge LMsgSendMaxHitProbeOK_$0_$1_$2
502 movl %ebx, maxHitProbes(%esi)// cacheData->maxHitProbes = probeCount
503 LMsgSendMaxHitProbeOK_$0_$1_$2:
505 // update cache hit probe histogram
506 cmpl $CACHE_HISTOGRAM_SIZE, %ebx // pin probeCount to max index
507 jl LMsgSendHitHistoIndexSet_$0_$1_$2
508 movl $(CACHE_HISTOGRAM_SIZE-1), %ebx
509 LMsgSendHitHistoIndexSet_$0_$1_$2:
510 LEA_STATIC_DATA %esi, _CacheHitHistogram, EXTERNAL_SYMBOL
511 shll $$2, %ebx // convert probeCount to histogram index
512 addl %ebx, %esi // calculate &CacheHitHistogram[probeCount<<2]
513 movl 0(%esi), %edi // get current tally
515 movl %edi, 0(%esi) // tally += 1
516 LMsgSendHitInstrumentDone_$0_$1_$2:
517 popl %ebx // restore non-volatile register
520 // load implementation address, restore state, and we're done
522 // method triplet is already in eax
524 movl method_imp(%eax), %eax // imp = method->method_imp
527 .if $0 == WORD_RETURN // Regular word return
528 .if $1 == MSG_SENDSUPER // MSG_SENDSUPER
529 // replace "super" arg with "self"
530 movl super+8(%esp), %edi
531 movl receiver(%edi), %esi
532 movl %esi, super+8(%esp)
534 .else // Struct return
535 .if $1 == MSG_SENDSUPER // MSG_SENDSUPER (stret)
536 // replace "super" arg with "self"
537 movl super_stret+8(%esp), %edi
538 movl receiver(%edi), %esi
539 movl %esi, super_stret+8(%esp)
543 // restore caller registers
549 /////////////////////////////////////////////////////////////////////
551 // MethodTableLookup WORD_RETURN | STRUCT_RETURN, MSG_SEND | MSG_SENDSUPER
553 // Takes: WORD_RETURN (first parameter is at sp+4)
554 // STRUCT_RETURN (struct address is at sp+4, first parameter at sp+8)
555 // MSG_SEND (first parameter is receiver)
556 // MSG_SENDSUPER (first parameter is address of objc_super structure)
561 // (all set by CacheLookup's miss case)
563 // Stack must be at 0xXXXXXXXc on entrance.
565 // On exit: esp unchanged
568 /////////////////////////////////////////////////////////////////////
570 .macro MethodTableLookup
572 // stack is already aligned
574 pushl %ecx // selector
575 pushl %edx // receiver
576 call __class_lookupMethodAndLoadCache3
577 addl $$12, %esp // pop parameters
581 /********************************************************************
582 * Method _cache_getMethod(Class cls, SEL sel, IMP msgForward_internal_imp)
584 * If found, returns method triplet pointer.
585 * If not found, returns NULL.
587 * NOTE: _cache_getMethod never returns any cache entry whose implementation
588 * is _objc_msgForward_impcache. It returns 1 instead. This prevents thread-
589 * safety and memory management bugs in _class_lookupMethodAndLoadCache.
590 * See _class_lookupMethodAndLoadCache for details.
592 * _objc_msgForward_impcache is passed as a parameter because it's more
593 * efficient to do the (PIC) lookup once in the caller than repeatedly here.
594 ********************************************************************/
596 STATIC_ENTRY __cache_getMethod
598 // load the class and selector
599 movl selector(%esp), %ecx
600 movl self(%esp), %edx
603 CacheLookup WORD_RETURN, CACHE_GET, LGetMethodMiss
605 // cache hit, method triplet in %eax
606 movl first_arg(%esp), %ecx // check for _objc_msgForward_impcache
607 cmpl method_imp(%eax), %ecx // if (imp==_objc_msgForward_impcache)
608 je 1f // return (Method)1
609 ret // else return method triplet address
614 // cache miss, return nil
615 xorl %eax, %eax // zero %eax
619 END_ENTRY __cache_getMethod
622 /********************************************************************
623 * IMP _cache_getImp(Class cls, SEL sel)
625 * If found, returns method implementation.
626 * If not found, returns NULL.
627 ********************************************************************/
629 STATIC_ENTRY __cache_getImp
631 // load the class and selector
632 movl selector(%esp), %ecx
633 movl self(%esp), %edx
636 CacheLookup WORD_RETURN, CACHE_GET, LGetImpMiss
638 // cache hit, method triplet in %eax
639 movl method_imp(%eax), %eax // return method imp
643 // cache miss, return nil
644 xorl %eax, %eax // zero %eax
648 END_ENTRY __cache_getImp
651 /********************************************************************
653 * id objc_msgSend(id self, SEL _cmd,...);
655 ********************************************************************/
661 // load receiver and selector
662 movl selector(%esp), %ecx
663 movl self(%esp), %eax
665 // check whether selector is ignored
667 je LMsgSendDone // return self from %eax
669 // check whether receiver is nil
673 // receiver (in %eax) is non-nil: search the cache
675 movl isa(%eax), %edx // class = self->isa
676 CacheLookup WORD_RETURN, MSG_SEND, LMsgSendCacheMiss
677 xor %edx, %edx // set nonstret for msgForward_internal
681 // cache miss: go search the method lists
683 MethodTableLookup WORD_RETURN, MSG_SEND
684 xor %edx, %edx // set nonstret for msgForward_internal
685 jmp *%eax // goto *imp
687 // message sent to nil: redirect to nil receiver, if any
689 call 1f // load new receiver
691 movl __objc_nilReceiver-1b(%edx),%eax
692 testl %eax, %eax // return nil if no new receiver
693 je LMsgSendReturnZero
694 movl %eax, self(%esp) // send to new receiver
695 jmp LMsgSendReceiverOk // receiver must be in %eax
697 // %eax is already zero
703 // guaranteed non-nil entry point (disabled for now)
704 // .globl _objc_msgSendNonNil
705 // _objc_msgSendNonNil:
706 // movl self(%esp), %eax
707 // jmp LMsgSendReceiverOk
710 END_ENTRY _objc_msgSend
712 /********************************************************************
714 * id objc_msgSendSuper(struct objc_super *super, SEL _cmd,...);
716 * struct objc_super {
720 ********************************************************************/
722 ENTRY _objc_msgSendSuper
726 // load selector and class to search
727 movl super(%esp), %eax // struct objc_super
728 movl selector(%esp), %ecx
729 movl class(%eax), %edx // struct objc_super->class
731 // check whether selector is ignored
733 je LMsgSendSuperIgnored // return self from %eax
735 // search the cache (class in %edx)
736 CacheLookup WORD_RETURN, MSG_SENDSUPER, LMsgSendSuperCacheMiss
737 xor %edx, %edx // set nonstret for msgForward_internal
739 jmp *%eax // goto *imp
741 // cache miss: go search the method lists
742 LMsgSendSuperCacheMiss:
743 MethodTableLookup WORD_RETURN, MSG_SENDSUPER
744 xor %edx, %edx // set nonstret for msgForward_internal
745 jmp *%eax // goto *imp
747 // ignored selector: return self
748 LMsgSendSuperIgnored:
749 movl super(%esp), %eax
750 movl receiver(%eax), %eax
755 END_ENTRY _objc_msgSendSuper
757 /********************************************************************
758 * id objc_msgSendv(id self, SEL _cmd, unsigned size, marg_list frame);
761 * (sp+4) is the message receiver,
762 * (sp+8) is the selector,
763 * (sp+12) is the size of the marg_list, in bytes,
764 * (sp+16) is the address of the marg_list
766 ********************************************************************/
771 trap // _objc_msgSendv is not for the kernel
775 // stack is currently aligned assuming no extra arguments
776 movl (marg_list+4)(%ebp), %edx
777 addl $8, %edx // skip self & selector
778 movl (marg_size+4)(%ebp), %ecx
779 subl $8, %ecx // skip self & selector
783 // %esp = %esp - (16 - ((numVariableArguments & 3) << 2))
784 movl %ecx, %eax // 16-byte align stack
792 movl 0(%edx, %ecx, 4), %eax
797 movl (selector+4)(%ebp), %ecx
799 movl (self+4)(%ebp),%ecx
807 END_ENTRY _objc_msgSendv
809 /********************************************************************
811 * double objc_msgSend_fpret(id self, SEL _cmd,...);
813 ********************************************************************/
815 ENTRY _objc_msgSend_fpret
819 // load receiver and selector
820 movl selector(%esp), %ecx
821 movl self(%esp), %eax
823 // check whether selector is ignored
825 je LMsgSendFpretDone // return self from %eax
827 // check whether receiver is nil
829 je LMsgSendFpretNilSelf
831 // receiver (in %eax) is non-nil: search the cache
832 LMsgSendFpretReceiverOk:
833 movl isa(%eax), %edx // class = self->isa
834 CacheLookup WORD_RETURN, MSG_SEND, LMsgSendFpretCacheMiss
835 xor %edx, %edx // set nonstret for msgForward_internal
837 jmp *%eax // goto *imp
839 // cache miss: go search the method lists
840 LMsgSendFpretCacheMiss:
841 MethodTableLookup WORD_RETURN, MSG_SEND
842 xor %edx, %edx // set nonstret for msgForward_internal
843 jmp *%eax // goto *imp
845 // message sent to nil: redirect to nil receiver, if any
846 LMsgSendFpretNilSelf:
847 call 1f // load new receiver
849 movl __objc_nilReceiver-1b(%edx),%eax
850 testl %eax, %eax // return zero if no new receiver
851 je LMsgSendFpretReturnZero
852 movl %eax, self(%esp) // send to new receiver
853 jmp LMsgSendFpretReceiverOk // receiver must be in %eax
854 LMsgSendFpretReturnZero:
861 END_ENTRY _objc_msgSend_fpret
863 /********************************************************************
864 * double objc_msgSendv_fpret(id self, SEL _cmd, unsigned size, marg_list frame);
867 * (sp+4) is the message receiver,
868 * (sp+8) is the selector,
869 * (sp+12) is the size of the marg_list, in bytes,
870 * (sp+16) is the address of the marg_list
872 ********************************************************************/
874 ENTRY _objc_msgSendv_fpret
877 trap // _objc_msgSendv is not for the kernel
881 // stack is currently aligned assuming no extra arguments
882 movl (marg_list+4)(%ebp), %edx
883 addl $8, %edx // skip self & selector
884 movl (marg_size+4)(%ebp), %ecx
885 subl $8, %ecx // skip self & selector
887 je LMsgSendvFpretArgsOK
889 // %esp = %esp - (16 - ((numVariableArguments & 3) << 2))
890 movl %ecx, %eax // 16-byte align stack
896 LMsgSendvFpretArgLoop:
898 movl 0(%edx, %ecx, 4), %eax
900 jg LMsgSendvFpretArgLoop
902 LMsgSendvFpretArgsOK:
903 movl (selector+4)(%ebp), %ecx
905 movl (self+4)(%ebp),%ecx
907 call _objc_msgSend_fpret
913 END_ENTRY _objc_msgSendv_fpret
915 /********************************************************************
917 * void objc_msgSend_stret(void *st_addr , id self, SEL _cmd, ...);
920 * objc_msgSend_stret is the struct-return form of msgSend.
921 * The ABI calls for (sp+4) to be used as the address of the structure
922 * being returned, with the parameters in the succeeding locations.
924 * On entry: (sp+4)is the address where the structure is returned,
925 * (sp+8) is the message receiver,
926 * (sp+12) is the selector
927 ********************************************************************/
929 ENTRY _objc_msgSend_stret
933 // load receiver and selector
934 movl self_stret(%esp), %eax
935 movl (selector_stret)(%esp), %ecx
937 // check whether receiver is nil
939 je LMsgSendStretNilSelf
941 // receiver (in %eax) is non-nil: search the cache
942 LMsgSendStretReceiverOk:
943 movl isa(%eax), %edx // class = self->isa
944 CacheLookup STRUCT_RETURN, MSG_SEND, LMsgSendStretCacheMiss
945 movl $1, %edx // set stret for objc_msgForward
947 jmp *%eax // goto *imp
949 // cache miss: go search the method lists
950 LMsgSendStretCacheMiss:
951 MethodTableLookup STRUCT_RETURN, MSG_SEND
952 movl $1, %edx // set stret for objc_msgForward
953 jmp *%eax // goto *imp
955 // message sent to nil: redirect to nil receiver, if any
956 LMsgSendStretNilSelf:
957 call 1f // load new receiver
959 movl __objc_nilReceiver-1b(%edx),%eax
960 testl %eax, %eax // return nil if no new receiver
962 movl %eax, self_stret(%esp) // send to new receiver
963 jmp LMsgSendStretReceiverOk // receiver must be in %eax
966 ret $4 // pop struct return address (#2995932)
968 // guaranteed non-nil entry point (disabled for now)
969 // .globl _objc_msgSendNonNil_stret
970 // _objc_msgSendNonNil_stret:
972 // movl self_stret(%esp), %eax
973 // jmp LMsgSendStretReceiverOk
976 END_ENTRY _objc_msgSend_stret
978 /********************************************************************
980 * void objc_msgSendSuper_stret(void *st_addr, struct objc_super *super, SEL _cmd, ...);
982 * struct objc_super {
987 * objc_msgSendSuper_stret is the struct-return form of msgSendSuper.
988 * The ABI calls for (sp+4) to be used as the address of the structure
989 * being returned, with the parameters in the succeeding registers.
991 * On entry: (sp+4)is the address where the structure is returned,
992 * (sp+8) is the address of the objc_super structure,
993 * (sp+12) is the selector
995 ********************************************************************/
997 ENTRY _objc_msgSendSuper_stret
1001 // load selector and class to search
1002 movl super_stret(%esp), %eax // struct objc_super
1003 movl (selector_stret)(%esp), %ecx // get selector
1004 movl class(%eax), %edx // struct objc_super->class
1006 // search the cache (class in %edx)
1007 CacheLookup STRUCT_RETURN, MSG_SENDSUPER, LMsgSendSuperStretCacheMiss
1008 movl $1, %edx // set stret for objc_msgForward
1010 jmp *%eax // goto *imp
1012 // cache miss: go search the method lists
1013 LMsgSendSuperStretCacheMiss:
1014 MethodTableLookup STRUCT_RETURN, MSG_SENDSUPER
1015 movl $1, %edx // set stret for objc_msgForward
1016 jmp *%eax // goto *imp
1018 LMsgSendSuperStretExit:
1019 END_ENTRY _objc_msgSendSuper_stret
1022 /********************************************************************
1023 * void objc_msgSendv_stret(void *st_addr, id self, SEL _cmd, unsigned size, marg_list frame);
1025 * objc_msgSendv_stret is the struct-return form of msgSendv.
1026 * This function does not use the struct-return ABI; instead, the
1027 * structure return address is passed as a normal parameter.
1029 * On entry: (sp+4) is the address in which the returned struct is put,
1030 * (sp+8) is the message receiver,
1031 * (sp+12) is the selector,
1032 * (sp+16) is the size of the marg_list, in bytes,
1033 * (sp+20) is the address of the marg_list
1035 ********************************************************************/
1037 ENTRY _objc_msgSendv_stret
1040 trap // _objc_msgSendv_stret is not for the kernel
1044 subl $12, %esp // align stack assuming no extra arguments
1045 movl (marg_list_stret+4)(%ebp), %edx
1046 addl $8, %edx // skip self & selector
1047 movl (marg_size_stret+4)(%ebp), %ecx
1048 subl $5, %ecx // skip self & selector
1050 jle LMsgSendvStretArgsOK
1052 // %esp = %esp - (16 - ((numVariableArguments & 3) << 2))
1053 movl %ecx, %eax // 16-byte align stack
1059 LMsgSendvStretArgLoop:
1061 movl 0(%edx, %ecx, 4), %eax
1063 jg LMsgSendvStretArgLoop
1065 LMsgSendvStretArgsOK:
1066 movl (selector_stret+4)(%ebp), %ecx
1068 movl (self_stret+4)(%ebp),%ecx
1070 movl (struct_addr+4)(%ebp),%ecx
1072 call _objc_msgSend_stret
1078 END_ENTRY _objc_msgSendv_stret
1081 /********************************************************************
1083 * id _objc_msgForward(id self, SEL _cmd,...);
1085 ********************************************************************/
1087 // _FwdSel is @selector(forward::), set up in map_images().
1088 // ALWAYS dereference _FwdSel to get to "forward::" !!
1091 .private_extern _FwdSel
1096 LUnkSelStr: .ascii "Does not recognize selector %s (while forwarding %s)\0"
1100 .private_extern __objc_forward_handler
1101 __objc_forward_handler: .long 0
1105 .private_extern __objc_forward_stret_handler
1106 __objc_forward_stret_handler: .long 0
1108 STATIC_ENTRY __objc_msgForward_impcache
1109 // Method cache version
1111 // THIS IS NOT A CALLABLE C FUNCTION
1112 // Out-of-band register %edx is nonzero for stret, zero otherwise
1118 // Check return type (stret or not)
1120 jnz __objc_msgForward_stret
1121 jmp __objc_msgForward
1123 END_ENTRY _objc_msgForward_impcache
1126 ENTRY __objc_msgForward
1127 // Non-struct return version
1129 // Get PIC base into %edx
1130 call L__objc_msgForward$pic_base
1131 L__objc_msgForward$pic_base:
1134 // Call user handler, if any
1135 movl __objc_forward_handler-L__objc_msgForward$pic_base(%edx),%ecx
1136 testl %ecx, %ecx // if not NULL
1137 je 1f // skip to default handler
1138 jmp *%ecx // call __objc_forward_handler
1145 // Die if forwarding "forward::"
1146 movl (selector+4)(%ebp), %eax
1147 movl _FwdSel-L__objc_msgForward$pic_base(%edx),%ecx
1151 // Call [receiver forward:sel :margs]
1152 subl $8, %esp // 16-byte align the stack
1153 leal (self+4)(%ebp), %ecx
1154 pushl %ecx // &margs
1156 movl _FwdSel-L__objc_msgForward$pic_base(%edx),%ecx
1157 pushl %ecx // forward::
1158 pushl (self+4)(%ebp) // receiver
1167 // Call __objc_error(receiver, "unknown selector %s %s", "forward::", forwardedSel)
1168 subl $8, %esp // 16-byte align the stack
1169 pushl (selector+4+4)(%ebp) // the forwarded selector
1170 movl _FwdSel-L__objc_msgForward$pic_base(%edx),%eax
1172 leal LUnkSelStr-L__objc_msgForward$pic_base(%edx),%eax
1174 pushl (self+4)(%ebp)
1175 call ___objc_error // never returns
1177 END_ENTRY __objc_msgForward
1180 ENTRY __objc_msgForward_stret
1181 // Struct return version
1183 // Get PIC base into %edx
1184 call L__objc_msgForwardStret$pic_base
1185 L__objc_msgForwardStret$pic_base:
1188 // Call user handler, if any
1189 movl __objc_forward_stret_handler-L__objc_msgForwardStret$pic_base(%edx), %ecx
1190 testl %ecx, %ecx // if not NULL
1191 je 1f // skip to default handler
1192 jmp *%ecx // call __objc_forward_stret_handler
1199 // Die if forwarding "forward::"
1200 movl (selector_stret+4)(%ebp), %eax
1201 movl _FwdSel-L__objc_msgForwardStret$pic_base(%edx), %ecx
1203 je LMsgForwardStretError
1205 // Call [receiver forward:sel :margs]
1206 subl $8, %esp // 16-byte align the stack
1207 leal (self_stret+4)(%ebp), %ecx
1208 pushl %ecx // &margs
1210 movl _FwdSel-L__objc_msgForwardStret$pic_base(%edx),%ecx
1211 pushl %ecx // forward::
1212 pushl (self_stret+4)(%ebp) // receiver
1218 ret $4 // pop struct return address (#2995932)
1220 LMsgForwardStretError:
1221 // Call __objc_error(receiver, "unknown selector %s %s", "forward::", forwardedSelector)
1222 subl $8, %esp // 16-byte align the stack
1223 pushl (selector_stret+4+4)(%ebp) // the forwarded selector
1224 leal _FwdSel-L__objc_msgForwardStret$pic_base(%edx),%eax
1226 leal LUnkSelStr-L__objc_msgForwardStret$pic_base(%edx),%eax
1228 pushl (self_stret+4)(%ebp)
1229 call ___objc_error // never returns
1231 END_ENTRY __objc_msgForward_stret
1234 ENTRY _method_invoke
1236 movl selector(%esp), %ecx
1237 movl method_name(%ecx), %edx
1238 movl method_imp(%ecx), %eax
1239 movl %edx, selector(%esp)
1242 END_ENTRY _method_invoke
1245 ENTRY _method_invoke_stret
1247 movl selector_stret(%esp), %ecx
1248 movl method_name(%ecx), %edx
1249 movl method_imp(%ecx), %eax
1250 movl %edx, selector_stret(%esp)
1253 END_ENTRY _method_invoke_stret
1256 STATIC_ENTRY __objc_ignored_method
1258 movl self(%esp), %eax
1261 END_ENTRY __objc_ignored_method
1264 .section __DATA,__objc_msg_break