xref: /openbmc/qemu/target/hexagon/meson.build (revision ed75658a)
1##
2##  Copyright(c) 2020-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
3##
4##  This program is free software; you can redistribute it and/or modify
5##  it under the terms of the GNU General Public License as published by
6##  the Free Software Foundation; either version 2 of the License, or
7##  (at your option) any later version.
8##
9##  This program is distributed in the hope that it will be useful,
10##  but WITHOUT ANY WARRANTY; without even the implied warranty of
11##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12##  GNU General Public License for more details.
13##
14##  You should have received a copy of the GNU General Public License
15##  along with this program; if not, see <http://www.gnu.org/licenses/>.
16##
17
18hexagon_ss = ss.source_set()
19
20hex_common_py = 'hex_common.py'
21attribs_def = meson.current_source_dir() / 'attribs_def.h.inc'
22gen_tcg_h = meson.current_source_dir() / 'gen_tcg.h'
23gen_tcg_hvx_h = meson.current_source_dir() / 'gen_tcg_hvx.h'
24idef_parser_dir = meson.current_source_dir() / 'idef-parser'
25
26#
27#  Step 1
28#  We use a C program to create semantics_generated.pyinc
29#
30gen_semantics = executable(
31    'gen_semantics',
32    'gen_semantics.c',
33    native: true, build_by_default: false)
34
35semantics_generated = custom_target(
36    'semantics_generated.pyinc',
37    output: 'semantics_generated.pyinc',
38    command: [gen_semantics, '@OUTPUT@'],
39)
40hexagon_ss.add(semantics_generated)
41
42#
43# Step 2
44# We use Python scripts to generate the following files
45#     shortcode_generated.h.inc
46#     tcg_func_table_generated.c.inc
47#     printinsn_generated.h.inc
48#     op_regs_generated.h.inc
49#     op_attribs_generated.h.inc
50#     opcodes_def_generated.h.inc
51#
52shortcode_generated = custom_target(
53    'shortcode_generated.h.inc',
54    output: 'shortcode_generated.h.inc',
55    depends: [semantics_generated],
56    depend_files: [hex_common_py, attribs_def],
57    command: [python, files('gen_shortcode.py'), semantics_generated, attribs_def, '@OUTPUT@'],
58)
59hexagon_ss.add(shortcode_generated)
60
61tcg_func_table_generated = custom_target(
62    'tcg_func_table_generated.c.inc',
63    output: 'tcg_func_table_generated.c.inc',
64    depends: [semantics_generated],
65    depend_files: [hex_common_py, attribs_def],
66    command: [python, files('gen_tcg_func_table.py'), semantics_generated, attribs_def, '@OUTPUT@'],
67)
68hexagon_ss.add(tcg_func_table_generated)
69
70printinsn_generated = custom_target(
71    'printinsn_generated.h.inc',
72    output: 'printinsn_generated.h.inc',
73    depends: [semantics_generated],
74    depend_files: [hex_common_py, attribs_def],
75    command: [python, files('gen_printinsn.py'), semantics_generated, attribs_def, '@OUTPUT@'],
76)
77hexagon_ss.add(printinsn_generated)
78
79op_regs_generated = custom_target(
80    'op_regs_generated.h.inc',
81    output: 'op_regs_generated.h.inc',
82    depends: [semantics_generated],
83    depend_files: [hex_common_py, attribs_def],
84    command: [python, files('gen_op_regs.py'), semantics_generated, attribs_def, '@OUTPUT@'],
85)
86hexagon_ss.add(op_regs_generated)
87
88op_attribs_generated = custom_target(
89    'op_attribs_generated.h.inc',
90    output: 'op_attribs_generated.h.inc',
91    depends: [semantics_generated],
92    depend_files: [hex_common_py, attribs_def],
93    command: [python, files('gen_op_attribs.py'), semantics_generated, attribs_def, '@OUTPUT@'],
94)
95hexagon_ss.add(op_attribs_generated)
96
97opcodes_def_generated = custom_target(
98    'opcodes_def_generated.h.inc',
99    output: 'opcodes_def_generated.h.inc',
100    depends: [semantics_generated],
101    depend_files: [hex_common_py, attribs_def],
102    command: [python, files('gen_opcodes_def.py'), semantics_generated, attribs_def, '@OUTPUT@'],
103)
104hexagon_ss.add(opcodes_def_generated)
105
106#
107# Step 3
108# We use a C program to create iset.py which is imported into dectree.py
109# to create the decode tree
110#
111gen_dectree_import = executable(
112    'gen_dectree_import',
113    'gen_dectree_import.c', opcodes_def_generated, op_regs_generated,
114    native: true, build_by_default: false)
115
116iset_py = custom_target(
117    'iset.py',
118    output: 'iset.py',
119    command: [gen_dectree_import, '@OUTPUT@'],
120)
121hexagon_ss.add(iset_py)
122
123#
124# Step 4
125# Generate the input to the QEMU decodetree.py script
126#
127normal_decode_generated = custom_target(
128    'normal_decode_generated',
129    output: 'normal_decode_generated',
130    depends: [iset_py, semantics_generated],
131    env: {'PYTHONPATH': meson.current_build_dir()},
132    command: [python, files('gen_decodetree.py'), semantics_generated, 'NORMAL', '@OUTPUT@'],
133)
134hexagon_ss.add(normal_decode_generated)
135
136hvx_decode_generated = custom_target(
137    'hvx_decode_generated',
138    output: 'hvx_decode_generated',
139    depends: [iset_py, semantics_generated],
140    env: {'PYTHONPATH': meson.current_build_dir()},
141    command: [python, files('gen_decodetree.py'), semantics_generated, 'EXT_mmvec', '@OUTPUT@'],
142)
143hexagon_ss.add(hvx_decode_generated)
144
145subinsn_a_decode_generated = custom_target(
146    'subinsn_a_decode_generated',
147    output: 'subinsn_a_decode_generated',
148    depends: [iset_py, semantics_generated],
149    env: {'PYTHONPATH': meson.current_build_dir()},
150    command: [python, files('gen_decodetree.py'), semantics_generated, 'SUBINSN_A', '@OUTPUT@'],
151)
152hexagon_ss.add(subinsn_a_decode_generated)
153
154subinsn_l1_decode_generated = custom_target(
155    'subinsn_l1_decode_generated',
156    output: 'subinsn_l1_decode_generated',
157    depends: [iset_py, semantics_generated],
158    env: {'PYTHONPATH': meson.current_build_dir()},
159    command: [python, files('gen_decodetree.py'), semantics_generated, 'SUBINSN_L1', '@OUTPUT@'],
160)
161hexagon_ss.add(subinsn_l1_decode_generated)
162
163subinsn_l2_decode_generated = custom_target(
164    'subinsn_l2_decode_generated',
165    output: 'subinsn_l2_decode_generated',
166    depends: [iset_py, semantics_generated],
167    env: {'PYTHONPATH': meson.current_build_dir()},
168    command: [python, files('gen_decodetree.py'), semantics_generated, 'SUBINSN_L2', '@OUTPUT@'],
169)
170hexagon_ss.add(subinsn_l2_decode_generated)
171
172subinsn_s1_decode_generated = custom_target(
173    'subinsn_s1_decode_generated',
174    output: 'subinsn_s1_decode_generated',
175    depends: [iset_py, semantics_generated],
176    env: {'PYTHONPATH': meson.current_build_dir()},
177    command: [python, files('gen_decodetree.py'), semantics_generated, 'SUBINSN_S1', '@OUTPUT@'],
178)
179hexagon_ss.add(subinsn_s1_decode_generated)
180
181subinsn_s2_decode_generated = custom_target(
182    'subinsn_s2_decode_generated',
183    output: 'subinsn_s2_decode_generated',
184    depends: [iset_py, semantics_generated],
185    env: {'PYTHONPATH': meson.current_build_dir()},
186    command: [python, files('gen_decodetree.py'), semantics_generated, 'SUBINSN_S2', '@OUTPUT@'],
187)
188hexagon_ss.add(subinsn_s2_decode_generated)
189
190#
191# Run the QEMU decodetree.py script to produce the instruction decoder
192#
193decodetree_py = meson.current_source_dir() / '../../scripts/decodetree.py'
194decode_normal_generated = custom_target(
195    'decode_normal_generated.c.inc',
196    output: 'decode_normal_generated.c.inc',
197    input: normal_decode_generated,
198    env: {'PYTHONPATH': meson.current_build_dir()},
199    command: [python, files(decodetree_py), normal_decode_generated, '--static-decode=decode_normal', '-o', '@OUTPUT@'],
200)
201hexagon_ss.add(decode_normal_generated)
202
203decode_hvx_generated = custom_target(
204    'decode_hvx_generated.c.inc',
205    output: 'decode_hvx_generated.c.inc',
206    input: hvx_decode_generated,
207    env: {'PYTHONPATH': meson.current_build_dir()},
208    command: [python, files(decodetree_py), hvx_decode_generated, '--static-decode=decode_hvx', '-o', '@OUTPUT@'],
209)
210hexagon_ss.add(decode_hvx_generated)
211
212decode_subinsn_a_generated = custom_target(
213    'decode_subinsn_a_generated.c.inc',
214    output: 'decode_subinsn_a_generated.c.inc',
215    input: subinsn_a_decode_generated,
216    env: {'PYTHONPATH': meson.current_build_dir()},
217    command: [python, files(decodetree_py), subinsn_a_decode_generated, ['--static-decode=decode_subinsn_a', '--insnwidth=16'], '-o', '@OUTPUT@'],
218)
219hexagon_ss.add(decode_subinsn_a_generated)
220
221decode_subinsn_l1_generated = custom_target(
222    'decode_subinsn_l1_generated.c.inc',
223    output: 'decode_subinsn_l1_generated.c.inc',
224    input: subinsn_l1_decode_generated,
225    env: {'PYTHONPATH': meson.current_build_dir()},
226    command: [python, files(decodetree_py), subinsn_l1_decode_generated, ['--static-decode=decode_subinsn_l1', '--insnwidth=16'], '-o', '@OUTPUT@'],
227)
228hexagon_ss.add(decode_subinsn_l1_generated)
229
230decode_subinsn_l2_generated = custom_target(
231    'decode_subinsn_l2_generated.c.inc',
232    output: 'decode_subinsn_l2_generated.c.inc',
233    input: subinsn_l2_decode_generated,
234    env: {'PYTHONPATH': meson.current_build_dir()},
235    command: [python, files(decodetree_py), subinsn_l2_decode_generated, ['--static-decode=decode_subinsn_l2', '--insnwidth=16'], '-o', '@OUTPUT@'],
236)
237hexagon_ss.add(decode_subinsn_l2_generated)
238
239decode_subinsn_s1_generated = custom_target(
240    'decode_subinsn_s1_generated.c.inc',
241    output: 'decode_subinsn_s1_generated.c.inc',
242    input: subinsn_s1_decode_generated,
243    env: {'PYTHONPATH': meson.current_build_dir()},
244    command: [python, files(decodetree_py), subinsn_s1_decode_generated, ['--static-decode=decode_subinsn_s1', '--insnwidth=16'], '-o', '@OUTPUT@'],
245)
246hexagon_ss.add(decode_subinsn_s1_generated)
247
248decode_subinsn_s2_generated = custom_target(
249    'decode_subinsn_s2_generated.c.inc',
250    output: 'decode_subinsn_s2_generated.c.inc',
251    input: subinsn_s2_decode_generated,
252    env: {'PYTHONPATH': meson.current_build_dir()},
253    command: [python, files(decodetree_py), subinsn_s2_decode_generated, ['--static-decode=decode_subinsn_s2', '--insnwidth=16'], '-o', '@OUTPUT@'],
254)
255hexagon_ss.add(decode_subinsn_s2_generated)
256
257#
258# Generate the trans_* functions that the decoder will use
259#
260decodetree_trans_funcs_generated = custom_target(
261    'decodetree_trans_funcs_generated.c.inc',
262    output: 'decodetree_trans_funcs_generated.c.inc',
263    depends: [iset_py, semantics_generated],
264    env: {'PYTHONPATH': meson.current_build_dir()},
265    command: [python, files('gen_trans_funcs.py'), semantics_generated, '@OUTPUT@'],
266)
267hexagon_ss.add(decodetree_trans_funcs_generated)
268
269hexagon_ss.add(files(
270    'cpu.c',
271    'translate.c',
272    'op_helper.c',
273    'gdbstub.c',
274    'genptr.c',
275    'reg_fields.c',
276    'decode.c',
277    'iclass.c',
278    'opcodes.c',
279    'printinsn.c',
280    'arch.c',
281    'fma_emu.c',
282    'mmvec/decode_ext_mmvec.c',
283    'mmvec/system_ext_mmvec.c',
284))
285
286#
287# Step 4.5
288# We use flex/bison based idef-parser to generate TCG code for a lot
289# of instructions. idef-parser outputs
290#     idef-generated-emitter.c
291#     idef-generated-emitter.h.inc
292#     idef-generated-enabled-instructions
293#
294idef_parser_enabled = get_option('hexagon_idef_parser')
295if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
296    idef_parser_input_generated = custom_target(
297        'idef_parser_input.h.inc',
298        output: 'idef_parser_input.h.inc',
299        depends: [semantics_generated],
300        depend_files: [hex_common_py],
301        command: [python, files('gen_idef_parser_funcs.py'), semantics_generated, attribs_def, '@OUTPUT@'],
302    )
303
304    preprocessed_idef_parser_input_generated = custom_target(
305        'idef_parser_input.preprocessed.h.inc',
306        output: 'idef_parser_input.preprocessed.h.inc',
307        input: idef_parser_input_generated,
308        depend_files: [idef_parser_dir / 'macros.inc'],
309        command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_dir, '-o', '@OUTPUT@'],
310    )
311
312    flex = generator(
313        find_program('flex'),
314        output: ['@BASENAME@.yy.c', '@BASENAME@.yy.h'],
315        arguments: ['-o', '@OUTPUT0@', '--header-file=@OUTPUT1@', '@INPUT@']
316    )
317
318    bison = generator(
319        find_program('bison', version: '>=3.0'),
320        output: ['@BASENAME@.tab.c', '@BASENAME@.tab.h'],
321        arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@']
322    )
323
324    glib_dep = dependency('glib-2.0', native: true)
325
326    idef_parser = executable(
327        'idef-parser',
328        [flex.process(idef_parser_dir / 'idef-parser.lex'),
329         bison.process(idef_parser_dir / 'idef-parser.y'),
330         idef_parser_dir / 'parser-helpers.c'],
331        include_directories: ['idef-parser', '../../include/'],
332        dependencies: [glib_dep],
333        native: true
334    )
335
336    idef_generated_tcg = custom_target(
337        'idef-generated-tcg',
338        output: ['idef-generated-emitter.c',
339                 'idef-generated-emitter.h.inc',
340                 'idef-generated-enabled-instructions'],
341        input: preprocessed_idef_parser_input_generated,
342        depend_files: [hex_common_py],
343        command: [idef_parser, '@INPUT@', '@OUTPUT0@', '@OUTPUT1@', '@OUTPUT2@']
344    )
345
346    indent = find_program('indent', required: false)
347    if indent.found()
348        idef_generated_tcg_c = custom_target(
349            'indent',
350            input: idef_generated_tcg[0],
351            output: 'idef-generated-emitter.indented.c',
352            command: [indent, '-linux', '@INPUT@', '-o', '@OUTPUT@']
353        )
354    else
355        idef_generated_tcg_c = custom_target(
356            'copy',
357            input: idef_generated_tcg[0],
358            output: 'idef-generated-emitter.indented.c',
359            command: ['cp', '@INPUT@', '@OUTPUT@']
360        )
361    endif
362
363    idef_generated_list = idef_generated_tcg[2].full_path()
364
365    hexagon_ss.add(idef_generated_tcg_c)
366
367    # Setup input and dependencies for the next step, this depends on whether or
368    # not idef-parser is enabled
369    helper_dep = [semantics_generated, idef_generated_tcg_c, idef_generated_tcg]
370    helper_in = [semantics_generated, attribs_def, gen_tcg_h, gen_tcg_hvx_h, idef_generated_list]
371else
372    # Setup input and dependencies for the next step, this depends on whether or
373    # not idef-parser is enabled
374    helper_dep = [semantics_generated]
375    helper_in = [semantics_generated, attribs_def, gen_tcg_h, gen_tcg_hvx_h]
376endif
377
378#
379# Step 5
380# We use Python scripts to generate the following files
381#     helper_protos_generated.h.inc
382#     helper_funcs_generated.c.inc
383#     tcg_funcs_generated.c.inc
384#
385helper_protos_generated = custom_target(
386    'helper_protos_generated.h.inc',
387    output: 'helper_protos_generated.h.inc',
388    depends: helper_dep,
389    depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h],
390    command: [python, files('gen_helper_protos.py'), helper_in, '@OUTPUT@'],
391)
392hexagon_ss.add(helper_protos_generated)
393
394helper_funcs_generated = custom_target(
395    'helper_funcs_generated.c.inc',
396    output: 'helper_funcs_generated.c.inc',
397    depends: helper_dep,
398    depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h],
399    command: [python, files('gen_helper_funcs.py'), helper_in, '@OUTPUT@'],
400)
401hexagon_ss.add(helper_funcs_generated)
402
403tcg_funcs_generated = custom_target(
404    'tcg_funcs_generated.c.inc',
405    output: 'tcg_funcs_generated.c.inc',
406    depends: helper_dep,
407    depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h],
408    command: [python, files('gen_tcg_funcs.py'), helper_in, '@OUTPUT@'],
409)
410hexagon_ss.add(tcg_funcs_generated)
411
412analyze_funcs_generated = custom_target(
413    'analyze_funcs_generated.c.inc',
414    output: 'analyze_funcs_generated.c.inc',
415    depends: helper_dep,
416    depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h],
417    command: [python, files('gen_analyze_funcs.py'), helper_in, '@OUTPUT@'],
418)
419hexagon_ss.add(analyze_funcs_generated)
420
421target_arch += {'hexagon': hexagon_ss}
422