mloop.in 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. # Simulator main loop for IQ2000. -*- C -*-
  2. # Copyright (C) 1998-2015 Free Software Foundation, Inc.
  3. # Contributed by Cygnus Solutions.
  4. #
  5. # This file is part of the GNU Simulators.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. # Syntax:
  20. # /bin/sh mainloop.in command
  21. #
  22. # Command is one of:
  23. #
  24. # init
  25. # support
  26. # extract-{simple,scache,pbb}
  27. # {full,fast}-exec-{simple,scache,pbb}
  28. #
  29. # A target need only provide a "full" version of one of simple,scache,pbb.
  30. # If the target wants it can also provide a fast version of same.
  31. # It can't provide more than this, however for illustration's sake the IQ2000
  32. # port provides examples of all.
  33. # ??? After a few more ports are done, revisit.
  34. # Will eventually need to machine generate a lot of this.
  35. case "x$1" in
  36. xsupport)
  37. cat <<EOF
  38. static INLINE const IDESC *
  39. extract (SIM_CPU *current_cpu, PCADDR pc, CGEN_INSN_INT insn, ARGBUF *abuf,
  40. int fast_p)
  41. {
  42. const IDESC *id = @cpu@_decode (current_cpu, pc, insn, insn, abuf);
  43. @cpu@_fill_argbuf (current_cpu, abuf, id, pc, fast_p);
  44. if (! fast_p)
  45. {
  46. int trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
  47. int profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
  48. @cpu@_fill_argbuf_tp (current_cpu, abuf, trace_p, profile_p);
  49. }
  50. return id;
  51. }
  52. static INLINE SEM_PC
  53. execute (SIM_CPU *current_cpu, SCACHE *sc, int fast_p)
  54. {
  55. SEM_PC vpc;
  56. /* Force R0 to zero before every insn. */
  57. @cpu@_h_gr_set (current_cpu, 0, 0);
  58. if (fast_p)
  59. {
  60. #if ! WITH_SEM_SWITCH_FAST
  61. #if WITH_SCACHE
  62. vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, sc);
  63. #else
  64. vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, &sc->argbuf);
  65. #endif
  66. #else
  67. abort ();
  68. #endif /* WITH_SEM_SWITCH_FAST */
  69. }
  70. else
  71. {
  72. #if ! WITH_SEM_SWITCH_FULL
  73. ARGBUF *abuf = &sc->argbuf;
  74. const IDESC *idesc = abuf->idesc;
  75. #if WITH_SCACHE_PBB
  76. int virtual_p = CGEN_ATTR_VALUE (NULL, idesc->attrs, CGEN_INSN_VIRTUAL);
  77. #else
  78. int virtual_p = 0;
  79. #endif
  80. if (! virtual_p)
  81. {
  82. /* FIXME: call x-before */
  83. if (ARGBUF_PROFILE_P (abuf))
  84. PROFILE_COUNT_INSN (current_cpu, abuf->addr, idesc->num);
  85. /* FIXME: Later make cover macros: PROFILE_INSN_{INIT,FINI}. */
  86. if (PROFILE_MODEL_P (current_cpu)
  87. && ARGBUF_PROFILE_P (abuf))
  88. @cpu@_model_insn_before (current_cpu, 1 /*first_p*/);
  89. CGEN_TRACE_INSN_INIT (current_cpu, abuf, 1);
  90. CGEN_TRACE_INSN (current_cpu, idesc->idata,
  91. (const struct argbuf *) abuf, abuf->addr);
  92. }
  93. #if WITH_SCACHE
  94. vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, sc);
  95. #else
  96. vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, abuf);
  97. #endif
  98. if (! virtual_p)
  99. {
  100. /* FIXME: call x-after */
  101. if (PROFILE_MODEL_P (current_cpu)
  102. && ARGBUF_PROFILE_P (abuf))
  103. {
  104. int cycles;
  105. cycles = (*idesc->timing->model_fn) (current_cpu, sc);
  106. @cpu@_model_insn_after (current_cpu, 1 /*last_p*/, cycles);
  107. }
  108. CGEN_TRACE_INSN_FINI (current_cpu, abuf, 1);
  109. }
  110. #else
  111. abort ();
  112. #endif /* WITH_SEM_SWITCH_FULL */
  113. }
  114. return vpc;
  115. }
  116. EOF
  117. ;;
  118. xinit)
  119. ;;
  120. xextract-simple | xextract-scache)
  121. # Inputs: current_cpu, vpc, sc, FAST_P
  122. # Outputs: sc filled in
  123. cat <<EOF
  124. {
  125. CGEN_INSN_INT insn = GETIMEMUSI (current_cpu, CPU2INSN(vpc));
  126. extract (current_cpu, vpc, insn, SEM_ARGBUF (sc), FAST_P);
  127. SEM_SKIP_COMPILE (current_cpu, sc, 1);
  128. }
  129. EOF
  130. ;;
  131. xextract-pbb)
  132. # Inputs: current_cpu, pc, sc, max_insns, FAST_P
  133. # Outputs: sc, pc
  134. # sc must be left pointing past the last created entry.
  135. # pc must be left pointing past the last created entry.
  136. # If the pbb is terminated by a cti insn, SET_CTI_VPC(sc) must be called
  137. # to record the vpc of the cti insn.
  138. # SET_INSN_COUNT(n) must be called to record number of real insns.
  139. cat <<EOF
  140. {
  141. const IDESC *idesc;
  142. int icount = 0;
  143. /* Is the CTI instruction at the end of the PBB a likely branch? */
  144. int likely_cti;
  145. while (max_insns > 0)
  146. {
  147. USI insn = GETIMEMUSI (current_cpu, CPU2INSN(pc));
  148. idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
  149. SEM_SKIP_COMPILE (current_cpu, sc, 1);
  150. ++sc;
  151. --max_insns;
  152. ++icount;
  153. pc += idesc->length;
  154. if (IDESC_CTI_P (idesc))
  155. {
  156. /* Likely branches annul their delay slot if the branch is
  157. not taken by using the (skip ..) rtx. We'll rely on
  158. that. */
  159. likely_cti = (IDESC_SKIP_P (idesc));
  160. SET_CTI_VPC (sc - 1);
  161. if (CGEN_ATTR_VALUE (NULL, idesc->attrs, CGEN_INSN_DELAY_SLOT))
  162. {
  163. USI insn = GETIMEMUSI (current_cpu, CPU2INSN(pc));
  164. idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
  165. if (likely_cti && IDESC_CTI_P (idesc))
  166. {
  167. /* malformed program */
  168. sim_io_eprintf (CPU_STATE (current_cpu),
  169. "malformed program, \`%s' insn in branch likely delay slot\n",
  170. CGEN_INSN_NAME (idesc->idata));
  171. }
  172. else
  173. {
  174. ++sc;
  175. --max_insns;
  176. ++icount;
  177. pc += idesc->length;
  178. }
  179. }
  180. break;
  181. }
  182. }
  183. Finish:
  184. SET_INSN_COUNT (icount);
  185. }
  186. EOF
  187. ;;
  188. xfull-exec-* | xfast-exec-*)
  189. # Inputs: current_cpu, sc, FAST_P
  190. # Outputs: vpc
  191. # vpc contains the address of the next insn to execute
  192. cat <<EOF
  193. {
  194. #if (! FAST_P && WITH_SEM_SWITCH_FULL) || (FAST_P && WITH_SEM_SWITCH_FAST)
  195. #define DEFINE_SWITCH
  196. #include "sem-switch.c"
  197. #else
  198. vpc = execute (current_cpu, vpc, FAST_P);
  199. #endif
  200. }
  201. EOF
  202. ;;
  203. *)
  204. echo "Invalid argument to mainloop.in: $1" >&2
  205. exit 1
  206. ;;
  207. esac