cpubase.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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,globtype,
  25. cutils,cclasses,aasmbase,cpuinfo,cgbase;
  26. {*****************************************************************************
  27. Assembler Opcodes
  28. *****************************************************************************}
  29. type
  30. TAsmOp=(A_None,
  31. { normal opcodes }
  32. a_add, a_add_, a_addo, a_addo_, a_addc, a_addc_, a_addco, a_addco_,
  33. a_adde, a_adde_, a_addeo, a_addeo_, a_addi, a_addic, a_addic_, a_addis,
  34. a_addme, a_addme_, a_addmeo, a_addmeo_, a_addze, a_addze_, a_addzeo,
  35. a_addzeo_, a_and, a_and_, a_andc, a_andc_, a_andi_, a_andis_, a_b,
  36. a_ba, a_bl, a_bla, a_bc, a_bca, a_bcl, a_bcla, a_bcctr, a_bcctrl, a_bclr,
  37. a_bclrl, a_cmp, a_cmpi, a_cmpl, a_cmpli, a_cntlzw, a_cntlzw_, a_crand,
  38. a_crandc, a_creqv, a_crnand, a_crnor, a_cror, a_crorc, a_crxor, a_dcba,
  39. a_dcbf, a_dcbi, a_dcbst, a_dcbt, a_dcbtst, a_dcbz, a_divw, a_divw_, a_divwo, a_divwo_,
  40. a_divwu, a_divwu_, a_divwuo, a_divwuo_, a_eciwx, a_ecowx, a_eieio, a_eqv,
  41. a_eqv_, a_extsb, a_extsb_, a_extsh, a_extsh_, a_fabs, a_fabs_, a_fadd,
  42. a_fadd_, a_fadds, a_fadds_, a_fcmpo, a_fcmpu, a_fctiw, a_fctw_, a_fctwz,
  43. a_fctwz_, a_fdiv, a_fdiv_, a_fdivs, a_fdivs_, a_fmadd, a_fmadd_, a_fmadds,
  44. a_fmadds_, a_fmr, a_fmsub, a_fmsub_, a_fmsubs, a_fmsubs_, a_fmul, a_fmul_,
  45. a_fmuls, a_fmuls_, a_fnabs, a_fnabs_, a_fneg, a_fneg_, a_fnmadd,
  46. a_fnmadd_, a_fnmadds, a_fnmadds_, a_fnmsub, a_fnmsub_, a_fnmsubs,
  47. a_fnmsubs_, a_fres, a_fres_, a_frsp, a_frsp_, a_frsqrte, a_frsqrte_,
  48. a_fsel, a_fsel_, a_fsqrt, a_fsqrt_, a_fsqrts, a_fsqrts_, a_fsub, a_fsub_,
  49. a_fsubs, a_fsubs_, a_icbi, a_isync, a_lbz, a_lbzu, a_lbzux, a_lbzx,
  50. a_lfd, a_lfdu, a_lfdux, a_lfdx, a_lfs, a_lfsu, a_lfsux, a_lfsx, a_lha,
  51. a_lhau, a_lhaux, a_lhax, a_hbrx, a_lhz, a_lhzu, a_lhzux, a_lhzx, a_lmw,
  52. a_lswi, a_lswx, a_lwarx, a_lwbrx, a_lwz, a_lwzu, a_lwzux, a_lwzx, a_mcrf,
  53. a_mcrfs, a_mcrxr, a_lcrxe, a_mfcr, a_mffs, a_maffs_, a_mfmsr, a_mfspr, a_mfsr,
  54. a_mfsrin, a_mftb, a_mtcrf, a_mtfsb0, a_mtfsb1, a_mtfsf, a_mtfsf_,
  55. a_mtfsfi, a_mtfsfi_, a_mtmsr, a_mtspr, a_mtsr, a_mtsrin, a_mulhw,
  56. a_mulhw_, a_mulhwu, a_mulhwu_, a_mulli, a_mullw, a_mullw_, a_mullwo,
  57. a_mullwo_, a_nand, a_nand_, a_neg, a_neg_, a_nego, a_nego_, a_nor, a_nor_,
  58. a_or, a_or_, a_orc, a_orc_, a_ori, a_oris, a_rfi, a_rlwimi, a_rlwimi_,
  59. a_rlwinm, a_rlwinm_, a_rlwnm, a_sc, a_slw, a_slw_, a_sraw, a_sraw_,
  60. a_srawi, a_srawi_,a_srw, a_srw_, a_stb, a_stbu, a_stbux, a_stbx, a_stfd,
  61. a_stfdu, a_stfdux, a_stfdx, a_stfiwx, a_stfs, a_stfsu, a_stfsux, a_stfsx,
  62. a_sth, a_sthbrx, a_sthu, a_sthux, a_sthx, a_stmw, a_stswi, a_stswx, a_stw,
  63. a_stwbrx, a_stwcx_, a_stwu, a_stwux, a_stwx, a_subf, a_subf_, a_subfo,
  64. a_subfo_, a_subfc, a_subfc_, a_subfco, a_subfco_, a_subfe, a_subfe_,
  65. a_subfeo, a_subfeo_, a_subfic, a_subfme, a_subfme_, a_subfmeo, a_subfmeo_,
  66. a_subfze, a_subfze_, a_subfzeo, a_subfzeo_, a_sync, a_tlbia, a_tlbie,
  67. a_tlbsync, a_tw, a_twi, a_xor, a_xor_, a_xori, a_xoris,
  68. { simplified mnemonics }
  69. a_subi, a_subis, a_subic, a_subic_, a_sub, a_sub_, a_subo, a_subo_,
  70. a_subc, a_subc_, a_subco, a_subco_, a_cmpwi, a_cmpw, a_cmplwi, a_cmplw,
  71. a_extlwi, a_extlwi_, a_extrwi, a_extrwi_, a_inslwi, a_inslwi_, a_insrwi,
  72. a_insrwi_, a_rotlwi, a_rotlwi_, a_rotlw, a_rotlw_, a_slwi, a_slwi_,
  73. a_srwi, a_srwi_, a_clrlwi, a_clrlwi_, a_clrrwi, a_clrrwi_, a_clrslwi,
  74. a_clrslwi_, a_blr, a_bctr, a_blrl, a_bctrl, a_crset, a_crclr, a_crmove,
  75. a_crnot, a_mt {move to special prupose reg}, a_mf {move from special purpose reg},
  76. a_nop, a_li, a_lis, a_la, a_mr, a_mr_, a_not, a_mtcr, a_mtlr, a_mflr,
  77. a_mtctr, a_mfctr);
  78. {# This should define the array of instructions as string }
  79. op2strtable=array[tasmop] of string[8];
  80. Const
  81. {# First value of opcode enumeration }
  82. firstop = low(tasmop);
  83. {# Last value of opcode enumeration }
  84. lastop = high(tasmop);
  85. {*****************************************************************************
  86. Registers
  87. *****************************************************************************}
  88. type
  89. { Number of registers used for indexing in tables }
  90. tregisterindex=0..{$i rppcnor.inc}-1;
  91. totherregisterset = set of tregisterindex;
  92. const
  93. maxvarregs = 32-6; { 32 int registers - r0 - stackpointer - r2 - 3 scratch registers }
  94. maxfpuvarregs = 28; { 32 fpuregisters - some scratch registers (minimally 2) }
  95. { Available Superregisters }
  96. {$i rppcsup.inc}
  97. { No Subregisters }
  98. R_SUBWHOLE=R_SUBNONE;
  99. { Available Registers }
  100. {$i rppccon.inc}
  101. { Integer Super registers first and last }
  102. first_int_imreg = $20;
  103. { Float Super register first and last }
  104. first_fpu_imreg = $20;
  105. { MM Super register first and last }
  106. first_mm_imreg = $20;
  107. {$warning TODO Calculate bsstart}
  108. regnumber_count_bsstart = 64;
  109. regnumber_table : array[tregisterindex] of tregister = (
  110. {$i rppcnum.inc}
  111. );
  112. regstabs_table : array[tregisterindex] of shortint = (
  113. {$i rppcstab.inc}
  114. );
  115. regdwarf_table : array[tregisterindex] of shortint = (
  116. {$i rppcdwrf.inc}
  117. );
  118. { registers which may be destroyed by calls }
  119. VOLATILE_INTREGISTERS = [RS_R3..RS_R12];
  120. {$warning FIXME!!}
  121. { FIXME: only R_F1..R_F8 under the SYSV ABI -> has to become a }
  122. { typed const (JM) }
  123. VOLATILE_FPUREGISTERS = [RS_F3..RS_F13];
  124. {*****************************************************************************
  125. Conditions
  126. *****************************************************************************}
  127. type
  128. TAsmCondFlag = (C_None { unconditional jumps },
  129. { conditions when not using ctr decrement etc }
  130. C_LT,C_LE,C_EQ,C_GE,C_GT,C_NL,C_NE,C_NG,C_SO,C_NS,C_UN,C_NU,
  131. { conditions when using ctr decrement etc }
  132. C_T,C_F,C_DNZ,C_DNZT,C_DNZF,C_DZ,C_DZT,C_DZF);
  133. TDirHint = (DH_None,DH_Minus,DH_Plus);
  134. const
  135. { these are in the XER, but when moved to CR_x they correspond with the }
  136. { bits below }
  137. C_OV = C_GT;
  138. C_CA = C_EQ;
  139. C_NO = C_NG;
  140. C_NC = C_NE;
  141. type
  142. TAsmCond = packed record
  143. dirhint : tdirhint;
  144. case simple: boolean of
  145. false: (BO, BI: byte);
  146. true: (
  147. cond: TAsmCondFlag;
  148. case byte of
  149. 0: ();
  150. { specifies in which part of the cr the bit has to be }
  151. { tested for blt,bgt,beq,..,bnu }
  152. 1: (cr: RS_CR0..RS_CR7);
  153. { specifies the bit to test for bt,bf,bdz,..,bdzf }
  154. 2: (crbit: byte)
  155. );
  156. end;
  157. const
  158. AsmCondFlag2BO: Array[C_T..C_DZF] of Byte =
  159. (12,4,16,8,0,18,10,2);
  160. AsmCondFlag2BOLT_NU: Array[C_LT..C_NU] of Byte =
  161. (12,4,12,4,12,4,4,4,12,4,12,4);
  162. AsmCondFlag2BI: Array[C_LT..C_NU] of Byte =
  163. (0,1,2,0,1,0,2,1,3,3,3,3);
  164. AsmCondFlagTF: Array[TAsmCondFlag] of Boolean =
  165. (false,true,false,true,false,true,false,false,false,true,false,true,false,
  166. true,false,false,true,false,false,true,false);
  167. AsmCondFlag2Str: Array[TAsmCondFlag] of string[4] = ({cf_none}'',
  168. { conditions when not using ctr decrement etc}
  169. 'lt','le','eq','ge','gt','nl','ne','ng','so','ns','un','nu',
  170. 't','f','dnz','dnzt','dnzf','dz','dzt','dzf');
  171. UpperAsmCondFlag2Str: Array[TAsmCondFlag] of string[4] = ({cf_none}'',
  172. { conditions when not using ctr decrement etc}
  173. 'LT','LE','EQ','GE','GT','NL','NE','NG','SO','NS','UN','NU',
  174. 'T','F','DNZ','DNZT','DNZF','DZ','DZT','DZF');
  175. const
  176. CondAsmOps=3;
  177. CondAsmOp:array[0..CondAsmOps-1] of TasmOp=(
  178. A_BC, A_TW, A_TWI
  179. );
  180. {*****************************************************************************
  181. Flags
  182. *****************************************************************************}
  183. type
  184. TResFlagsEnum = (F_EQ,F_NE,F_LT,F_LE,F_GT,F_GE,F_SO,F_FX,F_FEX,F_VX,F_OX);
  185. TResFlags = record
  186. cr: RS_CR0..RS_CR7;
  187. flag: TResFlagsEnum;
  188. end;
  189. (*
  190. const
  191. { arrays for boolean location conversions }
  192. flag_2_cond : array[TResFlags] of TAsmCond =
  193. (C_E,C_NE,C_LT,C_LE,C_GT,C_GE,???????????????);
  194. *)
  195. {*****************************************************************************
  196. Reference
  197. *****************************************************************************}
  198. type
  199. trefoptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  200. { reference record }
  201. preference = ^treference;
  202. treference = packed record
  203. { base register, R_NO if none }
  204. base,
  205. { index register, R_NO if none }
  206. index : tregister;
  207. { offset, 0 if none }
  208. offset : aint;
  209. { symbol this reference refers to, nil if none }
  210. symbol : tasmsymbol;
  211. { symbol the symbol of this reference is relative to, nil if none }
  212. relsymbol : tasmsymbol;
  213. { reference type addr or symbol itself }
  214. refaddr : trefaddr;
  215. { alignment this reference is guaranteed to have }
  216. alignment : byte;
  217. end;
  218. { reference record }
  219. pparareference = ^tparareference;
  220. tparareference = packed record
  221. index : tregister;
  222. offset : aword;
  223. end;
  224. const
  225. symaddr2str: array[trefaddr] of string[3] = ('','','@ha','@l');
  226. const
  227. { MacOS only. Whether the direct data area (TOC) directly contain
  228. global variables. Otherwise it contains pointers to global variables. }
  229. macos_direct_globals = false;
  230. {*****************************************************************************
  231. Operand Sizes
  232. *****************************************************************************}
  233. {*****************************************************************************
  234. Generic Location
  235. *****************************************************************************}
  236. type
  237. { tparamlocation describes where a parameter for a procedure is stored.
  238. References are given from the caller's point of view. The usual
  239. TLocation isn't used, because contains a lot of unnessary fields.
  240. }
  241. tparalocation = packed record
  242. size : TCGSize;
  243. { The location type where the parameter is passed, usually
  244. LOC_REFERENCE,LOC_REGISTER or LOC_FPUREGISTER
  245. }
  246. loc : TCGLoc;
  247. lochigh : TCGLoc;
  248. { Word alignment on stack 4 --> 32 bit }
  249. Alignment:Byte;
  250. case TCGLoc of
  251. LOC_REFERENCE : (reference : tparareference);
  252. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  253. LOC_REGISTER,LOC_CREGISTER : (
  254. case longint of
  255. 1 : (register,registerhigh : tregister);
  256. { overlay a registerlow }
  257. 2 : (registerlow : tregister);
  258. {$ifndef cpu64bit}
  259. { overlay a 64 Bit register type }
  260. 3 : (register64 : tregister64);
  261. {$endif cpu64bit}
  262. );
  263. end;
  264. tlocation = packed record
  265. size : TCGSize;
  266. loc : tcgloc;
  267. case tcgloc of
  268. LOC_CREFERENCE,LOC_REFERENCE : (reference : treference);
  269. LOC_CONSTANT : (
  270. case longint of
  271. {$ifdef FPC_BIG_ENDIAN}
  272. 1 : (_valuedummy,value : aint);
  273. {$else FPC_BIG_ENDIAN}
  274. 1 : (value : aint);
  275. {$endif FPC_BIG_ENDIAN}
  276. { can't do this, this layout depends on the host cpu. Use }
  277. { lo(valueqword)/hi(valueqword) instead (JM) }
  278. { overlay a complete 64 Bit value }
  279. 2 : (value64 : Int64);
  280. );
  281. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  282. LOC_REGISTER,LOC_CREGISTER : (
  283. case longint of
  284. 1 : (registerlow,registerhigh : tregister);
  285. 2 : (register : tregister);
  286. {$ifndef cpu64bit}
  287. { overlay a 64 Bit register type }
  288. 3 : (register64 : tregister64);
  289. {$endif cpu64bit}
  290. );
  291. LOC_FLAGS : (resflags : tresflags);
  292. end;
  293. {*****************************************************************************
  294. Constants
  295. *****************************************************************************}
  296. const
  297. max_operands = 5;
  298. {*****************************************************************************
  299. Default generic sizes
  300. *****************************************************************************}
  301. {# Defines the default address size for a processor, }
  302. OS_ADDR = OS_32;
  303. {# the natural int size for a processor, }
  304. OS_INT = OS_32;
  305. {# the maximum float size for a processor, }
  306. OS_FLOAT = OS_F64;
  307. {# the size of a vector register for a processor }
  308. OS_VECTOR = OS_M128;
  309. {*****************************************************************************
  310. GDB Information
  311. *****************************************************************************}
  312. {# Register indexes for stabs information, when some
  313. parameters or variables are stored in registers.
  314. Taken from rs6000.h (DBX_REGISTER_NUMBER)
  315. from GCC 3.x source code. PowerPC has 1:1 mapping
  316. according to the order of the registers defined
  317. in GCC
  318. }
  319. stab_regindex : array[tregisterindex] of shortint = (
  320. {$i rppcstab.inc}
  321. );
  322. {*****************************************************************************
  323. Generic Register names
  324. *****************************************************************************}
  325. {# Stack pointer register }
  326. NR_STACK_POINTER_REG = NR_R1;
  327. RS_STACK_POINTER_REG = RS_R1;
  328. {# Frame pointer register }
  329. NR_FRAME_POINTER_REG = NR_STACK_POINTER_REG;
  330. RS_FRAME_POINTER_REG = RS_STACK_POINTER_REG;
  331. {# Register for addressing absolute data in a position independant way,
  332. such as in PIC code. The exact meaning is ABI specific. For
  333. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  334. Taken from GCC rs6000.h
  335. }
  336. {$warning As indicated in rs6000.h, but can't find it anywhere else!}
  337. NR_PIC_OFFSET_REG = NR_R30;
  338. { Return address of a function }
  339. NR_RETURN_ADDRESS_REG = NR_R0;
  340. { Results are returned in this register (32-bit values) }
  341. NR_FUNCTION_RETURN_REG = NR_R3;
  342. RS_FUNCTION_RETURN_REG = RS_R3;
  343. { Low part of 64bit return value }
  344. NR_FUNCTION_RETURN64_LOW_REG = NR_R4;
  345. RS_FUNCTION_RETURN64_LOW_REG = RS_R4;
  346. { High part of 64bit return value }
  347. NR_FUNCTION_RETURN64_HIGH_REG = NR_R3;
  348. RS_FUNCTION_RETURN64_HIGH_REG = RS_R3;
  349. { The value returned from a function is available in this register }
  350. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  351. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  352. { The lowh part of 64bit value returned from a function }
  353. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  354. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  355. { The high part of 64bit value returned from a function }
  356. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  357. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  358. NR_FPU_RESULT_REG = NR_F1;
  359. NR_MM_RESULT_REG = NR_M0;
  360. {*****************************************************************************
  361. GCC /ABI linking information
  362. *****************************************************************************}
  363. {# Registers which must be saved when calling a routine declared as
  364. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  365. saved should be the ones as defined in the target ABI and / or GCC.
  366. This value can be deduced from CALLED_USED_REGISTERS array in the
  367. GCC source.
  368. }
  369. saved_standard_registers : array[0..18] of tsuperregister = (
  370. RS_R13,RS_R14,RS_R15,RS_R16,RS_R17,RS_R18,RS_R19,
  371. RS_R20,RS_R21,RS_R22,RS_R23,RS_R24,RS_R25,RS_R26,RS_R27,RS_R28,RS_R29,
  372. RS_R30,RS_R31
  373. );
  374. {# Required parameter alignment when calling a routine declared as
  375. stdcall and cdecl. The alignment value should be the one defined
  376. by GCC or the target ABI.
  377. The value of this constant is equal to the constant
  378. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  379. }
  380. std_param_align = 4; { for 32-bit version only }
  381. {*****************************************************************************
  382. CPU Dependent Constants
  383. *****************************************************************************}
  384. LinkageAreaSizeAIX = 24;
  385. LinkageAreaSizeSYSV = 8;
  386. { offset in the linkage area for the saved stack pointer }
  387. LA_SP = 0;
  388. { offset in the linkage area for the saved conditional register}
  389. LA_CR_AIX = 4;
  390. { offset in the linkage area for the saved link register}
  391. LA_LR_AIX = 8;
  392. LA_LR_SYSV = 4;
  393. { offset in the linkage area for the saved RTOC register}
  394. LA_RTOC_AIX = 20;
  395. PARENT_FRAMEPOINTER_OFFSET = 12;
  396. NR_RTOC = NR_R2;
  397. {*****************************************************************************
  398. Helpers
  399. *****************************************************************************}
  400. function is_calljmp(o:tasmop):boolean;
  401. procedure inverse_flags(var r : TResFlags);
  402. procedure inverse_cond(const c: TAsmCond;var r : TAsmCond);
  403. function flags_to_cond(const f: TResFlags) : TAsmCond;
  404. procedure create_cond_imm(BO,BI:byte;var r : TAsmCond);
  405. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte;var r : TasmCond);
  406. function cgsize2subreg(s:Tcgsize):Tsubregister;
  407. { Returns the tcgsize corresponding with the size of reg.}
  408. function reg_cgsize(const reg: tregister) : tcgsize;
  409. function findreg_by_number(r:Tregister):tregisterindex;
  410. function std_regnum_search(const s:string):Tregister;
  411. function std_regname(r:Tregister):string;
  412. function is_condreg(r : tregister):boolean;
  413. implementation
  414. uses
  415. rgBase,verbose;
  416. const
  417. std_regname_table : array[tregisterindex] of string[7] = (
  418. {$i rppcstd.inc}
  419. );
  420. regnumber_index : array[tregisterindex] of tregisterindex = (
  421. {$i rppcrni.inc}
  422. );
  423. std_regname_index : array[tregisterindex] of tregisterindex = (
  424. {$i rppcsri.inc}
  425. );
  426. {*****************************************************************************
  427. Helpers
  428. *****************************************************************************}
  429. function is_calljmp(o:tasmop):boolean;
  430. begin
  431. is_calljmp:=false;
  432. case o of
  433. A_B,A_BA,A_BL,A_BLA,A_BC,A_BCA,A_BCL,A_BCLA,A_BCCTR,A_BCCTRL,A_BCLR,
  434. A_BCLRL,A_TW,A_TWI: is_calljmp:=true;
  435. end;
  436. end;
  437. procedure inverse_flags(var r: TResFlags);
  438. const
  439. inv_flags: array[F_EQ..F_GE] of TResFlagsEnum =
  440. (F_NE,F_EQ,F_GE,F_GE,F_LE,F_LT);
  441. begin
  442. r.flag := inv_flags[r.flag];
  443. end;
  444. procedure inverse_cond(const c: TAsmCond;var r : TAsmCond);
  445. const
  446. inv_condflags:array[TAsmCondFlag] of TAsmCondFlag=(C_None,
  447. C_GE,C_GT,C_NE,C_LT,C_LE,C_LT,C_EQ,C_GT,C_NS,C_SO,C_NU,C_UN,
  448. C_F,C_T,C_DNZ,C_DNZF,C_DNZT,C_DZ,C_DZF,C_DZT);
  449. begin
  450. r := c;
  451. r.cond := inv_condflags[c.cond];
  452. end;
  453. function flags_to_cond(const f: TResFlags) : TAsmCond;
  454. const
  455. flag_2_cond: array[F_EQ..F_SO] of TAsmCondFlag =
  456. (C_EQ,C_NE,C_LT,C_LE,C_GT,C_GE,C_SO);
  457. begin
  458. if f.flag > high(flag_2_cond) then
  459. internalerror(200112301);
  460. result.simple := true;
  461. result.cr := f.cr;
  462. result.cond := flag_2_cond[f.flag];
  463. end;
  464. procedure create_cond_imm(BO,BI:byte;var r : TAsmCond);
  465. begin
  466. r.simple := false;
  467. r.bo := bo;
  468. r.bi := bi;
  469. end;
  470. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte;var r : TasmCond);
  471. begin
  472. r.simple := true;
  473. r.cond := cond;
  474. case cond of
  475. C_NONE:;
  476. C_T..C_DZF: r.crbit := cr
  477. else r.cr := RS_CR0+cr;
  478. end;
  479. end;
  480. function is_condreg(r : tregister):boolean;
  481. var
  482. supreg: tsuperregister;
  483. begin
  484. result := false;
  485. if (getregtype(r) = R_SPECIALREGISTER) then
  486. begin
  487. supreg := getsupreg(r);
  488. result := (supreg >= RS_CR0) and (supreg <= RS_CR7);
  489. end;
  490. end;
  491. function reg_cgsize(const reg: tregister): tcgsize;
  492. begin
  493. case getregtype(reg) of
  494. R_MMREGISTER,
  495. R_FPUREGISTER,
  496. R_INTREGISTER :
  497. result:=OS_32;
  498. else
  499. internalerror(200303181);
  500. end;
  501. end;
  502. function cgsize2subreg(s:Tcgsize):Tsubregister;
  503. begin
  504. cgsize2subreg:=R_SUBWHOLE;
  505. end;
  506. function findreg_by_number(r:Tregister):tregisterindex;
  507. begin
  508. result:=rgBase.findreg_by_number_table(r,regnumber_index);
  509. end;
  510. function std_regnum_search(const s:string):Tregister;
  511. begin
  512. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  513. end;
  514. function std_regname(r:Tregister):string;
  515. var
  516. p : tregisterindex;
  517. begin
  518. p:=findreg_by_number_table(r,regnumber_index);
  519. if p<>0 then
  520. result:=std_regname_table[p]
  521. else
  522. result:=generic_regname(r);
  523. end;
  524. end.
  525. {
  526. $Log$
  527. Revision 1.91 2004-10-26 18:22:04 jonas
  528. * fixed tlocation record again for big endian
  529. * fixed (currently unused) saved_standard_registers array
  530. Revision 1.90 2004/10/25 15:36:47 peter
  531. * save standard registers moved to tcgobj
  532. Revision 1.89 2004/06/20 08:55:32 florian
  533. * logs truncated
  534. Revision 1.88 2004/06/17 16:55:46 peter
  535. * powerpc compiles again
  536. Revision 1.87 2004/06/16 20:07:10 florian
  537. * dwarf branch merged
  538. Revision 1.86.2.1 2004/05/01 11:12:24 florian
  539. * spilling of registers with size<>4 fixed
  540. Revision 1.86 2004/02/27 10:21:05 florian
  541. * top_symbol killed
  542. + refaddr to treference added
  543. + refsymbol to treference added
  544. * top_local stuff moved to an extra record to save memory
  545. + aint introduced
  546. * tppufile.get/putint64/aint implemented
  547. Revision 1.85 2004/02/09 22:45:49 florian
  548. * compilation fixed
  549. }