machine_x86.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #include <stdint.h>
  3. #include <string>
  4. #include <sstream>
  5. #include <bitset>
  6. /* Machine registers */
  7. enum eReg
  8. {
  9. rUNDEF = 0,
  10. rAX = 1, /* These are numbered relative to real 8086 */
  11. rCX = 2,
  12. rDX = 3,
  13. rBX = 4,
  14. rSP = 5,
  15. rBP = 6,
  16. rSI = 7,
  17. rDI = 8,
  18. rES = 9,
  19. rCS = 10,
  20. rSS = 11,
  21. rDS = 12,
  22. rAL = 13,
  23. rCL = 14,
  24. rDL = 15,
  25. rBL = 16,
  26. rAH = 17,
  27. rCH = 18,
  28. rDH = 19,
  29. rBH = 20,
  30. rTMP= 21, /* temp register for DIV/IDIV/MOD */
  31. /* Indexed modes go from INDEXBASE to INDEXBASE+7 */
  32. INDEX_BX_SI = 22, // "bx+si"
  33. INDEX_BX_DI, // "bx+di"
  34. INDEX_BP_SI, // "bp+si"
  35. INDEX_BP_DI, // "bp+di"
  36. INDEX_SI, // "si"
  37. INDEX_DI, // "di"
  38. INDEX_BP, // "bp"
  39. INDEX_BX, // "bx"
  40. LAST_REG
  41. };
  42. class SourceMachine
  43. {
  44. public:
  45. virtual bool physicalReg(eReg r)=0;
  46. };
  47. //class Machine_X86_Disassembler
  48. //{
  49. // void formatRM(std::ostringstream &p, uint32_t flg, const LLOperand &pm);
  50. //};
  51. class Machine_X86 : public SourceMachine
  52. {
  53. public:
  54. Machine_X86();
  55. virtual ~Machine_X86() {}
  56. static const std::string &regName(eReg r);
  57. static const std::string &opcodeName(unsigned r);
  58. static const std::string &floatOpName(unsigned r);
  59. bool physicalReg(eReg r);
  60. /* Writes the registers that are set in the bitvector */
  61. //TODO: move this into Machine_X86 ?
  62. static void writeRegVector (std::ostream &ostr,const std::bitset<32> &regi)
  63. {
  64. int j;
  65. for (j = rAX; j < INDEX_BX_SI; j++)
  66. {
  67. if (regi.test(j-1))
  68. ostr << regName(eReg(j))<<" ";
  69. }
  70. }
  71. static eReg subRegH(eReg reg);
  72. static eReg subRegL(eReg reg);
  73. static bool isMemOff(eReg r);
  74. static bool isSubRegisterOf(eReg reg, eReg parent);
  75. };