sim: namespace sim_machs
[deliverable/binutils-gdb.git] / sim / common / sim-model.h
CommitLineData
c906108c 1/* Architecture, machine, and model support.
3666a048 2 Copyright (C) 1997-2021 Free Software Foundation, Inc.
c906108c
SS
3 Contributed by Cygnus Support.
4
5This file is part of GDB, the GNU debugger.
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
JB
9the Free Software Foundation; either version 3 of the License, or
10(at your option) any later version.
c906108c
SS
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/>. */
c906108c
SS
19
20/* Nomenclature:
21 architecture = one of sparc, mips, sh, etc.
22 in the sparc architecture, mach = one of v6, v7, v8, sparclite, etc.
23 in the v8 mach, model = one of supersparc, etc.
0d585950
MF
24
25 To use the model framework, your arch needs to do a few things:
26 (1) Call SIM_AC_OPTION_DEFAULT_MODEL() in configure.ac.
27 (2) Define enum mach_attr in sim-main.h.
28 (3) Define sim_machs array (and all the callbacks it uses).
c906108c
SS
29*/
30
31/* This file is intended to be included by sim-basics.h. */
32
33#ifndef SIM_MODEL_H
34#define SIM_MODEL_H
35
36/* Function unit and instruction timing support.
37 ??? This is obviously insufficiently general.
38 It's useful but it needs elaborating upon. */
39
40typedef struct {
41 unsigned char name; /* actually a UNIT_TYPE enum */
42 unsigned char issue;
43 unsigned char done;
44} UNIT;
45
46#ifndef MAX_UNITS
47#define MAX_UNITS 1
48#endif
49
0d585950 50#ifndef WITH_DEFAULT_MODEL
0d585950
MF
51# define WITH_DEFAULT_MODEL NULL
52# define WITH_MODEL_P 0
53#else
54# define WITH_MODEL_P 1
55#endif
56
c906108c
SS
57typedef int (MODEL_FN) (sim_cpu *, void *);
58
59typedef struct {
60 /* This is an integer that identifies this insn.
61 How this works is up to the target. */
62 int num;
63
64 /* Function to handle insn-specific profiling. */
65 MODEL_FN *model_fn;
66
67 /* Array of function units used by this insn. */
68 UNIT units[MAX_UNITS];
69} INSN_TIMING;
70
71/* Struct to describe various implementation properties of a cpu.
72 When multiple cpu variants are supported, the sizes of some structs
73 can vary. */
74
75typedef struct {
76 /* The size of the SIM_CPU struct. */
77 int sim_cpu_size;
78#define IMP_PROPS_SIM_CPU_SIZE(cpu_props) ((cpu_props)->sim_cpu_size)
79 /* An SCACHE element can vary in size, depending on the selected cpu.
80 This is zero if the SCACHE isn't in use for this variant. */
81 int scache_elm_size;
82#define IMP_PROPS_SCACHE_ELM_SIZE(cpu_props) ((cpu_props)->scache_elm_size)
8a0ebee6 83} SIM_MACH_IMP_PROPERTIES;
c906108c
SS
84
85/* A machine variant. */
86
87typedef struct {
88 const char *name;
89#define MACH_NAME(m) ((m)->name)
90 /* This is the argument to bfd_scan_arch. */
91 const char *bfd_name;
92#define MACH_BFD_NAME(m) ((m)->bfd_name)
1c636da0 93 int num;
7a292a7a
SS
94#define MACH_NUM(m) ((m)->num)
95
c906108c
SS
96 int word_bitsize;
97#define MACH_WORD_BITSIZE(m) ((m)->word_bitsize)
98 int addr_bitsize;
99#define MACH_ADDR_BITSIZE(m) ((m)->addr_bitsize)
100
101 /* Pointer to null-entry terminated table of models of this mach.
102 The default is the first one. */
103 const struct model *models;
104#define MACH_MODELS(m) ((m)->models)
105
106 /* Pointer to the implementation properties of this mach. */
8a0ebee6 107 const SIM_MACH_IMP_PROPERTIES *imp_props;
c906108c
SS
108#define MACH_IMP_PROPS(m) ((m)->imp_props)
109
110 /* Called by sim_model_set when the model of a cpu is set. */
111 void (* init_cpu) (sim_cpu *);
112#define MACH_INIT_CPU(m) ((m)->init_cpu)
113
114 /* Initialize the simulator engine for this cpu.
115 Used by cgen simulators to initialize the insn descriptor table. */
116 void (* prepare_run) (sim_cpu *);
117#define MACH_PREPARE_RUN(m) ((m)->prepare_run)
8a0ebee6 118} SIM_MACH;
c906108c
SS
119
120/* A model (implementation) of a machine. */
121
122typedef struct model {
123 const char *name;
124#define MODEL_NAME(m) ((m)->name)
8a0ebee6 125 const SIM_MACH *mach;
c906108c
SS
126#define MODEL_MACH(m) ((m)->mach)
127 /* An enum that distinguished the model. */
128 int num;
129#define MODEL_NUM(m) ((m)->num)
130 /* Pointer to timing table for this model. */
131 const INSN_TIMING *timing;
132#define MODEL_TIMING(m) ((m)->timing)
133 void (* init) (sim_cpu *);
134#define MODEL_INIT(m) ((m)->init)
8a0ebee6 135} SIM_MODEL;
c906108c 136
c906108c
SS
137/* Model module handlers. */
138extern MODULE_INSTALL_FN sim_model_install;
139
140/* Support routines. */
8a0ebee6 141extern void sim_model_set (SIM_DESC sd_, sim_cpu *cpu_, const SIM_MODEL *model_);
1c636da0
MF
142extern const SIM_MODEL *sim_model_lookup (SIM_DESC, const char *name_);
143extern const SIM_MACH *sim_mach_lookup (SIM_DESC, const char *name_);
144extern const SIM_MACH *sim_mach_lookup_bfd_name (SIM_DESC, const char *bfd_name_);
c906108c
SS
145
146#endif /* SIM_MODEL_H */
This page took 0.948861 seconds and 4 git commands to generate.