1793958c9STaylor Simpson#!/usr/bin/env python3 2793958c9STaylor Simpson 3793958c9STaylor Simpson## 4e28b77a6STaylor Simpson## Copyright(c) 2019-2023 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 35*c568919fSTaylor Simpson declared = [] 36*c568919fSTaylor Simpson ret_type = hex_common.helper_ret_type(tag, regs).proto_arg 37*c568919fSTaylor Simpson declared.append(ret_type) 38793958c9STaylor Simpson 39*c568919fSTaylor Simpson for arg in hex_common.helper_args(tag, regs, imms): 40*c568919fSTaylor Simpson declared.append(arg.proto_arg) 41793958c9STaylor Simpson 42*c568919fSTaylor Simpson arguments = ", ".join(declared) 43*c568919fSTaylor Simpson f.write(f"DEF_HELPER_{len(declared) - 1}({tag}, {arguments})\n") 445bb322e2SMarco Liebel 45793958c9STaylor Simpson 46793958c9STaylor Simpsondef main(): 47793958c9STaylor Simpson hex_common.read_semantics_file(sys.argv[1]) 48793958c9STaylor Simpson hex_common.read_attribs_file(sys.argv[2]) 49793958c9STaylor Simpson hex_common.read_overrides_file(sys.argv[3]) 50d51bcabeSTaylor Simpson hex_common.read_overrides_file(sys.argv[4]) 51e71fdc4fSAlessandro Di Federico ## Whether or not idef-parser is enabled is 52e71fdc4fSAlessandro Di Federico ## determined by the number of arguments to 53e71fdc4fSAlessandro Di Federico ## this script: 54e71fdc4fSAlessandro Di Federico ## 55e71fdc4fSAlessandro Di Federico ## 5 args. -> not enabled, 56e71fdc4fSAlessandro Di Federico ## 6 args. -> idef-parser enabled. 57e71fdc4fSAlessandro Di Federico ## 58e71fdc4fSAlessandro Di Federico ## The 6:th arg. then holds a list of the successfully 59e71fdc4fSAlessandro Di Federico ## parsed instructions. 60e71fdc4fSAlessandro Di Federico is_idef_parser_enabled = len(sys.argv) > 6 61e71fdc4fSAlessandro Di Federico if is_idef_parser_enabled: 62e71fdc4fSAlessandro Di Federico hex_common.read_idef_parser_enabled_file(sys.argv[5]) 63793958c9STaylor Simpson hex_common.calculate_attribs() 64*c568919fSTaylor Simpson hex_common.init_registers() 65793958c9STaylor Simpson tagregs = hex_common.get_tagregs() 66793958c9STaylor Simpson tagimms = hex_common.get_tagimms() 67793958c9STaylor Simpson 68e71fdc4fSAlessandro Di Federico output_file = sys.argv[-1] 695bb322e2SMarco Liebel with open(output_file, "w") as f: 70793958c9STaylor Simpson for tag in hex_common.tags: 71793958c9STaylor Simpson ## Skip the priv instructions 725bb322e2SMarco Liebel if "A_PRIV" in hex_common.attribdict[tag]: 73793958c9STaylor Simpson continue 74793958c9STaylor Simpson ## Skip the guest instructions 755bb322e2SMarco Liebel if "A_GUEST" in hex_common.attribdict[tag]: 76793958c9STaylor Simpson continue 77793958c9STaylor Simpson ## Skip the diag instructions 785bb322e2SMarco Liebel if tag == "Y6_diag": 79793958c9STaylor Simpson continue 805bb322e2SMarco Liebel if tag == "Y6_diag0": 81793958c9STaylor Simpson continue 825bb322e2SMarco Liebel if tag == "Y6_diag1": 83793958c9STaylor Simpson continue 84793958c9STaylor Simpson 855bb322e2SMarco Liebel if hex_common.skip_qemu_helper(tag): 86793958c9STaylor Simpson continue 875bb322e2SMarco Liebel if hex_common.is_idef_parser_enabled(tag): 88e71fdc4fSAlessandro Di Federico continue 89793958c9STaylor Simpson 90793958c9STaylor Simpson gen_helper_prototype(f, tag, tagregs, tagimms) 91793958c9STaylor Simpson 925bb322e2SMarco Liebel 93793958c9STaylor Simpsonif __name__ == "__main__": 94793958c9STaylor Simpson main() 95