1 |
157 |
simons |
/* Table of opcodes for the OpenRISC 16 ISA.
|
2 |
|
|
Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
|
3 |
|
|
Contributed by Johan Rydberg, <johan.rydberg@netinsight.se>
|
4 |
|
|
|
5 |
|
|
This file is part of GDB and GAS.
|
6 |
|
|
|
7 |
|
|
This program is free software; you can redistribute it and/or modify
|
8 |
|
|
it under the terms of the GNU General Public License as published by
|
9 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
10 |
|
|
(at your option) any later version.
|
11 |
|
|
|
12 |
|
|
This program is distributed in the hope that it will be useful,
|
13 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
|
|
GNU General Public License for more details.
|
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU General Public License
|
18 |
|
|
along with this program; if not, write to the Free Software
|
19 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
20 |
|
|
|
21 |
|
|
/* We treat all letters the same in encode/decode routines so
|
22 |
|
|
we need to assign some characteristics to them like signess etc.*/
|
23 |
|
|
|
24 |
|
|
#define NUM_UNSIGNED 0
|
25 |
|
|
#define NUM_SIGNED 1
|
26 |
|
|
|
27 |
|
|
struct or16_letter {
|
28 |
|
|
char letter;
|
29 |
|
|
int sign;
|
30 |
|
|
/* int reloc; relocation per letter ??*/
|
31 |
|
|
};
|
32 |
|
|
|
33 |
|
|
static struct or16_letter or16_letters[] =
|
34 |
|
|
{
|
35 |
|
|
{ 'A', NUM_UNSIGNED },
|
36 |
|
|
{ 'B', NUM_UNSIGNED },
|
37 |
|
|
{ 'D', NUM_UNSIGNED },
|
38 |
|
|
{ 'J', NUM_SIGNED },
|
39 |
|
|
{ 'L', NUM_UNSIGNED },
|
40 |
|
|
{ 'M', NUM_SIGNED },
|
41 |
|
|
{ 'N', NUM_SIGNED },
|
42 |
|
|
{ 'X', NUM_SIGNED },
|
43 |
|
|
{ 'Y', NUM_SIGNED },
|
44 |
|
|
{ '\0', 0 } /* dummy entry */
|
45 |
|
|
};
|
46 |
|
|
|
47 |
|
|
struct or16_opcode {
|
48 |
|
|
/* Name of the instruction. */
|
49 |
|
|
char *name;
|
50 |
|
|
|
51 |
|
|
/* A string of characters which describe the operands.
|
52 |
|
|
Ranges for I..O can be wrong (I change them the time ;-).
|
53 |
|
|
Valid characters are:
|
54 |
|
|
, Itself. The character appears in the assembly code.
|
55 |
|
|
rA Register operand.
|
56 |
|
|
rB Register operand.
|
57 |
|
|
rC Register operand.
|
58 |
|
|
rD Register operand.
|
59 |
|
|
I An immediate operand, range -32768 to 32767.
|
60 |
|
|
J An immediate operand, range -65536 to 65535.
|
61 |
|
|
K An immediate operand, range -131072 to 131071.
|
62 |
|
|
L An immediate operand, range 0 to 31.
|
63 |
|
|
M An immediate operand, range -128 to 127.
|
64 |
|
|
N An immediate operand, range -8 to 7.
|
65 |
|
|
O An immediate operand, unused at the moment.
|
66 |
|
|
X 12-bit PC relative address
|
67 |
|
|
Y 26-bit absoule address */
|
68 |
|
|
|
69 |
|
|
char *args;
|
70 |
|
|
|
71 |
|
|
/* Opcode and operand encoding. */
|
72 |
|
|
char *encoding;
|
73 |
|
|
};
|
74 |
|
|
|
75 |
|
|
#ifndef CONST
|
76 |
|
|
#define CONST
|
77 |
|
|
#endif /* CONST */
|
78 |
|
|
|
79 |
|
|
static CONST struct or16_opcode or16_opcodes[] =
|
80 |
|
|
{
|
81 |
|
|
/* Inherited from old OR32 */
|
82 |
|
|
{ "h.sfeq32", "rA,rB", "0x4 0x0 AAAA BBBB"},
|
83 |
|
|
{ "h.sfne32", "rA,rB", "0x4 0x1 AAAA BBBB"},
|
84 |
|
|
{ "h.sfgt32s", "rA,rB", "0x4 0x2 AAAA BBBB"},
|
85 |
|
|
{ "h.sfge32s", "rA,rB", "0x4 0x3 AAAA BBBB"},
|
86 |
|
|
{ "h.sflt32s", "rA,rB", "0x4 0x4 AAAA BBBB"},
|
87 |
|
|
{ "h.sfle32s", "rA,rB", "0x4 0x5 AAAA BBBB"},
|
88 |
|
|
{ "h.sfgt32u", "rA,rB", "0x4 0x6 AAAA BBBB"},
|
89 |
|
|
{ "h.sfge32u", "rA,rB", "0x4 0x7 AAAA BBBB"},
|
90 |
|
|
{ "h.sflt32u", "rA,rB", "0x4 0x8 AAAA BBBB"},
|
91 |
|
|
{ "h.sfle32u", "rA,rB", "0x4 0x9 AAAA BBBB"},
|
92 |
|
|
{ "h.ext16s", "rA", "0x4 0xB AAAA 0000"},
|
93 |
|
|
{ "h.ext16z", "rA", "0x4 0xB AAAA 0001"},
|
94 |
|
|
{ "h.ext8s", "rA", "0x4 0xB AAAA 0010"},
|
95 |
|
|
{ "h.ext8z", "rA", "0x4 0xB AAAA 0011"},
|
96 |
|
|
{ "h.nop", "", "0x4 0xB 0000 0100"},
|
97 |
|
|
{ "h.jalr", "rA", "0x4 0xB AAAA 0101"},
|
98 |
|
|
{ "h.add32s", "rA,rB,rD", "0x7 DDDD AAAA BBBB"},
|
99 |
|
|
{ "h.bnf", "X", "0xA XXXX XXXX XXXX"},
|
100 |
|
|
{ "h.bf", "X", "0xB XXXX XXXX XXXX"},
|
101 |
|
|
{ "h.movi8se", "rA,M", "0xC MMMM AAAA MMMM"},
|
102 |
|
|
{ "h.mov32", "rA,rB", "0xE 0x0 AAAA BBBB"},
|
103 |
|
|
/* { 2, "h.sched", "Z", "0xF ZZZZ ZZZZ ZZZZ"}, */
|
104 |
|
|
|
105 |
|
|
/* New insn opcodes, specified by Jimmy Chen-Min Chen, <jimmy87@sunplus.com.tw> */
|
106 |
|
|
{ "h.brk", "M", "0xD 0000 MMMM MMMM"},
|
107 |
|
|
{ "h.sys", "M", "0xD 1000 MMMM MMMM"},
|
108 |
|
|
{ "h.rfe", "", "0xD 1001 0000 0000"},
|
109 |
|
|
{ "h.ma32s", "rA,rB", "0xD 0011 AAAA BBBB"},
|
110 |
|
|
{ "h.ms32s", "rA,rB", "0xD 0010 AAAA BBBB"},
|
111 |
|
|
{ "h.mod32s", "rA,rB", "0xD 0101 AAAA BBBB"},
|
112 |
|
|
{ "h.mod32u", "rA,rB", "0xD 0111 AAAA BBBB"},
|
113 |
|
|
|
114 |
|
|
{ "h.mul32s", "rA,rB", "0x4 1100 AAAA BBBB"},
|
115 |
|
|
{ "h.mul32u", "rA,rB", "0x4 1101 AAAA BBBB"},
|
116 |
|
|
{ "h.div32s", "rA,rB", "0x4 1110 AAAA BBBB"},
|
117 |
|
|
{ "h.div32u", "rA,rB", "0x4 1111 AAAA BBBB"},
|
118 |
|
|
|
119 |
|
|
{ "h.sub32s", "rA,rB", "0xE 0011 AAAA BBBB"},
|
120 |
|
|
{ "h.xor32", "rA,rB", "0xE 0101 AAAA BBBB"},
|
121 |
|
|
{ "h.or32", "rA,rB", "0xE 0111 AAAA BBBB"},
|
122 |
|
|
{ "h.and32", "rA,rB", "0xE 1001 AAAA BBBB"},
|
123 |
|
|
|
124 |
|
|
{ "h.shlai32", "rA,L", "0xE 101L AAAA LLLL"},
|
125 |
|
|
{ "h.shrai32", "rA,L", "0xE 110L AAAA LLLL"},
|
126 |
|
|
{ "h.shrli32", "rA,L", "0xE 111L AAAA LLLL"},
|
127 |
|
|
|
128 |
|
|
{ "h.shla32", "rA,rB", "0xE 1010 AAAA BBBB"},
|
129 |
|
|
{ "h.shra32", "rA,rB", "0xE 1100 AAAA BBBB"},
|
130 |
|
|
{ "h.shrl32", "rA,rB", "0xE 1110 AAAA BBBB"},
|
131 |
|
|
|
132 |
|
|
{ "h.ror32", "rA,rB", "0xD 1011 AAAA BBBB"},
|
133 |
|
|
{ "h.rol32", "rA,rB", "0xD 1101 AAAA BBBB"},
|
134 |
|
|
|
135 |
|
|
{ "h.add32u", "rA,rB", "0xF 0000 AAAA BBBB"},
|
136 |
|
|
{ "h.sub32u", "rA,rB", "0xF 0001 AAAA BBBB"},
|
137 |
|
|
{ "h.addwc32s","rA,rB", "0xF 0010 AAAA BBBB"},
|
138 |
|
|
{ "h.subwc32s","rA,rB", "0xF 0011 AAAA BBBB"},
|
139 |
|
|
|
140 |
|
|
{ "h.jmp", "X", "0x8 XXXX XXXX XXXX"},
|
141 |
|
|
{ "h.jr", "rA", "0x4 1011 AAAA 0110"},
|
142 |
|
|
|
143 |
|
|
/* The next section with insns are a bit speciel. They are normal 16-bit insn but
|
144 |
|
|
are followed by the laster operator in its own 16-bit word. The length of these
|
145 |
|
|
insn are 4 bytes. */
|
146 |
|
|
{ "h.jal", "Y", "0x9 YYYY YYYY YYYY YYYYYYYYYYYYYYYY"},
|
147 |
|
|
|
148 |
|
|
{ "h.movi16ze","rA,J", "0xD 0110 AAAA 0010 JJJJJJJJJJJJJJJJ"},
|
149 |
|
|
{ "h.immhi16u","rA,J", "0xD 0110 AAAA 0011 JJJJJJJJJJJJJJJJ"},
|
150 |
|
|
{ "h.addi16s", "rA,rB,J", "0xE 0001 AAAA BBBB JJJJJJJJJJJJJJJJ"},
|
151 |
|
|
{ "h.subi16s", "rA,rB,J", "0xE 0010 AAAA BBBB JJJJJJJJJJJJJJJJ"},
|
152 |
|
|
{ "h.xori16", "rA,rB,J", "0xE 0100 AAAA BBBB JJJJJJJJJJJJJJJJ"},
|
153 |
|
|
{ "h.ori16", "rA,rB,J", "0xE 0110 AAAA BBBB JJJJJJJJJJJJJJJJ"},
|
154 |
|
|
{ "h.andi16", "rA,rB,J", "0xE 1000 AAAA BBBB JJJJJJJJJJJJJJJJ"},
|
155 |
|
|
|
156 |
|
|
{ "h.load32u", "rA,J(rB)", "0x5 0000 AAAA BBBB JJJJJJJJJJJJJJJJ"},
|
157 |
|
|
{ "h.load16u", "rA,J(rB)", "0x5 0001 AAAA BBBB JJJJJJJJJJJJJJJJ"},
|
158 |
|
|
{ "h.load8u", "rA,J(rB)", "0x5 0010 AAAA BBBB JJJJJJJJJJJJJJJJ"},
|
159 |
|
|
{ "h.stor32", "J(rA),rB", "0x6 0000 AAAA BBBB JJJJJJJJJJJJJJJJ"},
|
160 |
|
|
{ "h.stor16", "J(rA),rB", "0x6 0001 AAAA BBBB JJJJJJJJJJJJJJJJ"},
|
161 |
|
|
{ "h.stor8", "J(rA),rB", "0x6 0010 AAAA BBBB JJJJJJJJJJJJJJJJ"},
|
162 |
|
|
|
163 |
|
|
{ "h.load32painu", "rA,N", "0x5 0011 AAAA NNNN "},
|
164 |
|
|
{ "h.load16painu", "rA,N", "0x5 0100 AAAA NNNN "},
|
165 |
|
|
{ "h.load8painu", "rA,N", "0x5 0101 AAAA NNNN "},
|
166 |
|
|
|
167 |
|
|
{ "h.stor32pai", "N,rB", "0x6 0011 NNNN BBBB "},
|
168 |
|
|
{ "h.stor16pai", "N,rB", "0x6 0100 NNNN BBBB "},
|
169 |
|
|
{ "h.stor8pai", "N,rB", "0x6 0101 NNNN BBBB "},
|
170 |
|
|
|
171 |
|
|
{ "h.stor32pain", "N,rB", "0x6 0110 NNNN BBBB "},
|
172 |
|
|
{ "h.stor16pain", "N,rB", "0x6 0111 NNNN BBBB "},
|
173 |
|
|
{ "h.stor8pain", "N,rB", "0x6 1000 NNNN BBBB "},
|
174 |
|
|
|
175 |
|
|
{ "h.mtsr", "rA,rB", "0xF 1110 AAAA BBBB "},
|
176 |
|
|
{ "h.mfsr", "rA,rB", "0xF 1111 AAAA BBBB "},
|
177 |
|
|
|
178 |
|
|
{ "", "", "" } /* Dummy entry, not included in NUM_OPCODES. This
|
179 |
|
|
lets code examine entry i+1 without checking
|
180 |
|
|
if we've run off the end of the table. */
|
181 |
|
|
};
|
182 |
|
|
|
183 |
|
|
CONST unsigned int num_opcodes = (((sizeof or16_opcodes) / (sizeof or16_opcodes[0])) - 1);
|
184 |
|
|
|
185 |
|
|
/* Calculates instruction length in bytes. Either 2 or 4 for OR16
|
186 |
|
|
and always 4 for OR32. */
|
187 |
|
|
int insn_len(char *insn)
|
188 |
|
|
{
|
189 |
|
|
struct or16_opcode *pinsn;
|
190 |
|
|
char *enc;
|
191 |
|
|
int len = 0;
|
192 |
|
|
|
193 |
|
|
for(pinsn = or16_opcodes; strlen(pinsn->name); pinsn++) {
|
194 |
|
|
if (strcmp(pinsn->name, insn) == 0) {
|
195 |
|
|
for (enc = pinsn->encoding; *enc != '\0'; enc++)
|
196 |
|
|
if ((*enc == '0') && (*(enc+1) == 'x')) {
|
197 |
|
|
len += 4;
|
198 |
|
|
enc += 2;
|
199 |
|
|
}
|
200 |
|
|
else if (!isspace(*enc))
|
201 |
|
|
len++;
|
202 |
|
|
return len / 8;
|
203 |
|
|
}
|
204 |
|
|
}
|
205 |
|
|
printf("insn_len(%s): Unknown instruction.\n", insn);
|
206 |
|
|
exit(1);
|
207 |
|
|
}
|
208 |
|
|
|