cpubase.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. {
  2. $Id$
  3. Copyright (C) 1998-2000 by Florian Klaempfl
  4. This unit implements an asmlistitem class for the Alpha 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. {
  19. This unit implements an asmlistitem class for the Alpha architecture.
  20. }
  21. unit cpubase;
  22. {$i fpcdefs.inc}
  23. interface
  24. uses
  25. cutils,cclasses,globals,aasmbase,cpuinfo,cginfo;
  26. type
  27. { all registers }
  28. TRegister = (R_NO, { R_NO is Mandatory, signifies no register }
  29. R_0,R_1,R_2,R_3,R_4,R_5,R_6,R_7,R_8,R_9,
  30. R_10,R_11,R_12,R_13,R_14,R_15,R_16,R_17,R_18,R_19,
  31. R_20,R_21,R_22,R_23,R_24,R_25,R_26,R_27,R_28,R_29,
  32. R_30,R_31,
  33. R_F0,R_F1,R_F2,R_F3,R_F4,R_F5,R_F6,R_F7,R_F8,R_F9,
  34. R_F10,R_F11,R_F12,R_F13,R_F14,R_F15,R_F16,R_F17,R_F18,R_F19,
  35. R_F20,R_F21,R_F22,R_F23,R_F24,R_F25,R_F26,R_F27,R_F28,R_F29,
  36. R_F30,R_F31);
  37. tasmop = (A_ADDF,A_ADDG,A_ADDL,A_ADDQ,
  38. A_ADDS,A_ADDT,A_AMASK,A_AND,A_BEQ,A_BGE,
  39. A_BGT,A_BIC,A_BIS,A_BLBC,A_BLBS,A_BLE,
  40. A_BLT,A_BNE,A_BR,A_BSR,A_CALL_PAL,A_CMOVEQ,
  41. A_CMOVGE,A_CMOVGT,A_CMOVLBC,A_CMOVLBS,A_CMOVLE,A_CMOVLT,
  42. A_CMOVNE,A_CMPBGE,A_CMPEQ,A_CMPGEQ,A_CMPGLE,A_CMPGLT,
  43. A_CMPLE,A_CMPLT,A_CMPTEQ,A_CMPTLE,A_CMPTLT,A_CMPTUN,
  44. A_CMPULE,A_CMPULT,A_CPYS,A_CPYSE,A_CPYSN,A_CTLZ,
  45. A_CTPOP,A_CTTZ,A_CVTDG,A_CVTGD,A_CVTGF,A_CVTGQ,
  46. A_CVTLQ,A_CVTQF,A_CVTQG,A_CVTQL,A_CVTQS,A_CVTQT,
  47. A_CVTST,A_CVTTQ,A_CVTTS,A_DIVF,A_DIVG,A_DIVS,
  48. A_DIVT,A_ECB,A_EQV,A_EXCB,A_EXTBL,A_EXTLH,
  49. A_EXTLL,A_EXTQH,A_EXTQL,A_EXTWH,A_EXTWL,A_FBEQ,
  50. A_FBGE,A_FBGT,A_FBLE,A_FBLT,A_FBNE,A_FCMOVEQ,
  51. A_FCMOVGE,A_FCMOVGT,A_FCMOVLE,A_FCMOVLT,A_FCMOVNE,A_FETCH,
  52. A_FETCH_M,A_FTOIS,A_FTOIT,A_IMPLVER,A_INSBL,A_INSLH,
  53. A_INSLL,A_INSQH,A_INSQL,A_INSWH,A_INSWL,A_ITOFF,
  54. A_ITOFS,A_ITOFT,A_JMP,A_JSR,A_JSR_COROUTINE,A_LDA,
  55. A_LDAH,A_LDBU,A_LDWU,A_LDF,A_LDG,A_LDL,
  56. A_LDL_L,A_LDQ,A_LDQ_L,A_LDQ_U,A_LDS,A_LDT,
  57. A_MAXSB8,A_MAXSW4,A_MAXUB8,A_MAXUW4,A_MB,A_MF_FPCR,
  58. A_MINSB8,A_MINSW4,A_MINUB8,A_MINUW4,A_MSKBL,A_MSKLH,
  59. A_MSKLL,A_MSKQH,A_MSKQL,A_MSKWH,A_MSKWL,A_MT_FPCR,
  60. A_MULF,A_MULG,A_MULL,A_MULQ,
  61. A_MULS,A_MULT,A_ORNOT,A_PERR,A_PKLB,A_PKWB,
  62. A_RC,A_RET,A_RPCC,A_RS,A_S4ADDL,A_S4ADDQ,
  63. A_S4SUBL,A_S4SUBQ,A_S8ADDL,A_S8ADDQ,A_S8SUBL,A_S8SUBQ,
  64. A_SEXTB,A_SEXTW,A_SLL,A_SQRTF,A_SQRTG,A_SQRTS,
  65. A_SQRTT,A_SRA,A_SRL,A_STB,A_STF,A_STG,
  66. A_STS,A_STL,A_STL_C,A_STQ,A_STQ_C,A_STQ_U,
  67. A_STT,A_STW,A_SUBF,A_SUBG,A_SUBL,
  68. A_SUBQ,A_SUBS,A_SUBT,A_TRAPB,A_UMULH,
  69. A_UNPKBL,A_UNPKBW,A_WH64,A_WMB,A_XOR,A_ZAP,
  70. A_ZAPNOT
  71. { Psuedo code understood by the gnu assembler }
  72. ,A_LDGP);
  73. const
  74. firstop = low(tasmop);
  75. lastop = high(tasmop);
  76. std_reg2str : array[tregister] of string[4] = (
  77. '',
  78. '','','','','','','','','','',
  79. '','','','','','','','','','',
  80. '','','','','','','','','','',
  81. '','',
  82. '','','','','','','','','','',
  83. '','','','','','','','','','',
  84. '','','','','','','','','','',
  85. '',''
  86. );
  87. type
  88. TAsmCond =
  89. (
  90. 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,
  91. 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,
  92. C_PE,C_PO,C_S,C_Z
  93. );
  94. TRegisterset = Set of TRegister;
  95. tregister64 = tregister;
  96. Const
  97. Firstreg = R_0;
  98. LastReg = R_F31;
  99. {*****************************************************************************
  100. Default generic sizes
  101. *****************************************************************************}
  102. { Defines the default address size for a processor, }
  103. OS_ADDR = OS_64;
  104. { the natural int size for a processor, }
  105. OS_INT = OS_64;
  106. { the maximum float size for a processor, }
  107. OS_FLOAT = OS_F80;
  108. { the size of a vector register for a processor }
  109. OS_VECTOR = OS_M64;
  110. stack_pointer_reg = R_30;
  111. frame_pointer_reg = R_15;
  112. self_pointer_reg = R_16;
  113. accumulator = R_0;
  114. fpu_result_reg = R_F0;
  115. global_pointer = R_29;
  116. return_pointer = R_26;
  117. { it is used to pass the offset to the destructor helper routine }
  118. vmt_offset_reg = R_1;
  119. { low and high of the available maximum width integer general purpose }
  120. { registers }
  121. LoGPReg = R_0;
  122. HiGPReg = R_31;
  123. { low and high of every possible width general purpose register (same as
  124. above on most architctures apart from the 80x86) }
  125. LoReg = R_0;
  126. HiReg = R_31;
  127. { Constant defining possibly all registers which might require saving }
  128. ALL_REGISTERS = [firstreg..lastreg];
  129. general_registers = [R_0..R_31];
  130. availabletempregsint = [R_0..R_14,R_16..R_25,R_28];
  131. availabletempregsfpu = [R_F0..R_F30];
  132. availabletempregsmm = [];
  133. intregs = [R_0..R_31];
  134. usableregsint = [];
  135. c_countusableregsint = 26;
  136. maxfpuregs = 32;
  137. fpuregs = [R_F0..R_F31];
  138. usableregsfpu = [];
  139. c_countusableregsfpu = 31;
  140. mmregs = [];
  141. usableregsmm = [];
  142. c_countusableregsmm = 0;
  143. max_operands = 4;
  144. registers_saved_on_cdecl = [R_9..R_14,R_F2..R_F9];
  145. firstsaveintreg = R_NO;
  146. lastsaveintreg = R_NO;
  147. firstsavefpureg = R_NO;
  148. lastsavefpureg = R_NO;
  149. firstsavemmreg = R_NO;
  150. lastsavemmreg = R_NO;
  151. maxvarregs = 6;
  152. varregs : Array [1..maxvarregs] of Tregister =
  153. (R_9,R_10,R_11,R_12,R_13,R_14);
  154. maxfpuvarregs = 8;
  155. { Registers which are defined as scratch and no need to save across
  156. routine calls or in assembler blocks.
  157. }
  158. max_scratch_regs = 2;
  159. scratch_regs : array[1..max_scratch_regs] of tregister = (R_1,R_2);
  160. {*****************************************************************************
  161. GDB Information
  162. *****************************************************************************}
  163. { Register indexes for stabs information, when some
  164. parameters or variables are stored in registers.
  165. }
  166. stab_regindex : array[tregister] of shortint =
  167. (0,
  168. 0,0,0,0,0,0,0,0,0,0,
  169. 0,0,0,0,0,0,0,0,0,0,
  170. 0,0,0,0,0,0,0,0,0,0,
  171. 0,0,
  172. 0,0,0,0,0,0,0,0,0,0,
  173. 0,0,0,0,0,0,0,0,0,0,
  174. 0,0,0,0,0,0,0,0,0,0,
  175. 0,0
  176. );
  177. {*****************************************************************************
  178. Flags
  179. *****************************************************************************}
  180. type
  181. { The Alpha doesn't have flags but some generic code depends on this type. }
  182. TResFlags = (F_NO);
  183. { reference record }
  184. pparareference = ^tparareference;
  185. tparareference = packed record
  186. index : tregister;
  187. offset : longint;
  188. end;
  189. trefoptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  190. TReference = record
  191. offset : aword;
  192. symbol : tasmsymbol;
  193. base : tregister;
  194. { The index isn't used by the alpha port, but some generic code depends on it }
  195. index : tregister;
  196. is_immediate : boolean;
  197. offsetfixup : word; {needed for inline}
  198. options : trefoptions;
  199. { the boundary to which the reference is surely aligned }
  200. alignment : byte;
  201. end;
  202. PReference = ^TReference;
  203. TLoc=(
  204. LOC_INVALID, { added for tracking problems}
  205. LOC_CONSTANT, { constant value }
  206. LOC_JUMP, { boolean results only, jump to false or true label }
  207. LOC_FLAGS, { boolean results only, flags are set }
  208. LOC_CREFERENCE, { in memory constant value reference (cannot change) }
  209. LOC_REFERENCE, { in memory value }
  210. LOC_REGISTER, { in a processor register }
  211. LOC_CREGISTER, { Constant register which shouldn't be modified }
  212. LOC_FPUREGISTER, { FPU stack }
  213. LOC_CFPUREGISTER, { if it is a FPU register variable on the fpu stack }
  214. LOC_SSEREGISTER,
  215. LOC_CSSEREGISTER,
  216. LOC_CMMREGISTER,
  217. LOC_MMREGISTER
  218. );
  219. { tparamlocation describes where a parameter for a procedure is stored.
  220. References are given from the caller's point of view. The usual
  221. TLocation isn't used, because contains a lot of unnessary fields.
  222. }
  223. tparalocation = packed record
  224. size : TCGSize;
  225. loc : TLoc;
  226. sp_fixup : longint;
  227. case TLoc of
  228. LOC_REFERENCE : (reference : tparareference);
  229. { segment in reference at the same place as in loc_register }
  230. LOC_REGISTER,LOC_CREGISTER : (
  231. case longint of
  232. 1 : (register,registerhigh : tregister);
  233. { overlay a registerlow }
  234. 2 : (registerlow : tregister);
  235. { overlay a 64 Bit register type }
  236. 3 : (reg64 : tregister64);
  237. 4 : (register64 : tregister64);
  238. );
  239. end;
  240. tlocation = packed record
  241. loc : TLoc;
  242. size : TCGSize;
  243. case TLoc of
  244. LOC_CONSTANT : (
  245. case longint of
  246. 1 : (value : AWord);
  247. { can't do this, this layout depends on the host cpu. Use }
  248. { lo(valueqword)/hi(valueqword) instead (JM) }
  249. { 2 : (valuelow, valuehigh:AWord); }
  250. { overlay a complete 64 Bit value }
  251. 3 : (valueqword : qword);
  252. );
  253. LOC_CREFERENCE,
  254. LOC_REFERENCE : (reference : treference);
  255. { segment in reference at the same place as in loc_register }
  256. LOC_REGISTER,LOC_CREGISTER : (
  257. case longint of
  258. 1 : (register,registerhigh,segment : tregister);
  259. { overlay a registerlow }
  260. 2 : (registerlow : tregister);
  261. { overlay a 64 Bit register type }
  262. 3 : (reg64 : tregister64);
  263. 4 : (register64 : tregister64);
  264. );
  265. end;
  266. {*****************************************************************************
  267. Operands
  268. *****************************************************************************}
  269. { Types of operand }
  270. toptype=(top_none,top_reg,top_ref,top_const,top_symbol);
  271. toper=record
  272. ot : longint;
  273. case typ : toptype of
  274. top_none : ();
  275. top_reg : (reg:tregister);
  276. top_ref : (ref:preference);
  277. top_const : (val:longint);
  278. top_symbol : (sym:tasmsymbol;symofs:longint);
  279. end;
  280. const
  281. { Registers which must be saved when calling a routine declared as
  282. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  283. saved should be the ones as defined in the target ABI and / or GCC.
  284. This value can be deduced from the CALLED_USED_REGISTERS array in the
  285. GCC source.
  286. }
  287. std_saved_registers = [];
  288. { Required parameter alignment when calling a routine declared as
  289. stdcall and cdecl. The alignment value should be the one defined
  290. by GCC or the target ABI.
  291. The value of this constant is equal to the constant
  292. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  293. }
  294. std_param_align = 8;
  295. { offsets for the integer and floating point registers }
  296. INT_REG = 0;
  297. FLOAT_REG = 32;
  298. { operator qualifiers }
  299. OQ_CHOPPED_ROUNDING = $01; { /C }
  300. OQ_ROUNDING_MODE_DYNAMIC = $02; { /D }
  301. OQ_ROUND_TOWARD_MINUS_INFINITY = $04; { /M }
  302. OQ_INEXACT_RESULT_ENABLE = $08; { /I }
  303. OQ_SOFTWARE_COMPLETION_ENABLE = $10; { /S }
  304. OQ_FLOATING_UNDERFLOW_ENABLE = $20; { /U }
  305. OQ_INTEGER_OVERFLOW_ENABLE = $40; { /V }
  306. {*****************************************************************************
  307. Opcode propeties (needed for optimizer)
  308. *****************************************************************************}
  309. {$ifndef NOOPT}
  310. Type
  311. {What an instruction can change}
  312. TInsChange = (Ch_None);
  313. {$endif}
  314. { resets all values of ref to defaults }
  315. procedure reset_reference(var ref : treference);
  316. { set mostly used values of a new reference }
  317. function new_reference(base : tregister;offset : longint) : preference;
  318. function newreference(const r : treference) : preference;
  319. procedure disposereference(var r : preference);
  320. function reg2str(r : tregister) : string;
  321. {*****************************************************************************
  322. Init/Done
  323. *****************************************************************************}
  324. procedure InitCpu;
  325. procedure DoneCpu;
  326. implementation
  327. uses
  328. verbose;
  329. function reg2str(r : tregister) : string;
  330. begin
  331. if r in [R_0..R_31] then
  332. reg2str:='R'+tostr(longint(r)-longint(R_0))
  333. else if r in [R_F0..R_F31] then
  334. reg2str:='F'+tostr(longint(r)-longint(R_F0))
  335. else internalerror(38991);
  336. end;
  337. procedure reset_reference(var ref : treference);
  338. begin
  339. FillChar(ref,sizeof(treference),0);
  340. end;
  341. function new_reference(base : tregister;offset : longint) : preference;
  342. var
  343. r : preference;
  344. begin
  345. new(r);
  346. FillChar(r^,sizeof(treference),0);
  347. r^.offset:=offset;
  348. r^.alignment:=8;
  349. new_reference:=r;
  350. end;
  351. function newreference(const r : treference) : preference;
  352. var
  353. p : preference;
  354. begin
  355. new(p);
  356. p^:=r;
  357. newreference:=p;
  358. end;
  359. procedure disposereference(var r : preference);
  360. begin
  361. dispose(r);
  362. r:=Nil;
  363. end;
  364. {*****************************************************************************
  365. Init/Done
  366. *****************************************************************************}
  367. procedure InitCpu;
  368. begin
  369. end;
  370. procedure DoneCpu;
  371. begin
  372. end;
  373. end.
  374. {
  375. $Log$
  376. Revision 1.4 2002-09-29 23:54:12 florian
  377. * alpha compiles again, changes to common code not yet commited
  378. Revision 1.3 2002/09/29 23:42:45 florian
  379. * several fixes to get forward with alpha compilation
  380. Revision 1.2 2002/09/07 15:25:10 peter
  381. * old logs removed and tabs fixed
  382. Revision 1.1 2002/08/18 09:06:54 florian
  383. * alpha files moved compiler/alpha
  384. }