cpubase.pas 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. {
  2. $Id$
  3. Copyright (C) 2000 by Florian Klaempfl
  4. this unit implements an asmlistitem class for the iA-64 architecture
  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 cpubase;
  19. interface
  20. uses
  21. cutils,strings,systems,cobjects,globals,aasm,cpuinfo;
  22. type
  23. tasmop = (A_ADD,A_SUB,A_ADDP4,A_AND,A_ANDCM,A_OR,A_XOR,A_SHLADD,
  24. A_SHLADDP4,A_ADDS,A_ADDL,A_CMP,A_CMP4,A_PADD1,A_PADD2,
  25. A_PADD4,A_PSUB1,A_PSUB2,A_PSUB4,A_PAVG1,A_PAVG2,A_PAVGSUB1,
  26. A_PAVGSUB2,A_PCMP1,A_PCMP2,A_PCMP4,A_PSHLADD2,A_PSHRADD2,
  27. A_PMPY2,A_MIX1,A_MIX2,A_MIX4,A_PACK2,A_PACK4,A_UNPACK2,
  28. A_UNPACK4,A_PMIN1,A_PMAX1,A_PMIN2,A_PMAX2,A_PSAD1,A_MUX1,
  29. A_MUX2,A_PSHR2,A_PSHR4,A_SHR,A_PSHL2,A_SHL4,A_SHL,
  30. A_POPCNT,A_SHRP,A_EXTR,A_DEP,A_TBIT,A_TNAT,A_BREAK,
  31. A_NOP,A_CHK,A_MOV,A_ZX1,A_ZX2,A_ZXT4,A_SXT1,A_SXT2,A_SXT4,
  32. A_CXZ1,A_CZX2,A_LD1,A_LD2,A_LD4,A_LD8,A_ST1,A_ST2,A_ST4,
  33. A_ST8,A_LDFS,A_LDFD,A_LDF8,A_LDFE,A_LDF,A_STFS,A_STFD,A_STF8,
  34. A_STFE,A_STF,A_LDFPS,A_LDFPD,A_LDFP8,A_LFETCH,A_CMPXCHG1,
  35. A_CMPXCHG2,A_CMPXHG4,A_CMPXCHG8,A_XCHG1,A_XCHG2,A_XCHG4,
  36. A_XCHG8,A_FETCHADD4,A_FETCHADD8,A_SETF,A_GETF,
  37. A_INVALA,A_MF,A_SRLZ,A_SYNC,A_FLUSHRS,A_FC,A_ALLOC,A_SUM,
  38. A_RUM,A_BR,A_CLRRRB,A_FMA,A_FPMA,A_FMS,A_FPMS,A_FNMA,A_FPNMA,
  39. A_XMA,A_FSELECT,A_FCLASS,A_FRCPA,A_FPRCPA,A_FRSQRTA,
  40. A_FPRSQRTA,A_FMIN,A_FMAX,A_FAMIN,A_FAMAX,A_FPMIN,A_FPMAX,
  41. A_FPAMIN,A_FPAMAX,A_FPCMP,A_FMERGE,A_FMIX,A_FSXT,A_FPACK,
  42. A_FSWAP,A_FAND,A_FANDCM,A_FOR,A_FXOR,A_FPMERGE,A_FCVT,
  43. A_FPCVT,A_FSETC,A_FCLRT,A_FCHKF,A_MOVL);
  44. Const
  45. firstop = low(tasmop);
  46. lastop = high(tasmop);
  47. type
  48. TAsmCond = (C_NONE,C_LT,C_LTU,C_EQ,C_LT_UNC,C_LTU_UNC,C_EQ_UNC,
  49. C_EQ_AND,C_EQ_OR,C_EQ_OR_ANDCM,C_NE_AND,C_NE_OR);
  50. THint = (H_NONE,H_NT1,H_NT2,H_NTA);
  51. TLdStType = (LST_NONE,LST_S,LST_A,LSR_SA,LST_BIAS,LST_ACQ,LST_C_CLR,
  52. LST_FILL,LST_C_NC,LST_C_CLR_ACQ,LST_REL,
  53. LST_SPILL);
  54. Type
  55. TRegister = (R_NO, { R_NO is Mandatory, signifies no register }
  56. R_0,R_1,R_2,R_3,R_4,R_5,R_6,R_7,R_8,R_9,
  57. R_10,R_11,R_12,R_13,R_14,R_15,R_16,R_17,R_18,R_19,
  58. R_20,R_21,R_22,R_23,R_24,R_25,R_26,R_27,R_28,R_29,
  59. R_30,R_31,
  60. R_F0,R_F1,R_F2,R_F3,R_F4,R_F5,R_F6,R_F7,R_F8,R_F9,
  61. R_F10,R_F11,R_F12,R_F13,R_F14,R_F15,R_F16,R_F17,R_F18,R_F19,
  62. R_F20,R_F21,R_F22,R_F23,R_F24,R_F25,R_F26,R_F27,R_F28,R_F29,
  63. R_F30,R_F31);
  64. TRegisterset = Set of TRegister;
  65. { -1 indicates no qualifying prediction }
  66. tqp = -1..63;
  67. const
  68. qp_none : tqp = -1;
  69. { Constants describing the registers }
  70. Const
  71. Firstreg = R_0;
  72. LastReg = R_F31;
  73. stack_pointer_reg = R_30;
  74. frame_pointer_reg = R_15;
  75. self_pointer_reg = R_16;
  76. accumulator = R_0;
  77. {the return_result_reg, is used inside the called function to store its return
  78. value when that is a scalar value otherwise a pointer to the address of the
  79. result is placed inside it}
  80. return_result_reg = accumulator;
  81. {the function_result_reg contains the function result after a call to a scalar
  82. function othewise it contains a pointer to the returned result}
  83. function_result_reg = accumulator;
  84. global_pointer = R_29;
  85. return_pointer = R_26;
  86. max_scratch_regs = 2;
  87. scratch_regs : array[1..max_scratch_regs] of tregister = (R_1,R_2);
  88. { low and high of the available maximum width integer general purpose }
  89. { registers }
  90. LoGPReg = R_0;
  91. HiGPReg = R_31;
  92. { sizes }
  93. pointer_size = 8;
  94. extended_size = 16;
  95. general_registers = [R_0..R_31];
  96. intregs = [R_0..R_31];
  97. fpuregs = [R_F0..R_F31];
  98. mmregs = [];
  99. availabletempregsint = [R_0..R_14,R_16..R_25,R_28];
  100. availabletempregsfpu = [R_F0..R_F30];
  101. availabletempregsmm = [];
  102. c_countusableregsint = 26;
  103. c_countusableregsfpu = 31;
  104. c_countusableregsmm = 0;
  105. maxfpuvarregs = 128;
  106. maxvarregs = 128;
  107. max_operands = 4;
  108. varregs : Array [1..6] of Tregister =
  109. (R_9,R_10,R_11,R_12,R_13,R_14);
  110. {*****************************************************************************
  111. GCC /ABI linking information
  112. *****************************************************************************}
  113. {# Registers which must be saved when calling a routine declared as
  114. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  115. saved should be the ones as defined in the target ABI and / or GCC.
  116. This value can be deduced from CALLED_USED_REGISTERS array in the
  117. GCC source.
  118. }
  119. std_saved_registers = [R_9..R_14,R_F2..R_F9];
  120. {# Required parameter alignment when calling a routine declared as
  121. stdcall and cdecl. The alignment value should be the one defined
  122. by GCC or the target ABI.
  123. The value of this constant is equal to the constant
  124. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  125. }
  126. std_param_align = ???;
  127. Type
  128. TReference = record
  129. offset : aword;
  130. symbol : pasmsymbol;
  131. base : tregister;
  132. is_immediate : boolean;
  133. offsetfixup : word; {needed for inline}
  134. { the boundary to which the reference is surely aligned }
  135. alignment : byte;
  136. end;
  137. PReference = ^TReference;
  138. tloc = (LOC_INVALID,
  139. LOC_REGISTER,
  140. LOC_FPU,
  141. LOC_MEM,
  142. LOC_REFERENCE,
  143. LOC_JUMP,
  144. { the alpha doesn't have flags, but this }
  145. { avoid some conditional compiling }
  146. { DON'T USE for the alpha }
  147. LOC_FLAGS,
  148. LOC_CREGISTER,
  149. LOC_CFPUREGISTER,
  150. LOC_CONST);
  151. tlocation = record
  152. case loc : tloc of
  153. LOC_REFERENCE,LOC_MEM : (reference : treference);
  154. LOC_CREGISTER,
  155. LOC_REGISTER : (register : tregister);
  156. LOC_FLAGS : (qp : tqp);
  157. LOC_JUMP : ();
  158. end;
  159. {*****************************************************************************
  160. Opcode propeties (needed for optimizer)
  161. *****************************************************************************}
  162. {$ifndef NOOPT}
  163. Type
  164. {What an instruction can change}
  165. TInsChange = (Ch_None);
  166. {$endif}
  167. { resets all values of ref to defaults }
  168. procedure reset_reference(var ref : treference);
  169. { set mostly used values of a new reference }
  170. function new_reference(base : tregister;offset : longint) : preference;
  171. function newreference(const r : treference) : preference;
  172. procedure disposereference(var r : preference);
  173. procedure set_location(var destloc : tlocation;const sourceloc : tlocation);
  174. {*****************************************************************************
  175. Init/Done
  176. *****************************************************************************}
  177. procedure InitCpu;
  178. procedure DoneCpu;
  179. implementation
  180. uses
  181. verbose;
  182. procedure reset_reference(var ref : treference);
  183. begin
  184. FillChar(ref,sizeof(treference),0);
  185. end;
  186. function new_reference(base : tregister;offset : longint) : preference;
  187. var
  188. r : preference;
  189. begin
  190. new(r);
  191. FillChar(r^,sizeof(treference),0);
  192. r^.offset:=offset;
  193. r^.alignment:=8;
  194. new_reference:=r;
  195. end;
  196. function newreference(const r : treference) : preference;
  197. var
  198. p : preference;
  199. begin
  200. new(p);
  201. p^:=r;
  202. newreference:=p;
  203. end;
  204. procedure disposereference(var r : preference);
  205. begin
  206. dispose(r);
  207. r:=Nil;
  208. end;
  209. procedure set_location(var destloc : tlocation;const sourceloc : tlocation);
  210. begin
  211. destloc:=sourceloc;
  212. end;
  213. {*****************************************************************************
  214. Init/Done
  215. *****************************************************************************}
  216. procedure InitCpu;
  217. begin
  218. end;
  219. procedure DoneCpu;
  220. begin
  221. end;
  222. end.
  223. {
  224. $Log$
  225. Revision 1.6 2002-11-17 18:26:16 mazen
  226. * fixed a compilation bug accmulator-->accumulator, in definition of return_result_reg
  227. Revision 1.5 2002/11/17 17:49:09 mazen
  228. + return_result_reg and function_result_reg are now used, in all plateforms, to pass functions result between called function and its caller. See the explanation of each one
  229. Revision 1.4 2002/09/07 15:25:11 peter
  230. * old logs removed and tabs fixed
  231. Revision 1.3 2002/04/20 21:38:45 carl
  232. * renamed some constants
  233. }