cpubase.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Contains the base types for the PowerPC
  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. { This Unit contains the base types for the PowerPC
  19. }
  20. unit cpubase;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. strings,cutils,cclasses,aasmbase,cpuinfo,cginfo;
  25. {*****************************************************************************
  26. Assembler Opcodes
  27. *****************************************************************************}
  28. type
  29. TAsmOp=(A_None,
  30. { normal opcodes }
  31. a_add, a_add_, a_addo, a_addo_, a_addc, a_addc_, a_addco, a_addco_,
  32. a_adde, a_adde_, a_addeo, a_addeo_, a_addi, a_addic, a_addic_, a_addis,
  33. a_addme, a_addme_, a_addmeo, a_addmeo_, a_addze, a_addze_, a_addzeo,
  34. a_addzeo_, a_and, a_and_, a_andc, a_andc_, a_andi_, a_andis_, a_b,
  35. a_ba, a_bl, a_bla, a_bc, a_bca, a_bcl, a_bcla, a_bcctr, a_bcctrl, a_bclr,
  36. a_bclrl, a_cmp, a_cmpi, a_cmpl, a_cmpli, a_cntlzw, a_cntlzw_, a_crand,
  37. a_crandc, a_creqv, a_crnand, a_crnor, a_cror, a_crorc, a_crxor, a_dcba,
  38. a_dcbf, a_dcbi, a_dcbst, a_dcbt, a_divw, a_divw_, a_divwo, a_divwo_,
  39. a_divwu, a_divwu_, a_divwuo, a_divwuo_, a_eciwx, a_ecowx, a_eieio, a_eqv,
  40. a_eqv_, a_extsb, a_extsb_, a_extsh, a_extsh_, a_fabs, a_fabs_, a_fadd,
  41. a_fadd_, a_fadds, a_fadds_, a_fcmpo, a_fcmpu, a_fctiw, a_fctw_, a_fctwz,
  42. a_fctwz_, a_fdiv, a_fdiv_, a_fdivs, a_fdivs_, a_fmadd, a_fmadd_, a_fmadds,
  43. a_fmadds_, a_fmr, a_fmsub, a_fmsub_, a_fmsubs, a_fmsubs_, a_fmul, a_fmul_,
  44. a_fmuls, a_fmuls_, a_fnabs, a_fnabs_, a_fneg, a_fneg_, a_fnmadd,
  45. a_fnmadd_, a_fnmadds, a_fnmadds_, a_fnmsub, a_fnmsub_, a_fnmsubs,
  46. a_fnmsubs_, a_fres, a_fres_, a_frsp, a_frsp_, a_frsqrte, a_frsqrte_,
  47. a_fsel, a_fsel_, a_fsqrt, a_fsqrt_, a_fsqrts, a_fsqrts_, a_fsub, a_fsub_,
  48. a_fsubs, a_fsubs_, a_icbi, a_isync, a_lbz, a_lbzu, a_lbzux, a_lbzx,
  49. a_lfd, a_lfdu, a_lfdux, a_lfdx, a_lfs, a_lfsu, a_lfsux, a_lfsx, a_lha,
  50. a_lhau, a_lhaux, a_lhax, a_hbrx, a_lhz, a_lhzu, a_lhzux, a_lhzx, a_lmw,
  51. a_lswi, a_lswx, a_lwarx, a_lwbrx, a_lwz, a_lwzu, a_lwzux, a_lwzx, a_mcrf,
  52. a_mcrfs, a_mcrxr, a_lcrxe, a_mfcr, a_mffs, a_maffs_, a_mfmsr, a_mfspr, a_mfsr,
  53. a_mfsrin, a_mftb, a_mtfcrf, a_a_mtfd0, a_mtfsb1, a_mtfsf, a_mtfsf_,
  54. a_mtfsfi, a_mtfsfi_, a_mtmsr, a_mtspr, a_mtsr, a_mtsrin, a_mulhw,
  55. a_mulhw_, a_mulhwu, a_mulhwu_, a_mulli, a_mullw, a_mullw_, a_mullwo,
  56. a_mullwo_, a_nand, a_nand_, a_neg, a_neg_, a_nego, a_nego_, a_nor, a_nor_,
  57. a_or, a_or_, a_orc, a_orc_, a_ori, a_oris, a_rfi, a_rlwimi, a_rlwimi_,
  58. a_rlwinm, a_rlwinm_, a_rlwnm, a_sc, a_slw, a_slw_, a_sraw, a_sraw_,
  59. a_srawi, a_srawi_,a_srw, a_srw_, a_stb, a_stbu, a_stbux, a_stbx, a_stfd,
  60. a_stfdu, a_stfdux, a_stfdx, a_stfiwx, a_stfs, a_stfsu, a_stfsux, a_stfsx,
  61. a_sth, a_sthbrx, a_sthu, a_sthux, a_sthx, a_stmw, a_stswi, a_stswx, a_stw,
  62. a_stwbrx, a_stwx_, a_stwu, a_stwux, a_stwx, a_subf, a_subf_, a_subfo,
  63. a_subfo_, a_subfc, a_subfc_, a_subfco, a_subfco_, a_subfe, a_subfe_,
  64. a_subfeo, a_subfeo_, a_subfic, a_subfme, a_subfme_, a_subfmeo, a_subfmeo_,
  65. a_subfze, a_subfze_, a_subfzeo, a_subfzeo_, a_sync, a_tlbia, a_tlbie,
  66. a_tlbsync, a_tw, a_twi, a_xor, a_xor_, a_xori, a_xoris,
  67. { simplified mnemonics }
  68. a_subi, a_subis, a_subic, a_subic_, a_sub, a_sub_, a_subo, a_subo_,
  69. a_subc, a_subc_, a_subco, a_subco_, a_cmpwi, a_cmpw, a_cmplwi, a_cmplw,
  70. a_extlwi, a_extlwi_, a_extrwi, a_extrwi_, a_inslwi, a_inslwi_, a_insrwi,
  71. a_insrwi_, a_rotlwi, a_rotlwi_, a_rotlw, a_rotlw_, a_slwi, a_slwi_,
  72. a_srwi, a_srwi_, a_clrlwi, a_clrlwi_, a_clrrwi, a_clrrwi_, a_clrslwi,
  73. a_clrslwi_, a_blr, a_bctr, a_blrl, a_bctrl, a_crset, a_crclr, a_crmove,
  74. a_crnot, a_mt {move to special prupose reg}, a_mf {move from special purpose reg},
  75. a_nop, a_li, a_lis, a_la, a_mr, a_mr_, a_not, a_mtcr, a_mtlr, a_mflr,
  76. a_mtctr, a_mfctr);
  77. {# This should define the array of instructions as string }
  78. op2strtable=array[tasmop] of string[8];
  79. Const
  80. {# First value of opcode enumeration }
  81. firstop = low(tasmop);
  82. {# Last value of opcode enumeration }
  83. lastop = high(tasmop);
  84. {*****************************************************************************
  85. Registers
  86. *****************************************************************************}
  87. type
  88. { Number of registers used for indexing in tables }
  89. tregisterindex=0..{$i rppcnor.inc}-1;
  90. totherregisterset = set of tregisterindex;
  91. const
  92. { Available Superregisters }
  93. {$i rppcsup.inc}
  94. { No Subregisters }
  95. R_SUBWHOLE=R_SUBNONE;
  96. { Available Registers }
  97. {$i rppccon.inc}
  98. { Integer Super registers first and last }
  99. first_int_supreg = RS_R0;
  100. last_int_supreg = RS_R31;
  101. first_int_imreg = $20;
  102. last_int_imreg = $fe;
  103. { Float Super register first and last }
  104. first_fpu_supreg = $00;
  105. last_fpu_supreg = $1f;
  106. first_fpu_imreg = $20;
  107. last_fpu_imreg = $fe;
  108. { MM Super register first and last }
  109. first_mmx_supreg = RS_INVALID;
  110. last_mmx_supreg = RS_INVALID;
  111. first_mmx_imreg = RS_INVALID;
  112. last_mmx_imreg = RS_INVALID;
  113. {$warning TODO Calculate bsstart}
  114. regnumber_count_bsstart = 64;
  115. regnumber_table : array[tregisterindex] of tregister = (
  116. {$i rppcnum.inc}
  117. );
  118. regstabs_table : array[tregisterindex] of tregister = (
  119. {$i rppcstab.inc}
  120. );
  121. { registers which may be destroyed by calls }
  122. VOLATILE_INTREGISTERS = [RS_R3..RS_R12];
  123. {$warning FIXME!!}
  124. { FIXME: only R_F1..R_F8 under the SYSV ABI -> has to become a }
  125. { typed const (JM) }
  126. VOLATILE_FPUREGISTERS = [RS_F3..RS_F13];
  127. {*****************************************************************************
  128. Conditions
  129. *****************************************************************************}
  130. type
  131. TAsmCondFlag = (C_None { unconditional jumps },
  132. { conditions when not using ctr decrement etc }
  133. C_LT,C_LE,C_EQ,C_GE,C_GT,C_NL,C_NE,C_NG,C_SO,C_NS,C_UN,C_NU,
  134. { conditions when using ctr decrement etc }
  135. C_T,C_F,C_DNZ,C_DNZT,C_DNZF,C_DZ,C_DZT,C_DZF);
  136. const
  137. { these are in the XER, but when moved to CR_x they correspond with the }
  138. { bits below (still needs to be verified!!!) }
  139. C_OV = C_EQ;
  140. C_CA = C_GT;
  141. type
  142. TAsmCond = packed record
  143. case simple: boolean of
  144. false: (BO, BI: byte);
  145. true: (
  146. cond: TAsmCondFlag;
  147. case byte of
  148. 0: ();
  149. { specifies in which part of the cr the bit has to be }
  150. { tested for blt,bgt,beq,..,bnu }
  151. 1: (cr: RS_CR0..RS_CR7);
  152. { specifies the bit to test for bt,bf,bdz,..,bdzf }
  153. 2: (crbit: byte)
  154. );
  155. end;
  156. const
  157. AsmCondFlag2BO: Array[C_T..C_DZF] of Byte =
  158. (12,4,16,8,0,18,10,2);
  159. AsmCondFlag2BI: Array[C_LT..C_NU] of Byte =
  160. (0,1,2,0,1,0,2,1,3,3,3,3);
  161. AsmCondFlagTF: Array[TAsmCondFlag] of Boolean =
  162. (false,true,false,true,false,true,false,false,false,true,false,true,false,
  163. true,false,false,true,false,false,true,false);
  164. AsmCondFlag2Str: Array[TAsmCondFlag] of string[4] = ({cf_none}'',
  165. { conditions when not using ctr decrement etc}
  166. 'lt','le','eq','ge','gt','nl','ne','ng','so','ns','un','nu',
  167. 't','f','dnz','dzt','dnzf','dz','dzt','dzf');
  168. const
  169. CondAsmOps=3;
  170. CondAsmOp:array[0..CondAsmOps-1] of TasmOp=(
  171. A_BC, A_TW, A_TWI
  172. );
  173. {*****************************************************************************
  174. Flags
  175. *****************************************************************************}
  176. type
  177. TResFlagsEnum = (F_EQ,F_NE,F_LT,F_LE,F_GT,F_GE,F_SO,F_FX,F_FEX,F_VX,F_OX);
  178. TResFlags = record
  179. cr: RS_CR0..RS_CR7;
  180. flag: TResFlagsEnum;
  181. end;
  182. (*
  183. const
  184. { arrays for boolean location conversions }
  185. flag_2_cond : array[TResFlags] of TAsmCond =
  186. (C_E,C_NE,C_LT,C_LE,C_GT,C_GE,???????????????);
  187. *)
  188. {*****************************************************************************
  189. Reference
  190. *****************************************************************************}
  191. type
  192. trefoptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  193. { since we have only 16 offsets, we need to be able to specify the high }
  194. { and low 16 bits of the address of a symbol }
  195. trefsymaddr = (refs_full,refs_ha,refs_l);
  196. { reference record }
  197. preference = ^treference;
  198. treference = packed record
  199. { base register, R_NO if none }
  200. base,
  201. { index register, R_NO if none }
  202. index : tregister;
  203. { offset, 0 if none }
  204. offset : longint;
  205. { symbol this reference refers to, nil if none }
  206. symbol : tasmsymbol;
  207. { used in conjunction with symbols and offsets: refs_full means }
  208. { means a full 32bit reference, refs_ha means the upper 16 bits }
  209. { and refs_l the lower 16 bits of the address }
  210. symaddr : trefsymaddr;
  211. { changed when inlining and possibly in other cases, don't }
  212. { set manually }
  213. offsetfixup : longint;
  214. { used in conjunction with the previous field }
  215. options : trefoptions;
  216. { alignment this reference is guaranteed to have }
  217. alignment : byte;
  218. end;
  219. { reference record }
  220. pparareference = ^tparareference;
  221. tparareference = packed record
  222. index : tregister;
  223. offset : aword;
  224. end;
  225. const
  226. symaddr2str: array[trefsymaddr] of string[3] = ('','@ha','@l');
  227. const
  228. { MacOS only. Whether the direct data area (TOC) directly contain
  229. global variables. Otherwise it contains pointers to global variables. }
  230. macos_direct_globals = false;
  231. {*****************************************************************************
  232. Operand
  233. *****************************************************************************}
  234. type
  235. toptype=(top_none,top_reg,top_ref,top_const,top_symbol,top_bool);
  236. toper=record
  237. case typ : toptype of
  238. top_none : ();
  239. top_reg : (reg:tregister);
  240. top_ref : (ref:preference);
  241. top_const : (val:aword);
  242. top_symbol : (sym:tasmsymbol;symofs:longint);
  243. top_bool : (b: boolean);
  244. end;
  245. {*****************************************************************************
  246. Operand Sizes
  247. *****************************************************************************}
  248. {*****************************************************************************
  249. Generic Location
  250. *****************************************************************************}
  251. type
  252. { tparamlocation describes where a parameter for a procedure is stored.
  253. References are given from the caller's point of view. The usual
  254. TLocation isn't used, because contains a lot of unnessary fields.
  255. }
  256. tparalocation = packed record
  257. size : TCGSize;
  258. { The location type where the parameter is passed, usually
  259. LOC_REFERENCE,LOC_REGISTER or LOC_FPUREGISTER
  260. }
  261. loc : TCGLoc;
  262. { The stack pointer must be decreased by this value before
  263. the parameter is copied to the given destination.
  264. This allows to "encode" pushes with tparalocation.
  265. On the PowerPC, this field is unsed but it is there
  266. because several generic code accesses it.
  267. }
  268. sp_fixup : longint;
  269. case TCGLoc of
  270. LOC_REFERENCE : (reference : tparareference);
  271. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  272. LOC_REGISTER,LOC_CREGISTER : (
  273. case longint of
  274. 1 : (register,registerhigh : tregister);
  275. { overlay a registerlow }
  276. 2 : (registerlow : tregister);
  277. { overlay a 64 Bit register type }
  278. 3 : (reg64 : tregister64);
  279. 4 : (register64 : tregister64);
  280. );
  281. end;
  282. treglocation = packed record
  283. case longint of
  284. 1 : (register,registerhigh : tregister);
  285. { overlay a registerlow }
  286. 2 : (registerlow : tregister);
  287. { overlay a 64 Bit register type }
  288. 3 : (reg64 : tregister64);
  289. 4 : (register64 : tregister64);
  290. end;
  291. tlocation = packed record
  292. size : TCGSize;
  293. loc : tcgloc;
  294. case tcgloc of
  295. LOC_CREFERENCE,LOC_REFERENCE : (reference : treference);
  296. LOC_CONSTANT : (
  297. case longint of
  298. {$ifdef FPC_BIG_ENDIAN}
  299. 1 : (_valuedummy,value : AWord);
  300. {$else FPC_BIG_ENDIAN}
  301. 1 : (value : AWord);
  302. {$endif FPC_BIG_ENDIAN}
  303. { can't do this, this layout depends on the host cpu. Use }
  304. { lo(valueqword)/hi(valueqword) instead (JM) }
  305. { 2 : (valuelow, valuehigh:AWord); }
  306. { overlay a complete 64 Bit value }
  307. 3 : (valueqword : qword);
  308. );
  309. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  310. LOC_REGISTER,LOC_CREGISTER : (
  311. case longint of
  312. 1 : (registerlow,registerhigh : tregister);
  313. 2 : (register : tregister);
  314. { overlay a 64 Bit register type }
  315. 3 : (reg64 : tregister64);
  316. 4 : (register64 : tregister64);
  317. );
  318. LOC_FLAGS : (resflags : tresflags);
  319. end;
  320. {*****************************************************************************
  321. Constants
  322. *****************************************************************************}
  323. const
  324. max_operands = 5;
  325. general_superregisters = [RS_R0..RS_R31];
  326. {# Table of registers which can be allocated by the code generator
  327. internally, when generating the code.
  328. }
  329. { legend: }
  330. { xxxregs = set of all possibly used registers of that type in the code }
  331. { generator }
  332. { usableregsxxx = set of all 32bit components of registers that can be }
  333. { possible allocated to a regvar or using getregisterxxx (this }
  334. { excludes registers which can be only used for parameter }
  335. { passing on ABI's that define this) }
  336. { c_countusableregsxxx = amount of registers in the usableregsxxx set }
  337. maxintregs = 18;
  338. { to determine how many registers to use for regvars }
  339. maxintscratchregs = 3;
  340. usableregsint = [RS_R13..RS_R27];
  341. c_countusableregsint = 18;
  342. maxfpuregs = 31-14+1;
  343. usableregsfpu = [RS_F14..RS_F31];
  344. c_countusableregsfpu = 31-14+1;
  345. usableregsmm = [RS_M14..RS_M31];
  346. c_countusableregsmm = 31-14+1;
  347. { no distinction on this platform }
  348. maxaddrregs = 0;
  349. addrregs = [];
  350. usableregsaddr = [];
  351. c_countusableregsaddr = 0;
  352. firstsaveintreg = RS_R13;
  353. lastsaveintreg = RS_R31;
  354. firstsavefpureg = RS_F14;
  355. lastsavefpureg = RS_F31;
  356. { no altivec support yet. Need to override tcgobj.a_loadmm_* first in tcgppc }
  357. firstsavemmreg = RS_INVALID;
  358. lastsavemmreg = RS_INVALID;
  359. maxvarregs = 15;
  360. varregs : Array [1..maxvarregs] of Tsuperregister =
  361. (RS_R14,RS_R15,RS_R16,RS_R17,RS_R18,RS_R19,RS_R20,RS_R21,
  362. RS_R22,RS_R23,RS_R24,RS_R25,RS_R26,RS_R27,RS_R28);
  363. maxfpuvarregs = 31-14+1;
  364. fpuvarregs : Array [1..maxfpuvarregs] of Tsuperregister =
  365. (RS_F14,RS_F15,RS_F16,RS_F17,RS_F18,RS_F19,RS_F20,RS_F21,RS_F22,RS_F23,
  366. RS_F24,RS_F25,RS_F26,RS_F27,RS_F28,RS_F29,RS_F30,RS_F31);
  367. {
  368. // max_param_regs_int = 8;
  369. // param_regs_int: Array[1..max_param_regs_int] of Tsuperregister =
  370. // (R_3,R_4,R_5,R_6,R_7,R_8,R_9,R_10);
  371. // max_param_regs_fpu = 13;
  372. // param_regs_fpu: Array[1..max_param_regs_fpu] of Toldregister =
  373. // (RS_F1,RS_F2,RS_F3,RS_F4,RS_F5,RS_F6,RS_F7,RS_F8,RS_F9,RS_F10,RS_F11,RS_F12,RS_F13);
  374. max_param_regs_mm = 13;
  375. param_regs_mm: Array[1..max_param_regs_mm] of Toldregister =
  376. (R_M1,R_M2,R_M3,R_M4,R_M5,R_M6,R_M7,R_M8,R_M9,R_M10,R_M11,R_M12,R_M13);
  377. }
  378. {*****************************************************************************
  379. Default generic sizes
  380. *****************************************************************************}
  381. {# Defines the default address size for a processor, }
  382. OS_ADDR = OS_32;
  383. {# the natural int size for a processor, }
  384. OS_INT = OS_32;
  385. {# the maximum float size for a processor, }
  386. OS_FLOAT = OS_F64;
  387. {# the size of a vector register for a processor }
  388. OS_VECTOR = OS_M128;
  389. {*****************************************************************************
  390. GDB Information
  391. *****************************************************************************}
  392. {# Register indexes for stabs information, when some
  393. parameters or variables are stored in registers.
  394. Taken from rs6000.h (DBX_REGISTER_NUMBER)
  395. from GCC 3.x source code. PowerPC has 1:1 mapping
  396. according to the order of the registers defined
  397. in GCC
  398. }
  399. stab_regindex : array[tregisterindex] of shortint = (
  400. {$i rppcstab.inc}
  401. );
  402. {*****************************************************************************
  403. Generic Register names
  404. *****************************************************************************}
  405. {# Stack pointer register }
  406. NR_STACK_POINTER_REG = NR_R1;
  407. RS_STACK_POINTER_REG = RS_R1;
  408. {# Frame pointer register }
  409. NR_FRAME_POINTER_REG = NR_STACK_POINTER_REG;
  410. RS_FRAME_POINTER_REG = RS_STACK_POINTER_REG;
  411. {# Register for addressing absolute data in a position independant way,
  412. such as in PIC code. The exact meaning is ABI specific. For
  413. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  414. Taken from GCC rs6000.h
  415. }
  416. {$warning As indicated in rs6000.h, but can't find it anywhere else!}
  417. NR_PIC_OFFSET_REG = NR_R30;
  418. { Results are returned in this register (32-bit values) }
  419. NR_FUNCTION_RETURN_REG = NR_R3;
  420. RS_FUNCTION_RETURN_REG = RS_R3;
  421. { Low part of 64bit return value }
  422. NR_FUNCTION_RETURN64_LOW_REG = NR_R4;
  423. RS_FUNCTION_RETURN64_LOW_REG = RS_R4;
  424. { High part of 64bit return value }
  425. NR_FUNCTION_RETURN64_HIGH_REG = NR_R3;
  426. RS_FUNCTION_RETURN64_HIGH_REG = RS_R3;
  427. { The value returned from a function is available in this register }
  428. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  429. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  430. { The lowh part of 64bit value returned from a function }
  431. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  432. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  433. { The high part of 64bit value returned from a function }
  434. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  435. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  436. NR_FPU_RESULT_REG = NR_F1;
  437. NR_MM_RESULT_REG = NR_M0;
  438. {*****************************************************************************
  439. GCC /ABI linking information
  440. *****************************************************************************}
  441. {# Registers which must be saved when calling a routine declared as
  442. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  443. saved should be the ones as defined in the target ABI and / or GCC.
  444. This value can be deduced from CALLED_USED_REGISTERS array in the
  445. GCC source.
  446. }
  447. std_saved_registers = [RS_R13..RS_R29];
  448. {# Required parameter alignment when calling a routine declared as
  449. stdcall and cdecl. The alignment value should be the one defined
  450. by GCC or the target ABI.
  451. The value of this constant is equal to the constant
  452. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  453. }
  454. std_param_align = 4; { for 32-bit version only }
  455. {*****************************************************************************
  456. CPU Dependent Constants
  457. *****************************************************************************}
  458. LinkageAreaSizeAIX = 24;
  459. LinkageAreaSizeSYSV = 8;
  460. { offset in the linkage area for the saved stack pointer }
  461. LA_SP = 0;
  462. { offset in the linkage area for the saved conditional register}
  463. LA_CR_AIX = 4;
  464. { offset in the linkage area for the saved link register}
  465. LA_LR_AIX = 8;
  466. LA_LR_SYSV = 4;
  467. { offset in the linkage area for the saved RTOC register}
  468. LA_RTOC_AIX = 20;
  469. PARENT_FRAMEPOINTER_OFFSET = 12;
  470. NR_RTOC = NR_R2;
  471. {*****************************************************************************
  472. Helpers
  473. *****************************************************************************}
  474. function is_calljmp(o:tasmop):boolean;
  475. procedure inverse_flags(var r : TResFlags);
  476. procedure inverse_cond(const c: TAsmCond;var r : TAsmCond);
  477. function flags_to_cond(const f: TResFlags) : TAsmCond;
  478. procedure create_cond_imm(BO,BI:byte;var r : TAsmCond);
  479. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte;var r : TasmCond);
  480. function cgsize2subreg(s:Tcgsize):Tsubregister;
  481. function findreg_by_number(r:Tregister):tregisterindex;
  482. function std_regnum_search(const s:string):Tregister;
  483. function std_regname(r:Tregister):string;
  484. function gas_regname(r:Tregister):string;
  485. implementation
  486. uses
  487. verbose;
  488. const
  489. std_regname_table : array[tregisterindex] of string[7] = (
  490. {$i rppcstd.inc}
  491. );
  492. gas_regname_table : array[tregisterindex] of string[7] = (
  493. {$i rppcgas.inc}
  494. );
  495. regnumber_index : array[tregisterindex] of tregisterindex = (
  496. {$i rppcrni.inc}
  497. );
  498. std_regname_index : array[tregisterindex] of tregisterindex = (
  499. {$i rppcsri.inc}
  500. );
  501. {*****************************************************************************
  502. Helpers
  503. *****************************************************************************}
  504. function is_calljmp(o:tasmop):boolean;
  505. begin
  506. is_calljmp:=false;
  507. case o of
  508. A_B,A_BA,A_BL,A_BLA,A_BC,A_BCA,A_BCL,A_BCLA,A_BCCTR,A_BCCTRL,A_BCLR,
  509. A_BCLRL,A_TW,A_TWI: is_calljmp:=true;
  510. end;
  511. end;
  512. procedure inverse_flags(var r: TResFlags);
  513. const
  514. inv_flags: array[F_EQ..F_GE] of TResFlagsEnum =
  515. (F_NE,F_EQ,F_GE,F_GE,F_LE,F_LT);
  516. begin
  517. r.flag := inv_flags[r.flag];
  518. end;
  519. procedure inverse_cond(const c: TAsmCond;var r : TAsmCond);
  520. const
  521. inv_condflags:array[TAsmCondFlag] of TAsmCondFlag=(C_None,
  522. C_GE,C_GT,C_NE,C_LT,C_LE,C_LT,C_EQ,C_GT,C_NS,C_SO,C_NU,C_UN,
  523. C_F,C_T,C_DNZ,C_DNZF,C_DNZT,C_DZ,C_DZF,C_DZT);
  524. begin
  525. r := c;
  526. r.cond := inv_condflags[c.cond];
  527. end;
  528. function flags_to_cond(const f: TResFlags) : TAsmCond;
  529. const
  530. flag_2_cond: array[F_EQ..F_SO] of TAsmCondFlag =
  531. (C_EQ,C_NE,C_LT,C_LE,C_GT,C_GE,C_SO);
  532. begin
  533. if f.flag > high(flag_2_cond) then
  534. internalerror(200112301);
  535. result.simple := true;
  536. result.cr := f.cr;
  537. result.cond := flag_2_cond[f.flag];
  538. end;
  539. procedure create_cond_imm(BO,BI:byte;var r : TAsmCond);
  540. begin
  541. r.simple := false;
  542. r.bo := bo;
  543. r.bi := bi;
  544. end;
  545. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte;var r : TasmCond);
  546. begin
  547. r.simple := true;
  548. r.cond := cond;
  549. case cond of
  550. C_NONE:;
  551. C_T..C_DZF: r.crbit := cr
  552. else r.cr := RS_CR0+cr;
  553. end;
  554. end;
  555. function cgsize2subreg(s:Tcgsize):Tsubregister;
  556. begin
  557. cgsize2subreg:=R_SUBWHOLE;
  558. end;
  559. function findreg_by_stdname(const s:string):byte;
  560. var
  561. i,p : tregisterindex;
  562. begin
  563. {Binary search.}
  564. p:=0;
  565. i:=regnumber_count_bsstart;
  566. repeat
  567. if (p+i<=high(tregisterindex)) and (std_regname_table[std_regname_index[p+i]]<=s) then
  568. p:=p+i;
  569. i:=i shr 1;
  570. until i=0;
  571. if std_regname_table[std_regname_index[p]]=s then
  572. result:=std_regname_index[p]
  573. else
  574. result:=0;
  575. end;
  576. function findreg_by_number(r:Tregister):tregisterindex;
  577. var
  578. i,p : tregisterindex;
  579. begin
  580. {Binary search.}
  581. p:=0;
  582. i:=regnumber_count_bsstart;
  583. repeat
  584. if (p+i<=high(tregisterindex)) and (regnumber_table[regnumber_index[p+i]]<=r) then
  585. p:=p+i;
  586. i:=i shr 1;
  587. until i=0;
  588. if regnumber_table[regnumber_index[p]]=r then
  589. result:=regnumber_index[p]
  590. else
  591. result:=0;
  592. end;
  593. function std_regnum_search(const s:string):Tregister;
  594. begin
  595. result:=regnumber_table[findreg_by_stdname(s)];
  596. end;
  597. function std_regname(r:Tregister):string;
  598. var
  599. p : tregisterindex;
  600. begin
  601. p:=findreg_by_number(r);
  602. if p<>0 then
  603. result:=std_regname_table[p]
  604. else
  605. result:=generic_regname(r);
  606. end;
  607. function gas_regname(r:Tregister):string;
  608. var
  609. p : tregisterindex;
  610. begin
  611. p:=findreg_by_number(r);
  612. if p<>0 then
  613. result:=gas_regname_table[p]
  614. else
  615. result:=generic_regname(r);
  616. end;
  617. end.
  618. {
  619. $Log$
  620. Revision 1.68 2003-09-14 16:37:20 jonas
  621. * fixed some ppc problems
  622. Revision 1.67 2003/09/03 21:04:14 peter
  623. * some fixes for ppc
  624. Revision 1.66 2003/09/03 19:35:24 peter
  625. * powerpc compiles again
  626. Revision 1.65 2003/09/03 11:18:37 florian
  627. * fixed arm concatcopy
  628. + arm support in the common compiler sources added
  629. * moved some generic cg code around
  630. + tfputype added
  631. * ...
  632. Revision 1.64 2003/08/17 16:59:20 jonas
  633. * fixed regvars so they work with newra (at least for ppc)
  634. * fixed some volatile register bugs
  635. + -dnotranslation option for -dnewra, which causes the registers not to
  636. be translated from virtual to normal registers. Requires support in
  637. the assembler writer as well, which is only implemented in aggas/
  638. agppcgas currently
  639. Revision 1.63 2003/08/08 15:51:16 olle
  640. * merged macos entry/exit code generation into the general one.
  641. Revision 1.62 2003/07/23 11:00:09 jonas
  642. * "lastsaveintreg" is RS_R31 instead of RS_R27 with -dnewra, because
  643. there are no scratch regs anymore
  644. Revision 1.61 2003/07/06 20:25:03 jonas
  645. * fixed ppc compiler
  646. Revision 1.60 2003/07/06 15:28:24 jonas
  647. * VOLATILE_REGISTERS was wrong (it was more or less the inverted set
  648. of what it had to be :/ )
  649. Revision 1.59 2003/06/17 16:34:44 jonas
  650. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  651. * renamed all_intregisters to volatile_intregisters and made it
  652. processor dependent
  653. Revision 1.58 2003/06/14 22:32:43 jonas
  654. * ppc compiles with -dnewra, haven't tried to compile anything with it
  655. yet though
  656. Revision 1.57 2003/06/13 17:44:44 jonas
  657. + added supreg_name function
  658. Revision 1.56 2003/06/12 19:11:34 jonas
  659. - removed ALL_INTREGISTERS (only the one in rgobj is valid)
  660. Revision 1.55 2003/05/31 15:05:28 peter
  661. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  662. Revision 1.54 2003/05/30 23:57:08 peter
  663. * more sparc cleanup
  664. * accumulator removed, splitted in function_return_reg (called) and
  665. function_result_reg (caller)
  666. Revision 1.53 2003/05/30 18:49:59 jonas
  667. * changed scratchregs from r28-r30 to r29-r31
  668. * made sure the regvar registers don't overlap with the scratchregs
  669. anymore
  670. Revision 1.52 2003/05/24 16:02:01 jonas
  671. * fixed endian problem with tlocation.value/valueqword fields
  672. Revision 1.51 2003/05/16 16:26:05 jonas
  673. * adapted for Peter's regvar fixes
  674. Revision 1.50 2003/05/15 22:14:43 florian
  675. * fixed last commit, changing lastsaveintreg to r31 caused some strange problems
  676. Revision 1.49 2003/05/15 21:37:00 florian
  677. * sysv entry code saves r13 now as well
  678. Revision 1.48 2003/04/23 12:35:35 florian
  679. * fixed several issues with powerpc
  680. + applied a patch from Jonas for nested function calls (PowerPC only)
  681. * ...
  682. Revision 1.47 2003/04/22 11:27:48 florian
  683. + added first_ and last_imreg
  684. Revision 1.46 2003/03/19 14:26:26 jonas
  685. * fixed R_TOC bugs introduced by new register allocator conversion
  686. Revision 1.45 2003/03/11 21:46:24 jonas
  687. * lots of new regallocator fixes, both in generic and ppc-specific code
  688. (ppc compiler still can't compile the linux system unit though)
  689. Revision 1.44 2003/02/19 22:00:16 daniel
  690. * Code generator converted to new register notation
  691. - Horribily outdated todo.txt removed
  692. Revision 1.43 2003/02/02 19:25:54 carl
  693. * Several bugfixes for m68k target (register alloc., opcode emission)
  694. + VIS target
  695. + Generic add more complete (still not verified)
  696. Revision 1.42 2003/01/16 11:31:28 olle
  697. + added new register constants
  698. + implemented register convertion proc
  699. Revision 1.41 2003/01/13 17:17:50 olle
  700. * changed global var access, TOC now contain pointers to globals
  701. * fixed handling of function pointers
  702. Revision 1.40 2003/01/09 15:49:56 daniel
  703. * Added register conversion
  704. Revision 1.39 2003/01/08 18:43:58 daniel
  705. * Tregister changed into a record
  706. Revision 1.38 2002/11/25 17:43:27 peter
  707. * splitted defbase in defutil,symutil,defcmp
  708. * merged isconvertable and is_equal into compare_defs(_ext)
  709. * made operator search faster by walking the list only once
  710. Revision 1.37 2002/11/24 14:28:56 jonas
  711. + some comments describing the fields of treference
  712. Revision 1.36 2002/11/17 18:26:16 mazen
  713. * fixed a compilation bug accmulator-->FUNCTION_RETURN_REG, in definition of return_result_reg
  714. Revision 1.35 2002/11/17 17:49:09 mazen
  715. + 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
  716. Revision 1.34 2002/09/17 18:54:06 jonas
  717. * a_load_reg_reg() now has two size parameters: source and dest. This
  718. allows some optimizations on architectures that don't encode the
  719. register size in the register name.
  720. Revision 1.33 2002/09/07 17:54:59 florian
  721. * first part of PowerPC fixes
  722. Revision 1.32 2002/09/07 15:25:14 peter
  723. * old logs removed and tabs fixed
  724. Revision 1.31 2002/09/01 21:04:49 florian
  725. * several powerpc related stuff fixed
  726. Revision 1.30 2002/08/18 22:16:15 florian
  727. + the ppc gas assembler writer adds now registers aliases
  728. to the assembler file
  729. Revision 1.29 2002/08/18 21:36:42 florian
  730. + handling of local variables in direct reader implemented
  731. Revision 1.28 2002/08/14 18:41:47 jonas
  732. - remove valuelow/valuehigh fields from tlocation, because they depend
  733. on the endianess of the host operating system -> difficult to get
  734. right. Use lo/hi(location.valueqword) instead (remember to use
  735. valueqword and not value!!)
  736. Revision 1.27 2002/08/13 21:40:58 florian
  737. * more fixes for ppc calling conventions
  738. Revision 1.26 2002/08/12 15:08:44 carl
  739. + stab register indexes for powerpc (moved from gdb to cpubase)
  740. + tprocessor enumeration moved to cpuinfo
  741. + linker in target_info is now a class
  742. * many many updates for m68k (will soon start to compile)
  743. - removed some ifdef or correct them for correct cpu
  744. Revision 1.25 2002/08/10 17:15:06 jonas
  745. * endianess fix
  746. Revision 1.24 2002/08/06 20:55:24 florian
  747. * first part of ppc calling conventions fix
  748. Revision 1.23 2002/08/04 12:57:56 jonas
  749. * more misc. fixes, mostly constant-related
  750. Revision 1.22 2002/07/27 19:57:18 jonas
  751. * some typo corrections in the instruction tables
  752. * renamed the m* registers to v*
  753. Revision 1.21 2002/07/26 12:30:51 jonas
  754. * fixed typo in instruction table (_subco_ -> a_subco)
  755. Revision 1.20 2002/07/25 18:04:10 carl
  756. + FPURESULTREG -> FPU_RESULT_REG
  757. Revision 1.19 2002/07/13 19:38:44 florian
  758. * some more generic calling stuff fixed
  759. Revision 1.18 2002/07/11 14:41:34 florian
  760. * start of the new generic parameter handling
  761. Revision 1.17 2002/07/11 07:35:36 jonas
  762. * some available registers fixes
  763. Revision 1.16 2002/07/09 19:45:01 jonas
  764. * unarynminus and shlshr node fixed for 32bit and smaller ordinals
  765. * small fixes in the assembler writer
  766. * changed scratch registers, because they were used by the linker (r11
  767. and r12) and by the abi under linux (r31)
  768. Revision 1.15 2002/07/07 09:44:31 florian
  769. * powerpc target fixed, very simple units can be compiled
  770. Revision 1.14 2002/05/18 13:34:26 peter
  771. * readded missing revisions
  772. Revision 1.12 2002/05/14 19:35:01 peter
  773. * removed old logs and updated copyright year
  774. Revision 1.11 2002/05/14 17:28:10 peter
  775. * synchronized cpubase between powerpc and i386
  776. * moved more tables from cpubase to cpuasm
  777. * tai_align_abstract moved to tainst, cpuasm must define
  778. the tai_align class now, which may be empty
  779. }