aasmcpu.pas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. {
  2. Copyright (c) 1999-2002 by Mazen Neifer
  3. Contains the assembler object for the SPARC
  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,
  22. globtype,globals,verbose,
  23. aasmbase,aasmtai,aasmdata,aasmsym,
  24. cgbase,cgutils,cpubase,cpuinfo;
  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_sym)
  32. delayslot_annulled : boolean; { conditinal opcode with ,a }
  33. constructor op_none(op : tasmop);
  34. constructor op_reg(op : tasmop;_op1 : tregister);
  35. constructor op_const(op : tasmop;_op1 : LongInt);
  36. constructor op_ref(op : tasmop;const _op1 : treference);
  37. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  38. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  39. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  40. constructor op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  41. constructor op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  42. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  43. constructor op_reg_ref_reg(op:tasmop;_op1:TRegister;_op2:TReference;_op3:tregister);
  44. constructor op_reg_const_reg(op:tasmop;_op1:TRegister;_op2:aint;_op3:tregister);
  45. { this is for Jmp instructions }
  46. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  47. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  48. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  49. procedure loadbool(opidx:longint;_b:boolean);
  50. { register allocation }
  51. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  52. { register spilling code }
  53. function spilling_get_operation_type(opnr: longint): topertype;override;
  54. end;
  55. tai_align = class(tai_align_abstract)
  56. { nothing to add }
  57. end;
  58. procedure InitAsm;
  59. procedure DoneAsm;
  60. function spilling_create_load(const ref:treference;r:tregister): tai;
  61. function spilling_create_store(r:tregister; const ref:treference): tai;
  62. implementation
  63. {*****************************************************************************
  64. taicpu Constructors
  65. *****************************************************************************}
  66. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  67. begin
  68. if opidx>=ops then
  69. ops:=opidx+1;
  70. with oper[opidx]^ do
  71. begin
  72. if typ=top_ref then
  73. dispose(ref);
  74. b:=_b;
  75. typ:=top_bool;
  76. end;
  77. end;
  78. constructor taicpu.op_none(op : tasmop);
  79. begin
  80. inherited create(op);
  81. end;
  82. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  83. begin
  84. inherited create(op);
  85. ops:=1;
  86. loadreg(0,_op1);
  87. end;
  88. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  89. begin
  90. inherited create(op);
  91. ops:=1;
  92. loadref(0,_op1);
  93. end;
  94. constructor taicpu.op_const(op : tasmop;_op1 : LongInt);
  95. begin
  96. inherited create(op);
  97. ops:=1;
  98. loadconst(0,_op1);
  99. end;
  100. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  101. begin
  102. inherited create(op);
  103. ops:=2;
  104. loadreg(0,_op1);
  105. loadreg(1,_op2);
  106. end;
  107. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  108. begin
  109. inherited create(op);
  110. ops:=2;
  111. loadreg(0,_op1);
  112. loadconst(1,_op2);
  113. end;
  114. constructor taicpu.op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  115. begin
  116. inherited create(op);
  117. ops:=2;
  118. loadconst(0,_op1);
  119. loadreg(1,_op2);
  120. end;
  121. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  122. begin
  123. inherited create(op);
  124. ops:=2;
  125. loadreg(0,_op1);
  126. loadref(1,_op2);
  127. end;
  128. constructor taicpu.op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  129. begin
  130. inherited create(op);
  131. ops:=2;
  132. loadref(0,_op1);
  133. loadreg(1,_op2);
  134. end;
  135. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  136. begin
  137. inherited create(op);
  138. ops:=3;
  139. loadreg(0,_op1);
  140. loadreg(1,_op2);
  141. loadreg(2,_op3);
  142. end;
  143. constructor taicpu.op_reg_ref_reg(op:tasmop;_op1:TRegister;_op2:TReference;_op3:tregister);
  144. begin
  145. inherited create(op);
  146. { only allowed to load the address }
  147. if not(_op2.refaddr in [addr_lo,addr_hi]) then
  148. internalerror(200305311);
  149. ops:=3;
  150. loadreg(0,_op1);
  151. loadref(1,_op2);
  152. loadreg(2,_op3);
  153. end;
  154. constructor taicpu.op_reg_const_reg(op:tasmop;_op1:TRegister;_op2:aint;_op3:tregister);
  155. begin
  156. inherited create(op);
  157. ops:=3;
  158. loadreg(0,_op1);
  159. loadconst(1,_op2);
  160. loadreg(2,_op3);
  161. end;
  162. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  163. begin
  164. inherited create(op);
  165. is_jmp:=op in [A_BA,A_Bxx];
  166. condition:=cond;
  167. ops:=1;
  168. loadsymbol(0,_op1,0);
  169. end;
  170. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  171. begin
  172. inherited create(op);
  173. is_jmp:=op in [A_BA,A_Bxx];
  174. ops:=1;
  175. loadsymbol(0,_op1,0);
  176. end;
  177. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  178. begin
  179. inherited create(op);
  180. ops:=1;
  181. loadsymbol(0,_op1,_op1ofs);
  182. end;
  183. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  184. begin
  185. result:=(
  186. ((opcode=A_MOV) and (regtype = R_INTREGISTER)) or
  187. ((regtype = R_FPUREGISTER) and (opcode in [A_FMOVS,A_FMOVD]))
  188. ) and
  189. (ops=2) and
  190. (oper[0]^.typ=top_reg) and
  191. (oper[1]^.typ=top_reg) and
  192. (oper[0]^.reg=oper[1]^.reg);
  193. end;
  194. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  195. begin
  196. result := operand_read;
  197. case opcode of
  198. A_FCMPs,A_FCMPd,A_FCMPq :
  199. ;
  200. else
  201. begin
  202. if opnr=ops-1 then
  203. result := operand_write;
  204. end;
  205. end;
  206. end;
  207. function spilling_create_load(const ref:treference;r:tregister): tai;
  208. begin
  209. case getregtype(r) of
  210. R_INTREGISTER :
  211. result:=taicpu.op_ref_reg(A_LD,ref,r);
  212. R_FPUREGISTER :
  213. begin
  214. case getsubreg(r) of
  215. R_SUBFS :
  216. result:=taicpu.op_ref_reg(A_LDF,ref,r);
  217. R_SUBFD :
  218. result:=taicpu.op_ref_reg(A_LDD,ref,r);
  219. else
  220. internalerror(200401042);
  221. end;
  222. end
  223. else
  224. internalerror(200401041);
  225. end;
  226. end;
  227. function spilling_create_store(r:tregister; const ref:treference): tai;
  228. begin
  229. case getregtype(r) of
  230. R_INTREGISTER :
  231. result:=taicpu.op_reg_ref(A_ST,r,ref);
  232. R_FPUREGISTER :
  233. begin
  234. case getsubreg(r) of
  235. R_SUBFS :
  236. result:=taicpu.op_reg_ref(A_STF,r,ref);
  237. R_SUBFD :
  238. result:=taicpu.op_reg_ref(A_STD,r,ref);
  239. else
  240. internalerror(200401042);
  241. end;
  242. end
  243. else
  244. internalerror(200401041);
  245. end;
  246. end;
  247. procedure InitAsm;
  248. begin
  249. end;
  250. procedure DoneAsm;
  251. begin
  252. end;
  253. begin
  254. cai_cpu:=taicpu;
  255. cai_align:=tai_align;
  256. end.