rttip.inc 13 KB

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