OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_68/] [gen_or1k_isa/] [sources/] [or32.c] - Blame information for rev 1342

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 133 markom
/* Table of opcodes for the OpenRISC 1000 ISA.
2
   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3
   Contributed by Damjan Lampret (lampret@opencores.org).
4
 
5 717 markom
This file is part of gen_or1k_isa, or1ksim, GDB and GAS.
6 133 markom
 
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 1114 lampret
/*
22
 * $Log: not supported by cvs2svn $
23 1342 nogj
 * Revision 1.38  2005/01/27 13:15:50  nogj
24
 * Mark wich operand is the destination operand in the architechture definition
25
 *
26 1341 nogj
 * Revision 1.37  2005/01/11 15:41:58  andreje
27
 * l.ff1 instruction added
28
 *
29 1338 andreje
 * Revision 1.36  2004/07/22 20:17:23  phoenix
30
 * removed includes
31
 *
32 1309 phoenix
 * Revision 1.35  2004/07/19 23:07:37  phoenix
33
 * Gyorgy Jeney: extensive cleanup
34
 *
35 1308 phoenix
 * Revision 1.34  2004/06/27 22:56:48  lampret
36
 * Updated instruction set descriptions. Changed FP instructions encoding.
37
 *
38 1295 lampret
 * Revision 1.33  2004/05/09 19:52:31  lampret
39
 * Changed desciption of the l.cust5 insns
40
 *
41 1285 lampret
 * Revision 1.31  2003/07/01 19:34:49  csanchez
42
 * Added support for l.addc instruction.
43
 *
44 1169 csanchez
 * Revision 1.30  2003/01/28 03:49:24  lampret
45
 * Added cvs log keywords
46
 *
47 1114 lampret
 */
48
 
49 133 markom
#include <string.h>
50
#include <stdio.h>
51
#include <stdlib.h>
52 371 markom
#include <ctype.h>
53 133 markom
 
54 371 markom
 
55 138 markom
#ifdef HAVE_CONFIG_H
56
# include "config.h"
57
#endif
58 1342 nogj
#ifdef HAS_EXECUTION
59
# include "abstract.h" /* To get struct iqueue_entry */
60
#endif
61 133 markom
#include "opcode/or32.h"
62
 
63
/* **INDENT-OFF** */
64
 
65 1342 nogj
/* We treat all letters the same in encode/decode routines so
66
   we need to assign some characteristics to them like signess etc.*/
67 133 markom
CONST struct or32_letter or32_letters[] =
68
{
69
{ 'A', NUM_UNSIGNED },
70
{ 'B', NUM_UNSIGNED },
71
{ 'D', NUM_UNSIGNED },
72
{ 'I', NUM_SIGNED },
73
{ 'K', NUM_UNSIGNED },
74
{ 'L', NUM_UNSIGNED },
75
{ 'N', NUM_SIGNED },
76
{ '0', NUM_UNSIGNED },
77
{ '\0', 0 }     /* dummy entry */
78
};
79
 
80
/* Opcode encoding:
81
   machine[31:30]: first two bits of opcode
82
                   00 - neither of source operands is GPR
83
                   01 - second source operand is GPR (rB)
84
                   10 - first source operand is GPR (rA)
85
                   11 - both source operands are GPRs (rA and rB)
86
   machine[29:26]: next four bits of opcode
87
   machine[25:00]: instruction operands (specific to individual instruction)
88
 
89
  Recommendation: irrelevant instruction bits should be set with a value of
90
  bits in same positions of instruction preceding current instruction in the
91
  code (when assembling).
92
*/
93
 
94 1341 nogj
#ifdef HAS_EXECUTION
95
# if SIMPLE_EXECUTION
96
#  define EFN &l_none
97
#  define EF(func) &(func)
98
#  define EFI &l_invalid
99
# else /* SIMPLE_EXECUTION */
100
#  define EFN "l_none"
101
#  define EFI "l_invalid"
102
#  ifdef __GNUC__
103
#   define EF(func) #func
104
#  else
105
#   define EF(func) "func"
106
#  endif
107
# endif /* SIMPLE_EXECUTION */
108
#else /* HAS_EXECUTION */
109
# define EFN &l_none
110
# define EF(func) EFN
111
# define EFI EFN
112 133 markom
#endif /* HAS_EXECUTION */
113
 
