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(): 55*a4696661STaylor Simpson hex_common.read_common_files() 56793958c9STaylor Simpson tagregs = hex_common.get_tagregs() 57793958c9STaylor Simpson tagimms = hex_common.get_tagimms() 58793958c9STaylor Simpson 59e71fdc4fSAlessandro Di Federico output_file = sys.argv[-1] 605bb322e2SMarco Liebel with open(output_file, "w") as f: 61793958c9STaylor Simpson for tag in hex_common.tags: 62793958c9STaylor Simpson ## Skip the priv instructions 635bb322e2SMarco Liebel if "A_PRIV" in hex_common.attribdict[tag]: 64793958c9STaylor Simpson continue 65793958c9STaylor Simpson ## Skip the guest instructions 665bb322e2SMarco Liebel if "A_GUEST" in hex_common.attribdict[tag]: 67793958c9STaylor Simpson continue 68793958c9STaylor Simpson ## Skip the diag instructions 695bb322e2SMarco Liebel if tag == "Y6_diag": 70793958c9STaylor Simpson continue 715bb322e2SMarco Liebel if tag == "Y6_diag0": 72793958c9STaylor Simpson continue 735bb322e2SMarco Liebel if tag == "Y6_diag1": 74793958c9STaylor Simpson continue 75793958c9STaylor Simpson 765bb322e2SMarco Liebel if hex_common.skip_qemu_helper(tag): 77793958c9STaylor Simpson continue 785bb322e2SMarco Liebel if hex_common.is_idef_parser_enabled(tag): 79e71fdc4fSAlessandro Di Federico continue 80793958c9STaylor Simpson 81793958c9STaylor Simpson gen_helper_prototype(f, tag, tagregs, tagimms) 82793958c9STaylor Simpson 835bb322e2SMarco Liebel 84793958c9STaylor Simpsonif __name__ == "__main__": 85793958c9STaylor Simpson main() 86