cpubase.pas 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  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. Toldregister = (R_NO,
  89. R_0,R_1,R_2,R_3,R_4,R_5,R_6,R_7,R_8,R_9,R_10,R_11,R_12,R_13,R_14,R_15,R_16,
  90. R_17,R_18,R_19,R_20,R_21,R_22,R_23,R_24,R_25,R_26,R_27,R_28,R_29,R_30,R_31,
  91. R_F0,R_F1,R_F2,R_F3,R_F4,R_F5,R_F6,R_F7,R_F8,R_F9,R_F10,R_F11,R_F12,
  92. R_F13,R_F14,R_F15,R_F16,R_F17, R_F18,R_F19,R_F20,R_F21,R_F22, R_F23,R_F24,
  93. R_F25,R_F26,R_F27,R_F28,R_F29,R_F30,R_F31,
  94. R_M0,R_M1,R_M2,R_M3,R_M4,R_M5,R_M6,R_M7,R_M8,R_M9,R_M10,R_M11,R_M12,
  95. R_M13,R_M14,R_M15,R_M16,R_M17,R_M18,R_M19,R_M20,R_M21,R_M22, R_M23,R_M24,
  96. R_M25,R_M26,R_M27,R_M28,R_M29,R_M30,R_M31,
  97. R_CR,R_CR0,R_CR1,R_CR2,R_CR3,R_CR4,R_CR5,R_CR6,R_CR7,
  98. R_XER,R_LR,R_CTR,R_FPSCR
  99. );
  100. Tregister=record
  101. enum:Toldregister;
  102. number:word;
  103. end;
  104. {# Set type definition for registers }
  105. tregisterset = set of Toldregister;
  106. { A type to store register locations for 64 Bit values. }
  107. tregister64 = packed record
  108. reglo,reghi : tregister;
  109. end;
  110. { alias for compact code }
  111. treg64 = tregister64;
  112. Const
  113. {# First register in the tregister enumeration }
  114. firstreg = low(Toldregister);
  115. {# Last register in the tregister enumeration }
  116. lastreg = R_FPSCR;
  117. type
  118. {# Type definition for the array of string of register nnames }
  119. treg2strtable = array[firstreg..lastreg] of string[5];
  120. const
  121. R_SPR1 = R_XER;
  122. R_SPR8 = R_LR;
  123. R_SPR9 = R_CTR;
  124. R_TOC = R_2;
  125. { CR0 = 0;
  126. CR1 = 4;
  127. CR2 = 8;
  128. CR3 = 12;
  129. CR4 = 16;
  130. CR5 = 20;
  131. CR6 = 24;
  132. CR7 = 28;
  133. LT = 0;
  134. GT = 1;
  135. EQ = 2;
  136. SO = 3;
  137. FX = 4;
  138. FEX = 5;
  139. VX = 6;
  140. OX = 7;}
  141. mot_reg2str : treg2strtable = ('',
  142. 'r0','r1','r2','r3','r4','r5','r6','r7','r8','r9','r10','r11','r12','r13',
  143. 'r14','r15','r16','r17','r18','r19','r20','r21','r22','r23','r24','r25',
  144. 'r26','r27','r28','r29','r30','r31',
  145. 'F0','F1','F2','F3','F4','F5','F6','F7', 'F8','F9','F10','F11','F12',
  146. 'F13','F14','F15','F16','F17', 'F18','F19','F20','F21','F22', 'F23','F24',
  147. 'F25','F26','F27','F28','F29','F30','F31',
  148. 'M0','M1','M2','M3','M4','M5','M6','M7','M8','M9','M10','M11','M12',
  149. 'M13','M14','M15','M16','M17','M18','M19','M20','M21','M22', 'M23','M24',
  150. 'M25','M26','M27','M28','M29','M30','M31',
  151. 'CR','CR0','CR1','CR2','CR3','CR4','CR5','CR6','CR7',
  152. 'XER','LR','CTR','FPSCR'
  153. );
  154. std_reg2str : treg2strtable = ('',
  155. 'r0','r1','r2','r3','r4','r5','r6','r7','r8','r9','r10','r11','r12','r13',
  156. 'r14','r15','r16','r17','r18','r19','r20','r21','r22','r23','r24','r25',
  157. 'r26','r27','r28','r29','r30','r31',
  158. 'F0','F1','F2','F3','F4','F5','F6','F7', 'F8','F9','F10','F11','F12',
  159. 'F13','F14','F15','F16','F17', 'F18','F19','F20','F21','F22', 'F23','F24',
  160. 'F25','F26','F27','F28','F29','F30','F31',
  161. 'M0','M1','M2','M3','M4','M5','M6','M7','M8','M9','M10','M11','M12',
  162. 'M13','M14','M15','M16','M17','M18','M19','M20','M21','M22', 'M23','M24',
  163. 'M25','M26','M27','M28','M29','M30','M31',
  164. 'CR','CR0','CR1','CR2','CR3','CR4','CR5','CR6','CR7',
  165. 'XER','LR','CTR','FPSCR'
  166. );
  167. {*****************************************************************************
  168. Conditions
  169. *****************************************************************************}
  170. type
  171. TAsmCondFlag = (C_None { unconditional jumps },
  172. { conditions when not using ctr decrement etc }
  173. C_LT,C_LE,C_EQ,C_GE,C_GT,C_NL,C_NE,C_NG,C_SO,C_NS,C_UN,C_NU,
  174. { conditions when using ctr decrement etc }
  175. C_T,C_F,C_DNZ,C_DNZT,C_DNZF,C_DZ,C_DZT,C_DZF);
  176. const
  177. { these are in the XER, but when moved to CR_x they correspond with the }
  178. { bits below (still needs to be verified!!!) }
  179. C_OV = C_EQ;
  180. C_CA = C_GT;
  181. type
  182. TAsmCond = packed record
  183. case simple: boolean of
  184. false: (BO, BI: byte);
  185. true: (
  186. cond: TAsmCondFlag;
  187. case byte of
  188. 0: ();
  189. { specifies in which part of the cr the bit has to be }
  190. { tested for blt,bgt,beq,..,bnu }
  191. 1: (cr: R_CR0..R_CR7);
  192. { specifies the bit to test for bt,bf,bdz,..,bdzf }
  193. 2: (crbit: byte)
  194. );
  195. end;
  196. const
  197. AsmCondFlag2BO: Array[C_T..C_DZF] of Byte =
  198. (12,4,16,8,0,18,10,2);
  199. AsmCondFlag2BI: Array[C_LT..C_NU] of Byte =
  200. (0,1,2,0,1,0,2,1,3,3,3,3);
  201. AsmCondFlagTF: Array[TAsmCondFlag] of Boolean =
  202. (false,true,false,true,false,true,false,false,false,true,false,true,false,
  203. true,false,false,true,false,false,true,false);
  204. AsmCondFlag2Str: Array[TAsmCondFlag] of string[4] = ({cf_none}'',
  205. { conditions when not using ctr decrement etc}
  206. 'lt','le','eq','ge','gt','nl','ne','ng','so','ns','un','nu',
  207. 't','f','dnz','dzt','dnzf','dz','dzt','dzf');
  208. const
  209. CondAsmOps=3;
  210. CondAsmOp:array[0..CondAsmOps-1] of TasmOp=(
  211. A_BC, A_TW, A_TWI
  212. );
  213. {*****************************************************************************
  214. Flags
  215. *****************************************************************************}
  216. type
  217. TResFlagsEnum = (F_EQ,F_NE,F_LT,F_LE,F_GT,F_GE,F_SO,F_FX,F_FEX,F_VX,F_OX);
  218. TResFlags = record
  219. cr: R_CR0..R_CR7;
  220. flag: TResFlagsEnum;
  221. end;
  222. (*
  223. const
  224. { arrays for boolean location conversions }
  225. flag_2_cond : array[TResFlags] of TAsmCond =
  226. (C_E,C_NE,C_LT,C_LE,C_GT,C_GE,???????????????);
  227. *)
  228. {*****************************************************************************
  229. Reference
  230. *****************************************************************************}
  231. type
  232. trefoptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  233. { since we have only 16 offsets, we need to be able to specify the high }
  234. { and low 16 bits of the address of a symbol }
  235. trefsymaddr = (refs_full,refs_ha,refs_l);
  236. { reference record }
  237. preference = ^treference;
  238. treference = packed record
  239. { base register, R_NO if none }
  240. base,
  241. { index register, R_NO if none }
  242. index : tregister;
  243. { offset, 0 if none }
  244. offset : longint;
  245. { symbol this reference refers to, nil if none }
  246. symbol : tasmsymbol;
  247. { used in conjunction with symbols and offsets: refs_full means }
  248. { means a full 32bit reference, refs_ha means the upper 16 bits }
  249. { and refs_l the lower 16 bits of the address }
  250. symaddr : trefsymaddr;
  251. { changed when inlining and possibly in other cases, don't }
  252. { set manually }
  253. offsetfixup : longint;
  254. { used in conjunction with the previous field }
  255. options : trefoptions;
  256. { alignment this reference is guaranteed to have }
  257. alignment : byte;
  258. end;
  259. { reference record }
  260. pparareference = ^tparareference;
  261. tparareference = packed record
  262. index : tregister;
  263. offset : aword;
  264. end;
  265. const
  266. symaddr2str: array[trefsymaddr] of string[3] = ('','@ha','@l');
  267. const
  268. { MacOS only. Whether the direct data area (TOC) directly contain
  269. global variables. Otherwise it contains pointers to global variables. }
  270. macos_direct_globals = false;
  271. {*****************************************************************************
  272. Operand
  273. *****************************************************************************}
  274. type
  275. toptype=(top_none,top_reg,top_ref,top_const,top_symbol,top_bool);
  276. toper=record
  277. ot : longint;
  278. case typ : toptype of
  279. top_none : ();
  280. top_reg : (reg:tregister);
  281. top_ref : (ref:^treference);
  282. top_const : (val:aword);
  283. top_symbol : (sym:tasmsymbol;symofs:longint);
  284. top_bool : (b: boolean);
  285. end;
  286. {*****************************************************************************
  287. Operand Sizes
  288. *****************************************************************************}
  289. {*****************************************************************************
  290. Generic Location
  291. *****************************************************************************}
  292. type
  293. TLoc=(
  294. { added for tracking problems}
  295. LOC_INVALID,
  296. { ordinal constant }
  297. LOC_CONSTANT,
  298. { in a processor register }
  299. LOC_REGISTER,
  300. { Constant register which shouldn't be modified }
  301. LOC_CREGISTER,
  302. { FPU register}
  303. LOC_FPUREGISTER,
  304. { Constant FPU register which shouldn't be modified }
  305. LOC_CFPUREGISTER,
  306. { multimedia register }
  307. LOC_MMREGISTER,
  308. { Constant multimedia reg which shouldn't be modified }
  309. LOC_CMMREGISTER,
  310. { in memory }
  311. LOC_REFERENCE,
  312. { in memory (constant) }
  313. LOC_CREFERENCE,
  314. { boolean results only, jump to false or true label }
  315. LOC_JUMP,
  316. { boolean results only, flags are set }
  317. LOC_FLAGS
  318. );
  319. { tparamlocation describes where a parameter for a procedure is stored.
  320. References are given from the caller's point of view. The usual
  321. TLocation isn't used, because contains a lot of unnessary fields.
  322. }
  323. tparalocation = packed record
  324. size : TCGSize;
  325. { The location type where the parameter is passed, usually
  326. LOC_REFERENCE,LOC_REGISTER or LOC_FPUREGISTER
  327. }
  328. loc : TLoc;
  329. { The stack pointer must be decreased by this value before
  330. the parameter is copied to the given destination.
  331. This allows to "encode" pushes with tparalocation.
  332. On the PowerPC, this field is unsed but it is there
  333. because several generic code accesses it.
  334. }
  335. sp_fixup : longint;
  336. case TLoc of
  337. LOC_REFERENCE : (reference : tparareference);
  338. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  339. LOC_REGISTER,LOC_CREGISTER : (
  340. case longint of
  341. 1 : (register,registerhigh : tregister);
  342. { overlay a registerlow }
  343. 2 : (registerlow : tregister);
  344. { overlay a 64 Bit register type }
  345. 3 : (reg64 : tregister64);
  346. 4 : (register64 : tregister64);
  347. );
  348. end;
  349. treglocation = packed record
  350. case longint of
  351. 1 : (register,registerhigh : tregister);
  352. { overlay a registerlow }
  353. 2 : (registerlow : tregister);
  354. { overlay a 64 Bit register type }
  355. 3 : (reg64 : tregister64);
  356. 4 : (register64 : tregister64);
  357. end;
  358. tlocation = packed record
  359. size : TCGSize;
  360. loc : tloc;
  361. case tloc of
  362. LOC_CREFERENCE,LOC_REFERENCE : (reference : treference);
  363. LOC_CONSTANT : (
  364. case longint of
  365. 1 : (value : AWord);
  366. { can't do this, this layout depends on the host cpu. Use }
  367. { lo(valueqword)/hi(valueqword) instead (JM) }
  368. { 2 : (valuelow, valuehigh:AWord); }
  369. { overlay a complete 64 Bit value }
  370. 3 : (valueqword : qword);
  371. );
  372. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  373. LOC_REGISTER,LOC_CREGISTER : (
  374. case longint of
  375. 1 : (registerlow,registerhigh : tregister);
  376. 2 : (register : tregister);
  377. { overlay a 64 Bit register type }
  378. 3 : (reg64 : tregister64);
  379. 4 : (register64 : tregister64);
  380. );
  381. LOC_FLAGS : (resflags : tresflags);
  382. end;
  383. {*****************************************************************************
  384. Constants
  385. *****************************************************************************}
  386. const
  387. max_operands = 5;
  388. lvaluelocations = [LOC_REFERENCE, LOC_CREGISTER, LOC_CFPUREGISTER,
  389. LOC_CMMREGISTER];
  390. {# Constant defining possibly all registers which might require saving }
  391. {$warning FIX ME !!!!!!!!! }
  392. ALL_REGISTERS = [R_0..R_FPSCR];
  393. general_registers = [R_0..R_31];
  394. {# low and high of the available maximum width integer general purpose }
  395. { registers }
  396. LoGPReg = R_0;
  397. HiGPReg = R_31;
  398. {# low and high of every possible width general purpose register (same as }
  399. { above on most architctures apart from the 80x86) }
  400. LoReg = R_0;
  401. HiReg = R_31;
  402. {# Table of registers which can be allocated by the code generator
  403. internally, when generating the code.
  404. }
  405. { legend: }
  406. { xxxregs = set of all possibly used registers of that type in the code }
  407. { generator }
  408. { usableregsxxx = set of all 32bit components of registers that can be }
  409. { possible allocated to a regvar or using getregisterxxx (this }
  410. { excludes registers which can be only used for parameter }
  411. { passing on ABI's that define this) }
  412. { c_countusableregsxxx = amount of registers in the usableregsxxx set }
  413. maxintregs = 18;
  414. intregs = [R_0..R_31];
  415. usableregsint = [R_13..R_27];
  416. c_countusableregsint = 18;
  417. maxfpuregs = 31-14+1;
  418. fpuregs = [R_F0..R_F31];
  419. usableregsfpu = [R_F14..R_F31];
  420. c_countusableregsfpu = 31-14+1;
  421. mmregs = [R_M0..R_M31];
  422. usableregsmm = [R_M14..R_M31];
  423. c_countusableregsmm = 31-14+1;
  424. firstsaveintreg = R_13;
  425. lastsaveintreg = R_27;
  426. firstsavefpureg = R_F14;
  427. lastsavefpureg = R_F31;
  428. { no altivec support yet. Need to override tcgobj.a_loadmm_* first in tcgppc }
  429. firstsavemmreg = R_NO;
  430. lastsavemmreg = R_NO;
  431. maxvarregs = 17;
  432. varregs : Array [1..maxvarregs] of Toldregister =
  433. (R_14,R_15,R_16,R_17,R_18,R_19,R_20,R_21,R_22,R_23,R_24,R_25,
  434. R_26,R_27,R_28,R_29,R_30);
  435. maxfpuvarregs = 31-14+1;
  436. fpuvarregs : Array [1..maxfpuvarregs] of Toldregister =
  437. (R_F14,R_F15,R_F16,R_F17,R_F18,R_F19,R_F20,R_F21,R_F22,R_F23,
  438. R_F24,R_F25,R_F26,R_F27,R_F28,R_F29,R_F30,R_F31);
  439. max_param_regs_int = 8;
  440. param_regs_int: Array[1..max_param_regs_int] of Toldregister =
  441. (R_3,R_4,R_5,R_6,R_7,R_8,R_9,R_10);
  442. max_param_regs_fpu = 13;
  443. param_regs_fpu: Array[1..max_param_regs_fpu] of Toldregister =
  444. (R_F1,R_F2,R_F3,R_F4,R_F5,R_F6,R_F7,R_F8,R_F9,R_F10,R_F11,R_F12,R_F13);
  445. max_param_regs_mm = 13;
  446. param_regs_mm: Array[1..max_param_regs_mm] of Toldregister =
  447. (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);
  448. {# Registers which are defined as scratch and no need to save across
  449. routine calls or in assembler blocks.
  450. }
  451. max_scratch_regs = 3;
  452. scratch_regs: Array[1..max_scratch_regs] of Toldregister = (R_28,R_29,R_30);
  453. {*****************************************************************************
  454. Default generic sizes
  455. *****************************************************************************}
  456. {# Defines the default address size for a processor, }
  457. OS_ADDR = OS_32;
  458. {# the natural int size for a processor, }
  459. OS_INT = OS_32;
  460. {# the maximum float size for a processor, }
  461. OS_FLOAT = OS_F64;
  462. {# the size of a vector register for a processor }
  463. OS_VECTOR = OS_M128;
  464. {*****************************************************************************
  465. GDB Information
  466. *****************************************************************************}
  467. {# Register indexes for stabs information, when some
  468. parameters or variables are stored in registers.
  469. Taken from rs6000.h (DBX_REGISTER_NUMBER)
  470. from GCC 3.x source code. PowerPC has 1:1 mapping
  471. according to the order of the registers defined
  472. in GCC
  473. }
  474. stab_regindex : array[firstreg..lastreg] of shortint =
  475. (
  476. { R_NO }
  477. -1,
  478. { R0..R7 }
  479. 0,1,2,3,4,5,6,7,
  480. { R8..R15 }
  481. 8,9,10,11,12,13,14,15,
  482. { R16..R23 }
  483. 16,17,18,19,20,21,22,23,
  484. { R24..R32 }
  485. 24,25,26,27,28,29,30,31,
  486. { F0..F7 }
  487. 32,33,34,35,36,37,38,39,
  488. { F8..F15 }
  489. 40,41,42,43,44,45,46,47,
  490. { F16..F23 }
  491. 48,49,50,51,52,53,54,55,
  492. { F24..F31 }
  493. 56,57,58,59,60,61,62,63,
  494. { M0..M7 Multimedia registers are not supported by GCC }
  495. -1,-1,-1,-1,-1,-1,-1,-1,
  496. { M8..M15 }
  497. -1,-1,-1,-1,-1,-1,-1,-1,
  498. { M16..M23 }
  499. -1,-1,-1,-1,-1,-1,-1,-1,
  500. { M24..M31 }
  501. -1,-1,-1,-1,-1,-1,-1,-1,
  502. { CR }
  503. -1,
  504. { CR0..CR7 }
  505. 68,69,70,71,72,73,74,75,
  506. { XER }
  507. 76,
  508. { LR }
  509. 65,
  510. { CTR }
  511. 66,
  512. { FPSCR }
  513. -1
  514. );
  515. {*****************************************************************************
  516. Generic Register names
  517. *****************************************************************************}
  518. {# Stack pointer register }
  519. stack_pointer_reg = R_1;
  520. {# Frame pointer register }
  521. frame_pointer_reg = stack_pointer_reg;
  522. {# Self pointer register : contains the instance address of an
  523. object or class. }
  524. self_pointer_reg = R_9;
  525. {# Register for addressing absolute data in a position independant way,
  526. such as in PIC code. The exact meaning is ABI specific. For
  527. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  528. Taken from GCC rs6000.h
  529. }
  530. {$warning As indicated in rs6000.h, but can't find it anywhere else!}
  531. pic_offset_reg = R_30;
  532. {# Results are returned in this register (32-bit values) }
  533. accumulator = R_3;
  534. {the return_result_reg, is used inside the called function to store its return
  535. value when that is a scalar value otherwise a pointer to the address of the
  536. result is placed inside it}
  537. return_result_reg = accumulator;
  538. {the function_result_reg contains the function result after a call to a scalar
  539. function othewise it contains a pointer to the returned result}
  540. function_result_reg = accumulator;
  541. {# Hi-Results are returned in this register (64-bit value high register) }
  542. accumulatorhigh = R_4;
  543. { WARNING: don't change to R_ST0!! See comments above implementation of }
  544. { a_loadfpu* methods in rgcpu (JM) }
  545. fpu_result_reg = R_F1;
  546. mmresultreg = R_M0;
  547. {*****************************************************************************
  548. GCC /ABI linking information
  549. *****************************************************************************}
  550. {# Registers which must be saved when calling a routine declared as
  551. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  552. saved should be the ones as defined in the target ABI and / or GCC.
  553. This value can be deduced from CALLED_USED_REGISTERS array in the
  554. GCC source.
  555. }
  556. std_saved_registers = [R_13..R_29];
  557. {# Required parameter alignment when calling a routine declared as
  558. stdcall and cdecl. The alignment value should be the one defined
  559. by GCC or the target ABI.
  560. The value of this constant is equal to the constant
  561. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  562. }
  563. std_param_align = 4; { for 32-bit version only }
  564. {*****************************************************************************
  565. CPU Dependent Constants
  566. *****************************************************************************}
  567. LinkageAreaSize = 24;
  568. { offset in the linkage area for the saved stack pointer }
  569. LA_SP = 0;
  570. { offset in the linkage area for the saved conditional register}
  571. LA_CR = 4;
  572. { offset in the linkage area for the saved link register}
  573. LA_LR = 8;
  574. { offset in the linkage area for the saved RTOC register}
  575. LA_RTOC = 20;
  576. {*****************************************************************************
  577. Helpers
  578. *****************************************************************************}
  579. function is_calljmp(o:tasmop):boolean;
  580. procedure inverse_flags(var r : TResFlags);
  581. procedure inverse_cond(const c: TAsmCond;var r : TAsmCond);
  582. function flags_to_cond(const f: TResFlags) : TAsmCond;
  583. procedure create_cond_imm(BO,BI:byte;var r : TAsmCond);
  584. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte;var r : TasmCond);
  585. procedure convert_register_to_enum(var r:Tregister);
  586. implementation
  587. uses
  588. verbose;
  589. {*****************************************************************************
  590. Helpers
  591. *****************************************************************************}
  592. function is_calljmp(o:tasmop):boolean;
  593. begin
  594. is_calljmp:=false;
  595. case o of
  596. A_B,A_BA,A_BL,A_BLA,A_BC,A_BCA,A_BCL,A_BCLA,A_BCCTR,A_BCCTRL,A_BCLR,
  597. A_BCLRL,A_TW,A_TWI: is_calljmp:=true;
  598. end;
  599. end;
  600. procedure inverse_flags(var r: TResFlags);
  601. const
  602. inv_flags: array[F_EQ..F_GE] of TResFlagsEnum =
  603. (F_NE,F_EQ,F_GE,F_GE,F_LE,F_LT);
  604. begin
  605. r.flag := inv_flags[r.flag];
  606. end;
  607. procedure inverse_cond(const c: TAsmCond;var r : TAsmCond);
  608. const
  609. inv_condflags:array[TAsmCondFlag] of TAsmCondFlag=(C_None,
  610. C_GE,C_GT,C_NE,C_LT,C_LE,C_LT,C_EQ,C_GT,C_NS,C_SO,C_NU,C_UN,
  611. C_F,C_T,C_DNZ,C_DNZF,C_DNZT,C_DZ,C_DZF,C_DZT);
  612. begin
  613. r := c;
  614. r.cond := inv_condflags[c.cond];
  615. end;
  616. function flags_to_cond(const f: TResFlags) : TAsmCond;
  617. const
  618. flag_2_cond: array[F_EQ..F_SO] of TAsmCondFlag =
  619. (C_EQ,C_NE,C_LT,C_LE,C_GT,C_GE,C_SO);
  620. begin
  621. if f.flag > high(flag_2_cond) then
  622. internalerror(200112301);
  623. result.simple := true;
  624. result.cr := f.cr;
  625. result.cond := flag_2_cond[f.flag];
  626. end;
  627. procedure create_cond_imm(BO,BI:byte;var r : TAsmCond);
  628. begin
  629. r.simple := false;
  630. r.bo := bo;
  631. r.bi := bi;
  632. end;
  633. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte;var r : TasmCond);
  634. begin
  635. r.simple := true;
  636. r.cond := cond;
  637. case cond of
  638. C_NONE:;
  639. C_T..C_DZF: r.crbit := cr
  640. else r.cr := Toldregister(ord(R_CR0)+cr);
  641. end;
  642. end;
  643. procedure convert_register_to_enum(var r:Tregister);
  644. begin
  645. {$warning Convert_register_to_enum implementation is missing!}
  646. internalerror(200301082);
  647. end;
  648. end.
  649. {
  650. $Log$
  651. Revision 1.41 2003-01-13 17:17:50 olle
  652. * changed global var access, TOC now contain pointers to globals
  653. * fixed handling of function pointers
  654. Revision 1.40 2003/01/09 15:49:56 daniel
  655. * Added register conversion
  656. Revision 1.39 2003/01/08 18:43:58 daniel
  657. * Tregister changed into a record
  658. Revision 1.38 2002/11/25 17:43:27 peter
  659. * splitted defbase in defutil,symutil,defcmp
  660. * merged isconvertable and is_equal into compare_defs(_ext)
  661. * made operator search faster by walking the list only once
  662. Revision 1.37 2002/11/24 14:28:56 jonas
  663. + some comments describing the fields of treference
  664. Revision 1.36 2002/11/17 18:26:16 mazen
  665. * fixed a compilation bug accmulator-->accumulator, in definition of return_result_reg
  666. Revision 1.35 2002/11/17 17:49:09 mazen
  667. + 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
  668. Revision 1.34 2002/09/17 18:54:06 jonas
  669. * a_load_reg_reg() now has two size parameters: source and dest. This
  670. allows some optimizations on architectures that don't encode the
  671. register size in the register name.
  672. Revision 1.33 2002/09/07 17:54:59 florian
  673. * first part of PowerPC fixes
  674. Revision 1.32 2002/09/07 15:25:14 peter
  675. * old logs removed and tabs fixed
  676. Revision 1.31 2002/09/01 21:04:49 florian
  677. * several powerpc related stuff fixed
  678. Revision 1.30 2002/08/18 22:16:15 florian
  679. + the ppc gas assembler writer adds now registers aliases
  680. to the assembler file
  681. Revision 1.29 2002/08/18 21:36:42 florian
  682. + handling of local variables in direct reader implemented
  683. Revision 1.28 2002/08/14 18:41:47 jonas
  684. - remove valuelow/valuehigh fields from tlocation, because they depend
  685. on the endianess of the host operating system -> difficult to get
  686. right. Use lo/hi(location.valueqword) instead (remember to use
  687. valueqword and not value!!)
  688. Revision 1.27 2002/08/13 21:40:58 florian
  689. * more fixes for ppc calling conventions
  690. Revision 1.26 2002/08/12 15:08:44 carl
  691. + stab register indexes for powerpc (moved from gdb to cpubase)
  692. + tprocessor enumeration moved to cpuinfo
  693. + linker in target_info is now a class
  694. * many many updates for m68k (will soon start to compile)
  695. - removed some ifdef or correct them for correct cpu
  696. Revision 1.25 2002/08/10 17:15:06 jonas
  697. * endianess fix
  698. Revision 1.24 2002/08/06 20:55:24 florian
  699. * first part of ppc calling conventions fix
  700. Revision 1.23 2002/08/04 12:57:56 jonas
  701. * more misc. fixes, mostly constant-related
  702. Revision 1.22 2002/07/27 19:57:18 jonas
  703. * some typo corrections in the instruction tables
  704. * renamed the m* registers to v*
  705. Revision 1.21 2002/07/26 12:30:51 jonas
  706. * fixed typo in instruction table (_subco_ -> a_subco)
  707. Revision 1.20 2002/07/25 18:04:10 carl
  708. + FPURESULTREG -> FPU_RESULT_REG
  709. Revision 1.19 2002/07/13 19:38:44 florian
  710. * some more generic calling stuff fixed
  711. Revision 1.18 2002/07/11 14:41:34 florian
  712. * start of the new generic parameter handling
  713. Revision 1.17 2002/07/11 07:35:36 jonas
  714. * some available registers fixes
  715. Revision 1.16 2002/07/09 19:45:01 jonas
  716. * unarynminus and shlshr node fixed for 32bit and smaller ordinals
  717. * small fixes in the assembler writer
  718. * changed scratch registers, because they were used by the linker (r11
  719. and r12) and by the abi under linux (r31)
  720. Revision 1.15 2002/07/07 09:44:31 florian
  721. * powerpc target fixed, very simple units can be compiled
  722. Revision 1.14 2002/05/18 13:34:26 peter
  723. * readded missing revisions
  724. Revision 1.12 2002/05/14 19:35:01 peter
  725. * removed old logs and updated copyright year
  726. Revision 1.11 2002/05/14 17:28:10 peter
  727. * synchronized cpubase between powerpc and i386
  728. * moved more tables from cpubase to cpuasm
  729. * tai_align_abstract moved to tainst, cpuasm must define
  730. the tai_align class now, which may be empty
  731. }