aasmcpu.pas 14 KB

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