cpubase.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. {
  2. Copyright (C) 1998-2000 by Florian Klaempfl
  3. This unit implements an asmlistitem class for the Alpha architecture.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. {
  18. This unit implements an asmlistitem class for the Alpha architecture.
  19. }
  20. unit cpubase;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. cutils,cclasses,globals,aasmbase,cpuinfo,cginfo;
  25. type
  26. { all registers }
  27. TRegister = (R_NO, { R_NO is Mandatory, signifies no register }
  28. R_0,R_1,R_2,R_3,R_4,R_5,R_6,R_7,R_8,R_9,
  29. R_10,R_11,R_12,R_13,R_14,R_15,R_16,R_17,R_18,R_19,
  30. R_20,R_21,R_22,R_23,R_24,R_25,R_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LL,A_INSQH,A_INSQL,A_INSWH,A_INSWL,A_ITOFF,
  53. A_ITOFS,A_ITOFT,A_JMP,A_JSR,A_JSR_COROUTINE,A_LDA,
  54. A_LDAH,A_LDBU,A_LDWU,A_LDF,A_LDG,A_LDL,
  55. A_LDL_L,A_LDQ,A_LDQ_L,A_LDQ_U,A_LDS,A_LDT,
  56. A_MAXSB8,A_MAXSW4,A_MAXUB8,A_MAXUW4,A_MB,A_MF_FPCR,
  57. A_MINSB8,A_MINSW4,A_MINUB8,A_MINUW4,A_MSKBL,A_MSKLH,
  58. A_MSKLL,A_MSKQH,A_MSKQL,A_MSKWH,A_MSKWL,A_MT_FPCR,
  59. A_MULF,A_MULG,A_MULL,A_MULQ,
  60. A_MULS,A_MULT,A_ORNOT,A_PERR,A_PKLB,A_PKWB,
  61. A_RC,A_RET,A_RPCC,A_RS,A_S4ADDL,A_S4ADDQ,
  62. A_S4SUBL,A_S4SUBQ,A_S8ADDL,A_S8ADDQ,A_S8SUBL,A_S8SUBQ,
  63. A_SEXTB,A_SEXTW,A_SLL,A_SQRTF,A_SQRTG,A_SQRTS,
  64. A_SQRTT,A_SRA,A_SRL,A_STB,A_STF,A_STG,
  65. A_STS,A_STL,A_STL_C,A_STQ,A_STQ_C,A_STQ_U,
  66. A_STT,A_STW,A_SUBF,A_SUBG,A_SUBL,
  67. A_SUBQ,A_SUBS,A_SUBT,A_TRAPB,A_UMULH,
  68. A_UNPKBL,A_UNPKBW,A_WH64,A_WMB,A_XOR,A_ZAP,
  69. A_ZAPNOT
  70. { Psuedo code understood by the gnu assembler }
  71. ,A_LDGP);
  72. const
  73. firstop = low(tasmop);
  74. lastop = high(tasmop);
  75. std_reg2str : array[tregister] of string[4] = (
  76. '',
  77. '','','','','','','','','','',
  78. '','','','','','','','','','',
  79. '','','','','','','','','','',
  80. '','',
  81. '','','','','','','','','','',
  82. '','','','','','','','','','',
  83. '','','','','','','','','','',
  84. '',''
  85. );
  86. type
  87. TAsmCond =
  88. (
  89. 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,
  90. 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,
  91. C_PE,C_PO,C_S,C_Z
  92. );
  93. TRegisterset = Set of TRegister;
  94. tregister64 = tregister;
  95. Const
  96. Firstreg = R_0;
  97. LastReg = R_F31;
  98. {*****************************************************************************
  99. Default generic sizes
  100. *****************************************************************************}
  101. { Defines the default address size for a processor, }
  102. OS_ADDR = OS_64;
  103. { the natural int size for a processor,
  104. has to match osuinttype/ossinttype as initialized in psystem }
  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. maxfpuregs = 32;
  135. max_operands = 4;
  136. registers_saved_on_cdecl = [R_9..R_14,R_F2..R_F9];
  137. maxvarregs = 6;
  138. varregs : Array [1..maxvarregs] of Tregister =
  139. (R_9,R_10,R_11,R_12,R_13,R_14);
  140. maxfpuvarregs = 8;
  141. { Registers which are defined as scratch and no need to save across
  142. routine calls or in assembler blocks.
  143. }
  144. max_scratch_regs = 2;
  145. scratch_regs : array[1..max_scratch_regs] of tregister = (R_1,R_2);
  146. {*****************************************************************************
  147. GDB Information
  148. *****************************************************************************}
  149. { Register indexes for stabs information, when some
  150. parameters or variables are stored in registers.
  151. }
  152. stab_regindex : array[tregister] of shortint =
  153. (0,
  154. 0,0,0,0,0,0,0,0,0,0,
  155. 0,0,0,0,0,0,0,0,0,0,
  156. 0,0,0,0,0,0,0,0,0,0,
  157. 0,0,
  158. 0,0,0,0,0,0,0,0,0,0,
  159. 0,0,0,0,0,0,0,0,0,0,
  160. 0,0,0,0,0,0,0,0,0,0,
  161. 0,0
  162. );
  163. {*****************************************************************************
  164. Flags
  165. *****************************************************************************}
  166. type
  167. { The Alpha doesn't have flags but some generic code depends on this type. }
  168. TResFlags = (F_NO);
  169. { reference record }
  170. pparareference = ^tparareference;
  171. tparareference = packed record
  172. index : tregister;
  173. offset : longint;
  174. end;
  175. trefoptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  176. TReference = record
  177. offset : aword;
  178. symbol : tasmsymbol;
  179. base : tregister;
  180. { The index isn't used by the alpha port, but some generic code depends on it }
  181. index : tregister;
  182. is_immediate : boolean;
  183. offsetfixup : word; {needed for inline}
  184. options : trefoptions;
  185. { the boundary to which the reference is surely aligned }
  186. alignment : byte;
  187. end;
  188. PReference = ^TReference;
  189. TLoc=(
  190. LOC_INVALID, { added for tracking problems}
  191. LOC_CONSTANT, { constant value }
  192. LOC_JUMP, { boolean results only, jump to false or true label }
  193. LOC_FLAGS, { boolean results only, flags are set }
  194. LOC_CREFERENCE, { in memory constant value reference (cannot change) }
  195. LOC_REFERENCE, { in memory value }
  196. LOC_REGISTER, { in a processor register }
  197. LOC_CREGISTER, { Constant register which shouldn't be modified }
  198. LOC_FPUREGISTER, { FPU stack }
  199. LOC_CFPUREGISTER, { if it is a FPU register variable on the fpu stack }
  200. LOC_SSEREGISTER,
  201. LOC_CSSEREGISTER,
  202. LOC_CMMREGISTER,
  203. LOC_MMREGISTER
  204. );
  205. { tparamlocation describes where a parameter for a procedure is stored.
  206. References are given from the caller's point of view. The usual
  207. TLocation isn't used, because contains a lot of unnessary fields.
  208. }
  209. tparalocation = packed record
  210. size : TCGSize;
  211. loc : TLoc;
  212. sp_fixup : longint;
  213. case TLoc of
  214. LOC_REFERENCE : (reference : tparareference);
  215. { segment in reference at the same place as in loc_register }
  216. LOC_REGISTER,LOC_CREGISTER : (
  217. case longint of
  218. 1 : (register,register64.reghi : tregister);
  219. { overlay a register64.reglo }
  220. 2 : (register64.reglo : tregister);
  221. { overlay a 64 Bit register type }
  222. 3 : (reg64 : tregister64);
  223. 4 : (register64 : tregister64);
  224. );
  225. end;
  226. tlocation = packed record
  227. loc : TLoc;
  228. size : TCGSize;
  229. case TLoc of
  230. LOC_CONSTANT : (
  231. case longint of
  232. 1 : (value : AWord);
  233. { can't do this, this layout depends on the host cpu. Use }
  234. { lo(valueqword)/hi(valueqword) instead (JM) }
  235. { 2 : (valuelow, valuehigh:AWord); }
  236. { overlay a complete 64 Bit value }
  237. 3 : (valueqword : qword);
  238. );
  239. LOC_CREFERENCE,
  240. LOC_REFERENCE : (reference : treference);
  241. { segment in reference at the same place as in loc_register }
  242. LOC_REGISTER,LOC_CREGISTER : (
  243. case longint of
  244. 1 : (register,register64.reghi,segment : tregister);
  245. { overlay a register64.reglo }
  246. 2 : (register64.reglo : tregister);
  247. { overlay a 64 Bit register type }
  248. 3 : (reg64 : tregister64);
  249. 4 : (register64 : tregister64);
  250. );
  251. end;
  252. {*****************************************************************************
  253. Operands
  254. *****************************************************************************}
  255. { Types of operand }
  256. toptype=(top_none,top_reg,top_ref,top_const,top_symbol);
  257. toper=record
  258. ot : longint;
  259. case typ : toptype of
  260. top_none : ();
  261. top_reg : (reg:tregister);
  262. top_ref : (ref:preference);
  263. top_const : (val:longint);
  264. top_symbol : (sym:tasmsymbol;symofs:longint);
  265. end;
  266. const
  267. { Registers which must be saved when calling a routine declared as
  268. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  269. saved should be the ones as defined in the target ABI and / or GCC.
  270. This value can be deduced from the CALLED_USED_REGISTERS array in the
  271. GCC source.
  272. }
  273. std_saved_registers = [];
  274. { Required parameter alignment when calling a routine declared as
  275. stdcall and cdecl. The alignment value should be the one defined
  276. by GCC or the target ABI.
  277. The value of this constant is equal to the constant
  278. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  279. }
  280. std_param_align = 8;
  281. { offsets for the integer and floating point registers }
  282. INT_REG = 0;
  283. FLOAT_REG = 32;
  284. { operator qualifiers }
  285. OQ_CHOPPED_ROUNDING = $01; { /C }
  286. OQ_ROUNDING_MODE_DYNAMIC = $02; { /D }
  287. OQ_ROUND_TOWARD_MINUS_INFINITY = $04; { /M }
  288. OQ_INEXACT_RESULT_ENABLE = $08; { /I }
  289. OQ_SOFTWARE_COMPLETION_ENABLE = $10; { /S }
  290. OQ_FLOATING_UNDERFLOW_ENABLE = $20; { /U }
  291. OQ_INTEGER_OVERFLOW_ENABLE = $40; { /V }
  292. {*****************************************************************************
  293. Opcode propeties (needed for optimizer)
  294. *****************************************************************************}
  295. {$ifndef NOOPT}
  296. Type
  297. {What an instruction can change}
  298. TInsChange = (Ch_None);
  299. {$endif}
  300. { resets all values of ref to defaults }
  301. procedure reset_reference(var ref : treference);
  302. { set mostly used values of a new reference }
  303. function new_reference(base : tregister;offset : longint) : preference;
  304. function newreference(const r : treference) : preference;
  305. procedure disposereference(var r : preference);
  306. function reg2str(r : tregister) : string;
  307. {*****************************************************************************
  308. Init/Done
  309. *****************************************************************************}
  310. procedure InitCpu;
  311. procedure DoneCpu;
  312. implementation
  313. uses
  314. verbose;
  315. function reg2str(r : tregister) : string;
  316. begin
  317. if r in [R_0..R_31] then
  318. reg2str:='R'+tostr(longint(r)-longint(R_0))
  319. else if r in [R_F0..R_F31] then
  320. reg2str:='F'+tostr(longint(r)-longint(R_F0))
  321. else internalerror(38991);
  322. end;
  323. procedure reset_reference(var ref : treference);
  324. begin
  325. FillChar(ref,sizeof(treference),0);
  326. end;
  327. function new_reference(base : tregister;offset : longint) : preference;
  328. var
  329. r : preference;
  330. begin
  331. new(r);
  332. FillChar(r^,sizeof(treference),0);
  333. r^.offset:=offset;
  334. r^.alignment:=8;
  335. new_reference:=r;
  336. end;
  337. function newreference(const r : treference) : preference;
  338. var
  339. p : preference;
  340. begin
  341. new(p);
  342. p^:=r;
  343. newreference:=p;
  344. end;
  345. procedure disposereference(var r : preference);
  346. begin
  347. dispose(r);
  348. r:=Nil;
  349. end;
  350. {*****************************************************************************
  351. Init/Done
  352. *****************************************************************************}
  353. procedure InitCpu;
  354. begin
  355. end;
  356. procedure DoneCpu;
  357. begin
  358. end;
  359. end.