itcpugas.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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','fneg.q',
  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','fmv.x.w',
  108. 'feq.s','flt.s','fle.s','fclass.s',
  109. 'fcvt.w.s','fcvt.wu.s','fcvt.s.w','fcvt.s.wu',
  110. 'fmv.s.x','fmv.w.x',
  111. 'frcsr','frrm','frflags','fscsr','fsrm',
  112. 'fsflags','fsrmi','fsflagsi',
  113. {$ifdef RISCV64}
  114. { 64-bit }
  115. 'fcvt.l.s','fcvt.lu.s',
  116. 'fcvt.s.l','fcvt.s.lu',
  117. {$endif RISCV64}
  118. { d-extension }
  119. 'fld','fsd',
  120. 'fmadd.d','fmsub.d','fnmsub.d','fnmadd.d',
  121. 'fadd.d','fsub.d','fmul.d','fdiv.d',
  122. 'fsqrt.d','fsgnj.d','fsgnjn.d','fsgnjx.d',
  123. 'fmin.d','fmax.d',
  124. 'feq.d','flt.d','fle.d','fclass.d',
  125. 'fcvt.d.s','fcvt.s.d',
  126. 'fcvt.w.d','fcvt.wu.d','fcvt.d.w','fcvt.d.wu',
  127. {$ifdef RISCV64}
  128. { 64-bit }
  129. 'fcvt.l.d','fcvt.lu.d','fmv.x.d',
  130. 'fcvt.d.l','fcvt.d.lu','fmv.d.x',
  131. {$endif RISCV64}
  132. { Zfa extension }
  133. 'fli.s','fli.d','fli.q','fli.h',
  134. 'fminm.s','fmaxm.s','fminm.d','fmaxm.d','fminm.h','fmaxm.h','fminm.q','fmaxm.q',
  135. 'fround.s','froundnx.s','fround.d','froundnx.d','fround.h','froundnx.h','fround.q','froundnx.q',
  136. 'fcvtmod.w.d',
  137. 'fmvh.x.d,','fmvp.d.x','fmvh.x.q','fmvp.q.x',
  138. 'fleq.s,','fltq.s',
  139. 'fleq.d,','fltq.d',
  140. 'fleq.h,','fltq.h',
  141. 'fleq.q,','fltq.q',
  142. { q-extension }
  143. 'flq','fsq',
  144. 'fmax.q','fmax.q',
  145. { Zihintpause }
  146. 'pause',
  147. { Machine mode }
  148. 'mret','hret','sret','uret',
  149. 'wfi',
  150. { Supervisor mode }
  151. 'sfence.vm',
  152. { pseudo instructions for accessiong control and status registers }
  153. 'rdinstret','rdinstreth','rdcycle','rdcycleh','rdtime','rdtimeh','csrr','csrw','csrs','csrc','csrwi',
  154. 'csrsi','csrci'
  155. );
  156. function gas_regnum_search(const s: string): Tregister;
  157. function gas_regname(r: Tregister): string;
  158. implementation
  159. uses
  160. globtype,globals,aasmbase,
  161. cutils,verbose, systems,
  162. rgbase;
  163. {$ifdef riscv32}
  164. const
  165. gas_regname_table : TRegNameTable = (
  166. {$i rrv32std.inc}
  167. );
  168. gas_regname_index : array[tregisterindex] of tregisterindex = (
  169. {$i rrv32sri.inc}
  170. );
  171. {$endif riscv32}
  172. {$ifdef riscv64}
  173. const
  174. gas_regname_table : TRegNameTable = (
  175. {$i rrv64std.inc}
  176. );
  177. gas_regname_index : array[tregisterindex] of tregisterindex = (
  178. {$i rrv64sri.inc}
  179. );
  180. {$endif riscv64}
  181. function findreg_by_gasname(const s:string):tregisterindex;
  182. var
  183. i,p : tregisterindex;
  184. begin
  185. {Binary search.}
  186. p:=0;
  187. i:=regnumber_count_bsstart;
  188. repeat
  189. if (p+i<=high(tregisterindex)) and (gas_regname_table[gas_regname_index[p+i]]<=s) then
  190. p:=p+i;
  191. i:=i shr 1;
  192. until i=0;
  193. if gas_regname_table[gas_regname_index[p]]=s then
  194. findreg_by_gasname:=gas_regname_index[p]
  195. else
  196. findreg_by_gasname:=0;
  197. end;
  198. function gas_regnum_search(const s:string):Tregister;
  199. begin
  200. result:=regnumber_table[findreg_by_gasname(s)];
  201. end;
  202. function gas_regname(r:Tregister):string;
  203. var
  204. p : tregisterindex;
  205. begin
  206. p:=findreg_by_number(r);
  207. if p<>0 then
  208. result:=gas_regname_table[p]
  209. else
  210. result:=generic_regname(r);
  211. end;
  212. end.