aasmcpu.pas 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. ogbase;
  26. const
  27. { "mov reg,reg" source operand number }
  28. O_MOV_SOURCE = 1;
  29. { "mov reg,reg" source operand number }
  30. O_MOV_DEST = 0;
  31. maxinfolen = 5;
  32. type
  33. tinsentry = record
  34. opcode : tasmop;
  35. ops : byte;
  36. optypes : array[0..3] of longint;
  37. code : array[0..maxinfolen] of char;
  38. flags : longint;
  39. end;
  40. pinsentry=^tinsentry;
  41. taicpu = class(tai_cpu_abstract_sym)
  42. constructor op_none(op : tasmop);
  43. constructor op_reg(op : tasmop;_op1 : tregister);
  44. constructor op_const(op : tasmop;_op1 : LongInt);
  45. constructor op_ref(op : tasmop;const _op1 : treference);
  46. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  47. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  48. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  49. constructor op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  50. constructor op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  51. { this is for Jmp instructions }
  52. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  53. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  54. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  55. procedure loadbool(opidx:longint;_b:boolean);
  56. { register allocation }
  57. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  58. { register spilling code }
  59. function spilling_get_operation_type(opnr: longint): topertype;override;
  60. end;
  61. tai_align = class(tai_align_abstract)
  62. { nothing to add }
  63. end;
  64. procedure InitAsm;
  65. procedure DoneAsm;
  66. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  67. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  68. implementation
  69. {*****************************************************************************
  70. taicpu Constructors
  71. *****************************************************************************}
  72. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  73. begin
  74. if opidx>=ops then
  75. ops:=opidx+1;
  76. with oper[opidx]^ do
  77. begin
  78. if typ=top_ref then
  79. dispose(ref);
  80. b:=_b;
  81. typ:=top_bool;
  82. end;
  83. end;
  84. constructor taicpu.op_none(op : tasmop);
  85. begin
  86. inherited create(op);
  87. end;
  88. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  89. begin
  90. inherited create(op);
  91. ops:=1;
  92. loadreg(0,_op1);
  93. end;
  94. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  95. begin
  96. inherited create(op);
  97. ops:=1;
  98. loadref(0,_op1);
  99. end;
  100. constructor taicpu.op_const(op : tasmop;_op1 : LongInt);
  101. begin
  102. inherited create(op);
  103. ops:=1;
  104. loadconst(0,_op1);
  105. end;
  106. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  107. begin
  108. inherited create(op);
  109. ops:=2;
  110. loadreg(0,_op1);
  111. loadreg(1,_op2);
  112. end;
  113. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  114. begin
  115. inherited create(op);
  116. ops:=2;
  117. loadreg(0,_op1);
  118. loadconst(1,aint(_op2));
  119. end;
  120. constructor taicpu.op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  121. begin
  122. inherited create(op);
  123. ops:=2;
  124. loadconst(0,_op1);
  125. loadreg(1,_op2);
  126. end;
  127. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  128. begin
  129. inherited create(op);
  130. ops:=2;
  131. loadreg(0,_op1);
  132. loadref(1,_op2);
  133. end;
  134. constructor taicpu.op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  135. begin
  136. inherited create(op);
  137. ops:=2;
  138. loadref(0,_op1);
  139. loadreg(1,_op2);
  140. end;
  141. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  142. begin
  143. inherited create(op);
  144. is_jmp:=op in jmp_instructions;
  145. condition:=cond;
  146. ops:=1;
  147. loadsymbol(0,_op1,0);
  148. end;
  149. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  150. begin
  151. inherited create(op);
  152. is_jmp:=op in jmp_instructions;
  153. ops:=1;
  154. loadsymbol(0,_op1,0);
  155. end;
  156. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  157. begin
  158. inherited create(op);
  159. ops:=1;
  160. loadsymbol(0,_op1,_op1ofs);
  161. end;
  162. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  163. begin
  164. result:=(
  165. ((opcode in [A_LD]) and (regtype = R_INTREGISTER))
  166. ) and
  167. (ops=2) and
  168. (oper[0]^.typ=top_reg) and
  169. (oper[1]^.typ=top_reg) and
  170. (oper[0]^.reg=oper[1]^.reg);
  171. end;
  172. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  173. begin
  174. result:=operand_read;
  175. case opcode of
  176. A_LD,
  177. A_POP:
  178. if opnr=0 then
  179. result:=operand_write;
  180. A_PUSH,
  181. A_BIT,
  182. A_DJNZ,
  183. A_JR,
  184. A_JP:
  185. ;
  186. A_SET:
  187. if opnr=1 then
  188. result:=operand_readwrite;
  189. A_EX:
  190. result:=operand_readwrite;
  191. else
  192. begin
  193. if opnr=0 then
  194. result:=operand_readwrite;
  195. end;
  196. end;
  197. end;
  198. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  199. begin
  200. internalerror(2017032602);
  201. {
  202. case getregtype(r) of
  203. R_INTREGISTER :
  204. if ref.offset<>0 then
  205. result:=taicpu.op_reg_ref(A_LDD,r,ref)
  206. else
  207. result:=taicpu.op_reg_ref(A_LD,r,ref);
  208. R_ADDRESSREGISTER :
  209. if ref.offset<>0 then
  210. result:=taicpu.op_reg_ref(A_LDD,r,ref)
  211. else
  212. result:=taicpu.op_reg_ref(A_LD,r,ref);
  213. else
  214. internalerror(200401041);
  215. end;
  216. }
  217. end;
  218. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  219. begin
  220. internalerror(2017032601);
  221. {
  222. case getregtype(r) of
  223. R_INTREGISTER :
  224. if ref.offset<>0 then
  225. result:=taicpu.op_ref_reg(A_STD,ref,r)
  226. else
  227. result:=taicpu.op_ref_reg(A_ST,ref,r);
  228. R_ADDRESSREGISTER :
  229. if ref.offset<>0 then
  230. result:=taicpu.op_ref_reg(A_STD,ref,r)
  231. else
  232. result:=taicpu.op_ref_reg(A_ST,ref,r);
  233. else
  234. internalerror(200401041);
  235. end;
  236. }
  237. end;
  238. procedure InitAsm;
  239. begin
  240. end;
  241. procedure DoneAsm;
  242. begin
  243. end;
  244. begin
  245. cai_cpu:=taicpu;
  246. cai_align:=tai_align;
  247. end.