cpubase.pas 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. {
  2. $Id$
  3. Copyright (C) 1998-2000 by Florian Klaempfl
  4. this unit implements an asmlistitem class for the DEC Alpha
  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_ADDF,A_ADDG,A_ADDL,A_ADDQ,
  24. A_ADDS,A_ADDT,A_AMASK,A_AND,A_BEQ,A_BGE,
  25. A_BGT,A_BIC,A_BIS,A_BLBC,A_BLBS,A_BLE,
  26. A_BLT,A_BNE,A_BR,A_BSR,A_CALL_PAL,A_CMOVEQ,
  27. A_CMOVGE,A_CMOVGT,A_CMOVLBC,A_CMOVLBS,A_CMOVLE,A_CMOVLT,
  28. A_CMOVNE,A_CMPBGE,A_CMPEQ,A_CMPGEQ,A_CMPGLE,A_CMPGLT,
  29. A_CMPLE,A_CMPLT,A_CMPTEQ,A_CMPTLE,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TB,A_SEXTW,A_SLL,A_SQRTF,A_SQRTG,A_SQRTS,
  51. A_SQRTT,A_SRA,A_SRL,A_STB,A_STF,A_STG,
  52. A_STS,A_STL,A_STL_C,A_STQ,A_STQ_C,A_STQ_U,
  53. A_STT,A_STW,A_SUBF,A_SUBG,A_SUBL,
  54. A_SUBQ,A_SUBS,A_SUBT,A_TRAPB,A_UMULH,
  55. A_UNPKBL,A_UNPKBW,A_WH64,A_WMB,A_XOR,A_ZAP,
  56. A_ZAPNOT
  57. { Psuedo code understood by the gnu assembler }
  58. ,A_LDGP);
  59. Const
  60. firstop = low(tasmop);
  61. lastop = high(tasmop);
  62. type
  63. TAsmCond =
  64. (
  65. 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,
  66. 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,
  67. C_PE,C_PO,C_S,C_Z
  68. );
  69. Type
  70. { ALL registers }
  71. TRegister = (R_NO, { R_NO is Mandatory, signifies no register }
  72. R_0,R_1,R_2,R_3,R_4,R_5,R_6,R_7,R_8,R_9,
  73. R_10,R_11,R_12,R_13,R_14,R_15,R_16,R_17,R_18,R_19,
  74. R_20,R_21,R_22,R_23,R_24,R_25,R_26,R_27,R_28,R_29,
  75. R_30,R_31,
  76. R_F0,R_F1,R_F2,R_F3,R_F4,R_F5,R_F6,R_F7,R_F8,R_F9,
  77. R_F10,R_F11,R_F12,R_F13,R_F14,R_F15,R_F16,R_F17,R_F18,R_F19,
  78. R_F20,R_F21,R_F22,R_F23,R_F24,R_F25,R_F26,R_F27,R_F28,R_F29,
  79. R_F30,R_F31);
  80. TRegisterset = Set of TRegister;
  81. { Constants describing the registers }
  82. Const
  83. Firstreg = R_0;
  84. LastReg = R_F31;
  85. stack_pointer = R_30;
  86. frame_pointer = R_15;
  87. self_pointer = R_16;
  88. accumulator = R_0;
  89. global_pointer = R_29;
  90. return_pointer = R_26;
  91. { it is used to pass the offset to the destructor helper routine }
  92. vmt_offset_reg = R_1;
  93. max_scratch_regs = 2;
  94. scratch_regs : array[1..max_scratch_regs] of tregister = (R_1,R_2);
  95. { low and high of the available maximum width integer general purpose }
  96. { registers }
  97. LoGPReg = R_0;
  98. HiGPReg = R_31;
  99. { low and high of every possible width general purpose register (same as }
  100. { above on most architctures apart from the 80x86) }
  101. LoReg = R_0;
  102. HiReg = R_31;
  103. cpuflags = [cf_64bitaddr];
  104. { sizes }
  105. pointersize = 8;
  106. extended_size = 16;
  107. general_registers = [R_0..R_31];
  108. intregs = [R_0..R_31];
  109. fpuregs = [R_F0..R_F31];
  110. mmregs = [];
  111. availabletempregsint = [R_0..R_14,R_16..R_25,R_28];
  112. availabletempregsfpu = [R_F0..R_F30];
  113. availabletempregsmm = [];
  114. c_countusableregsint = 26;
  115. c_countusableregsfpu = 31;
  116. c_countusableregsmm = 0;
  117. max_operands = 4;
  118. registers_saved_on_cdecl = [R_9..R_14,R_F2..R_F9];
  119. maxvarregs = 6;
  120. varregs : Array [1..maxvarregs] of Tregister =
  121. (R_9,R_10,R_11,R_12,R_13,R_14);
  122. Type
  123. TReference = record
  124. offset : aword;
  125. symbol : pasmsymbol;
  126. base : tregister;
  127. is_immediate : boolean;
  128. offsetfixup : word; {needed for inline}
  129. { the boundary to which the reference is surely aligned }
  130. alignment : byte;
  131. end;
  132. PReference = ^TReference;
  133. tloc = (LOC_INVALID,
  134. LOC_REGISTER,
  135. LOC_MEM,
  136. LOC_REFERENCE,
  137. LOC_JUMP,
  138. { the alpha doesn't have flags, but this }
  139. { avoid some conditional compiling }
  140. { DON'T USE for the alpha }
  141. LOC_FLAGS,
  142. LOC_CREGISTER,
  143. LOC_CONST);
  144. tlocation = record
  145. case loc : tloc of
  146. LOC_REFERENCE,LOC_MEM : (reference : treference);
  147. LOC_REGISTER : (register : tregister);
  148. end;
  149. {*****************************************************************************
  150. Operands
  151. *****************************************************************************}
  152. { Types of operand }
  153. toptype=(top_none,top_reg,top_ref,top_const,top_symbol);
  154. toper=record
  155. ot : longint;
  156. case typ : toptype of
  157. top_none : ();
  158. top_reg : (reg:tregister);
  159. top_ref : (ref:preference);
  160. top_const : (val:longint);
  161. top_symbol : (sym:pasmsymbol;symofs:longint);
  162. end;
  163. Const
  164. { offsets for the integer and floating point registers }
  165. INT_REG = 0;
  166. FLOAT_REG = 32;
  167. { operator qualifiers }
  168. OQ_CHOPPED_ROUNDING = $01; { /C }
  169. OQ_ROUNDING_MODE_DYNAMIC = $02; { /D }
  170. OQ_ROUND_TOWARD_MINUS_INFINITY = $04; { /M }
  171. OQ_INEXACT_RESULT_ENABLE = $08; { /I }
  172. OQ_SOFTWARE_COMPLETION_ENABLE = $10; { /S }
  173. OQ_FLOATING_UNDERFLOW_ENABLE = $20; { /U }
  174. OQ_INTEGER_OVERFLOW_ENABLE = $40; { /V }
  175. {*****************************************************************************
  176. Opcode propeties (needed for optimizer)
  177. *****************************************************************************}
  178. {$ifndef NOOPT}
  179. Type
  180. {What an instruction can change}
  181. TInsChange = (Ch_None);
  182. {$endif}
  183. { resets all values of ref to defaults }
  184. procedure reset_reference(var ref : treference);
  185. { set mostly used values of a new reference }
  186. function new_reference(base : tregister;offset : longint) : preference;
  187. function newreference(const r : treference) : preference;
  188. procedure disposereference(var r : preference);
  189. function reg2str(r : tregister) : string;
  190. {*****************************************************************************
  191. Init/Done
  192. *****************************************************************************}
  193. procedure InitCpu;
  194. procedure DoneCpu;
  195. implementation
  196. uses
  197. verbose;
  198. function reg2str(r : tregister) : string;
  199. begin
  200. if r in [R_0..R_31] then
  201. reg2str:='R'+tostr(longint(r)-longint(R_0))
  202. else if r in [R_F0..R_F31] then
  203. reg2str:='F'+tostr(longint(r)-longint(R_F0))
  204. else internalerror(38991);
  205. end;
  206. procedure reset_reference(var ref : treference);
  207. begin
  208. FillChar(ref,sizeof(treference),0);
  209. end;
  210. function new_reference(base : tregister;offset : longint) : preference;
  211. var
  212. r : preference;
  213. begin
  214. new(r);
  215. FillChar(r^,sizeof(treference),0);
  216. r^.offset:=offset;
  217. r^.alignment:=8;
  218. new_reference:=r;
  219. end;
  220. function newreference(const r : treference) : preference;
  221. var
  222. p : preference;
  223. begin
  224. new(p);
  225. p^:=r;
  226. newreference:=p;
  227. end;
  228. procedure disposereference(var r : preference);
  229. begin
  230. dispose(r);
  231. r:=Nil;
  232. end;
  233. {*****************************************************************************
  234. Init/Done
  235. *****************************************************************************}
  236. procedure InitCpu;
  237. begin
  238. end;
  239. procedure DoneCpu;
  240. begin
  241. end;
  242. end.
  243. {
  244. $Log$
  245. Revision 1.2 2002-09-07 15:25:10 peter
  246. * old logs removed and tabs fixed
  247. Revision 1.1 2002/08/18 09:06:54 florian
  248. * alpha files moved compiler/alpha
  249. }