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