rttip.inc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 : 'FPC_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. # %ebx points to typeinfo pointer
  54. # Push type
  55. pushl (%ebx)
  56. addl $4,%ebx
  57. # %ebx points to offset in record.
  58. # Us it to calculate data
  59. movl 8(%ebp),%eax
  60. addl (%ebx),%eax
  61. addl $4,%ebx
  62. # push data
  63. pushl %eax
  64. call FPC_INITIALIZE
  65. jmp .MyRecordInitLoop
  66. # Array handling
  67. .DoArrayInit:
  68. # Skip array name !!
  69. incl %ebx
  70. movzbl (%ebx),%eax
  71. incl %eax
  72. addl %eax,%ebx
  73. # %ebx points to size. Put size in ecx
  74. movl (%ebx),%ecx
  75. addl $4, %ebx
  76. # %ebx points to count. Put count in %edx
  77. movl (%ebx),%edx
  78. addl $4, %ebx
  79. # %ebx points to type. Put into ebx.
  80. # Start treating elements.
  81. .MyArrayInitLoop:
  82. decl %edx
  83. jl .ExitInitialize
  84. # push type
  85. pushl (%ebx)
  86. # calculate data
  87. movl %ecx,%eax
  88. imull %edx,%eax
  89. addl 8(%ebp),%eax
  90. # push data
  91. pushl %eax
  92. call FPC_INITIALIZE
  93. jmp .MyArrayInitLoop
  94. # AnsiString handling :
  95. .DoAnsiStringInit:
  96. movl 8(%ebp), %eax
  97. movl $0,(%eax)
  98. .ExitInitialize:
  99. pop %edx
  100. pop %ecx
  101. pop %ebx
  102. pop %eax
  103. end;
  104. Procedure Finalize (Data,TypeInfo: Pointer);[Public,Alias : 'FPC_FINALIZE']; assembler;
  105. asm
  106. push %eax
  107. push %ebx
  108. push %ecx
  109. push %edx
  110. # decide what type it is
  111. movl 12(%ebp),%ebx
  112. movb (%ebx),%al
  113. subb $10,%al
  114. jz .DoAnsiStringFinal
  115. decb %al
  116. jz .DoAnsiStringFinal
  117. subb $2,%al
  118. jz .DoArrayFinal
  119. decb %al
  120. jz .DoRecordFinal
  121. decb %al
  122. decb %al
  123. jz .DoObjectFinal
  124. decb %al
  125. jz .DoClassFinal
  126. jmp .ExitFinalize
  127. .DoClassFinal:
  128. .DoObjectFinal:
  129. .DoRecordFinal:
  130. incl %ebx
  131. movzbl (%ebx),%eax
  132. # Skip also recordsize.
  133. addl $5,%eax
  134. addl %eax,%ebx
  135. # %ebx points to element count. Set in %edx
  136. movl (%ebx),%edx
  137. addl $4,%ebx
  138. # %ebx points to First element in record
  139. .MyRecordFinalLoop:
  140. decl %edx
  141. jl .ExitFinalize
  142. # %ebx points to typeinfo pointer
  143. # Push type
  144. pushl (%ebx)
  145. addl $4,%ebx
  146. # %ebx points to offset.
  147. # Use to calculate data
  148. movl 8(%ebp),%eax
  149. addl (%ebx),%eax
  150. addl $4,%ebx
  151. # push data
  152. pushl %eax
  153. call FPC_FINALIZE
  154. jmp .MyRecordFinalLoop
  155. # Array handling
  156. .DoArrayFinal:
  157. # Skip array name !!
  158. incl %ebx
  159. movzbl (%ebx),%eax
  160. incl %eax
  161. addl %eax,%ebx
  162. # %ebx points to size. Put size in ecx
  163. movl (%ebx),%ecx
  164. addl $4, %ebx
  165. # %ebx points to count. Put count in %edx
  166. movl (%ebx),%edx
  167. addl $4, %ebx
  168. # %ebx points to type. Put into ebx.
  169. # Start treating elements.
  170. .MyArrayFinalLoop:
  171. decl %edx
  172. jl .ExitFinalize
  173. # push type
  174. pushl (%ebx)
  175. # calculate data
  176. movl %ecx,%eax
  177. imull %edx,%eax
  178. addl 8(%ebp),%eax
  179. # push data
  180. pushl %eax
  181. call FPC_FINALIZE
  182. jmp .MyArrayFinalLoop
  183. # AnsiString handling :
  184. .DoAnsiStringFinal:
  185. pushl 8(%ebp)
  186. call FPC_DECR_ANSI_REF
  187. .ExitFinalize:
  188. pop %edx
  189. pop %ecx
  190. pop %ebx
  191. pop %eax
  192. end;
  193. Procedure Addref (Data,TypeInfo : Pointer); [Public,alias : 'FPC_ADDREF'];Assembler;
  194. asm
  195. # Save registers
  196. push %eax
  197. push %ebx
  198. push %ecx
  199. push %edx
  200. # decide what type it is
  201. movl 12(%ebp),%ebx
  202. movb (%ebx),%al
  203. subb $10,%al
  204. jz .DoAnsiStringAddRef
  205. decb %al
  206. jz .DoAnsiStringAddRef
  207. subb $2,%al
  208. jz .DoArrayAddRef
  209. decb %al
  210. jz .DoRecordAddRef
  211. decb %al
  212. decb %al
  213. jz .DoObjectAddRef
  214. decb %al
  215. jz .DoClassAddRef
  216. jmp .ExitAddRef
  217. .DoClassAddRef:
  218. .DoObjectAddRef:
  219. .DoRecordAddRef:
  220. incl %ebx
  221. movzbl (%ebx),%eax
  222. # Skip also recordsize.
  223. addl $5,%eax
  224. addl %eax,%ebx
  225. # %ebx points to element count. Set in %edx
  226. movl (%ebx),%edx
  227. addl $4,%ebx
  228. # %ebx points to First element in record
  229. .MyRecordAddRefLoop:
  230. decl %edx
  231. jl .ExitAddRef
  232. # Calculate data
  233. movl 8(%ebp),%eax
  234. addl (%ebx),%eax
  235. addl $4,%ebx
  236. # Push type
  237. pushl (%ebx)
  238. addl $4,%ebx
  239. # push data
  240. pushl %eax
  241. call FPC_ADDREF
  242. jmp .MyRecordAddRefLoop
  243. # Array handling
  244. .DoArrayAddRef:
  245. # %ebx points to size. Put size in ecx
  246. movl (%ebx),%ecx
  247. addl $4, %ebx
  248. # %ebx points to count. Put count in %edx
  249. movl (%ebx),%edx
  250. addl $4, %ebx
  251. # %ebx points to type. Put into ebx.
  252. # Start treating elements.
  253. .MyArrayAddRefLoop:
  254. decl %edx
  255. jl .ExitAddRef
  256. # push type
  257. pushl (%ebx)
  258. # calculate data
  259. movl %ecx,%eax
  260. imull %edx,%eax
  261. addl 8(%ebp),%eax
  262. # push data
  263. pushl %eax
  264. call FPC_ADDREF
  265. jmp .MyArrayAddRefLoop
  266. # AnsiString handling :
  267. .DoAnsiStringAddRef:
  268. pushl 8(%ebp)
  269. call FPC_INCR_ANSI_REF
  270. .ExitAddRef:
  271. pop %edx
  272. pop %ecx
  273. pop %ebx
  274. pop %eax
  275. end;
  276. Procedure DecRef (Data,TypeInfo : Pointer); [Public,alias : 'FPC_DECREF'];Assembler;
  277. asm
  278. # Save registers
  279. push %eax
  280. push %ebx
  281. push %ecx
  282. push %edx
  283. # decide what type it is
  284. movl 12(%ebp),%ebx
  285. movb (%ebx),%al
  286. subb $10,%al
  287. jz .DoAnsiStringDecRef
  288. decb %al
  289. jz .DoAnsiStringDecRef
  290. subb $2,%al
  291. jz .DoArrayDecRef
  292. decb %al
  293. jz .DoRecordDecRef
  294. decb %al
  295. decb %al
  296. jz .DoObjectDecRef
  297. decb %al
  298. jz .DoClassDecRef
  299. jmp .ExitDecRef
  300. .DoClassDecRef:
  301. .DoObjectDecRef:
  302. .DoRecordDecRef:
  303. incl %ebx
  304. movzbl (%ebx),%eax
  305. # Skip also recordsize.
  306. addl $5,%eax
  307. addl %eax,%ebx
  308. # %ebx points to element count. Set in %edx
  309. movl (%ebx),%edx
  310. addl $4,%ebx
  311. # %ebx points to First element in record
  312. .MyRecordDecRefLoop:
  313. decl %edx
  314. jl .ExitDecRef
  315. # Calculate data
  316. movl 8(%ebp),%eax
  317. addl (%ebx),%eax
  318. addl $4,%ebx
  319. # Push type
  320. pushl (%ebx)
  321. addl $4,%ebx
  322. # push data
  323. pushl %eax
  324. call FPC_DECREF
  325. jmp .MyRecordDecRefLoop
  326. # Array handling
  327. .DoArrayDecRef:
  328. # %ebx points to size. Put size in ecx
  329. movl (%ebx),%ecx
  330. addl $4, %ebx
  331. # %ebx points to count. Put count in %edx
  332. movl (%ebx),%edx
  333. addl $4, %ebx
  334. # %ebx points to type. Put into ebx.
  335. # Start treating elements.
  336. .MyArrayDecRefLoop:
  337. decl %edx
  338. jl .ExitDecRef
  339. # push type
  340. pushl (%ebx)
  341. # calculate data
  342. movl %ecx,%eax
  343. imull %edx,%eax
  344. addl 8(%ebp),%eax
  345. # push data
  346. pushl %eax
  347. call FPC_DECREF
  348. jmp .MyArrayDecRefLoop
  349. # AnsiString handling :
  350. .DoAnsiStringDecRef:
  351. movl 8(%ebp),%eax
  352. pushl %eax
  353. call FPC_DECR_ANSI_REF
  354. .ExitDecRef:
  355. pop %edx
  356. pop %ecx
  357. pop %ebx
  358. pop %eax
  359. end;
  360. {$ASMMODE DEFAULT}
  361. {
  362. $Log$
  363. Revision 1.9 1998-09-29 08:38:25 michael
  364. + Corrections in record and array handling.
  365. Revision 1.8 1998/09/20 17:49:07 florian
  366. * some ansistring fixes
  367. Revision 1.7 1998/09/14 10:48:11 peter
  368. * FPC_ names
  369. * Heap manager is now system independent
  370. Revision 1.6 1998/08/23 20:58:50 florian
  371. + rtti for objects and classes
  372. + TObject.GetClassName implemented
  373. Revision 1.5 1998/06/25 08:41:43 florian
  374. * better rtti
  375. Revision 1.4 1998/06/17 11:50:43 michael
  376. + Small patch: forgot to make alias public
  377. Revision 1.3 1998/06/10 07:46:49 michael
  378. + Forgot to commit some changes
  379. Revision 1.2 1998/06/08 19:31:03 michael
  380. + Implemented DecRef
  381. Revision 1.1 1998/06/08 15:32:12 michael
  382. + Split rtti according to processor. Implemented optimized i386 code.
  383. }