aasmcpu.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. {
  2. $Id$
  3. Copyright (c) 2003 by Florian Klaempfl
  4. Contains the assembler object for the ARM
  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,cginfo;
  25. const
  26. { "mov reg,reg" source operand number }
  27. O_MOV_SOURCE = 1;
  28. { "mov reg,reg" source operand number }
  29. O_MOV_DEST = 0;
  30. type
  31. taicpu = class(taicpu_abstract)
  32. oppostfix : TOpPostfix;
  33. roundingmode : troundingmode;
  34. procedure loadshifterop(opidx:longint;const so:tshifterop);
  35. procedure loadregset(opidx:longint;const s:tsuperregisterset);
  36. constructor op_none(op : tasmop);
  37. constructor op_reg(op : tasmop;_op1 : tregister);
  38. constructor op_const(op : tasmop;_op1 : longint);
  39. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  40. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  41. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  42. constructor op_ref_regset(op:tasmop; _op1: treference; _op2: tsuperregisterset);
  43. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  44. constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  45. constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  46. constructor op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  47. constructor op_reg_reg_shifterop(op : tasmop;_op1,_op2 : tregister;_op3 : tshifterop);
  48. { this is for Jmp instructions }
  49. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  50. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  51. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  52. constructor op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  53. constructor op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  54. function is_nop: boolean; override;
  55. function is_move:boolean; override;
  56. { register spilling code }
  57. function spilling_decode_loadstore(op: tasmop; var counterpart: tasmop; var wasload: boolean): boolean;override;
  58. function spilling_create_loadstore(op: tasmop; r:tregister; const ref:treference): tai;override;
  59. function spilling_create_load(const ref:treference;r:tregister): tai;override;
  60. function spilling_create_store(r:tregister; const ref:treference): tai;override;
  61. end;
  62. tai_align = class(tai_align_abstract)
  63. { nothing to add }
  64. end;
  65. function setoppostfix(i : taicpu;pf : toppostfix) : taicpu;
  66. function setroundingmode(i : taicpu;rm : troundingmode) : taicpu;
  67. function setcondition(i : taicpu;c : tasmcond) : taicpu;
  68. procedure InitAsm;
  69. procedure DoneAsm;
  70. implementation
  71. uses
  72. cutils,rgobj;
  73. procedure taicpu.loadshifterop(opidx:longint;const so:tshifterop);
  74. begin
  75. if opidx>=ops then
  76. ops:=opidx+1;
  77. with oper[opidx] do
  78. begin
  79. if typ<>top_shifterop then
  80. begin
  81. clearop(opidx);
  82. new(shifterop);
  83. end;
  84. shifterop^:=so;
  85. typ:=top_shifterop;
  86. end;
  87. end;
  88. procedure taicpu.loadregset(opidx:longint;const s:tsuperregisterset);
  89. begin
  90. if opidx>=ops then
  91. ops:=opidx+1;
  92. with oper[opidx] do
  93. begin
  94. if typ<>top_regset then
  95. clearop(opidx);
  96. regset:=s;
  97. typ:=top_regset;
  98. end;
  99. end;
  100. {*****************************************************************************
  101. taicpu Constructors
  102. *****************************************************************************}
  103. constructor taicpu.op_none(op : tasmop);
  104. begin
  105. inherited create(op);
  106. end;
  107. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  108. begin
  109. inherited create(op);
  110. ops:=1;
  111. loadreg(0,_op1);
  112. end;
  113. constructor taicpu.op_const(op : tasmop;_op1 : longint);
  114. begin
  115. inherited create(op);
  116. ops:=1;
  117. loadconst(0,aword(_op1));
  118. end;
  119. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  120. begin
  121. inherited create(op);
  122. ops:=2;
  123. loadreg(0,_op1);
  124. loadreg(1,_op2);
  125. end;
  126. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  127. begin
  128. inherited create(op);
  129. ops:=2;
  130. loadreg(0,_op1);
  131. loadconst(1,aword(_op2));
  132. end;
  133. constructor taicpu.op_ref_regset(op:tasmop; _op1: treference; _op2: tsuperregisterset);
  134. begin
  135. inherited create(op);
  136. ops:=2;
  137. loadref(0,_op1);
  138. loadregset(1,_op2);
  139. end;
  140. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  141. begin
  142. inherited create(op);
  143. ops:=2;
  144. loadreg(0,_op1);
  145. loadref(1,_op2);
  146. end;
  147. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  148. begin
  149. inherited create(op);
  150. ops:=3;
  151. loadreg(0,_op1);
  152. loadreg(1,_op2);
  153. loadreg(2,_op3);
  154. end;
  155. constructor taicpu.op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  156. begin
  157. inherited create(op);
  158. ops:=3;
  159. loadreg(0,_op1);
  160. loadreg(1,_op2);
  161. loadconst(2,aword(_op3));
  162. end;
  163. constructor taicpu.op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  164. begin
  165. inherited create(op);
  166. ops:=3;
  167. loadreg(0,_op1);
  168. loadreg(1,_op2);
  169. loadsymbol(0,_op3,_op3ofs);
  170. end;
  171. constructor taicpu.op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  172. begin
  173. inherited create(op);
  174. ops:=3;
  175. loadreg(0,_op1);
  176. loadreg(1,_op2);
  177. loadref(2,_op3);
  178. end;
  179. constructor taicpu.op_reg_reg_shifterop(op : tasmop;_op1,_op2 : tregister;_op3 : tshifterop);
  180. begin
  181. inherited create(op);
  182. ops:=3;
  183. loadreg(0,_op1);
  184. loadreg(1,_op2);
  185. loadshifterop(2,_op3);
  186. end;
  187. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  188. begin
  189. inherited create(op);
  190. condition:=cond;
  191. ops:=1;
  192. loadsymbol(0,_op1,0);
  193. end;
  194. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  195. begin
  196. inherited create(op);
  197. ops:=1;
  198. loadsymbol(0,_op1,0);
  199. end;
  200. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  201. begin
  202. inherited create(op);
  203. ops:=1;
  204. loadsymbol(0,_op1,_op1ofs);
  205. end;
  206. constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  207. begin
  208. inherited create(op);
  209. ops:=2;
  210. loadreg(0,_op1);
  211. loadsymbol(1,_op2,_op2ofs);
  212. end;
  213. constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  214. begin
  215. inherited create(op);
  216. ops:=2;
  217. loadsymbol(0,_op1,_op1ofs);
  218. loadref(1,_op2);
  219. end;
  220. { ****************************** newra stuff *************************** }
  221. function taicpu.is_nop: boolean;
  222. begin
  223. { we don't insert any more nops than necessary }
  224. is_nop := false;
  225. end;
  226. function taicpu.is_move:boolean;
  227. begin
  228. is_move := opcode=A_MOV;
  229. end;
  230. function taicpu.spilling_decode_loadstore(op: tasmop; var counterpart: tasmop; var wasload: boolean): boolean;
  231. begin
  232. result := true;
  233. wasload := true;
  234. case op of
  235. A_LDR:
  236. begin
  237. counterpart := A_STR;
  238. end;
  239. A_LDM:
  240. internalerror(2003070602);
  241. else
  242. result := false;
  243. end;
  244. end;
  245. function taicpu.spilling_create_loadstore(op: tasmop; r:tregister; const ref:treference): tai;
  246. begin
  247. result:=taicpu.op_reg_ref(opcode,r,ref);
  248. end;
  249. function taicpu.spilling_create_load(const ref:treference;r:tregister): tai;
  250. begin
  251. result:=taicpu.op_reg_ref(A_LDR,r,ref);
  252. end;
  253. function taicpu.spilling_create_store(r:tregister; const ref:treference): tai;
  254. begin
  255. result:=taicpu.op_reg_ref(A_STR,r,ref);
  256. end;
  257. procedure InitAsm;
  258. begin
  259. end;
  260. procedure DoneAsm;
  261. begin
  262. end;
  263. function setoppostfix(i : taicpu;pf : toppostfix) : taicpu;
  264. begin
  265. i.oppostfix:=pf;
  266. result:=i;
  267. end;
  268. function setroundingmode(i : taicpu;rm : troundingmode) : taicpu;
  269. begin
  270. i.roundingmode:=rm;
  271. result:=i;
  272. end;
  273. function setcondition(i : taicpu;c : tasmcond) : taicpu;
  274. begin
  275. i.condition:=c;
  276. result:=i;
  277. end;
  278. end.
  279. {
  280. $Log$
  281. Revision 1.12 2003-09-11 11:54:59 florian
  282. * improved arm code generation
  283. * move some protected and private field around
  284. * the temp. register for register parameters/arguments are now released
  285. before the move to the parameter register is done. This improves
  286. the code in a lot of cases.
  287. Revision 1.11 2003/09/06 11:21:49 florian
  288. * fixed stm and ldm to be usable with preindex operand
  289. Revision 1.10 2003/09/04 21:07:03 florian
  290. * ARM compiler compiles again
  291. Revision 1.9 2003/09/04 00:15:29 florian
  292. * first bunch of adaptions of arm compiler for new register type
  293. Revision 1.8 2003/09/03 11:18:37 florian
  294. * fixed arm concatcopy
  295. + arm support in the common compiler sources added
  296. * moved some generic cg code around
  297. + tfputype added
  298. * ...
  299. Revision 1.7 2003/08/29 21:36:28 florian
  300. * fixed procedure entry/exit code
  301. * started to fix reference handling
  302. Revision 1.6 2003/08/28 00:05:29 florian
  303. * today's arm patches
  304. Revision 1.5 2003/08/27 00:27:56 florian
  305. + same procedure as very day: today's work on arm
  306. Revision 1.4 2003/08/25 23:20:38 florian
  307. + started to implement FPU support for the ARM
  308. * fixed a lot of other things
  309. Revision 1.3 2003/08/24 12:27:26 florian
  310. * continued to work on the arm port
  311. Revision 1.2 2003/08/20 15:50:12 florian
  312. * more arm stuff
  313. Revision 1.1 2003/08/16 13:23:01 florian
  314. * several arm related stuff fixed
  315. }