aasmcpu.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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(tai_cpu_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. uses
  74. globtype;
  75. {*****************************************************************************
  76. Taicpu Constructors
  77. *****************************************************************************}
  78. procedure taicpu.loadregset(opidx:longint;const s:tcpuregisterset);
  79. var
  80. i : byte;
  81. begin
  82. allocate_oper(opidx+1);
  83. with oper[opidx]^ do
  84. begin
  85. if typ<>top_regset then
  86. clearop(opidx);
  87. new(regset);
  88. regset^:=s;
  89. typ:=top_regset;
  90. for i:=RS_D0 to RS_D7 do
  91. begin
  92. if assigned(add_reg_instruction_hook) and (i in regset^) then
  93. add_reg_instruction_hook(self,newreg(R_INTREGISTER,i,R_SUBWHOLE));
  94. end;
  95. for i:=RS_A0 to RS_SP do
  96. begin
  97. if assigned(add_reg_instruction_hook) and (i in regset^) then
  98. add_reg_instruction_hook(self,newreg(R_ADDRESSREGISTER,i,R_SUBWHOLE));
  99. end;
  100. end;
  101. end;
  102. procedure taicpu.init(_size : topsize);
  103. begin
  104. typ:=ait_instruction;
  105. is_jmp:=false;
  106. opsize:=_size;
  107. ops:=0;
  108. end;
  109. constructor taicpu.op_none(op : tasmop;_size : topsize);
  110. begin
  111. inherited create(op);
  112. init(_size);
  113. end;
  114. constructor taicpu.op_reg(op : tasmop;_size : topsize;_op1 : tregister);
  115. begin
  116. inherited create(op);
  117. init(_size);
  118. ops:=1;
  119. loadreg(0,_op1);
  120. end;
  121. constructor taicpu.op_const(op : tasmop;_size : topsize;_op1 : longint);
  122. begin
  123. inherited create(op);
  124. init(_size);
  125. ops:=1;
  126. loadconst(0,aword(_op1));
  127. end;
  128. constructor taicpu.op_ref(op : tasmop;_size : topsize;_op1 : treference);
  129. begin
  130. inherited create(op);
  131. init(_size);
  132. ops:=1;
  133. loadref(0,_op1);
  134. end;
  135. constructor taicpu.op_reg_reg(op : tasmop;_size : topsize;_op1,_op2 : tregister);
  136. begin
  137. inherited create(op);
  138. init(_size);
  139. ops:=2;
  140. loadreg(0,_op1);
  141. loadreg(1,_op2);
  142. end;
  143. constructor taicpu.op_reg_const(op:tasmop; _size: topsize; _op1: tregister; _op2: longint);
  144. begin
  145. inherited create(op);
  146. init(_size);
  147. ops:=2;
  148. loadreg(0,_op1);
  149. loadconst(1,aword(_op2));
  150. end;
  151. constructor taicpu.op_reg_ref(op : tasmop;_size : topsize;_op1 : tregister;_op2 : treference);
  152. begin
  153. inherited create(op);
  154. init(_size);
  155. ops:=2;
  156. loadreg(0,_op1);
  157. loadref(1,_op2);
  158. end;
  159. constructor taicpu.op_const_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister);
  160. begin
  161. inherited create(op);
  162. init(_size);
  163. ops:=2;
  164. loadconst(0,aword(_op1));
  165. loadreg(1,_op2);
  166. end;
  167. constructor taicpu.op_const_const(op : tasmop;_size : topsize;_op1,_op2 : longint);
  168. begin
  169. inherited create(op);
  170. init(_size);
  171. ops:=2;
  172. loadconst(0,aword(_op1));
  173. loadconst(1,aword(_op2));
  174. end;
  175. constructor taicpu.op_const_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : treference);
  176. begin
  177. inherited create(op);
  178. init(_size);
  179. ops:=2;
  180. loadconst(0,aword(_op1));
  181. loadref(1,_op2);
  182. end;
  183. constructor taicpu.op_ref_reg(op : tasmop;_size : topsize;_op1 : treference;_op2 : tregister);
  184. begin
  185. inherited create(op);
  186. init(_size);
  187. ops:=2;
  188. loadref(0,_op1);
  189. loadreg(1,_op2);
  190. end;
  191. constructor taicpu.op_ref_ref(op : tasmop;_size : topsize;_op1,_op2 : treference);
  192. begin
  193. inherited create(op);
  194. init(_size);
  195. ops:=2;
  196. loadref(0,_op1);
  197. loadref(1,_op2);
  198. end;
  199. constructor taicpu.op_reg_reg_reg(op : tasmop;_size : topsize;_op1,_op2,_op3 : tregister);
  200. begin
  201. inherited create(op);
  202. init(_size);
  203. ops:=3;
  204. loadreg(0,_op1);
  205. loadreg(1,_op2);
  206. loadreg(2,_op3);
  207. end;
  208. constructor taicpu.op_const_reg_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : tregister);
  209. begin
  210. inherited create(op);
  211. init(_size);
  212. ops:=3;
  213. loadconst(0,aword(_op1));
  214. loadreg(1,_op2);
  215. loadreg(2,_op3);
  216. end;
  217. constructor taicpu.op_reg_reg_ref(op : tasmop;_size : topsize;_op1,_op2 : tregister;_op3 : treference);
  218. begin
  219. inherited create(op);
  220. init(_size);
  221. ops:=3;
  222. loadreg(0,_op1);
  223. loadreg(1,_op2);
  224. loadref(2,_op3);
  225. end;
  226. constructor taicpu.op_const_ref_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : treference;_op3 : tregister);
  227. begin
  228. inherited create(op);
  229. init(_size);
  230. ops:=3;
  231. loadconst(0,aword(_op1));
  232. loadref(1,_op2);
  233. loadreg(2,_op3);
  234. end;
  235. constructor taicpu.op_const_reg_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : treference);
  236. begin
  237. inherited create(op);
  238. init(_size);
  239. ops:=3;
  240. loadconst(0,aword(_op1));
  241. loadreg(1,_op2);
  242. loadref(2,_op3);
  243. end;
  244. constructor taicpu.op_ref_regset(op: tasmop; _size : topsize; _op1: treference;const _op2: tcpuregisterset);
  245. Begin
  246. inherited create(op);
  247. init(_size);
  248. ops:=2;
  249. loadref(0,_op1);
  250. loadregset(1,_op2);
  251. end;
  252. constructor taicpu.op_regset_ref(op: tasmop; _size : topsize;const _op1: tcpuregisterset; _op2: treference);
  253. Begin
  254. inherited create(op);
  255. init(_size);
  256. ops:=2;
  257. loadregset(0,_op1);
  258. loadref(1,_op2);
  259. End;
  260. constructor taicpu.op_reg_regset(op: tasmop; _size : topsize; _op1: tregister;const _op2: tcpuregisterset);
  261. Begin
  262. inherited create(op);
  263. init(_size);
  264. ops:=2;
  265. loadreg(0,_op1);
  266. loadregset(1,_op2);
  267. end;
  268. constructor taicpu.op_regset_reg(op: tasmop; _size : topsize;const _op1: tcpuregisterset; _op2: tregister);
  269. Begin
  270. inherited create(op);
  271. init(_size);
  272. ops:=2;
  273. loadregset(0,_op1);
  274. loadreg(1,_op2);
  275. End;
  276. constructor taicpu.op_sym(op : tasmop;_size : topsize;_op1 : tasmsymbol);
  277. begin
  278. inherited create(op);
  279. init(_size);
  280. ops:=1;
  281. loadsymbol(0,_op1,0);
  282. end;
  283. constructor taicpu.op_reg_sym(op: tasmop; _size : topsize; _op1: tregister; _op2 :tasmsymbol);
  284. begin
  285. inherited create(op);
  286. init(_size);
  287. ops:=2;
  288. loadreg(0,_op1);
  289. loadsymbol(1,_op2,0);
  290. end;
  291. constructor taicpu.op_sym_ofs_ref(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  292. begin
  293. inherited create(op);
  294. init(_size);
  295. ops:=2;
  296. loadsymbol(0,_op1,_op1ofs);
  297. loadref(1,_op2);
  298. end;
  299. constructor taicpu.op_sym_ofs(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint);
  300. begin
  301. inherited create(op);
  302. init(_size);
  303. ops:=1;
  304. loadsymbol(0,_op1,_op1ofs);
  305. end;
  306. constructor taicpu.op_sym_ofs_reg(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;_op2 : tregister);
  307. begin
  308. inherited create(op);
  309. init(_size);
  310. ops:=2;
  311. if ((op >= A_DBCC) and (op <= A_DBF))
  312. or ((op >= A_FDBEQ) and (op <= A_FDBNGLE)) then
  313. begin
  314. loadreg(0,_op2);
  315. loadsymbol(1,_op1,_op1ofs);
  316. end
  317. else
  318. begin
  319. loadsymbol(0,_op1,_op1ofs);
  320. loadreg(1,_op2);
  321. end;
  322. end;
  323. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_size : topsize;_op1 : tasmsymbol);
  324. begin
  325. inherited create(op);
  326. init(_size);
  327. condition:=cond;
  328. ops:=1;
  329. loadsymbol(0,_op1,0);
  330. end;
  331. procedure InitAsm;
  332. begin
  333. end;
  334. procedure DoneAsm;
  335. begin
  336. end;
  337. end.
  338. {
  339. $Log$
  340. Revision 1.13 2004-06-20 08:55:31 florian
  341. * logs truncated
  342. Revision 1.12 2004/06/20 08:47:33 florian
  343. * spilling of doubles on sparc fixed
  344. Revision 1.11 2004/05/06 22:01:54 florian
  345. * register numbers for address registers fixed
  346. Revision 1.10 2004/01/30 12:17:18 florian
  347. * fixed some m68k compilation problems
  348. }