1 |
6 |
jlechner |
; Instruction fields.
|
2 |
|
|
; Copyright (C) 2000, 2002, 2009 Red Hat, Inc.
|
3 |
|
|
; This file is part of CGEN.
|
4 |
|
|
; See file COPYING.CGEN for details.
|
5 |
|
|
|
6 |
|
|
; (pronounced "I-field")
|
7 |
|
|
;
|
8 |
|
|
; These describe raw data, little semantic content is attributed to them.
|
9 |
|
|
; The goal being to avoid interfering with future applications.
|
10 |
|
|
;
|
11 |
|
|
; FIXME: Move start, word-offset, word-length into the instruction format?
|
12 |
|
|
; - would require proper ordering of fields in insns, but that's ok.
|
13 |
|
|
; (??? though the sparc64 description shows a case where its useful to
|
14 |
|
|
; not have to worry about instruction ordering - different versions of an
|
15 |
|
|
; insn take different fields and these fields are passed via a macro)
|
16 |
|
|
;
|
17 |
|
|
; ??? One could treat all ifields as being unsigned. They could be thought of
|
18 |
|
|
; as indices into a table of values, be they signed, unsigned, floating point,
|
19 |
|
|
; whatever. Just an idea.
|
20 |
|
|
;
|
21 |
|
|
; ??? Split into two? One for definition, and one for value.
|
22 |
|
|
; The mode the raw value is to be interpreted in.
|
23 |
|
|
|
24 |
|
|
; This contains the field's offset, start, length, word-length,
|
25 |
|
|
; and orientation (msb==0, lsb==0). The orientation is
|
26 |
|
|
; recorded to keep the <bitrange> object self-contained.
|
27 |
|
|
; Endianness is not recorded.
|
28 |
|
|
; Argument to :follows, as an object.
|
29 |
|
|
; FIXME: wip
|
30 |
|
|
|
31 |
|
|
; save `pc' and mode of field.
|
32 |
|
|
; If #f, no special processing is required.
|
33 |
|
|
; ??? It's not clear where the best place to process fields is.
|
34 |
|
|
; An earlier version had insert/extract fields in operands to
|
35 |
|
|
; handle more complicated cases. Following the goal of
|
36 |
|
|
; incremental complication, the special handling for m32r's
|
37 |
|
|
|
38 |
|
|
; here and partially in the operand.
|
39 |
|
|
; Value of field, if there is one.
|
40 |
|
|
; Possible types are: integer, <operand>, ???
|
41 |
|
|
|
42 |
|
|
; {value},{follows} are missing on purpose.
|
43 |
|
|
; {value} is handled specially.
|
44 |
|
|
; {follows} is rarely used
|
45 |
|
|
; Accessor fns
|
46 |
|
|
; ??? `value' is treated specially, needed anymore?
|
47 |
|
|
; internal fn
|
48 |
|
|
; Return the mode of the value passed to the encode rtl.
|
49 |
|
|
; This is the mode of the result of the decode rtl.
|
50 |
|
|
; cadr/cadr gets WI in ((value pc) (sra WI ...))
|
51 |
|
|
; FIXME: That's wrong for a fully canonical expression like
|
52 |
|
|
|
53 |
|
|
; Return the mode of the value passed to the decode rtl.
|
54 |
|
|
; This is the mode of the field.
|
55 |
|
|
; Return start of ifield.
|
56 |
|
|
; FIXME: It might make things more "readable" if enum values were preserved in
|
57 |
|
|
; their symbolic form and the get-field-value method did the lookup.
|
58 |
|
|
; Return a boolean indicating if X is an <ifield>.
|
59 |
|
|
|
60 |
|
|
; ("ilk" sounds klunky but "type" is too ambiguous. Here "ilk" means
|
61 |
|
|
; the kind of the hardware element, enum, etc.)
|
62 |
|
|
; The result is a character string naming the field type.
|
63 |
|
|
; ??? One could require that the `value' field always be an object.
|
64 |
|
|
; I can't get too worked up over it yet.
|
65 |
|
|
; send 'get-name to fetch the name
|
66 |
|
|
|
67 |
|
|
; Generate the name of the enum for instruction field ifld.
|
68 |
|
|
; If PREFIX? is present and #f, the @ARCH@_ prefix is omitted.
|
69 |
|
|
|
70 |
|
|
; (has a constant value).
|
71 |
|
|
|
72 |
|
|
; (if option:reserved-as-opcode?
|
73 |
|
|
|
74 |
|
|
; (not (has-attr? f 'RESERVED))))
|
75 |
|
|
; Return a boolean indicating if ifield F is an operand.
|
76 |
|
|
|
77 |
|
|
; Return known value table for rtx-simplify of <ifield> list ifld-list.
|
78 |
|
|
; Return mask to use for a field in <bitrange> CONTAINER.
|
79 |
|
|
|
80 |
|
|
; If CONTAINER is #f, use the recorded bitrange.
|
81 |
|
|
; BASE-LEN, if non-#f, overrides the base insn length of the insn.
|
82 |
|
|
|
83 |
|
|
; smaller than the base insn size (LIW).
|
84 |
|
|
;
|
85 |
|
|
; Simplifying restrictions [to be relaxed as necessary]:
|
86 |
|
|
; - the field must either be totally contained within CONTAINER or totally
|
87 |
|
|
; outside it, partial overlaps aren't handled
|
88 |
|
|
; - CONTAINER must be an integral number of bytes, beginning on a
|
89 |
|
|
; byte boundary [simplifies things]
|
90 |
|
|
; - both SELF's bitrange and CONTAINER must have the same word length
|
91 |
|
|
|
92 |
|
|
; must be same lsb0
|
93 |
|
|
"field-mask: different lsb0? values"; container occurs after?
|
94 |
|
|
|
95 |
|
|
; Return VALUE inserted into the field's position.
|
96 |
|
|
|
97 |
|
|
; BASE-LEN is present for architectures like the m32r where there are insns
|
98 |
|
|
|
99 |
|
|
; FIXME: confusion with ifld-get-value.
|
100 |
|
|
; Return a list of ifields required to compute <ifield> F's value.
|
101 |
|
|
; Normally this is just F itself. For multi-ifields it will be more.
|
102 |
|
|
; ??? It can also be more if F's value is derived from other fields but
|
103 |
|
|
; that isn't supported yet.
|
104 |
|
|
|
105 |
|
|
; VALUE is the entire insn's value if it fits in a word, or is a list
|
106 |
|
|
; of values, one per word (not implemented, sigh).
|
107 |
|
|
; ??? The instruction's format should specify where the word boundaries are.
|
108 |
|
|
|
109 |
|
|
; Return a boolean indicating if bit 0 is the least significant bit.
|
110 |
|
|
; Return the minimum value of a field.
|
111 |
|
|
"unsupported mode class"; Return the maximum value of a field.
|
112 |
|
|
"unsupported mode class"; Create a copy of field F with value VALUE.
|
113 |
|
|
; VALUE is either ... ???
|
114 |
|
|
|
115 |
|
|
; Return a copy of F with new {word-offset}.
|
116 |
|
|
|
117 |
|
|
; What a `word' here is defined by F in its bitrange.
|
118 |
|
|
; Return a boolean indicating if <ifield> F1 precedes <ifield> F2.
|
119 |
|
|
|
120 |
|
|
; different handling.
|
121 |
|
|
; ??? revisit
|
122 |
|
|
; Parse an ifield definition.
|
123 |
|
|
; This is the main routine for building an ifield object from a
|
124 |
|
|
; description in the .cpu file.
|
125 |
|
|
; All arguments are in raw (non-evaluated) form.
|
126 |
|
|
; The result is the parsed object or #f if object isn't for selected mach(s).
|
127 |
|
|
;
|
128 |
|
|
; Two forms of specification are supported, loosely defined as the RISC way
|
129 |
|
|
; and the CISC way. The reason for the distinction is to simplify ifield
|
130 |
|
|
; specification of RISC-like cpus.
|
131 |
|
|
; Note that VLIW's are another way. These are handled like the RISC way, with
|
132 |
|
|
; the possible addition of instruction framing (which is, surprise surprise,
|
133 |
|
|
; wip).
|
134 |
|
|
;
|
135 |
|
|
; RISC:
|
136 |
|
|
|
137 |
|
|
; (isa-default-insn-word-bitsize). WORD-OFFSET is computed from START.
|
138 |
|
|
|
139 |
|
|
; FLENGTH is the length of the field in bits.
|
140 |
|
|
|
141 |
|
|
; CISC:
|
142 |
|
|
; WORD-OFFSET is the offset in bits from the start to the first byte of the
|
143 |
|
|
; word containing the ifield.
|
144 |
|
|
; WORD-LENGTH is the length in bits of the word containing the ifield.
|
145 |
|
|
|
146 |
|
|
; (current-arch-insn-lsb0?).
|
147 |
|
|
; FLENGTH is the length in bits of the ifield. It is named that way to avoid
|
148 |
|
|
; collision with the proc named `length'.
|
149 |
|
|
;
|
150 |
|
|
; FIXME: More error checking.
|
151 |
|
|
"Processing ifield "" ...\n";; Pick out name first to augment the error context.
|
152 |
|
|
"cgen_ifld"; No longer ensure only one isa specified.
|
153 |
|
|
;(if (!= (length isas) 1)
|
154 |
|
|
|
155 |
|
|
"either both or neither of word-offset,word-length can be specified"; ??? 0.127 for now
|
156 |
|
|
; ??? 0.127 for now
|
157 |
|
|
|
158 |
|
|
; ??? Move positional info to format?
|
159 |
|
|
; CISC-like. Easy. Everything must be specified.
|
160 |
|
|
; RISC-like. Hard. Have to make best choice of start,
|
161 |
|
|
; flength. This doesn't have to be perfect, just easily
|
162 |
|
|
; explainable. Cases this doesn't handle can explicitly
|
163 |
|
|
; specify word-offset,word-length.
|
164 |
|
|
|
165 |
|
|
; "RISC-like" is inaccurate. Perhaps.
|
166 |
|
|
; Else ignore entry.
|
167 |
|
|
|
168 |
|
|
; Given START,FLENGTH, return the "best" choice for the offset to the word
|
169 |
|
|
; containing the ifield.
|
170 |
|
|
; This is easy to visualize, hard to put into words.
|
171 |
|
|
; Imagine several words of size DIWB laid out from the start of the insn.
|
172 |
|
|
; On top of that lay the ifield.
|
173 |
|
|
; Now pick the minimal set of words that are required to contain the ifield.
|
174 |
|
|
; That's what we want.
|
175 |
|
|
|
176 |
|
|
; particular architecture. For those where this isn't correct, the ifield
|
177 |
|
|
; must be fully specified (i.e. word-offset,word-length explicitly specified).
|
178 |
|
|
|
179 |
|
|
; NOTE: The conversion is seemingly wrong because `start' is misnamed.
|
180 |
|
|
|
181 |
|
|
; Subroutine of -ifield-parse to simplify it.
|
182 |
|
|
|
183 |
|
|
; containing the ifield.
|
184 |
|
|
; DIWB = default insn word bitsize
|
185 |
|
|
; See -get-ifld-word-offset for more info.
|
186 |
|
|
; Convert to non-lsb0 case, then it's easy.
|
187 |
|
|
; NOTE: The conversion is seemingly wrong because `start' is misnamed.
|
188 |
|
|
; It's now `end'.
|
189 |
|
|
; Read an instruction field description.
|
190 |
|
|
|
191 |
|
|
; CONTEXT is a <context> object for error messages.
|
192 |
|
|
; ARG-LIST is an associative list of field name and field value.
|
193 |
|
|
; -ifield-parse is invoked to create the <ifield> object.
|
194 |
|
|
""; FIXME: Hobbit computes the wrong symbol for `length'
|
195 |
|
|
; in the `case' expression below because there is a local var
|
196 |
|
|
; of the same name ("__1" gets appended to the symbol name).
|
197 |
|
|
; As a workaround we name it "length-".
|
198 |
|
|
; Loop over each element in ARG-LIST, recording what's found.
|
199 |
|
|
"invalid ifield arg"; See if encode/decode were specified as "unspecified".
|
200 |
|
|
; This happens with shorthand macros.
|
201 |
|
|
; Now that we've identified the elements, build the object.
|
202 |
|
|
; Parse a `follows' spec.
|
203 |
|
|
"unknown operand to follow"; Do common parts of <ifield> encode/decode processing.
|
204 |
|
|
"bad ifield "" spec"" expression must have a mode"; Parse an <ifield> encode spec.
|
205 |
|
|
|
206 |
|
|
"decode"; Define an instruction field object, name/value pair list version.
|
207 |
|
|
"define-ifield"; Define an instruction field object, all arguments specified.
|
208 |
|
|
; ??? Leave out word-offset,word-length,follows for now (RISC version).
|
209 |
|
|
; FIXME: Eventually this should be fixed to take *all* arguments.
|
210 |
|
|
"define-full-ifield""\
|
211 |
|
|
Define an instruction field, name/value pair list version.
|
212 |
|
|
""\
|
213 |
|
|
Define an instruction field, all arguments specified.
|
214 |
|
|
""\
|
215 |
|
|
Define an instruction multi-field, name/value pair list version.
|
216 |
|
|
""\
|
217 |
|
|
Define an instruction multi-field, all arguments specified.
|
218 |
|
|
"; Instruction fields consisting of multiple parts.
|
219 |
|
|
; List of <ifield> objects.
|
220 |
|
|
; rtl to set SUBFIELDS from self
|
221 |
|
|
; rtl to set self from SUBFIELDS
|
222 |
|
|
; Accessors
|
223 |
|
|
; Return a boolean indicating if X is an <ifield>.
|
224 |
|
|
; Return the starting bit number of the first field.
|
225 |
|
|
; Return the total length.
|
226 |
|
|
; Return the bit offset of the word after the last word SELF is in.
|
227 |
|
|
; What a `word' here is defined by subfields in their bitranges.
|
228 |
|
|
; Return mask of field in bitrange CONTAINER.
|
229 |
|
|
; Return VALUE inserted into the field's position.
|
230 |
|
|
; The value is spread out over the various subfields in sorted order.
|
231 |
|
|
; We assume the subfields have been sorted by starting bit position.
|
232 |
|
|
; Return a list of ifields required to compute the field's value.
|
233 |
|
|
; Extract <ifield> IFLD's value out of VALUE in <insn> INSN.
|
234 |
|
|
; VALUE is the entire insn's value if it fits in a word, or is a list
|
235 |
|
|
|
236 |
|
|
; ??? The instruction's format should specify where the word boundaries are.
|
237 |
|
|
; We have each subfield's value, now concatenate them.
|
238 |
|
|
; do the -1 drop here as it's easier
|
239 |
|
|
|
240 |
|
|
; Multi-ifield parsing.
|
241 |
|
|
; Subroutine of -multi-ifield-parse to build the default insert expression.
|
242 |
|
|
; Build RTL expression to shift and mask each ifield into right spot.
|
243 |
|
|
; Now set each ifield with their respective values.
|
244 |
|
|
|
245 |
|
|
; Build RTL expression to shift and mask each ifield into right spot.
|
246 |
|
|
; Now set {container-name} with all the values or'd together.
|
247 |
|
|
; Parse a multi-ifield spec.
|
248 |
|
|
; This is the main routine for building the object from the .cpu file.
|
249 |
|
|
; All arguments are in raw (non-evaluated) form.
|
250 |
|
|
; The result is the parsed object or #f if object isn't for selected mach(s).
|
251 |
|
|
"Processing multi-ifield element "" ...\n""empty subfield list";; Pick out name first to augment the error context.
|
252 |
|
|
"cgen_ifld"; No longer ensure only one isa specified.
|
253 |
|
|
; (if (!= (length isas) 1)
|
254 |
|
|
; (parse-error context "can only specify 1 isa" attrs))
|
255 |
|
|
"unknown ifield";; multi-ifields are always VIRTUAL
|
256 |
|
|
"multi-ifield"; else don't keep isa
|
257 |
|
|
; Read an instruction multi-ifield.
|
258 |
|
|
; This is the main routine for analyzing multi-ifields in the .cpu file.
|
259 |
|
|
|
260 |
|
|
; ARG-LIST is an associative list of field name and field value.
|
261 |
|
|
; -multi-ifield-parse is invoked to create the `multi-ifield' object.
|
262 |
|
|
""; Loop over each element in ARG-LIST, recording what's found.
|
263 |
|
|
"invalid ifield arg"; Now that we've identified the elements, build the object.
|
264 |
|
|
|
265 |
|
|
"define-multi-ifield"; Define an instruction multi-field object, all arguments specified.
|
266 |
|
|
; FIXME: encode/decode arguments are missing.
|
267 |
|
|
"define-full-multi-ifield"; Derived ifields (ifields based on one or more other ifields).
|
268 |
|
|
; These support the complicated requirements of CISC instructions
|
269 |
|
|
|
270 |
|
|
; which can consist of several ifields.
|
271 |
|
|
; These are also intended to support other complex ifield usage.
|
272 |
|
|
;
|
273 |
|
|
; Derived ifields are (currently) always machine generated from other
|
274 |
|
|
; elements of the description file so there is no reader support.
|
275 |
|
|
|
276 |
|
|
; ??? experimental and wip!
|
277 |
|
|
; ??? These are kind of like multi-ifields but I don't want to disturb them
|
278 |
|
|
; while this is still experimental.
|
279 |
|
|
|
280 |
|
|
; Unlike other ifields, derived ifields have a one-to-one
|
281 |
|
|
; correspondence with the operand that uses them.
|
282 |
|
|
; ??? Not true in -anyof-merge-subchoices.
|
283 |
|
|
; List of ifields that make up this ifield.
|
284 |
|
|
|
285 |
|
|
; Return a boolean indicating if F is a derived ifield with a derived operand
|
286 |
|
|
; for a value.
|
287 |
|
|
; ??? The former might imply the latter so some simplification may be possible.
|
288 |
|
|
; Return the bit offset of the word after the last word SELF is in.
|
289 |
|
|
; What a `word' here is defined by subfields in their bitranges.
|
290 |
|
|
; Traverse the ifield to collect all base (non-derived) ifields used in it.
|
291 |
|
|
; ((multi-ifield? ifld) (collect (lambda (subfield) (ifld-base-ifields subfield))
|
292 |
|
|
; (multi-ifld-subfields ifld)))
|
293 |
|
|
; Misc. utilities.
|
294 |
|
|
; Sort a list of fields (sorted by the starting bit number).
|
295 |
|
|
; This must be carefully defined to pass through Hobbit.
|
296 |
|
|
|
297 |
|
|
; (if x (define foo bar) (define foo baz)) is not ok.
|
298 |
|
|
;
|
299 |
|
|
; ??? Usually there aren't that many fields and the range of values is fixed,
|
300 |
|
|
|
301 |
|
|
; an issue).
|
302 |
|
|
|
303 |
|
|
; old way
|
304 |
|
|
;(< base-bitsize (+ (ifld-start f total-bitsize) (ifld-length f)))
|
305 |
|
|
; Return the mode of the decoded value of <ifield> F.
|
306 |
|
|
; ??? This is made easy because we require the decode expression to have
|
307 |
|
|
; an explicit mode.
|
308 |
|
|
|
309 |
|
|
; i.e. one of h-uint, h-sint.
|
310 |
|
|
|
311 |
|
|
"unsupported mode class"; Builtin fields, attributes, init/fini support.
|
312 |
|
|
|
313 |
|
|
; elements that aren't indexed by an instruction field (scalars).
|
314 |
|
|
; The f-anyof field is a placeholder when building "anyof" operands.
|
315 |
|
|
; Return a boolean indicating if F is an anyof ifield with an anyof operand
|
316 |
|
|
; for a value.
|
317 |
|
|
; ??? The former implies the latter so some simplification is possible.
|
318 |
|
|
; Called before loading the .cpu file to initialize.
|
319 |
|
|
; Called before loading the .cpu file to create any builtins.
|
320 |
|
|
; Standard ifield attributes.
|
321 |
|
|
|
322 |
|
|
; work with.
|
323 |
|
|
|
324 |
|
|
; To be revisited.
|
325 |
|
|
"value is unsigned"; Also (defined elsewhere): VIRTUAL
|
326 |
|
|
"empty ifield"; encode/decode
|
327 |
|
|
"placeholder for anyof operands"; encode/decode
|
328 |
|
|
; Called after the .cpu file has been read in.
|
329 |
|
|
|