4 Copyright (C) 1997 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 Yacc grammar for instruction table entries.
29 =======================================================================
30 Original Instruction table specification document:
32 MIPS Coprocessor Table Specification
33 ====================================
35 This document describes the format of the MIPS coprocessor table. The
36 table specifies a list of valid functions, data registers and control
37 registers that can be used in coprocessor instructions. This list,
38 together with the coprocessor instruction classes listed below,
39 specifies the complete list of coprocessor instructions that will
40 be recognized and assembled by the GNU assembler. In effect,
41 this makes the GNU assembler table-driven, where the table is
42 specified by the programmer.
44 The table is an ordinary text file that the GNU assembler reads when
45 it starts. Using the information in the table, the assembler
46 generates an internal list of valid coprocessor registers and
47 functions. The assembler uses this internal list in addition to the
48 standard MIPS registers and instructions which are built-in to the
49 assembler during code generation.
51 To specify the coprocessor table when invoking the GNU assembler, use
52 the command line option "--itbl file", where file is the
53 complete name of the table, including path and extension.
57 gas -t cop.tbl test.s -o test.o
58 gas -t /usr/local/lib/cop.tbl test.s -o test.o
59 gas --itbl d:\gnu\data\cop.tbl test.s -o test.o
61 Only one table may be supplied during a single invocation of
68 Below is a list of the valid coprocessor instruction classes for
69 any given coprocessor "z". These instructions are already recognized
70 by the assembler, and are listed here only for reference.
72 Class format instructions
73 -------------------------------------------------
104 The coprocessor table defines coprocessor-specific registers that can
105 be used with all of the above classes of instructions, where
106 appropriate. It also defines additional coprocessor-specific
107 functions for Class3 (COPz cofun) instructions, Thus, the table allows
108 the programmer to use convenient mnemonics and operands for these
109 functions, instead of the COPz mmenmonic and cofun operand.
111 The names of the MIPS general registers and their aliases are defined
112 by the assembler and will be recognized as valid register names by the
113 assembler when used (where allowed) in coprocessor instructions.
114 However, the names and values of all coprocessor data and control
115 register mnemonics must be specified in the coprocessor table.
121 Here is the grammar for the coprocessor table:
125 entry -> [z entrydef] [comment] '\n'
127 entrydef -> type name val
128 entrydef -> 'insn' name val funcdef ; type of entry (instruction)
130 z -> 'p'['0'..'3'] ; processor number
131 type -> ['dreg' | 'creg' | 'greg' ] ; type of entry (register)
132 ; 'dreg', 'creg' or 'greg' specifies a data, control, or general
133 ; register mnemonic, respectively
134 name -> [ltr|dec]* ; mnemonic of register/function
135 val -> [dec|hex] ; register/function number (integer constant)
137 funcdef -> frange flags fields
138 ; bitfield range for opcode
139 ; list of fields' formats
141 field -> [','] ftype frange flags
142 flags -> ['*' flagexpr]
143 flagexpr -> '[' flagexpr ']'
144 flagexpr -> val '|' flagexpr
145 ftype -> [ type | 'immed' | 'addr' ]
146 ; 'immed' specifies an immediate value; see grammar for "val" above
147 ; 'addr' specifies a C identifier; name of symbol to be resolved at
149 frange -> ':' val '-' val ; starting to ending bit positions, where
150 ; where 0 is least significant bit
151 frange -> (null) ; default range of 31-0 will be assumed
153 comment -> [';'|'#'] [char]*
154 char -> any printable character
155 ltr -> ['a'..'z'|'A'..'Z']
156 dec -> ['0'..'9']* ; value in decimal
157 hex -> '0x'['0'..'9' | 'a'..'f' | 'A'..'F']* ; value in hexidecimal
167 p1 dreg d1 1 ; data register "d1" for COP1 has value 1
168 p1 creg c3 3 ; ctrl register "c3" for COP1 has value 3
169 p3 func fill 0x1f:24-20 ; function "fill" for COP3 has value 31 and
172 will allow the assembler to accept the following coprocessor instructions:
177 Here, the general purpose register "$2", and instruction "LWC1", are standard
178 mnemonics built-in to the MIPS assembler.
185 p3 dreg d3 3 ; data register "d3" for COP3 has value 3
186 p3 creg c2 22 ; control register "c2" for COP3 has value 22
187 p3 func fee 0x1f:24-20 dreg:17-13 creg:12-8 immed:7-0
188 ; function "fee" for COP3 has value 31, and 3 fields
189 ; consisting of a data register, a control register,
190 ; and an immediate value.
192 will allow the assembler to accept the following coprocessor instruction:
196 and will emit the object code:
198 31-26 25 24-20 19-18 17-13 12-8 7-0
199 COPz CO fun dreg creg immed
200 010011 1 11111 00 00011 10110 00000001
209 p3 dreg d3 3 ; data register "d3" for COP3 has value 3
210 p3 creg c2 22 ; control register "c2" for COP3 has value 22
211 p3 func fuu 0x01f00001 dreg:17-13 creg:12-8
213 will allow the assembler to accept the following coprocessor
218 and will emit the object code:
220 31-26 25 24-20 19-18 17-13 12-8 7-0
221 COPz CO fun dreg creg
222 010011 1 11111 00 00011 10110 00000001
226 In this way, the programmer can force arbitrary bits of an instruction
227 to have predefined values.
229 =======================================================================
233 To handle more than one bit position range within an instruction,
234 use 0s to mask out the ranges which don't apply.
235 May decide to modify the syntax to allow commas separate multiple
236 ranges within an instruction (range','range).
239 The number of parms argument to the function entry
240 was deleted from the original format such that we now count the fields.
243 FIXME! should really change lexical analyzer
244 to recognize 'dreg' etc. in context sensative way.
245 Currently function names or mnemonics may be incorrectly parsed as keywords
247 FIXME! hex is ambiguous with any digit
252 #include "itbl-ops.h"
265 #define DBG(x) printf x
271 #define DBGL2(x) printf x
276 static int sbit, ebit;
277 static struct itbl_entry *insn=0;
278 extern int insntbl_line;
292 %token DREG CREG GREG IMMED ADDR INSN NUM ID NL PNUM
293 %type <val> value flags flagexpr
294 %type <num> number NUM ftype regtype pnum PNUM
311 pnum regtype name value NL
313 DBG (("line %d: entry pnum=%d type=%d name=%s value=x%x\n",
314 insntbl_line, $1, $2, $3, $4));
315 itbl_add_reg ($1, $2, $3, $4);
317 | pnum INSN name value range flags
319 DBG (("line %d: entry pnum=%d type=INSN name=%s value=x%x",
320 insntbl_line, $1, $3, $4));
321 DBG ((" sbit=%d ebit=%d flags=0x%x\n", sbit, ebit, $6));
322 insn=itbl_add_insn ($1, $3, $4, sbit, ebit, $6);
330 ',' fieldspec fieldspecs
331 | fieldspec fieldspecs
356 DBG (("line %d: field type=%d sbit=%d ebit=%d, flags=0x%x\n",
357 insntbl_line, $1, sbit, ebit, $3));
358 itbl_add_operand (insn, $1, sbit, ebit, $3);
380 DBGL2 (("flags=%d\n", $2));
392 DBGL2 (("range %d %d\n", $2, $4));
406 DBGL2 (("pnum=%d\n",$1));
432 DBGL2 (("name=%s\n",$1));
440 DBGL2 (("num=%d\n",$1));
448 DBGL2 (("val=x%x\n",$1));
457 printf ("line %d: %s\n", insntbl_line, msg);