itcpugas.pas 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit contains the i386 AT&T instruction tables
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit itcpugas;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cgbase,cpubase;
  23. type
  24. TAttSuffix = (AttSufNONE,AttSufINT,AttSufFPU,AttSufFPUint);
  25. const
  26. {$ifdef x86_64}
  27. {x86att.inc contains the name for each x86-64 mnemonic}
  28. gas_op2str:op2strtable={$i x8664att.inc}
  29. gas_needsuffix:array[tasmop] of TAttSuffix={$i x8664ats.inc}
  30. {$else x86_64}
  31. {x86att.inc contains the name for each i386 mnemonic}
  32. gas_op2str:op2strtable={$i i386att.inc}
  33. gas_needsuffix:array[tasmop] of TAttSuffix={$i i386atts.inc}
  34. {$endif x86_64}
  35. {$ifdef x86_64}
  36. gas_opsize2str : array[topsize] of string[2] = ('',
  37. 'b','w','l','q','bw','bl','wl','bq','wq','lq',
  38. 's','l','q',
  39. 's','l','t','v','x',
  40. 'd',
  41. '','',''
  42. );
  43. {$else x86_64}
  44. gas_opsize2str : array[topsize] of string[2] = ('',
  45. 'b','w','l','q','bw','bl','wl',
  46. 's','l','q',
  47. 's','l','t','v','',
  48. 'd',
  49. '','',''
  50. );
  51. {$endif x86_64}
  52. function gas_regnum_search(const s:string):Tregister;
  53. function gas_regname(r:Tregister):string;
  54. implementation
  55. uses
  56. cutils,verbose;
  57. const
  58. {$ifdef x86_64}
  59. att_regname_table : array[tregisterindex] of string[7] = (
  60. {r8664att.inc contains the AT&T name of each register.}
  61. {$i r8664att.inc}
  62. );
  63. att_regname_index : array[tregisterindex] of tregisterindex = (
  64. {r8664ari.inc contains an index which sorts att_regname_table by
  65. ATT name.}
  66. {$i r8664ari.inc}
  67. );
  68. {$else x86_64}
  69. att_regname_table : array[tregisterindex] of string[7] = (
  70. {r386att.inc contains the AT&T name of each register.}
  71. {$i r386att.inc}
  72. );
  73. att_regname_index : array[tregisterindex] of tregisterindex = (
  74. {r386ari.inc contains an index which sorts att_regname_table by
  75. ATT name.}
  76. {$i r386ari.inc}
  77. );
  78. {$endif x86_64}
  79. function findreg_by_attname(const s:string):byte;
  80. var
  81. i,p : tregisterindex;
  82. begin
  83. {Binary search.}
  84. p:=0;
  85. i:=regnumber_count_bsstart;
  86. repeat
  87. if (p+i<=high(tregisterindex)) and (att_regname_table[att_regname_index[p+i]]<=s) then
  88. p:=p+i;
  89. i:=i shr 1;
  90. until i=0;
  91. if att_regname_table[att_regname_index[p]]=s then
  92. findreg_by_attname:=att_regname_index[p]
  93. else
  94. findreg_by_attname:=0;
  95. end;
  96. function gas_regnum_search(const s:string):Tregister;
  97. begin
  98. result:=regnumber_table[findreg_by_attname(s)];
  99. end;
  100. function gas_regname(r:Tregister):string;
  101. var
  102. p : tregisterindex;
  103. begin
  104. p:=findreg_by_number(r);
  105. if p<>0 then
  106. result:=att_regname_table[p]
  107. else
  108. result:='%'+generic_regname(r);
  109. end;
  110. end.
  111. {
  112. $Log$
  113. Revision 1.4 2004-06-20 08:55:32 florian
  114. * logs truncated
  115. Revision 1.3 2004/02/05 18:28:37 peter
  116. * x86_64 fixes for opsize
  117. Revision 1.2 2004/01/15 14:01:32 florian
  118. + x86 instruction tables for x86-64 extended
  119. }