mloop.in 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. # Simulator main loop for IQ2000. -*- C -*-
  2. # Copyright (C) 1998-2022 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. #include <stdlib.h>
  39. static INLINE const IDESC *
  40. extract (SIM_CPU *current_cpu, PCADDR pc, CGEN_INSN_INT insn, ARGBUF *abuf,
  41. int fast_p)
  42. {
  43. const IDESC *id = @cpu@_decode (current_cpu, pc, insn, insn, abuf);
  44. @cpu@_fill_argbuf (current_cpu, abuf, id, pc, fast_p);
  45. if (! fast_p)
  46. {
  47. int trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
  48. int profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
  49. @cpu@_fill_argbuf_tp (current_cpu, abuf, trace_p, profile_p);
  50. }
  51. return id;
  52. }
  53. static INLINE SEM_PC
  54. execute (SIM_CPU *current_cpu, SCACHE *sc, int fast_p)
  55. {
  56. SEM_PC vpc;
  57. /* Force R0 to zero before every insn. */
  58. @cpu@_h_gr_set (current_cpu, 0, 0);
  59. if (fast_p)
  60. {
  61. #if ! WITH_SEM_SWITCH_FAST
  62. #if WITH_SCACHE
  63. vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, sc);
  64. #else
  65. vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, &sc->argbuf);
  66. #endif
  67. #else
  68. abort ();
  69. #endif /* WITH_SEM_SWITCH_FAST */
  70. }
  71. else
  72. {
  73. #if ! WITH_SEM_SWITCH_FULL
  74. ARGBUF *abuf = &sc->argbuf;
  75. const IDESC *idesc = abuf->idesc;
  76. #if WITH_SCACHE_PBB
  77. int virtual_p = CGEN_ATTR_VALUE (NULL, idesc->attrs, CGEN_INSN_VIRTUAL);
  78. #else
  79. int virtual_p = 0;
  80. #endif
  81. if (! virtual_p)
  82. {
  83. /* FIXME: call x-before */
  84. if (ARGBUF_PROFILE_P (abuf))
  85. PROFILE_COUNT_INSN (current_cpu, abuf->addr, idesc->num);
  86. /* FIXME: Later make cover macros: PROFILE_INSN_{INIT,FINI}. */
  87. if (PROFILE_MODEL_P (current_cpu)
  88. && ARGBUF_PROFILE_P (abuf))
  89. @cpu@_model_insn_before (current_cpu, 1 /*first_p*/);
  90. CGEN_TRACE_INSN_INIT (current_cpu, abuf, 1);
  91. CGEN_TRACE_INSN (current_cpu, idesc->idata,
  92. (const struct argbuf *) abuf, abuf->addr);
  93. }
  94. #if WITH_SCACHE
  95. vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, sc);
  96. #else
  97. vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, abuf);
  98. #endif
  99. if (! virtual_p)
  100. {
  101. /* FIXME: call x-after */
  102. if (PROFILE_MODEL_P (current_cpu)
  103. && ARGBUF_PROFILE_P (abuf))
  104. {
  105. int cycles;
  106. cycles = (*idesc->timing->model_fn) (current_cpu, sc);
  107. @cpu@_model_insn_after (current_cpu, 1 /*last_p*/, cycles);
  108. }
  109. CGEN_TRACE_INSN_FINI (current_cpu, abuf, 1);
  110. }
  111. #else
  112. abort ();
  113. #endif /* WITH_SEM_SWITCH_FULL */
  114. }
  115. return vpc;
  116. }
  117. EOF
  118. ;;
  119. xinit)
  120. ;;
  121. xextract-simple | xextract-scache)
  122. # Inputs: current_cpu, vpc, sc, FAST_P
  123. # Outputs: sc filled in
  124. cat <<EOF
  125. {
  126. CGEN_INSN_INT insn = GETIMEMUSI (current_cpu, CPU2INSN(vpc));
  127. extract (current_cpu, vpc, insn, SEM_ARGBUF (sc), FAST_P);
  128. SEM_SKIP_COMPILE (current_cpu, sc, 1);
  129. }
  130. EOF
  131. ;;
  132. xextract-pbb)
  133. # Inputs: current_cpu, pc, sc, max_insns, FAST_P
  134. # Outputs: sc, pc
  135. # sc must be left pointing past the last created entry.
  136. # pc must be left pointing past the last created entry.
  137. # If the pbb is terminated by a cti insn, SET_CTI_VPC(sc) must be called
  138. # to record the vpc of the cti insn.
  139. # SET_INSN_COUNT(n) must be called to record number of real insns.
  140. cat <<EOF
  141. {
  142. const IDESC *idesc;
  143. int icount = 0;
  144. /* Is the CTI instruction at the end of the PBB a likely branch? */
  145. int likely_cti;
  146. while (max_insns > 0)
  147. {
  148. USI insn = GETIMEMUSI (current_cpu, CPU2INSN(pc));
  149. idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
  150. SEM_SKIP_COMPILE (current_cpu, sc, 1);
  151. ++sc;
  152. --max_insns;
  153. ++icount;
  154. pc += idesc->length;
  155. if (IDESC_CTI_P (idesc))
  156. {
  157. /* Likely branches annul their delay slot if the branch is
  158. not taken by using the (skip ..) rtx. We'll rely on
  159. that. */
  160. likely_cti = (IDESC_SKIP_P (idesc));
  161. SET_CTI_VPC (sc - 1);
  162. if (CGEN_ATTR_VALUE (NULL, idesc->attrs, CGEN_INSN_DELAY_SLOT))
  163. {
  164. USI insn = GETIMEMUSI (current_cpu, CPU2INSN(pc));
  165. idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
  166. if (likely_cti && IDESC_CTI_P (idesc))
  167. {
  168. /* malformed program */
  169. sim_io_eprintf (CPU_STATE (current_cpu),
  170. "malformed program, \`%s' insn in branch likely delay slot\n",
  171. CGEN_INSN_NAME (idesc->idata));
  172. }
  173. else
  174. {
  175. ++sc;
  176. --max_insns;
  177. ++icount;
  178. pc += idesc->length;
  179. }
  180. }
  181. break;
  182. }
  183. }
  184. Finish:
  185. SET_INSN_COUNT (icount);
  186. }
  187. EOF
  188. ;;
  189. xfull-exec-* | xfast-exec-*)
  190. # Inputs: current_cpu, sc, FAST_P
  191. # Outputs: vpc
  192. # vpc contains the address of the next insn to execute
  193. cat <<EOF
  194. {
  195. #if (! FAST_P && WITH_SEM_SWITCH_FULL) || (FAST_P && WITH_SEM_SWITCH_FAST)
  196. #define DEFINE_SWITCH
  197. #include "sem-switch.c"
  198. #else
  199. vpc = execute (current_cpu, vpc, FAST_P);
  200. #endif
  201. }
  202. EOF
  203. ;;
  204. *)
  205. echo "Invalid argument to mainloop.in: $1" >&2
  206. exit 1
  207. ;;
  208. esac