rttip.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. Procedure Initialize (Data,TypeInfo : pointer);[Public,Alias:'FPC_INITIALIZE'];assembler;
  14. asm
  15. // Save registers
  16. push %eax
  17. push %ebx
  18. push %ecx
  19. push %edx
  20. // decide what type it is
  21. movl 12(%ebp),%ebx
  22. movb (%ebx),%al
  23. // This is MANIFESTLY wrong
  24. subb $9,%al
  25. jz .LDoAnsiStringInit
  26. decb %al
  27. jz .LDoAnsiStringInit
  28. subb $3,%al
  29. jz .LDoArrayInit
  30. decb %al
  31. jz .LDoRecordInit
  32. decb %al
  33. decb %al
  34. jz .LDoObjectInit
  35. decb %al
  36. jz .LDoClassInit
  37. jmp .LExitInitialize
  38. .LDoObjectInit:
  39. .LDoClassInit:
  40. .LDoRecordInit:
  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. .LMyRecordInitLoop:
  51. decl %edx
  52. jl .LExitInitialize
  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 INITIALIZE
  65. jmp .LMyRecordInitLoop
  66. // Array handling
  67. .LDoArrayInit:
  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. .LMyArrayInitLoop:
  82. decl %edx
  83. jl .LExitInitialize
  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 INITIALIZE
  93. jmp .LMyArrayInitLoop
  94. // AnsiString handling :
  95. .LDoAnsiStringInit:
  96. movl 8(%ebp), %eax
  97. movl $0,(%eax)
  98. .LExitInitialize:
  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 $9,%al
  114. jz .LDoAnsiStringFinal
  115. decb %al
  116. jz .LDoAnsiStringFinal
  117. subb $3,%al
  118. jz .LDoArrayFinal
  119. decb %al
  120. jz .LDoRecordFinal
  121. decb %al
  122. decb %al
  123. jz .LDoObjectFinal
  124. decb %al
  125. jz .LDoClassFinal
  126. jmp .LExitFinalize
  127. .LDoClassFinal:
  128. .LDoObjectFinal:
  129. .LDoRecordFinal:
  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. .LMyRecordFinalLoop:
  140. decl %edx
  141. jl .LExitFinalize
  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 FINALIZE
  154. jmp .LMyRecordFinalLoop
  155. // Array handling
  156. .LDoArrayFinal:
  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. .LMyArrayFinalLoop:
  171. decl %edx
  172. jl .LExitFinalize
  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 FINALIZE
  182. jmp .LMyArrayFinalLoop
  183. // AnsiString handling :
  184. .LDoAnsiStringFinal:
  185. pushl 8(%ebp)
  186. call ANSISTR_DECR_REF
  187. .LExitFinalize:
  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 $9,%al
  204. jz .LDoAnsiStringAddRef
  205. decb %al
  206. jz .LDoAnsiStringAddRef
  207. subb $2,%al
  208. jz .LDoArrayAddRef
  209. decb %al
  210. jz .LDoRecordAddRef
  211. decb %al
  212. decb %al
  213. jz .LDoObjectAddRef
  214. decb %al
  215. jz .LDoClassAddRef
  216. jmp .LExitAddRef
  217. .LDoClassAddRef:
  218. .LDoObjectAddRef:
  219. .LDoRecordAddRef:
  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. .LMyRecordAddRefLoop:
  230. decl %edx
  231. jl .LExitAddRef
  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 ADDREF
  242. jmp .LMyRecordAddRefLoop
  243. // Array handling
  244. .LDoArrayAddRef:
  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. .LMyArrayAddRefLoop:
  254. decl %edx
  255. jl .LExitAddRef
  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 ADDREF
  265. jmp .LMyArrayAddRefLoop
  266. // AnsiString handling :
  267. .LDoAnsiStringAddRef:
  268. pushl 8(%ebp)
  269. call ANSISTR_INCR_REF
  270. .LExitAddRef:
  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 $9,%al
  287. jz .LDoAnsiStringDecRef
  288. decb %al
  289. jz .LDoAnsiStringDecRef
  290. subb $2,%al
  291. jz .LDoArrayDecRef
  292. decb %al
  293. jz .LDoRecordDecRef
  294. decb %al
  295. decb %al
  296. jz .LDoObjectDecRef
  297. decb %al
  298. jz .LDoClassDecRef
  299. jmp .LExitDecRef
  300. .LDoClassDecRef:
  301. .LDoObjectDecRef:
  302. .LDoRecordDecRef:
  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. .LMyRecordDecRefLoop:
  313. decl %edx
  314. jl .LExitDecRef
  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 DECREF
  325. jmp .LMyRecordDecRefLoop
  326. // Array handling
  327. .LDoArrayDecRef:
  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. .LMyArrayDecRefLoop:
  337. decl %edx
  338. jl .LExitDecRef
  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 DECREF
  348. jmp .LMyArrayDecRefLoop
  349. // AnsiString handling :
  350. .LDoAnsiStringDecRef:
  351. movl 8(%ebp),%eax
  352. pushl %eax
  353. call ANSISTR_DECR_REF
  354. .LExitDecRef:
  355. pop %edx
  356. pop %ecx
  357. pop %ebx
  358. pop %eax
  359. end;
  360. {
  361. $Log$
  362. Revision 1.16 1999-03-01 15:40:58 peter
  363. * use external names
  364. * removed all direct assembler modes
  365. Revision 1.15 1998/12/20 14:08:06 michael
  366. + Finalize fixed after florians fix :)
  367. Revision 1.14 1998/12/19 00:22:09 florian
  368. * Finalize fixed, constant for ansistrings is 9, not 10
  369. Revision 1.13 1998/12/15 22:42:59 peter
  370. * removed temp symbols
  371. Revision 1.12 1998/11/30 10:07:34 michael
  372. + Adjusted typeinfo constants
  373. Revision 1.11 1998/11/17 00:41:10 peter
  374. * renamed string functions
  375. Revision 1.10 1998/11/16 12:21:47 peter
  376. * fixes for 0.99.8
  377. Revision 1.9 1998/09/29 08:38:25 michael
  378. + Corrections in record and array handling.
  379. Revision 1.8 1998/09/20 17:49:07 florian
  380. * some ansistring fixes
  381. Revision 1.7 1998/09/14 10:48:11 peter
  382. * FPC_ names
  383. * Heap manager is now system independent
  384. Revision 1.6 1998/08/23 20:58:50 florian
  385. + rtti for objects and classes
  386. + TObject.GetClassName implemented
  387. Revision 1.5 1998/06/25 08:41:43 florian
  388. * better rtti
  389. Revision 1.4 1998/06/17 11:50:43 michael
  390. + Small patch: forgot to make alias public
  391. Revision 1.3 1998/06/10 07:46:49 michael
  392. + Forgot to commit some changes
  393. Revision 1.2 1998/06/08 19:31:03 michael
  394. + Implemented DecRef
  395. Revision 1.1 1998/06/08 15:32:12 michael
  396. + Split rtti according to processor. Implemented optimized i386 code.
  397. }