* Makefile.in (sim-options_h): Define.
[deliverable/binutils-gdb.git] / sim / common / sim-base.h
1 /* Simulator pseudo baseclass.
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4
5 This file is part of GDB, the GNU debugger.
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 2, or (at your option)
10 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 along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 /* This file is meant to be included by sim-basics.h. */
22
23 #ifndef SIM_BASE_H
24 #define SIM_BASE_H
25
26 /* Global pointer to current state while sim_resume is running.
27 On a machine with lots of registers, it might be possible to reserve
28 one of them for current_state. However on a machine with few registers
29 current_state can't permanently live in one and indirecting through it
30 will be slower [in which case one can have sim_resume set globals from
31 current_state for faster access].
32 If CURRENT_STATE_REG is defined, it means current_state is living in
33 a global register. */
34
35 #ifdef CURRENT_STATE_REG
36 /* FIXME: wip */
37 #else
38 extern struct sim_state *current_state;
39 #endif
40
41 /* The simulator may provide different (and faster) definition. */
42 #ifndef CURRENT_STATE
43 #define CURRENT_STATE current_state
44 #endif
45
46 /* Simulator state pseudo baseclass.
47 Each simulator is required to have a sim-main.h file that includes
48 sim-basics.h and defines struct sim_state to be:
49
50 struct sim_state {
51 sim_cpu cpu;
52 #define STATE_CPU(sd,n) (&(sd)->cpu)
53 ... simulator specific members ...
54 sim_state_base base;
55 };
56
57 for a single processor or
58
59 struct sim_state {
60 sim_cpu cpu[MAX_NR_PROCESSORS]; -- could be also be array of pointers
61 #define STATE_CPU(sd,n) (&(sd)->cpu[n])
62 ... simulator specific members ...
63 sim_state_base base;
64 };
65
66 for multiprocessors.
67 Note that `base' appears last. This makes `base.magic' appear last
68 in the entire struct and helps catch miscompilation errors.
69
70 sim_cpu is defined to be:
71
72 typedef struct _sim_cpu {
73 ... simulator specific members ...
74 sim_cpu_base base;
75 } sim_cpu;
76 */
77
78 typedef struct {
79 /* Simulator's argv[0]. */
80 const char *my_name;
81 #define STATE_MY_NAME(sd) ((sd)->base.my_name)
82
83 /* Who opened the simulator. */
84 SIM_OPEN_KIND open_kind;
85 #define STATE_OPEN_KIND(sd) ((sd)->base.open_kind)
86
87 /* The host callbacks. */
88 struct host_callback_struct *callback;
89 #define STATE_CALLBACK(sd) ((sd)->base.callback)
90
91 #if 0 /* FIXME: Not ready yet. */
92 /* Stuff defined in sim-config.h. */
93 struct sim_config config;
94 #define STATE_CONFIG(sd) ((sd)->base.config)
95 #endif
96
97 /* List of installed module `init' handlers. */
98 MODULE_INIT_LIST *init_list;
99 #define STATE_INIT_LIST(sd) ((sd)->base.init_list)
100 /* List of installed module `uninstall' handlers. */
101 MODULE_UNINSTALL_LIST *uninstall_list;
102 #define STATE_UNINSTALL_LIST(sd) ((sd)->base.uninstall_list)
103
104 /* ??? This might be more appropriate in sim_cpu. */
105 /* Machine tables for this cpu. See sim-model.h. */
106 const MODEL *model;
107 #define STATE_MODEL(sd) ((sd)->base.model)
108
109 /* Supported options. */
110 struct option_list *options;
111 #define STATE_OPTIONS(sd) ((sd)->base.options)
112
113 /* Non-zero if -v specified. */
114 int verbose_p;
115 #define STATE_VERBOSE_P(sd) ((sd)->base.verbose_p)
116
117 /* In standalone simulator, this is the program's arguments passed
118 on the command line. */
119 char **prog_argv;
120 #define STATE_PROG_ARGV(sd) ((sd)->base.prog_argv)
121
122 /* The program's bfd. */
123 struct _bfd *prog_bfd;
124 #define STATE_PROG_BFD(sd) ((sd)->base.prog_bfd)
125
126 /* The program's text section. */
127 struct sec *text_section;
128 /* Starting and ending text section addresses from the bfd. */
129 SIM_ADDR text_start, text_end;
130 #define STATE_TEXT_SECTION(sd) ((sd)->base.text_section)
131 #define STATE_TEXT_START(sd) ((sd)->base.text_start)
132 #define STATE_TEXT_END(sd) ((sd)->base.text_end)
133
134 /* Start address, set when the program is loaded from the bfd. */
135 SIM_ADDR start_addr;
136 #define STATE_START_ADDR(sd) ((sd)->base.start_addr)
137
138 #if WITH_SCACHE
139 /* Size of the simulator's cache, if any.
140 This is not the target's cache. It is the cache the simulator uses
141 to process instructions. */
142 unsigned int scache_size;
143 #define STATE_SCACHE_SIZE(sd) ((sd)->base.scache_size)
144 #endif
145
146 /* FIXME: Move to top level sim_state struct (as some struct)? */
147 #ifdef SIM_HAVE_FLATMEM
148 unsigned int mem_size;
149 #define STATE_MEM_SIZE(sd) ((sd)->base.mem_size)
150 unsigned char *memory;
151 #define STATE_MEMORY(sd) ((sd)->base.memory)
152 #endif
153
154 /* Marker for those wanting to do sanity checks.
155 This should remain the last member of this struct to help catch
156 miscompilation errors. */
157 int magic;
158 #define SIM_MAGIC_NUMBER 0x4242
159 #define STATE_MAGIC(sd) ((sd)->base.magic)
160 } sim_state_base;
161
162 /* Pseudo baseclass for each cpu. */
163
164 typedef struct {
165 /* Backlink to main state struct. */
166 SIM_DESC state;
167 #define CPU_STATE(cpu) ((cpu)->base.state)
168
169 /* Trace data. See sim-trace.h. */
170 TRACE_DATA trace_data;
171 #define CPU_TRACE_DATA(cpu) (& (cpu)->base.trace_data)
172
173 /* Maximum number of debuggable entities.
174 This debugging is not intended for normal use.
175 It is only enabled when the simulator is configured with --with-debug
176 which shouldn't normally be specified. */
177 #ifndef MAX_DEBUG_VALUES
178 #define MAX_DEBUG_VALUES 4
179 #endif
180
181 /* Boolean array of specified debugging flags. */
182 char debug_flags[MAX_DEBUG_VALUES];
183 #define CPU_DEBUG_FLAGS(cpu) ((cpu)->base.debug_flags)
184 /* Standard values. */
185 #define DEBUG_INSN_IDX 0
186 #define DEBUG_NEXT_IDX 2 /* simulator specific debug bits begin here */
187
188 /* Debugging output goes to this or stderr if NULL.
189 We can't store `stderr' here as stderr goes through a callback. */
190 FILE *debug_file;
191 #define CPU_DEBUG_FILE(cpu) ((cpu)->base.debug_file)
192
193 /* Profile data. See sim-profile.h. */
194 PROFILE_DATA profile_data;
195 #define CPU_PROFILE_DATA(cpu) (& (cpu)->base.profile_data)
196 } sim_cpu_base;
197
198 /* Functions for allocating/freeing a sim_state. */
199 SIM_DESC sim_state_alloc PARAMS ((void));
200 void sim_state_free PARAMS ((SIM_DESC));
201
202 #endif /* SIM_BASE_H */
This page took 0.033819 seconds and 5 git commands to generate.