2
0

cpubase.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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. {the return_result_reg, is used inside the called function to store its return
  115. value when that is a scalar value otherwise a pointer to the address of the
  116. result is placed inside it}
  117. return_result_reg = accumulator;
  118. {the function_result_reg contains the function result after a call to a scalar
  119. function othewise it contains a pointer to the returned result}
  120. function_result_reg = accumulator;
  121. fpu_result_reg = R_F0;
  122. global_pointer = R_29;
  123. return_pointer = R_26;
  124. { it is used to pass the offset to the destructor helper routine }
  125. vmt_offset_reg = R_1;
  126. { low and high of the available maximum width integer general purpose }
  127. { registers }
  128. LoGPReg = R_0;
  129. HiGPReg = R_31;
  130. { low and high of every possible width general purpose register (same as
  131. above on most architctures apart from the 80x86) }
  132. LoReg = R_0;
  133. HiReg = R_31;
  134. { Constant defining possibly all registers which might require saving }
  135. ALL_REGISTERS = [firstreg..lastreg];
  136. general_registers = [R_0..R_31];
  137. availabletempregsint = [R_0..R_14,R_16..R_25,R_28];
  138. availabletempregsfpu = [R_F0..R_F30];
  139. availabletempregsmm = [];
  140. intregs = [R_0..R_31];
  141. usableregsint = [];
  142. c_countusableregsint = 26;
  143. maxfpuregs = 32;
  144. fpuregs = [R_F0..R_F31];
  145. usableregsfpu = [];
  146. c_countusableregsfpu = 31;
  147. mmregs = [];
  148. usableregsmm = [];
  149. c_countusableregsmm = 0;
  150. max_operands = 4;
  151. registers_saved_on_cdecl = [R_9..R_14,R_F2..R_F9];
  152. firstsaveintreg = R_NO;
  153. lastsaveintreg = R_NO;
  154. firstsavefpureg = R_NO;
  155. lastsavefpureg = R_NO;
  156. firstsavemmreg = R_NO;
  157. lastsavemmreg = R_NO;
  158. maxvarregs = 6;
  159. varregs : Array [1..maxvarregs] of Tregister =
  160. (R_9,R_10,R_11,R_12,R_13,R_14);
  161. maxfpuvarregs = 8;
  162. { Registers which are defined as scratch and no need to save across
  163. routine calls or in assembler blocks.
  164. }
  165. max_scratch_regs = 2;
  166. scratch_regs : array[1..max_scratch_regs] of tregister = (R_1,R_2);
  167. {*****************************************************************************
  168. GDB Information
  169. *****************************************************************************}
  170. { Register indexes for stabs information, when some
  171. parameters or variables are stored in registers.
  172. }
  173. stab_regindex : array[tregister] of shortint =
  174. (0,
  175. 0,0,0,0,0,0,0,0,0,0,
  176. 0,0,0,0,0,0,0,0,0,0,
  177. 0,0,0,0,0,0,0,0,0,0,
  178. 0,0,
  179. 0,0,0,0,0,0,0,0,0,0,
  180. 0,0,0,0,0,0,0,0,0,0,
  181. 0,0,0,0,0,0,0,0,0,0,
  182. 0,0
  183. );
  184. {*****************************************************************************
  185. Flags
  186. *****************************************************************************}
  187. type
  188. { The Alpha doesn't have flags but some generic code depends on this type. }
  189. TResFlags = (F_NO);
  190. { reference record }
  191. pparareference = ^tparareference;
  192. tparareference = packed record
  193. index : tregister;
  194. offset : longint;
  195. end;
  196. trefoptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  197. TReference = record
  198. offset : aword;
  199. symbol : tasmsymbol;
  200. base : tregister;
  201. { The index isn't used by the alpha port, but some generic code depends on it }
  202. index : tregister;
  203. is_immediate : boolean;
  204. offsetfixup : word; {needed for inline}
  205. options : trefoptions;
  206. { the boundary to which the reference is surely aligned }
  207. alignment : byte;
  208. end;
  209. PReference = ^TReference;
  210. TLoc=(
  211. LOC_INVALID, { added for tracking problems}
  212. LOC_CONSTANT, { constant value }
  213. LOC_JUMP, { boolean results only, jump to false or true label }
  214. LOC_FLAGS, { boolean results only, flags are set }
  215. LOC_CREFERENCE, { in memory constant value reference (cannot change) }
  216. LOC_REFERENCE, { in memory value }
  217. LOC_REGISTER, { in a processor register }
  218. LOC_CREGISTER, { Constant register which shouldn't be modified }
  219. LOC_FPUREGISTER, { FPU stack }
  220. LOC_CFPUREGISTER, { if it is a FPU register variable on the fpu stack }
  221. LOC_SSEREGISTER,
  222. LOC_CSSEREGISTER,
  223. LOC_CMMREGISTER,
  224. LOC_MMREGISTER
  225. );
  226. { tparamlocation describes where a parameter for a procedure is stored.
  227. References are given from the caller's point of view. The usual
  228. TLocation isn't used, because contains a lot of unnessary fields.
  229. }
  230. tparalocation = packed record
  231. size : TCGSize;
  232. loc : TLoc;
  233. sp_fixup : longint;
  234. case TLoc of
  235. LOC_REFERENCE : (reference : tparareference);
  236. { segment in reference at the same place as in loc_register }
  237. LOC_REGISTER,LOC_CREGISTER : (
  238. case longint of
  239. 1 : (register,registerhigh : tregister);
  240. { overlay a registerlow }
  241. 2 : (registerlow : tregister);
  242. { overlay a 64 Bit register type }
  243. 3 : (reg64 : tregister64);
  244. 4 : (register64 : tregister64);
  245. );
  246. end;
  247. tlocation = packed record
  248. loc : TLoc;
  249. size : TCGSize;
  250. case TLoc of
  251. LOC_CONSTANT : (
  252. case longint of
  253. 1 : (value : AWord);
  254. { can't do this, this layout depends on the host cpu. Use }
  255. { lo(valueqword)/hi(valueqword) instead (JM) }
  256. { 2 : (valuelow, valuehigh:AWord); }
  257. { overlay a complete 64 Bit value }
  258. 3 : (valueqword : qword);
  259. );
  260. LOC_CREFERENCE,
  261. LOC_REFERENCE : (reference : treference);
  262. { segment in reference at the same place as in loc_register }
  263. LOC_REGISTER,LOC_CREGISTER : (
  264. case longint of
  265. 1 : (register,registerhigh,segment : tregister);
  266. { overlay a registerlow }
  267. 2 : (registerlow : tregister);
  268. { overlay a 64 Bit register type }
  269. 3 : (reg64 : tregister64);
  270. 4 : (register64 : tregister64);
  271. );
  272. end;
  273. {*****************************************************************************
  274. Operands
  275. *****************************************************************************}
  276. { Types of operand }
  277. toptype=(top_none,top_reg,top_ref,top_const,top_symbol);
  278. toper=record
  279. ot : longint;
  280. case typ : toptype of
  281. top_none : ();
  282. top_reg : (reg:tregister);
  283. top_ref : (ref:preference);
  284. top_const : (val:longint);
  285. top_symbol : (sym:tasmsymbol;symofs:longint);
  286. end;
  287. const
  288. { Registers which must be saved when calling a routine declared as
  289. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  290. saved should be the ones as defined in the target ABI and / or GCC.
  291. This value can be deduced from the CALLED_USED_REGISTERS array in the
  292. GCC source.
  293. }
  294. std_saved_registers = [];
  295. { Required parameter alignment when calling a routine declared as
  296. stdcall and cdecl. The alignment value should be the one defined
  297. by GCC or the target ABI.
  298. The value of this constant is equal to the constant
  299. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  300. }
  301. std_param_align = 8;
  302. { offsets for the integer and floating point registers }
  303. INT_REG = 0;
  304. FLOAT_REG = 32;
  305. { operator qualifiers }
  306. OQ_CHOPPED_ROUNDING = $01; { /C }
  307. OQ_ROUNDING_MODE_DYNAMIC = $02; { /D }
  308. OQ_ROUND_TOWARD_MINUS_INFINITY = $04; { /M }
  309. OQ_INEXACT_RESULT_ENABLE = $08; { /I }
  310. OQ_SOFTWARE_COMPLETION_ENABLE = $10; { /S }
  311. OQ_FLOATING_UNDERFLOW_ENABLE = $20; { /U }
  312. OQ_INTEGER_OVERFLOW_ENABLE = $40; { /V }
  313. {*****************************************************************************
  314. Opcode propeties (needed for optimizer)
  315. *****************************************************************************}
  316. {$ifndef NOOPT}
  317. Type
  318. {What an instruction can change}
  319. TInsChange = (Ch_None);
  320. {$endif}
  321. { resets all values of ref to defaults }
  322. procedure reset_reference(var ref : treference);
  323. { set mostly used values of a new reference }
  324. function new_reference(base : tregister;offset : longint) : preference;
  325. function newreference(const r : treference) : preference;
  326. procedure disposereference(var r : preference);
  327. function reg2str(r : tregister) : string;
  328. {*****************************************************************************
  329. Init/Done
  330. *****************************************************************************}
  331. procedure InitCpu;
  332. procedure DoneCpu;
  333. implementation
  334. uses
  335. verbose;
  336. function reg2str(r : tregister) : string;
  337. begin
  338. if r in [R_0..R_31] then
  339. reg2str:='R'+tostr(longint(r)-longint(R_0))
  340. else if r in [R_F0..R_F31] then
  341. reg2str:='F'+tostr(longint(r)-longint(R_F0))
  342. else internalerror(38991);
  343. end;
  344. procedure reset_reference(var ref : treference);
  345. begin
  346. FillChar(ref,sizeof(treference),0);
  347. end;
  348. function new_reference(base : tregister;offset : longint) : preference;
  349. var
  350. r : preference;
  351. begin
  352. new(r);
  353. FillChar(r^,sizeof(treference),0);
  354. r^.offset:=offset;
  355. r^.alignment:=8;
  356. new_reference:=r;
  357. end;
  358. function newreference(const r : treference) : preference;
  359. var
  360. p : preference;
  361. begin
  362. new(p);
  363. p^:=r;
  364. newreference:=p;
  365. end;
  366. procedure disposereference(var r : preference);
  367. begin
  368. dispose(r);
  369. r:=Nil;
  370. end;
  371. {*****************************************************************************
  372. Init/Done
  373. *****************************************************************************}
  374. procedure InitCpu;
  375. begin
  376. end;
  377. procedure DoneCpu;
  378. begin
  379. end;
  380. end.
  381. {
  382. $Log$
  383. Revision 1.6 2002-11-17 18:26:15 mazen
  384. * fixed a compilation bug accmulator-->accumulator, in definition of return_result_reg
  385. Revision 1.5 2002/11/17 17:49:08 mazen
  386. + 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
  387. Revision 1.4 2002/09/29 23:54:12 florian
  388. * alpha compiles again, changes to common code not yet commited
  389. Revision 1.3 2002/09/29 23:42:45 florian
  390. * several fixes to get forward with alpha compilation
  391. Revision 1.2 2002/09/07 15:25:10 peter
  392. * old logs removed and tabs fixed
  393. Revision 1.1 2002/08/18 09:06:54 florian
  394. * alpha files moved compiler/alpha
  395. }