blob: ce21d3b688ed695cdb2f49775202775526aa5d5b [file] [log] [blame]
Taylor Simpson793958c2021-02-07 23:46:10 -06001#!/usr/bin/env python3
2
3##
Taylor Simpsone28b77a2023-03-06 18:58:26 -08004## Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
Taylor Simpson793958c2021-02-07 23:46:10 -06005##
6## This program is free software; you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation; either version 2 of the License, or
9## (at your option) any later version.
10##
11## This program is distributed in the hope that it will be useful,
12## but WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14## GNU General Public License for more details.
15##
16## You should have received a copy of the GNU General Public License
17## along with this program; if not, see <http://www.gnu.org/licenses/>.
18##
19
20import sys
21import re
22import string
23import hex_common
24
Marco Liebel5bb322e2023-03-20 02:25:33 -070025
Taylor Simpson793958c2021-02-07 23:46:10 -060026##
27## Helpers for gen_helper_function
28##
29def gen_decl_ea(f):
30 f.write(" uint32_t EA;\n")
31
Marco Liebel5bb322e2023-03-20 02:25:33 -070032
33def gen_helper_return_type(f, regtype, regid, regno):
34 if regno > 1:
35 f.write(", ")
Taylor Simpson793958c2021-02-07 23:46:10 -060036 f.write("int32_t")
37
Marco Liebel5bb322e2023-03-20 02:25:33 -070038
39def gen_helper_return_type_pair(f, regtype, regid, regno):
40 if regno > 1:
41 f.write(", ")
Taylor Simpson793958c2021-02-07 23:46:10 -060042 f.write("int64_t")
43
Marco Liebel5bb322e2023-03-20 02:25:33 -070044
45def gen_helper_arg(f, regtype, regid, regno):
46 if regno > 0:
47 f.write(", ")
Marco Liebelcd6c4ed2023-03-20 02:25:32 -070048 f.write(f"int32_t {regtype}{regid}V")
Taylor Simpson793958c2021-02-07 23:46:10 -060049
Marco Liebel5bb322e2023-03-20 02:25:33 -070050
51def gen_helper_arg_new(f, regtype, regid, regno):
52 if regno >= 0:
53 f.write(", ")
Marco Liebelcd6c4ed2023-03-20 02:25:32 -070054 f.write(f"int32_t {regtype}{regid}N")
Taylor Simpson793958c2021-02-07 23:46:10 -060055
Marco Liebel5bb322e2023-03-20 02:25:33 -070056
57def gen_helper_arg_pair(f, regtype, regid, regno):
58 if regno >= 0:
59 f.write(", ")
Marco Liebelcd6c4ed2023-03-20 02:25:32 -070060 f.write(f"int64_t {regtype}{regid}V")
Taylor Simpson793958c2021-02-07 23:46:10 -060061
Marco Liebel5bb322e2023-03-20 02:25:33 -070062
63def gen_helper_arg_ext(f, regtype, regid, regno):
64 if regno > 0:
65 f.write(", ")
Marco Liebelcd6c4ed2023-03-20 02:25:32 -070066 f.write(f"void *{regtype}{regid}V_void")
Taylor Simpsonccd9eec2020-12-09 18:35:22 -060067
Marco Liebel5bb322e2023-03-20 02:25:33 -070068
69def gen_helper_arg_ext_pair(f, regtype, regid, regno):
70 if regno > 0:
71 f.write(", ")
Marco Liebelcd6c4ed2023-03-20 02:25:32 -070072 f.write(f"void *{regtype}{regid}V_void")
Taylor Simpsonccd9eec2020-12-09 18:35:22 -060073
Marco Liebel5bb322e2023-03-20 02:25:33 -070074
75def gen_helper_arg_opn(f, regtype, regid, i, tag):
76 if hex_common.is_pair(regid):
77 if hex_common.is_hvx_reg(regtype):
78 gen_helper_arg_ext_pair(f, regtype, regid, i)
Taylor Simpsonccd9eec2020-12-09 18:35:22 -060079 else:
Marco Liebel5bb322e2023-03-20 02:25:33 -070080 gen_helper_arg_pair(f, regtype, regid, i)
81 elif hex_common.is_single(regid):
Taylor Simpson793958c2021-02-07 23:46:10 -060082 if hex_common.is_old_val(regtype, regid, tag):
Marco Liebel5bb322e2023-03-20 02:25:33 -070083 if hex_common.is_hvx_reg(regtype):
84 gen_helper_arg_ext(f, regtype, regid, i)
Taylor Simpsonccd9eec2020-12-09 18:35:22 -060085 else:
Marco Liebel5bb322e2023-03-20 02:25:33 -070086 gen_helper_arg(f, regtype, regid, i)
Taylor Simpson793958c2021-02-07 23:46:10 -060087 elif hex_common.is_new_val(regtype, regid, tag):
Marco Liebel5bb322e2023-03-20 02:25:33 -070088 gen_helper_arg_new(f, regtype, regid, i)
Taylor Simpson793958c2021-02-07 23:46:10 -060089 else:
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -030090 hex_common.bad_register(regtype, regid)
Taylor Simpson793958c2021-02-07 23:46:10 -060091 else:
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -030092 hex_common.bad_register(regtype, regid)
Taylor Simpson793958c2021-02-07 23:46:10 -060093
Marco Liebel5bb322e2023-03-20 02:25:33 -070094
95def gen_helper_arg_imm(f, immlett):
Marco Liebelcd6c4ed2023-03-20 02:25:32 -070096 f.write(f", int32_t {hex_common.imm_name(immlett)}")
Taylor Simpson793958c2021-02-07 23:46:10 -060097
Marco Liebel5bb322e2023-03-20 02:25:33 -070098
99def gen_helper_dest_decl(f, regtype, regid, regno, subfield=""):
Marco Liebelcd6c4ed2023-03-20 02:25:32 -0700100 f.write(f" int32_t {regtype}{regid}V{subfield} = 0;\n")
Taylor Simpson793958c2021-02-07 23:46:10 -0600101
Marco Liebel5bb322e2023-03-20 02:25:33 -0700102
103def gen_helper_dest_decl_pair(f, regtype, regid, regno, subfield=""):
Marco Liebelcd6c4ed2023-03-20 02:25:32 -0700104 f.write(f" int64_t {regtype}{regid}V{subfield} = 0;\n")
Taylor Simpson793958c2021-02-07 23:46:10 -0600105
Marco Liebel5bb322e2023-03-20 02:25:33 -0700106
107def gen_helper_dest_decl_ext(f, regtype, regid):
108 if regtype == "Q":
109 f.write(
110 f" /* {regtype}{regid}V is *(MMQReg *)" f"({regtype}{regid}V_void) */\n"
111 )
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600112 else:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700113 f.write(
114 f" /* {regtype}{regid}V is *(MMVector *)"
115 f"({regtype}{regid}V_void) */\n"
116 )
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600117
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600118
Marco Liebel5bb322e2023-03-20 02:25:33 -0700119def gen_helper_dest_decl_ext_pair(f, regtype, regid, regno):
120 f.write(
121 f" /* {regtype}{regid}V is *(MMVectorPair *))"
122 f"{regtype}{regid}V_void) */\n"
123 )
124
125
126def gen_helper_dest_decl_opn(f, regtype, regid, i):
127 if hex_common.is_pair(regid):
128 if hex_common.is_hvx_reg(regtype):
129 gen_helper_dest_decl_ext_pair(f, regtype, regid, i)
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600130 else:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700131 gen_helper_dest_decl_pair(f, regtype, regid, i)
132 elif hex_common.is_single(regid):
133 if hex_common.is_hvx_reg(regtype):
134 gen_helper_dest_decl_ext(f, regtype, regid)
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600135 else:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700136 gen_helper_dest_decl(f, regtype, regid, i)
Taylor Simpson793958c2021-02-07 23:46:10 -0600137 else:
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300138 hex_common.bad_register(regtype, regid)
Taylor Simpson793958c2021-02-07 23:46:10 -0600139
Marco Liebel5bb322e2023-03-20 02:25:33 -0700140
141def gen_helper_src_var_ext(f, regtype, regid):
142 if regtype == "Q":
143 f.write(
144 f" /* {regtype}{regid}V is *(MMQReg *)" f"({regtype}{regid}V_void) */\n"
145 )
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600146 else:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700147 f.write(
148 f" /* {regtype}{regid}V is *(MMVector *)"
149 f"({regtype}{regid}V_void) */\n"
150 )
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600151
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600152
Marco Liebel5bb322e2023-03-20 02:25:33 -0700153def gen_helper_src_var_ext_pair(f, regtype, regid, regno):
154 f.write(
155 f" /* {regtype}{regid}V{regno} is *(MMVectorPair *)"
156 f"({regtype}{regid}V{regno}_void) */\n"
157 )
158
159
160def gen_helper_return(f, regtype, regid, regno):
Marco Liebelcd6c4ed2023-03-20 02:25:32 -0700161 f.write(f" return {regtype}{regid}V;\n")
Taylor Simpson793958c2021-02-07 23:46:10 -0600162
Marco Liebel5bb322e2023-03-20 02:25:33 -0700163
164def gen_helper_return_pair(f, regtype, regid, regno):
Marco Liebelcd6c4ed2023-03-20 02:25:32 -0700165 f.write(f" return {regtype}{regid}V;\n")
Taylor Simpson793958c2021-02-07 23:46:10 -0600166
Marco Liebel5bb322e2023-03-20 02:25:33 -0700167
168def gen_helper_dst_write_ext(f, regtype, regid):
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600169 return
170
Marco Liebel5bb322e2023-03-20 02:25:33 -0700171
172def gen_helper_dst_write_ext_pair(f, regtype, regid):
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600173 return
174
Marco Liebel5bb322e2023-03-20 02:25:33 -0700175
Taylor Simpson793958c2021-02-07 23:46:10 -0600176def gen_helper_return_opn(f, regtype, regid, i):
Marco Liebel5bb322e2023-03-20 02:25:33 -0700177 if hex_common.is_pair(regid):
178 if hex_common.is_hvx_reg(regtype):
179 gen_helper_dst_write_ext_pair(f, regtype, regid)
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600180 else:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700181 gen_helper_return_pair(f, regtype, regid, i)
182 elif hex_common.is_single(regid):
183 if hex_common.is_hvx_reg(regtype):
184 gen_helper_dst_write_ext(f, regtype, regid)
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600185 else:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700186 gen_helper_return(f, regtype, regid, i)
Taylor Simpson793958c2021-02-07 23:46:10 -0600187 else:
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300188 hex_common.bad_register(regtype, regid)
Marco Liebel5bb322e2023-03-20 02:25:33 -0700189
Taylor Simpson793958c2021-02-07 23:46:10 -0600190
191##
192## Generate the TCG code to call the helper
193## For A2_add: Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;}
194## We produce:
195## int32_t HELPER(A2_add)(CPUHexagonState *env, int32_t RsV, int32_t RtV)
196## {
197## uint32_t slot __attribute__(unused)) = 4;
198## int32_t RdV = 0;
199## { RdV=RsV+RtV;}
200## COUNT_HELPER(A2_add);
201## return RdV;
202## }
203##
204def gen_helper_function(f, tag, tagregs, tagimms):
205 regs = tagregs[tag]
206 imms = tagimms[tag]
207
208 numresults = 0
209 numscalarresults = 0
210 numscalarreadwrite = 0
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300211 for regtype, regid in regs:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700212 if hex_common.is_written(regid):
Taylor Simpson793958c2021-02-07 23:46:10 -0600213 numresults += 1
Marco Liebel5bb322e2023-03-20 02:25:33 -0700214 if hex_common.is_scalar_reg(regtype):
Taylor Simpson793958c2021-02-07 23:46:10 -0600215 numscalarresults += 1
Marco Liebel5bb322e2023-03-20 02:25:33 -0700216 if hex_common.is_readwrite(regid):
217 if hex_common.is_scalar_reg(regtype):
Taylor Simpson793958c2021-02-07 23:46:10 -0600218 numscalarreadwrite += 1
219
Marco Liebel5bb322e2023-03-20 02:25:33 -0700220 if numscalarresults > 1:
Taylor Simpson793958c2021-02-07 23:46:10 -0600221 ## The helper is bogus when there is more than one result
Marco Liebel5bb322e2023-03-20 02:25:33 -0700222 f.write(
223 f"void HELPER({tag})(CPUHexagonState *env) " f"{{ BOGUS_HELPER({tag}); }}\n"
224 )
Taylor Simpson793958c2021-02-07 23:46:10 -0600225 else:
226 ## The return type of the function is the type of the destination
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600227 ## register (if scalar)
Marco Liebel5bb322e2023-03-20 02:25:33 -0700228 i = 0
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300229 for regtype, regid in regs:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700230 if hex_common.is_written(regid):
231 if hex_common.is_pair(regid):
232 if hex_common.is_hvx_reg(regtype):
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600233 continue
234 else:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700235 gen_helper_return_type_pair(f, regtype, regid, i)
236 elif hex_common.is_single(regid):
237 if hex_common.is_hvx_reg(regtype):
238 continue
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600239 else:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700240 gen_helper_return_type(f, regtype, regid, i)
Taylor Simpson793958c2021-02-07 23:46:10 -0600241 else:
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300242 hex_common.bad_register(regtype, regid)
Taylor Simpson793958c2021-02-07 23:46:10 -0600243 i += 1
244
Marco Liebel5bb322e2023-03-20 02:25:33 -0700245 if numscalarresults == 0:
Taylor Simpson793958c2021-02-07 23:46:10 -0600246 f.write("void")
Marco Liebelcd6c4ed2023-03-20 02:25:32 -0700247 f.write(f" HELPER({tag})(CPUHexagonState *env")
Taylor Simpson793958c2021-02-07 23:46:10 -0600248
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600249 ## Arguments include the vector destination operands
Taylor Simpson793958c2021-02-07 23:46:10 -0600250 i = 1
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300251 for regtype, regid in regs:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700252 if hex_common.is_written(regid):
253 if hex_common.is_pair(regid):
254 if hex_common.is_hvx_reg(regtype):
255 gen_helper_arg_ext_pair(f, regtype, regid, i)
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600256 else:
257 continue
Marco Liebel5bb322e2023-03-20 02:25:33 -0700258 elif hex_common.is_single(regid):
259 if hex_common.is_hvx_reg(regtype):
260 gen_helper_arg_ext(f, regtype, regid, i)
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600261 else:
262 # This is the return value of the function
263 continue
264 else:
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300265 hex_common.bad_register(regtype, regid)
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600266 i += 1
Taylor Simpson793958c2021-02-07 23:46:10 -0600267
Taylor Simpsone28b77a2023-03-06 18:58:26 -0800268 ## For conditional instructions, we pass in the destination register
Marco Liebel5bb322e2023-03-20 02:25:33 -0700269 if "A_CONDEXEC" in hex_common.attribdict[tag]:
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300270 for regtype, regid in regs:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700271 if hex_common.is_writeonly(regid) and not hex_common.is_hvx_reg(
272 regtype
273 ):
Taylor Simpsone28b77a2023-03-06 18:58:26 -0800274 gen_helper_arg_opn(f, regtype, regid, i, tag)
275 i += 1
276
Taylor Simpson793958c2021-02-07 23:46:10 -0600277 ## Arguments to the helper function are the source regs and immediates
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300278 for regtype, regid in regs:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700279 if hex_common.is_read(regid):
280 if hex_common.is_hvx_reg(regtype) and hex_common.is_readwrite(regid):
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600281 continue
Marco Liebel5bb322e2023-03-20 02:25:33 -0700282 gen_helper_arg_opn(f, regtype, regid, i, tag)
Taylor Simpson793958c2021-02-07 23:46:10 -0600283 i += 1
Marco Liebel5bb322e2023-03-20 02:25:33 -0700284 for immlett, bits, immshift in imms:
285 gen_helper_arg_imm(f, immlett)
Taylor Simpson793958c2021-02-07 23:46:10 -0600286 i += 1
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600287
Marco Liebel5bb322e2023-03-20 02:25:33 -0700288 if hex_common.need_pkt_has_multi_cof(tag):
Taylor Simpsonfb67c2b2022-11-08 08:28:59 -0800289 f.write(", uint32_t pkt_has_multi_cof")
Taylor Simpsond54c5612023-04-27 16:00:02 -0700290 if (hex_common.need_pkt_need_commit(tag)):
291 f.write(", uint32_t pkt_need_commit")
Taylor Simpsonfb67c2b2022-11-08 08:28:59 -0800292
Taylor Simpson40085902022-11-08 08:29:00 -0800293 if hex_common.need_PC(tag):
Marco Liebel5bb322e2023-03-20 02:25:33 -0700294 if i > 0:
295 f.write(", ")
Taylor Simpson40085902022-11-08 08:29:00 -0800296 f.write("target_ulong PC")
297 i += 1
Taylor Simpson613653e2022-11-08 08:29:01 -0800298 if hex_common.helper_needs_next_PC(tag):
Marco Liebel5bb322e2023-03-20 02:25:33 -0700299 if i > 0:
300 f.write(", ")
Taylor Simpson613653e2022-11-08 08:29:01 -0800301 f.write("target_ulong next_PC")
302 i += 1
Taylor Simpson793958c2021-02-07 23:46:10 -0600303 if hex_common.need_slot(tag):
Marco Liebel5bb322e2023-03-20 02:25:33 -0700304 if i > 0:
305 f.write(", ")
Taylor Simpsone5d0d782023-04-27 16:00:11 -0700306 f.write("uint32_t slotval")
Taylor Simpson793958c2021-02-07 23:46:10 -0600307 i += 1
308 if hex_common.need_part1(tag):
Marco Liebel5bb322e2023-03-20 02:25:33 -0700309 if i > 0:
310 f.write(", ")
Taylor Simpson793958c2021-02-07 23:46:10 -0600311 f.write("uint32_t part1")
312 f.write(")\n{\n")
Marco Liebel5bb322e2023-03-20 02:25:33 -0700313 if hex_common.need_ea(tag):
314 gen_decl_ea(f)
Taylor Simpson793958c2021-02-07 23:46:10 -0600315 ## Declare the return variable
Marco Liebel5bb322e2023-03-20 02:25:33 -0700316 i = 0
317 if "A_CONDEXEC" not in hex_common.attribdict[tag]:
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300318 for regtype, regid in regs:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700319 if hex_common.is_writeonly(regid):
320 gen_helper_dest_decl_opn(f, regtype, regid, i)
Taylor Simpsone28b77a2023-03-06 18:58:26 -0800321 i += 1
Taylor Simpson793958c2021-02-07 23:46:10 -0600322
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300323 for regtype, regid in regs:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700324 if hex_common.is_read(regid):
325 if hex_common.is_pair(regid):
326 if hex_common.is_hvx_reg(regtype):
327 gen_helper_src_var_ext_pair(f, regtype, regid, i)
328 elif hex_common.is_single(regid):
329 if hex_common.is_hvx_reg(regtype):
330 gen_helper_src_var_ext(f, regtype, regid)
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600331 else:
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300332 hex_common.bad_register(regtype, regid)
Taylor Simpsonccd9eec2020-12-09 18:35:22 -0600333
Taylor Simpsone5d0d782023-04-27 16:00:11 -0700334 if hex_common.need_slot(tag):
335 if "A_LOAD" in hex_common.attribdict[tag]:
336 f.write(" bool pkt_has_store_s1 = slotval & 0x1;\n")
337 f.write(" uint32_t slot = slotval >> 1;\n")
338
Marco Liebel5bb322e2023-03-20 02:25:33 -0700339 if "A_FPOP" in hex_common.attribdict[tag]:
340 f.write(" arch_fpop_start(env);\n")
Taylor Simpson793958c2021-02-07 23:46:10 -0600341
Marco Liebelcd6c4ed2023-03-20 02:25:32 -0700342 f.write(f" {hex_common.semdict[tag]}\n")
Taylor Simpson793958c2021-02-07 23:46:10 -0600343
Marco Liebel5bb322e2023-03-20 02:25:33 -0700344 if "A_FPOP" in hex_common.attribdict[tag]:
345 f.write(" arch_fpop_end(env);\n")
Taylor Simpson793958c2021-02-07 23:46:10 -0600346
347 ## Save/return the return variable
Matheus Tavares Bernardino3608c242023-05-24 11:41:47 -0300348 for regtype, regid in regs:
Marco Liebel5bb322e2023-03-20 02:25:33 -0700349 if hex_common.is_written(regid):
Taylor Simpson793958c2021-02-07 23:46:10 -0600350 gen_helper_return_opn(f, regtype, regid, i)
351 f.write("}\n\n")
352 ## End of the helper definition
353
Marco Liebel5bb322e2023-03-20 02:25:33 -0700354
Taylor Simpson793958c2021-02-07 23:46:10 -0600355def main():
356 hex_common.read_semantics_file(sys.argv[1])
357 hex_common.read_attribs_file(sys.argv[2])
358 hex_common.read_overrides_file(sys.argv[3])
Taylor Simpsond51bcab2021-05-18 12:01:09 -0500359 hex_common.read_overrides_file(sys.argv[4])
Alessandro Di Federicoe71fdc42022-09-23 19:38:30 +0200360 ## Whether or not idef-parser is enabled is
361 ## determined by the number of arguments to
362 ## this script:
363 ##
364 ## 5 args. -> not enabled,
365 ## 6 args. -> idef-parser enabled.
366 ##
367 ## The 6:th arg. then holds a list of the successfully
368 ## parsed instructions.
369 is_idef_parser_enabled = len(sys.argv) > 6
370 if is_idef_parser_enabled:
371 hex_common.read_idef_parser_enabled_file(sys.argv[5])
Taylor Simpson793958c2021-02-07 23:46:10 -0600372 hex_common.calculate_attribs()
373 tagregs = hex_common.get_tagregs()
374 tagimms = hex_common.get_tagimms()
375
Alessandro Di Federicoe71fdc42022-09-23 19:38:30 +0200376 output_file = sys.argv[-1]
Marco Liebel5bb322e2023-03-20 02:25:33 -0700377 with open(output_file, "w") as f:
Taylor Simpson793958c2021-02-07 23:46:10 -0600378 for tag in hex_common.tags:
379 ## Skip the priv instructions
Marco Liebel5bb322e2023-03-20 02:25:33 -0700380 if "A_PRIV" in hex_common.attribdict[tag]:
Taylor Simpson793958c2021-02-07 23:46:10 -0600381 continue
382 ## Skip the guest instructions
Marco Liebel5bb322e2023-03-20 02:25:33 -0700383 if "A_GUEST" in hex_common.attribdict[tag]:
Taylor Simpson793958c2021-02-07 23:46:10 -0600384 continue
385 ## Skip the diag instructions
Marco Liebel5bb322e2023-03-20 02:25:33 -0700386 if tag == "Y6_diag":
Taylor Simpson793958c2021-02-07 23:46:10 -0600387 continue
Marco Liebel5bb322e2023-03-20 02:25:33 -0700388 if tag == "Y6_diag0":
Taylor Simpson793958c2021-02-07 23:46:10 -0600389 continue
Marco Liebel5bb322e2023-03-20 02:25:33 -0700390 if tag == "Y6_diag1":
Taylor Simpson793958c2021-02-07 23:46:10 -0600391 continue
Marco Liebel5bb322e2023-03-20 02:25:33 -0700392 if hex_common.skip_qemu_helper(tag):
Taylor Simpson793958c2021-02-07 23:46:10 -0600393 continue
Marco Liebel5bb322e2023-03-20 02:25:33 -0700394 if hex_common.is_idef_parser_enabled(tag):
Alessandro Di Federicoe71fdc42022-09-23 19:38:30 +0200395 continue
Taylor Simpson793958c2021-02-07 23:46:10 -0600396
397 gen_helper_function(f, tag, tagregs, tagimms)
398
Marco Liebel5bb322e2023-03-20 02:25:33 -0700399
Taylor Simpson793958c2021-02-07 23:46:10 -0600400if __name__ == "__main__":
401 main()