rttip.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. { I think we should use the pascal version, this code isn't }
  14. { much faster }
  15. Procedure Initialize (Data,TypeInfo : pointer);[Public,Alias:'FPC_INITIALIZE'];assembler;
  16. asm
  17. // Save registers
  18. push %eax
  19. push %ebx
  20. push %ecx
  21. push %edx
  22. // decide what type it is
  23. movl TypeInfo,%ebx
  24. movb (%ebx),%al
  25. // This is MANIFESTLY wrong
  26. subb $9,%al
  27. jz .LDoAnsiStringInit
  28. decb %al
  29. jz .LDoAnsiStringInit
  30. decb %al
  31. jz .LDoVariantInit
  32. decb %al
  33. jz .LDoArrayInit
  34. decb %al
  35. jz .LDoRecordInit
  36. decb %al
  37. jz .LDoInterfaceInit
  38. decb %al
  39. jz .LDoClassInit
  40. decb %al
  41. jz .LDoObjectInit
  42. decb %al
  43. // what is called here ??? FK
  44. jz .LDoClassInit
  45. subb $4,%al
  46. jz .LDoDynArrayInit
  47. jmp .LExitInitialize
  48. // Interfaces
  49. .LDoInterfaceInit:
  50. movl Data, %eax
  51. movl $0,(%eax)
  52. jmp .LExitInitialize
  53. // Variants
  54. .LDoVariantInit:
  55. jmp .LExitInitialize
  56. // dynamic Array
  57. .LDoDynArrayInit:
  58. movl Data, %eax
  59. movl $0,(%eax)
  60. jmp .LExitInitialize
  61. .LDoObjectInit:
  62. .LDoClassInit:
  63. .LDoRecordInit:
  64. incl %ebx
  65. movzbl (%ebx),%eax
  66. // Skip also recordsize.
  67. addl $5,%eax
  68. addl %eax,%ebx
  69. // %ebx points to element count. Set in %edx
  70. movl (%ebx),%edx
  71. addl $4,%ebx
  72. // %ebx points to First element in record
  73. .LMyRecordInitLoop:
  74. decl %edx
  75. jl .LExitInitialize
  76. // %ebx points to typeinfo pointer
  77. // Push type
  78. pushl (%ebx)
  79. addl $4,%ebx
  80. // %ebx points to offset in record.
  81. // Us it to calculate data
  82. movl Data,%eax
  83. addl (%ebx),%eax
  84. addl $4,%ebx
  85. // push data
  86. pushl %eax
  87. call Initialize
  88. jmp .LMyRecordInitLoop
  89. // Array handling
  90. .LDoArrayInit:
  91. // Skip array name !!
  92. incl %ebx
  93. movzbl (%ebx),%eax
  94. incl %eax
  95. addl %eax,%ebx
  96. // %ebx points to size. Put size in ecx
  97. movl (%ebx),%ecx
  98. addl $4, %ebx
  99. // %ebx points to count. Put count in %edx
  100. movl (%ebx),%edx
  101. addl $4, %ebx
  102. // %ebx points to type. Put into ebx.
  103. // Start treating elements.
  104. .LMyArrayInitLoop:
  105. decl %edx
  106. jl .LExitInitialize
  107. // push type
  108. pushl (%ebx)
  109. // calculate data
  110. movl %ecx,%eax
  111. imull %edx,%eax
  112. addl Data,%eax
  113. // push data
  114. pushl %eax
  115. call Initialize
  116. jmp .LMyArrayInitLoop
  117. // AnsiString handling :
  118. .LDoAnsiStringInit:
  119. movl Data, %eax
  120. movl $0,(%eax)
  121. .LExitInitialize:
  122. pop %edx
  123. pop %ecx
  124. pop %ebx
  125. pop %eax
  126. end;
  127. Procedure int_finalize (Data,TypeInfo: Pointer);[Public,Alias:'FPC_FINALIZE'];assembler;
  128. asm
  129. push %eax
  130. push %ebx
  131. push %ecx
  132. push %edx
  133. // decide what type it is
  134. movl TypeInfo,%ebx
  135. movb (%ebx),%al
  136. subb $9,%al
  137. jz .LDoAnsiStringFinal
  138. decb %al
  139. jz .LDoAnsiStringFinal
  140. decb %al
  141. jz .LDoVariantFinal
  142. decb %al
  143. jz .LDoArrayFinal
  144. decb %al
  145. jz .LDoRecordFinal
  146. decb %al
  147. jz .LDoInterfaceFinal
  148. decb %al
  149. jz .LDoClassFinal
  150. decb %al
  151. jz .LDoObjectFinal
  152. decb %al
  153. // what is called here ??? FK
  154. jz .LDoClassFinal
  155. subb $4,%al
  156. jz .LDoDynArrayFinal
  157. jmp .LExitFinalize
  158. // Interfaces
  159. .LDoInterfaceFinal:
  160. pushl Data
  161. call Int_Intf_Decr_Ref
  162. jmp .LExitFinalize
  163. // Variants
  164. .LDoVariantFinal:
  165. jmp .LExitFinalize
  166. // dynamic Array
  167. .LDoDynArrayFinal:
  168. pushl TypeInfo
  169. pushl Data
  170. call DYNARRAY_DECR_REF
  171. jmp .LExitFinalize
  172. .LDoClassFinal:
  173. .LDoObjectFinal:
  174. .LDoRecordFinal:
  175. incl %ebx
  176. movzbl (%ebx),%eax
  177. // Skip also recordsize.
  178. addl $5,%eax
  179. addl %eax,%ebx
  180. // %ebx points to element count. Set in %edx
  181. movl (%ebx),%edx
  182. addl $4,%ebx
  183. // %ebx points to First element in record
  184. .LMyRecordFinalLoop:
  185. decl %edx
  186. jl .LExitFinalize
  187. // %ebx points to typeinfo pointer
  188. // Push type
  189. pushl (%ebx)
  190. addl $4,%ebx
  191. // %ebx points to offset.
  192. // Use to calculate data
  193. movl Data,%eax
  194. addl (%ebx),%eax
  195. addl $4,%ebx
  196. // push data
  197. pushl %eax
  198. call INT_FINALIZE
  199. jmp .LMyRecordFinalLoop
  200. // Array handling
  201. .LDoArrayFinal:
  202. // Skip array name !!
  203. incl %ebx
  204. movzbl (%ebx),%eax
  205. incl %eax
  206. addl %eax,%ebx
  207. // %ebx points to size. Put size in ecx
  208. movl (%ebx),%ecx
  209. addl $4, %ebx
  210. // %ebx points to count. Put count in %edx
  211. movl (%ebx),%edx
  212. addl $4, %ebx
  213. // %ebx points to type. Put into ebx.
  214. // Start treating elements.
  215. .LMyArrayFinalLoop:
  216. decl %edx
  217. jl .LExitFinalize
  218. // push type
  219. pushl (%ebx)
  220. // calculate data
  221. movl %ecx,%eax
  222. imull %edx,%eax
  223. addl Data,%eax
  224. // push data
  225. pushl %eax
  226. call INT_FINALIZE
  227. jmp .LMyArrayFinalLoop
  228. // AnsiString handling :
  229. .LDoAnsiStringFinal:
  230. pushl Data
  231. call ANSISTR_DECR_REF
  232. .LExitFinalize:
  233. pop %edx
  234. pop %ecx
  235. pop %ebx
  236. pop %eax
  237. end;
  238. Procedure Addref (Data,TypeInfo : Pointer); [Public,alias : 'FPC_ADDREF'];Assembler;
  239. asm
  240. // Save registers
  241. push %eax
  242. push %ebx
  243. push %ecx
  244. push %edx
  245. // decide what type it is
  246. movl TypeInfo,%ebx
  247. movb (%ebx),%al
  248. subb $9,%al
  249. jz .LDoAnsiStringAddRef
  250. decb %al
  251. jz .LDoAnsiStringAddRef
  252. decb %al
  253. jz .LDoVariantAddRef
  254. decb %al
  255. jz .LDoArrayAddRef
  256. decb %al
  257. jz .LDoRecordAddRef
  258. decb %al
  259. jz .LDoInterfaceAddRef
  260. decb %al
  261. jz .LDoClassAddRef
  262. decb %al
  263. jz .LDoObjectAddRef
  264. decb %al
  265. // what is called here ??? FK
  266. jz .LDoClassAddRef
  267. subb $4,%al
  268. jz .LDoDynArrayAddRef
  269. jmp .LExitAddRef
  270. // Interfaces
  271. .LDoInterfaceAddRef:
  272. pushl Data
  273. call INT_INTF_INCR_REF
  274. jmp .LExitAddRef
  275. // Variants
  276. .LDoVariantAddRef:
  277. jmp .LExitAddRef
  278. // Dynamic Arrays
  279. .LDoDynArrayAddRef:
  280. movl Data,%eax
  281. orl %eax,%eax
  282. jz .LExitAddRef
  283. lock
  284. incl -8(%eax)
  285. jmp .LExitAddRef
  286. .LDoClassAddRef:
  287. .LDoObjectAddRef:
  288. .LDoRecordAddRef:
  289. incl %ebx
  290. movzbl (%ebx),%eax
  291. // Skip also recordsize.
  292. addl $5,%eax
  293. addl %eax,%ebx
  294. // %ebx points to element count. Set in %edx
  295. movl (%ebx),%edx
  296. addl $4,%ebx
  297. // %ebx points to First element in record
  298. .LMyRecordAddRefLoop:
  299. decl %edx
  300. jl .LExitAddRef
  301. // Push type
  302. pushl (%ebx)
  303. addl $4,%ebx
  304. // Calculate data
  305. movl Data,%eax
  306. addl (%ebx),%eax
  307. addl $4,%ebx
  308. // push data
  309. pushl %eax
  310. call ADDREF
  311. jmp .LMyRecordAddRefLoop
  312. // Array handling
  313. .LDoArrayAddRef:
  314. // Skip array name !!
  315. incl %ebx
  316. movzbl (%ebx),%eax
  317. incl %eax
  318. addl %eax,%ebx
  319. // %ebx points to size. Put size in ecx
  320. movl (%ebx),%ecx
  321. addl $4, %ebx
  322. // %ebx points to count. Put count in %edx
  323. movl (%ebx),%edx
  324. addl $4, %ebx
  325. // %ebx points to type. Put into ebx.
  326. // Start treating elements.
  327. .LMyArrayAddRefLoop:
  328. decl %edx
  329. jl .LExitAddRef
  330. // push type
  331. pushl (%ebx)
  332. // calculate data
  333. movl %ecx,%eax
  334. imull %edx,%eax
  335. addl Data,%eax
  336. // push data
  337. pushl %eax
  338. call ADDREF
  339. jmp .LMyArrayAddRefLoop
  340. // AnsiString handling :
  341. .LDoAnsiStringAddRef:
  342. pushl Data
  343. call ANSISTR_INCR_REF
  344. .LExitAddRef:
  345. pop %edx
  346. pop %ecx
  347. pop %ebx
  348. pop %eax
  349. end;
  350. Procedure DecRef (Data,TypeInfo : Pointer); [Public,alias : 'FPC_DECREF'];Assembler;
  351. asm
  352. // Save registers
  353. push %eax
  354. push %ebx
  355. push %ecx
  356. push %edx
  357. // decide what type it is
  358. movl TypeInfo,%ebx
  359. movb (%ebx),%al
  360. subb $9,%al
  361. jz .LDoAnsiStringDecRef
  362. decb %al
  363. jz .LDoAnsiStringDecRef
  364. decb %al
  365. jz .LDoVariantDecRef
  366. decb %al
  367. jz .LDoArrayDecRef
  368. decb %al
  369. jz .LDoRecordDecRef
  370. decb %al
  371. jz .LDoInterfaceDecRef
  372. decb %al
  373. jz .LDoClassDecRef
  374. decb %al
  375. jz .LDoObjectDecRef
  376. decb %al
  377. // what is called here ??? FK
  378. jz .LDoClassDecRef
  379. subb $4,%al
  380. jz .LDoDynArrayDecRef
  381. jmp .LExitDecRef
  382. // Interfaces
  383. .LDoInterfaceDecRef:
  384. pushl Data
  385. call INT_INTF_DECR_REF
  386. jmp .LExitDecRef
  387. // Variants
  388. .LDoVariantDecRef:
  389. jmp .LExitDecRef
  390. // Dynamic Arrays
  391. .LDoDynArrayDecRef:
  392. pushl TypeInfo
  393. pushl Data
  394. call DYNARRAY_DECR_REF
  395. jmp .LExitDecRef
  396. .LDoClassDecRef:
  397. .LDoObjectDecRef:
  398. .LDoRecordDecRef:
  399. incl %ebx
  400. movzbl (%ebx),%eax
  401. // Skip also recordsize.
  402. addl $5,%eax
  403. addl %eax,%ebx
  404. // %ebx points to element count. Set in %edx
  405. movl (%ebx),%edx
  406. addl $4,%ebx
  407. // %ebx points to First element in record
  408. .LMyRecordDecRefLoop:
  409. decl %edx
  410. jl .LExitDecRef
  411. // Push type
  412. pushl (%ebx)
  413. addl $4,%ebx
  414. // Calculate data
  415. movl Data,%eax
  416. addl (%ebx),%eax
  417. addl $4,%ebx
  418. // push data
  419. pushl %eax
  420. call DECREF
  421. jmp .LMyRecordDecRefLoop
  422. // Array handling
  423. .LDoArrayDecRef:
  424. // Skip array name !!
  425. incl %ebx
  426. movzbl (%ebx),%eax
  427. incl %eax
  428. addl %eax,%ebx
  429. // %ebx points to size. Put size in ecx
  430. movl (%ebx),%ecx
  431. addl $4, %ebx
  432. // %ebx points to count. Put count in %edx
  433. movl (%ebx),%edx
  434. addl $4, %ebx
  435. // %ebx points to type. Put into ebx.
  436. // Start treating elements.
  437. .LMyArrayDecRefLoop:
  438. decl %edx
  439. jl .LExitDecRef
  440. // push type
  441. pushl (%ebx)
  442. // calculate data
  443. movl %ecx,%eax
  444. imull %edx,%eax
  445. addl Data,%eax
  446. // push data
  447. pushl %eax
  448. call DECREF
  449. jmp .LMyArrayDecRefLoop
  450. // AnsiString handling :
  451. .LDoAnsiStringDecRef:
  452. movl Data,%eax
  453. pushl %eax
  454. call ANSISTR_DECR_REF
  455. .LExitDecRef:
  456. pop %edx
  457. pop %ecx
  458. pop %ebx
  459. pop %eax
  460. end;
  461. procedure FinalizeArray(data,typeinfo : pointer;count,size : longint);
  462. [Public,Alias:'FPC_FINALIZEARRAY'];
  463. var
  464. i : longint;
  465. begin
  466. for i:=0 to count-1 do
  467. int_finalize(data+size*i,typeinfo);
  468. end;
  469. {
  470. $Log$
  471. Revision 1.7 2000-11-09 17:49:34 florian
  472. + FPC_FINALIZEARRAY
  473. * Finalize to int_finalize renamed
  474. Revision 1.6 2000/11/06 21:52:21 florian
  475. * another fix for interfaces
  476. Revision 1.5 2000/11/06 21:35:59 peter
  477. * removed some warnings
  478. Revision 1.4 2000/11/04 16:30:35 florian
  479. + interfaces support
  480. Revision 1.3 2000/10/21 18:20:17 florian
  481. * a lot of small changes:
  482. - setlength is internal
  483. - win32 graph unit extended
  484. ....
  485. Revision 1.2 2000/07/13 11:33:41 michael
  486. + removed logs
  487. }