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