2
0

aasmcpu.pas 14 KB

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