]>
git.proxmox.com Git - mirror_qemu.git/blob - target/hexagon/gen_helper_protos.py
4 ## Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
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.
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.
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/>.
26 ## Helpers for gen_helper_prototype
39 def_helper_types_pair
= {
48 def gen_def_helper_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
):
49 if (hex_common
.is_pair(regid
)):
50 f
.write(", %s" % (def_helper_types_pair
[regtype
]))
51 elif (hex_common
.is_single(regid
)):
52 f
.write(", %s" % (def_helper_types
[regtype
]))
54 print("Bad register parse: ",regtype
,regid
,toss
,numregs
)
57 ## Generate the DEF_HELPER prototype for an instruction
58 ## For A2_add: Rd32=add(Rs32,Rt32)
60 ## DEF_HELPER_3(A2_add, s32, env, s32, s32)
62 def gen_helper_prototype(f
, tag
, tagregs
, tagimms
):
68 numscalarreadwrite
= 0
69 for regtype
,regid
,toss
,numregs
in regs
:
70 if (hex_common
.is_written(regid
)):
72 if (hex_common
.is_scalar_reg(regtype
)):
74 if (hex_common
.is_readwrite(regid
)):
75 if (hex_common
.is_scalar_reg(regtype
)):
76 numscalarreadwrite
+= 1
78 if (numscalarresults
> 1):
79 ## The helper is bogus when there is more than one result
80 f
.write('DEF_HELPER_1(%s, void, env)\n' % tag
)
82 ## Figure out how many arguments the helper will take
83 if (numscalarresults
== 0):
84 def_helper_size
= len(regs
)+len(imms
)+numscalarreadwrite
+1
85 if hex_common
.need_pkt_has_multi_cof(tag
): def_helper_size
+= 1
86 if hex_common
.need_part1(tag
): def_helper_size
+= 1
87 if hex_common
.need_slot(tag
): def_helper_size
+= 1
88 if hex_common
.need_PC(tag
): def_helper_size
+= 1
89 if hex_common
.helper_needs_next_PC(tag
): def_helper_size
+= 1
90 if hex_common
.need_condexec_reg(tag
, regs
): def_helper_size
+= 1
91 f
.write('DEF_HELPER_%s(%s' % (def_helper_size
, tag
))
92 ## The return type is void
95 def_helper_size
= len(regs
)+len(imms
)+numscalarreadwrite
96 if hex_common
.need_pkt_has_multi_cof(tag
): def_helper_size
+= 1
97 if hex_common
.need_part1(tag
): def_helper_size
+= 1
98 if hex_common
.need_slot(tag
): def_helper_size
+= 1
99 if hex_common
.need_PC(tag
): def_helper_size
+= 1
100 if hex_common
.need_condexec_reg(tag
, regs
): def_helper_size
+= 1
101 if hex_common
.helper_needs_next_PC(tag
): def_helper_size
+= 1
102 f
.write('DEF_HELPER_%s(%s' % (def_helper_size
, tag
))
104 ## Generate the qemu DEF_HELPER type for each result
105 ## Iterate over this list twice
106 ## - Emit the scalar result
107 ## - Emit the vector result
109 for regtype
,regid
,toss
,numregs
in regs
:
110 if (hex_common
.is_written(regid
)):
111 if (not hex_common
.is_hvx_reg(regtype
)):
112 gen_def_helper_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
)
115 ## Put the env between the outputs and inputs
120 for regtype
,regid
,toss
,numregs
in regs
:
121 if (hex_common
.is_written(regid
)):
122 if (hex_common
.is_hvx_reg(regtype
)):
123 gen_def_helper_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
)
126 ## For conditional instructions, we pass in the destination register
127 if 'A_CONDEXEC' in hex_common
.attribdict
[tag
]:
128 for regtype
, regid
, toss
, numregs
in regs
:
129 if (hex_common
.is_writeonly(regid
) and
130 not hex_common
.is_hvx_reg(regtype
)):
131 gen_def_helper_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
)
134 ## Generate the qemu type for each input operand (regs and immediates)
135 for regtype
,regid
,toss
,numregs
in regs
:
136 if (hex_common
.is_read(regid
)):
137 if (hex_common
.is_hvx_reg(regtype
) and
138 hex_common
.is_readwrite(regid
)):
140 gen_def_helper_opn(f
, tag
, regtype
, regid
, toss
, numregs
, i
)
142 for immlett
,bits
,immshift
in imms
:
145 ## Add the arguments for the instruction pkt_has_multi_cof, slot and
147 if hex_common
.need_pkt_has_multi_cof(tag
): f
.write(', i32')
148 if hex_common
.need_PC(tag
): f
.write(', i32')
149 if hex_common
.helper_needs_next_PC(tag
): f
.write(', i32')
150 if hex_common
.need_slot(tag
): f
.write(', i32' )
151 if hex_common
.need_part1(tag
): f
.write(' , i32' )
155 hex_common
.read_semantics_file(sys
.argv
[1])
156 hex_common
.read_attribs_file(sys
.argv
[2])
157 hex_common
.read_overrides_file(sys
.argv
[3])
158 hex_common
.read_overrides_file(sys
.argv
[4])
159 ## Whether or not idef-parser is enabled is
160 ## determined by the number of arguments to
163 ## 5 args. -> not enabled,
164 ## 6 args. -> idef-parser enabled.
166 ## The 6:th arg. then holds a list of the successfully
167 ## parsed instructions.
168 is_idef_parser_enabled
= len(sys
.argv
) > 6
169 if is_idef_parser_enabled
:
170 hex_common
.read_idef_parser_enabled_file(sys
.argv
[5])
171 hex_common
.calculate_attribs()
172 tagregs
= hex_common
.get_tagregs()
173 tagimms
= hex_common
.get_tagimms()
175 output_file
= sys
.argv
[-1]
176 with
open(output_file
, 'w') as f
:
177 for tag
in hex_common
.tags
:
178 ## Skip the priv instructions
179 if ( "A_PRIV" in hex_common
.attribdict
[tag
] ) :
181 ## Skip the guest instructions
182 if ( "A_GUEST" in hex_common
.attribdict
[tag
] ) :
184 ## Skip the diag instructions
185 if ( tag
== "Y6_diag" ) :
187 if ( tag
== "Y6_diag0" ) :
189 if ( tag
== "Y6_diag1" ) :
192 if ( hex_common
.skip_qemu_helper(tag
) ):
194 if ( hex_common
.is_idef_parser_enabled(tag
) ):
197 gen_helper_prototype(f
, tag
, tagregs
, tagimms
)
199 if __name__
== "__main__":