itcpugas.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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',
  25. 'lui','auipc','jal','jalr',
  26. 'b','lb','lh','lw','lbu','lhu',
  27. 'sb','sh','sw',
  28. 'addi','slti','sltiu',
  29. 'xori','ori','andi',
  30. 'slli','srli','srai',
  31. 'add','sub','sll','slt','sltu',
  32. 'xor','srl','sra','or','and',
  33. 'fence','fence.i',
  34. 'ecall','ebreak',
  35. 'csrrw','csrrs','csrrc','csrrwi','csrrsi','csrrci',
  36. {$ifdef RISCV64}
  37. { 64-bit }
  38. 'addiw','slliw','srliw','sraiw',
  39. 'addw','sllw','srlw','subw','sraw',
  40. 'ld','sd','lwu',
  41. {$endif RISCV64}
  42. { m-extension }
  43. 'mul','mulh','mulhsu','mulhu',
  44. 'div','divu','rem','remu',
  45. {$ifdef RISCV64}
  46. { 64-bit }
  47. 'mulw',
  48. 'divw','divuw','remw','remuw',
  49. {$endif RISCV64}
  50. { a-extension }
  51. 'lr.w','sc.w','amoswap.w','amoadd.w','amoxor.w','amoand.w',
  52. 'amoor.w','amomin.w','amomax.w','amominu.w','amomaxu.w',
  53. {$ifdef RISCV64}
  54. { 64-bit }
  55. 'lr.d','sc.d','amoswap.d','amoadd.d','amoxor.d','amoand.d',
  56. 'amoor.d','amomin.d','amomax.d','amominu.d','amomaxu.d',
  57. {$endif RISCV64}
  58. { f-extension }
  59. 'flw','fsw',
  60. 'fmadd.s','fmsub.s','fnmsub.s','fnmadd.s',
  61. 'fadd.s','fsub.s','fmul.s','fdiv.s',
  62. 'fsqrt.s','fsgnj.s','fsgnjn.s','fsgnjx.s',
  63. 'fmin.s','fmax.s',
  64. 'fmv.x.s','feq.s','flt.s','fle.s','fclass.s',
  65. 'fcvt.w.s','fcvt.wu.s','fcvt.s.w','fcvt.s.wu',
  66. 'fmv.s.x',
  67. 'frcsr','frrm','frflags','fscsr','fsrm',
  68. 'fsflags','fsrmi','fsflagsi',
  69. {$ifdef RISCV64}
  70. { 64-bit }
  71. 'fcvt.l.s','fcvt.lu.s',
  72. 'fcvt.s.l','fcvt.s.lu',
  73. {$endif RISCV64}
  74. { d-extension }
  75. 'fld','fsd',
  76. 'fmadd.d','fmsub.d','fnmsub.d','fnmadd.d',
  77. 'fadd.d','fsub.d','fmul.d','fdiv.d',
  78. 'fsqrt.d','fsgnj.d','fsgnjn.d','fsgnjx.d',
  79. 'fmin.d','fmax.d',
  80. 'feq.d','flt.d','fle.d','fclass.d',
  81. 'fcvt.d.s','fcvt.s.d',
  82. 'fcvt.w.d','fcvt.wu.d','fcvt.d.w','fcvt.d.wu',
  83. {$ifdef RISCV64}
  84. { 64-bit }
  85. 'fcvt.l.d','fcvt.lu.d','fmv.x.d',
  86. 'fcvt.d.l','fcvt.d.lu','fmv.d.x',
  87. {$endif RISCV64}
  88. { Machine mode }
  89. 'mret','hret','sret','uret',
  90. 'wfi',
  91. { Supervisor mode }
  92. 'sfence.vm'
  93. );
  94. function gas_regnum_search(const s: string): Tregister;
  95. function gas_regname(r: Tregister): string;
  96. implementation
  97. uses
  98. globtype,globals,aasmbase,
  99. cutils,verbose, systems,
  100. rgbase;
  101. const
  102. gas_regname_table : TRegNameTable = (
  103. {$i rrv32std.inc}
  104. );
  105. gas_regname_index : array[tregisterindex] of tregisterindex = (
  106. {$i rrv32sri.inc}
  107. );
  108. function findreg_by_gasname(const s:string):tregisterindex;
  109. var
  110. i,p : tregisterindex;
  111. begin
  112. {Binary search.}
  113. p:=0;
  114. i:=regnumber_count_bsstart;
  115. repeat
  116. if (p+i<=high(tregisterindex)) and (gas_regname_table[gas_regname_index[p+i]]<=s) then
  117. p:=p+i;
  118. i:=i shr 1;
  119. until i=0;
  120. if gas_regname_table[gas_regname_index[p]]=s then
  121. findreg_by_gasname:=gas_regname_index[p]
  122. else
  123. findreg_by_gasname:=0;
  124. end;
  125. function gas_regnum_search(const s:string):Tregister;
  126. begin
  127. result:=regnumber_table[findreg_by_gasname(s)];
  128. end;
  129. function gas_regname(r:Tregister):string;
  130. var
  131. p : tregisterindex;
  132. begin
  133. p:=findreg_by_number(r);
  134. if p<>0 then
  135. result:=gas_regname_table[p]
  136. else
  137. result:=generic_regname(r);
  138. end;
  139. end.