itcpugas.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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);
  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. );
  47. { suffix-to-opsize conversion tables, used in asmreadrer }
  48. { !! S_LQ excluded: movzlq does not exist, movslq is processed
  49. as a separate instruction w/o suffix (aka movsxd), and there are
  50. no more instructions needing it. }
  51. att_sizesuffixstr : array[0..13] of string[2] = (
  52. '','BW','BL','WL','BQ','WQ',{'LQ',}'B','W','L','S','Q','T','X','Y'
  53. );
  54. att_sizesuffix : array[0..13] of topsize = (
  55. 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
  56. );
  57. att_sizefpusuffix : array[0..13] of topsize = (
  58. 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
  59. );
  60. att_sizefpuintsuffix : array[0..13] of topsize = (
  61. 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
  62. );
  63. att_sizemmsuffix : array[0..13] of topsize = (
  64. 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_YMM
  65. );
  66. {$else x86_64}
  67. gas_opsize2str : array[topsize] of string[2] = ('',
  68. 'b','w','l','q','bw','bl','wl',
  69. 's','l','q',
  70. 's','l','t','v','',
  71. 'd',
  72. '','','',
  73. 't',
  74. 'x',
  75. 'y'
  76. );
  77. { suffix-to-opsize conversion tables, used in asmreadrer }
  78. att_sizesuffixstr : array[0..11] of string[2] = (
  79. '','BW','BL','WL','B','W','L','S','Q','T','X','Y'
  80. );
  81. att_sizesuffix : array[0..11] of topsize = (
  82. S_NO,S_BW,S_BL,S_WL,S_B,S_W,S_L,S_NO,S_NO,S_NO,S_NO,S_NO
  83. );
  84. att_sizefpusuffix : array[0..11] of topsize = (
  85. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_FL,S_FS,S_NO,S_FX,S_NO,S_NO
  86. );
  87. att_sizefpuintsuffix : array[0..11] of topsize = (
  88. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO,S_NO,S_NO
  89. );
  90. att_sizemmsuffix : array[0..11] of topsize = (
  91. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_XMM,S_YMM
  92. );
  93. {$endif x86_64}
  94. function gas_regnum_search(const s:string):Tregister;
  95. function gas_regname(r:Tregister):string;
  96. implementation
  97. uses
  98. cutils,rgbase;
  99. const
  100. {$if defined(x86_64)}
  101. att_regname_table : TRegNameTable = (
  102. {r8664att.inc contains the AT&T name of each register.}
  103. {$i r8664att.inc}
  104. );
  105. att_regname_index : array[tregisterindex] of tregisterindex = (
  106. {r8664ari.inc contains an index which sorts att_regname_table by
  107. ATT name.}
  108. {$i r8664ari.inc}
  109. );
  110. {$elseif defined(i386)}
  111. att_regname_table : TRegNameTable = (
  112. {r386att.inc contains the AT&T name of each register.}
  113. {$i r386att.inc}
  114. );
  115. att_regname_index : array[tregisterindex] of tregisterindex = (
  116. {r386ari.inc contains an index which sorts att_regname_table by
  117. ATT name.}
  118. {$i r386ari.inc}
  119. );
  120. {$elseif defined(i8086)}
  121. att_regname_table : TRegNameTable = (
  122. {r8086att.inc contains the AT&T name of each register.}
  123. {$i r8086att.inc}
  124. );
  125. att_regname_index : array[tregisterindex] of tregisterindex = (
  126. {r8086ari.inc contains an index which sorts att_regname_table by
  127. ATT name.}
  128. {$i r8086ari.inc}
  129. );
  130. {$endif}
  131. function gas_regnum_search(const s:string):Tregister;
  132. begin
  133. result:=regnumber_table[findreg_by_name_table(s,att_regname_table,att_regname_index)];
  134. end;
  135. function gas_regname(r:Tregister):string;
  136. var
  137. p : tregisterindex;
  138. begin
  139. p:=findreg_by_number(r);
  140. if p<>0 then
  141. result:=att_regname_table[p]
  142. else
  143. result:='%'+generic_regname(r);
  144. end;
  145. end.