itcpugas.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit contains the RiscV GAS instruction tables
  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. unit itcpugas;
  18. {$I fpcdefs.inc}
  19. interface
  20. uses
  21. cpubase, cgbase;
  22. const
  23. gas_op2str: array[tasmop] of string[14] = ('<none>',
  24. 'nop','call','la','lla','lga','li','mv','not','neg','negw',
  25. 'sext.b','sext.h','zext.b','zex.h','seqz','sneg','sltz','sgtz',
  26. 'fmv.s','fabs.s','fneg.s','fmv.d','fabs.d','fneg.d',
  27. 'beqz','bnez','blez','bgez','bltz','bgtz','gt','ble',
  28. 'bgtu','bleu','j','jr','ret','tail',
  29. 'lui','auipc','jal','jalr',
  30. 'b','lb','lh','lw','lbu','lhu',
  31. 'sb','sh','sw',
  32. 'addi','slti','sltiu',
  33. 'xori','ori','andi',
  34. 'slli','srli','srai',
  35. 'add','sub','sll','slt','sltu',
  36. 'xor','srl','sra','or','and',
  37. 'fence','fence.i',
  38. 'ecall','ebreak',
  39. 'csrrw','csrrs','csrrc','csrrwi','csrrsi','csrrci',
  40. {$ifdef RISCV64}
  41. { 64-bit }
  42. 'addiw','slliw','srliw','sraiw',
  43. 'addw','sllw','srlw','subw','sraw',
  44. 'ld','sd','lwu',
  45. {$endif RISCV64}
  46. { m-extension }
  47. 'mul','mulh','mulhsu','mulhu',
  48. 'div','divu','rem','remu',
  49. {$ifdef RISCV64}
  50. { 64-bit }
  51. 'mulw',
  52. 'divw','divuw','remw','remuw',
  53. {$endif RISCV64}
  54. { a-extension }
  55. 'lr.w','sc.w','amoswap.w','amoadd.w','amoxor.w','amoand.w',
  56. 'amoor.w','amomin.w','amomax.w','amominu.w','amomaxu.w',
  57. {$ifdef RISCV64}
  58. { 64-bit }
  59. 'lr.d','sc.d','amoswap.d','amoadd.d','amoxor.d','amoand.d',
  60. 'amoor.d','amomin.d','amomax.d','amominu.d','amomaxu.d',
  61. {$endif RISCV64}
  62. { f-extension }
  63. 'flw','fsw',
  64. 'fmadd.s','fmsub.s','fnmsub.s','fnmadd.s',
  65. 'fadd.s','fsub.s','fmul.s','fdiv.s',
  66. 'fsqrt.s','fsgnj.s','fsgnjn.s','fsgnjx.s',
  67. 'fmin.s','fmax.s',
  68. 'fmv.x.s','feq.s','flt.s','fle.s','fclass.s',
  69. 'fcvt.w.s','fcvt.wu.s','fcvt.s.w','fcvt.s.wu',
  70. 'fmv.s.x',
  71. 'frcsr','frrm','frflags','fscsr','fsrm',
  72. 'fsflags','fsrmi','fsflagsi',
  73. {$ifdef RISCV64}
  74. { 64-bit }
  75. 'fcvt.l.s','fcvt.lu.s',
  76. 'fcvt.s.l','fcvt.s.lu',
  77. {$endif RISCV64}
  78. { d-extension }
  79. 'fld','fsd',
  80. 'fmadd.d','fmsub.d','fnmsub.d','fnmadd.d',
  81. 'fadd.d','fsub.d','fmul.d','fdiv.d',
  82. 'fsqrt.d','fsgnj.d','fsgnjn.d','fsgnjx.d',
  83. 'fmin.d','fmax.d',
  84. 'feq.d','flt.d','fle.d','fclass.d',
  85. 'fcvt.d.s','fcvt.s.d',
  86. 'fcvt.w.d','fcvt.wu.d','fcvt.d.w','fcvt.d.wu',
  87. {$ifdef RISCV64}
  88. { 64-bit }
  89. 'fcvt.l.d','fcvt.lu.d','fmv.x.d',
  90. 'fcvt.d.l','fcvt.d.lu','fmv.d.x',
  91. {$endif RISCV64}
  92. { Machine mode }
  93. 'mret','hret','sret','uret',
  94. 'wfi',
  95. { Supervisor mode }
  96. 'sfence.vm',
  97. { pseudo instructions for accessiong control and status registers }
  98. 'rdinstret','rdcycle','rdtime','csrr','csrw','csrs','csrc','csrwi',
  99. 'csrsi','csrci'
  100. );
  101. function gas_regnum_search(const s: string): Tregister;
  102. function gas_regname(r: Tregister): string;
  103. implementation
  104. uses
  105. globtype,globals,aasmbase,
  106. cutils,verbose, systems,
  107. rgbase;
  108. const
  109. gas_regname_table : TRegNameTable = (
  110. {$i rrv32std.inc}
  111. );
  112. gas_regname_index : array[tregisterindex] of tregisterindex = (
  113. {$i rrv32sri.inc}
  114. );
  115. function findreg_by_gasname(const s:string):tregisterindex;
  116. var
  117. i,p : tregisterindex;
  118. begin
  119. {Binary search.}
  120. p:=0;
  121. i:=regnumber_count_bsstart;
  122. repeat
  123. if (p+i<=high(tregisterindex)) and (gas_regname_table[gas_regname_index[p+i]]<=s) then
  124. p:=p+i;
  125. i:=i shr 1;
  126. until i=0;
  127. if gas_regname_table[gas_regname_index[p]]=s then
  128. findreg_by_gasname:=gas_regname_index[p]
  129. else
  130. findreg_by_gasname:=0;
  131. end;
  132. function gas_regnum_search(const s:string):Tregister;
  133. begin
  134. result:=regnumber_table[findreg_by_gasname(s)];
  135. end;
  136. function gas_regname(r:Tregister):string;
  137. var
  138. p : tregisterindex;
  139. begin
  140. p:=findreg_by_number(r);
  141. if p<>0 then
  142. result:=gas_regname_table[p]
  143. else
  144. result:=generic_regname(r);
  145. end;
  146. end.