itcpugas.pas 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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','zext.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. { pseudo instructions }
  45. 'ld','sd','lwu','sext.w','zext.w',
  46. {$endif RISCV64}
  47. { m-extension }
  48. 'mul','mulh','mulhsu','mulhu',
  49. 'div','divu','rem','remu',
  50. {$ifdef RISCV64}
  51. { 64-bit }
  52. 'mulw',
  53. 'divw','divuw','remw','remuw',
  54. {$endif RISCV64}
  55. { a-extension }
  56. 'lr.w','sc.w','amoswap.w','amoadd.w','amoxor.w','amoand.w',
  57. 'amoor.w','amomin.w','amomax.w','amominu.w','amomaxu.w',
  58. {$ifdef RISCV64}
  59. { 64-bit }
  60. 'lr.d','sc.d','amoswap.d','amoadd.d','amoxor.d','amoand.d',
  61. 'amoor.d','amomin.d','amomax.d','amominu.d','amomaxu.d',
  62. {$endif RISCV64}
  63. { B-extension }
  64. 'add.uw','andn','clmul','clmulh','clmulr','clz',
  65. {$ifdef RISCV64}
  66. 'clzw',
  67. {$endif RISCV64}
  68. 'cpop',
  69. {$ifdef RISCV64}
  70. 'cpopw',
  71. {$endif RISCV64}
  72. 'ctz',
  73. {$ifdef RISCV64}
  74. 'ctzw',
  75. {$endif RISCV64}
  76. 'max','maxu','min','minu','orc.b','orn','rev8','rol',
  77. {$ifdef RISCV64}
  78. 'rolw',
  79. {$endif RISCV64}
  80. 'ror','rori',
  81. {$ifdef RISCV64}
  82. 'roriw',
  83. 'rorw',
  84. {$endif RISCV64}
  85. 'bclr','bclri','bext','bexti','binv','binvi','bset','seti',{ 'sext.b','sext.h', }
  86. 'sh1add',
  87. {$ifdef RISCV64}
  88. 'sh1add.uw',
  89. {$endif RISCV64}
  90. 'sh2add',
  91. {$ifdef RISCV64}
  92. 'sh2add.uw',
  93. {$endif RISCV64}
  94. 'sh3add',
  95. {$ifdef RISCV64}
  96. 'sh3add.uw',
  97. 'slli.uw',
  98. {$endif RISCV64}
  99. 'xnor',
  100. { 'zext.h', }
  101. { f-extension }
  102. 'flw','fsw',
  103. 'fmadd.s','fmsub.s','fnmsub.s','fnmadd.s',
  104. 'fadd.s','fsub.s','fmul.s','fdiv.s',
  105. 'fsqrt.s','fsgnj.s','fsgnjn.s','fsgnjx.s',
  106. 'fmin.s','fmax.s',
  107. 'fmv.x.s','feq.s','flt.s','fle.s','fclass.s',
  108. 'fcvt.w.s','fcvt.wu.s','fcvt.s.w','fcvt.s.wu',
  109. 'fmv.s.x',
  110. 'frcsr','frrm','frflags','fscsr','fsrm',
  111. 'fsflags','fsrmi','fsflagsi',
  112. {$ifdef RISCV64}
  113. { 64-bit }
  114. 'fcvt.l.s','fcvt.lu.s',
  115. 'fcvt.s.l','fcvt.s.lu',
  116. {$endif RISCV64}
  117. { d-extension }
  118. 'fld','fsd',
  119. 'fmadd.d','fmsub.d','fnmsub.d','fnmadd.d',
  120. 'fadd.d','fsub.d','fmul.d','fdiv.d',
  121. 'fsqrt.d','fsgnj.d','fsgnjn.d','fsgnjx.d',
  122. 'fmin.d','fmax.d',
  123. 'feq.d','flt.d','fle.d','fclass.d',
  124. 'fcvt.d.s','fcvt.s.d',
  125. 'fcvt.w.d','fcvt.wu.d','fcvt.d.w','fcvt.d.wu',
  126. {$ifdef RISCV64}
  127. { 64-bit }
  128. 'fcvt.l.d','fcvt.lu.d','fmv.x.d',
  129. 'fcvt.d.l','fcvt.d.lu','fmv.d.x',
  130. {$endif RISCV64}
  131. { q-extension }
  132. 'fmax.q','fmax.q',
  133. { Machine mode }
  134. 'mret','hret','sret','uret',
  135. 'wfi',
  136. { Supervisor mode }
  137. 'sfence.vm',
  138. { pseudo instructions for accessiong control and status registers }
  139. 'rdinstret','rdinstreth','rdcycle','rdcycleh','rdtime','rdtimeh','csrr','csrw','csrs','csrc','csrwi',
  140. 'csrsi','csrci'
  141. );
  142. function gas_regnum_search(const s: string): Tregister;
  143. function gas_regname(r: Tregister): string;
  144. implementation
  145. uses
  146. globtype,globals,aasmbase,
  147. cutils,verbose, systems,
  148. rgbase;
  149. {$ifdef riscv32}
  150. const
  151. gas_regname_table : TRegNameTable = (
  152. {$i rrv32std.inc}
  153. );
  154. gas_regname_index : array[tregisterindex] of tregisterindex = (
  155. {$i rrv32sri.inc}
  156. );
  157. {$endif riscv32}
  158. {$ifdef riscv64}
  159. const
  160. gas_regname_table : TRegNameTable = (
  161. {$i rrv64std.inc}
  162. );
  163. gas_regname_index : array[tregisterindex] of tregisterindex = (
  164. {$i rrv64sri.inc}
  165. );
  166. {$endif riscv64}
  167. function findreg_by_gasname(const s:string):tregisterindex;
  168. var
  169. i,p : tregisterindex;
  170. begin
  171. {Binary search.}
  172. p:=0;
  173. i:=regnumber_count_bsstart;
  174. repeat
  175. if (p+i<=high(tregisterindex)) and (gas_regname_table[gas_regname_index[p+i]]<=s) then
  176. p:=p+i;
  177. i:=i shr 1;
  178. until i=0;
  179. if gas_regname_table[gas_regname_index[p]]=s then
  180. findreg_by_gasname:=gas_regname_index[p]
  181. else
  182. findreg_by_gasname:=0;
  183. end;
  184. function gas_regnum_search(const s:string):Tregister;
  185. begin
  186. result:=regnumber_table[findreg_by_gasname(s)];
  187. end;
  188. function gas_regname(r:Tregister):string;
  189. var
  190. p : tregisterindex;
  191. begin
  192. p:=findreg_by_number(r);
  193. if p<>0 then
  194. result:=gas_regname_table[p]
  195. else
  196. result:=generic_regname(r);
  197. end;
  198. end.