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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_36/] [insight/] [opcodes/] [or32.c] - Blame information for rev 1295

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

powered by: WebSVN 2.1.0

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