1 /* Simulator pseudo baseclass.
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
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)
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.
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. */
21 /* This file is meant to be included by sim-basics.h. */
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
35 #ifdef CURRENT_STATE_REG
38 extern struct sim_state
*current_state
;
41 /* The simulator may provide different (and faster) definition. */
43 #define CURRENT_STATE current_state
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:
52 #define STATE_CPU(sd,n) (&(sd)->cpu)
53 ... simulator specific members ...
57 for a single processor or
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 ...
67 Note that `base' appears last. This makes `base.magic' appear last
68 in the entire struct and helps catch miscompilation errors.
70 sim_cpu is defined to be:
72 typedef struct _sim_cpu {
73 ... simulator specific members ...
79 /* Simulator's argv[0]. */
81 #define STATE_MY_NAME(sd) ((sd)->base.my_name)
83 /* Who opened the simulator. */
84 SIM_OPEN_KIND open_kind
;
85 #define STATE_OPEN_KIND(sd) ((sd)->base.open_kind)
87 /* The host callbacks. */
88 struct host_callback_struct
*callback
;
89 #define STATE_CALLBACK(sd) ((sd)->base.callback)
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)
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)
104 /* ??? This might be more appropriate in sim_cpu. */
105 /* Machine tables for this cpu. See sim-model.h. */
107 #define STATE_MODEL(sd) ((sd)->base.model)
109 /* Supported options. */
110 struct option_list
*options
;
111 #define STATE_OPTIONS(sd) ((sd)->base.options)
113 /* Non-zero if -v specified. */
115 #define STATE_VERBOSE_P(sd) ((sd)->base.verbose_p)
117 /* In standalone simulator, this is the program's arguments passed
118 on the command line. */
120 #define STATE_PROG_ARGV(sd) ((sd)->base.prog_argv)
122 /* The program's bfd. */
123 struct _bfd
*prog_bfd
;
124 #define STATE_PROG_BFD(sd) ((sd)->base.prog_bfd)
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)
134 /* Start address, set when the program is loaded from the bfd. */
136 #define STATE_START_ADDR(sd) ((sd)->base.start_addr)
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)
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)
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. */
158 #define SIM_MAGIC_NUMBER 0x4242
159 #define STATE_MAGIC(sd) ((sd)->base.magic)
162 /* Pseudo baseclass for each cpu. */
165 /* Backlink to main state struct. */
167 #define CPU_STATE(cpu) ((cpu)->base.state)
169 /* Trace data. See sim-trace.h. */
170 TRACE_DATA trace_data
;
171 #define CPU_TRACE_DATA(cpu) (& (cpu)->base.trace_data)
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
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 */
188 /* Debugging output goes to this or stderr if NULL.
189 We can't store `stderr' here as stderr goes through a callback. */
191 #define CPU_DEBUG_FILE(cpu) ((cpu)->base.debug_file)
193 /* Profile data. See sim-profile.h. */
194 PROFILE_DATA profile_data
;
195 #define CPU_PROFILE_DATA(cpu) (& (cpu)->base.profile_data)
198 /* Functions for allocating/freeing a sim_state. */
199 SIM_DESC sim_state_alloc
PARAMS ((void));
200 void sim_state_free
PARAMS ((SIM_DESC
));
202 #endif /* SIM_BASE_H */