cpuasm.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. {
  2. $Id$
  3. Copyright (c) 1999-2001 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 cpuasm;
  19. interface
  20. uses
  21. cclasses,
  22. aasm,globals,verbose,tainst,
  23. cpubase;
  24. type
  25. taicpu = class(tainstruction)
  26. constructor op_none(op : tasmop);
  27. constructor op_reg(op : tasmop;_op1 : tregister);
  28. constructor op_const(op : tasmop;_op1 : longint);
  29. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  30. constructor op_reg_ref(op : tasmop;_op1 : tregister;_op2 : preference);
  31. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  32. constructor op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  33. constructor op_const_const(op : tasmop;_op1,_op2 : longint);
  34. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  35. constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  36. constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  37. constructor op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; _op3: preference);
  38. constructor op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  39. constructor op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  40. constructor op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  41. constructor op_reg_bool_reg_reg(op : tasmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  42. constructor op_reg_bool_reg_const(op : tasmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: longint);
  43. constructor op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_op4,_op5 : Longint);
  44. { this is for Jmp instructions }
  45. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  46. constructor op_const_const_sym(op : tasmop;_op1,_op2 : longint;_op3: tasmsymbol);
  47. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  48. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  49. constructor op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  50. constructor op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;_op2 : preference);
  51. procedure loadbool(opidx:longint;_b:boolean);
  52. procedure loadconst(opidx:longint;l:longint);
  53. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  54. procedure loadref(opidx:longint;p:preference);
  55. procedure loadreg(opidx:longint;r:tregister);
  56. procedure loadoper(opidx:longint;o:toper);
  57. destructor destroy;override;
  58. end;
  59. implementation
  60. {*****************************************************************************
  61. taicpu Constructors
  62. *****************************************************************************}
  63. procedure taicpu.loadconst(opidx:longint;l:longint);
  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. disposereference(ref);
  71. val:=l;
  72. typ:=top_const;
  73. end;
  74. end;
  75. procedure taicpu.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  76. begin
  77. if opidx>=ops then
  78. ops:=opidx+1;
  79. with oper[opidx] do
  80. begin
  81. if typ=top_ref then
  82. disposereference(ref);
  83. sym:=s;
  84. symofs:=sofs;
  85. typ:=top_symbol;
  86. end;
  87. { Mark the symbol as used }
  88. if assigned(s) then
  89. inc(s.refs);
  90. end;
  91. procedure taicpu.loadref(opidx:longint;p:preference);
  92. begin
  93. if opidx>=ops then
  94. ops:=opidx+1;
  95. with oper[opidx] do
  96. begin
  97. if typ=top_ref then
  98. disposereference(ref);
  99. if p^.is_immediate then
  100. begin
  101. {$ifdef REF_IMMEDIATE_WARN}
  102. Comment(V_Warning,'Reference immediate');
  103. {$endif}
  104. val:=p^.offset;
  105. disposereference(p);
  106. typ:=top_const;
  107. end
  108. else
  109. begin
  110. ref:=p;
  111. typ:=top_ref;
  112. { mark symbol as used }
  113. if assigned(ref^.symbol) then
  114. inc(ref^.symbol.refs);
  115. end;
  116. end;
  117. end;
  118. procedure taicpu.loadreg(opidx:longint;r:tregister);
  119. begin
  120. if opidx>=ops then
  121. ops:=opidx+1;
  122. with oper[opidx] do
  123. begin
  124. if typ=top_ref then
  125. disposereference(ref);
  126. reg:=r;
  127. typ:=top_reg;
  128. end;
  129. end;
  130. procedure taicpu.loadoper(opidx:longint;o:toper);
  131. begin
  132. if opidx>=ops then
  133. ops:=opidx+1;
  134. if oper[opidx].typ=top_ref then
  135. disposereference(oper[opidx].ref);
  136. oper[opidx]:=o;
  137. { copy also the reference }
  138. if oper[opidx].typ=top_ref then
  139. oper[opidx].ref:=newreference(o.ref^);
  140. end;
  141. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  142. begin
  143. if opidx>=ops then
  144. ops:=opidx+1;
  145. with oper[opidx] do
  146. begin
  147. if typ=top_ref then
  148. disposereference(ref);
  149. b:=_b;
  150. typ:=top_bool;
  151. end;
  152. end;
  153. constructor taicpu.op_none(op : tasmop);
  154. begin
  155. inherited create(op);
  156. end;
  157. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  158. begin
  159. inherited create(op);
  160. ops:=1;
  161. loadreg(0,_op1);
  162. end;
  163. constructor taicpu.op_const(op : tasmop;_op1 : longint);
  164. begin
  165. inherited create(op);
  166. ops:=1;
  167. loadconst(0,_op1);
  168. end;
  169. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  170. begin
  171. inherited create(op);
  172. ops:=2;
  173. loadreg(0,_op1);
  174. loadreg(1,_op2);
  175. end;
  176. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  177. begin
  178. inherited create(op);
  179. ops:=2;
  180. loadreg(0,_op1);
  181. loadconst(1,_op2);
  182. end;
  183. constructor taicpu.op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  184. begin
  185. inherited create(op);
  186. ops:=2;
  187. loadconst(0,_op1);
  188. loadreg(1,_op2);
  189. end;
  190. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;_op2 : preference);
  191. begin
  192. inherited create(op);
  193. ops:=2;
  194. loadreg(0,_op1);
  195. loadref(1,_op2);
  196. end;
  197. constructor taicpu.op_const_const(op : tasmop;_op1,_op2 : longint);
  198. begin
  199. inherited create(op);
  200. ops:=2;
  201. loadconst(0,_op1);
  202. loadconst(1,_op2);
  203. end;
  204. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  205. begin
  206. inherited create(op);
  207. ops:=3;
  208. loadreg(0,_op1);
  209. loadreg(1,_op2);
  210. loadreg(2,_op3);
  211. end;
  212. constructor taicpu.op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  213. begin
  214. inherited create(op);
  215. ops:=3;
  216. loadreg(0,_op1);
  217. loadreg(1,_op2);
  218. loadconst(2,_op3);
  219. end;
  220. constructor taicpu.op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  221. begin
  222. inherited create(op);
  223. ops:=3;
  224. loadreg(0,_op1);
  225. loadreg(1,_op2);
  226. loadsymbol(0,_op3,_op3ofs);
  227. end;
  228. constructor taicpu.op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; _op3: preference);
  229. begin
  230. inherited create(op);
  231. ops:=3;
  232. loadreg(0,_op1);
  233. loadreg(1,_op2);
  234. loadref(2,_op3);
  235. end;
  236. constructor taicpu.op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  237. begin
  238. inherited create(op);
  239. ops:=3;
  240. loadconst(0,_op1);
  241. loadreg(1,_op2);
  242. loadreg(2,_op3);
  243. end;
  244. constructor taicpu.op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  245. begin
  246. inherited create(op);
  247. ops:=3;
  248. loadconst(0,_op1);
  249. loadreg(1,_op2);
  250. loadconst(2,_op3);
  251. end;
  252. constructor taicpu.op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  253. begin
  254. inherited create(op);
  255. ops:=4;
  256. loadreg(0,_op1);
  257. loadreg(1,_op2);
  258. loadreg(2,_op3);
  259. loadreg(3,_op4);
  260. end;
  261. constructor taicpu.op_reg_bool_reg_reg(op : tasmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  262. begin
  263. inherited create(op);
  264. ops:=4;
  265. loadreg(0,_op1);
  266. loadbool(1,_op2);
  267. loadreg(2,_op3);
  268. loadreg(3,_op4);
  269. end;
  270. constructor taicpu.op_reg_bool_reg_const(op : tasmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: longint);
  271. begin
  272. inherited create(op);
  273. ops:=4;
  274. loadreg(0,_op1);
  275. loadbool(0,_op2);
  276. loadreg(0,_op3);
  277. loadconst(0,_op4);
  278. end;
  279. constructor taicpu.op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_op4,_op5 : Longint);
  280. begin
  281. inherited create(op);
  282. ops:=5;
  283. loadreg(0,_op1);
  284. loadreg(1,_op2);
  285. loadconst(2,_op3);
  286. loadconst(3,_op4);
  287. loadconst(4,_op5);
  288. end;
  289. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  290. begin
  291. inherited create(op);
  292. condition:=cond;
  293. ops:=1;
  294. loadsymbol(0,_op1,0);
  295. end;
  296. constructor taicpu.op_const_const_sym(op : tasmop;_op1,_op2 : longint; _op3: tasmsymbol);
  297. begin
  298. inherited create(op);
  299. ops:=3;
  300. loadconst(0,_op1);
  301. loadconst(1,_op2);
  302. loadsymbol(2,_op3,0);
  303. end;
  304. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  305. begin
  306. inherited create(op);
  307. ops:=1;
  308. loadsymbol(0,_op1,0);
  309. end;
  310. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  311. begin
  312. inherited create(op);
  313. ops:=1;
  314. loadsymbol(0,_op1,_op1ofs);
  315. end;
  316. constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  317. begin
  318. inherited create(op);
  319. ops:=2;
  320. loadreg(0,_op1);
  321. loadsymbol(1,_op2,_op2ofs);
  322. end;
  323. constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;_op2 : preference);
  324. begin
  325. inherited create(op);
  326. ops:=2;
  327. loadsymbol(0,_op1,_op1ofs);
  328. loadref(1,_op2);
  329. end;
  330. destructor taicpu.destroy;
  331. var
  332. i : longint;
  333. begin
  334. for i:=ops-1 downto 0 do
  335. if (oper[i].typ=top_ref) then
  336. dispose(oper[i].ref);
  337. inherited destroy;
  338. end;
  339. end.
  340. {
  341. $Log$
  342. Revision 1.2 2001-08-26 13:31:04 florian
  343. * some cg reorganisation
  344. * some PPC updates
  345. Revision 1.2 2001/08/26 13:29:34 florian
  346. * some cg reorganisation
  347. * some PPC updates
  348. Revision 1.1 2000/07/13 06:30:12 michael
  349. + Initial import
  350. Revision 1.5 2000/01/07 01:14:58 peter
  351. * updated copyright to 2000
  352. Revision 1.4 1999/08/25 12:00:24 jonas
  353. * changed pai386, paippc and paiapha (same for tai*) to paicpu (taicpu)
  354. Revision 1.3 1999/08/06 16:41:11 jonas
  355. * PowerPC compiles again, several routines implemented in cgcpu.pas
  356. * added constant to cpubase of alpha and powerpc for maximum
  357. number of operands
  358. Revision 1.2 1999/08/04 12:59:24 jonas
  359. * all tokes now start with an underscore
  360. * PowerPC compiles!!
  361. Revision 1.1 1999/08/03 23:37:53 jonas
  362. + initial implementation for PowerPC based on the Alpha stuff
  363. }