cpubase.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. { F-extension }
  71. A_FLW,A_FSW,
  72. A_FMADD_S,A_FMSUB_S,A_FNMSUB_S,A_FNMADD_S,
  73. A_FADD_S,A_FSUB_S,A_FMUL_S,A_FDIV_S,
  74. A_FSQRT_S,A_FSGNJ_S,A_FSGNJN_S,A_FSGNJX_S,
  75. A_FMIN_S,A_FMAX_S,
  76. A_FMV_X_S,A_FEQ_S,A_FLT_S,A_FLE_S,A_FCLASS_S,
  77. A_FCVT_W_S,A_FCVT_WU_S,A_FCVT_S_W,A_FCVT_S_WU,
  78. A_FMV_S_X,
  79. A_FRCSR,A_FRRM,A_FRFLAGS,A_FSCSR,A_FSRM,
  80. A_FSFLAGS,A_FSRMI,A_FSFLAGSI,
  81. {$ifdef RISCV64}
  82. { 64-bit }
  83. A_FCVT_L_S,A_FCVT_LU_S,
  84. A_FCVT_S_L,A_FCVT_S_LU,
  85. {$endif RISCV64}
  86. { D-extension }
  87. A_FLD,A_FSD,
  88. A_FMADD_D,A_FMSUB_D,A_FNMSUB_D,A_FNMADD_D,
  89. A_FADD_D,A_FSUB_D,A_FMUL_D,A_FDIV_D,
  90. A_FSQRT_D,A_FSGNJ_D,A_FSGNJN_D,A_FSGNJX_D,
  91. A_FMIN_D,A_FMAX_D,
  92. A_FEQ_D,A_FLT_D,A_FLE_D,A_FCLASS_D,
  93. A_FCVT_D_S,A_FCVT_S_D,
  94. A_FCVT_W_D,A_FCVT_WU_D,A_FCVT_D_W,A_FCVT_D_WU,
  95. {$ifdef RISCV64}
  96. { 64-bit }
  97. A_FCVT_L_D,A_FCVT_LU_D,A_FMV_X_D,
  98. A_FCVT_D_L,A_FCVT_D_LU,A_FMV_D_X,
  99. {$endif RISCV64}
  100. { Machine mode }
  101. A_MRET,A_HRET,A_SRET,A_URET,
  102. A_WFI,
  103. { Supervisor }
  104. A_SFENCE_VM,
  105. { pseudo instructions for accessiong control and status registers }
  106. A_RDINSTRET,A_RDINSTRETH,A_RDCYCLE,A_RDCYCLEH,A_RDTIME,A_RDTIMEH,A_CSRR,A_CSRW,A_CSRS,A_CSRC,A_CSRWI,
  107. A_CSRSI,A_CSRCI
  108. );
  109. TAsmOps = set of TAsmOp;
  110. {# This should define the array of instructions as string }
  111. op2strtable=array[tasmop] of string[8];
  112. Const
  113. {# First value of opcode enumeration }
  114. firstop = low(tasmop);
  115. {# Last value of opcode enumeration }
  116. lastop = high(tasmop);
  117. {*****************************************************************************
  118. Registers
  119. *****************************************************************************}
  120. {$ifdef riscv32}
  121. type
  122. { Number of registers used for indexing in tables }
  123. tregisterindex=0..{$i rrv32nor.inc}-1;
  124. const
  125. maxvarregs = 32-6; { 32 int registers - r0 - stackpointer - r2 - 3 scratch registers }
  126. maxfpuvarregs = 28; { 32 fpuregisters - some scratch registers (minimally 2) }
  127. { Available Superregisters }
  128. {$i rrv32sup.inc}
  129. { No Subregisters }
  130. R_SUBWHOLE=R_SUBNONE;
  131. { Available Registers }
  132. {$i rrv32con.inc}
  133. { Integer Super registers first and last }
  134. first_int_imreg = $20;
  135. { Float Super register first and last }
  136. first_fpu_imreg = $20;
  137. { MM Super register first and last }
  138. first_mm_imreg = $20;
  139. { TODO: Calculate bsstart}
  140. regnumber_count_bsstart = 64;
  141. regnumber_table : array[tregisterindex] of tregister = (
  142. {$i rrv32num.inc}
  143. );
  144. regstabs_table : array[tregisterindex] of shortint = (
  145. {$i rrv32sta.inc}
  146. );
  147. regdwarf_table : array[tregisterindex] of shortint = (
  148. {$i rrv32dwa.inc}
  149. );
  150. {$endif riscv32}
  151. {$ifdef riscv64}
  152. type
  153. { Number of registers used for indexing in tables }
  154. tregisterindex=0..{$i rrv64nor.inc}-1;
  155. const
  156. maxvarregs = 32-6; { 32 int registers - r0 - stackpointer - r2 - 3 scratch registers }
  157. maxfpuvarregs = 28; { 32 fpuregisters - some scratch registers (minimally 2) }
  158. { Available Superregisters }
  159. {$i rrv64sup.inc}
  160. { No Subregisters }
  161. R_SUBWHOLE=R_SUBNONE;
  162. { Available Registers }
  163. {$i rrv64con.inc}
  164. { Integer Super registers first and last }
  165. first_int_imreg = $20;
  166. { Float Super register first and last }
  167. first_fpu_imreg = $20;
  168. { MM Super register first and last }
  169. first_mm_imreg = $20;
  170. { TODO: Calculate bsstart}
  171. regnumber_count_bsstart = 64;
  172. regnumber_table : array[tregisterindex] of tregister = (
  173. {$i rrv64num.inc}
  174. );
  175. regstabs_table : array[tregisterindex] of shortint = (
  176. {$i rrv64sta.inc}
  177. );
  178. regdwarf_table : array[tregisterindex] of shortint = (
  179. {$i rrv64dwa.inc}
  180. );
  181. {$endif riscv32}
  182. {*****************************************************************************
  183. Conditions
  184. *****************************************************************************}
  185. type
  186. TAsmCond = (C_None { unconditional jumps },
  187. C_LT,C_LTU,C_GE,C_GEU,C_NE,C_EQ);
  188. TAsmConds = set of TAsmCond;
  189. const
  190. cond2str: Array[TAsmCond] of string[4] = ({cf_none}'',
  191. { conditions when not using ctr decrement etc}
  192. 'lt','ltu','ge','geu','ne','eq');
  193. uppercond2str: Array[TAsmCond] of string[4] = ({cf_none}'',
  194. { conditions when not using ctr decrement etc}
  195. 'LT','LTU','GE','GEU','NE','EQ');
  196. {*****************************************************************************
  197. Flags
  198. *****************************************************************************}
  199. type
  200. TResFlagsEnum = (F_EQ,F_NE,F_LT,F_LTU,F_GE,F_GEU);
  201. {*****************************************************************************
  202. Reference
  203. *****************************************************************************}
  204. {*****************************************************************************
  205. Operands
  206. *****************************************************************************}
  207. type
  208. TMemoryOrderingFlag = (moRl, moAq);
  209. TMemoryOrdering = set of TMemoryOrderingFlag;
  210. TFenceFlag = (ffI, ffO, ffR, ffW);
  211. TFenceFlags = set of TFenceFlag;
  212. TRoundingMode = (RM_Default,
  213. RM_RNE,
  214. RM_RTZ,
  215. RM_RDN,
  216. RM_RUP,
  217. RM_RMM);
  218. const
  219. roundingmode2str : array[TRoundingMode] of string[3] = ('',
  220. 'rne','rtz','rdn','rup','rmm');
  221. {*****************************************************************************
  222. Constants
  223. *****************************************************************************}
  224. const
  225. max_operands = 5;
  226. {*****************************************************************************
  227. Default generic sizes
  228. *****************************************************************************}
  229. {# Defines the default address size for a processor, }
  230. {$ifdef RISCV64}
  231. OS_ADDR = OS_64;
  232. {# the natural int size for a processor,
  233. has to match osuinttype/ossinttype as initialized in psystem }
  234. OS_INT = OS_64;
  235. OS_SINT = OS_S64;
  236. {$endif RISCV64}
  237. {$ifdef RISCV32}
  238. OS_ADDR = OS_32;
  239. {# the natural int size for a processor,
  240. has to match osuinttype/ossinttype as initialized in psystem }
  241. OS_INT = OS_32;
  242. OS_SINT = OS_S32;
  243. {$endif RISCV64}
  244. {# the maximum float size for a processor, }
  245. OS_FLOAT = OS_F64;
  246. {# the size of a vector register for a processor }
  247. OS_VECTOR = OS_M128;
  248. {*****************************************************************************
  249. GDB Information
  250. *****************************************************************************}
  251. {$ifdef riscv32}
  252. stab_regindex : array[tregisterindex] of shortint = (
  253. {$i rrv32sta.inc}
  254. );
  255. {$endif riscv32}
  256. {$ifdef riscv64}
  257. stab_regindex : array[tregisterindex] of shortint = (
  258. {$i rrv64sta.inc}
  259. );
  260. {$endif riscv64}
  261. {*****************************************************************************
  262. Generic Register names
  263. *****************************************************************************}
  264. {# Stack pointer register }
  265. NR_STACK_POINTER_REG = NR_X2;
  266. RS_STACK_POINTER_REG = RS_X2;
  267. {# Frame pointer register }
  268. NR_FRAME_POINTER_REG = NR_X8;
  269. RS_FRAME_POINTER_REG = RS_X8;
  270. NR_PIC_OFFSET_REG = NR_X3;
  271. { Return address of a function }
  272. NR_RETURN_ADDRESS_REG = NR_X1;
  273. RS_RETURN_ADDRESS_REG = RS_X1;
  274. { Results are returned in this register (32-bit values) }
  275. NR_FUNCTION_RETURN_REG = NR_X10;
  276. RS_FUNCTION_RETURN_REG = RS_X10;
  277. { Low part of 64bit return value }
  278. NR_FUNCTION_RETURN64_LOW_REG = NR_X10;
  279. RS_FUNCTION_RETURN64_LOW_REG = RS_X10;
  280. { High part of 64bit return value }
  281. NR_FUNCTION_RETURN64_HIGH_REG = NR_X11;
  282. RS_FUNCTION_RETURN64_HIGH_REG = RS_X11;
  283. { The value returned from a function is available in this register }
  284. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  285. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  286. { The lowh part of 64bit value returned from a function }
  287. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  288. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  289. { The high part of 64bit value returned from a function }
  290. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  291. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  292. NR_FPU_RESULT_REG = NR_F10;
  293. NR_MM_RESULT_REG = NR_NO;
  294. NR_DEFAULTFLAGS = NR_NO;
  295. RS_DEFAULTFLAGS = RS_NO;
  296. {*****************************************************************************
  297. GCC /ABI linking information
  298. *****************************************************************************}
  299. {# Registers which must be saved when calling a routine declared as
  300. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  301. saved should be the ones as defined in the target ABI and / or GCC.
  302. This value can be deduced from CALLED_USED_REGISTERS array in the
  303. GCC source.
  304. }
  305. saved_standard_registers : array[0..12] of tsuperregister = (
  306. RS_X2,
  307. RS_X8,RS_X9,
  308. RS_X18,RS_X19,
  309. RS_X20,RS_X21,RS_X22,RS_X23,RS_X24,RS_X25,RS_X26,RS_X27
  310. );
  311. { this is only for the generic code which is not used for this architecture }
  312. saved_address_registers : array[0..0] of tsuperregister = (RS_INVALID);
  313. saved_mm_registers : array[0..0] of tsuperregister = (RS_INVALID);
  314. {# Required parameter alignment when calling a routine declared as
  315. stdcall and cdecl. The alignment value should be the one defined
  316. by GCC or the target ABI.
  317. The value of this constant is equal to the constant
  318. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  319. }
  320. {$ifdef RISCV64}
  321. std_param_align = 8;
  322. {$endif RISCV64}
  323. {$ifdef RISCV32}
  324. std_param_align = 4;
  325. {$endif RISCV32}
  326. {*****************************************************************************
  327. CPU Dependent Constants
  328. *****************************************************************************}
  329. maxfpuregs = 8;
  330. {*****************************************************************************
  331. Helpers
  332. *****************************************************************************}
  333. function is_imm12(value: tcgint): boolean;
  334. function is_lui_imm(value: tcgint): boolean;
  335. function is_calljmp(o:tasmop):boolean;
  336. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  337. { Returns the tcgsize corresponding with the size of reg.}
  338. function reg_cgsize(const reg: tregister) : tcgsize;
  339. function findreg_by_number(r:Tregister):tregisterindex;
  340. function std_regnum_search(const s:string):Tregister;
  341. function std_regname(r:Tregister):string;
  342. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  343. function dwarf_reg(r:tregister):shortint;
  344. function dwarf_reg_no_error(r:tregister):shortint;
  345. function eh_return_data_regno(nr: longint): longint;
  346. function conditions_equal(const c1,c2: TAsmCond): boolean;
  347. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  348. function condition_in(const Subset, c: TAsmCond): Boolean;
  349. function is_extra_reg(const s : string) : tregister;
  350. implementation
  351. uses
  352. rgbase,verbose;
  353. {$ifdef riscv32}
  354. const
  355. std_regname_table : TRegNameTable = (
  356. {$i rrv32std.inc}
  357. );
  358. regnumber_index : array[tregisterindex] of tregisterindex = (
  359. {$i rrv32rni.inc}
  360. );
  361. std_regname_index : array[tregisterindex] of tregisterindex = (
  362. {$i rrv32sri.inc}
  363. );
  364. {$endif riscv32}
  365. {$ifdef riscv64}
  366. const
  367. std_regname_table : TRegNameTable = (
  368. {$i rrv64std.inc}
  369. );
  370. regnumber_index : array[tregisterindex] of tregisterindex = (
  371. {$i rrv64rni.inc}
  372. );
  373. std_regname_index : array[tregisterindex] of tregisterindex = (
  374. {$i rrv64sri.inc}
  375. );
  376. {$endif riscv64}
  377. {*****************************************************************************
  378. Helpers
  379. *****************************************************************************}
  380. function is_imm12(value: tcgint): boolean;
  381. begin
  382. result:=(value >= -2048) and (value <= 2047);
  383. end;
  384. function is_lui_imm(value: tcgint): boolean;
  385. begin
  386. result:=SarInt64((value and $FFFFF000) shl 32, 32) = value;
  387. end;
  388. function is_calljmp(o:tasmop):boolean;
  389. begin
  390. is_calljmp:=false;
  391. case o of
  392. A_JAL,A_JALR,A_Bxx,A_CALL:
  393. is_calljmp:=true;
  394. else
  395. ;
  396. end;
  397. end;
  398. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  399. const
  400. inv_condflags:array[TAsmCond] of TAsmCond=(C_None,
  401. C_GE,C_GEU,C_LT,C_LTU,C_EQ,C_NE);
  402. begin
  403. result := inv_condflags[c];
  404. end;
  405. function reg_cgsize(const reg: tregister): tcgsize;
  406. begin
  407. case getregtype(reg) of
  408. R_INTREGISTER :
  409. result:=OS_INT;
  410. R_MMREGISTER:
  411. result:=OS_M128;
  412. R_FPUREGISTER:
  413. result:=OS_F64;
  414. else
  415. internalerror(200303181);
  416. end;
  417. end;
  418. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  419. begin
  420. cgsize2subreg:=R_SUBWHOLE;
  421. end;
  422. function findreg_by_number(r:Tregister):tregisterindex;
  423. begin
  424. result:=rgBase.findreg_by_number_table(r,regnumber_index);
  425. end;
  426. function std_regnum_search(const s:string):Tregister;
  427. begin
  428. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  429. end;
  430. function std_regname(r:Tregister):string;
  431. var
  432. p : tregisterindex;
  433. begin
  434. p:=findreg_by_number_table(r,regnumber_index);
  435. if p<>0 then
  436. result:=std_regname_table[p]
  437. else
  438. result:=generic_regname(r);
  439. end;
  440. function dwarf_reg(r:tregister):shortint;
  441. begin
  442. result:=regdwarf_table[findreg_by_number(r)];
  443. if result=-1 then
  444. internalerror(200603251);
  445. end;
  446. function dwarf_reg_no_error(r:tregister):shortint;
  447. begin
  448. result:=regdwarf_table[findreg_by_number(r)];
  449. end;
  450. function eh_return_data_regno(nr: longint): longint;
  451. begin
  452. if (nr>=0) and (nr<4) then
  453. result:=nr+10
  454. else
  455. result:=-1;
  456. end;
  457. function conditions_equal(const c1, c2: TAsmCond): boolean;
  458. begin
  459. result:=c1=c2;
  460. end;
  461. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  462. function condition_in(const Subset, c: TAsmCond): Boolean;
  463. begin
  464. Result := (c = C_None) or conditions_equal(Subset, c);
  465. if not Result then
  466. case Subset of
  467. C_EQ:
  468. Result := (c in [C_GE, C_GEU]);
  469. else
  470. Result := False;
  471. end;
  472. end;
  473. function is_extra_reg(const s: string): tregister;
  474. type
  475. treg2str = record
  476. name : string[4];
  477. reg : tregister;
  478. end;
  479. const
  480. extraregs : array[0..32] of treg2str = (
  481. (name: 'A0'; reg : NR_X10),
  482. (name: 'A1'; reg : NR_X11),
  483. (name: 'A2'; reg : NR_X12),
  484. (name: 'A3'; reg : NR_X13),
  485. (name: 'A4'; reg : NR_X14),
  486. (name: 'A5'; reg : NR_X15),
  487. (name: 'A6'; reg : NR_X16),
  488. (name: 'A7'; reg : NR_X17),
  489. (name: 'ZERO'; reg : NR_X0),
  490. (name: 'RA'; reg : NR_X1),
  491. (name: 'SP'; reg : NR_X2),
  492. (name: 'GP'; reg : NR_X3),
  493. (name: 'TP'; reg : NR_X4),
  494. (name: 'T0'; reg : NR_X5),
  495. (name: 'T1'; reg : NR_X6),
  496. (name: 'T2'; reg : NR_X7),
  497. (name: 'S0'; reg : NR_X8),
  498. (name: 'FP'; reg : NR_X8),
  499. (name: 'S1'; reg : NR_X9),
  500. (name: 'S2'; reg : NR_X18),
  501. (name: 'S3'; reg : NR_X19),
  502. (name: 'S4'; reg : NR_X20),
  503. (name: 'S5'; reg : NR_X21),
  504. (name: 'S6'; reg : NR_X22),
  505. (name: 'S7'; reg : NR_X23),
  506. (name: 'S8'; reg : NR_X24),
  507. (name: 'S9'; reg : NR_X25),
  508. (name: 'S10';reg : NR_X26),
  509. (name: 'S11';reg : NR_X27),
  510. (name: 'T3'; reg : NR_X28),
  511. (name: 'T4'; reg : NR_X29),
  512. (name: 'T5'; reg : NR_X30),
  513. (name: 'T6'; reg : NR_X31)
  514. );
  515. var
  516. i : longint;
  517. begin
  518. result:=NR_NO;
  519. { reg found?
  520. possible aliases are always 2 to 4 chars
  521. }
  522. if not (length(s) in [2..4]) then
  523. exit;
  524. for i:=low(extraregs) to high(extraregs) do
  525. begin
  526. if s=extraregs[i].name then
  527. begin
  528. result:=extraregs[i].reg;
  529. exit;
  530. end;
  531. end;
  532. end;
  533. end.