rttip.inc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1998 by Michael Van Canneyt
  5. member of the Free Pascal development team
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. { Run-Time type information routines - processor dependent part }
  13. {$ASMMODE DIRECT}
  14. Procedure Initialize (Data,TypeInfo : pointer);[Public,Alias : 'INITIALIZE'];assembler;
  15. asm
  16. # Save registers
  17. push %eax
  18. push %ebx
  19. push %ecx
  20. push %edx
  21. # decide what type it is
  22. movl 12(%ebp),%ebx
  23. movb (%ebx),%al
  24. subb $10,%al
  25. jz .DoAnsiStringInit
  26. decb %al
  27. jz .DoAnsiStringInit
  28. subb $2,%al
  29. jz .DoArrayInit
  30. decb %al
  31. jz .DoRecordInit
  32. decb %al
  33. decb %al
  34. jz .DoObjectInit
  35. decb %al
  36. jz .DoClassInit
  37. jmp .ExitInitialize
  38. .DoObjectInit:
  39. .DoClassInit:
  40. .DoRecordInit:
  41. incl %ebx
  42. movzbl (%ebx),%eax
  43. # Skip also recordsize.
  44. addl $5,%eax
  45. addl %eax,%ebx
  46. # %ebx points to element count. Set in %edx
  47. movl (%ebx),%edx
  48. addl $4,%ebx
  49. # %ebx points to First element in record
  50. .MyRecordInitLoop:
  51. decl %edx
  52. jl .ExitInitialize
  53. # Calculate data
  54. movl 8(%ebp),%eax
  55. addl (%ebx),%eax
  56. addl $4,%ebx
  57. # Push type
  58. pushl (%ebx)
  59. addl $4,%ebx
  60. # push data
  61. pushl %eax
  62. call INITIALIZE
  63. jmp .MyRecordInitLoop
  64. # Array handling
  65. .DoArrayInit:
  66. # %ebx points to size. Put size in ecx
  67. movl (%ebx),%ecx
  68. addl $4, %ebx
  69. # %ebx points to count. Put count in %edx
  70. movl (%ebx),%edx
  71. addl $4, %ebx
  72. # %ebx points to type. Put into ebx.
  73. # Start treating elements.
  74. .MyArrayInitLoop:
  75. decl %edx
  76. jl .ExitInitialize
  77. # push type
  78. pushl (%ebx)
  79. # calculate data
  80. movl %ecx,%eax
  81. imull %edx,%eax
  82. addl 8(%ebp),%eax
  83. # push data
  84. pushl %eax
  85. call INITIALIZE
  86. jmp .MyArrayInitLoop
  87. # AnsiString handling :
  88. .DoAnsiStringInit:
  89. movl $0,8(%ebp)
  90. .ExitInitialize:
  91. pop %edx
  92. pop %ecx
  93. pop %ebx
  94. pop %eax
  95. end;
  96. Procedure Finalize (Data,TypeInfo: Pointer);[Public,Alias : 'FINALIZE']; assembler;
  97. asm
  98. push %eax
  99. push %ebx
  100. push %ecx
  101. push %edx
  102. # decide what type it is
  103. movl 12(%ebp),%ebx
  104. movb (%ebx),%al
  105. subb $10,%al
  106. jz .DoAnsiStringFinal
  107. decb %al
  108. jz .DoAnsiStringFinal
  109. subb $2,%al
  110. jz .DoArrayFinal
  111. decb %al
  112. jz .DoRecordFinal
  113. decb %al
  114. decb %al
  115. jz .DoObjectFinal
  116. decb %al
  117. jz .DoClassFinal
  118. jmp .ExitFinalize
  119. .DoClassFinal:
  120. .DoObjectFinal:
  121. .DoRecordFinal:
  122. incl %ebx
  123. movzbl (%ebx),%eax
  124. # Skip also recordsize.
  125. addl $5,%eax
  126. addl %eax,%ebx
  127. # %ebx points to element count. Set in %edx
  128. movl (%ebx),%edx
  129. addl $4,%ebx
  130. # %ebx points to First element in record
  131. .MyRecordFinalLoop:
  132. decl %edx
  133. jl .ExitFinalize
  134. # Calculate data
  135. movl 8(%ebp),%eax
  136. addl (%ebx),%eax
  137. addl $4,%ebx
  138. # Push type
  139. pushl (%ebx)
  140. addl $4,%ebx
  141. # push data
  142. pushl %eax
  143. call FINALIZE
  144. jmp .MyRecordFinalLoop
  145. # Array handling
  146. .DoArrayFinal:
  147. # %ebx points to size. Put size in ecx
  148. movl (%ebx),%ecx
  149. addl $4, %ebx
  150. # %ebx points to count. Put count in %edx
  151. movl (%ebx),%edx
  152. addl $4, %ebx
  153. # %ebx points to type. Put into ebx.
  154. # Start treating elements.
  155. .MyArrayFinalLoop:
  156. decl %edx
  157. jl .ExitFinalize
  158. # push type
  159. pushl (%ebx)
  160. # calculate data
  161. movl %ecx,%eax
  162. imull %edx,%eax
  163. addl 8(%ebp),%eax
  164. # push data
  165. pushl %eax
  166. call FINALIZE
  167. jmp .MyArrayFinalLoop
  168. # AnsiString handling :
  169. .DoAnsiStringFinal:
  170. movl 8(%ebp),%eax
  171. pushl %eax
  172. call DECR_ANSI_REF
  173. .ExitFinalize:
  174. pop %edx
  175. pop %ecx
  176. pop %ebx
  177. pop %eax
  178. end;
  179. Procedure Addref (Data,TypeInfo : Pointer); [Public,alias : 'ADDREF'];Assembler;
  180. asm
  181. # Save registers
  182. push %eax
  183. push %ebx
  184. push %ecx
  185. push %edx
  186. # decide what type it is
  187. movl 12(%ebp),%ebx
  188. movb (%ebx),%al
  189. subb $10,%al
  190. jz .DoAnsiStringAddRef
  191. decb %al
  192. jz .DoAnsiStringAddRef
  193. subb $2,%al
  194. jz .DoArrayAddRef
  195. decb %al
  196. jz .DoRecordAddRef
  197. decb %al
  198. decb %al
  199. jz .DoObjectAddRef
  200. decb %al
  201. jz .DoClassAddRef
  202. jmp .ExitAddRef
  203. .DoClassAddRef:
  204. .DoObjectAddRef:
  205. .DoRecordAddRef:
  206. incl %ebx
  207. movzbl (%ebx),%eax
  208. # Skip also recordsize.
  209. addl $5,%eax
  210. addl %eax,%ebx
  211. # %ebx points to element count. Set in %edx
  212. movl (%ebx),%edx
  213. addl $4,%ebx
  214. # %ebx points to First element in record
  215. .MyRecordAddRefLoop:
  216. decl %edx
  217. jl .ExitAddRef
  218. # Calculate data
  219. movl 8(%ebp),%eax
  220. addl (%ebx),%eax
  221. addl $4,%ebx
  222. # Push type
  223. pushl (%ebx)
  224. addl $4,%ebx
  225. # push data
  226. pushl %eax
  227. call ADDREF
  228. jmp .MyRecordAddRefLoop
  229. # Array handling
  230. .DoArrayAddRef:
  231. # %ebx points to size. Put size in ecx
  232. movl (%ebx),%ecx
  233. addl $4, %ebx
  234. # %ebx points to count. Put count in %edx
  235. movl (%ebx),%edx
  236. addl $4, %ebx
  237. # %ebx points to type. Put into ebx.
  238. # Start treating elements.
  239. .MyArrayAddRefLoop:
  240. decl %edx
  241. jl .ExitAddRef
  242. # push type
  243. pushl (%ebx)
  244. # calculate data
  245. movl %ecx,%eax
  246. imull %edx,%eax
  247. addl 8(%ebp),%eax
  248. # push data
  249. pushl %eax
  250. call ADDREF
  251. jmp .MyArrayAddRefLoop
  252. # AnsiString handling :
  253. .DoAnsiStringAddRef:
  254. movl 8(%ebp),%eax
  255. pushl %eax
  256. call INCR_ANSI_REF
  257. .ExitAddRef:
  258. pop %edx
  259. pop %ecx
  260. pop %ebx
  261. pop %eax
  262. end;
  263. Procedure DecRef (Data,TypeInfo : Pointer); [Public,alias : 'DECREF'];Assembler;
  264. asm
  265. # Save registers
  266. push %eax
  267. push %ebx
  268. push %ecx
  269. push %edx
  270. # decide what type it is
  271. movl 12(%ebp),%ebx
  272. movb (%ebx),%al
  273. subb $10,%al
  274. jz .DoAnsiStringDecRef
  275. decb %al
  276. jz .DoAnsiStringDecRef
  277. subb $2,%al
  278. jz .DoArrayDecRef
  279. decb %al
  280. jz .DoRecordDecRef
  281. decb %al
  282. decb %al
  283. jz .DoObjectDecRef
  284. decb %al
  285. jz .DoClassDecRef
  286. jmp .ExitDecRef
  287. .DoClassDecRef:
  288. .DoObjectDecRef:
  289. .DoRecordDecRef:
  290. incl %ebx
  291. movzbl (%ebx),%eax
  292. # Skip also recordsize.
  293. addl $5,%eax
  294. addl %eax,%ebx
  295. # %ebx points to element count. Set in %edx
  296. movl (%ebx),%edx
  297. addl $4,%ebx
  298. # %ebx points to First element in record
  299. .MyRecordDecRefLoop:
  300. decl %edx
  301. jl .ExitDecRef
  302. # Calculate data
  303. movl 8(%ebp),%eax
  304. addl (%ebx),%eax
  305. addl $4,%ebx
  306. # Push type
  307. pushl (%ebx)
  308. addl $4,%ebx
  309. # push data
  310. pushl %eax
  311. call DECREF
  312. jmp .MyRecordDecRefLoop
  313. # Array handling
  314. .DoArrayDecRef:
  315. # %ebx points to size. Put size in ecx
  316. movl (%ebx),%ecx
  317. addl $4, %ebx
  318. # %ebx points to count. Put count in %edx
  319. movl (%ebx),%edx
  320. addl $4, %ebx
  321. # %ebx points to type. Put into ebx.
  322. # Start treating elements.
  323. .MyArrayDecRefLoop:
  324. decl %edx
  325. jl .ExitDecRef
  326. # push type
  327. pushl (%ebx)
  328. # calculate data
  329. movl %ecx,%eax
  330. imull %edx,%eax
  331. addl 8(%ebp),%eax
  332. # push data
  333. pushl %eax
  334. call DECREF
  335. jmp .MyArrayDecRefLoop
  336. # AnsiString handling :
  337. .DoAnsiStringDecRef:
  338. movl 8(%ebp),%eax
  339. pushl %eax
  340. call DECR_ANSI_REF
  341. .ExitDecRef:
  342. pop %edx
  343. pop %ecx
  344. pop %ebx
  345. pop %eax
  346. end;
  347. {$ASMMODE DEFAULT}
  348. {
  349. $Log$
  350. Revision 1.6 1998-08-23 20:58:50 florian
  351. + rtti for objects and classes
  352. + TObject.GetClassName implemented
  353. Revision 1.5 1998/06/25 08:41:43 florian
  354. * better rtti
  355. Revision 1.4 1998/06/17 11:50:43 michael
  356. + Small patch: forgot to make alias public
  357. Revision 1.3 1998/06/10 07:46:49 michael
  358. + Forgot to commit some changes
  359. Revision 1.2 1998/06/08 19:31:03 michael
  360. + Implemented DecRef
  361. Revision 1.1 1998/06/08 15:32:12 michael
  362. + Split rtti according to processor. Implemented optimized i386 code.
  363. }