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 1169

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

powered by: WebSVN 2.1.0

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