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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [opcodes/] [or32.c] - Blame information for rev 1308

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

powered by: WebSVN 2.1.0

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