2
0

aasmcpu.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. {
  2. $Id$
  3. Copyright (c) 1998-2001 by Florian Klaempfl and Pierre Muller
  4. m68k family assembler instructions
  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 = 0;
  28. { "mov reg,reg" source operand number }
  29. O_MOV_DEST = 1;
  30. type
  31. taicpu = class(taicpu_abstract)
  32. opsize : topsize;
  33. constructor op_none(op : tasmop;_size : topsize);
  34. constructor op_reg(op : tasmop;_size : topsize;_op1 : tregister);
  35. constructor op_const(op : tasmop;_size : topsize;_op1 : longint);
  36. constructor op_ref(op : tasmop;_size : topsize;_op1 : treference);
  37. constructor op_reg_reg(op : tasmop;_size : topsize;_op1,_op2 : tregister);
  38. constructor op_reg_ref(op : tasmop;_size : topsize;_op1 : tregister;_op2 : treference);
  39. constructor op_reg_const(op:tasmop; _size: topsize; _op1: tregister; _op2: longint);
  40. constructor op_const_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister);
  41. constructor op_const_const(op : tasmop;_size : topsize;_op1,_op2 : longint);
  42. constructor op_const_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : treference);
  43. constructor op_ref_reg(op : tasmop;_size : topsize;_op1 : treference;_op2 : tregister);
  44. { this is only allowed if _op1 is an int value (_op1^.isintvalue=true) }
  45. constructor op_ref_ref(op : tasmop;_size : topsize;_op1,_op2 : treference);
  46. constructor op_reg_reg_reg(op : tasmop;_size : topsize;_op1,_op2,_op3 : tregister);
  47. constructor op_const_reg_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : tregister);
  48. constructor op_const_ref_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : treference;_op3 : tregister);
  49. constructor op_reg_reg_ref(op : tasmop;_size : topsize;_op1,_op2 : tregister; _op3 : treference);
  50. constructor op_const_reg_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : treference);
  51. constructor op_reg_reglist(op: tasmop; _size : topsize; _op1: tregister;_op2: Tsupregset);
  52. constructor op_reglist_reg(op: tasmop; _size : topsize; _op1: Tsupregset; _op2: tregister);
  53. constructor op_ref_reglist(op: tasmop; _size : topsize; _op1: treference;_op2: Tsupregset);
  54. constructor op_reglist_ref(op: tasmop; _size : topsize; _op1: Tsupregset; _op2: treference);
  55. { this is for Jmp instructions }
  56. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_size : topsize;_op1 : tasmsymbol);
  57. constructor op_sym(op : tasmop;_size : topsize;_op1 : tasmsymbol);
  58. { for DBxx opcodes }
  59. constructor op_reg_sym(op: tasmop; _size : topsize; _op1: tregister; _op2 :tasmsymbol);
  60. constructor op_sym_ofs_reg(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;_op2 : tregister);
  61. constructor op_sym_ofs(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint);
  62. constructor op_sym_ofs_ref(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  63. private
  64. procedure loadreglist(opidx:longint;r:Tsupregset);
  65. procedure init(_size : topsize); { this need to be called by all constructor }
  66. end;
  67. tai_align = class(tai_align_abstract)
  68. { nothing to add }
  69. end;
  70. procedure InitAsm;
  71. procedure DoneAsm;
  72. implementation
  73. {*****************************************************************************
  74. Taicpu Constructors
  75. *****************************************************************************}
  76. procedure taicpu.loadreglist(opidx:longint;r:Tsupregset);
  77. begin
  78. if opidx>=ops then
  79. ops:=opidx+1;
  80. with oper[opidx] do
  81. begin
  82. registerlist:=r;
  83. typ:=top_reglist;
  84. end;
  85. end;
  86. procedure taicpu.init(_size : topsize);
  87. begin
  88. typ:=ait_instruction;
  89. is_jmp:=false;
  90. opsize:=_size;
  91. ops:=0;
  92. end;
  93. constructor taicpu.op_none(op : tasmop;_size : topsize);
  94. begin
  95. inherited create(op);;
  96. init(_size);
  97. end;
  98. constructor taicpu.op_reg(op : tasmop;_size : topsize;_op1 : tregister);
  99. begin
  100. inherited create(op);;
  101. init(_size);
  102. ops:=1;
  103. loadreg(0,_op1);
  104. end;
  105. constructor taicpu.op_const(op : tasmop;_size : topsize;_op1 : longint);
  106. begin
  107. inherited create(op);;
  108. init(_size);
  109. ops:=1;
  110. loadconst(0,aword(_op1));
  111. end;
  112. constructor taicpu.op_ref(op : tasmop;_size : topsize;_op1 : treference);
  113. begin
  114. inherited create(op);;
  115. init(_size);
  116. ops:=1;
  117. loadref(0,_op1);
  118. end;
  119. constructor taicpu.op_reg_reg(op : tasmop;_size : topsize;_op1,_op2 : tregister);
  120. begin
  121. inherited create(op);;
  122. init(_size);
  123. ops:=2;
  124. loadreg(0,_op1);
  125. loadreg(1,_op2);
  126. end;
  127. constructor taicpu.op_reg_const(op:tasmop; _size: topsize; _op1: tregister; _op2: longint);
  128. begin
  129. inherited create(op);;
  130. init(_size);
  131. ops:=2;
  132. loadreg(0,_op1);
  133. loadconst(1,aword(_op2));
  134. end;
  135. constructor taicpu.op_reg_ref(op : tasmop;_size : topsize;_op1 : tregister;_op2 : treference);
  136. begin
  137. inherited create(op);;
  138. init(_size);
  139. ops:=2;
  140. loadreg(0,_op1);
  141. loadref(1,_op2);
  142. end;
  143. constructor taicpu.op_const_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister);
  144. begin
  145. inherited create(op);;
  146. init(_size);
  147. ops:=2;
  148. loadconst(0,aword(_op1));
  149. loadreg(1,_op2);
  150. end;
  151. constructor taicpu.op_const_const(op : tasmop;_size : topsize;_op1,_op2 : longint);
  152. begin
  153. inherited create(op);;
  154. init(_size);
  155. ops:=2;
  156. loadconst(0,aword(_op1));
  157. loadconst(1,aword(_op2));
  158. end;
  159. constructor taicpu.op_const_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : treference);
  160. begin
  161. inherited create(op);;
  162. init(_size);
  163. ops:=2;
  164. loadconst(0,aword(_op1));
  165. loadref(1,_op2);
  166. end;
  167. constructor taicpu.op_ref_reg(op : tasmop;_size : topsize;_op1 : treference;_op2 : tregister);
  168. begin
  169. inherited create(op);;
  170. init(_size);
  171. ops:=2;
  172. loadref(0,_op1);
  173. loadreg(1,_op2);
  174. end;
  175. constructor taicpu.op_ref_ref(op : tasmop;_size : topsize;_op1,_op2 : treference);
  176. begin
  177. inherited create(op);;
  178. init(_size);
  179. ops:=2;
  180. loadref(0,_op1);
  181. loadref(1,_op2);
  182. end;
  183. constructor taicpu.op_reg_reg_reg(op : tasmop;_size : topsize;_op1,_op2,_op3 : tregister);
  184. begin
  185. inherited create(op);;
  186. init(_size);
  187. ops:=3;
  188. loadreg(0,_op1);
  189. loadreg(1,_op2);
  190. loadreg(2,_op3);
  191. end;
  192. constructor taicpu.op_const_reg_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : tregister);
  193. begin
  194. inherited create(op);;
  195. init(_size);
  196. ops:=3;
  197. loadconst(0,aword(_op1));
  198. loadreg(1,_op2);
  199. loadreg(2,_op3);
  200. end;
  201. constructor taicpu.op_reg_reg_ref(op : tasmop;_size : topsize;_op1,_op2 : tregister;_op3 : treference);
  202. begin
  203. inherited create(op);;
  204. init(_size);
  205. ops:=3;
  206. loadreg(0,_op1);
  207. loadreg(1,_op2);
  208. loadref(2,_op3);
  209. end;
  210. constructor taicpu.op_const_ref_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : treference;_op3 : tregister);
  211. begin
  212. inherited create(op);;
  213. init(_size);
  214. ops:=3;
  215. loadconst(0,aword(_op1));
  216. loadref(1,_op2);
  217. loadreg(2,_op3);
  218. end;
  219. constructor taicpu.op_const_reg_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : treference);
  220. begin
  221. inherited create(op);;
  222. init(_size);
  223. ops:=3;
  224. loadconst(0,aword(_op1));
  225. loadreg(1,_op2);
  226. loadref(2,_op3);
  227. end;
  228. constructor taicpu.op_ref_reglist(op: tasmop; _size : topsize; _op1: treference;_op2: Tsupregset);
  229. Begin
  230. inherited create(op);;
  231. init(_size);
  232. ops:=2;
  233. loadref(0,_op1);
  234. loadreglist(1,_op2);
  235. end;
  236. constructor taicpu.op_reglist_ref(op: tasmop; _size : topsize; _op1: Tsupregset; _op2: treference);
  237. Begin
  238. inherited create(op);;
  239. init(_size);
  240. ops:=2;
  241. loadreglist(0,_op1);
  242. loadref(1,_op2);
  243. End;
  244. constructor taicpu.op_reg_reglist(op: tasmop; _size : topsize; _op1: tregister;_op2: Tsupregset);
  245. Begin
  246. inherited create(op);;
  247. init(_size);
  248. ops:=2;
  249. loadreg(0,_op1);
  250. loadreglist(1,_op2);
  251. end;
  252. constructor taicpu.op_reglist_reg(op: tasmop; _size : topsize; _op1: Tsupregset; _op2: tregister);
  253. Begin
  254. inherited create(op);;
  255. init(_size);
  256. ops:=2;
  257. loadreglist(0,_op1);
  258. loadreg(1,_op2);
  259. End;
  260. constructor taicpu.op_sym(op : tasmop;_size : topsize;_op1 : tasmsymbol);
  261. begin
  262. inherited create(op);;
  263. init(_size);
  264. ops:=1;
  265. loadsymbol(0,_op1,0);
  266. end;
  267. constructor taicpu.op_reg_sym(op: tasmop; _size : topsize; _op1: tregister; _op2 :tasmsymbol);
  268. begin
  269. inherited create(op);
  270. init(_size);
  271. ops:=2;
  272. loadreg(0,_op1);
  273. loadsymbol(1,_op2,0);
  274. end;
  275. constructor taicpu.op_sym_ofs_ref(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  276. begin
  277. inherited create(op);
  278. init(_size);
  279. ops:=2;
  280. loadsymbol(0,_op1,_op1ofs);
  281. loadref(1,_op2);
  282. end;
  283. constructor taicpu.op_sym_ofs(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint);
  284. begin
  285. inherited create(op);
  286. init(_size);
  287. ops:=1;
  288. loadsymbol(0,_op1,_op1ofs);
  289. end;
  290. constructor taicpu.op_sym_ofs_reg(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;_op2 : tregister);
  291. begin
  292. inherited create(op);;
  293. init(_size);
  294. ops:=2;
  295. if ((op >= A_DBCC) and (op <= A_DBF))
  296. or ((op >= A_FDBEQ) and (op <= A_FDBNGLE)) then
  297. begin
  298. loadreg(0,_op2);
  299. loadsymbol(1,_op1,_op1ofs);
  300. end
  301. else
  302. begin
  303. loadsymbol(0,_op1,_op1ofs);
  304. loadreg(1,_op2);
  305. end;
  306. end;
  307. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_size : topsize;_op1 : tasmsymbol);
  308. begin
  309. inherited create(op);
  310. init(_size);
  311. condition:=cond;
  312. ops:=1;
  313. loadsymbol(0,_op1,0);
  314. end;
  315. procedure InitAsm;
  316. begin
  317. end;
  318. procedure DoneAsm;
  319. begin
  320. end;
  321. end.
  322. {
  323. $Log$
  324. Revision 1.9 2003-06-14 14:53:50 jonas
  325. * fixed newra cycle for x86
  326. * added constants for indicating source and destination operands of the
  327. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  328. Revision 1.8 2003/02/19 22:00:16 daniel
  329. * Code generator converted to new register notation
  330. - Horribily outdated todo.txt removed
  331. Revision 1.7 2002/12/14 15:02:03 carl
  332. * maxoperands -> max_operands (for portability in rautils.pas)
  333. * fix some range-check errors with loadconst
  334. + add ncgadd unit to m68k
  335. * some bugfix of a_param_reg with LOC_CREFERENCE
  336. Revision 1.6 2002/11/30 23:33:02 carl
  337. * merges from Pierre's fixes in m68k fixes branch
  338. Revision 1.5 2002/09/07 15:25:11 peter
  339. * old logs removed and tabs fixed
  340. Revision 1.4 2002/08/13 18:58:54 carl
  341. + m68k problems with cvs fixed?()!
  342. Revision 1.2 2002/08/12 15:08:43 carl
  343. + stab register indexes for powerpc (moved from gdb to cpubase)
  344. + tprocessor enumeration moved to cpuinfo
  345. + linker in target_info is now a class
  346. * many many updates for m68k (will soon start to compile)
  347. - removed some ifdef or correct them for correct cpu
  348. Revision 1.1 2002/07/29 17:51:32 carl
  349. + restart m68k support
  350. }