aasmcpu.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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,cgbase;
  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_regset(op: tasmop; _size : topsize; _op1: tregister;const _op2: tcpuregisterset);
  52. constructor op_regset_reg(op: tasmop; _size : topsize;const _op1: tcpuregisterset; _op2: tregister);
  53. constructor op_ref_regset(op: tasmop; _size : topsize; _op1: treference;const _op2: tcpuregisterset);
  54. constructor op_regset_ref(op: tasmop; _size : topsize;const _op1: tcpuregisterset; _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 loadregset(opidx:longint;const s:tcpuregisterset);
  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.loadregset(opidx:longint;const s:tcpuregisterset);
  77. var
  78. i : byte;
  79. begin
  80. allocate_oper(opidx+1);
  81. with oper[opidx]^ do
  82. begin
  83. if typ<>top_regset then
  84. clearop(opidx);
  85. new(regset);
  86. regset^:=s;
  87. typ:=top_regset;
  88. for i:=RS_D0 to RS_D7 do
  89. begin
  90. if assigned(add_reg_instruction_hook) and (i in regset^) then
  91. add_reg_instruction_hook(self,newreg(R_INTREGISTER,i,R_SUBWHOLE));
  92. end;
  93. for i:=RS_A0 to RS_SP do
  94. begin
  95. if assigned(add_reg_instruction_hook) and (i in regset^) then
  96. add_reg_instruction_hook(self,newreg(R_ADDRESSREGISTER,i,R_SUBWHOLE));
  97. end;
  98. end;
  99. end;
  100. procedure taicpu.init(_size : topsize);
  101. begin
  102. typ:=ait_instruction;
  103. is_jmp:=false;
  104. opsize:=_size;
  105. ops:=0;
  106. end;
  107. constructor taicpu.op_none(op : tasmop;_size : topsize);
  108. begin
  109. inherited create(op);
  110. init(_size);
  111. end;
  112. constructor taicpu.op_reg(op : tasmop;_size : topsize;_op1 : tregister);
  113. begin
  114. inherited create(op);
  115. init(_size);
  116. ops:=1;
  117. loadreg(0,_op1);
  118. end;
  119. constructor taicpu.op_const(op : tasmop;_size : topsize;_op1 : longint);
  120. begin
  121. inherited create(op);
  122. init(_size);
  123. ops:=1;
  124. loadconst(0,aword(_op1));
  125. end;
  126. constructor taicpu.op_ref(op : tasmop;_size : topsize;_op1 : treference);
  127. begin
  128. inherited create(op);
  129. init(_size);
  130. ops:=1;
  131. loadref(0,_op1);
  132. end;
  133. constructor taicpu.op_reg_reg(op : tasmop;_size : topsize;_op1,_op2 : tregister);
  134. begin
  135. inherited create(op);
  136. init(_size);
  137. ops:=2;
  138. loadreg(0,_op1);
  139. loadreg(1,_op2);
  140. end;
  141. constructor taicpu.op_reg_const(op:tasmop; _size: topsize; _op1: tregister; _op2: longint);
  142. begin
  143. inherited create(op);
  144. init(_size);
  145. ops:=2;
  146. loadreg(0,_op1);
  147. loadconst(1,aword(_op2));
  148. end;
  149. constructor taicpu.op_reg_ref(op : tasmop;_size : topsize;_op1 : tregister;_op2 : treference);
  150. begin
  151. inherited create(op);
  152. init(_size);
  153. ops:=2;
  154. loadreg(0,_op1);
  155. loadref(1,_op2);
  156. end;
  157. constructor taicpu.op_const_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister);
  158. begin
  159. inherited create(op);
  160. init(_size);
  161. ops:=2;
  162. loadconst(0,aword(_op1));
  163. loadreg(1,_op2);
  164. end;
  165. constructor taicpu.op_const_const(op : tasmop;_size : topsize;_op1,_op2 : longint);
  166. begin
  167. inherited create(op);
  168. init(_size);
  169. ops:=2;
  170. loadconst(0,aword(_op1));
  171. loadconst(1,aword(_op2));
  172. end;
  173. constructor taicpu.op_const_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : treference);
  174. begin
  175. inherited create(op);
  176. init(_size);
  177. ops:=2;
  178. loadconst(0,aword(_op1));
  179. loadref(1,_op2);
  180. end;
  181. constructor taicpu.op_ref_reg(op : tasmop;_size : topsize;_op1 : treference;_op2 : tregister);
  182. begin
  183. inherited create(op);
  184. init(_size);
  185. ops:=2;
  186. loadref(0,_op1);
  187. loadreg(1,_op2);
  188. end;
  189. constructor taicpu.op_ref_ref(op : tasmop;_size : topsize;_op1,_op2 : treference);
  190. begin
  191. inherited create(op);
  192. init(_size);
  193. ops:=2;
  194. loadref(0,_op1);
  195. loadref(1,_op2);
  196. end;
  197. constructor taicpu.op_reg_reg_reg(op : tasmop;_size : topsize;_op1,_op2,_op3 : tregister);
  198. begin
  199. inherited create(op);
  200. init(_size);
  201. ops:=3;
  202. loadreg(0,_op1);
  203. loadreg(1,_op2);
  204. loadreg(2,_op3);
  205. end;
  206. constructor taicpu.op_const_reg_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : tregister);
  207. begin
  208. inherited create(op);
  209. init(_size);
  210. ops:=3;
  211. loadconst(0,aword(_op1));
  212. loadreg(1,_op2);
  213. loadreg(2,_op3);
  214. end;
  215. constructor taicpu.op_reg_reg_ref(op : tasmop;_size : topsize;_op1,_op2 : tregister;_op3 : treference);
  216. begin
  217. inherited create(op);
  218. init(_size);
  219. ops:=3;
  220. loadreg(0,_op1);
  221. loadreg(1,_op2);
  222. loadref(2,_op3);
  223. end;
  224. constructor taicpu.op_const_ref_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : treference;_op3 : tregister);
  225. begin
  226. inherited create(op);
  227. init(_size);
  228. ops:=3;
  229. loadconst(0,aword(_op1));
  230. loadref(1,_op2);
  231. loadreg(2,_op3);
  232. end;
  233. constructor taicpu.op_const_reg_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : treference);
  234. begin
  235. inherited create(op);
  236. init(_size);
  237. ops:=3;
  238. loadconst(0,aword(_op1));
  239. loadreg(1,_op2);
  240. loadref(2,_op3);
  241. end;
  242. constructor taicpu.op_ref_regset(op: tasmop; _size : topsize; _op1: treference;const _op2: tcpuregisterset);
  243. Begin
  244. inherited create(op);
  245. init(_size);
  246. ops:=2;
  247. loadref(0,_op1);
  248. loadregset(1,_op2);
  249. end;
  250. constructor taicpu.op_regset_ref(op: tasmop; _size : topsize;const _op1: tcpuregisterset; _op2: treference);
  251. Begin
  252. inherited create(op);
  253. init(_size);
  254. ops:=2;
  255. loadregset(0,_op1);
  256. loadref(1,_op2);
  257. End;
  258. constructor taicpu.op_reg_regset(op: tasmop; _size : topsize; _op1: tregister;const _op2: tcpuregisterset);
  259. Begin
  260. inherited create(op);
  261. init(_size);
  262. ops:=2;
  263. loadreg(0,_op1);
  264. loadregset(1,_op2);
  265. end;
  266. constructor taicpu.op_regset_reg(op: tasmop; _size : topsize;const _op1: tcpuregisterset; _op2: tregister);
  267. Begin
  268. inherited create(op);
  269. init(_size);
  270. ops:=2;
  271. loadregset(0,_op1);
  272. loadreg(1,_op2);
  273. End;
  274. constructor taicpu.op_sym(op : tasmop;_size : topsize;_op1 : tasmsymbol);
  275. begin
  276. inherited create(op);
  277. init(_size);
  278. ops:=1;
  279. loadsymbol(0,_op1,0);
  280. end;
  281. constructor taicpu.op_reg_sym(op: tasmop; _size : topsize; _op1: tregister; _op2 :tasmsymbol);
  282. begin
  283. inherited create(op);
  284. init(_size);
  285. ops:=2;
  286. loadreg(0,_op1);
  287. loadsymbol(1,_op2,0);
  288. end;
  289. constructor taicpu.op_sym_ofs_ref(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  290. begin
  291. inherited create(op);
  292. init(_size);
  293. ops:=2;
  294. loadsymbol(0,_op1,_op1ofs);
  295. loadref(1,_op2);
  296. end;
  297. constructor taicpu.op_sym_ofs(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint);
  298. begin
  299. inherited create(op);
  300. init(_size);
  301. ops:=1;
  302. loadsymbol(0,_op1,_op1ofs);
  303. end;
  304. constructor taicpu.op_sym_ofs_reg(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;_op2 : tregister);
  305. begin
  306. inherited create(op);
  307. init(_size);
  308. ops:=2;
  309. if ((op >= A_DBCC) and (op <= A_DBF))
  310. or ((op >= A_FDBEQ) and (op <= A_FDBNGLE)) then
  311. begin
  312. loadreg(0,_op2);
  313. loadsymbol(1,_op1,_op1ofs);
  314. end
  315. else
  316. begin
  317. loadsymbol(0,_op1,_op1ofs);
  318. loadreg(1,_op2);
  319. end;
  320. end;
  321. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_size : topsize;_op1 : tasmsymbol);
  322. begin
  323. inherited create(op);
  324. init(_size);
  325. condition:=cond;
  326. ops:=1;
  327. loadsymbol(0,_op1,0);
  328. end;
  329. procedure InitAsm;
  330. begin
  331. end;
  332. procedure DoneAsm;
  333. begin
  334. end;
  335. end.
  336. {
  337. $Log$
  338. Revision 1.11 2004-05-06 22:01:54 florian
  339. * register numbers for address registers fixed
  340. Revision 1.10 2004/01/30 12:17:18 florian
  341. * fixed some m68k compilation problems
  342. Revision 1.9 2003/06/14 14:53:50 jonas
  343. * fixed newra cycle for x86
  344. * added constants for indicating source and destination operands of the
  345. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  346. Revision 1.8 2003/02/19 22:00:16 daniel
  347. * Code generator converted to new register notation
  348. - Horribily outdated todo.txt removed
  349. Revision 1.7 2002/12/14 15:02:03 carl
  350. * maxoperands -> max_operands (for portability in rautils.pas)
  351. * fix some range-check errors with loadconst
  352. + add ncgadd unit to m68k
  353. * some bugfix of a_param_reg with LOC_CREFERENCE
  354. Revision 1.6 2002/11/30 23:33:02 carl
  355. * merges from Pierre's fixes in m68k fixes branch
  356. Revision 1.5 2002/09/07 15:25:11 peter
  357. * old logs removed and tabs fixed
  358. Revision 1.4 2002/08/13 18:58:54 carl
  359. + m68k problems with cvs fixed?()!
  360. Revision 1.2 2002/08/12 15:08:43 carl
  361. + stab register indexes for powerpc (moved from gdb to cpubase)
  362. + tprocessor enumeration moved to cpuinfo
  363. + linker in target_info is now a class
  364. * many many updates for m68k (will soon start to compile)
  365. - removed some ifdef or correct them for correct cpu
  366. Revision 1.1 2002/07/29 17:51:32 carl
  367. + restart m68k support
  368. }