aasmcpu.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. const
  26. { "mov reg,reg" source operand number }
  27. O_MOV_SOURCE = 1;
  28. { "mov reg,reg" source operand number }
  29. O_MOV_DEST = 0;
  30. type
  31. taicpu = class(taicpu_abstract)
  32. constructor op_none(op : tasmop);
  33. constructor op_reg(op : tasmop;_op1 : tregister);
  34. constructor op_const(op : tasmop;_op1 : longint);
  35. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  36. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  37. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  38. constructor op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  39. constructor op_const_const(op : tasmop;_op1,_op2 : longint);
  40. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  41. constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  42. constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  43. constructor op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  44. constructor op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  45. constructor op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  46. constructor op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  47. constructor op_reg_bool_reg_reg(op : tasmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  48. constructor op_reg_bool_reg_const(op : tasmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: longint);
  49. constructor op_reg_reg_reg_const_const(op : tasmop;_op1,_op2,_op3 : tregister;_op4,_op5 : Longint);
  50. constructor op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_op4,_op5 : Longint);
  51. { this is for Jmp instructions }
  52. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  53. constructor op_const_const_sym(op : tasmop;_op1,_op2 : longint;_op3: tasmsymbol);
  54. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  55. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  56. constructor op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  57. constructor op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  58. procedure loadbool(opidx:longint;_b:boolean);
  59. function is_nop: boolean; override;
  60. function is_move:boolean; override;
  61. function spill_registers(list:Taasmoutput;
  62. rgget:Trggetproc;
  63. rgunget:Trgungetproc;
  64. r:Tsupregset;
  65. var unusedregsint:Tsupregset;
  66. const spilltemplist:Tspill_temp_list):boolean; override;
  67. end;
  68. tai_align = class(tai_align_abstract)
  69. { nothing to add }
  70. end;
  71. procedure InitAsm;
  72. procedure DoneAsm;
  73. implementation
  74. {*****************************************************************************
  75. taicpu Constructors
  76. *****************************************************************************}
  77. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  78. begin
  79. if opidx>=ops then
  80. ops:=opidx+1;
  81. with oper[opidx] do
  82. begin
  83. if typ=top_ref then
  84. dispose(ref);
  85. b:=_b;
  86. typ:=top_bool;
  87. end;
  88. end;
  89. constructor taicpu.op_none(op : tasmop);
  90. begin
  91. inherited create(op);
  92. end;
  93. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  94. begin
  95. inherited create(op);
  96. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  97. internalerror(2003031207);
  98. ops:=1;
  99. loadreg(0,_op1);
  100. end;
  101. constructor taicpu.op_const(op : tasmop;_op1 : longint);
  102. begin
  103. inherited create(op);
  104. ops:=1;
  105. loadconst(0,aword(_op1));
  106. end;
  107. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  108. begin
  109. inherited create(op);
  110. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  111. internalerror(2003031205);
  112. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  113. internalerror(2003031206);
  114. ops:=2;
  115. loadreg(0,_op1);
  116. loadreg(1,_op2);
  117. end;
  118. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  119. begin
  120. inherited create(op);
  121. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  122. internalerror(2003031208);
  123. ops:=2;
  124. loadreg(0,_op1);
  125. loadconst(1,aword(_op2));
  126. end;
  127. constructor taicpu.op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  128. begin
  129. inherited create(op);
  130. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  131. internalerror(2003031209);
  132. ops:=2;
  133. loadconst(0,aword(_op1));
  134. loadreg(1,_op2);
  135. end;
  136. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  137. begin
  138. inherited create(op);
  139. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  140. internalerror(2003031210);
  141. ops:=2;
  142. loadreg(0,_op1);
  143. loadref(1,_op2);
  144. end;
  145. constructor taicpu.op_const_const(op : tasmop;_op1,_op2 : longint);
  146. begin
  147. inherited create(op);
  148. ops:=2;
  149. loadconst(0,aword(_op1));
  150. loadconst(1,aword(_op2));
  151. end;
  152. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  153. begin
  154. inherited create(op);
  155. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  156. internalerror(2003031211);
  157. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  158. internalerror(2003031212);
  159. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  160. internalerror(2003031213);
  161. ops:=3;
  162. loadreg(0,_op1);
  163. loadreg(1,_op2);
  164. loadreg(2,_op3);
  165. end;
  166. constructor taicpu.op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  167. begin
  168. inherited create(op);
  169. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  170. internalerror(2003031214);
  171. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  172. internalerror(2003031215);
  173. ops:=3;
  174. loadreg(0,_op1);
  175. loadreg(1,_op2);
  176. loadconst(2,aword(_op3));
  177. end;
  178. constructor taicpu.op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  179. begin
  180. inherited create(op);
  181. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  182. internalerror(2003031216);
  183. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  184. internalerror(2003031217);
  185. ops:=3;
  186. loadreg(0,_op1);
  187. loadreg(1,_op2);
  188. loadsymbol(0,_op3,_op3ofs);
  189. end;
  190. constructor taicpu.op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  191. begin
  192. inherited create(op);
  193. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  194. internalerror(2003031218);
  195. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  196. internalerror(2003031219);
  197. ops:=3;
  198. loadreg(0,_op1);
  199. loadreg(1,_op2);
  200. loadref(2,_op3);
  201. end;
  202. constructor taicpu.op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  203. begin
  204. inherited create(op);
  205. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  206. internalerror(2003031221);
  207. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  208. internalerror(2003031220);
  209. ops:=3;
  210. loadconst(0,aword(_op1));
  211. loadreg(1,_op2);
  212. loadreg(2,_op3);
  213. end;
  214. constructor taicpu.op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  215. begin
  216. inherited create(op);
  217. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  218. internalerror(2003031222);
  219. ops:=3;
  220. loadconst(0,aword(_op1));
  221. loadreg(1,_op2);
  222. loadconst(2,aword(_op3));
  223. end;
  224. constructor taicpu.op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  225. begin
  226. inherited create(op);
  227. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  228. internalerror(2003031223);
  229. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  230. internalerror(2003031224);
  231. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  232. internalerror(2003031225);
  233. if (_op4.enum = R_INTREGISTER) and (_op4.number = NR_NO) then
  234. internalerror(2003031226);
  235. ops:=4;
  236. loadreg(0,_op1);
  237. loadreg(1,_op2);
  238. loadreg(2,_op3);
  239. loadreg(3,_op4);
  240. end;
  241. constructor taicpu.op_reg_bool_reg_reg(op : tasmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  242. begin
  243. inherited create(op);
  244. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  245. internalerror(2003031227);
  246. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  247. internalerror(2003031228);
  248. if (_op4.enum = R_INTREGISTER) and (_op4.number = NR_NO) then
  249. internalerror(2003031229);
  250. ops:=4;
  251. loadreg(0,_op1);
  252. loadbool(1,_op2);
  253. loadreg(2,_op3);
  254. loadreg(3,_op4);
  255. end;
  256. constructor taicpu.op_reg_bool_reg_const(op : tasmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: longint);
  257. begin
  258. inherited create(op);
  259. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  260. internalerror(2003031230);
  261. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  262. internalerror(2003031231);
  263. ops:=4;
  264. loadreg(0,_op1);
  265. loadbool(0,_op2);
  266. loadreg(0,_op3);
  267. loadconst(0,cardinal(_op4));
  268. end;
  269. constructor taicpu.op_reg_reg_reg_const_const(op : tasmop;_op1,_op2,_op3 : tregister;_op4,_op5 : Longint);
  270. begin
  271. inherited create(op);
  272. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  273. internalerror(2003031232);
  274. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  275. internalerror(2003031233);
  276. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  277. internalerror(2003031233);
  278. ops:=5;
  279. loadreg(0,_op1);
  280. loadreg(1,_op2);
  281. loadreg(2,_op3);
  282. loadconst(3,cardinal(_op4));
  283. loadconst(4,cardinal(_op5));
  284. end;
  285. constructor taicpu.op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_op4,_op5 : Longint);
  286. begin
  287. inherited create(op);
  288. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  289. internalerror(2003031232);
  290. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  291. internalerror(2003031233);
  292. ops:=5;
  293. loadreg(0,_op1);
  294. loadreg(1,_op2);
  295. loadconst(2,aword(_op3));
  296. loadconst(3,cardinal(_op4));
  297. loadconst(4,cardinal(_op5));
  298. end;
  299. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  300. begin
  301. inherited create(op);
  302. condition:=cond;
  303. ops:=1;
  304. loadsymbol(0,_op1,0);
  305. end;
  306. constructor taicpu.op_const_const_sym(op : tasmop;_op1,_op2 : longint; _op3: tasmsymbol);
  307. begin
  308. inherited create(op);
  309. ops:=3;
  310. loadconst(0,aword(_op1));
  311. loadconst(1,aword(_op2));
  312. loadsymbol(2,_op3,0);
  313. end;
  314. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  315. begin
  316. inherited create(op);
  317. ops:=1;
  318. loadsymbol(0,_op1,0);
  319. end;
  320. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  321. begin
  322. inherited create(op);
  323. ops:=1;
  324. loadsymbol(0,_op1,_op1ofs);
  325. end;
  326. constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  327. begin
  328. inherited create(op);
  329. ops:=2;
  330. loadreg(0,_op1);
  331. loadsymbol(1,_op2,_op2ofs);
  332. end;
  333. constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  334. begin
  335. inherited create(op);
  336. ops:=2;
  337. loadsymbol(0,_op1,_op1ofs);
  338. loadref(1,_op2);
  339. end;
  340. { ****************************** newra stuff *************************** }
  341. function taicpu.is_nop: boolean;
  342. begin
  343. { we don't insert any more nops than necessary }
  344. is_nop := false;
  345. end;
  346. function taicpu.is_move:boolean;
  347. begin
  348. is_move := opcode = A_MR;
  349. end;
  350. function taicpu.spill_registers(list:Taasmoutput;
  351. rgget:Trggetproc;
  352. rgunget:Trgungetproc;
  353. r:Tsupregset;
  354. var unusedregsint:Tsupregset;
  355. const spilltemplist:Tspill_temp_list): boolean;
  356. begin
  357. internalerror(211);
  358. end;
  359. procedure InitAsm;
  360. begin
  361. end;
  362. procedure DoneAsm;
  363. begin
  364. end;
  365. end.
  366. {
  367. $Log$
  368. Revision 1.8 2003-06-14 22:32:43 jonas
  369. * ppc compiles with -dnewra, haven't tried to compile anything with it
  370. yet though
  371. Revision 1.7 2003/06/14 14:53:50 jonas
  372. * fixed newra cycle for x86
  373. * added constants for indicating source and destination operands of the
  374. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  375. Revision 1.6 2003/05/11 11:08:25 jonas
  376. + op_reg_reg_reg_const_const (for rlwnm)
  377. Revision 1.5 2003/03/12 22:43:38 jonas
  378. * more powerpc and generic fixes related to the new register allocator
  379. Revision 1.4 2002/12/14 15:02:03 carl
  380. * maxoperands -> max_operands (for portability in rautils.pas)
  381. * fix some range-check errors with loadconst
  382. + add ncgadd unit to m68k
  383. * some bugfix of a_param_reg with LOC_CREFERENCE
  384. Revision 1.3 2002/09/17 18:26:02 jonas
  385. - removed taicpu.destroy, its job is already handled by
  386. taicpu_abstract.destroy() and this caused heap corruption
  387. Revision 1.2 2002/07/26 11:19:57 jonas
  388. * fixed range errors
  389. Revision 1.1 2002/07/07 09:44:31 florian
  390. * powerpc target fixed, very simple units can be compiled
  391. Revision 1.8 2002/05/18 13:34:26 peter
  392. * readded missing revisions
  393. Revision 1.7 2002/05/16 19:46:53 carl
  394. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  395. + try to fix temp allocation (still in ifdef)
  396. + generic constructor calls
  397. + start of tassembler / tmodulebase class cleanup
  398. Revision 1.4 2002/05/13 19:52:46 peter
  399. * a ppcppc can be build again
  400. }