-
Notifications
You must be signed in to change notification settings - Fork 0
/
sim-arch.scm
180 lines (149 loc) · 4.58 KB
/
sim-arch.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
; Simulator generator support routines.
; Copyright (C) 2000, 2009, 2014 Red Hat, Inc.
; This file is part of CGEN.
; Utilities of cgen-arch.h.
; Return C macro definitions of the various supported cpus.
(define (/gen-cpuall-defines)
"" ; nothing yet
)
; Return C declarations of misc. support stuff.
; ??? Modes are now defined in sim/common/cgen-types.h but we will need
; target specific modes.
(define (/gen-support-decls)
(string-append
; (gen-enum-decl 'mode_type "mode types"
; "MODE_"
; ; Aliases are not distinct from their real mode so ignore
; ; them here.
; (append (map list (map obj:name
; (mode-list-non-alias-values)))
; '((max))))
; "#define MAX_MODES ((int) MODE_MAX)\n\n"
)
)
; Utilities of cgen-cpuall.h.
; Subroutine of /gen-cpuall-includes.
(define (/gen-cpu-header cpu prefix)
(string-append "#include \"" prefix (cpu-file-transform cpu) ".h\"\n")
)
; Return C code to include all the relevant headers for each cpu family,
; conditioned on ifdef WANT_CPU_@CPU@.
(define (/gen-cpuall-includes)
(string-list
"/* Include files for each cpu family. */\n\n"
(string-list-map
(lambda (cpu)
(let* ((cpu-name (gen-sym cpu))
(CPU-NAME (string-upcase cpu-name)))
(string-list "#ifdef WANT_CPU_" CPU-NAME "\n"
(/gen-cpu-header cpu "eng")
(/gen-cpu-header cpu "cpu")
(/gen-cpu-header cpu "decode")
"#endif\n\n")))
(current-cpu-list))
)
)
; Subroutine of /gen-cpuall-decls to generate cpu-specific structure entries.
; The result is "struct <cpu>_<type-name> <member-name>;".
; INDENT is the amount to indent by.
; CPU is the cpu object.
(define (/gen-cpu-specific-decl indent cpu type-name member-name)
(let* ((cpu-name (gen-sym cpu))
(CPU-NAME (string-upcase cpu-name)))
(string-append
"#ifdef WANT_CPU_" CPU-NAME "\n"
(spaces indent)
"struct " cpu-name "_" type-name " " member-name ";\n"
"#endif\n"))
)
; Return C declarations of cpu-specific structs.
; These are defined here to achieve a simple and moderately type-safe
; inheritance. In the non-cpu-specific files, these structs consist of
; just the baseclass. In cpu-specific files, the baseclass is augmented
; with the cpu-specific data.
(define (/gen-cpuall-decls)
(string-list
(gen-argbuf-type #f)
(gen-scache-type #f)
)
)
; Top level generators for non-cpu-specific files.
; Generate arch.h
; This file defines non cpu family specific data about the architecture
; and also data structures that combine all variants (e.g. cpu struct).
; It is intended to be included before sim-basics.h and sim-base.h.
(define (cgen-arch.h)
(logit 1 "Generating " (current-arch-name) "'s arch.h ...\n")
(string-write
(gen-c-copyright "Simulator header for @arch@."
CURRENT-COPYRIGHT CURRENT-PACKAGE)
"#ifndef @ARCH@_ARCH_H\n"
"#define @ARCH@_ARCH_H\n"
"\n"
"#define TARGET_BIG_ENDIAN 1\n\n" ; FIXME
;(gen-mem-macros)
"#define WI " (mode:c-type WI) "\n"
"#define UWI " (mode:c-type UWI) "\n"
"#define AI " (mode:c-type AI) "\n" "\n"
"#define IAI " (mode:c-type IAI) "\n" "\n"
/gen-cpuall-defines
/gen-support-decls
/gen-arch-model-decls
"#endif /* @ARCH@_ARCH_H */\n"
)
)
; Generate arch.c
; This file defines non cpu family specific data about the architecture.
(define (cgen-arch.c)
(logit 1 "Generating " (current-arch-name) "'s arch.c ...\n")
(string-write
(gen-c-copyright "Simulator support for @arch@."
CURRENT-COPYRIGHT CURRENT-PACKAGE)
"\
#include \"sim-main.h\"
#include \"bfd.h\"
"
/gen-mach-data
)
)
; Generate cpuall.h
; This file pulls together all of the cpu variants .h's.
; It is intended to be included after sim-base.h/cgen-sim.h.
(define (cgen-cpuall.h)
(logit 1 "Generating " (current-arch-name) "'s cpuall.h ...\n")
(string-write
(gen-c-copyright "Simulator CPU header for @arch@."
CURRENT-COPYRIGHT CURRENT-PACKAGE)
"#ifndef @ARCH@_CPUALL_H\n"
"#define @ARCH@_CPUALL_H\n"
"\n"
/gen-cpuall-includes
/gen-mach-decls
/gen-cpuall-decls
"#endif /* @ARCH@_CPUALL_H */\n"
)
)
; Generate ops.c
; No longer used.
(define (cgen-ops.c)
(logit 1 "Generating " (current-arch-name) "'s ops.c ...\n")
(string-write
(gen-c-copyright "Simulator operational support for @arch@."
CURRENT-COPYRIGHT CURRENT-PACKAGE)
"\
#define MEMOPS_DEFINE_INLINE
#include \"config.h\"
#include <signal.h>
#include \"ansidecl.h\"
#include \"bfd.h\"
#include \"tconfig.h\"
#include \"cgen-sim.h\"
#include \"memops.h\"
/* FIXME: wip */
int pow2masks[] = {
0, 0, 1, -1, 3, -1, -1, -1, 7, -1, -1, -1, -1, -1, -1, -1, 15
};
"
gen-mode-defs
)
)