magic_client.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "magic_client.h"
  2. #include "magic_server.h"
  3. #include "sim_api.h"
  4. #include "simulator.h"
  5. #include "core.h"
  6. #include "core_manager.h"
  7. #include "thread.h"
  8. #include "thread_manager.h"
  9. static UInt64 handleMagic(thread_id_t thread_id, UInt64 cmd, UInt64 arg0 = 0, UInt64 arg1 = 0)
  10. {
  11. Thread *thread = (thread_id == INVALID_THREAD_ID) ? NULL : Sim()->getThreadManager()->getThreadFromID(thread_id);
  12. Core *core = thread == NULL ? NULL : thread->getCore();
  13. return Sim()->getMagicServer()->Magic(thread_id, core ? core->getId() : INVALID_CORE_ID, cmd, arg0, arg1);
  14. }
  15. void setInstrumentationMode(UInt64 opt)
  16. {
  17. handleMagic(INVALID_THREAD_ID, SIM_CMD_INSTRUMENT_MODE, opt);
  18. }
  19. UInt64 handleMagicInstruction(thread_id_t thread_id, UInt64 cmd, UInt64 arg0, UInt64 arg1)
  20. {
  21. switch(cmd)
  22. {
  23. case SIM_CMD_ROI_TOGGLE:
  24. case SIM_CMD_ROI_START:
  25. case SIM_CMD_ROI_END:
  26. case SIM_CMD_MHZ_SET:
  27. case SIM_CMD_MARKER:
  28. case SIM_CMD_NAMED_MARKER:
  29. case SIM_CMD_USER:
  30. case SIM_CMD_INSTRUMENT_MODE:
  31. case SIM_CMD_MHZ_GET:
  32. case SIM_CMD_SET_THREAD_NAME:
  33. return handleMagic(thread_id, cmd, arg0, arg1);
  34. case SIM_CMD_PROC_ID:
  35. {
  36. Core *core = Sim()->getCoreManager()->getCurrentCore();
  37. return core->getId();
  38. }
  39. case SIM_CMD_THREAD_ID:
  40. return thread_id;
  41. case SIM_CMD_NUM_PROCS:
  42. return Sim()->getConfig()->getApplicationCores();
  43. case SIM_CMD_NUM_THREADS:
  44. return Sim()->getThreadManager()->getNumThreads();
  45. case SIM_CMD_IN_SIMULATOR:
  46. return 0;
  47. default:
  48. LOG_PRINT_WARNING_ONCE("Encountered unknown magic instruction cmd(%u)", cmd);
  49. return 1;
  50. }
  51. }