itcpugas.pas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit contains the i386 AT&T 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. cgbase,cpubase;
  22. type
  23. TAttSuffix = (AttSufNONE,AttSufINT,AttSufFPU,AttSufFPUint,AttSufINTdual,AttSufMM,AttSufMMX,AttSufMMS);
  24. const
  25. { include mnemonic strings }
  26. {$if defined(x86_64)}
  27. gas_op2str:op2strtable={$i x8664att.inc}
  28. gas_needsuffix:array[tasmop] of TAttSuffix={$i x8664ats.inc}
  29. {$elseif defined(i386)}
  30. gas_op2str:op2strtable={$i i386att.inc}
  31. gas_needsuffix:array[tasmop] of TAttSuffix={$i i386atts.inc}
  32. {$elseif defined(i8086)}
  33. gas_op2str:op2strtable={$i i8086att.inc}
  34. gas_needsuffix:array[tasmop] of TAttSuffix={$i i8086atts.inc}
  35. {$endif}
  36. {$ifdef x86_64}
  37. gas_opsize2str : array[topsize] of string[2] = ('',
  38. 'b','w','l','q','bw','bl','wl','bq','wq','lq',
  39. 's','l','q',
  40. 's','l','t','v','x',
  41. 'd',
  42. '','','',
  43. 't',
  44. 'x',
  45. 'y',
  46. 'z'
  47. );
  48. { suffix-to-opsize conversion tables, used in asmreadrer }
  49. { !! S_LQ excluded: movzlq does not exist, movslq is processed
  50. as a separate instruction w/o suffix (aka movsxd), and there are
  51. no more instructions needing it. }
  52. att_sizesuffixstr : array[0..14] of string[2] = (
  53. '','BW','BL','WL','BQ','WQ',{'LQ',}'B','W','L','S','Q','T','X','Y','Z'
  54. );
  55. att_sizesuffix : array[0..14] of topsize = (
  56. S_NO,S_BW,S_BL,S_WL,S_BQ,S_WQ,{S_LQ,}S_B,S_W,S_L,S_NO,S_Q,S_NO,S_NO,S_NO,S_NO
  57. );
  58. att_sizefpusuffix : array[0..14] of topsize = (
  59. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,{S_NO,}S_NO,S_NO,S_FL,S_FS,S_NO,S_FX,S_NO,S_NO,S_NO
  60. );
  61. att_sizefpuintsuffix : array[0..14] of topsize = (
  62. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,{S_NO,}S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO,S_NO,S_NO,S_NO
  63. );
  64. att_sizemmsuffix : array[0..14] of topsize = (
  65. S_NO,S_NO,S_NO,S_NO,S_NO, S_NO,{S_NO,}S_NO,S_NO,S_IL,S_NO,S_IQ,S_NO,S_XMM,S_YMM,S_ZMM
  66. );
  67. att_sizemmxsuffix : array[0..14] of topsize = (
  68. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,{S_NO,}S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_XMM,S_NO,S_NO
  69. );
  70. {$else x86_64}
  71. gas_opsize2str : array[topsize] of string[2] = ('',
  72. 'b','w','l','q','bw','bl','wl',
  73. 's','l','q',
  74. 's','l','t','v','',
  75. 'd',
  76. '','','',
  77. 't',
  78. 'x',
  79. 'y',
  80. 'z'
  81. );
  82. { suffix-to-opsize conversion tables, used in asmreadrer }
  83. att_sizesuffixstr : array[0..12] of string[2] = (
  84. '','BW','BL','WL','B','W','L','S','Q','T','X','Y','Z'
  85. );
  86. att_sizesuffix : array[0..12] of topsize = (
  87. S_NO,S_BW,S_BL,S_WL,S_B,S_W,S_L,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO
  88. );
  89. att_sizefpusuffix : array[0..12] of topsize = (
  90. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_FL,S_FS,S_NO,S_FX,S_NO,S_NO,S_NO
  91. );
  92. att_sizefpuintsuffix : array[0..12] of topsize = (
  93. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO,S_NO,S_NO,S_NO
  94. );
  95. att_sizemmsuffix : array[0..12] of topsize = (
  96. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_XMM,S_YMM,S_ZMM
  97. );
  98. att_sizemmxsuffix : array[0..12] of topsize = (
  99. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_XMM,S_NO,S_NO
  100. );
  101. {$endif x86_64}
  102. function gas_regnum_search(const s:string):Tregister;
  103. function gas_regname(r:Tregister):string;
  104. implementation
  105. uses
  106. cutils,rgbase;
  107. const
  108. {$if defined(x86_64)}
  109. att_regname_table : TRegNameTable = (
  110. {r8664att.inc contains the AT&T name of each register.}
  111. {$i r8664att.inc}
  112. );
  113. att_regname_index : array[tregisterindex] of tregisterindex = (
  114. {r8664ari.inc contains an index which sorts att_regname_table by
  115. ATT name.}
  116. {$i r8664ari.inc}
  117. );
  118. {$elseif defined(i386)}
  119. att_regname_table : TRegNameTable = (
  120. {r386att.inc contains the AT&T name of each register.}
  121. {$i r386att.inc}
  122. );
  123. att_regname_index : array[tregisterindex] of tregisterindex = (
  124. {r386ari.inc contains an index which sorts att_regname_table by
  125. ATT name.}
  126. {$i r386ari.inc}
  127. );
  128. {$elseif defined(i8086)}
  129. att_regname_table : TRegNameTable = (
  130. {r8086att.inc contains the AT&T name of each register.}
  131. {$i r8086att.inc}
  132. );
  133. att_regname_index : array[tregisterindex] of tregisterindex = (
  134. {r8086ari.inc contains an index which sorts att_regname_table by
  135. ATT name.}
  136. {$i r8086ari.inc}
  137. );
  138. {$endif}
  139. function gas_regnum_search(const s:string):Tregister;
  140. begin
  141. result:=regnumber_table[findreg_by_name_table(s,att_regname_table,att_regname_index)];
  142. end;
  143. function gas_regname(r:Tregister):string;
  144. var
  145. p : tregisterindex;
  146. begin
  147. p:=findreg_by_number(r);
  148. if p<>0 then
  149. result:=att_regname_table[p]
  150. else
  151. result:='%'+generic_regname(r);
  152. end;
  153. end.