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 371

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

powered by: WebSVN 2.1.0

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