rttip.inc 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 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 TypeInfo,%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. jz .LDoClassInit
  34. decb %al
  35. jz .LDoObjectInit
  36. decb %al
  37. jz .LDoClassInit
  38. jmp .LExitInitialize
  39. .LDoObjectInit:
  40. .LDoClassInit:
  41. .LDoRecordInit:
  42. incl %ebx
  43. movzbl (%ebx),%eax
  44. // Skip also recordsize.
  45. addl $5,%eax
  46. addl %eax,%ebx
  47. // %ebx points to element count. Set in %edx
  48. movl (%ebx),%edx
  49. addl $4,%ebx
  50. // %ebx points to First element in record
  51. .LMyRecordInitLoop:
  52. decl %edx
  53. jl .LExitInitialize
  54. // %ebx points to typeinfo pointer
  55. // Push type
  56. pushl (%ebx)
  57. addl $4,%ebx
  58. // %ebx points to offset in record.
  59. // Us it to calculate data
  60. movl Data,%eax
  61. addl (%ebx),%eax
  62. addl $4,%ebx
  63. // push data
  64. pushl %eax
  65. call INITIALIZE
  66. jmp .LMyRecordInitLoop
  67. // Array handling
  68. .LDoArrayInit:
  69. // Skip array name !!
  70. incl %ebx
  71. movzbl (%ebx),%eax
  72. incl %eax
  73. addl %eax,%ebx
  74. // %ebx points to size. Put size in ecx
  75. movl (%ebx),%ecx
  76. addl $4, %ebx
  77. // %ebx points to count. Put count in %edx
  78. movl (%ebx),%edx
  79. addl $4, %ebx
  80. // %ebx points to type. Put into ebx.
  81. // Start treating elements.
  82. .LMyArrayInitLoop:
  83. decl %edx
  84. jl .LExitInitialize
  85. // push type
  86. pushl (%ebx)
  87. // calculate data
  88. movl %ecx,%eax
  89. imull %edx,%eax
  90. addl Data,%eax
  91. // push data
  92. pushl %eax
  93. call INITIALIZE
  94. jmp .LMyArrayInitLoop
  95. // AnsiString handling :
  96. .LDoAnsiStringInit:
  97. movl Data, %eax
  98. movl $0,(%eax)
  99. .LExitInitialize:
  100. pop %edx
  101. pop %ecx
  102. pop %ebx
  103. pop %eax
  104. end;
  105. Procedure Finalize (Data,TypeInfo: Pointer);[Public,Alias:'FPC_FINALIZE'];assembler;
  106. asm
  107. push %eax
  108. push %ebx
  109. push %ecx
  110. push %edx
  111. // decide what type it is
  112. movl TypeInfo,%ebx
  113. movb (%ebx),%al
  114. subb $9,%al
  115. jz .LDoAnsiStringFinal
  116. decb %al
  117. jz .LDoAnsiStringFinal
  118. subb $3,%al
  119. jz .LDoArrayFinal
  120. decb %al
  121. jz .LDoRecordFinal
  122. decb %al
  123. jz .LDoClassFinal
  124. decb %al
  125. jz .LDoObjectFinal
  126. decb %al
  127. jz .LDoClassFinal
  128. jmp .LExitFinalize
  129. .LDoClassFinal:
  130. .LDoObjectFinal:
  131. .LDoRecordFinal:
  132. incl %ebx
  133. movzbl (%ebx),%eax
  134. // Skip also recordsize.
  135. addl $5,%eax
  136. addl %eax,%ebx
  137. // %ebx points to element count. Set in %edx
  138. movl (%ebx),%edx
  139. addl $4,%ebx
  140. // %ebx points to First element in record
  141. .LMyRecordFinalLoop:
  142. decl %edx
  143. jl .LExitFinalize
  144. // %ebx points to typeinfo pointer
  145. // Push type
  146. pushl (%ebx)
  147. addl $4,%ebx
  148. // %ebx points to offset.
  149. // Use to calculate data
  150. movl Data,%eax
  151. addl (%ebx),%eax
  152. addl $4,%ebx
  153. // push data
  154. pushl %eax
  155. call FINALIZE
  156. jmp .LMyRecordFinalLoop
  157. // Array handling
  158. .LDoArrayFinal:
  159. // Skip array name !!
  160. incl %ebx
  161. movzbl (%ebx),%eax
  162. incl %eax
  163. addl %eax,%ebx
  164. // %ebx points to size. Put size in ecx
  165. movl (%ebx),%ecx
  166. addl $4, %ebx
  167. // %ebx points to count. Put count in %edx
  168. movl (%ebx),%edx
  169. addl $4, %ebx
  170. // %ebx points to type. Put into ebx.
  171. // Start treating elements.
  172. .LMyArrayFinalLoop:
  173. decl %edx
  174. jl .LExitFinalize
  175. // push type
  176. pushl (%ebx)
  177. // calculate data
  178. movl %ecx,%eax
  179. imull %edx,%eax
  180. addl Data,%eax
  181. // push data
  182. pushl %eax
  183. call FINALIZE
  184. jmp .LMyArrayFinalLoop
  185. // AnsiString handling :
  186. .LDoAnsiStringFinal:
  187. pushl Data
  188. call ANSISTR_DECR_REF
  189. .LExitFinalize:
  190. pop %edx
  191. pop %ecx
  192. pop %ebx
  193. pop %eax
  194. end;
  195. Procedure Addref (Data,TypeInfo : Pointer); [Public,alias : 'FPC_ADDREF'];Assembler;
  196. asm
  197. // Save registers
  198. push %eax
  199. push %ebx
  200. push %ecx
  201. push %edx
  202. // decide what type it is
  203. movl TypeInfo,%ebx
  204. movb (%ebx),%al
  205. subb $9,%al
  206. jz .LDoAnsiStringAddRef
  207. decb %al
  208. jz .LDoAnsiStringAddRef
  209. subb $2,%al
  210. jz .LDoArrayAddRef
  211. decb %al
  212. jz .LDoRecordAddRef
  213. decb %al
  214. jz .LDoClassAddRef
  215. decb %al
  216. jz .LDoObjectAddRef
  217. decb %al
  218. jz .LDoClassAddRef
  219. jmp .LExitAddRef
  220. .LDoClassAddRef:
  221. .LDoObjectAddRef:
  222. .LDoRecordAddRef:
  223. incl %ebx
  224. movzbl (%ebx),%eax
  225. // Skip also recordsize.
  226. addl $5,%eax
  227. addl %eax,%ebx
  228. // %ebx points to element count. Set in %edx
  229. movl (%ebx),%edx
  230. addl $4,%ebx
  231. // %ebx points to First element in record
  232. .LMyRecordAddRefLoop:
  233. decl %edx
  234. jl .LExitAddRef
  235. // Calculate data
  236. movl Data,%eax
  237. addl (%ebx),%eax
  238. addl $4,%ebx
  239. // Push type
  240. pushl (%ebx)
  241. addl $4,%ebx
  242. // push data
  243. pushl %eax
  244. call ADDREF
  245. jmp .LMyRecordAddRefLoop
  246. // Array handling
  247. .LDoArrayAddRef:
  248. // %ebx points to size. Put size in ecx
  249. movl (%ebx),%ecx
  250. addl $4, %ebx
  251. // %ebx points to count. Put count in %edx
  252. movl (%ebx),%edx
  253. addl $4, %ebx
  254. // %ebx points to type. Put into ebx.
  255. // Start treating elements.
  256. .LMyArrayAddRefLoop:
  257. decl %edx
  258. jl .LExitAddRef
  259. // push type
  260. pushl (%ebx)
  261. // calculate data
  262. movl %ecx,%eax
  263. imull %edx,%eax
  264. addl Data,%eax
  265. // push data
  266. pushl %eax
  267. call ADDREF
  268. jmp .LMyArrayAddRefLoop
  269. // AnsiString handling :
  270. .LDoAnsiStringAddRef:
  271. pushl Data
  272. call ANSISTR_INCR_REF
  273. .LExitAddRef:
  274. pop %edx
  275. pop %ecx
  276. pop %ebx
  277. pop %eax
  278. end;
  279. Procedure DecRef (Data,TypeInfo : Pointer); [Public,alias : 'FPC_DECREF'];Assembler;
  280. asm
  281. // Save registers
  282. push %eax
  283. push %ebx
  284. push %ecx
  285. push %edx
  286. // decide what type it is
  287. movl TypeInfo,%ebx
  288. movb (%ebx),%al
  289. subb $9,%al
  290. jz .LDoAnsiStringDecRef
  291. decb %al
  292. jz .LDoAnsiStringDecRef
  293. subb $2,%al
  294. jz .LDoArrayDecRef
  295. decb %al
  296. jz .LDoRecordDecRef
  297. decb %al
  298. jz .LDoClassDecRef
  299. decb %al
  300. jz .LDoObjectDecRef
  301. decb %al
  302. jz .LDoClassDecRef
  303. jmp .LExitDecRef
  304. .LDoClassDecRef:
  305. .LDoObjectDecRef:
  306. .LDoRecordDecRef:
  307. incl %ebx
  308. movzbl (%ebx),%eax
  309. // Skip also recordsize.
  310. addl $5,%eax
  311. addl %eax,%ebx
  312. // %ebx points to element count. Set in %edx
  313. movl (%ebx),%edx
  314. addl $4,%ebx
  315. // %ebx points to First element in record
  316. .LMyRecordDecRefLoop:
  317. decl %edx
  318. jl .LExitDecRef
  319. // Calculate data
  320. movl Data,%eax
  321. addl (%ebx),%eax
  322. addl $4,%ebx
  323. // Push type
  324. pushl (%ebx)
  325. addl $4,%ebx
  326. // push data
  327. pushl %eax
  328. call DECREF
  329. jmp .LMyRecordDecRefLoop
  330. // Array handling
  331. .LDoArrayDecRef:
  332. // %ebx points to size. Put size in ecx
  333. movl (%ebx),%ecx
  334. addl $4, %ebx
  335. // %ebx points to count. Put count in %edx
  336. movl (%ebx),%edx
  337. addl $4, %ebx
  338. // %ebx points to type. Put into ebx.
  339. // Start treating elements.
  340. .LMyArrayDecRefLoop:
  341. decl %edx
  342. jl .LExitDecRef
  343. // push type
  344. pushl (%ebx)
  345. // calculate data
  346. movl %ecx,%eax
  347. imull %edx,%eax
  348. addl Data,%eax
  349. // push data
  350. pushl %eax
  351. call DECREF
  352. jmp .LMyArrayDecRefLoop
  353. // AnsiString handling :
  354. .LDoAnsiStringDecRef:
  355. movl Data,%eax
  356. pushl %eax
  357. call ANSISTR_DECR_REF
  358. .LExitDecRef:
  359. pop %edx
  360. pop %ecx
  361. pop %ebx
  362. pop %eax
  363. end;
  364. {
  365. $Log$
  366. Revision 1.20 2000-02-09 16:59:29 peter
  367. * truncated log
  368. Revision 1.19 2000/01/11 21:11:34 marco
  369. * Direct params to internal assembler
  370. Revision 1.18 2000/01/07 16:41:33 daniel
  371. * copyright 2000
  372. Revision 1.17 1999/07/31 22:27:28 michael
  373. Object finalization data fixed
  374. }