aasmcpu.pas 12 KB

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