114
CONST struct or32_opcode or32_opcodes[] =
115
{
116
 
117
{ "l.j",       "N",            "00 0x0  NNNNN NNNNN NNNN NNNN NNNN NNNN", EF(l_j), OR32_IF_DELAY },
118
{ "l.jal",     "N",            "00 0x1  NNNNN NNNNN NNNN NNNN NNNN NNNN", EF(l_jal), OR32_IF_DELAY },
119 138 markom
{ "l.bnf",     "N",            "00 0x3  NNNNN NNNNN NNNN NNNN NNNN NNNN", EF(l_bnf), OR32_IF_DELAY | OR32_R_FLAG},
120
{ "l.bf",      "N",            "00 0x4  NNNNN NNNNN NNNN NNNN NNNN NNNN", EF(l_bf), OR32_IF_DELAY | OR32_R_FLAG },
121 676 markom
{ "l.nop",     "K",            "00 0x5  01--- ----- KKKK KKKK KKKK KKKK", EF(l_nop), 0 },
122 133 markom
{ "l.movhi",   "rD,K",         "00 0x6  DDDDD ----0 KKKK KKKK KKKK KKKK", EF(l_movhi), 0 }, /*MM*/
123
{ "l.macrc",   "rD",           "00 0x6  DDDDD ----1 0000 0000 0000 0000", EF(l_macrc), 0 }, /*MM*/
124 676 markom
 
125 133 markom
{ "l.sys",     "K",            "00 0x8  00000 00000 KKKK KKKK KKKK KKKK", EF(l_sys), 0 },
126 144 chris
{ "l.trap",    "K",            "00 0x8  01000 00000 KKKK KKKK KKKK KKKK", EF(l_trap), 0 }, /* CZ 21/06/01 */
127 133 markom
{ "l.msync",   "",             "00 0x8  10000 00000 0000 0000 0000 0000", EFN, 0 },
128
{ "l.psync",   "",             "00 0x8  10100 00000 0000 0000 0000 0000", EFN, 0 },
129
{ "l.csync",   "",             "00 0x8  11000 00000 0000 0000 0000 0000", EFN, 0 },
130
{ "l.rfe",     "",             "00 0x9  ----- ----- ---- ---- ---- ----", EF(l_rfe), OR32_IF_DELAY },
131
 
132
{ "lv.all_eq.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x0", EFI, 0 },
133
{ "lv.all_eq.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x1", EFI, 0 },
134
{ "lv.all_ge.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x2", EFI, 0 },
135
{ "lv.all_ge.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x3", EFI, 0 },
136
{ "lv.all_gt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x4", EFI, 0 },
137
{ "lv.all_gt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x5", EFI, 0 },
138
{ "lv.all_le.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x6", EFI, 0 },
139
{ "lv.all_le.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x7", EFI, 0 },
140
{ "lv.all_lt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x8", EFI, 0 },
141
{ "lv.all_lt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x9", EFI, 0 },
142
{ "lv.all_ne.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0xA", EFI, 0 },
143
{ "lv.all_ne.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0xB", EFI, 0 },
144
{ "lv.any_eq.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x0", EFI, 0 },
145
{ "lv.any_eq.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x1", EFI, 0 },
146
{ "lv.any_ge.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x2", EFI, 0 },
147
{ "lv.any_ge.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x3", EFI, 0 },
148
{ "lv.any_gt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x4", EFI, 0 },
149
{ "lv.any_gt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x5", EFI, 0 },
150
{ "lv.any_le.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x6", EFI, 0 },
151
{ "lv.any_le.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x7", EFI, 0 },
152
{ "lv.any_lt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x8", EFI, 0 },
153
{ "lv.any_lt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x9", EFI, 0 },
154
{ "lv.any_ne.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0xA", EFI, 0 },
155
{ "lv.any_ne.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0xB", EFI, 0 },
156
{ "lv.add.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x0", EFI, 0 },
157
{ "lv.add.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x1", EFI, 0 },
158
{ "lv.adds.b", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x2", EFI, 0 },
159
{ "lv.adds.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x3", EFI, 0 },
160
{ "lv.addu.b", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x4", EFI, 0 },
161
{ "lv.addu.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x5", EFI, 0 },
162
{ "lv.addus.b","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x6", EFI, 0 },
163
{ "lv.addus.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x7", EFI, 0 },
164
{ "lv.and",    "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x8", EFI, 0 },
165
{ "lv.avg.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x9", EFI, 0 },
166
{ "lv.avg.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0xA", EFI, 0 },
167
{ "lv.cmp_eq.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x0", EFI, 0 },
168
{ "lv.cmp_eq.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x1", EFI, 0 },
169
{ "lv.cmp_ge.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x2", EFI, 0 },
170
{ "lv.cmp_ge.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x3", EFI, 0 },
171
{ "lv.cmp_gt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x4", EFI, 0 },
172
{ "lv.cmp_gt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x5", EFI, 0 },
173
{ "lv.cmp_le.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x6", EFI, 0 },
174
{ "lv.cmp_le.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x7", EFI, 0 },
175
{ "lv.cmp_lt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x8", EFI, 0 },
176
{ "lv.cmp_lt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x9", EFI, 0 },
177
{ "lv.cmp_ne.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0xA", EFI, 0 },
178
{ "lv.cmp_ne.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0xB", EFI, 0 },
179
{ "lv.madds.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x4", EFI, 0 },
180
{ "lv.max.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x5", EFI, 0 },
181
{ "lv.max.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x6", EFI, 0 },
182
{ "lv.merge.b","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x7", EFI, 0 },
183
{ "lv.merge.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x8", EFI, 0 },
184
{ "lv.min.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x9", EFI, 0 },
185
{ "lv.min.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xA", EFI, 0 },
186
{ "lv.msubs.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xB", EFI, 0 },
187
{ "lv.muls.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xC", EFI, 0 },
188
{ "lv.nand",   "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xD", EFI, 0 },
189
{ "lv.nor",    "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xE", EFI, 0 },
190
{ "lv.or",     "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xF", EFI, 0 },
191
{ "lv.pack.b", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x0", EFI, 0 },
192
{ "lv.pack.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x1", EFI, 0 },
193
{ "lv.packs.b","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x2", EFI, 0 },
194
{ "lv.packs.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x3", EFI, 0 },
195
{ "lv.packus.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x4", EFI, 0 },
196
{ "lv.packus.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x5", EFI, 0 },
197
{ "lv.perm.n", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x6", EFI, 0 },
198
{ "lv.rl.b",   "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x7", EFI, 0 },
199
{ "lv.rl.h",   "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x8", EFI, 0 },
200
{ "lv.sll.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x9", EFI, 0 },
201
{ "lv.sll.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xA", EFI, 0 },
202
{ "lv.sll",    "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xB", EFI, 0 },
203
{ "lv.srl.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xC", EFI, 0 },
204
{ "lv.srl.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xD", EFI, 0 },
205
{ "lv.sra.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xE", EFI, 0 },
206
{ "lv.sra.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xF", EFI, 0 },
207
{ "lv.srl",    "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x0", EFI, 0 },
208
{ "lv.sub.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x1", EFI, 0 },
209
{ "lv.sub.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x2", EFI, 0 },
210
{ "lv.subs.b", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x3", EFI, 0 },
211
{ "lv.subs.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x4", EFI, 0 },
212
{ "lv.subu.b", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x5", EFI, 0 },
213
{ "lv.subu.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x6", EFI, 0 },
214
{ "lv.subus.b","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x7", EFI, 0 },
215
{ "lv.subus.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x8", EFI, 0 },
216
{ "lv.unpack.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x9", EFI, 0 },
217
{ "lv.unpack.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0xA", EFI, 0 },
218
{ "lv.xor",    "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0xB", EFI, 0 },
219
{ "lv.cust1",  "",             "00 0xA  ----- ----- ---- ---- 0xC ----", EFI, 0 },
220
{ "lv.cust2",  "",             "00 0xA  ----- ----- ---- ---- 0xD ----", EFI, 0 },
221
{ "lv.cust3",  "",             "00 0xA  ----- ----- ---- ---- 0xE ----", EFI, 0 },
222
{ "lv.cust4",  "",             "00 0xA  ----- ----- ---- ---- 0xF ----", EFI, 0 },
223
 
224
{ "l.jr",      "rB",           "01 0x1  ----- ----- BBBB B--- ---- ----", EF(l_jr), OR32_IF_DELAY },
225
{ "l.jalr",    "rB",           "01 0x2  ----- ----- BBBB B--- ---- ----", EF(l_jalr), OR32_IF_DELAY },
226 676 markom
{ "l.maci",    "rB,I",         "01 0x3  IIIII ----- BBBB BIII IIII IIII", EF(l_mac), 0 },
227 174 markom
{ "l.cust1",   "",             "01 0xC  ----- ----- ---- ---- ---- ----", EF(l_cust1), 0 },
228
{ "l.cust2",   "",             "01 0xD  ----- ----- ---- ---- ---- ----", EF(l_cust2), 0 },
229
{ "l.cust3",   "",             "01 0xE  ----- ----- ---- ---- ---- ----", EF(l_cust3), 0 },
230
{ "l.cust4",   "",             "01 0xF  ----- ----- ---- ---- ---- ----", EF(l_cust4), 0 },
231 133 markom
 
232
{ "l.ld",      "rD,I(rA)",     "10 0x0  DDDDD AAAAA IIII IIII IIII IIII", EFI, 0 },
233
{ "l.lwz",     "rD,I(rA)",     "10 0x1  DDDDD AAAAA IIII IIII IIII IIII", EF(l_lwz), 0 },
234
{ "l.lws",     "rD,I(rA)",     "10 0x2  DDDDD AAAAA IIII IIII IIII IIII", EFI, 0 },
235
{ "l.lbz",     "rD,I(rA)",     "10 0x3  DDDDD AAAAA IIII IIII IIII IIII", EF(l_lbz), 0 },
236
{ "l.lbs",     "rD,I(rA)",     "10 0x4  DDDDD AAAAA IIII IIII IIII IIII", EF(l_lbs), 0 },
237
{ "l.lhz",     "rD,I(rA)",     "10 0x5  DDDDD AAAAA IIII IIII IIII IIII", EF(l_lhz), 0 },
238
{ "l.lhs",     "rD,I(rA)",     "10 0x6  DDDDD AAAAA IIII IIII IIII IIII", EF(l_lhs), 0 },
239
 
240 676 markom
{ "l.addi",    "rD,rA,I",      "10 0x7  DDDDD AAAAA IIII IIII IIII IIII", EF(l_add), OR32_W_FLAG },
241 133 markom
{ "l.addic",   "rD,rA,I",      "10 0x8  DDDDD AAAAA IIII IIII IIII IIII", EFI, 0 },
242 676 markom
{ "l.andi",    "rD,rA,K",      "10 0x9  DDDDD AAAAA KKKK KKKK KKKK KKKK", EF(l_and), OR32_W_FLAG },
243 133 markom
{ "l.ori",     "rD,rA,K",      "10 0xA  DDDDD AAAAA KKKK KKKK KKKK KKKK", EF(l_or), 0  },
244
{ "l.xori",    "rD,rA,I",      "10 0xB  DDDDD AAAAA IIII IIII IIII IIII", EF(l_xor), 0 },
245 801 markom
{ "l.muli",    "rD,rA,I",      "10 0xC  DDDDD AAAAA IIII IIII IIII IIII", EF(l_mul), 0 },
246 676 markom
{ "l.mfspr",   "rD,rA,K",      "10 0xD  DDDDD AAAAA KKKK KKKK KKKK KKKK", EF(l_mfspr), 0 },
247 133 markom
{ "l.slli",    "rD,rA,L",      "10 0xE  DDDDD AAAAA ---- ---- 00LL LLLL", EF(l_sll), 0 },
248
{ "l.srli",    "rD,rA,L",      "10 0xE  DDDDD AAAAA ---- ---- 01LL LLLL", EF(l_srl), 0 },
249
{ "l.srai",    "rD,rA,L",      "10 0xE  DDDDD AAAAA ---- ---- 10LL LLLL", EF(l_sra), 0 },
250
{ "l.rori",    "rD,rA,L",      "10 0xE  DDDDD AAAAA ---- ---- 11LL LLLL", EFI, 0 },
251
 
252 138 markom
{ "l.sfeqi",   "rA,I",         "10 0xF  00000 AAAAA IIII IIII IIII IIII", EF(l_sfeq), OR32_W_FLAG },
253
{ "l.sfnei",   "rA,I",         "10 0xF  00001 AAAAA IIII IIII IIII IIII", EF(l_sfne), OR32_W_FLAG },
254
{ "l.sfgtui",  "rA,I",         "10 0xF  00010 AAAAA IIII IIII IIII IIII", EF(l_sfgtu), OR32_W_FLAG },
255
{ "l.sfgeui",  "rA,I",         "10 0xF  00011 AAAAA IIII IIII IIII IIII", EF(l_sfgeu), OR32_W_FLAG },
256
{ "l.sfltui",  "rA,I",         "10 0xF  00100 AAAAA IIII IIII IIII IIII", EF(l_sfltu), OR32_W_FLAG },
257
{ "l.sfleui",  "rA,I",         "10 0xF  00101 AAAAA IIII IIII IIII IIII", EF(l_sfleu), OR32_W_FLAG },
258
{ "l.sfgtsi",  "rA,I",         "10 0xF  01010 AAAAA IIII IIII IIII IIII", EF(l_sfgts), OR32_W_FLAG },
259
{ "l.sfgesi",  "rA,I",         "10 0xF  01011 AAAAA IIII IIII IIII IIII", EF(l_sfges), OR32_W_FLAG },
260
{ "l.sfltsi",  "rA,I",         "10 0xF  01100 AAAAA IIII IIII IIII IIII", EF(l_sflts), OR32_W_FLAG },
261
{ "l.sflesi",  "rA,I",         "10 0xF  01101 AAAAA IIII IIII IIII IIII", EF(l_sfles), OR32_W_FLAG },
262 133 markom
 
263 676 markom
{ "l.mtspr",   "rA,rB,K",      "11 0x0  KKKKK AAAAA BBBB BKKK KKKK KKKK", EF(l_mtspr), 0 },
264
{ "l.mac",     "rA,rB",        "11 0x1  ----- AAAAA BBBB B--- ---- 0x1", EF(l_mac), 0 }, /*MM*/
265
{ "l.msb",     "rA,rB",        "11 0x1  ----- AAAAA BBBB B--- ---- 0x2", EF(l_msb), 0 }, /*MM*/
266
 
267 1295 lampret
{ "lf.add.s",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x0", EF(lf_add_s), 0 },
268
{ "lf.sub.s",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x1", EF(lf_sub_s), 0 },
269
{ "lf.mul.s",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x2", EF(lf_mul_s), 0 },
270
{ "lf.div.s",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x3", EF(lf_div_s), 0 },
271
{ "lf.itof.s",  "rD,rA",       "11 0x2  DDDDD AAAAA 0000 0--- 0x0 0x4", EF(lf_itof_s), 0 },
272
{ "lf.ftoi.s",  "rD,rA",       "11 0x2  DDDDD AAAAA 0000 0--- 0x0 0x5", EF(lf_ftoi_s), 0 },
273
{ "lf.rem.s",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x6", EF(lf_rem_s), 0 },
274
{ "lf.madd.s",  "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x7", EF(lf_madd_s), 0 },
275
{ "lf.sfeq.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0x8", EF(lf_sfeq_s), 0 },
276
{ "lf.sfne.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0x9", EF(lf_sfne_s), 0 },
277
{ "lf.sfgt.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0xA", EF(lf_sfgt_s), 0 },
278
{ "lf.sfge.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0xB", EF(lf_sfge_s), 0 },
279
{ "lf.sflt.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0xC", EF(lf_sflt_s), 0 },
280
{ "lf.sfle.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0xD", EF(lf_sfle_s), 0 },
281
{ "lf.cust1.s", "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0xD ----", EFI, 0 },
282
 
283
{ "lf.add.d",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x0", EFI, 0 },
284
{ "lf.sub.d",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x1", EFI, 0 },
285
{ "lf.mul.d",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x2", EFI, 0 },
286
{ "lf.div.d",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x3", EFI, 0 },
287
{ "lf.itof.d",  "rD,rA",       "11 0x2  DDDDD AAAAA 0000 0--- 0x1 0x4", EFI, 0 },
288
{ "lf.ftoi.d",  "rD,rA",       "11 0x2  DDDDD AAAAA 0000 0--- 0x1 0x5", EFI, 0 },
289
{ "lf.rem.d",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x6", EFI, 0 },
290
{ "lf.madd.d",  "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x7", EFI, 0 },
291
{ "lf.sfeq.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0x8", EFI, 0 },
292
{ "lf.sfne.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0x9", EFI, 0 },
293
{ "lf.sfgt.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0xA", EFI, 0 },
294
{ "lf.sfge.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0xB", EFI, 0 },
295
{ "lf.sflt.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0xC", EFI, 0 },
296
{ "lf.sfle.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0xD", EFI, 0 },
297
{ "lf.cust1.d", "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0xE ----", EFI, 0 },
298
 
299 1341 nogj
{ "l.sd",      "I(rD),rB",     "11 0x4  IIIII DDDDD BBBB BIII IIII IIII", EFI, 0 },
300
{ "l.sw",      "I(rD),rB",     "11 0x5  IIIII DDDDD BBBB BIII IIII IIII", EF(l_sw), 0 },
301
{ "l.sb",      "I(rD),rB",     "11 0x6  IIIII DDDDD BBBB BIII IIII IIII", EF(l_sb), 0 },
302
{ "l.sh",      "I(rD),rB",     "11 0x7  IIIII DDDDD BBBB BIII IIII IIII", EF(l_sh), 0 },
303 133 markom
 
304 676 markom
{ "l.add",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x0", EF(l_add), OR32_W_FLAG },
305 1169 csanchez
{ "l.addc",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x1", EF(l_addc), OR32_W_FLAG },
306 133 markom
{ "l.sub",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x2", EF(l_sub), 0 },
307 676 markom
{ "l.and",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x3", EF(l_and), OR32_W_FLAG },
308 133 markom
{ "l.or",      "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x4", EF(l_or), 0 },
309
{ "l.xor",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x5", EF(l_xor), 0 },
310
{ "l.mul",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-11 ---- 0x6", EF(l_mul), 0 },
311 676 markom
 
312 133 markom
{ "l.sll",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 00-- 0x8", EF(l_sll), 0 },
313
{ "l.srl",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 01-- 0x8", EF(l_srl), 0 },
314
{ "l.sra",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 10-- 0x8", EF(l_sra), 0 },
315
{ "l.ror",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 11-- 0x8", EFI, 0 },
316 1034 lampret
{ "l.div",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-11 ---- 0x9", EF(l_div), 0 },
317
{ "l.divu",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-11 ---- 0xA", EF(l_divu), 0 },
318 133 markom
{ "l.mulu",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-11 ---- 0xB", EFI, 0 },
319 1295 lampret
{ "l.extbs",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 01-- 0xC", EF(l_extbs), 0 },
320
{ "l.exths",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 00-- 0xC", EF(l_exths), 0 },
321
{ "l.extws",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 00-- 0xD", EF(l_extws), 0 },
322
{ "l.extbz",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 11-- 0xC", EF(l_extbz), 0 },
323
{ "l.exthz",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 10-- 0xC", EF(l_exthz), 0 },
324
{ "l.extwz",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 01-- 0xD", EF(l_extwz), 0 },
325 676 markom
{ "l.cmov",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0xE", EF(l_cmov), OR32_R_FLAG },
326 1338 andreje
{ "l.ff1",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0xF", EF(l_ff1), 0 },
327
 
328 138 markom
{ "l.sfeq",    "rA,rB",        "11 0x9  00000 AAAAA BBBB B--- ---- ----", EF(l_sfeq), OR32_W_FLAG },
329
{ "l.sfne",    "rA,rB",        "11 0x9  00001 AAAAA BBBB B--- ---- ----", EF(l_sfne), OR32_W_FLAG },
330
{ "l.sfgtu",   "rA,rB",        "11 0x9  00010 AAAAA BBBB B--- ---- ----", EF(l_sfgtu), OR32_W_FLAG },
331
{ "l.sfgeu",   "rA,rB",        "11 0x9  00011 AAAAA BBBB B--- ---- ----", EF(l_sfgeu), OR32_W_FLAG },
332
{ "l.sfltu",   "rA,rB",        "11 0x9  00100 AAAAA BBBB B--- ---- ----", EF(l_sfltu), OR32_W_FLAG },
333
{ "l.sfleu",   "rA,rB",        "11 0x9  00101 AAAAA BBBB B--- ---- ----", EF(l_sfleu), OR32_W_FLAG },
334
{ "l.sfgts",   "rA,rB",        "11 0x9  01010 AAAAA BBBB B--- ---- ----", EF(l_sfgts), OR32_W_FLAG },
335
{ "l.sfges",   "rA,rB",        "11 0x9  01011 AAAAA BBBB B--- ---- ----", EF(l_sfges), OR32_W_FLAG },
336
{ "l.sflts",   "rA,rB",        "11 0x9  01100 AAAAA BBBB B--- ---- ----", EF(l_sflts), OR32_W_FLAG },
337
{ "l.sfles",   "rA,rB",        "11 0x9  01101 AAAAA BBBB B--- ---- ----", EF(l_sfles), OR32_W_FLAG },
338 133 markom
 
339 1285 lampret
{ "l.cust5",   "rD,rA,rB,L,K", "11 0xC  DDDDD AAAAA BBBB BLLL LLLK KKKK", EFI, 0 },
340 133 markom
{ "l.cust6",   "",             "11 0xD  ----- ----- ---- ---- ---- ----", EFI, 0 },
341
{ "l.cust7",   "",             "11 0xE  ----- ----- ---- ---- ---- ----", EFI, 0 },
342
{ "l.cust8",   "",             "11 0xF  ----- ----- ---- ---- ---- ----", EFI, 0 },
343
 
344 221 markom
/* This section should not be defined in or1ksim, since it contains duplicates,
345
   which would cause machine builder to complain.  */
346 374 simons
#ifdef HAS_CUST
347 221 markom
{ "l.cust5_1",   "rD",         "11 0xC  DDDDD ----- ---- ---- ---- ----", EFI, 0 },
348
{ "l.cust5_2",   "rD,rA"   ,   "11 0xC  DDDDD AAAAA ---- ---- ---- ----", EFI, 0 },
349
{ "l.cust5_3",   "rD,rA,rB",   "11 0xC  DDDDD AAAAA BBBB B--- ---- ----", EFI, 0 },
350
 
351
{ "l.cust6_1",   "rD",         "11 0xD  DDDDD ----- ---- ---- ---- ----", EFI, 0 },
352
{ "l.cust6_2",   "rD,rA"   ,   "11 0xD  DDDDD AAAAA ---- ---- ---- ----", EFI, 0 },
353
{ "l.cust6_3",   "rD,rA,rB",   "11 0xD  DDDDD AAAAA BBBB B--- ---- ----", EFI, 0 },
354
 
355
{ "l.cust7_1",   "rD",         "11 0xE  DDDDD ----- ---- ---- ---- ----", EFI, 0 },
356
{ "l.cust7_2",   "rD,rA"   ,   "11 0xE  DDDDD AAAAA ---- ---- ---- ----", EFI, 0 },
357
{ "l.cust7_3",   "rD,rA,rB",   "11 0xE  DDDDD AAAAA BBBB B--- ---- ----", EFI, 0 },
358
 
359
{ "l.cust8_1",   "rD",         "11 0xF  DDDDD ----- ---- ---- ---- ----", EFI, 0 },
360
{ "l.cust8_2",   "rD,rA"   ,   "11 0xF  DDDDD AAAAA ---- ---- ---- ----", EFI, 0 },
361
{ "l.cust8_3",   "rD,rA,rB",   "11 0xF  DDDDD AAAAA BBBB B--- ---- ----", EFI, 0 },
362
#endif
363
 
364 133 markom
{ "", "", "", EFI, 0 }           /* Dummy entry, not included in num_opcodes.  This
365
                           lets code examine entry i+1 without checking
366
                           if we've run off the end of the table.  */
367
};
368
 
369
#undef EFI
370
#undef EFN
371
#undef EF 
372
 
373
/* **INDENT-ON** */
374
 
375 371 markom
/* Define dummy, if debug is not defined.  */
376 1341 nogj
#ifndef HAS_DEBUG
377
#define debug(l, fmt...) ;
378 371 markom
#endif
379 133 markom
 
380 371 markom
CONST int num_opcodes = ((sizeof(or32_opcodes)) / (sizeof(struct or32_opcode))) - 1;
381
 
382 138 markom
/* Calculates instruction length in bytes. Always 4 for OR32. */
383
int
384
insn_len(int insn_index)
385 133 markom
{
386
  insn_index = 0; /* Just to get rid that warning.  */
387
  return 4;
388
}
389
 
390
/* Is individual insn's operand signed or unsigned? */
391 138 markom
int
392
letter_signed(char l)
393 133 markom
{
394
  CONST struct or32_letter *pletter;
395
 
396
  for(pletter = or32_letters; pletter->letter != '\0'; pletter++)
397
    if (pletter->letter == l)
398
      return pletter->sign;
399
 
400
  printf("letter_signed(%c): Unknown letter.\n", l);
401
  return 0;
402
}
403
 
404 703 markom
/* Simple cache for letter ranges */
405
static int range_cache[256] = {0};
406
 
407 133 markom
/* Number of letters in the individual lettered operand. */
408 138 markom
int
409
letter_range(char l)
410 133 markom
{
411
  CONST struct or32_opcode *pinsn;
412
  char *enc;
413
  int range = 0;
414 703 markom
 
415
  /* Is value cached? */
416 1308 phoenix
  if ((range = range_cache[(unsigned char)l])) return range;
417 133 markom
 
418 138 markom
  for(pinsn = or32_opcodes; strlen(pinsn->name); pinsn++)
419
    {
420
      if (strchr(pinsn->encoding,l))
421
        {
422
          for (enc = pinsn->encoding; *enc != '\0'; enc++)
423
            if ((*enc == '0') && (*(enc+1) == 'x'))
424
              enc += 2;
425
            else if (*enc == l)
426
              range++;
427 703 markom
          return range_cache[(unsigned char)l] = range;
428 133 markom
        }
429
    }
430 703 markom
 
431 133 markom
  printf("\nABORT: letter_range(%c): Never used letter.\n", l);
432
  exit(1);
433
}
434
 
435
/* MM: Returns index of given instruction name.  */
436 138 markom
int
437
insn_index (char *insn)
438
{
439 133 markom
  int i, found = -1;
440 371 markom
  for (i = 0; i < num_opcodes; i++)
441 138 markom
    if (!strcmp (or32_opcodes[i].name, insn))
442
      {
443
        found = i;
444
        break;
445
      }
446 133 markom
  return found;
447
}
448
 
449 717 markom
/* Returns name of the specified instruction index */
450
CONST char *
451
insn_name(int index)
452 138 markom
{
453 371 markom
  if (index >= 0 && index < num_opcodes)
454 133 markom
    return or32_opcodes[index].name;
455
  else
456
    return "???";
457
}
458
 
459 1342 nogj
#if defined(HAS_EXECUTION) && SIMPLE_EXECUTION
460 717 markom
void
461 1342 nogj
l_none(struct iqueue_entry *current)
462
{
463
}
464
#else
465
void
466 717 markom
l_none()
467 138 markom
{
468 133 markom
}
469 1342 nogj
#endif
470 133 markom
 
471
/*** Finite automata for instruction decoding building code ***/
472
 
473 1341 nogj
/* Find symbols in encoding.  */
474 706 markom
unsigned long
475 133 markom
insn_extract(param_ch, enc_initial)
476
     char param_ch;
477
     char *enc_initial;
478
{
479
  char *enc;
480
  unsigned long ret = 0;
481
  unsigned opc_pos = 32;
482
  for (enc = enc_initial; *enc != '\0'; )
483
    if ((*enc == '0') && (*(enc+1) == 'x'))
484
      {
485
        unsigned long tmp = strtol(enc+2, NULL, 16);
486
        opc_pos -= 4;
487 138 markom
        if (param_ch == '0' || param_ch == '1')
488
          {
489
            if (param_ch == '0')
490
              tmp = 15 - tmp;
491
            ret |= tmp << opc_pos;
492
          }
493 133 markom
        enc += 3;
494
      }
495 138 markom
    else
496
      {
497
        if (*enc == '0' || *enc == '1' || *enc == '-' || isalpha(*enc) )
498
          {
499
            opc_pos--;
500
            if (param_ch == *enc)
501
              ret |= 1 << opc_pos;
502
          }
503
        enc++;
504 133 markom
      }
505
  return ret;
506
}
507
 
508 138 markom
#define MAX_AUTOMATA_SIZE (1200)
509
#define MAX_OP_TABLE_SIZE (1200)
510 133 markom
#define MAX_LEN           (8)
511
 
512
#ifndef MIN
513
# define MIN(x,y)          ((x) < (y) ? (x) : (y))
514
#endif
515
 
516
unsigned long *automata;
517
int nuncovered;
518
int curpass = 0;
519
 
520 1341 nogj
/* MM: Struct that holds runtime build information about instructions.  */
521 1342 nogj
struct temp_insn_struct *ti;
522 138 markom
 
523
struct insn_op_struct *op_data, **op_start;
524
 
525
/* Recursive utility function used to find best match and to build automata.  */
526
 
527
static unsigned long *
528
cover_insn (unsigned long *cur, int pass, unsigned int mask)
529
{
530 133 markom
  int best_first = 0, best_len = 0, i, last_match = -1, ninstr = 0;
531
  unsigned long cur_mask = mask;
532
  unsigned long *next;
533
 
534
  for (i = 0; i < num_opcodes; i++)
535 138 markom
    if (ti[i].in_pass == pass)
536
      {
537
        cur_mask &= ti[i].insn_mask;
538
        ninstr++;
539
        last_match = i;
540
      }
541
 
542 344 markom
  debug(8, "%08X %08X\n", mask, cur_mask);
543 138 markom
  if (ninstr == 0)
544
    return 0;
545
  if (ninstr == 1)
546
    {
547
      /* Leaf holds instruction index. */
548 344 markom
      debug(8, "%i>I%i %s\n", cur - automata, last_match, or32_opcodes[last_match].name);
549 138 markom
      *cur = LEAF_FLAG | last_match;
550
      cur++;
551
      nuncovered--;
552
    } else {
553
      /* Find longest match.  */
554
      for (i = 0; i < 32; i++)
555
        {
556
          int len;
557
          for (len = best_len + 1; len < MIN(MAX_LEN, 33 - i); len++)
558
            {
559
              unsigned long m = (1UL << ((unsigned long)len)) - 1;
560 344 markom
              debug(9, " (%i(%08X & %08X>>%i = %08X, %08X)",len,m, cur_mask, i, (cur_mask >> (unsigned)i), (cur_mask >> (unsigned)i) & m);
561 138 markom
              if ((m & (cur_mask >> (unsigned)i)) == m)
562
                {
563
                  best_len = len;
564
                  best_first = i;
565 344 markom
                  debug(9, "!");
566 138 markom
                }
567
              else
568
                break;
569
            }
570
        }
571 344 markom
      debug(9, "\n");
572 138 markom
      if (!best_len)
573
        {
574
          fprintf (stderr, "%i instructions match mask 0x%08X:\n", ninstr, mask);
575
          for (i = 0; i < num_opcodes; i++)
576
            if (ti[i].in_pass == pass)
577
              fprintf (stderr, "%s ", or32_opcodes[i].name);
578
 
579
          fprintf (stderr, "\n");
580
          exit (1);
581
        }
582 344 markom
      debug(8, "%i> #### %i << %i (%i) ####\n", cur - automata, best_len, best_first, ninstr);
583 138 markom
      *cur = best_first;
584
      cur++;
585
      *cur = (1 << best_len) - 1;
586
      cur++;
587
      next = cur;
588
      /* Allocate space for pointers.  */
589
      cur += 1 << best_len;
590
      cur_mask = (1 << (unsigned long)best_len) - 1;
591
 
592
      for (i = 0; i < (1 << (unsigned long)best_len); i++)
593
        {
594
          int j;
595
          unsigned long *c;
596
          curpass++;
597
          for (j = 0; j < num_opcodes; j++)
598
            if (ti[j].in_pass == pass
599 371 markom
                && ((ti[j].insn >> best_first) & cur_mask) == (unsigned long) i
600 138 markom
                && ((ti[j].insn_mask >> best_first) & cur_mask) == cur_mask)
601
              ti[j].in_pass = curpass;
602
 
603 344 markom
          debug(9, "%08X %08X %i\n", mask, cur_mask, best_first);
604 138 markom
          c = cover_insn (cur, curpass, mask & (~(cur_mask << best_first)));
605
          if (c)
606
            {
607 344 markom
              debug(8, "%i> #%X -> %u\n", next - automata, i, cur - automata);
608 138 markom
              *next = cur - automata;
609
              cur = c;
610
            }
611
          else
612
            {
613 344 markom
              debug(8, "%i> N/A\n", next - automata);
614 138 markom
              *next = 0;
615
            }
616
          next++;
617
        }
618 133 markom
    }
619 138 markom
  return cur;
620
}
621 133 markom
 
622 138 markom
/* Returns number of nonzero bits. */
623
static int
624
num_ones (unsigned long value)
625
{
626
  int c = 0;
627
  while (value)
628
    {
629
      if (value & 1)
630
        c++;
631
      value >>= 1;
632 133 markom
    }
633 138 markom
  return c;
634
}
635 133 markom
 
636 138 markom
/* Utility function, which converts parameters from or32_opcode format to more binary form.
637
   Parameters are stored in ti struct.  */
638
 
639
static struct insn_op_struct *
640
parse_params (CONST struct or32_opcode *opcode, struct insn_op_struct *cur)
641
{
642
  char *args = opcode->args;
643
  int i, type;
644
 
645
  i = 0;
646
  type = 0;
647 262 markom
  /* In case we don't have any parameters, we add dummy read from r0.  */
648
  if (!(*args)) {
649 263 markom
    cur->type = OPTYPE_REG | OPTYPE_OP | OPTYPE_LAST;
650 262 markom
    cur->data = 0;
651 355 markom
    debug(9, "#%08X %08X\n", cur->type, cur->data);
652 262 markom
    cur++;
653
    return cur;
654
  }
655
 
656 138 markom
  while (*args != '\0')
657
    {
658
      if (*args == 'r')
659
        {
660
          args++;
661
          type |= OPTYPE_REG;
662 1341 nogj
          if(args[1] == 'D')
663
            type |= OPTYPE_DST;
664 133 markom
        }
665 138 markom
      else if (isalpha (*args))
666
        {
667
          unsigned long arg;
668
          arg = insn_extract(*args, opcode->encoding);
669 355 markom
          debug(9, "%s : %08X ------\n", opcode->name, arg);
670 138 markom
          if (letter_signed (*args))
671
            {
672
              type |= OPTYPE_SIG;
673
              type |= ((num_ones (arg) - 1) << OPTYPE_SBIT_SHR) & OPTYPE_SBIT;
674
            }
675
 
676
          /* Split argument to sequences of consecutive ones.  */
677
          while (arg)
678
            {
679
              int shr = 0;
680
              unsigned long tmp = arg, mask = 0;
681
              while ((tmp & 1) == 0)
682
                {
683
                  shr++;
684
                  tmp >>= 1;
685
                }
686
              while (tmp & 1)
687
                {
688
                  mask++;
689
                  tmp >>= 1;
690
                }
691
              cur->type = type | shr;
692
              cur->data = mask;
693
              arg &= ~(((1 << mask) - 1) << shr);
694 355 markom
              debug(6, "|%08X %08X\n", cur->type, cur->data);
695 138 markom
              cur++;
696
            }
697
          args++;
698
        }
699
      else if (*args == '(')
700
        {
701
          /* Next param is displacement.  Later we will treat them as one operand.  */
702
          cur--;
703
          cur->type = type | cur->type | OPTYPE_DIS | OPTYPE_OP;
704 355 markom
          debug(9, ">%08X %08X\n", cur->type, cur->data);
705 138 markom
          cur++;
706
          type = 0;
707
          i++;
708
          args++;
709
        }
710
      else if (*args == OPERAND_DELIM)
711
        {
712
          cur--;
713
          cur->type = type | cur->type | OPTYPE_OP;
714 355 markom
          debug(9, ">%08X %08X\n", cur->type, cur->data);
715 138 markom
          cur++;
716
          type = 0;
717
          i++;
718
          args++;
719
        }
720
      else if (*args == '0')
721
        {
722
          cur->type = type;
723
          cur->data = 0;
724 355 markom
          debug(9, ">%08X %08X\n", cur->type, cur->data);
725 138 markom
          cur++;
726
          type = 0;
727
          i++;
728
          args++;
729
        }
730
      else if (*args == ')')
731
        args++;
732
      else
733
        {
734
          fprintf (stderr, "%s : parse error in args.\n", opcode->name);
735
          exit (1);
736
        }
737 133 markom
    }
738 138 markom
  cur--;
739
  cur->type = type | cur->type | OPTYPE_OP | OPTYPE_LAST;
740 355 markom
  debug(9, "#%08X %08X\n", cur->type, cur->data);
741 138 markom
  cur++;
742 133 markom
  return cur;
743
}
744
 
745 138 markom
/* Constructs new automata based on or32_opcodes array.  */
746
 
747
void
748
build_automata()
749
{
750 371 markom
  int i;
751 133 markom
  unsigned long *end;
752 138 markom
  struct insn_op_struct *cur;
753
 
754 133 markom
  automata = (unsigned long *) malloc (MAX_AUTOMATA_SIZE * sizeof (unsigned long));
755 138 markom
  ti = (struct temp_insn_struct *) malloc (sizeof (struct temp_insn_struct) * num_opcodes);
756 133 markom
 
757
  nuncovered = num_opcodes;
758 709 markom
 
759
#ifdef HAS_EXECUTION
760 138 markom
  printf("Building automata... ");
761 709 markom
#endif
762
 
763 133 markom
  /* Build temporary information about instructions.  */
764 138 markom
  for (i = 0; i < num_opcodes; i++)
765
    {
766
      unsigned long ones, zeros;
767
      char *encoding = or32_opcodes[i].encoding;
768
      ones  = insn_extract('1', encoding);
769
      zeros = insn_extract('0', encoding);
770
      ti[i].insn_mask = ones | zeros;
771
      ti[i].insn = ones;
772
      ti[i].in_pass = curpass = 0;
773 344 markom
      /*debug(9, "%s: %s %08X %08X\n", or32_opcodes[i].name,
774 138 markom
        or32_opcodes[i].encoding, ti[i].insn_mask, ti[i].insn);*/
775
    }
776 133 markom
 
777
  /* Until all are covered search for best criteria to separate them.  */
778 138 markom
  end = cover_insn (automata, curpass, 0xFFFFFFFF);
779
  if (end - automata > MAX_AUTOMATA_SIZE)
780
    {
781
      fprintf (stderr, "Automata too large. Increase MAX_AUTOMATA_SIZE.");
782
      exit (1);
783
    }
784 709 markom
#ifdef HAS_EXECUTION
785 138 markom
  printf("done, num uncovered: %i/%i.\n", nuncovered, num_opcodes);
786 709 markom
#endif
787 371 markom
 
788 709 markom
#ifdef HAS_EXECUTION
789 138 markom
  printf("Parsing operands data... ");
790 709 markom
#endif
791 138 markom
  op_data = (struct insn_op_struct *) malloc (MAX_OP_TABLE_SIZE * sizeof (struct insn_op_struct));
792
  op_start = (struct insn_op_struct **) malloc (num_opcodes * sizeof (struct insn_op_struct *));
793
  cur = op_data;
794
  for (i = 0; i < num_opcodes; i++)
795
    {
796
      op_start[i] = cur;
797
      cur = parse_params (&or32_opcodes[i], cur);
798
      if (cur - op_data > MAX_OP_TABLE_SIZE)
799
        {
800
          fprintf (stderr, "Operands table too small, increase MAX_OP_TABLE_SIZE.\n");
801
          exit (1);
802
        }
803
    }
804 709 markom
#ifdef HAS_EXECUTION
805 138 markom
  printf("done.\n");
806 709 markom
#endif
807 133 markom
}
808
 
809 138 markom
void destruct_automata ()
810
{
811
  free (ti);
812 133 markom
  free (automata);
813 138 markom
  free (op_data);
814
  free (op_start);
815 133 markom
}
816
 
817
/* Decodes instruction and returns instruction index.  */
818 138 markom
int insn_decode (unsigned int insn)
819
{
820 133 markom
  unsigned long *a = automata;
821 138 markom
  int i;
822
  while (!(*a & LEAF_FLAG))
823
    {
824
      unsigned int first = *a;
825 703 markom
      //debug(9, "%i ", a - automata);
826 138 markom
      a++;
827
      i = (insn >> first) & *a;
828
      a++;
829
      if (!*(a + i))
830
        { /* Invalid instruction found?  */
831 703 markom
          //debug(9, "XXX\n", i);
832 138 markom
          return -1;
833
        }
834
      a = automata + *(a + i);
835
    }
836
  i = *a & ~LEAF_FLAG;
837 703 markom
  //debug(9, "%i\n", i);
838 138 markom
  /* Final check - do we have direct match?
839
     (based on or32_opcodes this should be the only possibility,
840
     but in case of invalid/missing instruction we must perform a check)  */
841
  if ((ti[i].insn_mask & insn) == ti[i].insn)
842
    return i;
843
  else
844
    return -1;
845 133 markom
}
846 371 markom
 
847
static char disassembled_str[50];
848
char *disassembled = &disassembled_str[0];
849
 
850
/* Automagically does zero- or sign- extension and also finds correct
851
   sign bit position if sign extension is correct extension. Which extension
852
   is proper is figured out from letter description. */
853
 
854 879 markom
unsigned long
855 371 markom
extend_imm(unsigned long imm, char l)
856
{
857
  unsigned long mask;
858
  int letter_bits;
859
 
860
  /* First truncate all bits above valid range for this letter
861
     in case it is zero extend. */
862
  letter_bits = letter_range(l);
863
  mask = (1 << letter_bits) - 1;
864
  imm &= mask;
865
 
866
  /* Do sign extend if this is the right one. */
867
  if (letter_signed(l) && (imm >> (letter_bits - 1)))
868
    imm |= (~mask);
869
 
870
  return imm;
871
}
872
 
873 879 markom
unsigned long
874 371 markom
or32_extract(param_ch, enc_initial, insn)
875
     char param_ch;
876
     char *enc_initial;
877
     unsigned long insn;
878
{
879
  char *enc;
880
  unsigned long ret = 0;
881
  int opc_pos = 0;
882
  int param_pos = 0;
883
 
884
  for (enc = enc_initial; *enc != '\0'; enc++)
885
    if (*enc == param_ch)
886
      {
887
        if (enc - 2 >= enc_initial && (*(enc - 2) == '0') && (*(enc - 1) == 'x'))
888
          continue;
889
        else
890
          param_pos++;
891
      }
892
 
893
#if DEBUG
894
  printf("or32_extract: %x ", param_pos);
895
#endif
896
  opc_pos = 32;
897
  for (enc = enc_initial; *enc != '\0'; )
898
    if ((*enc == '0') && (*(enc+1) == 'x'))
899
      {
900
        opc_pos -= 4;
901
        if ((param_ch == '0') || (param_ch == '1'))
902
          {
903
            unsigned long tmp = strtol(enc, NULL, 16);
904
#if DEBUG
905
            printf(" enc=%s, tmp=%x ", enc, tmp);
906
#endif
907
            if (param_ch == '0')
908
              tmp = 15 - tmp;
909
            ret |= tmp << opc_pos;
910
          }
911
        enc += 3;
912
      }
913
    else if ((*enc == '0') || (*enc == '1'))
914
      {
915
        opc_pos--;
916
        if (param_ch == *enc)
917
          ret |= 1 << opc_pos;
918
        enc++;
919
      }
920
    else if (*enc == param_ch)
921
      {
922
        opc_pos--;
923
        param_pos--;
924
#if DEBUG
925
        printf("\n  ret=%x opc_pos=%x, param_pos=%x\n", ret, opc_pos, param_pos);
926
#endif  
927
        if (islower(param_ch))
928
          ret -= ((insn >> opc_pos) & 0x1) << param_pos;
929
        else
930
          ret += ((insn >> opc_pos) & 0x1) << param_pos;
931
        enc++;
932
      }
933
    else if (isalpha(*enc))
934
      {
935
        opc_pos--;
936
        enc++;
937
      }
938
    else if (*enc == '-')
939
      {
940
        opc_pos--;
941
        enc++;
942
      }
943
    else
944
      enc++;
945
 
946
#if DEBUG
947
  printf ("ret=%x\n", ret);
948
#endif
949
  return ret;
950
}
951
 
952
/* Print register. Used only by print_insn. */
953
 
954 703 markom
static char *
955
or32_print_register (dest, param_ch, encoding, insn)
956
     char *dest;
957 371 markom
     char param_ch;
958
     char *encoding;
959
     unsigned long insn;
960
{
961
  int regnum = or32_extract(param_ch, encoding, insn);
962
 
963 703 markom
  sprintf (dest, "r%d", regnum);
964
  while (*dest) dest++;
965
  return dest;
966 371 markom
}
967
 
968
/* Print immediate. Used only by print_insn. */
969
 
970 703 markom
static char *
971
or32_print_immediate (dest, param_ch, encoding, insn)
972
     char *dest;
973 371 markom
     char param_ch;
974
     char *encoding;
975
     unsigned long insn;
976
{
977
  int imm = or32_extract (param_ch, encoding, insn);
978
 
979
  imm = extend_imm(imm, param_ch);
980
 
981
  if (letter_signed(param_ch))
982
    {
983
      if (imm < 0)
984 703 markom
        sprintf (dest, "%d", imm);
985 371 markom
      else
986 703 markom
        sprintf (dest, "0x%x", imm);
987 371 markom
    }
988
  else
989 703 markom
    sprintf (dest, "%#x", imm);
990
  while (*dest) dest++;
991
  return dest;
992 371 markom
}
993
 
994
/* Disassemble one instruction from insn to disassemble.
995
   Return the size of the instruction.  */
996
 
997
int
998
disassemble_insn (insn)
999
     unsigned long insn;
1000
{
1001 703 markom
  return disassemble_index (insn, insn_decode (insn));
1002
}
1003 371 markom
 
1004 703 markom
/* Disassemble one instruction from insn index.
1005
   Return the size of the instruction.  */
1006
 
1007
int
1008
disassemble_index (insn, index)
1009
     unsigned long insn;
1010
     int index;
1011
{
1012
  char *dest = disassembled;
1013 371 markom
  if (index >= 0)
1014
    {
1015
      struct or32_opcode const *opcode = &or32_opcodes[index];
1016
      char *s;
1017
 
1018 703 markom
      strcpy (dest, opcode->name);
1019
      while (*dest) dest++;
1020
      *dest++ = ' ';
1021
      *dest = 0;
1022
 
1023 371 markom
      for (s = opcode->args; *s != '\0'; ++s)
1024
        {
1025
          switch (*s)
1026
            {
1027
            case '\0':
1028 703 markom
              return insn_len (insn);
1029 714 markom
 
1030 371 markom
            case 'r':
1031 703 markom
              dest = or32_print_register(dest, *++s, opcode->encoding, insn);
1032 371 markom
              break;
1033 714 markom
 
1034 371 markom
            default:
1035
              if (strchr (opcode->encoding, *s))
1036 703 markom
                dest = or32_print_immediate (dest, *s, opcode->encoding, insn);
1037
              else {
1038
                *dest++ = *s;
1039
                *dest = 0;
1040
              }
1041 371 markom
            }
1042
        }
1043
    }
1044
  else
1045
    {
1046
      /* This used to be %8x for binutils.  */
1047 1308 phoenix
      sprintf(dest, ".word 0x%08lx", insn);
1048 703 markom
      while (*dest) dest++;
1049 371 markom
    }
1050
  return insn_len (insn);
1051
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.