cpubase.pas 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. 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,A_CHK,
  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_CMP,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 =
  49. (
  50. C_None,C_A,C_AE,C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_NA,C_NAE,
  51. C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_NO,C_NP,C_NS,C_NZ,C_O,C_P,
  52. C_PE,C_PO,C_S,C_Z
  53. );
  54. Type
  55. { ALL registers }
  56. TRegister = (R_NO, { R_NO is Mandatory, signifies no register }
  57. R_0,R_1,R_2,R_3,R_4,R_5,R_6,R_7,R_8,R_9,
  58. R_10,R_11,R_12,R_13,R_14,R_15,R_16,R_17,R_18,R_19,
  59. R_20,R_21,R_22,R_23,R_24,R_25,R_26,R_27,R_28,R_29,
  60. R_30,R_31,
  61. R_F0,R_F1,R_F2,R_F3,R_F4,R_F5,R_F6,R_F7,R_F8,R_F9,
  62. R_F10,R_F11,R_F12,R_F13,R_F14,R_F15,R_F16,R_F17,R_F18,R_F19,
  63. R_F20,R_F21,R_F22,R_F23,R_F24,R_F25,R_F26,R_F27,R_F28,R_F29,
  64. R_F30,R_F31);
  65. TRegisterset = Set of TRegister;
  66. { Constants describing the registers }
  67. Const
  68. Firstreg = R_0;
  69. LastReg = R_F31;
  70. stack_pointer = R_30;
  71. frame_pointer = R_15;
  72. self_pointer = R_16;
  73. accumulator = R_0;
  74. global_pointer = R_29;
  75. return_pointer = R_26;
  76. { it is used to pass the offset to the destructor helper routine }
  77. vmt_offset_reg = R_1;
  78. max_scratch_regs = 2;
  79. scratch_regs : array[1..max_scratch_regs] of tregister = (R_1,R_2);
  80. { low and high of the available maximum width integer general purpose }
  81. { registers }
  82. LoGPReg = R_0;
  83. HiGPReg = R_31;
  84. { low and high of every possible width general purpose register (same as }
  85. { above on most architctures apart from the 80x86) }
  86. LoReg = R_0;
  87. HiReg = R_31;
  88. cpuflags = [cf_64bitaddr];
  89. { sizes }
  90. pointersize = 8;
  91. extended_size = 16;
  92. general_registers = [R_0..R_31];
  93. intregs = [R_0..R_31];
  94. fpuregs = [R_F0..R_F31];
  95. mmregs = [];
  96. availabletempregsint = [R_0..R_14,R_16..R_25,R_28];
  97. availabletempregsfpu = [R_F0..R_F30];
  98. availabletempregsmm = [];
  99. c_countusableregsint = 26;
  100. c_countusableregsfpu = 31;
  101. c_countusableregsmm = 0;
  102. max_operands = 4;
  103. registers_saved_on_cdecl = [R_9..R_14,R_F2..R_F9];
  104. maxvarregs = 6;
  105. varregs : Array [1..maxvarregs] of Tregister =
  106. (R_9,R_10,R_11,R_12,R_13,R_14);
  107. Type
  108. TReference = record
  109. offset : aword;
  110. symbol : pasmsymbol;
  111. base : tregister;
  112. is_immediate : boolean;
  113. offsetfixup : word; {needed for inline}
  114. { the boundary to which the reference is surely aligned }
  115. alignment : byte;
  116. end;
  117. PReference = ^TReference;
  118. tloc = (LOC_INVALID,
  119. LOC_REGISTER,
  120. LOC_MEM,
  121. LOC_REFERENCE,
  122. LOC_JUMP,
  123. { the alpha doesn't have flags, but this }
  124. { avoid some conditional compiling }
  125. { DON'T USE for the alpha }
  126. LOC_FLAGS,
  127. LOC_CREGISTER,
  128. LOC_CONST);
  129. tlocation = record
  130. case loc : tloc of
  131. LOC_REFERENCE,LOC_MEM : (reference : treference);
  132. LOC_REGISTER : (register : tregister);
  133. end;
  134. {*****************************************************************************
  135. Operands
  136. *****************************************************************************}
  137. { Types of operand }
  138. toptype=(top_none,top_reg,top_ref,top_const,top_symbol);
  139. toper=record
  140. ot : longint;
  141. case typ : toptype of
  142. top_none : ();
  143. top_reg : (reg:tregister);
  144. top_ref : (ref:preference);
  145. top_const : (val:longint);
  146. top_symbol : (sym:pasmsymbol;symofs:longint);
  147. end;
  148. Const
  149. { offsets for the integer and floating point registers }
  150. INT_REG = 0;
  151. FLOAT_REG = 32;
  152. { operator qualifiers }
  153. OQ_CHOPPED_ROUNDING = $01; { /C }
  154. OQ_ROUNDING_MODE_DYNAMIC = $02; { /D }
  155. OQ_ROUND_TOWARD_MINUS_INFINITY = $04; { /M }
  156. OQ_INEXACT_RESULT_ENABLE = $08; { /I }
  157. OQ_SOFTWARE_COMPLETION_ENABLE = $10; { /S }
  158. OQ_FLOATING_UNDERFLOW_ENABLE = $20; { /U }
  159. OQ_INTEGER_OVERFLOW_ENABLE = $40; { /V }
  160. {*****************************************************************************
  161. Opcode propeties (needed for optimizer)
  162. *****************************************************************************}
  163. {$ifndef NOOPT}
  164. Type
  165. {What an instruction can change}
  166. TInsChange = (Ch_None);
  167. {$endif}
  168. { resets all values of ref to defaults }
  169. procedure reset_reference(var ref : treference);
  170. { set mostly used values of a new reference }
  171. function new_reference(base : tregister;offset : longint) : preference;
  172. function newreference(const r : treference) : preference;
  173. procedure disposereference(var r : preference);
  174. function reg2str(r : tregister) : string;
  175. {*****************************************************************************
  176. Init/Done
  177. *****************************************************************************}
  178. procedure InitCpu;
  179. procedure DoneCpu;
  180. implementation
  181. uses
  182. verbose;
  183. function reg2str(r : tregister) : string;
  184. begin
  185. if r in [R_0..R_31] then
  186. reg2str:='R'+tostr(longint(r)-longint(R_0))
  187. else if r in [R_F0..R_F31] then
  188. reg2str:='F'+tostr(longint(r)-longint(R_F0))
  189. else internalerror(38991);
  190. end;
  191. procedure reset_reference(var ref : treference);
  192. begin
  193. FillChar(ref,sizeof(treference),0);
  194. end;
  195. function new_reference(base : tregister;offset : longint) : preference;
  196. var
  197. r : preference;
  198. begin
  199. new(r);
  200. FillChar(r^,sizeof(treference),0);
  201. r^.offset:=offset;
  202. r^.alignment:=8;
  203. new_reference:=r;
  204. end;
  205. function newreference(const r : treference) : preference;
  206. var
  207. p : preference;
  208. begin
  209. new(p);
  210. p^:=r;
  211. newreference:=p;
  212. end;
  213. procedure disposereference(var r : preference);
  214. begin
  215. dispose(r);
  216. r:=Nil;
  217. end;
  218. {*****************************************************************************
  219. Init/Done
  220. *****************************************************************************}
  221. procedure InitCpu;
  222. begin
  223. end;
  224. procedure DoneCpu;
  225. begin
  226. end;
  227. end.
  228. {
  229. $Log$
  230. Revision 1.1 2000-07-13 06:30:11 michael
  231. + Initial import
  232. Revision 1.1 2000/07/09 10:40:12 peter
  233. * renamed to lowercase
  234. Revision 1.1 2000/03/09 20:28:00 florian
  235. * initial release derieved from the ALPHA cpubase.pas, the
  236. file still contains some ALPHA stuff
  237. }