Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | ## |
Taylor Simpson | 2f0a771 | 2024-02-13 21:27:26 -0700 | [diff] [blame] | 4 | ## Copyright(c) 2019-2024 Qualcomm Innovation Center, Inc. All Rights Reserved. |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 5 | ## |
| 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 | |
| 20 | import sys |
| 21 | import re |
| 22 | import string |
| 23 | import hex_common |
| 24 | |
| 25 | ## |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 26 | ## Generate the DEF_HELPER prototype for an instruction |
| 27 | ## For A2_add: Rd32=add(Rs32,Rt32) |
| 28 | ## We produce: |
| 29 | ## DEF_HELPER_3(A2_add, s32, env, s32, s32) |
| 30 | ## |
| 31 | def gen_helper_prototype(f, tag, tagregs, tagimms): |
| 32 | regs = tagregs[tag] |
| 33 | imms = tagimms[tag] |
| 34 | |
Taylor Simpson | c568919 | 2023-12-10 15:07:06 -0700 | [diff] [blame] | 35 | declared = [] |
| 36 | ret_type = hex_common.helper_ret_type(tag, regs).proto_arg |
| 37 | declared.append(ret_type) |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 38 | |
Taylor Simpson | c568919 | 2023-12-10 15:07:06 -0700 | [diff] [blame] | 39 | for arg in hex_common.helper_args(tag, regs, imms): |
| 40 | declared.append(arg.proto_arg) |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 41 | |
Taylor Simpson | c568919 | 2023-12-10 15:07:06 -0700 | [diff] [blame] | 42 | arguments = ", ".join(declared) |
Taylor Simpson | 2f0a771 | 2024-02-13 21:27:26 -0700 | [diff] [blame] | 43 | |
| 44 | ## Add the TCG_CALL_NO_RWG_SE flag to helpers that don't take the env |
| 45 | ## argument and aren't HVX instructions. Since HVX instructions take |
| 46 | ## pointers to their arguments, they will have side effects. |
| 47 | if hex_common.need_env(tag) or hex_common.is_hvx_insn(tag): |
| 48 | f.write(f"DEF_HELPER_{len(declared) - 1}({tag}, {arguments})\n") |
| 49 | else: |
| 50 | f.write(f"DEF_HELPER_FLAGS_{len(declared) - 1}({tag}, " |
| 51 | f"TCG_CALL_NO_RWG_SE, {arguments})\n") |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 52 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 53 | |
| 54 | def main(): |
Taylor Simpson | a469666 | 2024-03-06 20:23:27 -0700 | [diff] [blame] | 55 | hex_common.read_common_files() |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 56 | tagregs = hex_common.get_tagregs() |
| 57 | tagimms = hex_common.get_tagimms() |
| 58 | |
Alessandro Di Federico | e71fdc4 | 2022-09-23 19:38:30 +0200 | [diff] [blame] | 59 | output_file = sys.argv[-1] |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 60 | with open(output_file, "w") as f: |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 61 | for tag in hex_common.tags: |
| 62 | ## Skip the priv instructions |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 63 | if "A_PRIV" in hex_common.attribdict[tag]: |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 64 | continue |
| 65 | ## Skip the guest instructions |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 66 | if "A_GUEST" in hex_common.attribdict[tag]: |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 67 | continue |
| 68 | ## Skip the diag instructions |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 69 | if tag == "Y6_diag": |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 70 | continue |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 71 | if tag == "Y6_diag0": |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 72 | continue |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 73 | if tag == "Y6_diag1": |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 74 | continue |
| 75 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 76 | if hex_common.skip_qemu_helper(tag): |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 77 | continue |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 78 | if hex_common.is_idef_parser_enabled(tag): |
Alessandro Di Federico | e71fdc4 | 2022-09-23 19:38:30 +0200 | [diff] [blame] | 79 | continue |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 80 | |
| 81 | gen_helper_prototype(f, tag, tagregs, tagimms) |
| 82 | |
Marco Liebel | 5bb322e | 2023-03-20 02:25:33 -0700 | [diff] [blame] | 83 | |
Taylor Simpson | 793958c | 2021-02-07 23:46:10 -0600 | [diff] [blame] | 84 | if __name__ == "__main__": |
| 85 | main() |