1793958c9STaylor Simpson#!/usr/bin/env python3 2793958c9STaylor Simpson 3793958c9STaylor Simpson## 42f0a771dSTaylor Simpson## Copyright(c) 2019-2024 Qualcomm Innovation Center, Inc. All Rights Reserved. 5793958c9STaylor Simpson## 6793958c9STaylor Simpson## This program is free software; you can redistribute it and/or modify 7793958c9STaylor Simpson## it under the terms of the GNU General Public License as published by 8793958c9STaylor Simpson## the Free Software Foundation; either version 2 of the License, or 9793958c9STaylor Simpson## (at your option) any later version. 10793958c9STaylor Simpson## 11793958c9STaylor Simpson## This program is distributed in the hope that it will be useful, 12793958c9STaylor Simpson## but WITHOUT ANY WARRANTY; without even the implied warranty of 13793958c9STaylor Simpson## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14793958c9STaylor Simpson## GNU General Public License for more details. 15793958c9STaylor Simpson## 16793958c9STaylor Simpson## You should have received a copy of the GNU General Public License 17793958c9STaylor Simpson## along with this program; if not, see <http://www.gnu.org/licenses/>. 18793958c9STaylor Simpson## 19793958c9STaylor Simpson 20793958c9STaylor Simpsonimport sys 21793958c9STaylor Simpsonimport re 22793958c9STaylor Simpsonimport string 23793958c9STaylor Simpsonimport hex_common 24793958c9STaylor Simpson 25793958c9STaylor Simpson## 26793958c9STaylor Simpson## Generate the DEF_HELPER prototype for an instruction 27793958c9STaylor Simpson## For A2_add: Rd32=add(Rs32,Rt32) 28793958c9STaylor Simpson## We produce: 29793958c9STaylor Simpson## DEF_HELPER_3(A2_add, s32, env, s32, s32) 30793958c9STaylor Simpson## 31793958c9STaylor Simpsondef gen_helper_prototype(f, tag, tagregs, tagimms): 32793958c9STaylor Simpson regs = tagregs[tag] 33793958c9STaylor Simpson imms = tagimms[tag] 34793958c9STaylor Simpson 35c568919fSTaylor Simpson declared = [] 36c568919fSTaylor Simpson ret_type = hex_common.helper_ret_type(tag, regs).proto_arg 37c568919fSTaylor Simpson declared.append(ret_type) 38793958c9STaylor Simpson 39c568919fSTaylor Simpson for arg in hex_common.helper_args(tag, regs, imms): 40c568919fSTaylor Simpson declared.append(arg.proto_arg) 41793958c9STaylor Simpson 42c568919fSTaylor Simpson arguments = ", ".join(declared) 432f0a771dSTaylor Simpson 442f0a771dSTaylor Simpson ## Add the TCG_CALL_NO_RWG_SE flag to helpers that don't take the env 452f0a771dSTaylor Simpson ## argument and aren't HVX instructions. Since HVX instructions take 462f0a771dSTaylor Simpson ## pointers to their arguments, they will have side effects. 472f0a771dSTaylor Simpson if hex_common.need_env(tag) or hex_common.is_hvx_insn(tag): 48c568919fSTaylor Simpson f.write(f"DEF_HELPER_{len(declared) - 1}({tag}, {arguments})\n") 492f0a771dSTaylor Simpson else: 502f0a771dSTaylor Simpson f.write(f"DEF_HELPER_FLAGS_{len(declared) - 1}({tag}, " 512f0a771dSTaylor Simpson f"TCG_CALL_NO_RWG_SE, {arguments})\n") 525bb322e2SMarco Liebel 53793958c9STaylor Simpson 54793958c9STaylor Simpsondef main(): 55793958c9STaylor Simpson hex_common.read_semantics_file(sys.argv[1]) 56793958c9STaylor Simpson hex_common.read_attribs_file(sys.argv[2]) 57793958c9STaylor Simpson hex_common.read_overrides_file(sys.argv[3]) 58d51bcabeSTaylor Simpson hex_common.read_overrides_file(sys.argv[4]) 59e71fdc4fSAlessandro Di Federico ## Whether or not idef-parser is enabled is 60e71fdc4fSAlessandro Di Federico ## determined by the number of arguments to 61e71fdc4fSAlessandro Di Federico ## this script: 62e71fdc4fSAlessandro Di Federico ## 63e71fdc4fSAlessandro Di Federico ## 5 args. -> not enabled, 64e71fdc4fSAlessandro Di Federico ## 6 args. -> idef-parser enabled. 65e71fdc4fSAlessandro Di Federico ## 66e71fdc4fSAlessandro Di Federico ## The 6:th arg. then holds a list of the successfully 67e71fdc4fSAlessandro Di Federico ## parsed instructions. 68e71fdc4fSAlessandro Di Federico is_idef_parser_enabled = len(sys.argv) > 6 69e71fdc4fSAlessandro Di Federico if is_idef_parser_enabled: 70e71fdc4fSAlessandro Di Federico hex_common.read_idef_parser_enabled_file(sys.argv[5]) 71793958c9STaylor Simpson hex_common.calculate_attribs() 72c568919fSTaylor Simpson hex_common.init_registers() 73793958c9STaylor Simpson tagregs = hex_common.get_tagregs() 74793958c9STaylor Simpson tagimms = hex_common.get_tagimms() 75793958c9STaylor Simpson 76e71fdc4fSAlessandro Di Federico output_file = sys.argv[-1] 775bb322e2SMarco Liebel with open(output_file, "w") as f: 78793958c9STaylor Simpson for tag in hex_common.tags: 79793958c9STaylor Simpson ## Skip the priv instructions 805bb322e2SMarco Liebel if "A_PRIV" in hex_common.attribdict[tag]: 81793958c9STaylor Simpson continue 82793958c9STaylor Simpson ## Skip the guest instructions 835bb322e2SMarco Liebel if "A_GUEST" in hex_common.attribdict[tag]: 84793958c9STaylor Simpson continue 85793958c9STaylor Simpson ## Skip the diag instructions 865bb322e2SMarco Liebel if tag == "Y6_diag": 87793958c9STaylor Simpson continue 885bb322e2SMarco Liebel if tag == "Y6_diag0": 89793958c9STaylor Simpson continue 905bb322e2SMarco Liebel if tag == "Y6_diag1": 91793958c9STaylor Simpson continue 92793958c9STaylor Simpson 935bb322e2SMarco Liebel if hex_common.skip_qemu_helper(tag): 94793958c9STaylor Simpson continue 955bb322e2SMarco Liebel if hex_common.is_idef_parser_enabled(tag): 96e71fdc4fSAlessandro Di Federico continue 97793958c9STaylor Simpson 98793958c9STaylor Simpson gen_helper_prototype(f, tag, tagregs, tagimms) 99793958c9STaylor Simpson 1005bb322e2SMarco Liebel 101793958c9STaylor Simpsonif __name__ == "__main__": 102793958c9STaylor Simpson main() 103