aasmcpu.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. {
  2. $Id$
  3. Copyright (c) 1999-2002 by Jonas Maebe
  4. Contains the assembler object for the PowerPC
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit aasmcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,aasmtai,
  23. aasmbase,globals,verbose,
  24. cpubase,cpuinfo;
  25. type
  26. taicpu = class(taicpu_abstract)
  27. constructor op_none(op : tasmop);
  28. constructor op_reg(op : tasmop;_op1 : tregister);
  29. constructor op_const(op : tasmop;_op1 : longint);
  30. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  31. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  32. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  33. constructor op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  34. constructor op_const_const(op : tasmop;_op1,_op2 : longint);
  35. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  36. constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  37. constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  38. constructor op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  39. constructor op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  40. constructor op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  41. constructor op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  42. constructor op_reg_bool_reg_reg(op : tasmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  43. constructor op_reg_bool_reg_const(op : tasmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: longint);
  44. constructor op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_op4,_op5 : Longint);
  45. { this is for Jmp instructions }
  46. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  47. constructor op_const_const_sym(op : tasmop;_op1,_op2 : longint;_op3: tasmsymbol);
  48. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  49. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  50. constructor op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  51. constructor op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  52. procedure loadbool(opidx:longint;_b:boolean);
  53. end;
  54. tai_align = class(tai_align_abstract)
  55. { nothing to add }
  56. end;
  57. procedure InitAsm;
  58. procedure DoneAsm;
  59. implementation
  60. {*****************************************************************************
  61. taicpu Constructors
  62. *****************************************************************************}
  63. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  64. begin
  65. if opidx>=ops then
  66. ops:=opidx+1;
  67. with oper[opidx] do
  68. begin
  69. if typ=top_ref then
  70. dispose(ref);
  71. b:=_b;
  72. typ:=top_bool;
  73. end;
  74. end;
  75. constructor taicpu.op_none(op : tasmop);
  76. begin
  77. inherited create(op);
  78. end;
  79. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  80. begin
  81. inherited create(op);
  82. ops:=1;
  83. loadreg(0,_op1);
  84. end;
  85. constructor taicpu.op_const(op : tasmop;_op1 : longint);
  86. begin
  87. inherited create(op);
  88. ops:=1;
  89. loadconst(0,aword(_op1));
  90. end;
  91. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  92. begin
  93. inherited create(op);
  94. ops:=2;
  95. loadreg(0,_op1);
  96. loadreg(1,_op2);
  97. end;
  98. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  99. begin
  100. inherited create(op);
  101. ops:=2;
  102. loadreg(0,_op1);
  103. loadconst(1,aword(_op2));
  104. end;
  105. constructor taicpu.op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  106. begin
  107. inherited create(op);
  108. ops:=2;
  109. loadconst(0,aword(_op1));
  110. loadreg(1,_op2);
  111. end;
  112. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  113. begin
  114. inherited create(op);
  115. ops:=2;
  116. loadreg(0,_op1);
  117. loadref(1,_op2);
  118. end;
  119. constructor taicpu.op_const_const(op : tasmop;_op1,_op2 : longint);
  120. begin
  121. inherited create(op);
  122. ops:=2;
  123. loadconst(0,aword(_op1));
  124. loadconst(1,aword(_op2));
  125. end;
  126. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  127. begin
  128. inherited create(op);
  129. ops:=3;
  130. loadreg(0,_op1);
  131. loadreg(1,_op2);
  132. loadreg(2,_op3);
  133. end;
  134. constructor taicpu.op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  135. begin
  136. inherited create(op);
  137. ops:=3;
  138. loadreg(0,_op1);
  139. loadreg(1,_op2);
  140. loadconst(2,aword(_op3));
  141. end;
  142. constructor taicpu.op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  143. begin
  144. inherited create(op);
  145. ops:=3;
  146. loadreg(0,_op1);
  147. loadreg(1,_op2);
  148. loadsymbol(0,_op3,_op3ofs);
  149. end;
  150. constructor taicpu.op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  151. begin
  152. inherited create(op);
  153. ops:=3;
  154. loadreg(0,_op1);
  155. loadreg(1,_op2);
  156. loadref(2,_op3);
  157. end;
  158. constructor taicpu.op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  159. begin
  160. inherited create(op);
  161. ops:=3;
  162. loadconst(0,aword(_op1));
  163. loadreg(1,_op2);
  164. loadreg(2,_op3);
  165. end;
  166. constructor taicpu.op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  167. begin
  168. inherited create(op);
  169. ops:=3;
  170. loadconst(0,aword(_op1));
  171. loadreg(1,_op2);
  172. loadconst(2,aword(_op3));
  173. end;
  174. constructor taicpu.op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  175. begin
  176. inherited create(op);
  177. ops:=4;
  178. loadreg(0,_op1);
  179. loadreg(1,_op2);
  180. loadreg(2,_op3);
  181. loadreg(3,_op4);
  182. end;
  183. constructor taicpu.op_reg_bool_reg_reg(op : tasmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  184. begin
  185. inherited create(op);
  186. ops:=4;
  187. loadreg(0,_op1);
  188. loadbool(1,_op2);
  189. loadreg(2,_op3);
  190. loadreg(3,_op4);
  191. end;
  192. constructor taicpu.op_reg_bool_reg_const(op : tasmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: longint);
  193. begin
  194. inherited create(op);
  195. ops:=4;
  196. loadreg(0,_op1);
  197. loadbool(0,_op2);
  198. loadreg(0,_op3);
  199. loadconst(0,cardinal(_op4));
  200. end;
  201. constructor taicpu.op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_op4,_op5 : Longint);
  202. begin
  203. inherited create(op);
  204. ops:=5;
  205. loadreg(0,_op1);
  206. loadreg(1,_op2);
  207. loadconst(2,aword(_op3));
  208. loadconst(3,cardinal(_op4));
  209. loadconst(4,cardinal(_op5));
  210. end;
  211. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  212. begin
  213. inherited create(op);
  214. condition:=cond;
  215. ops:=1;
  216. loadsymbol(0,_op1,0);
  217. end;
  218. constructor taicpu.op_const_const_sym(op : tasmop;_op1,_op2 : longint; _op3: tasmsymbol);
  219. begin
  220. inherited create(op);
  221. ops:=3;
  222. loadconst(0,aword(_op1));
  223. loadconst(1,aword(_op2));
  224. loadsymbol(2,_op3,0);
  225. end;
  226. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  227. begin
  228. inherited create(op);
  229. ops:=1;
  230. loadsymbol(0,_op1,0);
  231. end;
  232. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  233. begin
  234. inherited create(op);
  235. ops:=1;
  236. loadsymbol(0,_op1,_op1ofs);
  237. end;
  238. constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  239. begin
  240. inherited create(op);
  241. ops:=2;
  242. loadreg(0,_op1);
  243. loadsymbol(1,_op2,_op2ofs);
  244. end;
  245. constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  246. begin
  247. inherited create(op);
  248. ops:=2;
  249. loadsymbol(0,_op1,_op1ofs);
  250. loadref(1,_op2);
  251. end;
  252. procedure InitAsm;
  253. begin
  254. end;
  255. procedure DoneAsm;
  256. begin
  257. end;
  258. end.
  259. {
  260. $Log$
  261. Revision 1.4 2002-12-14 15:02:03 carl
  262. * maxoperands -> max_operands (for portability in rautils.pas)
  263. * fix some range-check errors with loadconst
  264. + add ncgadd unit to m68k
  265. * some bugfix of a_param_reg with LOC_CREFERENCE
  266. Revision 1.3 2002/09/17 18:26:02 jonas
  267. - removed taicpu.destroy, its job is already handled by
  268. taicpu_abstract.destroy() and this caused heap corruption
  269. Revision 1.2 2002/07/26 11:19:57 jonas
  270. * fixed range errors
  271. Revision 1.1 2002/07/07 09:44:31 florian
  272. * powerpc target fixed, very simple units can be compiled
  273. Revision 1.8 2002/05/18 13:34:26 peter
  274. * readded missing revisions
  275. Revision 1.7 2002/05/16 19:46:53 carl
  276. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  277. + try to fix temp allocation (still in ifdef)
  278. + generic constructor calls
  279. + start of tassembler / tmodulebase class cleanup
  280. Revision 1.4 2002/05/13 19:52:46 peter
  281. * a ppcppc can be build again
  282. }