generate_tail.c Source File
Back to the index.
src
cpus
generate_tail.c
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2005-2009 Anders Gavare. All rights reserved.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
6
*
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
* 3. The name of the author may not be used to endorse or promote products
13
* derived from this software without specific prior written permission.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
* SUCH DAMAGE.
26
*/
27
28
#include <stdio.h>
29
#include <stdlib.h>
30
31
32
char
*
uppercase
(
char
*l)
33
{
34
static
char
staticbuf[1000];
35
size_t
i = 0;
36
37
while
(*l && i <
sizeof
(staticbuf)) {
38
char
u = *l++;
39
if
(u >=
'a'
&& u <=
'z'
)
40
u -= 32;
41
staticbuf[i++] = u;
42
}
43
if
(i ==
sizeof
(staticbuf))
44
i--;
45
staticbuf[i] = 0;
46
return
staticbuf;
47
}
48
49
50
int
main
(
int
argc,
char
*argv[])
51
{
52
char
*a, *b;
53
54
if
(argc != 3) {
55
fprintf(stderr,
"usage: %s arch Arch\n"
, argv[0]);
56
fprintf(stderr,
"Example: %s alpha Alpha\n"
, argv[0]);
57
fprintf(stderr,
" or: %s arm ARM\n"
, argv[0]);
58
exit(1);
59
}
60
61
a = argv[1];
62
b = argv[2];
63
64
printf(
"\n/*\n * AUTOMATICALLY GENERATED! Do not edit.\n */\n\n"
);
65
66
printf(
"extern size_t dyntrans_cache_size;\n"
);
67
68
printf(
"#ifdef DYNTRANS_32\n"
);
69
printf(
"#define MODE32\n"
);
70
printf(
"#endif\n"
);
71
72
printf(
"#define DYNTRANS_FUNCTION_TRACE_DEF "
73
"%s_cpu_functioncall_trace\n"
, a);
74
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
75
printf(
"#undef DYNTRANS_FUNCTION_TRACE_DEF\n\n"
);
76
77
printf(
"#define DYNTRANS_INIT_TABLES "
78
"%s_cpu_init_tables\n"
, a);
79
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
80
printf(
"#undef DYNTRANS_INIT_TABLES\n\n"
);
81
82
printf(
"#define DYNTRANS_TC_ALLOCATE_DEFAULT_PAGE_DEF "
83
"%s_tc_allocate_default_page\n"
, a);
84
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
85
printf(
"#undef DYNTRANS_TC_ALLOCATE_DEFAULT_PAGE_DEF\n\n"
);
86
87
printf(
"#define DYNTRANS_INVAL_ENTRY\n"
);
88
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
89
printf(
"#undef DYNTRANS_INVAL_ENTRY\n\n"
);
90
91
printf(
"#define DYNTRANS_INVALIDATE_TC "
92
"%s_invalidate_translation_caches\n"
, a);
93
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
94
printf(
"#undef DYNTRANS_INVALIDATE_TC\n\n"
);
95
96
printf(
"#define DYNTRANS_INVALIDATE_TC_CODE "
97
"%s_invalidate_code_translation\n"
, a);
98
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
99
printf(
"#undef DYNTRANS_INVALIDATE_TC_CODE\n\n"
);
100
101
printf(
"#define DYNTRANS_UPDATE_TRANSLATION_TABLE "
102
"%s_update_translation_table\n"
, a);
103
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
104
printf(
"#undef DYNTRANS_UPDATE_TRANSLATION_TABLE\n\n"
);
105
106
printf(
"#define MEMORY_RW %s_memory_rw\n"
, a);
107
printf(
"#define MEM_%s\n"
,
uppercase
(a));
108
printf(
"#include \"memory_rw.cc\"\n"
);
109
printf(
"#undef MEM_%s\n"
,
uppercase
(a));
110
printf(
"#undef MEMORY_RW\n\n"
);
111
112
printf(
"#define DYNTRANS_PC_TO_POINTERS_FUNC %s_pc_to_pointers\n"
, a);
113
printf(
"#define DYNTRANS_PC_TO_POINTERS_GENERIC "
114
"%s_pc_to_pointers_generic\n"
, a);
115
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
116
printf(
"#undef DYNTRANS_PC_TO_POINTERS_FUNC\n\n"
);
117
printf(
"#undef DYNTRANS_PC_TO_POINTERS_GENERIC\n\n"
);
118
119
120
printf(
"#define COMBINE_INSTRUCTIONS %s_combine_instructions\n"
, a);
121
printf(
"#ifndef DYNTRANS_32\n"
);
122
printf(
"#define reg(x) (*((uint64_t *)(x)))\n"
);
123
printf(
"#define MODE_uint_t uint64_t\n"
);
124
printf(
"#define MODE_int_t int64_t\n"
);
125
printf(
"#else\n"
);
126
printf(
"#define reg(x) (*((uint32_t *)(x)))\n"
);
127
printf(
"#define MODE_uint_t uint32_t\n"
);
128
printf(
"#define MODE_int_t int32_t\n"
);
129
printf(
"#endif\n"
);
130
printf(
"#define COMBINE(n) %s_combine_ ## n\n"
, a);
131
printf(
"#include \"quick_pc_to_pointers.h\"\n"
);
132
printf(
"#include \"cpu_%s_instr.cc\"\n\n"
, a);
133
134
printf(
"#define DYNTRANS_RUN_INSTR_DEF %s_run_instr\n"
, a);
135
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
136
printf(
"#undef DYNTRANS_RUN_INSTR_DEF\n\n"
);
137
138
139
printf(
"#ifdef DYNTRANS_DUALMODE_32\n"
);
140
printf(
"#undef COMBINE_INSTRUCTIONS\n"
);
141
printf(
"#define COMBINE_INSTRUCTIONS %s32_combine_instructions\n"
, a);
142
printf(
"#undef X\n#undef instr\n#undef reg\n"
143
"#define X(n) void %s32_instr_ ## n(struct cpu *cpu, \\\n"
144
"\tstruct %s_instr_call *ic)\n"
, a, a);
145
printf(
"#define instr(n) %s32_instr_ ## n\n"
, a);
146
printf(
"#ifdef HOST_LITTLE_ENDIAN\n"
);
147
printf(
"#define reg(x) ( *((uint32_t *)(x)) )\n"
);
148
printf(
"#else\n"
);
149
printf(
"#define reg(x) ( *((uint32_t *)(x)+1) )\n"
);
150
printf(
"#endif\n"
);
151
printf(
"#define MODE32\n"
);
152
printf(
"#undef MODE_uint_t\n#undef MODE_int_t\n"
);
153
printf(
"#define MODE_uint_t uint32_t\n"
);
154
printf(
"#define MODE_int_t int32_t\n"
);
155
156
printf(
"#define DYNTRANS_INVAL_ENTRY\n"
);
157
printf(
"#undef DYNTRANS_INVALIDATE_TLB_ENTRY\n"
158
"#define DYNTRANS_INVALIDATE_TLB_ENTRY "
159
"%s32_invalidate_tlb_entry\n"
, a);
160
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
161
printf(
"#undef DYNTRANS_INVAL_ENTRY\n\n"
);
162
printf(
"#define DYNTRANS_INVALIDATE_TC "
163
"%s32_invalidate_translation_caches\n"
, a);
164
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
165
printf(
"#undef DYNTRANS_INVALIDATE_TC\n\n"
);
166
printf(
"#define DYNTRANS_INVALIDATE_TC_CODE "
167
"%s32_invalidate_code_translation\n"
, a);
168
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
169
printf(
"#undef DYNTRANS_INVALIDATE_TC_CODE\n\n"
);
170
printf(
"#define DYNTRANS_UPDATE_TRANSLATION_TABLE "
171
"%s32_update_translation_table\n"
, a);
172
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
173
printf(
"#undef DYNTRANS_UPDATE_TRANSLATION_TABLE\n\n"
);
174
printf(
"#define DYNTRANS_PC_TO_POINTERS_FUNC %s32_pc_to_pointers\n"
, a);
175
printf(
"#define DYNTRANS_PC_TO_POINTERS_GENERIC "
176
"%s32_pc_to_pointers_generic\n"
, a);
177
printf(
"#undef DYNTRANS_PC_TO_POINTERS\n"
178
"#define DYNTRANS_PC_TO_POINTERS %s32_pc_to_pointers\n"
, a);
179
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
180
printf(
"#undef DYNTRANS_PC_TO_POINTERS_FUNC\n\n"
);
181
printf(
"#undef DYNTRANS_PC_TO_POINTERS_GENERIC\n\n"
);
182
printf(
"#undef COMBINE\n"
);
183
printf(
"#define COMBINE(n) %s32_combine_ ## n\n"
, a);
184
printf(
"#include \"quick_pc_to_pointers.h\"\n"
);
185
printf(
"#include \"cpu_%s_instr.cc\"\n"
, a);
186
187
printf(
"\n#undef DYNTRANS_PC_TO_POINTERS\n"
188
"#define DYNTRANS_PC_TO_POINTERS %s_pc_to_pointers\n"
189
"#define DYNTRANS_PC_TO_POINTERS32 %s32_pc_to_pointers\n\n"
, a, a);
190
191
printf(
"#define DYNTRANS_RUN_INSTR_DEF %s32_run_instr\n"
, a);
192
printf(
"#include \"cpu_dyntrans.cc\"\n"
);
193
printf(
"#undef DYNTRANS_RUN_INSTR_DEF\n\n"
);
194
195
printf(
"#endif /* DYNTRANS_DUALMODE_32 */\n\n\n"
);
196
197
198
printf(
"CPU_FAMILY_INIT(%s,\"%s\")\n\n"
, a, b);
199
200
return
0;
201
}
202
uppercase
char * uppercase(char *l)
Definition:
generate_tail.c:32
main
int main(int argc, char *argv[])
Definition:
generate_tail.c:50
Generated on Tue Aug 25 2020 19:25:06 for GXemul by
1.8.18