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 1286

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

powered by: WebSVN 2.1.0

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