machine_x86.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 Machine_X86
  43. {
  44. public:
  45. Machine_X86();
  46. static const std::string &regName(eReg r);
  47. static const std::string &opcodeName(unsigned r);
  48. static const std::string &floatOpName(unsigned r);
  49. static bool physicalReg(eReg r);
  50. /* Writes the registers that are set in the bitvector */
  51. //TODO: move this into Machine_X86 ?
  52. static void writeBitVector (std::ostream &ostr,const std::bitset<32> &regi)
  53. {
  54. int j;
  55. for (j = rAX; j < INDEX_BX_SI; j++)
  56. {
  57. if (regi.test(j-1))
  58. ostr << regName(eReg(j));
  59. }
  60. }
  61. static eReg subRegH(eReg reg); //TODO: move these into machine_x86
  62. static eReg subRegL(eReg reg);
  63. static bool isMemOff(eReg r);
  64. static bool isSubRegisterOf(eReg reg, eReg parent);
  65. };