cpubase.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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. unit cpubase;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. strings,cutils,cclasses,aasm,cpuinfo,cginfo;
  23. {*****************************************************************************
  24. Assembler Opcodes
  25. *****************************************************************************}
  26. type
  27. TAsmOp=(A_None,
  28. { normal opcodes }
  29. a_add, a_add_, a_addo, a_addo_, a_addc, a_addc_, a_addco, a_addco_,
  30. a_adde, a_adde_, a_addeo, a_addeo_, a_addi, a_addic, a_addic_, a_addis,
  31. a_addme, a_addme_, a_addmeo, a_addmeo_, a_addze, a_addze_, a_addzeo,
  32. a_addzeo_, a_and, a_and_, a_andc, a_andc_, a_andi_, a_andis_, a_b,
  33. a_ba, a_bl, a_bla, a_bc, a_bca, a_bcl, a_bcla, a_bcctr, a_bcctrl, a_bclr,
  34. a_bclrl, a_cmp, a_cmpi, a_cmpl, a_cmpli, a_cntlzw, a_cntlzw_, a_crand,
  35. a_crandc, a_creqv, a_crnand, a_crnor, a_cror, a_crorc, a_crxor, a_dcba,
  36. a_dcbf, a_dcbi, a_dcbst, a_dcbt, a_divw, a_divw_, a_divwo, a_divwo_,
  37. a_divwu, a_divwu_, a_divwuo, a_divwuo_, a_eciwx, a_ecowx, a_eieio, a_eqv,
  38. a_eqv_, a_extsb, a_extsb_, a_extsh, a_extsh_, a_fabs, a_fabs_, a_fadd,
  39. a_fadd_, a_fadds, a_fadds_, a_fcmpo, a_fcmpu, a_fctiw, a_fctw_, a_fctwz,
  40. a_fctwz_, a_fdiv, a_fdiv_, a_fdivs, a_fdivs_, a_fmadd, a_fmadd_, a_fmadds,
  41. a_fmadds_, a_fmr, a_fmsub, a_fmsub_, a_fmsubs, a_fmsubs_, a_fmul, a_fmul_,
  42. a_fmuls, a_fmuls_, a_fnabs, a_fnabs_, a_fneg, a_fneg_, a_fnmadd,
  43. a_fnmadd_, a_fnmadds, a_fnmadds_, a_fnmsub, a_fnmsub_, a_fnmsubs,
  44. a_fnmsubs_, a_fres, a_fres_, a_frsp, a_frsp_, a_frsqrte, a_frsqrte_,
  45. a_fsel, a_fsel_, a_fsqrt, a_fsqrt_, a_fsqrts, a_fsqrts_, a_fsub, a_fsub_,
  46. a_fsubs, a_fsubs_, a_icbi, a_isync, a_lbz, a_lbzu, a_lbzux, a_lbzx,
  47. a_lfd, a_lfdu, a_lfdux, a_lfdx, a_lfs, a_lfsu, a_lfsux, a_lfsx, a_lha,
  48. a_lhau, a_lhaux, a_lhax, a_hbrx, a_lhz, a_lhzu, a_lhzux, a_lhzx, a_lmw,
  49. a_lswi, a_lswx, a_lwarx, a_lwbrx, a_lwz, a_lwzu, a_lwzux, a_lwzx, a_mcrf,
  50. a_mcrfs, a_mcrxr, a_lcrxe, a_mfcr, a_mffs, a_maffs_, a_mfmsr, a_mfspr, a_mfsr,
  51. a_mfsrin, a_mftb, a_mtfcrf, a_a_mtfd0, a_mtfsb1, a_mtfsf, a_mtfsf_,
  52. a_mtfsfi, a_mtfsfi_, a_mtmsr, a_mtspr, a_mtsr, a_mtsrin, a_mulhw,
  53. a_mulhw_, a_mulhwu, a_mulhwu_, a_mulli, a_mullw, a_mullw_, a_mullwo,
  54. a_mullwo_, a_nand, a_nand_, a_neg, a_neg_, a_nego, a_nego_, a_nor, a_nor_,
  55. a_or, a_or_, a_orc, a_orc_, a_ori, a_oris, a_rfi, a_rlwimi, a_rlwimi_,
  56. a_rlwinm, a_tlwinm_, a_rlwnm, a_sc, a_slw, a_slw_, a_sraw, a_sraw_,
  57. a_srawi, a_srawi_,a_srw, a_srw_, a_stb, a_stbu, a_stbux, a_stbx, a_stfd,
  58. a_stfdu, a_stfdux, a_stfdx, a_stfiwx, a_stfs, a_stfsu, a_stfsux, a_stfsx,
  59. a_sth, a_sthbrx, a_sthu, a_sthux, a_sthx, a_stmw, a_stswi, a_stswx, a_stw,
  60. a_stwbrx, a_stwx_, a_stwu, a_stwux, a_stwx, a_subf, a_subf_, a_subfo,
  61. a_subfo_, a_subfc, a_subfc_, a_subfco, a_subfco_, a_subfe, a_subfe_,
  62. a_subfeo, a_subfeo_, a_subfic, a_subfme, a_subfme_, a_subfmeo, a_subfmeo_,
  63. a_subfze, a_subfze_, a_subfzeo, a_subfzeo_, a_sync, a_tlbia, a_tlbie,
  64. a_tlbsync, a_tw, a_twi, a_xor, a_xor_, a_xori, a_xoris,
  65. { simplified mnemonics }
  66. a_subi, a_subis, a_subic, a_subic_, a_sub, a_sub_, a_subo, a_subo_,
  67. a_subc, a_subc_, a_subco, _subco_, a_cmpwi, a_cmpw, a_cmplwi, a_cmplw,
  68. a_extlwi, a_extlwi_, a_extrwi, a_extrwi_, a_inslwi, a_inslwi_, a_insrwi,
  69. a_insrwi_, a_rotlwi, a_rotlwi_, a_rotlw, a_rotlw_, a_slwi, a_slwi_,
  70. a_srwi, a_srwi_, a_clrlwi, a_clrlwi_, a_clrrwi, a_clrrwi_, a_clrslwi,
  71. a_clrslwi_, a_blr, a_bctr, a_blrl, a_bctrl, a_crset, a_crclr, a_crmove,
  72. a_crnot, a_mt {move to special prupose reg}, a_mf {move from special purpose reg},
  73. a_nop, a_li, a_lis, a_la, a_mr, a_mr_, a_not, a_mtcr);
  74. {# This should define the array of instructions as string }
  75. op2strtable=array[tasmop] of string[8];
  76. Const
  77. {# First value of opcode enumeration }
  78. firstop = low(tasmop);
  79. {# Last value of opcode enumeration }
  80. lastop = high(tasmop);
  81. {*****************************************************************************
  82. Registers
  83. *****************************************************************************}
  84. type
  85. tregister = (R_NO,
  86. 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,
  87. 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,
  88. 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,
  89. R_F13,R_F14,R_F15,R_F16,R_F17, R_F18,R_F19,R_F20,R_F21,R_F22, R_F23,R_F24,
  90. R_F25,R_F26,R_F27,R_F28,R_F29,R_F30,R_F31,
  91. 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,
  92. R_M13,R_M14,R_M15,R_M16,R_M17,R_M18,R_M19,R_M20,R_M21,R_M22, R_M23,R_M24,
  93. R_M25,R_M26,R_M27,R_M28,R_M29,R_M30,R_M31,
  94. R_CR,R_CR0,R_CR1,R_CR2,R_CR3,R_CR4,R_CR5,R_CR6,R_CR7,
  95. R_XER,R_LR,R_CTR,R_FPSCR
  96. );
  97. {# Set type definition for registers }
  98. tregisterset = set of tregister;
  99. {# Type definition for the array of string of register nnames }
  100. reg2strtable = array[tregister] of string[5];
  101. Const
  102. {# First register in the tregister enumeration }
  103. firstreg = low(tregister);
  104. {# Last register in the tregister enumeration }
  105. lastreg = high(tregister);
  106. R_SPR1 = R_XER;
  107. R_SPR8 = R_LR;
  108. R_SPR9 = R_CTR;
  109. R_TOC = R_2;
  110. { CR0 = 0;
  111. CR1 = 4;
  112. CR2 = 8;
  113. CR3 = 12;
  114. CR4 = 16;
  115. CR5 = 20;
  116. CR6 = 24;
  117. CR7 = 28;
  118. LT = 0;
  119. GT = 1;
  120. EQ = 2;
  121. SO = 3;
  122. FX = 4;
  123. FEX = 5;
  124. VX = 6;
  125. OX = 7;}
  126. att_reg2str : reg2strtable = ('',
  127. '0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
  128. '17','18','19','20','21','22','23','24','25','26','27','28','29','30','31',
  129. 'F0','F1','F2','F3','F4','F5','F6','F7', 'F8','F9','F10','F11','F12',
  130. 'F13','F14','F15','F16','F17', 'F18','F19','F20','F21','F22', 'F23','F24',
  131. 'F25','F26','F27','F28','F29','F30','F31',
  132. 'M0','M1','M2','M3','M4','M5','M6','M7','M8','M9','M10','M11','M12',
  133. 'M13','M14','M15','M16','M17','M18','M19','M20','M21','M22', 'M23','M24',
  134. 'M25','M26','M27','M28','M29','M30','M31',
  135. 'CR','CR0','CR1','CR2','CR3','CR4','CR5','CR6','CR7',
  136. 'XER','LR','CTR','FPSCR'
  137. );
  138. mot_reg2str : reg2strtable = ('',
  139. 'r0','r1','r2','r3','r4','r5','r6','r7','r8','r9','r10','r11','r12','r13',
  140. 'r14','r15','r16','r17','r18','r19','r20','r21','r22','r23','r24','r25',
  141. 'r26','r27','r28','r29','r30','r31',
  142. 'F0','F1','F2','F3','F4','F5','F6','F7', 'F8','F9','F10','F11','F12',
  143. 'F13','F14','F15','F16','F17', 'F18','F19','F20','F21','F22', 'F23','F24',
  144. 'F25','F26','F27','F28','F29','F30','F31',
  145. 'M0','M1','M2','M3','M4','M5','M6','M7','M8','M9','M10','M11','M12',
  146. 'M13','M14','M15','M16','M17','M18','M19','M20','M21','M22', 'M23','M24',
  147. 'M25','M26','M27','M28','M29','M30','M31',
  148. 'CR','CR0','CR1','CR2','CR3','CR4','CR5','CR6','CR7',
  149. 'XER','LR','CTR','FPSCR'
  150. );
  151. std_reg2str : reg2strtable = ('',
  152. 'r0','r1','r2','r3','r4','r5','r6','r7','r8','r9','r10','r11','r12','r13',
  153. 'r14','r15','r16','r17','r18','r19','r20','r21','r22','r23','r24','r25',
  154. 'r26','r27','r28','r29','r30','r31',
  155. 'F0','F1','F2','F3','F4','F5','F6','F7', 'F8','F9','F10','F11','F12',
  156. 'F13','F14','F15','F16','F17', 'F18','F19','F20','F21','F22', 'F23','F24',
  157. 'F25','F26','F27','F28','F29','F30','F31',
  158. 'M0','M1','M2','M3','M4','M5','M6','M7','M8','M9','M10','M11','M12',
  159. 'M13','M14','M15','M16','M17','M18','M19','M20','M21','M22', 'M23','M24',
  160. 'M25','M26','M27','M28','M29','M30','M31',
  161. 'CR','CR0','CR1','CR2','CR3','CR4','CR5','CR6','CR7',
  162. 'XER','LR','CTR','FPSCR'
  163. );
  164. {*****************************************************************************
  165. Conditions
  166. *****************************************************************************}
  167. type
  168. TAsmCondFlag = (C_None { unconditional jumps },
  169. { conditions when not using ctr decrement etc }
  170. C_LT,C_LE,C_EQ,C_GE,C_GT,C_NL,C_NE,C_NG,C_SO,C_NS,C_UN,C_NU,
  171. { conditions when using ctr decrement etc }
  172. C_T,C_F,C_DNZ,C_DNZT,C_DNZF,C_DZ,C_DZT,C_DZF);
  173. const
  174. { these are in the XER, but when moved to CR_x they correspond with the }
  175. { bits below (still needs to be verified!!!) }
  176. C_OV = C_EQ;
  177. C_CA = C_GT;
  178. type
  179. TAsmCond = packed record
  180. case simple: boolean of
  181. false: (BO, BI: byte);
  182. true: (
  183. cond: TAsmCondFlag;
  184. case byte of
  185. 0: ();
  186. { specifies in which part of the cr the bit has to be }
  187. { tested for blt,bgt,beq,..,bnu }
  188. 1: (cr: R_CR0..R_CR7);
  189. { specifies the bit to test for bt,bf,bdz,..,bdzf }
  190. 2: (crbit: byte)
  191. );
  192. end;
  193. const
  194. AsmCondFlag2BO: Array[C_T..C_DZF] of Byte =
  195. (12,4,16,8,0,18,10,2);
  196. AsmCondFlag2BI: Array[C_LT..C_NU] of Byte =
  197. (0,1,2,0,1,0,2,1,3,3,3,3);
  198. AsmCondFlagTF: Array[TAsmCondFlag] of Boolean =
  199. (false,true,false,true,false,true,false,false,false,true,false,true,false,
  200. true,false,false,true,false,false,true,false);
  201. AsmCondFlag2Str: Array[TAsmCondFlag] of string[4] = ({cf_none}'',
  202. { conditions when not using ctr decrement etc}
  203. 'lt','le','eq','ge','gt','nl','ne','ng','so','ns','un','nu',
  204. 't','f','dnz','dzt','dnzf','dz','dzt','dzf');
  205. const
  206. CondAsmOps=3;
  207. CondAsmOp:array[0..CondAsmOps-1] of TasmOp=(
  208. A_BC, A_TW, A_TWI
  209. );
  210. {*****************************************************************************
  211. Flags
  212. *****************************************************************************}
  213. type
  214. TResFlagsEnum = (F_EQ,F_NE,F_LT,F_LE,F_GT,F_GE,F_SO,F_FX,F_FEX,F_VX,F_OX);
  215. TResFlags = record
  216. cr: R_CR0..R_CR7;
  217. flag: TResFlagsEnum;
  218. end;
  219. (*
  220. const
  221. { arrays for boolean location conversions }
  222. flag_2_cond : array[TResFlags] of TAsmCond =
  223. (C_E,C_NE,C_LT,C_LE,C_GT,C_GE,???????????????);
  224. *)
  225. {*****************************************************************************
  226. Reference
  227. *****************************************************************************}
  228. type
  229. trefoptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  230. { since we have only 16 offsets, we need to be able to specify the high }
  231. { and low 16 bits of the address of a symbol }
  232. trefsymaddr = (refs_full,refs_ha,refs_l);
  233. { reference record }
  234. preference = ^treference;
  235. treference = packed record
  236. base,
  237. index : tregister;
  238. offset : longint;
  239. symbol : tasmsymbol;
  240. symaddr : trefsymaddr;
  241. offsetfixup : longint;
  242. options : trefoptions;
  243. alignment : byte;
  244. end;
  245. const
  246. symaddr2str: array[trefsymaddr] of string[3] = ('','@ha','@l');
  247. {*****************************************************************************
  248. Operand
  249. *****************************************************************************}
  250. type
  251. toptype=(top_none,top_reg,top_ref,top_const,top_symbol,top_bool);
  252. toper=record
  253. ot : longint;
  254. case typ : toptype of
  255. top_none : ();
  256. top_reg : (reg:tregister);
  257. top_ref : (ref:^treference);
  258. top_const : (val:aword);
  259. top_symbol : (sym:tasmsymbol;symofs:longint);
  260. top_bool : (b: boolean);
  261. end;
  262. {*****************************************************************************
  263. Operand Sizes
  264. *****************************************************************************}
  265. {*****************************************************************************
  266. Generic Location
  267. *****************************************************************************}
  268. type
  269. TLoc=(
  270. LOC_INVALID, { added for tracking problems}
  271. LOC_CONSTANT, { ordinal constant }
  272. LOC_REGISTER, { in a processor register }
  273. LOC_CREGISTER, { Constant register which shouldn't be modified }
  274. LOC_FPUREGISTER, { FPU register}
  275. LOC_CFPUREGISTER,{ Constant FPU register which shouldn't be modified }
  276. LOC_MMREGISTER, { multimedia register }
  277. LOC_CMMREGISTER, { Constant multimedia reg which shouldn't be modified }
  278. LOC_REFERENCE, { in memory }
  279. LOC_CREFERENCE, { in memory (constant) }
  280. LOC_JUMP, { boolean results only, jump to false or true label }
  281. LOC_FLAGS { boolean results only, flags are set }
  282. );
  283. tlocation = packed record
  284. size : TCGSize;
  285. case loc : tloc of
  286. LOC_CREFERENCE,LOC_REFERENCE : (reference : treference);
  287. LOC_CONSTANT : (
  288. case longint of
  289. 1 : (value : AWord);
  290. 2 : (valuelow, valuehigh:AWord);
  291. );
  292. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  293. LOC_REGISTER,LOC_CREGISTER : (
  294. case longint of
  295. 1 : (registerlow,registerhigh : tregister);
  296. 2 : (register : tregister);
  297. );
  298. LOC_JUMP : ();
  299. LOC_FLAGS : (resflags : tresflags);
  300. LOC_INVALID : ();
  301. end;
  302. {*****************************************************************************
  303. Constants
  304. *****************************************************************************}
  305. const
  306. max_operands = 5;
  307. lvaluelocations = [LOC_REFERENCE, LOC_CREGISTER, LOC_CFPUREGISTER,
  308. LOC_CMMREGISTER];
  309. {# Constant defining possibly all registers which might require saving }
  310. {$warning FIX ME !!!!!!!!! }
  311. ALL_REGISTERS = [R_0..R_FPSCR];
  312. general_registers = [R_0..R_31];
  313. {# low and high of the available maximum width integer general purpose }
  314. { registers }
  315. LoGPReg = R_0;
  316. HiGPReg = R_31;
  317. {# low and high of every possible width general purpose register (same as }
  318. { above on most architctures apart from the 80x86) }
  319. LoReg = R_0;
  320. HiReg = R_31;
  321. {# Table of registers which can be allocated by the code generator
  322. internally, when generating the code.
  323. }
  324. { legend: }
  325. { xxxregs = set of all possibly used registers of that type in the code }
  326. { generator }
  327. { usableregsxxx = set of all 32bit components of registers that can be }
  328. { possible allocated to a regvar or using getregisterxxx (this }
  329. { excludes registers which can be only used for parameter }
  330. { passing on ABI's that define this) }
  331. { c_countusableregsxxx = amount of registers in the usableregsxxx set }
  332. maxintregs = 18;
  333. intregs = [R_0..R_31];
  334. usableregsint = [R_13..R_30];
  335. c_countusableregsint = 21;
  336. maxfpuregs = 31-14+1;
  337. fpuregs = [R_F0..R_F31];
  338. usableregsfpu = [R_F14..R_F31];
  339. c_countusableregsfpu = 32;
  340. mmregs = [R_M0..R_M31];
  341. usableregsmm = [R_M14..R_M31];
  342. c_countusableregsmm = 32;
  343. firstsaveintreg = R_13;
  344. lastsaveintreg = R_30;
  345. firstsavefpureg = R_F14;
  346. lastsavefpureg = R_F31;
  347. { no altivec support yet. Need to override tcgobj.a_loadmm_* first in tcgppc }
  348. firstsavemmreg = R_NO;
  349. lastsavemmreg = R_NO;
  350. maxvarregs = 18;
  351. varregs : Array [1..maxvarregs] of Tregister =
  352. (R_13,R_14,R_15,R_16,R_17,R_18,R_19,R_20,R_21,R_22,R_23,R_24,R_25,
  353. R_26,R_27,R_28,R_29,R_30);
  354. maxfpuvarregs = 31-14+1;
  355. fpuvarregs : Array [1..maxfpuvarregs] of Tregister =
  356. (R_F14,R_F15,R_F16,R_F17,R_F18,R_F19,R_F20,R_F21,R_F22,R_F23,
  357. R_F24,R_F25,R_F26,R_F27,R_F28,R_F29,R_F30,R_F31);
  358. max_param_regs_int = 8;
  359. param_regs_int: Array[1..max_param_regs_int] of tregister =
  360. (R_3,R_4,R_5,R_6,R_7,R_8,R_9,R_10);
  361. max_param_regs_fpu = 13;
  362. param_regs_fpu: Array[1..max_param_regs_fpu] of tregister =
  363. (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);
  364. max_param_regs_mm = 13;
  365. param_regs_mm: Array[1..max_param_regs_mm] of tregister =
  366. (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);
  367. {# Registers which are defined as scratch and no need to save across
  368. routine calls or in assembler blocks.
  369. }
  370. max_scratch_regs = 3;
  371. scratch_regs: Array[1..max_scratch_regs] of TRegister = (R_11,R_12,R_31);
  372. {*****************************************************************************
  373. Default generic sizes
  374. *****************************************************************************}
  375. {# Defines the default address size for a processor, }
  376. OS_ADDR = OS_32;
  377. {# the natural int size for a processor, }
  378. OS_INT = OS_32;
  379. {# the maximum float size for a processor, }
  380. OS_FLOAT = OS_F64;
  381. {# the size of a vector register for a processor }
  382. OS_VECTOR = OS_M128;
  383. {*****************************************************************************
  384. Generic Register names
  385. *****************************************************************************}
  386. {# Stack pointer register }
  387. stack_pointer_reg = R_1;
  388. {# Frame pointer register }
  389. frame_pointer_reg = stack_pointer_reg;
  390. {# Self pointer register : contains the instance address of an
  391. object or class. }
  392. self_pointer_reg = R_9;
  393. {# Register for addressing absolute data in a position independant way,
  394. such as in PIC code. The exact meaning is ABI specific }
  395. {$warning Needs checking, this is just a dummy (PFV) }
  396. pic_offset_reg = R_8;
  397. {# Results are returned in this register (32-bit values) }
  398. accumulator = R_3;
  399. {# Hi-Results are returned in this register (64-bit value high register) }
  400. accumulatorhigh = R_4;
  401. { WARNING: don't change to R_ST0!! See comments above implementation of }
  402. { a_loadfpu* methods in rgcpu (JM) }
  403. {$warning I don't know the exact values, please check (PFV) }
  404. fpuresultreg = R_F0;
  405. mmresultreg = R_M0;
  406. {*****************************************************************************
  407. GCC /ABI linking information
  408. *****************************************************************************}
  409. {# Registers which must be saved when calling a routine declared as
  410. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  411. saved should be the ones as defined in the target ABI and / or GCC.
  412. This value can be deduced from CALLED_USED_REGISTERS array in the
  413. GCC source.
  414. }
  415. std_saved_registers = [R_13..R_29];
  416. {# Required parameter alignment when calling a routine declared as
  417. stdcall and cdecl. The alignment value should be the one defined
  418. by GCC or the target ABI.
  419. The value of this constant is equal to the constant
  420. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  421. }
  422. std_param_align = 4; { for 32-bit version only }
  423. {*****************************************************************************
  424. CPU Dependent Constants
  425. *****************************************************************************}
  426. LinkageAreaSize = 24;
  427. { offset in the linkage area for the saved stack pointer }
  428. LA_SP = 0;
  429. { offset in the linkage area for the saved conditional register}
  430. LA_CR = 4;
  431. { offset in the linkage area for the saved link register}
  432. LA_LR = 8;
  433. { offset in the linkage area for the saved RTOC register}
  434. LA_RTOC = 20;
  435. {*****************************************************************************
  436. Helpers
  437. *****************************************************************************}
  438. function is_calljmp(o:tasmop):boolean;
  439. procedure inverse_cond(c: TAsmCond;var r : TAsmCond);
  440. function flags_to_cond(const f: TResFlags) : TAsmCond;
  441. procedure create_cond_imm(BO,BI:byte;var r : TAsmCond);
  442. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte;var r : TasmCond);
  443. implementation
  444. uses
  445. verbose;
  446. {*****************************************************************************
  447. Helpers
  448. *****************************************************************************}
  449. function is_calljmp(o:tasmop):boolean;
  450. begin
  451. is_calljmp:=false;
  452. case o of
  453. A_B,A_BA,A_BL,A_BLA,A_BC,A_BCA,A_BCL,A_BCLA,A_BCCTR,A_BCCTRL,A_BCLR,
  454. A_BCLRL,A_TW,A_TWI: is_calljmp:=true;
  455. end;
  456. end;
  457. procedure inverse_cond(c: TAsmCond;var r : TAsmCond);
  458. const
  459. inv_condflags:array[TAsmCondFlag] of TAsmCondFlag=(C_None,
  460. C_GE,C_GT,C_NE,C_LT,C_LE,C_LT,C_EQ,C_GT,C_NS,C_SO,C_NU,C_UN,
  461. C_F,C_T,C_DNZ,C_DNZF,C_DNZT,C_DZ,C_DZF,C_DZT);
  462. begin
  463. c.cond := inv_condflags[c.cond];
  464. r := c;
  465. end;
  466. function flags_to_cond(const f: TResFlags) : TAsmCond;
  467. const
  468. flag_2_cond: array[F_EQ..F_SO] of TAsmCondFlag =
  469. (C_EQ,C_NE,C_LT,C_LE,C_GT,C_GE,C_SO);
  470. begin
  471. if f.flag > high(flag_2_cond) then
  472. internalerror(200112301);
  473. result.simple := true;
  474. result.cr := f.cr;
  475. result.cond := flag_2_cond[f.flag];
  476. end;
  477. procedure create_cond_imm(BO,BI:byte;var r : TAsmCond);
  478. begin
  479. r.simple := false;
  480. r.bo := bo;
  481. r.bi := bi;
  482. end;
  483. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte;var r : TasmCond);
  484. const cr2reg: array[0..7] of tregister =
  485. (R_CR0,R_CR1,R_CR2,R_CR3,R_CR4,R_CR5,R_CR6,R_CR7);
  486. begin
  487. r.simple := true;
  488. r.cond := cond;
  489. case cond of
  490. C_NONE:;
  491. C_T..C_DZF: r.crbit := cr
  492. else r.cr := cr2reg[cr];
  493. end;
  494. end;
  495. end.
  496. {
  497. $Log$
  498. Revision 1.14 2002-05-18 13:34:26 peter
  499. * readded missing revisions
  500. Revision 1.12 2002/05/14 19:35:01 peter
  501. * removed old logs and updated copyright year
  502. Revision 1.11 2002/05/14 17:28:10 peter
  503. * synchronized cpubase between powerpc and i386
  504. * moved more tables from cpubase to cpuasm
  505. * tai_align_abstract moved to tainst, cpuasm must define
  506. the tai_align class now, which may be empty
  507. Revision 1.10 2002/05/13 19:52:46 peter
  508. * a ppcppc can be build again
  509. Revision 1.9 2002/04/21 15:48:39 carl
  510. * some small updates according to i386 version
  511. Revision 1.8 2002/04/20 21:41:51 carl
  512. * renamed some constants
  513. Revision 1.7 2002/04/06 18:13:02 jonas
  514. * several powerpc-related additions and fixes
  515. }