rttip.inc 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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 $2,%al
  29. jz .LDoArrayInit
  30. decb %al
  31. jz .LDoRecordInit
  32. subb $2,%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 $2,%al
  119. jz .LDoArrayFinal
  120. decb %al
  121. jz .LDoRecordFinal
  122. subb $2,%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. subb $2,%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. // Push type
  236. pushl (%ebx)
  237. addl $4,%ebx
  238. // Calculate data
  239. movl Data,%eax
  240. addl (%ebx),%eax
  241. addl $4,%ebx
  242. // push data
  243. pushl %eax
  244. call ADDREF
  245. jmp .LMyRecordAddRefLoop
  246. // Array handling
  247. .LDoArrayAddRef:
  248. // Skip array name !!
  249. incl %ebx
  250. movzbl (%ebx),%eax
  251. incl %eax
  252. addl %eax,%ebx
  253. // %ebx points to size. Put size in ecx
  254. movl (%ebx),%ecx
  255. addl $4, %ebx
  256. // %ebx points to count. Put count in %edx
  257. movl (%ebx),%edx
  258. addl $4, %ebx
  259. // %ebx points to type. Put into ebx.
  260. // Start treating elements.
  261. .LMyArrayAddRefLoop:
  262. decl %edx
  263. jl .LExitAddRef
  264. // push type
  265. pushl (%ebx)
  266. // calculate data
  267. movl %ecx,%eax
  268. imull %edx,%eax
  269. addl Data,%eax
  270. // push data
  271. pushl %eax
  272. call ADDREF
  273. jmp .LMyArrayAddRefLoop
  274. // AnsiString handling :
  275. .LDoAnsiStringAddRef:
  276. pushl Data
  277. call ANSISTR_INCR_REF
  278. .LExitAddRef:
  279. pop %edx
  280. pop %ecx
  281. pop %ebx
  282. pop %eax
  283. end;
  284. Procedure DecRef (Data,TypeInfo : Pointer); [Public,alias : 'FPC_DECREF'];Assembler;
  285. asm
  286. // Save registers
  287. push %eax
  288. push %ebx
  289. push %ecx
  290. push %edx
  291. // decide what type it is
  292. movl TypeInfo,%ebx
  293. movb (%ebx),%al
  294. subb $9,%al
  295. jz .LDoAnsiStringDecRef
  296. decb %al
  297. jz .LDoAnsiStringDecRef
  298. subb $2,%al
  299. jz .LDoArrayDecRef
  300. decb %al
  301. jz .LDoRecordDecRef
  302. subb $2,%al
  303. jz .LDoClassDecRef
  304. decb %al
  305. jz .LDoObjectDecRef
  306. decb %al
  307. jz .LDoClassDecRef
  308. jmp .LExitDecRef
  309. .LDoClassDecRef:
  310. .LDoObjectDecRef:
  311. .LDoRecordDecRef:
  312. incl %ebx
  313. movzbl (%ebx),%eax
  314. // Skip also recordsize.
  315. addl $5,%eax
  316. addl %eax,%ebx
  317. // %ebx points to element count. Set in %edx
  318. movl (%ebx),%edx
  319. addl $4,%ebx
  320. // %ebx points to First element in record
  321. .LMyRecordDecRefLoop:
  322. decl %edx
  323. jl .LExitDecRef
  324. // Push type
  325. pushl (%ebx)
  326. addl $4,%ebx
  327. // Calculate data
  328. movl Data,%eax
  329. addl (%ebx),%eax
  330. addl $4,%ebx
  331. // push data
  332. pushl %eax
  333. call DECREF
  334. jmp .LMyRecordDecRefLoop
  335. // Array handling
  336. .LDoArrayDecRef:
  337. // Skip array name !!
  338. incl %ebx
  339. movzbl (%ebx),%eax
  340. incl %eax
  341. addl %eax,%ebx
  342. // %ebx points to size. Put size in ecx
  343. movl (%ebx),%ecx
  344. addl $4, %ebx
  345. // %ebx points to count. Put count in %edx
  346. movl (%ebx),%edx
  347. addl $4, %ebx
  348. // %ebx points to type. Put into ebx.
  349. // Start treating elements.
  350. .LMyArrayDecRefLoop:
  351. decl %edx
  352. jl .LExitDecRef
  353. // push type
  354. pushl (%ebx)
  355. // calculate data
  356. movl %ecx,%eax
  357. imull %edx,%eax
  358. addl Data,%eax
  359. // push data
  360. pushl %eax
  361. call DECREF
  362. jmp .LMyArrayDecRefLoop
  363. // AnsiString handling :
  364. .LDoAnsiStringDecRef:
  365. movl Data,%eax
  366. pushl %eax
  367. call ANSISTR_DECR_REF
  368. .LExitDecRef:
  369. pop %edx
  370. pop %ecx
  371. pop %ebx
  372. pop %eax
  373. end;
  374. {
  375. $Log$
  376. Revision 1.2 2000-07-13 11:33:41 michael
  377. + removed logs
  378. }