objc-msg-simulator-i386.s 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. /*
  2. * Copyright (c) 1999-2009 Apple Inc. All Rights Reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  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
  11. * file.
  12. *
  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.
  20. *
  21. * @APPLE_LICENSE_HEADER_END@
  22. */
  23. #include <TargetConditionals.h>
  24. #if defined(__i386__) && TARGET_OS_SIMULATOR
  25. #include "objc-config.h"
  26. .data
  27. // _objc_entryPoints and _objc_exitPoints are used by objc
  28. // to get the critical regions for which method caches
  29. // cannot be garbage collected.
  30. .align 2
  31. .private_extern _objc_entryPoints
  32. _objc_entryPoints:
  33. .long _cache_getImp
  34. .long _objc_msgSend
  35. .long _objc_msgSend_fpret
  36. .long _objc_msgSend_stret
  37. .long _objc_msgSendSuper
  38. .long _objc_msgSendSuper2
  39. .long _objc_msgSendSuper_stret
  40. .long _objc_msgSendSuper2_stret
  41. .long _objc_msgLookup
  42. .long _objc_msgLookup_fpret
  43. .long _objc_msgLookup_stret
  44. .long _objc_msgLookupSuper2
  45. .long _objc_msgLookupSuper2_stret
  46. .long 0
  47. .private_extern _objc_exitPoints
  48. _objc_exitPoints:
  49. .long LExit_cache_getImp
  50. .long LExit_objc_msgSend
  51. .long LExit_objc_msgSend_fpret
  52. .long LExit_objc_msgSend_stret
  53. .long LExit_objc_msgSendSuper
  54. .long LExit_objc_msgSendSuper2
  55. .long LExit_objc_msgSendSuper_stret
  56. .long LExit_objc_msgSendSuper2_stret
  57. .long LExit_objc_msgLookup
  58. .long LExit_objc_msgLookup_fpret
  59. .long LExit_objc_msgLookup_stret
  60. .long LExit_objc_msgLookupSuper2
  61. .long LExit_objc_msgLookupSuper2_stret
  62. .long 0
  63. /********************************************************************
  64. * Names for relative labels
  65. * DO NOT USE THESE LABELS ELSEWHERE
  66. * Reserved labels: 5: 6: 7: 8: 9:
  67. ********************************************************************/
  68. #define LCacheMiss 5
  69. #define LCacheMiss_f 5f
  70. #define LCacheMiss_b 5b
  71. #define LNilTestDone 6
  72. #define LNilTestDone_f 6f
  73. #define LNilTestDone_b 6b
  74. #define LNilTestSlow 7
  75. #define LNilTestSlow_f 7f
  76. #define LNilTestSlow_b 7b
  77. #define LGetIsaDone 8
  78. #define LGetIsaDone_f 8f
  79. #define LGetIsaDone_b 8b
  80. #define LGetIsaSlow 9
  81. #define LGetIsaSlow_f 9f
  82. #define LGetIsaSlow_b 9b
  83. /********************************************************************
  84. * Macro parameters
  85. ********************************************************************/
  86. #define NORMAL 0
  87. #define FPRET 1
  88. #define STRET 2
  89. #define CALL 100
  90. #define GETIMP 101
  91. #define LOOKUP 102
  92. /********************************************************************
  93. *
  94. * Structure definitions.
  95. *
  96. ********************************************************************/
  97. // Offsets from %esp
  98. #define self 4
  99. #define super 4
  100. #define selector 8
  101. #define marg_size 12
  102. #define marg_list 16
  103. #define first_arg 12
  104. #define struct_addr 4
  105. #define self_stret 8
  106. #define super_stret 8
  107. #define selector_stret 12
  108. #define marg_size_stret 16
  109. #define marg_list_stret 20
  110. // objc_super parameter to sendSuper
  111. #define receiver 0
  112. #define class 4
  113. // Selected field offsets in class structure
  114. #define isa 0
  115. #define superclass 4
  116. #define cache_buckets 8
  117. #define cache_mask 12
  118. // Method cache
  119. #define cached_sel 0
  120. #define cached_imp 4
  121. // Method descriptor
  122. #define method_name 0
  123. #define method_imp 8
  124. //////////////////////////////////////////////////////////////////////
  125. //
  126. // ENTRY functionName
  127. //
  128. // Assembly directives to begin an exported function.
  129. //
  130. // Takes: functionName - name of the exported function
  131. //////////////////////////////////////////////////////////////////////
  132. .macro ENTRY
  133. .text
  134. .globl $0
  135. .align 2, 0x90
  136. $0:
  137. .endmacro
  138. .macro STATIC_ENTRY
  139. .text
  140. .private_extern $0
  141. .align 4, 0x90
  142. $0:
  143. .endmacro
  144. //////////////////////////////////////////////////////////////////////
  145. //
  146. // END_ENTRY functionName
  147. //
  148. // Assembly directives to end an exported function. Just a placeholder,
  149. // a close-parenthesis for ENTRY, until it is needed for something.
  150. //
  151. // Takes: functionName - name of the exported function
  152. //////////////////////////////////////////////////////////////////////
  153. .macro END_ENTRY
  154. LExit$0:
  155. .endmacro
  156. /********************************************************************
  157. * UNWIND name, flags
  158. * Unwind info generation
  159. ********************************************************************/
  160. .macro UNWIND
  161. .section __LD,__compact_unwind,regular,debug
  162. .long $0
  163. .set LUnwind$0, LExit$0 - $0
  164. .long LUnwind$0
  165. .long $1
  166. .long 0 /* no personality */
  167. .long 0 /* no LSDA */
  168. .text
  169. .endmacro
  170. #define NoFrame 0x02010000 // no frame, no SP adjustment except return address
  171. #define FrameWithNoSaves 0x01000000 // frame, no non-volatile saves
  172. /////////////////////////////////////////////////////////////////////
  173. //
  174. // CacheLookup return-type, caller
  175. //
  176. // Locate the implementation for a selector in a class method cache.
  177. //
  178. // Takes:
  179. // $0 = NORMAL, FPRET, STRET
  180. // $1 = CALL, LOOKUP, GETIMP
  181. // ecx = selector to search for
  182. // edx = class to search
  183. //
  184. // On exit: ecx clobbered
  185. // (found) calls or returns IMP in eax, eq/ne set for forwarding
  186. // (not found) jumps to LCacheMiss, class still in edx
  187. //
  188. /////////////////////////////////////////////////////////////////////
  189. .macro CacheHit
  190. // CacheHit must always be preceded by a not-taken `jne` instruction
  191. // in case the imp is _objc_msgForward_impcache.
  192. // eax = found bucket
  193. .if $1 == GETIMP
  194. movl cached_imp(%eax), %eax // return imp
  195. ret
  196. .else
  197. .if $0 != STRET
  198. // eq already set for forwarding by `jne`
  199. .else
  200. test %eax, %eax // set ne for stret forwarding
  201. .endif
  202. .if $1 == CALL
  203. jmp *cached_imp(%eax) // call imp
  204. .elseif $1 == LOOKUP
  205. movl cached_imp(%eax), %eax // return imp
  206. ret
  207. .else
  208. .abort oops
  209. .endif
  210. .endif
  211. .endmacro
  212. .macro CacheLookup
  213. movzwl cache_mask(%edx), %eax // eax = mask
  214. andl %ecx, %eax // eax = SEL & mask
  215. shll $$3, %eax // eax = offset = (SEL & mask) * 8
  216. addl cache_buckets(%edx), %eax // eax = bucket = buckets+offset
  217. cmpl cached_sel(%eax), %ecx // if (bucket->sel != SEL)
  218. jne 1f // scan more
  219. // The `jne` above sets flags for CacheHit
  220. CacheHit $0, $1 // call or return imp
  221. 1:
  222. // loop
  223. cmpl $$1, cached_sel(%eax)
  224. jbe 3f // if (bucket->sel <= 1) wrap or miss
  225. addl $$8, %eax // bucket++
  226. 2:
  227. cmpl cached_sel(%eax), %ecx // if (bucket->sel != sel)
  228. jne 1b // scan more
  229. // The `jne` above sets flags for CacheHit
  230. CacheHit $0, $1 // call or return imp
  231. 3:
  232. // wrap or miss
  233. jb LCacheMiss_f // if (bucket->sel < 1) cache miss
  234. // wrap
  235. movl cached_imp(%eax), %eax // bucket->imp is really first bucket
  236. jmp 2f
  237. // Clone scanning loop to miss instead of hang when cache is corrupt.
  238. // The slow path may detect any corruption and halt later.
  239. 1:
  240. // loop
  241. cmpl $$1, cached_sel(%eax)
  242. jbe 3f // if (bucket->sel <= 1) wrap or miss
  243. addl $$8, %eax // bucket++
  244. 2:
  245. cmpl cached_sel(%eax), %ecx // if (bucket->sel != sel)
  246. jne 1b // scan more
  247. // The `jne` above sets flags for CacheHit
  248. CacheHit $0, $1 // call or return imp
  249. 3:
  250. // double wrap or miss
  251. jmp LCacheMiss_f
  252. .endmacro
  253. /////////////////////////////////////////////////////////////////////
  254. //
  255. // MethodTableLookup NORMAL|STRET
  256. //
  257. // Takes:
  258. // receiver (not struct objc_super) and selector on stack
  259. // edx = class to search
  260. //
  261. // On exit: IMP in eax, eq/ne set for forwarding
  262. //
  263. /////////////////////////////////////////////////////////////////////
  264. .macro MethodTableLookup
  265. pushl %ebp
  266. movl %esp, %ebp
  267. subl $$(8+5*16), %esp
  268. .if $0 == NORMAL
  269. movl self+4(%ebp), %eax
  270. movl selector+4(%ebp), %ecx
  271. .else
  272. movl self_stret+4(%ebp), %eax
  273. movl selector_stret+4(%ebp), %ecx
  274. .endif
  275. movdqa %xmm3, 4*16(%esp)
  276. movdqa %xmm2, 3*16(%esp)
  277. movdqa %xmm1, 2*16(%esp)
  278. movdqa %xmm0, 1*16(%esp)
  279. movl %edx, 8(%esp) // class
  280. movl %ecx, 4(%esp) // selector
  281. movl %eax, 0(%esp) // receiver
  282. call __class_lookupMethodAndLoadCache3
  283. // imp in eax
  284. movdqa 4*16(%esp), %xmm3
  285. movdqa 3*16(%esp), %xmm2
  286. movdqa 2*16(%esp), %xmm1
  287. movdqa 1*16(%esp), %xmm0
  288. .if $0 == NORMAL
  289. cmp %eax, %eax // set eq for nonstret forwarding
  290. .else
  291. test %eax, %eax // set ne for stret forwarding
  292. .endif
  293. leave
  294. .endmacro
  295. /////////////////////////////////////////////////////////////////////
  296. //
  297. // NilTest return-type
  298. //
  299. // Takes: $0 = NORMAL or FPRET or STRET
  300. // eax = receiver
  301. //
  302. // On exit: Loads non-nil receiver in eax and self(esp) or self_stret(esp),
  303. // or returns zero.
  304. //
  305. // NilTestReturnZero return-type
  306. //
  307. // Takes: $0 = NORMAL or FPRET or STRET
  308. // eax = receiver
  309. //
  310. // On exit: Loads non-nil receiver in eax and self(esp) or self_stret(esp),
  311. // or returns zero.
  312. //
  313. // NilTestReturnIMP return-type
  314. //
  315. // Takes: $0 = NORMAL or FPRET or STRET
  316. // eax = receiver
  317. //
  318. // On exit: Loads non-nil receiver in eax and self(esp) or self_stret(esp),
  319. // or returns an IMP in eax that returns zero.
  320. //
  321. /////////////////////////////////////////////////////////////////////
  322. .macro ZeroReturn
  323. xorl %eax, %eax
  324. xorl %edx, %edx
  325. xorps %xmm0, %xmm0
  326. xorps %xmm1, %xmm1
  327. .endmacro
  328. .macro ZeroReturnFPRET
  329. fldz
  330. .endmacro
  331. .macro ZeroReturnSTRET
  332. // empty
  333. .endmacro
  334. STATIC_ENTRY __objc_msgNil
  335. ZeroReturn
  336. ret
  337. END_ENTRY __objc_msgNil
  338. STATIC_ENTRY __objc_msgNil_fpret
  339. ZeroReturnFPRET
  340. ret
  341. END_ENTRY __objc_msgNil_fpret
  342. STATIC_ENTRY __objc_msgNil_stret
  343. ZeroReturnSTRET
  344. ret $4
  345. END_ENTRY __objc_msgNil_stret
  346. .macro NilTest
  347. testl %eax, %eax
  348. jz LNilTestSlow_f
  349. LNilTestDone:
  350. .endmacro
  351. .macro NilTestReturnZero
  352. .align 3
  353. LNilTestSlow:
  354. .if $0 == NORMAL
  355. ZeroReturn
  356. ret
  357. .elseif $0 == FPRET
  358. ZeroReturnFPRET
  359. ret
  360. .elseif $0 == STRET
  361. ZeroReturnSTRET
  362. ret $$4
  363. .else
  364. .abort oops
  365. .endif
  366. .endmacro
  367. .macro NilTestReturnIMP
  368. .align 3
  369. LNilTestSlow:
  370. call 1f
  371. 1: pop %eax
  372. .if $0 == NORMAL
  373. leal __objc_msgNil-1b(%eax), %eax
  374. .elseif $0 == FPRET
  375. leal __objc_msgNil_fpret-1b(%eax), %eax
  376. .elseif $0 == STRET
  377. leal __objc_msgNil_stret-1b(%eax), %eax
  378. .else
  379. .abort oops
  380. .endif
  381. ret
  382. .endmacro
  383. /********************************************************************
  384. * IMP _cache_getImp(Class cls, SEL sel)
  385. *
  386. * If found, returns method implementation.
  387. * If not found, returns NULL.
  388. ********************************************************************/
  389. STATIC_ENTRY _cache_getImp
  390. // load the class and selector
  391. movl selector(%esp), %ecx
  392. movl self(%esp), %edx
  393. CacheLookup NORMAL, GETIMP // returns IMP on success
  394. LCacheMiss:
  395. // cache miss, return nil
  396. xorl %eax, %eax
  397. ret
  398. END_ENTRY _cache_getImp
  399. /********************************************************************
  400. *
  401. * id objc_msgSend(id self, SEL _cmd, ...);
  402. * IMP objc_msgLookup(id self, SEL _cmd, ...);
  403. *
  404. * objc_msgLookup ABI:
  405. * IMP returned in eax
  406. * Forwarding returned in Z flag
  407. * edx reserved for our use but not used
  408. *
  409. ********************************************************************/
  410. ENTRY _objc_msgSend
  411. UNWIND _objc_msgSend, NoFrame
  412. movl selector(%esp), %ecx
  413. movl self(%esp), %eax
  414. NilTest NORMAL
  415. movl isa(%eax), %edx // class = self->isa
  416. CacheLookup NORMAL, CALL // calls IMP on success
  417. NilTestReturnZero NORMAL
  418. LCacheMiss:
  419. // isa still in edx
  420. jmp __objc_msgSend_uncached
  421. END_ENTRY _objc_msgSend
  422. ENTRY _objc_msgLookup
  423. UNWIND _objc_msgLookup, NoFrame
  424. movl selector(%esp), %ecx
  425. movl self(%esp), %eax
  426. NilTest NORMAL
  427. movl isa(%eax), %edx // class = self->isa
  428. CacheLookup NORMAL, LOOKUP // returns IMP on success
  429. NilTestReturnIMP NORMAL
  430. LCacheMiss:
  431. // isa still in edx
  432. jmp __objc_msgLookup_uncached
  433. END_ENTRY _objc_msgLookup
  434. /********************************************************************
  435. *
  436. * id objc_msgSendSuper(struct objc_super *super, SEL _cmd, ...);
  437. *
  438. ********************************************************************/
  439. ENTRY _objc_msgSendSuper
  440. UNWIND _objc_msgSendSuper, NoFrame
  441. movl selector(%esp), %ecx
  442. movl super(%esp), %eax // struct objc_super
  443. movl class(%eax), %edx // struct objc_super->class
  444. movl receiver(%eax), %eax // struct objc_super->receiver
  445. movl %eax, super(%esp) // replace super arg with receiver
  446. CacheLookup NORMAL, CALL // calls IMP on success
  447. LCacheMiss:
  448. // class still in edx
  449. jmp __objc_msgSend_uncached
  450. END_ENTRY _objc_msgSendSuper
  451. /********************************************************************
  452. *
  453. * id objc_msgSendSuper2(struct objc_super *super, SEL _cmd, ...);
  454. * IMP objc_msgLookupSuper2(struct objc_super *super, SEL _cmd, ...);
  455. *
  456. ********************************************************************/
  457. ENTRY _objc_msgSendSuper2
  458. UNWIND _objc_msgSendSuper2, NoFrame
  459. movl selector(%esp), %ecx
  460. movl super(%esp), %eax // struct objc_super
  461. movl class(%eax), %edx // struct objc_super->class
  462. movl receiver(%eax), %eax // struct objc_super->receiver
  463. movl %eax, super(%esp) // replace super arg with receiver
  464. movl superclass(%edx), %edx // edx = objc_super->class->super_class
  465. CacheLookup NORMAL, CALL // calls IMP on success
  466. LCacheMiss:
  467. // class still in edx
  468. jmp __objc_msgSend_uncached
  469. END_ENTRY _objc_msgSendSuper2
  470. ENTRY _objc_msgLookupSuper2
  471. UNWIND _objc_msgLookupSuper2, NoFrame
  472. movl selector(%esp), %ecx
  473. movl super(%esp), %eax // struct objc_super
  474. movl class(%eax), %edx // struct objc_super->class
  475. movl receiver(%eax), %eax // struct objc_super->receiver
  476. movl %eax, super(%esp) // replace super arg with receiver
  477. movl superclass(%edx), %edx // edx = objc_super->class->super_class
  478. CacheLookup NORMAL, LOOKUP // returns IMP on success
  479. LCacheMiss:
  480. // class still in edx
  481. jmp __objc_msgLookup_uncached
  482. END_ENTRY _objc_msgLookupSuper2
  483. /********************************************************************
  484. *
  485. * double objc_msgSend_fpret(id self, SEL _cmd, ...);
  486. * IMP objc_msgLookup_fpret(id self, SEL _cmd, ...);
  487. *
  488. ********************************************************************/
  489. ENTRY _objc_msgSend_fpret
  490. UNWIND _objc_msgSend_fpret, NoFrame
  491. movl selector(%esp), %ecx
  492. movl self(%esp), %eax
  493. NilTest FPRET
  494. movl isa(%eax), %edx // class = self->isa
  495. CacheLookup FPRET, CALL // calls IMP on success
  496. NilTestReturnZero FPRET
  497. LCacheMiss:
  498. // class still in edx
  499. jmp __objc_msgSend_uncached
  500. END_ENTRY _objc_msgSend_fpret
  501. ENTRY _objc_msgLookup_fpret
  502. UNWIND _objc_msgLookup_fpret, NoFrame
  503. movl selector(%esp), %ecx
  504. movl self(%esp), %eax
  505. NilTest FPRET
  506. movl isa(%eax), %edx // class = self->isa
  507. CacheLookup FPRET, LOOKUP // returns IMP on success
  508. NilTestReturnIMP FPRET
  509. LCacheMiss:
  510. // class still in edx
  511. jmp __objc_msgLookup_uncached
  512. END_ENTRY _objc_msgLookup_fpret
  513. /********************************************************************
  514. *
  515. * void objc_msgSend_stret(void *st_addr, id self, SEL _cmd, ...);
  516. * IMP objc_msgLookup_stret(void *st_addr, id self, SEL _cmd, ...);
  517. *
  518. ********************************************************************/
  519. ENTRY _objc_msgSend_stret
  520. UNWIND _objc_msgSend_stret, NoFrame
  521. movl selector_stret(%esp), %ecx
  522. movl self_stret(%esp), %eax
  523. NilTest STRET
  524. movl isa(%eax), %edx // class = self->isa
  525. CacheLookup STRET, CALL // calls IMP on success
  526. NilTestReturnZero STRET
  527. LCacheMiss:
  528. // class still in edx
  529. jmp __objc_msgSend_stret_uncached
  530. END_ENTRY _objc_msgSend_stret
  531. ENTRY _objc_msgLookup_stret
  532. UNWIND _objc_msgLookup_stret, NoFrame
  533. movl selector_stret(%esp), %ecx
  534. movl self_stret(%esp), %eax
  535. NilTest STRET
  536. movl isa(%eax), %edx // class = self->isa
  537. CacheLookup STRET, LOOKUP // returns IMP on success
  538. NilTestReturnIMP STRET
  539. LCacheMiss:
  540. // class still in edx
  541. jmp __objc_msgLookup_stret_uncached
  542. END_ENTRY _objc_msgLookup_stret
  543. /********************************************************************
  544. *
  545. * void objc_msgSendSuper_stret(void *st_addr, struct objc_super *super, SEL _cmd, ...);
  546. *
  547. ********************************************************************/
  548. ENTRY _objc_msgSendSuper_stret
  549. UNWIND _objc_msgSendSuper_stret, NoFrame
  550. movl selector_stret(%esp), %ecx
  551. movl super_stret(%esp), %eax // struct objc_super
  552. movl class(%eax), %edx // struct objc_super->class
  553. movl receiver(%eax), %eax // struct objc_super->receiver
  554. movl %eax, super_stret(%esp) // replace super arg with receiver
  555. CacheLookup STRET, CALL // calls IMP on success
  556. LCacheMiss:
  557. // class still in edx
  558. jmp __objc_msgSend_stret_uncached
  559. END_ENTRY _objc_msgSendSuper_stret
  560. /********************************************************************
  561. *
  562. * void objc_msgSendSuper2_stret(void *st_addr, struct objc_super *super, SEL _cmd, ...);
  563. * IMP objc_msgLookupSuper2_stret(void *st_addr, struct objc_super *super, SEL _cmd, ...);
  564. *
  565. ********************************************************************/
  566. ENTRY _objc_msgSendSuper2_stret
  567. UNWIND _objc_msgSendSuper2_stret, NoFrame
  568. movl selector_stret(%esp), %ecx
  569. movl super_stret(%esp), %eax // struct objc_super
  570. movl class(%eax), %edx // struct objc_super->class
  571. movl receiver(%eax), %eax // struct objc_super->receiver
  572. movl %eax, super_stret(%esp) // replace super arg with receiver
  573. mov superclass(%edx), %edx // edx = objc_super->class->super_class
  574. CacheLookup STRET, CALL // calls IMP on success
  575. // cache miss: go search the method lists
  576. LCacheMiss:
  577. // class still in edx
  578. jmp __objc_msgSend_stret_uncached
  579. END_ENTRY _objc_msgSendSuper2_stret
  580. ENTRY _objc_msgLookupSuper2_stret
  581. UNWIND _objc_msgLookupSuper2_stret, NoFrame
  582. movl selector_stret(%esp), %ecx
  583. movl super_stret(%esp), %eax // struct objc_super
  584. movl class(%eax), %edx // struct objc_super->class
  585. movl receiver(%eax), %eax // struct objc_super->receiver
  586. movl %eax, super_stret(%esp) // replace super arg with receiver
  587. mov superclass(%edx), %edx // edx = objc_super->class->super_class
  588. CacheLookup STRET, LOOKUP // returns IMP on success
  589. // cache miss: go search the method lists
  590. LCacheMiss:
  591. // class still in edx
  592. jmp __objc_msgLookup_stret_uncached
  593. END_ENTRY _objc_msgLookupSuper2_stret
  594. /********************************************************************
  595. *
  596. * _objc_msgSend_uncached
  597. * _objc_msgSend_stret_uncached
  598. * _objc_msgLookup_uncached
  599. * _objc_msgLookup_stret_uncached
  600. *
  601. * The uncached method lookup.
  602. *
  603. ********************************************************************/
  604. STATIC_ENTRY __objc_msgSend_uncached
  605. UNWIND __objc_msgSend_uncached, FrameWithNoSaves
  606. // THIS IS NOT A CALLABLE C FUNCTION
  607. // Out-of-band edx is the searched class
  608. // edx is already the class to search
  609. MethodTableLookup NORMAL
  610. jmp *%eax // call imp
  611. END_ENTRY __objc_msgSend_uncached
  612. STATIC_ENTRY __objc_msgSend_stret_uncached
  613. UNWIND __objc_msgSend_stret_uncached, FrameWithNoSaves
  614. // THIS IS NOT A CALLABLE C FUNCTION
  615. // Out-of-band edx is the searched class
  616. // edx is already the class to search
  617. MethodTableLookup STRET
  618. jmp *%eax // call imp
  619. END_ENTRY __objc_msgSend_stret_uncached
  620. STATIC_ENTRY __objc_msgLookup_uncached
  621. UNWIND __objc_msgLookup_uncached, FrameWithNoSaves
  622. // THIS IS NOT A CALLABLE C FUNCTION
  623. // Out-of-band edx is the searched class
  624. // edx is already the class to search
  625. MethodTableLookup NORMAL // eax = IMP
  626. ret
  627. END_ENTRY __objc_msgLookup_uncached
  628. STATIC_ENTRY __objc_msgLookup_stret_uncached
  629. UNWIND __objc_msgLookup_stret_uncached, FrameWithNoSaves
  630. // THIS IS NOT A CALLABLE C FUNCTION
  631. // Out-of-band edx is the searched class
  632. // edx is already the class to search
  633. MethodTableLookup STRET // eax = IMP
  634. ret
  635. END_ENTRY __objc_msgLookup_stret_uncached
  636. /********************************************************************
  637. *
  638. * id _objc_msgForward(id self, SEL _cmd,...);
  639. *
  640. * _objc_msgForward and _objc_msgForward_stret are the externally-callable
  641. * functions returned by things like method_getImplementation().
  642. * _objc_msgForward_impcache is the function pointer actually stored in
  643. * method caches.
  644. *
  645. ********************************************************************/
  646. .non_lazy_symbol_pointer
  647. L_forward_handler:
  648. .indirect_symbol __objc_forward_handler
  649. .long 0
  650. L_forward_stret_handler:
  651. .indirect_symbol __objc_forward_stret_handler
  652. .long 0
  653. STATIC_ENTRY __objc_msgForward_impcache
  654. // Method cache version
  655. // THIS IS NOT A CALLABLE C FUNCTION
  656. // Out-of-band condition register is NE for stret, EQ otherwise.
  657. jne __objc_msgForward_stret
  658. jmp __objc_msgForward
  659. END_ENTRY _objc_msgForward_impcache
  660. ENTRY __objc_msgForward
  661. // Non-struct return version
  662. call 1f
  663. 1: popl %edx
  664. movl L_forward_handler-1b(%edx), %edx
  665. jmp *(%edx)
  666. END_ENTRY __objc_msgForward
  667. ENTRY __objc_msgForward_stret
  668. // Struct return version
  669. call 1f
  670. 1: popl %edx
  671. movl L_forward_stret_handler-1b(%edx), %edx
  672. jmp *(%edx)
  673. END_ENTRY __objc_msgForward_stret
  674. ENTRY _objc_msgSend_debug
  675. jmp _objc_msgSend
  676. END_ENTRY _objc_msgSend_debug
  677. ENTRY _objc_msgSendSuper2_debug
  678. jmp _objc_msgSendSuper2
  679. END_ENTRY _objc_msgSendSuper2_debug
  680. ENTRY _objc_msgSend_stret_debug
  681. jmp _objc_msgSend_stret
  682. END_ENTRY _objc_msgSend_stret_debug
  683. ENTRY _objc_msgSendSuper2_stret_debug
  684. jmp _objc_msgSendSuper2_stret
  685. END_ENTRY _objc_msgSendSuper2_stret_debug
  686. ENTRY _objc_msgSend_fpret_debug
  687. jmp _objc_msgSend_fpret
  688. END_ENTRY _objc_msgSend_fpret_debug
  689. ENTRY _objc_msgSend_noarg
  690. jmp _objc_msgSend
  691. END_ENTRY _objc_msgSend_noarg
  692. ENTRY _method_invoke
  693. movl selector(%esp), %ecx
  694. movl method_name(%ecx), %edx
  695. movl method_imp(%ecx), %eax
  696. movl %edx, selector(%esp)
  697. jmp *%eax
  698. END_ENTRY _method_invoke
  699. ENTRY _method_invoke_stret
  700. movl selector_stret(%esp), %ecx
  701. movl method_name(%ecx), %edx
  702. movl method_imp(%ecx), %eax
  703. movl %edx, selector_stret(%esp)
  704. jmp *%eax
  705. END_ENTRY _method_invoke_stret
  706. .section __DATA,__objc_msg_break
  707. .long 0
  708. .long 0
  709. #endif