cpubase.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Contains the base types for the Risc-V32
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. { This Unit contains the base types for the Risc-V32
  18. }
  19. unit cpubase;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. strings,globtype,
  24. cutils,cclasses,aasmbase,cpuinfo,cgbase;
  25. {*****************************************************************************
  26. Assembler Opcodes
  27. *****************************************************************************}
  28. type
  29. TAsmOp=(A_None,
  30. { Pseudo instructions }
  31. A_NOP,A_CALL,A_LA,A_LLA,A_LGA,A_LI,A_MV,A_NOT,A_NEG,A_NEGW,
  32. A_SEXT_B,A_SEXT_H,A_ZEXT_B,A_ZEXT_H,A_SEQZ,A_SNEG,A_SLTZ,A_SGTZ,
  33. A_FMV_S,A_FABS_S,A_FNEG_S,A_FMV_D,A_FABS_D,A_FNEG_D,
  34. A_BEQZ,A_BNEZ,A_BLEZ,A_BGEZ,A_BLTZ,A_BGTZ,A_GT,A_BLE,
  35. A_BGTU,A_BLEU,A_J,A_JR,A_RET,A_TAIL,
  36. { normal opcodes }
  37. A_LUI,A_AUIPC,A_JAL,A_JALR,
  38. A_Bxx,A_LB,A_LH,A_LW,A_LBU,A_LHU,
  39. A_SB,A_SH,A_SW,
  40. A_ADDI,A_SLTI,A_SLTIU,
  41. A_XORI,A_ORI,A_ANDI,
  42. A_SLLI,A_SRLI,A_SRAI,
  43. A_ADD,A_SUB,A_SLL,A_SLT,A_SLTU,
  44. A_XOR,A_SRL,A_SRA,A_OR,A_AND,
  45. A_FENCE,A_FENCE_I,
  46. A_ECALL,A_EBREAK,
  47. A_CSRRW,A_CSRRS,A_CSRRC,A_CSRRWI,A_CSRRSI,A_CSRRCI,
  48. {$ifdef RISCV64}
  49. { 64-bit }
  50. A_ADDIW,A_SLLIW,A_SRLIW,A_SRAIW,
  51. A_ADDW,A_SLLW,A_SRLW,A_SUBW,A_SRAW,
  52. A_LD,A_SD,A_LWU,A_SEXT_W,A_ZEXT_W,
  53. {$endif RISCV64}
  54. { M-extension }
  55. A_MUL,A_MULH,A_MULHSU,A_MULHU,
  56. A_DIV,A_DIVU,A_REM,A_REMU,
  57. {$ifdef RISCV64}
  58. { 64-bit }
  59. A_MULW,
  60. A_DIVW,A_DIVUW,A_REMW,A_REMUW,
  61. {$endif RISCV64}
  62. { A-extension }
  63. A_LR_W,A_SC_W,A_AMOSWAP_W,A_AMOADD_W,A_AMOXOR_W,A_AMOAND_W,
  64. A_AMOOR_W,A_AMOMIN_W,A_AMOMAX_W,A_AMOMINU_W,A_AMOMAXU_W,
  65. {$ifdef RISCV64}
  66. { 64-bit }
  67. A_LR_D,A_SC_D,A_AMOSWAP_D,A_AMOADD_D,A_AMOXOR_D,A_AMOAND_D,
  68. A_AMOOR_D,A_AMOMIN_D,A_AMOMAX_D,A_AMOMINU_D,A_AMOMAXU_D,
  69. {$endif RISCV64}
  70. { B-extension }
  71. A_ADD_UW,A_ANDN,A_CLMUL,A_CLMULH,A_CLMULR,A_CLZ,
  72. {$ifdef RISCV64}
  73. A_CLZW,
  74. {$endif RISCV64}
  75. A_CPOP,
  76. {$ifdef RISCV64}
  77. A_CPOPW,
  78. {$endif RISCV64}
  79. A_CTZ,
  80. {$ifdef RISCV64}
  81. A_CTZW,
  82. {$endif RISCV64}
  83. A_MAX,A_MAXU,A_MIN,A_MINU,A_ORC_B,A_ORN,A_REV8,A_ROL,
  84. {$ifdef RISCV64}
  85. A_ROLW,
  86. {$endif RISCV64}
  87. A_ROR,A_RORI,
  88. {$ifdef RISCV64}
  89. A_RORIW,
  90. A_RORW,
  91. {$endif RISCV64}
  92. A_BCLR,A_BCLRI,A_BEXT,A_BEXTI,A_BINV,A_BINVI,A_BSET,A_SETI,{ A_SEXT_B,A_SEXT_H, }
  93. A_SH1ADD,
  94. {$ifdef RISCV64}
  95. A_SH1ADD_UW,
  96. {$endif RISCV64}
  97. A_SH2ADD,
  98. {$ifdef RISCV64}
  99. A_SH2ADD_UW,
  100. {$endif RISCV64}
  101. A_SH3ADD,
  102. {$ifdef RISCV64}
  103. A_SH3ADD_UW,
  104. A_SLLI_UW,
  105. {$endif RISCV64}
  106. A_XNOR,
  107. { A_ZEXT_H, }
  108. { F-extension }
  109. A_FLW,A_FSW,
  110. A_FMADD_S,A_FMSUB_S,A_FNMSUB_S,A_FNMADD_S,
  111. A_FADD_S,A_FSUB_S,A_FMUL_S,A_FDIV_S,
  112. A_FSQRT_S,A_FSGNJ_S,A_FSGNJN_S,A_FSGNJX_S,
  113. A_FMIN_S,A_FMAX_S,
  114. A_FMV_X_S,A_FEQ_S,A_FLT_S,A_FLE_S,A_FCLASS_S,
  115. A_FCVT_W_S,A_FCVT_WU_S,A_FCVT_S_W,A_FCVT_S_WU,
  116. A_FMV_S_X,
  117. A_FRCSR,A_FRRM,A_FRFLAGS,A_FSCSR,A_FSRM,
  118. A_FSFLAGS,A_FSRMI,A_FSFLAGSI,
  119. {$ifdef RISCV64}
  120. { 64-bit }
  121. A_FCVT_L_S,A_FCVT_LU_S,
  122. A_FCVT_S_L,A_FCVT_S_LU,
  123. {$endif RISCV64}
  124. { D-extension }
  125. A_FLD,A_FSD,
  126. A_FMADD_D,A_FMSUB_D,A_FNMSUB_D,A_FNMADD_D,
  127. A_FADD_D,A_FSUB_D,A_FMUL_D,A_FDIV_D,
  128. A_FSQRT_D,A_FSGNJ_D,A_FSGNJN_D,A_FSGNJX_D,
  129. A_FMIN_D,A_FMAX_D,
  130. A_FEQ_D,A_FLT_D,A_FLE_D,A_FCLASS_D,
  131. A_FCVT_D_S,A_FCVT_S_D,
  132. A_FCVT_W_D,A_FCVT_WU_D,A_FCVT_D_W,A_FCVT_D_WU,
  133. {$ifdef RISCV64}
  134. { 64-bit }
  135. A_FCVT_L_D,A_FCVT_LU_D,A_FMV_X_D,
  136. A_FCVT_D_L,A_FCVT_D_LU,A_FMV_D_X,
  137. {$endif RISCV64}
  138. { Machine mode }
  139. A_MRET,A_HRET,A_SRET,A_URET,
  140. A_WFI,
  141. { Supervisor }
  142. A_SFENCE_VM,
  143. { pseudo instructions for accessiong control and status registers }
  144. A_RDINSTRET,A_RDINSTRETH,A_RDCYCLE,A_RDCYCLEH,A_RDTIME,A_RDTIMEH,A_CSRR,A_CSRW,A_CSRS,A_CSRC,A_CSRWI,
  145. A_CSRSI,A_CSRCI
  146. );
  147. { This should define the array of instructions as string }
  148. op2strtable=array[tasmop] of string[8];
  149. Const
  150. { First value of opcode enumeration }
  151. firstop = low(tasmop);
  152. { Last value of opcode enumeration }
  153. lastop = high(tasmop);
  154. { Last value of opcode for TCommonAsmOps set below }
  155. LastCommonAsmOp = A_MRET;
  156. Type
  157. TCommonAsmOps = Set of A_None .. LastCommonAsmOp;
  158. {*****************************************************************************
  159. Registers
  160. *****************************************************************************}
  161. {$ifdef riscv32}
  162. type
  163. { Number of registers used for indexing in tables }
  164. tregisterindex=0..{$i rrv32nor.inc}-1;
  165. const
  166. maxvarregs = 32-6; { 32 int registers - r0 - stackpointer - r2 - 3 scratch registers }
  167. maxfpuvarregs = 28; { 32 fpuregisters - some scratch registers (minimally 2) }
  168. { Available Superregisters }
  169. {$i rrv32sup.inc}
  170. { No Subregisters }
  171. R_SUBWHOLE=R_SUBNONE;
  172. { Available Registers }
  173. {$i rrv32con.inc}
  174. { Integer Super registers first and last }
  175. first_int_imreg = $20;
  176. { Float Super register first and last }
  177. first_fpu_imreg = $20;
  178. { MM Super register first and last }
  179. first_mm_imreg = $20;
  180. { TODO: Calculate bsstart}
  181. regnumber_count_bsstart = 64;
  182. regnumber_table : array[tregisterindex] of tregister = (
  183. {$i rrv32num.inc}
  184. );
  185. regstabs_table : array[tregisterindex] of shortint = (
  186. {$i rrv32sta.inc}
  187. );
  188. regdwarf_table : array[tregisterindex] of shortint = (
  189. {$i rrv32dwa.inc}
  190. );
  191. {$endif riscv32}
  192. {$ifdef riscv64}
  193. type
  194. { Number of registers used for indexing in tables }
  195. tregisterindex=0..{$i rrv64nor.inc}-1;
  196. const
  197. maxvarregs = 32-6; { 32 int registers - r0 - stackpointer - r2 - 3 scratch registers }
  198. maxfpuvarregs = 28; { 32 fpuregisters - some scratch registers (minimally 2) }
  199. { Available Superregisters }
  200. {$i rrv64sup.inc}
  201. { No Subregisters }
  202. R_SUBWHOLE=R_SUBNONE;
  203. { Available Registers }
  204. {$i rrv64con.inc}
  205. { Integer Super registers first and last }
  206. first_int_imreg = $20;
  207. { Float Super register first and last }
  208. first_fpu_imreg = $20;
  209. { MM Super register first and last }
  210. first_mm_imreg = $20;
  211. { TODO: Calculate bsstart}
  212. regnumber_count_bsstart = 64;
  213. regnumber_table : array[tregisterindex] of tregister = (
  214. {$i rrv64num.inc}
  215. );
  216. regstabs_table : array[tregisterindex] of shortint = (
  217. {$i rrv64sta.inc}
  218. );
  219. regdwarf_table : array[tregisterindex] of shortint = (
  220. {$i rrv64dwa.inc}
  221. );
  222. {$endif riscv32}
  223. {*****************************************************************************
  224. Conditions
  225. *****************************************************************************}
  226. type
  227. TAsmCond = (C_None { unconditional jumps },
  228. C_LT,C_LTU,C_GE,C_GEU,C_NE,C_EQ);
  229. TAsmConds = set of TAsmCond;
  230. const
  231. cond2str: Array[TAsmCond] of string[4] = ({cf_none}'',
  232. { conditions when not using ctr decrement etc}
  233. 'lt','ltu','ge','geu','ne','eq');
  234. uppercond2str: Array[TAsmCond] of string[4] = ({cf_none}'',
  235. { conditions when not using ctr decrement etc}
  236. 'LT','LTU','GE','GEU','NE','EQ');
  237. {*****************************************************************************
  238. Flags
  239. *****************************************************************************}
  240. type
  241. TResFlagsEnum = (F_EQ,F_NE,F_LT,F_LTU,F_GE,F_GEU);
  242. {*****************************************************************************
  243. Reference
  244. *****************************************************************************}
  245. {*****************************************************************************
  246. Operands
  247. *****************************************************************************}
  248. type
  249. TMemoryOrderingFlag = (moRl, moAq);
  250. TMemoryOrdering = set of TMemoryOrderingFlag;
  251. TFenceFlag = (ffI, ffO, ffR, ffW);
  252. TFenceFlags = set of TFenceFlag;
  253. TRoundingMode = (RM_Default,
  254. RM_RNE,
  255. RM_RTZ,
  256. RM_RDN,
  257. RM_RUP,
  258. RM_RMM);
  259. const
  260. roundingmode2str : array[TRoundingMode] of string[3] = ('',
  261. 'rne','rtz','rdn','rup','rmm');
  262. {*****************************************************************************
  263. Constants
  264. *****************************************************************************}
  265. const
  266. max_operands = 5;
  267. {*****************************************************************************
  268. Default generic sizes
  269. *****************************************************************************}
  270. {# Defines the default address size for a processor, }
  271. {$ifdef RISCV64}
  272. OS_ADDR = OS_64;
  273. {# the natural int size for a processor,
  274. has to match osuinttype/ossinttype as initialized in psystem }
  275. OS_INT = OS_64;
  276. OS_SINT = OS_S64;
  277. {$endif RISCV64}
  278. {$ifdef RISCV32}
  279. OS_ADDR = OS_32;
  280. {# the natural int size for a processor,
  281. has to match osuinttype/ossinttype as initialized in psystem }
  282. OS_INT = OS_32;
  283. OS_SINT = OS_S32;
  284. {$endif RISCV64}
  285. {# the maximum float size for a processor, }
  286. OS_FLOAT = OS_F64;
  287. {# the size of a vector register for a processor }
  288. OS_VECTOR = OS_M128;
  289. {*****************************************************************************
  290. GDB Information
  291. *****************************************************************************}
  292. {$ifdef riscv32}
  293. stab_regindex : array[tregisterindex] of shortint = (
  294. {$i rrv32sta.inc}
  295. );
  296. {$endif riscv32}
  297. {$ifdef riscv64}
  298. stab_regindex : array[tregisterindex] of shortint = (
  299. {$i rrv64sta.inc}
  300. );
  301. {$endif riscv64}
  302. {*****************************************************************************
  303. Generic Register names
  304. *****************************************************************************}
  305. {# Stack pointer register }
  306. NR_STACK_POINTER_REG = NR_X2;
  307. RS_STACK_POINTER_REG = RS_X2;
  308. {# Frame pointer register }
  309. NR_FRAME_POINTER_REG = NR_X8;
  310. RS_FRAME_POINTER_REG = RS_X8;
  311. NR_PIC_OFFSET_REG = NR_X3;
  312. { Return address of a function }
  313. NR_RETURN_ADDRESS_REG = NR_X1;
  314. RS_RETURN_ADDRESS_REG = RS_X1;
  315. { Results are returned in this register (32-bit values) }
  316. NR_FUNCTION_RETURN_REG = NR_X10;
  317. RS_FUNCTION_RETURN_REG = RS_X10;
  318. { Low part of 64bit return value }
  319. NR_FUNCTION_RETURN64_LOW_REG = NR_X10;
  320. RS_FUNCTION_RETURN64_LOW_REG = RS_X10;
  321. { High part of 64bit return value }
  322. NR_FUNCTION_RETURN64_HIGH_REG = NR_X11;
  323. RS_FUNCTION_RETURN64_HIGH_REG = RS_X11;
  324. { The value returned from a function is available in this register }
  325. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  326. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  327. { The lowh part of 64bit value returned from a function }
  328. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  329. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  330. { The high part of 64bit value returned from a function }
  331. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  332. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  333. NR_FPU_RESULT_REG = NR_F10;
  334. NR_MM_RESULT_REG = NR_NO;
  335. NR_DEFAULTFLAGS = NR_NO;
  336. RS_DEFAULTFLAGS = RS_NO;
  337. {*****************************************************************************
  338. GCC /ABI linking information
  339. *****************************************************************************}
  340. {# Registers which must be saved when calling a routine declared as
  341. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  342. saved should be the ones as defined in the target ABI and / or GCC.
  343. This value can be deduced from CALLED_USED_REGISTERS array in the
  344. GCC source.
  345. }
  346. saved_standard_registers : array[0..12] of tsuperregister = (
  347. RS_X2,
  348. RS_X8,RS_X9,
  349. RS_X18,RS_X19,
  350. RS_X20,RS_X21,RS_X22,RS_X23,RS_X24,RS_X25,RS_X26,RS_X27
  351. );
  352. { this is only for the generic code which is not used for this architecture }
  353. saved_address_registers : array[0..0] of tsuperregister = (RS_INVALID);
  354. saved_mm_registers : array[0..0] of tsuperregister = (RS_INVALID);
  355. {# Required parameter alignment when calling a routine declared as
  356. stdcall and cdecl. The alignment value should be the one defined
  357. by GCC or the target ABI.
  358. The value of this constant is equal to the constant
  359. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  360. }
  361. {$ifdef RISCV64}
  362. std_param_align = 8;
  363. {$endif RISCV64}
  364. {$ifdef RISCV32}
  365. std_param_align = 4;
  366. {$endif RISCV32}
  367. {*****************************************************************************
  368. CPU Dependent Constants
  369. *****************************************************************************}
  370. maxfpuregs = 8;
  371. {*****************************************************************************
  372. Helpers
  373. *****************************************************************************}
  374. function is_imm12(value: tcgint): boolean;
  375. function is_lui_imm(value: tcgint): boolean;
  376. function is_calljmp(o:tasmop):boolean;
  377. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  378. { Returns the tcgsize corresponding with the size of reg.}
  379. function reg_cgsize(const reg: tregister) : tcgsize;
  380. function findreg_by_number(r:Tregister):tregisterindex;
  381. function std_regnum_search(const s:string):Tregister;
  382. function std_regname(r:Tregister):string;
  383. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  384. function dwarf_reg(r:tregister):shortint;
  385. function dwarf_reg_no_error(r:tregister):shortint;
  386. function eh_return_data_regno(nr: longint): longint;
  387. function conditions_equal(const c1,c2: TAsmCond): boolean;
  388. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  389. function condition_in(const Subset, c: TAsmCond): Boolean;
  390. function is_extra_reg(const s : string) : tregister;
  391. implementation
  392. uses
  393. rgbase,verbose;
  394. {$ifdef riscv32}
  395. const
  396. std_regname_table : TRegNameTable = (
  397. {$i rrv32std.inc}
  398. );
  399. regnumber_index : array[tregisterindex] of tregisterindex = (
  400. {$i rrv32rni.inc}
  401. );
  402. std_regname_index : array[tregisterindex] of tregisterindex = (
  403. {$i rrv32sri.inc}
  404. );
  405. {$endif riscv32}
  406. {$ifdef riscv64}
  407. const
  408. std_regname_table : TRegNameTable = (
  409. {$i rrv64std.inc}
  410. );
  411. regnumber_index : array[tregisterindex] of tregisterindex = (
  412. {$i rrv64rni.inc}
  413. );
  414. std_regname_index : array[tregisterindex] of tregisterindex = (
  415. {$i rrv64sri.inc}
  416. );
  417. {$endif riscv64}
  418. {*****************************************************************************
  419. Helpers
  420. *****************************************************************************}
  421. function is_imm12(value: tcgint): boolean;
  422. begin
  423. result:=(value >= -2048) and (value <= 2047);
  424. end;
  425. function is_lui_imm(value: tcgint): boolean;
  426. begin
  427. result:=SarInt64((value and $FFFFF000) shl 32, 32) = value;
  428. end;
  429. function is_calljmp(o:tasmop):boolean;
  430. begin
  431. is_calljmp:=false;
  432. case o of
  433. A_JAL,A_JALR,A_Bxx,A_CALL:
  434. is_calljmp:=true;
  435. else
  436. ;
  437. end;
  438. end;
  439. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  440. const
  441. inv_condflags:array[TAsmCond] of TAsmCond=(C_None,
  442. C_GE,C_GEU,C_LT,C_LTU,C_EQ,C_NE);
  443. begin
  444. result := inv_condflags[c];
  445. end;
  446. function reg_cgsize(const reg: tregister): tcgsize;
  447. begin
  448. case getregtype(reg) of
  449. R_INTREGISTER :
  450. result:=OS_INT;
  451. R_MMREGISTER:
  452. result:=OS_M128;
  453. R_FPUREGISTER:
  454. result:=OS_F64;
  455. else
  456. internalerror(200303181);
  457. end;
  458. end;
  459. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  460. begin
  461. cgsize2subreg:=R_SUBWHOLE;
  462. end;
  463. function findreg_by_number(r:Tregister):tregisterindex;
  464. begin
  465. result:=rgBase.findreg_by_number_table(r,regnumber_index);
  466. end;
  467. function std_regnum_search(const s:string):Tregister;
  468. begin
  469. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  470. end;
  471. function std_regname(r:Tregister):string;
  472. var
  473. p : tregisterindex;
  474. begin
  475. p:=findreg_by_number_table(r,regnumber_index);
  476. if p<>0 then
  477. result:=std_regname_table[p]
  478. else
  479. result:=generic_regname(r);
  480. end;
  481. function dwarf_reg(r:tregister):shortint;
  482. begin
  483. result:=regdwarf_table[findreg_by_number(r)];
  484. if result=-1 then
  485. internalerror(200603251);
  486. end;
  487. function dwarf_reg_no_error(r:tregister):shortint;
  488. begin
  489. result:=regdwarf_table[findreg_by_number(r)];
  490. end;
  491. function eh_return_data_regno(nr: longint): longint;
  492. begin
  493. if (nr>=0) and (nr<4) then
  494. result:=nr+10
  495. else
  496. result:=-1;
  497. end;
  498. function conditions_equal(const c1, c2: TAsmCond): boolean;
  499. begin
  500. result:=c1=c2;
  501. end;
  502. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  503. function condition_in(const Subset, c: TAsmCond): Boolean;
  504. begin
  505. Result := (c = C_None) or conditions_equal(Subset, c);
  506. if not Result then
  507. case Subset of
  508. C_EQ:
  509. Result := (c in [C_GE, C_GEU]);
  510. else
  511. Result := False;
  512. end;
  513. end;
  514. function is_extra_reg(const s: string): tregister;
  515. type
  516. treg2str = record
  517. name : string[4];
  518. reg : tregister;
  519. end;
  520. const
  521. extraregs : array[0..32] of treg2str = (
  522. (name: 'A0'; reg : NR_X10),
  523. (name: 'A1'; reg : NR_X11),
  524. (name: 'A2'; reg : NR_X12),
  525. (name: 'A3'; reg : NR_X13),
  526. (name: 'A4'; reg : NR_X14),
  527. (name: 'A5'; reg : NR_X15),
  528. (name: 'A6'; reg : NR_X16),
  529. (name: 'A7'; reg : NR_X17),
  530. (name: 'ZERO'; reg : NR_X0),
  531. (name: 'RA'; reg : NR_X1),
  532. (name: 'SP'; reg : NR_X2),
  533. (name: 'GP'; reg : NR_X3),
  534. (name: 'TP'; reg : NR_X4),
  535. (name: 'T0'; reg : NR_X5),
  536. (name: 'T1'; reg : NR_X6),
  537. (name: 'T2'; reg : NR_X7),
  538. (name: 'S0'; reg : NR_X8),
  539. (name: 'FP'; reg : NR_X8),
  540. (name: 'S1'; reg : NR_X9),
  541. (name: 'S2'; reg : NR_X18),
  542. (name: 'S3'; reg : NR_X19),
  543. (name: 'S4'; reg : NR_X20),
  544. (name: 'S5'; reg : NR_X21),
  545. (name: 'S6'; reg : NR_X22),
  546. (name: 'S7'; reg : NR_X23),
  547. (name: 'S8'; reg : NR_X24),
  548. (name: 'S9'; reg : NR_X25),
  549. (name: 'S10';reg : NR_X26),
  550. (name: 'S11';reg : NR_X27),
  551. (name: 'T3'; reg : NR_X28),
  552. (name: 'T4'; reg : NR_X29),
  553. (name: 'T5'; reg : NR_X30),
  554. (name: 'T6'; reg : NR_X31)
  555. );
  556. var
  557. i : longint;
  558. begin
  559. result:=NR_NO;
  560. { reg found?
  561. possible aliases are always 2 to 4 chars
  562. }
  563. if not (length(s) in [2..4]) then
  564. exit;
  565. for i:=low(extraregs) to high(extraregs) do
  566. begin
  567. if s=extraregs[i].name then
  568. begin
  569. result:=extraregs[i].reg;
  570. exit;
  571. end;
  572. end;
  573. end;
  574. end.