2
0

aasmcpu.pas 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. {
  2. Copyright (c) 1999-2008 by Mazen Neifer and Florian Klaempfl
  3. Contains the assembler object for the AVR
  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 = 1;
  28. { "mov reg,reg" source operand number }
  29. O_MOV_DEST = 0;
  30. type
  31. taicpu = class(tai_cpu_abstract_sym)
  32. constructor op_none(op : tasmop);
  33. constructor op_reg(op : tasmop;_op1 : tregister);
  34. constructor op_const(op : tasmop;_op1 : LongInt);
  35. constructor op_ref(op : tasmop;const _op1 : treference);
  36. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  37. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  38. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  39. constructor op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  40. constructor op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  41. { this is for Jmp instructions }
  42. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  43. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  44. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  45. procedure loadbool(opidx:longint;_b:boolean);
  46. { register allocation }
  47. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  48. { register spilling code }
  49. function spilling_get_operation_type(opnr: longint): topertype;override;
  50. end;
  51. tai_align = class(tai_align_abstract)
  52. { nothing to add }
  53. end;
  54. procedure InitAsm;
  55. procedure DoneAsm;
  56. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  57. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  58. function setcondition(i : taicpu;c : tasmcond) : taicpu;
  59. implementation
  60. {*****************************************************************************
  61. taicpu Constructors
  62. *****************************************************************************}
  63. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  64. begin
  65. if opidx>=ops then
  66. ops:=opidx+1;
  67. with oper[opidx]^ do
  68. begin
  69. if typ=top_ref then
  70. dispose(ref);
  71. b:=_b;
  72. typ:=top_bool;
  73. end;
  74. end;
  75. constructor taicpu.op_none(op : tasmop);
  76. begin
  77. inherited create(op);
  78. end;
  79. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  80. begin
  81. inherited create(op);
  82. ops:=1;
  83. loadreg(0,_op1);
  84. end;
  85. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  86. begin
  87. inherited create(op);
  88. ops:=1;
  89. loadref(0,_op1);
  90. end;
  91. constructor taicpu.op_const(op : tasmop;_op1 : LongInt);
  92. begin
  93. inherited create(op);
  94. ops:=1;
  95. loadconst(0,_op1);
  96. end;
  97. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  98. begin
  99. inherited create(op);
  100. ops:=2;
  101. loadreg(0,_op1);
  102. loadreg(1,_op2);
  103. end;
  104. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  105. begin
  106. inherited create(op);
  107. ops:=2;
  108. loadreg(0,_op1);
  109. loadconst(1,aint(_op2));
  110. end;
  111. constructor taicpu.op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  112. begin
  113. inherited create(op);
  114. ops:=2;
  115. loadconst(0,_op1);
  116. loadreg(1,_op2);
  117. end;
  118. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  119. begin
  120. inherited create(op);
  121. ops:=2;
  122. loadreg(0,_op1);
  123. loadref(1,_op2);
  124. end;
  125. constructor taicpu.op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  126. begin
  127. inherited create(op);
  128. ops:=2;
  129. loadref(0,_op1);
  130. loadreg(1,_op2);
  131. end;
  132. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  133. begin
  134. inherited create(op);
  135. is_jmp:=op in jmp_instructions;
  136. condition:=cond;
  137. ops:=1;
  138. loadsymbol(0,_op1,0);
  139. end;
  140. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  141. begin
  142. inherited create(op);
  143. is_jmp:=op in jmp_instructions;
  144. ops:=1;
  145. loadsymbol(0,_op1,0);
  146. end;
  147. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  148. begin
  149. inherited create(op);
  150. ops:=1;
  151. loadsymbol(0,_op1,_op1ofs);
  152. end;
  153. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  154. begin
  155. result:=(
  156. ((opcode in [A_MOV,A_MOVW]) and (regtype = R_INTREGISTER))
  157. ) and
  158. (ops=2) and
  159. (oper[0]^.typ=top_reg) and
  160. (oper[1]^.typ=top_reg) and
  161. (oper[0]^.reg=oper[1]^.reg);
  162. end;
  163. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  164. begin
  165. result := operand_read;
  166. case opcode of
  167. A_CP,A_CPC,A_CPI :
  168. ;
  169. else
  170. begin
  171. if opnr=ops-1 then
  172. result := operand_write;
  173. end;
  174. end;
  175. end;
  176. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  177. begin
  178. case getregtype(r) of
  179. R_INTREGISTER :
  180. result:=taicpu.op_ref_reg(A_LD,ref,r);
  181. R_ADDRESSREGISTER :
  182. result:=taicpu.op_ref_reg(A_LD,ref,r);
  183. else
  184. internalerror(200401041);
  185. end;
  186. end;
  187. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  188. begin
  189. case getregtype(r) of
  190. R_INTREGISTER :
  191. result:=taicpu.op_reg_ref(A_ST,r,ref);
  192. R_ADDRESSREGISTER :
  193. result:=taicpu.op_reg_ref(A_ST,r,ref);
  194. else
  195. internalerror(200401041);
  196. end;
  197. end;
  198. procedure InitAsm;
  199. begin
  200. end;
  201. procedure DoneAsm;
  202. begin
  203. end;
  204. function setcondition(i : taicpu;c : tasmcond) : taicpu;
  205. begin
  206. i.condition:=c;
  207. result:=i;
  208. end;
  209. begin
  210. cai_cpu:=taicpu;
  211. cai_align:=tai_align;
  212. end.