sim_api.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef __SIM_API
  2. #define __SIM_API
  3. #define SIM_CMD_ROI_TOGGLE 0 // Deprecated, for compatibility with programs compiled long ago
  4. #define SIM_CMD_ROI_START 1
  5. #define SIM_CMD_ROI_END 2
  6. #define SIM_CMD_MHZ_SET 3
  7. #define SIM_CMD_MARKER 4
  8. #define SIM_CMD_USER 5
  9. #define SIM_CMD_INSTRUMENT_MODE 6
  10. #define SIM_CMD_MHZ_GET 7
  11. #define SIM_CMD_IN_SIMULATOR 8
  12. #define SIM_CMD_PROC_ID 9
  13. #define SIM_CMD_THREAD_ID 10
  14. #define SIM_CMD_NUM_PROCS 11
  15. #define SIM_CMD_NUM_THREADS 12
  16. #define SIM_CMD_NAMED_MARKER 13
  17. #define SIM_CMD_SET_THREAD_NAME 14
  18. #define SIM_OPT_INSTRUMENT_DETAILED 0
  19. #define SIM_OPT_INSTRUMENT_WARMUP 1
  20. #define SIM_OPT_INSTRUMENT_FASTFORWARD 2
  21. #if defined(__i386)
  22. #define MAGIC_REG_A "eax"
  23. #define MAGIC_REG_B "edx" // Required for -fPIC support
  24. #define MAGIC_REG_C "ecx"
  25. #else
  26. #define MAGIC_REG_A "rax"
  27. #define MAGIC_REG_B "rbx"
  28. #define MAGIC_REG_C "rcx"
  29. #endif
  30. #define SimMagic0(cmd) ({ \
  31. unsigned long _cmd = (cmd), _res; \
  32. __asm__ __volatile__ ( \
  33. "mov %1, %%" MAGIC_REG_A "\n" \
  34. "\txchg %%bx, %%bx\n" \
  35. : "=a" (_res) /* output */ \
  36. : "g"(_cmd) /* input */ \
  37. ); /* clobbered */ \
  38. _res; \
  39. })
  40. #define SimMagic1(cmd, arg0) ({ \
  41. unsigned long _cmd = (cmd), _arg0 = (arg0), _res; \
  42. __asm__ __volatile__ ( \
  43. "mov %1, %%" MAGIC_REG_A "\n" \
  44. "\tmov %2, %%" MAGIC_REG_B "\n" \
  45. "\txchg %%bx, %%bx\n" \
  46. : "=a" (_res) /* output */ \
  47. : "g"(_cmd), \
  48. "g"(_arg0) /* input */ \
  49. : "%" MAGIC_REG_B ); /* clobbered */ \
  50. _res; \
  51. })
  52. #define SimMagic2(cmd, arg0, arg1) ({ \
  53. unsigned long _cmd = (cmd), _arg0 = (arg0), _arg1 = (arg1), _res; \
  54. __asm__ __volatile__ ( \
  55. "mov %1, %%" MAGIC_REG_A "\n" \
  56. "\tmov %2, %%" MAGIC_REG_B "\n" \
  57. "\tmov %3, %%" MAGIC_REG_C "\n" \
  58. "\txchg %%bx, %%bx\n" \
  59. : "=a" (_res) /* output */ \
  60. : "g"(_cmd), \
  61. "g"(_arg0), \
  62. "g"(_arg1) /* input */ \
  63. : "%" MAGIC_REG_B, "%" MAGIC_REG_C ); /* clobbered */ \
  64. _res; \
  65. })
  66. #define SimRoiStart() SimMagic0(SIM_CMD_ROI_START)
  67. #define SimRoiEnd() SimMagic0(SIM_CMD_ROI_END)
  68. #define SimGetProcId() SimMagic0(SIM_CMD_PROC_ID)
  69. #define SimGetThreadId() SimMagic0(SIM_CMD_THREAD_ID)
  70. #define SimSetThreadName(name) SimMagic1(SIM_CMD_SET_THREAD_NAME, (unsigned long)(name))
  71. #define SimGetNumProcs() SimMagic0(SIM_CMD_NUM_PROCS)
  72. #define SimGetNumThreads() SimMagic0(SIM_CMD_NUM_THREADS)
  73. #define SimSetFreqMHz(proc, mhz) SimMagic2(SIM_CMD_MHZ_SET, proc, mhz)
  74. #define SimSetOwnFreqMHz(mhz) SimSetFreqMHz(SimGetProcId(), mhz)
  75. #define SimGetFreqMHz(proc) SimMagic1(SIM_CMD_MHZ_GET, proc)
  76. #define SimGetOwnFreqMHz() SimGetFreqMHz(SimGetProcId())
  77. #define SimMarker(arg0, arg1) SimMagic2(SIM_CMD_MARKER, arg0, arg1)
  78. #define SimNamedMarker(arg0, str) SimMagic2(SIM_CMD_NAMED_MARKER, arg0, (unsigned long)(str))
  79. #define SimUser(cmd, arg) SimMagic2(SIM_CMD_USER, cmd, arg)
  80. #define SimSetInstrumentMode(opt) SimMagic1(SIM_CMD_INSTRUMENT_MODE, opt)
  81. #define SimInSimulator() (SimMagic0(SIM_CMD_IN_SIMULATOR)!=SIM_CMD_IN_SIMULATOR)
  82. #endif /* __SIM_API */