URL
https://opencores.org/ocsvn/scarts/scarts/trunk
Subversion Repositories scarts
[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [ifield.scm] - Rev 6
Compare with Previous | Blame | View Log
; Instruction fields. ; Copyright (C) 2000, 2002, 2009 Red Hat, Inc. ; This file is part of CGEN. ; See file COPYING.CGEN for details. ; The `<ifield>' class. ; (pronounced "I-field") ; ; These describe raw data, little semantic content is attributed to them. ; The goal being to avoid interfering with future applications. ; ; FIXME: Move start, word-offset, word-length into the instruction format? ; - would require proper ordering of fields in insns, but that's ok. ; (??? though the sparc64 description shows a case where its useful to ; not have to worry about instruction ordering - different versions of an ; insn take different fields and these fields are passed via a macro) ; ; ??? One could treat all ifields as being unsigned. They could be thought of ; as indices into a table of values, be they signed, unsigned, floating point, ; whatever. Just an idea. ; ; ??? Split into two? One for definition, and one for value. ; The mode the raw value is to be interpreted in. ; A <bitrange> object. ; This contains the field's offset, start, length, word-length, ; and orientation (msb==0, lsb==0). The orientation is ; recorded to keep the <bitrange> object self-contained. ; Endianness is not recorded. ; Argument to :follows, as an object. ; FIXME: wip ; ENCODE/DECODE operate on the raw value, absent of any context ; save `pc' and mode of field. ; If #f, no special processing is required. ; ??? It's not clear where the best place to process fields is. ; An earlier version had insert/extract fields in operands to ; handle more complicated cases. Following the goal of ; incremental complication, the special handling for m32r's ; f-disp8 field is handled entirely here, rather than partially ; here and partially in the operand. ; Value of field, if there is one. ; Possible types are: integer, <operand>, ??? ; {ordinal} is missing on purpose, it's handled at a higher level. ; {value},{follows} are missing on purpose. ; {value} is handled specially. ; {follows} is rarely used ; Accessor fns ; ??? `value' is treated specially, needed anymore? ; internal fn ; Return the mode of the value passed to the encode rtl. ; This is the mode of the result of the decode rtl. ; cadr/cadr gets WI in ((value pc) (sra WI ...)) ; FIXME: That's wrong for a fully canonical expression like ; ((value pc) (sra () WI ...)). ; Return the mode of the value passed to the decode rtl. ; This is the mode of the field. ; Return start of ifield. ; FIXME: It might make things more "readable" if enum values were preserved in ; their symbolic form and the get-field-value method did the lookup. ; Return a boolean indicating if X is an <ifield>. ; Return ilk of field as a string. ; ("ilk" sounds klunky but "type" is too ambiguous. Here "ilk" means ; the kind of the hardware element, enum, etc.) ; The result is a character string naming the field type. ; ??? One could require that the `value' field always be an object. ; I can't get too worked up over it yet. ; send 'get-name to fetch the name "#"; # -> "it's a number" ; Generate the name of the enum for instruction field ifld. ; If PREFIX? is present and #f, the @ARCH@_ prefix is omitted. "@ARCH@_"""; Return a boolean indicating if ifield F is an opcode field ; (has a constant value). ; (and (number? (ifld-get-value f)) ; (if option:reserved-as-opcode? ; #t ; (not (has-attr? f 'RESERVED)))) ; Return a boolean indicating if ifield F is an operand. ; FIXME: Should check for operand? or some such. ; Return known value table for rtx-simplify of <ifield> list ifld-list. ; Return mask to use for a field in <bitrange> CONTAINER. ; If the bitrange is outside the range of the field, return 0. ; If CONTAINER is #f, use the recorded bitrange. ; BASE-LEN, if non-#f, overrides the base insn length of the insn. ; BASE-LEN is present for architectures like the m32r where there are insns ; smaller than the base insn size (LIW). ; ; Simplifying restrictions [to be relaxed as necessary]: ; - the field must either be totally contained within CONTAINER or totally ; outside it, partial overlaps aren't handled ; - CONTAINER must be an integral number of bytes, beginning on a ; byte boundary [simplifies things] ; - both SELF's bitrange and CONTAINER must have the same word length ; - LSB0? of SELF's bitrange and CONTAINER must be the same ; must be same lsb0 "field-mask: different lsb0? values"; container occurs after? ; container occurs before? ; Return VALUE inserted into the field's position. ; BASE-LEN, if non-#f, overrides the base insn length of the insn. ; BASE-LEN is present for architectures like the m32r where there are insns ; smaller than the base insn size (LIW). ; FIXME: confusion with ifld-get-value. ; Return a list of ifields required to compute <ifield> F's value. ; Normally this is just F itself. For multi-ifields it will be more. ; ??? It can also be more if F's value is derived from other fields but ; that isn't supported yet. ; Extract <ifield> IFLD's value out of VALUE in <insn> INSN. ; VALUE is the entire insn's value if it fits in a word, or is a list ; of values, one per word (not implemented, sigh). ; ??? The instruction's format should specify where the word boundaries are. ; start is msb ; Return a boolean indicating if bit 0 is the least significant bit. ; Return the minimum value of a field. "unsupported mode class"; Return the maximum value of a field. "unsupported mode class"; Create a copy of field F with value VALUE. ; VALUE is either ... ??? ; Change the offset of the word containing an ifield to {word-offset}. ; Return a copy of F with new {word-offset}. ; Return the bit offset of the word after the word <ifield> F is in. ; What a `word' here is defined by F in its bitrange. ; Return a boolean indicating if <ifield> F1 precedes <ifield> F2. ; FIXME: Move into a method as different subclasses will need ; different handling. ; ??? revisit ; Parse an ifield definition. ; This is the main routine for building an ifield object from a ; description in the .cpu file. ; All arguments are in raw (non-evaluated) form. ; The result is the parsed object or #f if object isn't for selected mach(s). ; ; Two forms of specification are supported, loosely defined as the RISC way ; and the CISC way. The reason for the distinction is to simplify ifield ; specification of RISC-like cpus. ; Note that VLIW's are another way. These are handled like the RISC way, with ; the possible addition of instruction framing (which is, surprise surprise, ; wip). ; ; RISC: ; WORD-OFFSET and WORD-LENGTH are #f. Insns are assumed to be N copies of ; (isa-default-insn-word-bitsize). WORD-OFFSET is computed from START. ; START is the offset in bits from the start of the insn. ; FLENGTH is the length of the field in bits. ; ; CISC: ; WORD-OFFSET is the offset in bits from the start to the first byte of the ; word containing the ifield. ; WORD-LENGTH is the length in bits of the word containing the ifield. ; START is the starting bit number in the word. Bit numbering is taken from ; (current-arch-insn-lsb0?). ; FLENGTH is the length in bits of the ifield. It is named that way to avoid ; collision with the proc named `length'. ; ; FIXME: More error checking. "Processing ifield "" ...\n";; Pick out name first to augment the error context. "cgen_ifld"; No longer ensure only one isa specified. ;(if (!= (length isas) 1) ; (parse-error context "can only specify 1 isa" attrs)) "either both or neither of word-offset,word-length can be specified"; ??? 0.127 for now ; ??? 0.127 for now ; Calculate the <bitrange> object. ; ??? Move positional info to format? ; CISC-like. Easy. Everything must be specified. ; RISC-like. Hard. Have to make best choice of start, ; flength. This doesn't have to be perfect, just easily ; explainable. Cases this doesn't handle can explicitly ; specify word-offset,word-length. ; One can certainly argue the choice of the term ; "RISC-like" is inaccurate. Perhaps. ; Else ignore entry. "Ignoring "".\n"; Subroutine of -ifield-parse to simplify it. ; Given START,FLENGTH, return the "best" choice for the offset to the word ; containing the ifield. ; This is easy to visualize, hard to put into words. ; Imagine several words of size DIWB laid out from the start of the insn. ; On top of that lay the ifield. ; Now pick the minimal set of words that are required to contain the ifield. ; That's what we want. ; No claim is made that this is always the correct choice for any ; particular architecture. For those where this isn't correct, the ifield ; must be fully specified (i.e. word-offset,word-length explicitly specified). ; Convert to non-lsb0 case, then it's easy. ; NOTE: The conversion is seemingly wrong because `start' is misnamed. ; It's now `end'. ; Subroutine of -ifield-parse to simplify it. ; Given START,FLENGTH, return the "best" choice for the length of the word ; containing the ifield. ; DIWB = default insn word bitsize ; See -get-ifld-word-offset for more info. ; Convert to non-lsb0 case, then it's easy. ; NOTE: The conversion is seemingly wrong because `start' is misnamed. ; It's now `end'. ; Read an instruction field description. ; This is the main routine for analyzing instruction fields in the .cpu file. ; CONTEXT is a <context> object for error messages. ; ARG-LIST is an associative list of field name and field value. ; -ifield-parse is invoked to create the <ifield> object. ""; FIXME: Hobbit computes the wrong symbol for `length' ; in the `case' expression below because there is a local var ; of the same name ("__1" gets appended to the symbol name). ; As a workaround we name it "length-". ; Loop over each element in ARG-LIST, recording what's found. "invalid ifield arg"; See if encode/decode were specified as "unspecified". ; This happens with shorthand macros. ; Now that we've identified the elements, build the object. ; Parse a `follows' spec. "unknown operand to follow"; Do common parts of <ifield> encode/decode processing. "bad ifield "" spec"" expression must have a mode"; Parse an <ifield> encode spec. "encode"; Parse an <ifield> decode spec. "decode"; Define an instruction field object, name/value pair list version. "define-ifield"; Define an instruction field object, all arguments specified. ; ??? Leave out word-offset,word-length,follows for now (RISC version). ; FIXME: Eventually this should be fixed to take *all* arguments. "define-full-ifield""\ Define an instruction field, name/value pair list version. ""\ Define an instruction field, all arguments specified. ""\ Define an instruction multi-field, name/value pair list version. ""\ Define an instruction multi-field, all arguments specified. "; Instruction fields consisting of multiple parts. ; List of <ifield> objects. ; rtl to set SUBFIELDS from self ; rtl to set self from SUBFIELDS ; Accessors ; Return a boolean indicating if X is an <ifield>. ; Return the starting bit number of the first field. ; Return the total length. ; Return the bit offset of the word after the last word SELF is in. ; What a `word' here is defined by subfields in their bitranges. ; Return mask of field in bitrange CONTAINER. ; Return VALUE inserted into the field's position. ; The value is spread out over the various subfields in sorted order. ; We assume the subfields have been sorted by starting bit position. ; Return a list of ifields required to compute the field's value. ; Extract <ifield> IFLD's value out of VALUE in <insn> INSN. ; VALUE is the entire insn's value if it fits in a word, or is a list ; of values, one per word (not implemented, sigh). ; ??? The instruction's format should specify where the word boundaries are. ; We have each subfield's value, now concatenate them. ; do the -1 drop here as it's easier ; Return a boolean indicating if bit 0 is the least significant bit. ; Multi-ifield parsing. ; Subroutine of -multi-ifield-parse to build the default insert expression. ; Build RTL expression to shift and mask each ifield into right spot. ; Now set each ifield with their respective values. ; Subroutine of -multi-ifield-parse to build the default extract expression. ; Build RTL expression to shift and mask each ifield into right spot. ; Now set {container-name} with all the values or'd together. ; Parse a multi-ifield spec. ; This is the main routine for building the object from the .cpu file. ; All arguments are in raw (non-evaluated) form. ; The result is the parsed object or #f if object isn't for selected mach(s). "Processing multi-ifield element "" ...\n""empty subfield list";; Pick out name first to augment the error context. "cgen_ifld"; No longer ensure only one isa specified. ; (if (!= (length isas) 1) ; (parse-error context "can only specify 1 isa" attrs)) "unknown ifield";; multi-ifields are always VIRTUAL "multi-ifield"; else don't keep isa ; Read an instruction multi-ifield. ; This is the main routine for analyzing multi-ifields in the .cpu file. ; CONTEXT is a <context> object for error messages. ; ARG-LIST is an associative list of field name and field value. ; -multi-ifield-parse is invoked to create the `multi-ifield' object. ""; Loop over each element in ARG-LIST, recording what's found. "invalid ifield arg"; Now that we've identified the elements, build the object. ; Define an instruction multi-field object, name/value pair list version. "define-multi-ifield"; Define an instruction multi-field object, all arguments specified. ; FIXME: encode/decode arguments are missing. "define-full-multi-ifield"; Derived ifields (ifields based on one or more other ifields). ; These support the complicated requirements of CISC instructions ; where one "ifield" is actually a placeholder for an addressing mode ; which can consist of several ifields. ; These are also intended to support other complex ifield usage. ; ; Derived ifields are (currently) always machine generated from other ; elements of the description file so there is no reader support. ; ; ??? experimental and wip! ; ??? These are kind of like multi-ifields but I don't want to disturb them ; while this is still experimental. ; Operand that uses this ifield. ; Unlike other ifields, derived ifields have a one-to-one ; correspondence with the operand that uses them. ; ??? Not true in -anyof-merge-subchoices. ; List of ifields that make up this ifield. ; Accessors. ; Return a boolean indicating if F is a derived ifield with a derived operand ; for a value. ; ??? The former might imply the latter so some simplification may be possible. ; Return the bit offset of the word after the last word SELF is in. ; What a `word' here is defined by subfields in their bitranges. ; Traverse the ifield to collect all base (non-derived) ifields used in it. ; ((multi-ifield? ifld) (collect (lambda (subfield) (ifld-base-ifields subfield)) ; (multi-ifld-subfields ifld))) ; Misc. utilities. ; Sort a list of fields (sorted by the starting bit number). ; This must be carefully defined to pass through Hobbit. ; (define foo (if x bar baz)) is ok. ; (if x (define foo bar) (define foo baz)) is not ok. ; ; ??? Usually there aren't that many fields and the range of values is fixed, ; so I think this needn't use a general purpose sort routine (should it become ; an issue). ; Return a boolean indicating if field F extends beyond the base insn. ; old way ;(< base-bitsize (+ (ifld-start f total-bitsize) (ifld-length f))) ; Return the mode of the decoded value of <ifield> F. ; ??? This is made easy because we require the decode expression to have ; an explicit mode. ; Return <hardware> object to use to hold value of <ifield> F. ; i.e. one of h-uint, h-sint. ; NB: Should be defined in terms of `hardware-for-mode'. "unsupported mode class"; Builtin fields, attributes, init/fini support. ; The f-nil field is a placeholder when building operands out of hardware ; elements that aren't indexed by an instruction field (scalars). ; The f-anyof field is a placeholder when building "anyof" operands. ; Return a boolean indicating if F is an anyof ifield with an anyof operand ; for a value. ; ??? The former implies the latter so some simplification is possible. ; Called before loading the .cpu file to initialize. ; Called before loading the .cpu file to create any builtins. ; Standard ifield attributes. ; ??? Some of these can be combined into one, booleans are easier to ; work with. "pc relative address""absolute address""field is reserved""value is signed or unsigned"; ??? This is an internal attribute for implementation purposes only. ; To be revisited. "value is unsigned"; Also (defined elsewhere): VIRTUAL "empty ifield"; encode/decode "placeholder for anyof operands"; encode/decode ; Called after the .cpu file has been read in.