aasmcpu.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. {
  2. Copyright (c) 1998-2001 by Florian Klaempfl and Pierre Muller
  3. m68k family assembler instructions
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit aasmcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,aasmtai,
  22. aasmbase,globals,verbose,symtype,
  23. cpubase,cpuinfo,cgbase,cgutils;
  24. const
  25. { "mov reg,reg" source operand number }
  26. O_MOV_SOURCE = 0;
  27. { "mov reg,reg" source operand number }
  28. O_MOV_DEST = 1;
  29. type
  30. taicpu = class(tai_cpu_abstract)
  31. opsize : topsize;
  32. constructor op_none(op : tasmop;_size : topsize);
  33. constructor op_reg(op : tasmop;_size : topsize;_op1 : tregister);
  34. constructor op_const(op : tasmop;_size : topsize;_op1 : longint);
  35. constructor op_ref(op : tasmop;_size : topsize;_op1 : treference);
  36. constructor op_reg_reg(op : tasmop;_size : topsize;_op1,_op2 : tregister);
  37. constructor op_reg_ref(op : tasmop;_size : topsize;_op1 : tregister;_op2 : treference);
  38. constructor op_reg_const(op:tasmop; _size: topsize; _op1: tregister; _op2: longint);
  39. constructor op_const_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister);
  40. constructor op_const_const(op : tasmop;_size : topsize;_op1,_op2 : longint);
  41. constructor op_const_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : treference);
  42. constructor op_ref_reg(op : tasmop;_size : topsize;_op1 : treference;_op2 : tregister);
  43. { this is only allowed if _op1 is an int value (_op1^.isintvalue=true) }
  44. constructor op_ref_ref(op : tasmop;_size : topsize;_op1,_op2 : treference);
  45. constructor op_reg_reg_reg(op : tasmop;_size : topsize;_op1,_op2,_op3 : tregister);
  46. constructor op_const_reg_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : tregister);
  47. constructor op_const_ref_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : treference;_op3 : tregister);
  48. constructor op_reg_reg_ref(op : tasmop;_size : topsize;_op1,_op2 : tregister; _op3 : treference);
  49. constructor op_const_reg_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : treference);
  50. constructor op_reg_regset(op: tasmop; _size : topsize; _op1: tregister;const _op2: tcpuregisterset);
  51. constructor op_regset_reg(op: tasmop; _size : topsize;const _op1: tcpuregisterset; _op2: tregister);
  52. constructor op_ref_regset(op: tasmop; _size : topsize; _op1: treference;const _op2: tcpuregisterset);
  53. constructor op_regset_ref(op: tasmop; _size : topsize;const _op1: tcpuregisterset; _op2: treference);
  54. { this is for Jmp instructions }
  55. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_size : topsize;_op1 : tasmsymbol);
  56. constructor op_sym(op : tasmop;_size : topsize;_op1 : tasmsymbol);
  57. { for DBxx opcodes }
  58. constructor op_reg_sym(op: tasmop; _size : topsize; _op1: tregister; _op2 :tasmsymbol);
  59. constructor op_sym_ofs_reg(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;_op2 : tregister);
  60. constructor op_sym_ofs(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint);
  61. constructor op_sym_ofs_ref(op : tasmop;_size : topsize;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  62. function is_same_reg_move(regtype: Tregistertype):boolean;override;
  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 taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  334. begin
  335. result:=(((opcode=A_MOVE) or (opcode=A_EXG)) and
  336. (regtype = R_INTREGISTER) and
  337. (ops=2) and
  338. (oper[0]^.typ=top_reg) and
  339. (oper[1]^.typ=top_reg) and
  340. (oper[0]^.reg=oper[1]^.reg)
  341. ) or
  342. ((opcode=A_FMOVE) and
  343. (regtype = R_FPUREGISTER) and
  344. (ops=2) and
  345. (oper[0]^.typ=top_reg) and
  346. (oper[1]^.typ=top_reg) and
  347. (oper[0]^.reg=oper[1]^.reg)
  348. );
  349. end;
  350. function spilling_create_load(const ref:treference;r:tregister): tai;
  351. begin
  352. {
  353. case getregtype(r) of
  354. R_INTREGISTER :
  355. result:=taicpu.op_ref_reg(A_LD,ref,r);
  356. R_FPUREGISTER :
  357. begin
  358. case getsubreg(r) of
  359. R_SUBFS :
  360. result:=taicpu.op_ref_reg(A_LDF,ref,r);
  361. R_SUBFD :
  362. result:=taicpu.op_ref_reg(A_LDD,ref,r);
  363. else
  364. internalerror(200401042);
  365. end;
  366. end
  367. else
  368. internalerror(200401041);
  369. end;}
  370. end;
  371. function spilling_create_store(r:tregister; const ref:treference): tai;
  372. begin
  373. {case getregtype(r) of
  374. R_INTREGISTER :
  375. result:=taicpu.op_reg_ref(A_ST,r,ref);
  376. R_FPUREGISTER :
  377. begin
  378. case getsubreg(r) of
  379. R_SUBFS :
  380. result:=taicpu.op_reg_ref(A_STF,r,ref);
  381. R_SUBFD :
  382. result:=taicpu.op_reg_ref(A_STD,r,ref);
  383. else
  384. internalerror(200401042);
  385. end;
  386. end
  387. else
  388. internalerror(200401041);
  389. end;}
  390. end;
  391. procedure InitAsm;
  392. begin
  393. end;
  394. procedure DoneAsm;
  395. begin
  396. end;
  397. end.