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_OS_SIMULATOR
27 /********************************************************************
28 ********************************************************************
30 ** objc-msg-i386.s - i386 code to support objc messaging.
32 ********************************************************************
33 ********************************************************************/
36 /********************************************************************
37 * Data used by the ObjC runtime.
39 ********************************************************************/
43 // _objc_entryPoints and _objc_exitPoints are used by objc
44 // to get the critical regions for which method caches
45 // cannot be garbage collected.
48 .private_extern _objc_entryPoints
51 .long __cache_getMethod
53 .long _objc_msgSend_fpret
54 .long _objc_msgSend_stret
55 .long _objc_msgSendSuper
56 .long _objc_msgSendSuper_stret
59 .private_extern _objc_exitPoints
64 .long LMsgSendFpretExit
65 .long LMsgSendStretExit
66 .long LMsgSendSuperExit
67 .long LMsgSendSuperStretExit
71 /********************************************************************
75 ********************************************************************/
93 /********************************************************************
95 * Structure definitions.
97 ********************************************************************/
99 // objc_super parameter to sendSuper
103 // Selected field offsets in class structure
114 buckets = 8 // variable length array
116 #if defined(OBJC_INSTRUMENTED)
117 // Cache instrumentation data, follows buckets
119 hitProbes = hitCount + 4
120 maxHitProbes = hitProbes + 4
121 missCount = maxHitProbes + 4
122 missProbes = missCount + 4
123 maxMissProbes = missProbes + 4
124 flushCount = maxMissProbes + 4
125 flushedEntries = flushCount + 4
127 // Buckets in CacheHitHistogram and CacheMissHistogram
128 CACHE_HISTOGRAM_SIZE = 512
132 //////////////////////////////////////////////////////////////////////
134 // ENTRY functionName
136 // Assembly directives to begin an exported function.
138 // Takes: functionName - name of the exported function
139 //////////////////////////////////////////////////////////////////////
155 //////////////////////////////////////////////////////////////////////
157 // END_ENTRY functionName
159 // Assembly directives to end an exported function. Just a placeholder,
160 // a close-parenthesis for ENTRY, until it is needed for something.
162 // Takes: functionName - name of the exported function
163 //////////////////////////////////////////////////////////////////////
168 //////////////////////////////////////////////////////////////////////
172 // Calls mcount() profiling routine. Must be called immediately on
173 // function entry, before any prologue executes.
175 //////////////////////////////////////////////////////////////////////
179 // Current stack contents: ret
183 // Current stack contents: ret, ebp, pad, pad
191 /////////////////////////////////////////////////////////////////////
194 // CacheLookup WORD_RETURN | STRUCT_RETURN, MSG_SEND | MSG_SENDSUPER | CACHE_GET, cacheMissLabel
196 // Locate the implementation for a selector in a class method cache.
198 // Takes: WORD_RETURN (first parameter is at sp+4)
199 // STRUCT_RETURN (struct address is at sp+4, first parameter at sp+8)
200 // MSG_SEND (first parameter is receiver)
201 // MSG_SENDSUPER (first parameter is address of objc_super structure)
202 // CACHE_GET (first parameter is class; return method triplet)
204 // class to search in %edx
206 // cacheMissLabel = label to branch to iff method is not cached
208 // On exit: (found) MSG_SEND and MSG_SENDSUPER: return imp in eax
209 // (found) CACHE_GET: return method triplet in eax
210 // (not found) jumps to cacheMissLabel
212 /////////////////////////////////////////////////////////////////////
215 // Values to specify to method lookup macros whether the return type of
216 // the method is word or structure.
220 // Values to specify to method lookup macros whether the first argument
221 // is an object/class reference or a 'objc_super' structure.
222 MSG_SEND = 0 // first argument is receiver, search the isa
223 MSG_SENDSUPER = 1 // first argument is objc_super, search the class
224 CACHE_GET = 2 // first argument is class, search that class
228 // load variables and save caller registers.
230 pushl %edi // save scratch register
231 movl cache(%edx), %edi // cache = class->cache
232 pushl %esi // save scratch register
234 #if defined(OBJC_INSTRUMENTED)
235 pushl %ebx // save non-volatile register
236 pushl %eax // save cache pointer
237 xorl %ebx, %ebx // probeCount = 0
239 movl mask(%edi), %esi // mask = cache->mask
240 movl %ecx, %edx // index = selector
241 shrl $$2, %edx // index = selector >> 2
243 // search the receiver's cache
248 // eax = method (soon)
249 LMsgSendProbeCache_$0_$1_$2:
250 #if defined(OBJC_INSTRUMENTED)
251 addl $$1, %ebx // probeCount += 1
253 andl %esi, %edx // index &= mask
254 movl buckets(%edi, %edx, 4), %eax // meth = cache->buckets[index]
256 testl %eax, %eax // check for end of bucket
257 je LMsgSendCacheMiss_$0_$1_$2 // go to cache miss code
258 cmpl method_name(%eax), %ecx // check for method name match
259 je LMsgSendCacheHit_$0_$1_$2 // go handle cache hit
260 addl $$1, %edx // bump index ...
261 jmp LMsgSendProbeCache_$0_$1_$2 // ... and loop
263 // not found in cache: restore state and go to callers handler
264 LMsgSendCacheMiss_$0_$1_$2:
265 #if defined(OBJC_INSTRUMENTED)
266 popl %edx // retrieve cache pointer
267 movl mask(%edx), %esi // mask = cache->mask
268 testl %esi, %esi // a mask of zero is only for the...
269 je LMsgSendMissInstrumentDone_$0_$1_$2 // ... emptyCache, do not record anything
271 // locate and update the CacheInstrumentation structure
272 addl $$1, %esi // entryCount = mask + 1
273 shll $$2, %esi // tableSize = entryCount * sizeof(entry)
274 addl $buckets, %esi // offset = buckets + tableSize
275 addl %edx, %esi // cacheData = &cache->buckets[mask+1]
277 movl missCount(%esi), %edi //
279 movl %edi, missCount(%esi) // cacheData->missCount += 1
280 movl missProbes(%esi), %edi //
282 movl %edi, missProbes(%esi) // cacheData->missProbes += probeCount
283 movl maxMissProbes(%esi), %edi// if (cacheData->maxMissProbes < probeCount)
285 jge LMsgSendMaxMissProbeOK_$0_$1_$2 //
286 movl %ebx, maxMissProbes(%esi)// cacheData->maxMissProbes = probeCount
287 LMsgSendMaxMissProbeOK_$0_$1_$2:
289 // update cache miss probe histogram
290 cmpl $CACHE_HISTOGRAM_SIZE, %ebx // pin probeCount to max index
291 jl LMsgSendMissHistoIndexSet_$0_$1_$2
292 movl $(CACHE_HISTOGRAM_SIZE-1), %ebx
293 LMsgSendMissHistoIndexSet_$0_$1_$2:
294 LEA_STATIC_DATA %esi, _CacheMissHistogram, EXTERNAL_SYMBOL
295 shll $$2, %ebx // convert probeCount to histogram index
296 addl %ebx, %esi // calculate &CacheMissHistogram[probeCount<<2]
297 movl 0(%esi), %edi // get current tally
299 movl %edi, 0(%esi) // tally += 1
300 LMsgSendMissInstrumentDone_$0_$1_$2:
301 popl %ebx // restore non-volatile register
304 .if $0 == WORD_RETURN // Regular word return
305 .if $1 == MSG_SEND // MSG_SEND
306 popl %esi // restore callers register
307 popl %edi // restore callers register
308 movl self(%esp), %edx // get messaged object
309 movl isa(%edx), %eax // get objects class
310 .elseif $1 == MSG_SENDSUPER // MSG_SENDSUPER
311 // replace "super" arg with "receiver"
312 movl super+8(%esp), %edi // get super structure
313 movl receiver(%edi), %edx // get messaged object
314 movl %edx, super+8(%esp) // make it the first argument
315 movl class(%edi), %eax // get messaged class
316 popl %esi // restore callers register
317 popl %edi // restore callers register
319 popl %esi // restore callers register
320 popl %edi // restore callers register
322 .else // Struct return
323 .if $1 == MSG_SEND // MSG_SEND (stret)
324 popl %esi // restore callers register
325 popl %edi // restore callers register
326 movl self_stret(%esp), %edx // get messaged object
327 movl isa(%edx), %eax // get objects class
328 .elseif $1 == MSG_SENDSUPER // MSG_SENDSUPER (stret)
329 // replace "super" arg with "receiver"
330 movl super_stret+8(%esp), %edi// get super structure
331 movl receiver(%edi), %edx // get messaged object
332 movl %edx, super_stret+8(%esp)// make it the first argument
333 movl class(%edi), %eax // get messaged class
334 popl %esi // restore callers register
335 popl %edi // restore callers register
337 !! This should not happen.
344 jmp $2 // go to callers handler
346 // eax points to matching cache entry
348 LMsgSendCacheHit_$0_$1_$2:
349 #if defined(OBJC_INSTRUMENTED)
350 popl %edx // retrieve cache pointer
351 movl mask(%edx), %esi // mask = cache->mask
352 testl %esi, %esi // a mask of zero is only for the...
353 je LMsgSendHitInstrumentDone_$0_$1_$2 // ... emptyCache, do not record anything
355 // locate and update the CacheInstrumentation structure
356 addl $$1, %esi // entryCount = mask + 1
357 shll $$2, %esi // tableSize = entryCount * sizeof(entry)
358 addl $buckets, %esi // offset = buckets + tableSize
359 addl %edx, %esi // cacheData = &cache->buckets[mask+1]
361 movl hitCount(%esi), %edi
363 movl %edi, hitCount(%esi) // cacheData->hitCount += 1
364 movl hitProbes(%esi), %edi
366 movl %edi, hitProbes(%esi) // cacheData->hitProbes += probeCount
367 movl maxHitProbes(%esi), %edi// if (cacheData->maxHitProbes < probeCount)
369 jge LMsgSendMaxHitProbeOK_$0_$1_$2
370 movl %ebx, maxHitProbes(%esi)// cacheData->maxHitProbes = probeCount
371 LMsgSendMaxHitProbeOK_$0_$1_$2:
373 // update cache hit probe histogram
374 cmpl $CACHE_HISTOGRAM_SIZE, %ebx // pin probeCount to max index
375 jl LMsgSendHitHistoIndexSet_$0_$1_$2
376 movl $(CACHE_HISTOGRAM_SIZE-1), %ebx
377 LMsgSendHitHistoIndexSet_$0_$1_$2:
378 LEA_STATIC_DATA %esi, _CacheHitHistogram, EXTERNAL_SYMBOL
379 shll $$2, %ebx // convert probeCount to histogram index
380 addl %ebx, %esi // calculate &CacheHitHistogram[probeCount<<2]
381 movl 0(%esi), %edi // get current tally
383 movl %edi, 0(%esi) // tally += 1
384 LMsgSendHitInstrumentDone_$0_$1_$2:
385 popl %ebx // restore non-volatile register
388 // load implementation address, restore state, and we're done
390 // method triplet is already in eax
392 movl method_imp(%eax), %eax // imp = method->method_imp
395 .if $0 == WORD_RETURN // Regular word return
396 .if $1 == MSG_SENDSUPER // MSG_SENDSUPER
397 // replace "super" arg with "self"
398 movl super+8(%esp), %edi
399 movl receiver(%edi), %esi
400 movl %esi, super+8(%esp)
402 .else // Struct return
403 .if $1 == MSG_SENDSUPER // MSG_SENDSUPER (stret)
404 // replace "super" arg with "self"
405 movl super_stret+8(%esp), %edi
406 movl receiver(%edi), %esi
407 movl %esi, super_stret+8(%esp)
411 // restore caller registers
417 /////////////////////////////////////////////////////////////////////
419 // MethodTableLookup WORD_RETURN | STRUCT_RETURN, MSG_SEND | MSG_SENDSUPER
421 // Takes: WORD_RETURN (first parameter is at sp+4)
422 // STRUCT_RETURN (struct address is at sp+4, first parameter at sp+8)
423 // MSG_SEND (first parameter is receiver)
424 // MSG_SENDSUPER (first parameter is address of objc_super structure)
429 // (all set by CacheLookup's miss case)
431 // Stack must be at 0xXXXXXXXc on entrance.
433 // On exit: esp unchanged
436 /////////////////////////////////////////////////////////////////////
438 .macro MethodTableLookup
439 // stack has return address and nothing else
440 subl $$(12+5*16), %esp
442 movdqa %xmm3, 4*16(%esp)
443 movdqa %xmm2, 3*16(%esp)
444 movdqa %xmm1, 2*16(%esp)
445 movdqa %xmm0, 1*16(%esp)
447 movl %eax, 8(%esp) // class
448 movl %ecx, 4(%esp) // selector
449 movl %edx, 0(%esp) // receiver
450 call __class_lookupMethodAndLoadCache3
452 movdqa 4*16(%esp), %xmm3
453 movdqa 3*16(%esp), %xmm2
454 movdqa 2*16(%esp), %xmm1
455 movdqa 1*16(%esp), %xmm0
457 addl $$(12+5*16), %esp // pop parameters
461 /********************************************************************
462 * Method _cache_getMethod(Class cls, SEL sel, IMP msgForward_internal_imp)
464 * If found, returns method triplet pointer.
465 * If not found, returns NULL.
467 * NOTE: _cache_getMethod never returns any cache entry whose implementation
468 * is _objc_msgForward_impcache. It returns 1 instead. This prevents thread-
469 * safety and memory management bugs in _class_lookupMethodAndLoadCache.
470 * See _class_lookupMethodAndLoadCache for details.
472 * _objc_msgForward_impcache is passed as a parameter because it's more
473 * efficient to do the (PIC) lookup once in the caller than repeatedly here.
474 ********************************************************************/
476 STATIC_ENTRY __cache_getMethod
478 // load the class and selector
479 movl selector(%esp), %ecx
480 movl self(%esp), %edx
483 CacheLookup WORD_RETURN, CACHE_GET, LGetMethodMiss
485 // cache hit, method triplet in %eax
486 movl first_arg(%esp), %ecx // check for _objc_msgForward_impcache
487 cmpl method_imp(%eax), %ecx // if (imp==_objc_msgForward_impcache)
488 je 1f // return (Method)1
489 ret // else return method triplet address
494 // cache miss, return nil
495 xorl %eax, %eax // zero %eax
499 END_ENTRY __cache_getMethod
502 /********************************************************************
503 * IMP _cache_getImp(Class cls, SEL sel)
505 * If found, returns method implementation.
506 * If not found, returns NULL.
507 ********************************************************************/
509 STATIC_ENTRY __cache_getImp
511 // load the class and selector
512 movl selector(%esp), %ecx
513 movl self(%esp), %edx
516 CacheLookup WORD_RETURN, CACHE_GET, LGetImpMiss
518 // cache hit, method triplet in %eax
519 movl method_imp(%eax), %eax // return method imp
523 // cache miss, return nil
524 xorl %eax, %eax // zero %eax
528 END_ENTRY __cache_getImp
531 /********************************************************************
533 * id objc_msgSend(id self, SEL _cmd,...);
535 ********************************************************************/
540 // load receiver and selector
541 movl selector(%esp), %ecx
542 movl self(%esp), %eax
544 // check whether receiver is nil
548 // receiver (in %eax) is non-nil: search the cache
550 movl isa(%eax), %edx // class = self->isa
551 CacheLookup WORD_RETURN, MSG_SEND, LMsgSendCacheMiss
552 xor %edx, %edx // set nonstret for msgForward_internal
555 // cache miss: go search the method lists
557 MethodTableLookup WORD_RETURN, MSG_SEND
558 xor %edx, %edx // set nonstret for msgForward_internal
559 jmp *%eax // goto *imp
561 // message sent to nil: redirect to nil receiver, if any
563 // %eax is already zero
569 // guaranteed non-nil entry point (disabled for now)
570 // .globl _objc_msgSendNonNil
571 // _objc_msgSendNonNil:
572 // movl self(%esp), %eax
573 // jmp LMsgSendReceiverOk
576 END_ENTRY _objc_msgSend
578 /********************************************************************
580 * id objc_msgSendSuper(struct objc_super *super, SEL _cmd,...);
582 * struct objc_super {
586 ********************************************************************/
588 ENTRY _objc_msgSendSuper
591 // load selector and class to search
592 movl super(%esp), %eax // struct objc_super
593 movl selector(%esp), %ecx
594 movl class(%eax), %edx // struct objc_super->class
596 // search the cache (class in %edx)
597 CacheLookup WORD_RETURN, MSG_SENDSUPER, LMsgSendSuperCacheMiss
598 xor %edx, %edx // set nonstret for msgForward_internal
599 jmp *%eax // goto *imp
601 // cache miss: go search the method lists
602 LMsgSendSuperCacheMiss:
603 MethodTableLookup WORD_RETURN, MSG_SENDSUPER
604 xor %edx, %edx // set nonstret for msgForward_internal
605 jmp *%eax // goto *imp
607 // ignored selector: return self
608 LMsgSendSuperIgnored:
609 movl super(%esp), %eax
610 movl receiver(%eax), %eax
614 END_ENTRY _objc_msgSendSuper
616 /********************************************************************
617 * id objc_msgSendv(id self, SEL _cmd, unsigned size, marg_list frame);
620 * (sp+4) is the message receiver,
621 * (sp+8) is the selector,
622 * (sp+12) is the size of the marg_list, in bytes,
623 * (sp+16) is the address of the marg_list
625 ********************************************************************/
630 trap // _objc_msgSendv is not for the kernel
634 // stack is currently aligned assuming no extra arguments
635 movl (marg_list+4)(%ebp), %edx
636 addl $8, %edx // skip self & selector
637 movl (marg_size+4)(%ebp), %ecx
638 subl $8, %ecx // skip self & selector
642 // %esp = %esp - (16 - ((numVariableArguments & 3) << 2))
643 movl %ecx, %eax // 16-byte align stack
651 movl 0(%edx, %ecx, 4), %eax
656 movl (selector+4)(%ebp), %ecx
658 movl (self+4)(%ebp),%ecx
666 END_ENTRY _objc_msgSendv
668 /********************************************************************
670 * double objc_msgSend_fpret(id self, SEL _cmd,...);
672 ********************************************************************/
674 ENTRY _objc_msgSend_fpret
677 // load receiver and selector
678 movl selector(%esp), %ecx
679 movl self(%esp), %eax
681 // check whether receiver is nil
683 je LMsgSendFpretNilSelf
685 // receiver (in %eax) is non-nil: search the cache
686 LMsgSendFpretReceiverOk:
687 movl isa(%eax), %edx // class = self->isa
688 CacheLookup WORD_RETURN, MSG_SEND, LMsgSendFpretCacheMiss
689 xor %edx, %edx // set nonstret for msgForward_internal
690 jmp *%eax // goto *imp
692 // cache miss: go search the method lists
693 LMsgSendFpretCacheMiss:
694 MethodTableLookup WORD_RETURN, MSG_SEND
695 xor %edx, %edx // set nonstret for msgForward_internal
696 jmp *%eax // goto *imp
698 // message sent to nil: redirect to nil receiver, if any
699 LMsgSendFpretNilSelf:
700 // %eax is already zero
706 END_ENTRY _objc_msgSend_fpret
708 /********************************************************************
709 * double objc_msgSendv_fpret(id self, SEL _cmd, unsigned size, marg_list frame);
712 * (sp+4) is the message receiver,
713 * (sp+8) is the selector,
714 * (sp+12) is the size of the marg_list, in bytes,
715 * (sp+16) is the address of the marg_list
717 ********************************************************************/
719 ENTRY _objc_msgSendv_fpret
722 trap // _objc_msgSendv is not for the kernel
726 // stack is currently aligned assuming no extra arguments
727 movl (marg_list+4)(%ebp), %edx
728 addl $8, %edx // skip self & selector
729 movl (marg_size+4)(%ebp), %ecx
730 subl $8, %ecx // skip self & selector
732 je LMsgSendvFpretArgsOK
734 // %esp = %esp - (16 - ((numVariableArguments & 3) << 2))
735 movl %ecx, %eax // 16-byte align stack
741 LMsgSendvFpretArgLoop:
743 movl 0(%edx, %ecx, 4), %eax
745 jg LMsgSendvFpretArgLoop
747 LMsgSendvFpretArgsOK:
748 movl (selector+4)(%ebp), %ecx
750 movl (self+4)(%ebp),%ecx
752 call _objc_msgSend_fpret
758 END_ENTRY _objc_msgSendv_fpret
760 /********************************************************************
762 * void objc_msgSend_stret(void *st_addr , id self, SEL _cmd, ...);
765 * objc_msgSend_stret is the struct-return form of msgSend.
766 * The ABI calls for (sp+4) to be used as the address of the structure
767 * being returned, with the parameters in the succeeding locations.
769 * On entry: (sp+4)is the address where the structure is returned,
770 * (sp+8) is the message receiver,
771 * (sp+12) is the selector
772 ********************************************************************/
774 ENTRY _objc_msgSend_stret
777 // load receiver and selector
778 movl self_stret(%esp), %eax
779 movl (selector_stret)(%esp), %ecx
781 // check whether receiver is nil
783 je LMsgSendStretNilSelf
785 // receiver (in %eax) is non-nil: search the cache
786 LMsgSendStretReceiverOk:
787 movl isa(%eax), %edx // class = self->isa
788 CacheLookup STRUCT_RETURN, MSG_SEND, LMsgSendStretCacheMiss
789 movl $1, %edx // set stret for objc_msgForward
790 jmp *%eax // goto *imp
792 // cache miss: go search the method lists
793 LMsgSendStretCacheMiss:
794 MethodTableLookup STRUCT_RETURN, MSG_SEND
795 movl $1, %edx // set stret for objc_msgForward
796 jmp *%eax // goto *imp
798 // message sent to nil: redirect to nil receiver, if any
799 LMsgSendStretNilSelf:
800 ret $4 // pop struct return address (#2995932)
802 // guaranteed non-nil entry point (disabled for now)
803 // .globl _objc_msgSendNonNil_stret
804 // _objc_msgSendNonNil_stret:
806 // movl self_stret(%esp), %eax
807 // jmp LMsgSendStretReceiverOk
810 END_ENTRY _objc_msgSend_stret
812 /********************************************************************
814 * void objc_msgSendSuper_stret(void *st_addr, struct objc_super *super, SEL _cmd, ...);
816 * struct objc_super {
821 * objc_msgSendSuper_stret is the struct-return form of msgSendSuper.
822 * The ABI calls for (sp+4) to be used as the address of the structure
823 * being returned, with the parameters in the succeeding registers.
825 * On entry: (sp+4)is the address where the structure is returned,
826 * (sp+8) is the address of the objc_super structure,
827 * (sp+12) is the selector
829 ********************************************************************/
831 ENTRY _objc_msgSendSuper_stret
834 // load selector and class to search
835 movl super_stret(%esp), %eax // struct objc_super
836 movl (selector_stret)(%esp), %ecx // get selector
837 movl class(%eax), %edx // struct objc_super->class
839 // search the cache (class in %edx)
840 CacheLookup STRUCT_RETURN, MSG_SENDSUPER, LMsgSendSuperStretCacheMiss
841 movl $1, %edx // set stret for objc_msgForward
842 jmp *%eax // goto *imp
844 // cache miss: go search the method lists
845 LMsgSendSuperStretCacheMiss:
846 MethodTableLookup STRUCT_RETURN, MSG_SENDSUPER
847 movl $1, %edx // set stret for objc_msgForward
848 jmp *%eax // goto *imp
850 LMsgSendSuperStretExit:
851 END_ENTRY _objc_msgSendSuper_stret
854 /********************************************************************
855 * void objc_msgSendv_stret(void *st_addr, id self, SEL _cmd, unsigned size, marg_list frame);
857 * objc_msgSendv_stret is the struct-return form of msgSendv.
858 * This function does not use the struct-return ABI; instead, the
859 * structure return address is passed as a normal parameter.
861 * On entry: (sp+4) is the address in which the returned struct is put,
862 * (sp+8) is the message receiver,
863 * (sp+12) is the selector,
864 * (sp+16) is the size of the marg_list, in bytes,
865 * (sp+20) is the address of the marg_list
867 ********************************************************************/
869 ENTRY _objc_msgSendv_stret
872 trap // _objc_msgSendv_stret is not for the kernel
876 subl $12, %esp // align stack assuming no extra arguments
877 movl (marg_list_stret+4)(%ebp), %edx
878 addl $8, %edx // skip self & selector
879 movl (marg_size_stret+4)(%ebp), %ecx
880 subl $5, %ecx // skip self & selector
882 jle LMsgSendvStretArgsOK
884 // %esp = %esp - (16 - ((numVariableArguments & 3) << 2))
885 movl %ecx, %eax // 16-byte align stack
891 LMsgSendvStretArgLoop:
893 movl 0(%edx, %ecx, 4), %eax
895 jg LMsgSendvStretArgLoop
897 LMsgSendvStretArgsOK:
898 movl (selector_stret+4)(%ebp), %ecx
900 movl (self_stret+4)(%ebp),%ecx
902 movl (struct_addr+4)(%ebp),%ecx
904 call _objc_msgSend_stret
910 END_ENTRY _objc_msgSendv_stret
913 /********************************************************************
915 * id _objc_msgForward(id self, SEL _cmd,...);
917 ********************************************************************/
919 // _FwdSel is @selector(forward::), set up in map_images().
920 // ALWAYS dereference _FwdSel to get to "forward::" !!
923 .private_extern _FwdSel
928 LUnkSelStr: .ascii "Does not recognize selector %s (while forwarding %s)\0"
930 .non_lazy_symbol_pointer
932 .indirect_symbol __objc_forward_handler
934 L_forward_stret_handler:
935 .indirect_symbol __objc_forward_stret_handler
938 STATIC_ENTRY __objc_msgForward_impcache
939 // Method cache version
941 // THIS IS NOT A CALLABLE C FUNCTION
942 // Out-of-band register %edx is nonzero for stret, zero otherwise
944 // Check return type (stret or not)
946 jnz __objc_msgForward_stret
947 jmp __objc_msgForward
949 END_ENTRY _objc_msgForward_impcache
952 ENTRY __objc_msgForward
953 // Non-struct return version
955 // Get PIC base into %edx
956 call L__objc_msgForward$pic_base
957 L__objc_msgForward$pic_base:
960 // Call user handler, if any
961 movl L_forward_handler-L__objc_msgForward$pic_base(%edx),%ecx
963 testl %ecx, %ecx // if not NULL
964 je 1f // skip to default handler
965 jmp *%ecx // call __objc_forward_handler
972 // Die if forwarding "forward::"
973 movl (selector+4)(%ebp), %eax
974 movl _FwdSel-L__objc_msgForward$pic_base(%edx),%ecx
978 // Call [receiver forward:sel :margs]
979 subl $8, %esp // 16-byte align the stack
980 leal (self+4)(%ebp), %ecx
983 movl _FwdSel-L__objc_msgForward$pic_base(%edx),%ecx
984 pushl %ecx // forward::
985 pushl (self+4)(%ebp) // receiver
994 // Call __objc_error(receiver, "unknown selector %s %s", "forward::", forwardedSel)
995 subl $8, %esp // 16-byte align the stack
996 pushl (selector+4+4)(%ebp) // the forwarded selector
997 movl _FwdSel-L__objc_msgForward$pic_base(%edx),%eax
999 leal LUnkSelStr-L__objc_msgForward$pic_base(%edx),%eax
1001 pushl (self+4)(%ebp)
1002 call ___objc_error // never returns
1004 END_ENTRY __objc_msgForward
1007 ENTRY __objc_msgForward_stret
1008 // Struct return version
1010 // Get PIC base into %edx
1011 call L__objc_msgForwardStret$pic_base
1012 L__objc_msgForwardStret$pic_base:
1015 // Call user handler, if any
1016 movl L_forward_stret_handler-L__objc_msgForwardStret$pic_base(%edx), %ecx
1018 testl %ecx, %ecx // if not NULL
1019 je 1f // skip to default handler
1020 jmp *%ecx // call __objc_forward_stret_handler
1027 // Die if forwarding "forward::"
1028 movl (selector_stret+4)(%ebp), %eax
1029 movl _FwdSel-L__objc_msgForwardStret$pic_base(%edx), %ecx
1031 je LMsgForwardStretError
1033 // Call [receiver forward:sel :margs]
1034 subl $8, %esp // 16-byte align the stack
1035 leal (self_stret+4)(%ebp), %ecx
1036 pushl %ecx // &margs
1038 movl _FwdSel-L__objc_msgForwardStret$pic_base(%edx),%ecx
1039 pushl %ecx // forward::
1040 pushl (self_stret+4)(%ebp) // receiver
1046 ret $4 // pop struct return address (#2995932)
1048 LMsgForwardStretError:
1049 // Call __objc_error(receiver, "unknown selector %s %s", "forward::", forwardedSelector)
1050 subl $8, %esp // 16-byte align the stack
1051 pushl (selector_stret+4+4)(%ebp) // the forwarded selector
1052 leal _FwdSel-L__objc_msgForwardStret$pic_base(%edx),%eax
1054 leal LUnkSelStr-L__objc_msgForwardStret$pic_base(%edx),%eax
1056 pushl (self_stret+4)(%ebp)
1057 call ___objc_error // never returns
1059 END_ENTRY __objc_msgForward_stret
1062 ENTRY _method_invoke
1064 movl selector(%esp), %ecx
1065 movl method_name(%ecx), %edx
1066 movl method_imp(%ecx), %eax
1067 movl %edx, selector(%esp)
1070 END_ENTRY _method_invoke
1073 ENTRY _method_invoke_stret
1075 movl selector_stret(%esp), %ecx
1076 movl method_name(%ecx), %edx
1077 movl method_imp(%ecx), %eax
1078 movl %edx, selector_stret(%esp)
1081 END_ENTRY _method_invoke_stret
1084 .section __DATA,__objc_msg_break