mloop.in 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. # Simulator main loop for lm32. -*- C -*-
  2. # Contributed by Jon Beniston <jon@beniston.com>
  3. #
  4. # This file is part of the GNU Simulators.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, see <http://www.gnu.org/licenses/>.
  18. # Syntax:
  19. # /bin/sh mainloop.in command
  20. #
  21. # Command is one of:
  22. #
  23. # init
  24. # support
  25. # extract-{simple,scache,pbb}
  26. # {full,fast}-exec-{simple,scache,pbb}
  27. #
  28. case "x$1" in
  29. xsupport)
  30. cat <<EOF
  31. #include <stdlib.h>
  32. static INLINE const IDESC *
  33. extract (SIM_CPU *current_cpu, PCADDR pc, CGEN_INSN_INT insn,
  34. ARGBUF *abuf, int fast_p)
  35. {
  36. const IDESC *id = @cpu@_decode (current_cpu, pc, insn, insn, abuf);
  37. @cpu@_fill_argbuf (current_cpu, abuf, id, pc, fast_p);
  38. if (! fast_p)
  39. {
  40. int trace_p = PC_IN_TRACE_RANGE_P (current_cpu, pc);
  41. int profile_p = PC_IN_PROFILE_RANGE_P (current_cpu, pc);
  42. @cpu@_fill_argbuf_tp (current_cpu, abuf, trace_p, profile_p);
  43. }
  44. return id;
  45. }
  46. static INLINE SEM_PC
  47. execute (SIM_CPU *current_cpu, SCACHE *sc, int fast_p)
  48. {
  49. SEM_PC vpc;
  50. if (fast_p)
  51. {
  52. #if ! WITH_SEM_SWITCH_FAST
  53. #if WITH_SCACHE
  54. vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, sc);
  55. #else
  56. vpc = (*sc->argbuf.semantic.sem_fast) (current_cpu, &sc->argbuf);
  57. #endif
  58. #else
  59. abort ();
  60. #endif /* WITH_SEM_SWITCH_FAST */
  61. }
  62. else
  63. {
  64. #if ! WITH_SEM_SWITCH_FULL
  65. ARGBUF *abuf = &sc->argbuf;
  66. const IDESC *idesc = abuf->idesc;
  67. const CGEN_INSN *idata = idesc->idata;
  68. #if WITH_SCACHE_PBB
  69. int virtual_p = CGEN_INSN_ATTR_VALUE (idata, CGEN_INSN_VIRTUAL);
  70. #else
  71. int virtual_p = 0;
  72. #endif
  73. if (! virtual_p)
  74. {
  75. /* FIXME: call x-before */
  76. if (ARGBUF_PROFILE_P (abuf))
  77. PROFILE_COUNT_INSN (current_cpu, abuf->addr, idesc->num);
  78. /* FIXME: Later make cover macros: PROFILE_INSN_{INIT,FINI}. */
  79. if (PROFILE_MODEL_P (current_cpu)
  80. && ARGBUF_PROFILE_P (abuf))
  81. @cpu@_model_insn_before (current_cpu, 1 /*first_p*/);
  82. CGEN_TRACE_INSN_INIT (current_cpu, abuf, 1);
  83. CGEN_TRACE_INSN (current_cpu, idata,
  84. (const struct argbuf *) abuf, abuf->addr);
  85. }
  86. #if WITH_SCACHE
  87. vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, sc);
  88. #else
  89. vpc = (*sc->argbuf.semantic.sem_full) (current_cpu, abuf);
  90. #endif
  91. if (! virtual_p)
  92. {
  93. /* FIXME: call x-after */
  94. if (PROFILE_MODEL_P (current_cpu)
  95. && ARGBUF_PROFILE_P (abuf))
  96. {
  97. int cycles;
  98. cycles = (*idesc->timing->model_fn) (current_cpu, sc);
  99. @cpu@_model_insn_after (current_cpu, 1 /*last_p*/, cycles);
  100. }
  101. CGEN_TRACE_INSN_FINI (current_cpu, abuf, 1);
  102. }
  103. #else
  104. abort ();
  105. #endif /* WITH_SEM_SWITCH_FULL */
  106. }
  107. return vpc;
  108. }
  109. EOF
  110. ;;
  111. xinit)
  112. # Nothing needed.
  113. ;;
  114. xextract-simple | xextract-scache)
  115. cat <<EOF
  116. {
  117. CGEN_INSN_INT insn = GETIMEMUSI (current_cpu, vpc);
  118. extract (current_cpu, vpc, insn, SEM_ARGBUF (sc), FAST_P);
  119. }
  120. EOF
  121. ;;
  122. xextract-pbb)
  123. # Inputs: current_cpu, pc, sc, max_insns, FAST_P
  124. # Outputs: sc, pc
  125. # sc must be left pointing past the last created entry.
  126. # pc must be left pointing past the last created entry.
  127. # If the pbb is terminated by a cti insn, SET_CTI_VPC(sc) must be called
  128. # to record the vpc of the cti insn.
  129. # SET_INSN_COUNT(n) must be called to record number of real insns.
  130. cat <<EOF
  131. {
  132. const IDESC *idesc;
  133. int icount = 0;
  134. while (max_insns > 0)
  135. {
  136. USI insn = GETIMEMUSI (current_cpu, pc);
  137. idesc = extract (current_cpu, pc, insn, &sc->argbuf, FAST_P);
  138. ++sc;
  139. --max_insns;
  140. ++icount;
  141. pc += idesc->length;
  142. if (IDESC_CTI_P (idesc))
  143. {
  144. SET_CTI_VPC (sc - 1);
  145. break;
  146. }
  147. }
  148. Finish:
  149. SET_INSN_COUNT (icount);
  150. }
  151. EOF
  152. ;;
  153. xfull-exec-* | xfast-exec-*)
  154. # Inputs: current_cpu, vpc, FAST_P
  155. # Outputs: vpc
  156. cat <<EOF
  157. /* Update cycle counter */
  158. SET_H_CSR (LM32_CSR_CC, GET_H_CSR (LM32_CSR_CC) + 1);
  159. #if (! FAST_P && WITH_SEM_SWITCH_FULL) || (FAST_P && WITH_SEM_SWITCH_FAST)
  160. #define DEFINE_SWITCH
  161. #include "sem-switch.c"
  162. #else
  163. vpc = execute (current_cpu, vpc, FAST_P);
  164. #endif
  165. EOF
  166. ;;
  167. *)
  168. echo "Invalid argument to mainloop.in: $1" >&2
  169. exit 1
  170. ;;
  171. esac