sim-main.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* Main header for the CRIS simulator, based on the m32r header.
  2. Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. Contributed by Axis Communications.
  4. This file is part of the GNU simulators.
  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. /* All FIXME:s present in m32r apply here too; I just refuse to blindly
  16. carry them over, as I don't know if they're really things that need
  17. fixing. */
  18. #ifndef SIM_MAIN_H
  19. #define SIM_MAIN_H
  20. /* This is a global setting. Different cpu families can't mix-n-match -scache
  21. and -pbb. However some cpu families may use -simple while others use
  22. one of -scache/-pbb. */
  23. #define WITH_SCACHE_PBB 1
  24. #include "symcat.h"
  25. #include "sim-basics.h"
  26. #include "cgen-types.h"
  27. #include "cris-desc.h"
  28. #include "cris-opc.h"
  29. #include "arch.h"
  30. #include "sim-base.h"
  31. #include "cgen-sim.h"
  32. #include "cris-sim.h"
  33. struct cris_sim_mmapped_page {
  34. USI addr;
  35. struct cris_sim_mmapped_page *prev;
  36. };
  37. struct cris_thread_info {
  38. /* Identifier for this thread. */
  39. unsigned int threadid;
  40. /* Identifier for parent thread. */
  41. unsigned int parent_threadid;
  42. /* Signal to send to parent at exit. */
  43. int exitsig;
  44. /* Exit status. */
  45. int exitval;
  46. /* Only as storage to return the "set" value to the "get" method.
  47. I'm not sure whether this is useful per-thread. */
  48. USI priority;
  49. struct
  50. {
  51. USI altstack;
  52. USI options;
  53. char action;
  54. char pending;
  55. char blocked;
  56. char blocked_suspendsave;
  57. /* The handler stub unblocks the signal, so we don't need a separate
  58. "temporary save" for that. */
  59. } sigdata[64];
  60. /* Register context, swapped with _sim_cpu.cpu_data. */
  61. void *cpu_context;
  62. /* Similar, temporary copy for the state at a signal call. */
  63. void *cpu_context_atsignal;
  64. /* The number of the reading and writing ends of a pipe if waiting for
  65. the reader, else 0. */
  66. int pipe_read_fd;
  67. int pipe_write_fd;
  68. /* System time at last context switch when this thread ran. */
  69. USI last_execution;
  70. /* Nonzero if we just executed a syscall. */
  71. char at_syscall;
  72. /* Nonzero if any of sigaction[0..64].pending is true. */
  73. char sigpending;
  74. /* Nonzero if in (rt_)sigsuspend call. Cleared at every sighandler
  75. call. */
  76. char sigsuspended;
  77. };
  78. typedef int (*cris_interrupt_delivery_fn) (SIM_CPU *,
  79. enum cris_interrupt_type,
  80. unsigned int);
  81. struct _sim_cpu {
  82. /* sim/common cpu base. */
  83. sim_cpu_base base;
  84. /* Static parts of cgen. */
  85. CGEN_CPU cgen_cpu;
  86. CRIS_MISC_PROFILE cris_misc_profile;
  87. #define CPU_CRIS_MISC_PROFILE(cpu) (& (cpu)->cris_misc_profile)
  88. /* Copy of previous data; only valid when emitting trace-data after
  89. each insn. */
  90. CRIS_MISC_PROFILE cris_prev_misc_profile;
  91. #define CPU_CRIS_PREV_MISC_PROFILE(cpu) (& (cpu)->cris_prev_misc_profile)
  92. #if WITH_HW
  93. cris_interrupt_delivery_fn deliver_interrupt;
  94. #define CPU_CRIS_DELIVER_INTERRUPT(cpu) (cpu->deliver_interrupt)
  95. #endif
  96. /* Simulator environment data. */
  97. USI endmem;
  98. USI endbrk;
  99. USI stack_low;
  100. struct cris_sim_mmapped_page *highest_mmapped_page;
  101. /* Number of syscalls performed or in progress, counting once extra
  102. for every time a blocked thread (internally, when threading) polls
  103. the (pipe) blockage. By default, this is also a time counter: to
  104. minimize performance noise from minor compiler changes,
  105. instructions take no time and syscalls always take 1ms. */
  106. USI syscalls;
  107. /* Number of execution contexts minus one. */
  108. int m1threads;
  109. /* Current thread number; index into thread_data when m1threads != 0. */
  110. int threadno;
  111. /* When a new thread is created, it gets a unique number, which we
  112. count here. */
  113. int max_threadid;
  114. /* Thread-specific info, for simulator thread support, created at
  115. "clone" call. Vector of [threads+1] when m1threads > 0. */
  116. struct cris_thread_info *thread_data;
  117. /* "If CLONE_SIGHAND is set, the calling process and the child pro-
  118. cesses share the same table of signal handlers." ... "However, the
  119. calling process and child processes still have distinct signal
  120. masks and sets of pending signals." See struct cris_thread_info
  121. for sigmasks and sigpendings. */
  122. USI sighandler[64];
  123. /* This is a hack to implement just the parts of fcntl F_GETFL that
  124. are used in open+fdopen calls for the standard scenario: for such
  125. a call we check that the last syscall was open, we check that the
  126. passed fd is the same returned then, and so we return the same
  127. flags passed to open. This way, we avoid complicating the
  128. generic sim callback machinery by introducing fcntl
  129. mechanisms. */
  130. USI last_syscall;
  131. USI last_open_fd;
  132. USI last_open_flags;
  133. /* Function for initializing CPU thread context, which varies in size
  134. with each CPU model. They should be in some constant parts or
  135. initialized in *_init_cpu, but we can't modify that for now. */
  136. void* (*make_thread_cpu_data) (SIM_CPU *, void *);
  137. size_t thread_cpu_data_size;
  138. /* The register differs, so we dispatch to a CPU-specific function. */
  139. void (*set_target_thread_data) (SIM_CPU *, USI);
  140. /* CPU-model specific parts go here.
  141. Note that in files that don't need to access these pieces WANT_CPU_FOO
  142. won't be defined and thus these parts won't appear. This is ok in the
  143. sense that things work. It is a source of bugs though.
  144. One has to of course be careful to not take the size of this
  145. struct and no structure members accessed in non-cpu specific files can
  146. go after here. */
  147. #if defined (WANT_CPU_CRISV0F)
  148. CRISV0F_CPU_DATA cpu_data;
  149. #elif defined (WANT_CPU_CRISV3F)
  150. CRISV3F_CPU_DATA cpu_data;
  151. #elif defined (WANT_CPU_CRISV8F)
  152. CRISV8F_CPU_DATA cpu_data;
  153. #elif defined (WANT_CPU_CRISV10F)
  154. CRISV10F_CPU_DATA cpu_data;
  155. #elif defined (WANT_CPU_CRISV32F)
  156. CRISV32F_CPU_DATA cpu_data;
  157. #else
  158. /* Let's assume all cpu_data have the same alignment requirements, so
  159. they all are laid out at the same address. Since we can't get the
  160. exact definition, we also assume that it has no higher alignment
  161. requirements than a vector of, say, 16 pointers. (A single member
  162. is often special-cased, and possibly two as well so we don't want
  163. that). */
  164. union { void *dummy[16]; } cpu_data_placeholder;
  165. #endif
  166. };
  167. /* Misc. */
  168. /* Catch address exceptions. */
  169. extern SIM_CORE_SIGNAL_FN cris_core_signal;
  170. #define SIM_CORE_SIGNAL(SD,CPU,CIA,MAP,NR_BYTES,ADDR,TRANSFER,ERROR) \
  171. cris_core_signal ((SD), (CPU), (CIA), (MAP), (NR_BYTES), (ADDR), \
  172. (TRANSFER), (ERROR))
  173. /* Default memory size. */
  174. #define CRIS_DEFAULT_MEM_SIZE 0x800000 /* 8M */
  175. #endif /* SIM_MAIN_H */