sim-engine.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Generic simulator halt/resume.
  2. Copyright (C) 1997-2015 Free Software Foundation, Inc.
  3. Contributed by Cygnus Support.
  4. This file is part of GDB, the GNU debugger.
  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 3 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, see <http://www.gnu.org/licenses/>. */
  15. #ifndef SIM_ENGINE_H
  16. #define SIM_ENGINE_H
  17. typedef struct _sim_engine sim_engine;
  18. struct _sim_engine
  19. {
  20. void *jmpbuf;
  21. sim_cpu *last_cpu;
  22. sim_cpu *next_cpu;
  23. int nr_cpus;
  24. enum sim_stop reason;
  25. sim_event *stepper;
  26. int sigrc;
  27. };
  28. /* jmpval: 0 (initial use) start simulator
  29. 1 halt simulator
  30. 2 restart simulator
  31. This is required by the ISO C standard (the only time 0 is returned
  32. is at the initial call to setjmp). */
  33. enum {
  34. sim_engine_start_jmpval,
  35. sim_engine_halt_jmpval,
  36. sim_engine_restart_jmpval,
  37. };
  38. /* Get/set the run state of CPU to REASON/SIGRC.
  39. REASON/SIGRC are the values returned by sim_stop_reason. */
  40. void sim_engine_get_run_state (SIM_DESC sd, enum sim_stop *reason, int *sigrc);
  41. void sim_engine_set_run_state (SIM_DESC sd, enum sim_stop reason, int sigrc);
  42. /* Halt the simulator *now* */
  43. extern void sim_engine_halt
  44. (SIM_DESC sd,
  45. sim_cpu *last_cpu, /* NULL -> in event-mgr */
  46. sim_cpu *next_cpu, /* NULL -> succ (last_cpu) or event-mgr */
  47. sim_cia cia,
  48. enum sim_stop reason,
  49. int sigrc) __attribute__ ((noreturn));
  50. /* Halt hook - allow target specific operation when halting a
  51. simulator */
  52. #if !defined (SIM_ENGINE_HALT_HOOK)
  53. #define SIM_ENGINE_HALT_HOOK(SD, LAST_CPU, CIA) \
  54. if ((LAST_CPU) != NULL) CPU_PC_SET (LAST_CPU, CIA)
  55. #endif
  56. /* NB: If a port uses the SIM_CPU_EXCEPTION_* hooks, the default
  57. SIM_ENGINE_HALT_HOOK and SIM_ENGINE_RESUME_HOOK must not be used.
  58. They conflict in that the PC set by the HALT_HOOK may overwrite the
  59. proper one, as intended to be saved by the EXCEPTION_TRIGGER
  60. hook. */
  61. /* restart the simulator *now* */
  62. extern void sim_engine_restart
  63. (SIM_DESC sd,
  64. sim_cpu *last_cpu, /* NULL -> in event-mgr */
  65. sim_cpu *next_cpu, /* NULL -> succ (last_cpu) or event-mgr */
  66. sim_cia cia);
  67. /* Restart hook - allow target specific operation when restarting a
  68. simulator */
  69. #if !defined (SIM_ENGINE_RESTART_HOOK)
  70. #define SIM_ENGINE_RESTART_HOOK(SD, LAST_CPU, CIA) SIM_ENGINE_HALT_HOOK(SD, LAST_CPU, CIA)
  71. #endif
  72. /* Abort the simulator *now*.
  73. This function is NULL safe. It can be called when either of SD or
  74. CIA are NULL.
  75. This function is setjmp/longjmp safe. It can be called when of
  76. the sim_engine setjmp/longjmp buffer has not been established.
  77. Simulators that are using components such as sim-core but are not
  78. yet using this sim-engine module should link in file sim-abort.o
  79. which implements a non setjmp/longjmp version of
  80. sim_engine_abort. */
  81. extern void sim_engine_abort
  82. (SIM_DESC sd,
  83. sim_cpu *cpu,
  84. sim_cia cia,
  85. const char *fmt,
  86. ...) __attribute__ ((format (printf, 4, 5))) __attribute__ ((noreturn));
  87. extern void sim_engine_vabort
  88. (SIM_DESC sd,
  89. sim_cpu *cpu,
  90. sim_cia cia,
  91. const char *fmt,
  92. va_list ap) __attribute__ ((noreturn));
  93. /* No abort hook - when possible this function exits using the
  94. engine_halt function (and SIM_ENGINE_HALT_HOOK). */
  95. /* Called by the generic sim_resume to run the simulation within the
  96. above safty net.
  97. An example implementation of sim_engine_run can be found in the
  98. file sim-run.c */
  99. extern void sim_engine_run
  100. (SIM_DESC sd,
  101. int next_cpu_nr,
  102. int nr_cpus,
  103. int siggnal); /* most simulators ignore siggnal */
  104. /* Determine the state of next/last cpu when the simulator was last
  105. halted - a value >= MAX_NR_PROCESSORS indicates that the
  106. event-queue was next/last. */
  107. extern int sim_engine_next_cpu_nr (SIM_DESC sd);
  108. extern int sim_engine_last_cpu_nr (SIM_DESC sd);
  109. extern int sim_engine_nr_cpus (SIM_DESC sd);
  110. /* Establish the simulator engine */
  111. MODULE_INSTALL_FN sim_engine_install;
  112. #endif