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

Subversion Repositories or1k

[/] [or1k/] [tags/] [pre-GNU-merge/] [insight/] [opcodes/] [or32.c] - Blame information for rev 1778

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 627 markom
{ "l.nop",     "K",            "00 0x5  01--- ----- KKKK KKKK KKKK KKKK", EF(l_nop), 0 },
81 133 markom
{ "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 627 markom
 
84 133 markom
{ "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.jr",      "rB",           "01 0x1  ----- ----- BBBB B--- ---- ----", EF(l_jr), OR32_IF_DELAY },
221
{ "l.jalr",    "rB",           "01 0x2  ----- ----- BBBB B--- ---- ----", EF(l_jalr), OR32_IF_DELAY },
222 627 markom
{ "l.maci",    "rB,I",         "01 0x3  IIIII ----- BBBB BIII IIII IIII", EF(l_mac), 0 },
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 627 markom
{ "l.addi",    "rD,rA,I",      "10 0x7  DDDDD AAAAA IIII IIII IIII IIII", EF(l_add), OR32_W_FLAG },
237 133 markom
{ "l.addic",   "rD,rA,I",      "10 0x8  DDDDD AAAAA IIII IIII IIII IIII", EFI, 0 },
238 627 markom
{ "l.andi",    "rD,rA,K",      "10 0x9  DDDDD AAAAA KKKK KKKK KKKK KKKK", EF(l_and), OR32_W_FLAG },
239 133 markom
{ "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 627 markom
{ "l.mfspr",   "rD,rA,K",      "10 0xD  DDDDD AAAAA KKKK KKKK KKKK KKKK", EF(l_mfspr), 0 },
243 133 markom
{ "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 627 markom
{ "l.mtspr",   "rA,rB,K",      "11 0x0  KKKKK AAAAA BBBB BKKK KKKK KKKK", EF(l_mtspr), 0 },
260
{ "l.mac",     "rA,rB",        "11 0x1  ----- AAAAA BBBB B--- ---- 0x1", EF(l_mac), 0 }, /*MM*/
261
{ "l.msb",     "rA,rB",        "11 0x1  ----- AAAAA BBBB B--- ---- 0x2", EF(l_msb), 0 }, /*MM*/
262
 
263 133 markom
{ "l.sd",      "I(rA),rB",     "11 0x4  IIIII AAAAA BBBB BIII IIII IIII", EFI, 0 },
264
{ "l.sw",      "I(rA),rB",     "11 0x5  IIIII AAAAA BBBB BIII IIII IIII", EF(l_sw), 0 },
265
{ "l.sb",      "I(rA),rB",     "11 0x6  IIIII AAAAA BBBB BIII IIII IIII", EF(l_sb), 0 },
266
{ "l.sh",      "I(rA),rB",     "11 0x7  IIIII AAAAA BBBB BIII IIII IIII", EF(l_sh), 0 },
267
 
268 627 markom
{ "l.add",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x0", EF(l_add), OR32_W_FLAG },
269 133 markom
{ "l.addc",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x1", EFI, 0 },
270
{ "l.sub",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x2", EF(l_sub), 0 },
271 627 markom
{ "l.and",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x3", EF(l_and), OR32_W_FLAG },
272 133 markom
{ "l.or",      "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x4", EF(l_or), 0 },
273
{ "l.xor",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x5", EF(l_xor), 0 },
274
{ "l.mul",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-11 ---- 0x6", EF(l_mul), 0 },
275 627 markom
 
276 133 markom
{ "l.sll",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 00-- 0x8", EF(l_sll), 0 },
277
{ "l.srl",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 01-- 0x8", EF(l_srl), 0 },
278
{ "l.sra",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 10-- 0x8", EF(l_sra), 0 },
279
{ "l.ror",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 11-- 0x8", EFI, 0 },
280
{ "l.div",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x9", EF(l_div), 0 },
281
{ "l.divu",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0xA", EF(l_divu), 0 },
282
{ "l.mulu",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-11 ---- 0xB", EFI, 0 },
283 627 markom
{ "l.extbs",   "rD,rA,rB",     "11 0x8  DDDDD AAAAA ---- --00 01-- 0xC", EF(l_extbs), 0 },
284
{ "l.exths",   "rD,rA,rB",     "11 0x8  DDDDD AAAAA ---- --00 00-- 0xC", EF(l_exths), 0 },
285
{ "l.extws",   "rD,rA,rB",     "11 0x8  DDDDD AAAAA ---- --00 00-- 0xD", EF(l_extws), 0 },
286
{ "l.extbz",   "rD,rA,rB",     "11 0x8  DDDDD AAAAA ---- --00 11-- 0xC", EF(l_extbz), 0 },
287
{ "l.exthz",   "rD,rA,rB",     "11 0x8  DDDDD AAAAA ---- --00 10-- 0xC", EF(l_exthz), 0 },
288
{ "l.extwz",   "rD,rA,rB",     "11 0x8  DDDDD AAAAA ---- --00 01-- 0xD", EF(l_extwz), 0 },
289
{ "l.cmov",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0xE", EF(l_cmov), OR32_R_FLAG },
290 133 markom
{ "l.ff1",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0xF", EFI, 0 },
291
 
292 138 markom
{ "l.sfeq",    "rA,rB",        "11 0x9  00000 AAAAA BBBB B--- ---- ----", EF(l_sfeq), OR32_W_FLAG },
293
{ "l.sfne",    "rA,rB",        "11 0x9  00001 AAAAA BBBB B--- ---- ----", EF(l_sfne), OR32_W_FLAG },
294
{ "l.sfgtu",   "rA,rB",        "11 0x9  00010 AAAAA BBBB B--- ---- ----", EF(l_sfgtu), OR32_W_FLAG },
295
{ "l.sfgeu",   "rA,rB",        "11 0x9  00011 AAAAA BBBB B--- ---- ----", EF(l_sfgeu), OR32_W_FLAG },
296
{ "l.sfltu",   "rA,rB",        "11 0x9  00100 AAAAA BBBB B--- ---- ----", EF(l_sfltu), OR32_W_FLAG },
297
{ "l.sfleu",   "rA,rB",        "11 0x9  00101 AAAAA BBBB B--- ---- ----", EF(l_sfleu), OR32_W_FLAG },
298
{ "l.sfgts",   "rA,rB",        "11 0x9  01010 AAAAA BBBB B--- ---- ----", EF(l_sfgts), OR32_W_FLAG },
299
{ "l.sfges",   "rA,rB",        "11 0x9  01011 AAAAA BBBB B--- ---- ----", EF(l_sfges), OR32_W_FLAG },
300
{ "l.sflts",   "rA,rB",        "11 0x9  01100 AAAAA BBBB B--- ---- ----", EF(l_sflts), OR32_W_FLAG },
301
{ "l.sfles",   "rA,rB",        "11 0x9  01101 AAAAA BBBB B--- ---- ----", EF(l_sfles), OR32_W_FLAG },
302 133 markom
 
303
{ "l.cust5",   "",             "11 0xC  ----- ----- ---- ---- ---- ----", EFI, 0 },
304
{ "l.cust6",   "",             "11 0xD  ----- ----- ---- ---- ---- ----", EFI, 0 },
305
{ "l.cust7",   "",             "11 0xE  ----- ----- ---- ---- ---- ----", EFI, 0 },
306
{ "l.cust8",   "",             "11 0xF  ----- ----- ---- ---- ---- ----", EFI, 0 },
307
 
308 221 markom
/* This section should not be defined in or1ksim, since it contains duplicates,
309
   which would cause machine builder to complain.  */
310 374 simons
#ifdef HAS_CUST
311 221 markom
{ "l.cust5_1",   "rD",         "11 0xC  DDDDD ----- ---- ---- ---- ----", EFI, 0 },
312
{ "l.cust5_2",   "rD,rA"   ,   "11 0xC  DDDDD AAAAA ---- ---- ---- ----", EFI, 0 },
313
{ "l.cust5_3",   "rD,rA,rB",   "11 0xC  DDDDD AAAAA BBBB B--- ---- ----", EFI, 0 },
314
 
315
{ "l.cust6_1",   "rD",         "11 0xD  DDDDD ----- ---- ---- ---- ----", EFI, 0 },
316
{ "l.cust6_2",   "rD,rA"   ,   "11 0xD  DDDDD AAAAA ---- ---- ---- ----", EFI, 0 },
317
{ "l.cust6_3",   "rD,rA,rB",   "11 0xD  DDDDD AAAAA BBBB B--- ---- ----", EFI, 0 },
318
 
319
{ "l.cust7_1",   "rD",         "11 0xE  DDDDD ----- ---- ---- ---- ----", EFI, 0 },
320
{ "l.cust7_2",   "rD,rA"   ,   "11 0xE  DDDDD AAAAA ---- ---- ---- ----", EFI, 0 },
321
{ "l.cust7_3",   "rD,rA,rB",   "11 0xE  DDDDD AAAAA BBBB B--- ---- ----", EFI, 0 },
322
 
323
{ "l.cust8_1",   "rD",         "11 0xF  DDDDD ----- ---- ---- ---- ----", EFI, 0 },
324
{ "l.cust8_2",   "rD,rA"   ,   "11 0xF  DDDDD AAAAA ---- ---- ---- ----", EFI, 0 },
325
{ "l.cust8_3",   "rD,rA,rB",   "11 0xF  DDDDD AAAAA BBBB B--- ---- ----", EFI, 0 },
326
#endif
327
 
328 133 markom
{ "", "", "", EFI, 0 }           /* Dummy entry, not included in num_opcodes.  This
329
                           lets code examine entry i+1 without checking
330
                           if we've run off the end of the table.  */
331
};
332
 
333
#undef EFI
334
#undef EFN
335
#undef EF 
336
 
337
/* **INDENT-ON** */
338
 
339 371 markom
/* Define dummy, if debug is not defined.  */
340
#if !defined HAS_DEBUG
341
void debug(int level, const char *format, ...)
342
{
343
  /* Just to get rid of warnings.  */
344
  format = level = 0;
345
}
346
#endif
347 133 markom
 
348 371 markom
CONST int num_opcodes = ((sizeof(or32_opcodes)) / (sizeof(struct or32_opcode))) - 1;
349
 
350 138 markom
/* Calculates instruction length in bytes. Always 4 for OR32. */
351
int
352
insn_len(int insn_index)
353 133 markom
{
354
  insn_index = 0; /* Just to get rid that warning.  */
355
  return 4;
356
}
357
 
358
/* Is individual insn's operand signed or unsigned? */
359 138 markom
int
360
letter_signed(char l)
361 133 markom
{
362
  CONST struct or32_letter *pletter;
363
 
364
  for(pletter = or32_letters; pletter->letter != '\0'; pletter++)
365
    if (pletter->letter == l)
366
      return pletter->sign;
367
 
368
  printf("letter_signed(%c): Unknown letter.\n", l);
369
  return 0;
370
}
371
 
372
/* Number of letters in the individual lettered operand. */
373 138 markom
int
374
letter_range(char l)
375 133 markom
{
376
  CONST struct or32_opcode *pinsn;
377
  char *enc;
378
  int range = 0;
379
 
380 138 markom
  for(pinsn = or32_opcodes; strlen(pinsn->name); pinsn++)
381
    {
382
      if (strchr(pinsn->encoding,l))
383
        {
384
          for (enc = pinsn->encoding; *enc != '\0'; enc++)
385
            if ((*enc == '0') && (*(enc+1) == 'x'))
386
              enc += 2;
387
            else if (*enc == l)
388
              range++;
389
          return range;
390 133 markom
        }
391
    }
392
  printf("\nABORT: letter_range(%c): Never used letter.\n", l);
393
  exit(1);
394
}
395
 
396
/* MM: Returns index of given instruction name.  */
397 138 markom
int
398
insn_index (char *insn)
399
{
400 133 markom
  int i, found = -1;
401 371 markom
  for (i = 0; i < num_opcodes; i++)
402 138 markom
    if (!strcmp (or32_opcodes[i].name, insn))
403
      {
404
        found = i;
405
        break;
406
      }
407 133 markom
  return found;
408
}
409
 
410 138 markom
CONST char *insn_name(int index)
411
{
412 371 markom
  if (index >= 0 && index < num_opcodes)
413 133 markom
    return or32_opcodes[index].name;
414
  else
415
    return "???";
416
}
417
 
418 138 markom
void l_none()
419
{
420 133 markom
}
421
 
422
 
423
/*** Finite automata for instruction decoding building code ***/
424
 
425
/* Find simbols in encoding.  */
426
static unsigned long
427
insn_extract(param_ch, enc_initial)
428
     char param_ch;
429
     char *enc_initial;
430
{
431
  char *enc;
432
  unsigned long ret = 0;
433
  unsigned opc_pos = 32;
434
  for (enc = enc_initial; *enc != '\0'; )
435
    if ((*enc == '0') && (*(enc+1) == 'x'))
436
      {
437
        unsigned long tmp = strtol(enc+2, NULL, 16);
438
        opc_pos -= 4;
439 138 markom
        if (param_ch == '0' || param_ch == '1')
440
          {
441
            if (param_ch == '0')
442
              tmp = 15 - tmp;
443
            ret |= tmp << opc_pos;
444
          }
445 133 markom
        enc += 3;
446
      }
447 138 markom
    else
448
      {
449
        if (*enc == '0' || *enc == '1' || *enc == '-' || isalpha(*enc) )
450
          {
451
            opc_pos--;
452
            if (param_ch == *enc)
453
              ret |= 1 << opc_pos;
454
          }
455
        enc++;
456 133 markom
      }
457
  return ret;
458
}
459
 
460 138 markom
#define MAX_AUTOMATA_SIZE (1200)
461
#define MAX_OP_TABLE_SIZE (1200)
462 133 markom
#define LEAF_FLAG         (0x80000000)
463
#define MAX_LEN           (8)
464
 
465
#ifndef MIN
466
# define MIN(x,y)          ((x) < (y) ? (x) : (y))
467
#endif
468
 
469
unsigned long *automata;
470
int nuncovered;
471
int curpass = 0;
472
 
473 138 markom
/* MM: Struct that hold runtime build information about instructions.  */
474
struct temp_insn_struct
475
{
476
  unsigned long insn;
477
  unsigned long insn_mask;
478
  int in_pass;
479
} *ti;
480
 
481
struct insn_op_struct *op_data, **op_start;
482
 
483
/* Recursive utility function used to find best match and to build automata.  */
484
 
485
static unsigned long *
486
cover_insn (unsigned long *cur, int pass, unsigned int mask)
487
{
488 133 markom
  int best_first = 0, best_len = 0, i, last_match = -1, ninstr = 0;
489
  unsigned long cur_mask = mask;
490
  unsigned long *next;
491
 
492
  for (i = 0; i < num_opcodes; i++)
493 138 markom
    if (ti[i].in_pass == pass)
494
      {
495
        cur_mask &= ti[i].insn_mask;
496
        ninstr++;
497
        last_match = i;
498
      }
499
 
500 344 markom
  debug(8, "%08X %08X\n", mask, cur_mask);
501 138 markom
  if (ninstr == 0)
502
    return 0;
503
  if (ninstr == 1)
504
    {
505
      /* Leaf holds instruction index. */
506 344 markom
      debug(8, "%i>I%i %s\n", cur - automata, last_match, or32_opcodes[last_match].name);
507 138 markom
      *cur = LEAF_FLAG | last_match;
508
      cur++;
509
      nuncovered--;
510
    } else {
511
      /* Find longest match.  */
512
      for (i = 0; i < 32; i++)
513
        {
514
          int len;
515
          for (len = best_len + 1; len < MIN(MAX_LEN, 33 - i); len++)
516
            {
517
              unsigned long m = (1UL << ((unsigned long)len)) - 1;
518 344 markom
              debug(9, " (%i(%08X & %08X>>%i = %08X, %08X)",len,m, cur_mask, i, (cur_mask >> (unsigned)i), (cur_mask >> (unsigned)i) & m);
519 138 markom
              if ((m & (cur_mask >> (unsigned)i)) == m)
520
                {
521
                  best_len = len;
522
                  best_first = i;
523 344 markom
                  debug(9, "!");
524 138 markom
                }
525
              else
526
                break;
527
            }
528
        }
529 344 markom
      debug(9, "\n");
530 138 markom
      if (!best_len)
531
        {
532
          fprintf (stderr, "%i instructions match mask 0x%08X:\n", ninstr, mask);
533
          for (i = 0; i < num_opcodes; i++)
534
            if (ti[i].in_pass == pass)
535
              fprintf (stderr, "%s ", or32_opcodes[i].name);
536
 
537
          fprintf (stderr, "\n");
538
          exit (1);
539
        }
540 344 markom
      debug(8, "%i> #### %i << %i (%i) ####\n", cur - automata, best_len, best_first, ninstr);
541 138 markom
      *cur = best_first;
542
      cur++;
543
      *cur = (1 << best_len) - 1;
544
      cur++;
545
      next = cur;
546
      /* Allocate space for pointers.  */
547
      cur += 1 << best_len;
548
      cur_mask = (1 << (unsigned long)best_len) - 1;
549
 
550
      for (i = 0; i < (1 << (unsigned long)best_len); i++)
551
        {
552
          int j;
553
          unsigned long *c;
554
          curpass++;
555
          for (j = 0; j < num_opcodes; j++)
556
            if (ti[j].in_pass == pass
557 371 markom
                && ((ti[j].insn >> best_first) & cur_mask) == (unsigned long) i
558 138 markom
                && ((ti[j].insn_mask >> best_first) & cur_mask) == cur_mask)
559
              ti[j].in_pass = curpass;
560
 
561 344 markom
          debug(9, "%08X %08X %i\n", mask, cur_mask, best_first);
562 138 markom
          c = cover_insn (cur, curpass, mask & (~(cur_mask << best_first)));
563
          if (c)
564
            {
565 344 markom
              debug(8, "%i> #%X -> %u\n", next - automata, i, cur - automata);
566 138 markom
              *next = cur - automata;
567
              cur = c;
568
            }
569
          else
570
            {
571 344 markom
              debug(8, "%i> N/A\n", next - automata);
572 138 markom
              *next = 0;
573
            }
574
          next++;
575
        }
576 133 markom
    }
577 138 markom
  return cur;
578
}
579 133 markom
 
580 138 markom
/* Returns number of nonzero bits. */
581
static int
582
num_ones (unsigned long value)
583
{
584
  int c = 0;
585
  while (value)
586
    {
587
      if (value & 1)
588
        c++;
589
      value >>= 1;
590 133 markom
    }
591 138 markom
  return c;
592
}
593 133 markom
 
594 138 markom
/* Utility function, which converts parameters from or32_opcode format to more binary form.
595
   Parameters are stored in ti struct.  */
596
 
597
static struct insn_op_struct *
598
parse_params (CONST struct or32_opcode *opcode, struct insn_op_struct *cur)
599
{
600
  char *args = opcode->args;
601
  int i, type;
602
 
603
  i = 0;
604
  type = 0;
605 262 markom
  /* In case we don't have any parameters, we add dummy read from r0.  */
606
  if (!(*args)) {
607 263 markom
    cur->type = OPTYPE_REG | OPTYPE_OP | OPTYPE_LAST;
608 262 markom
    cur->data = 0;
609 355 markom
    debug(9, "#%08X %08X\n", cur->type, cur->data);
610 262 markom
    cur++;
611
    return cur;
612
  }
613
 
614 138 markom
  while (*args != '\0')
615
    {
616
      if (*args == 'r')
617
        {
618
          args++;
619
          type |= OPTYPE_REG;
620 133 markom
        }
621 138 markom
      else if (isalpha (*args))
622
        {
623
          unsigned long arg;
624
          arg = insn_extract(*args, opcode->encoding);
625 355 markom
          debug(9, "%s : %08X ------\n", opcode->name, arg);
626 138 markom
          if (letter_signed (*args))
627
            {
628
              type |= OPTYPE_SIG;
629
              type |= ((num_ones (arg) - 1) << OPTYPE_SBIT_SHR) & OPTYPE_SBIT;
630
            }
631
 
632
          /* Split argument to sequences of consecutive ones.  */
633
          while (arg)
634
            {
635
              int shr = 0;
636
              unsigned long tmp = arg, mask = 0;
637
              while ((tmp & 1) == 0)
638
                {
639
                  shr++;
640
                  tmp >>= 1;
641
                }
642
              while (tmp & 1)
643
                {
644
                  mask++;
645
                  tmp >>= 1;
646
                }
647
              cur->type = type | shr;
648
              cur->data = mask;
649
              arg &= ~(((1 << mask) - 1) << shr);
650 355 markom
              debug(6, "|%08X %08X\n", cur->type, cur->data);
651 138 markom
              cur++;
652
            }
653
          args++;
654
        }
655
      else if (*args == '(')
656
        {
657
          /* Next param is displacement.  Later we will treat them as one operand.  */
658
          cur--;
659
          cur->type = type | cur->type | OPTYPE_DIS | OPTYPE_OP;
660 355 markom
          debug(9, ">%08X %08X\n", cur->type, cur->data);
661 138 markom
          cur++;
662
          type = 0;
663
          i++;
664
          args++;
665
        }
666
      else if (*args == OPERAND_DELIM)
667
        {
668
          cur--;
669
          cur->type = type | cur->type | OPTYPE_OP;
670 355 markom
          debug(9, ">%08X %08X\n", cur->type, cur->data);
671 138 markom
          cur++;
672
          type = 0;
673
          i++;
674
          args++;
675
        }
676
      else if (*args == '0')
677
        {
678
          cur->type = type;
679
          cur->data = 0;
680 355 markom
          debug(9, ">%08X %08X\n", cur->type, cur->data);
681 138 markom
          cur++;
682
          type = 0;
683
          i++;
684
          args++;
685
        }
686
      else if (*args == ')')
687
        args++;
688
      else
689
        {
690
          fprintf (stderr, "%s : parse error in args.\n", opcode->name);
691
          exit (1);
692
        }
693 133 markom
    }
694 138 markom
  cur--;
695
  cur->type = type | cur->type | OPTYPE_OP | OPTYPE_LAST;
696 355 markom
  debug(9, "#%08X %08X\n", cur->type, cur->data);
697 138 markom
  cur++;
698 133 markom
  return cur;
699
}
700
 
701 138 markom
/* Constructs new automata based on or32_opcodes array.  */
702
 
703
void
704
build_automata()
705
{
706 371 markom
  int i;
707 133 markom
  unsigned long *end;
708 138 markom
  struct insn_op_struct *cur;
709
 
710 133 markom
  automata = (unsigned long *) malloc (MAX_AUTOMATA_SIZE * sizeof (unsigned long));
711 138 markom
  ti = (struct temp_insn_struct *) malloc (sizeof (struct temp_insn_struct) * num_opcodes);
712 133 markom
 
713
  nuncovered = num_opcodes;
714 138 markom
  printf("Building automata... ");
715 133 markom
  /* Build temporary information about instructions.  */
716 138 markom
  for (i = 0; i < num_opcodes; i++)
717
    {
718
      unsigned long ones, zeros;
719
      char *encoding = or32_opcodes[i].encoding;
720
      ones  = insn_extract('1', encoding);
721
      zeros = insn_extract('0', encoding);
722
      ti[i].insn_mask = ones | zeros;
723
      ti[i].insn = ones;
724
      ti[i].in_pass = curpass = 0;
725 344 markom
      /*debug(9, "%s: %s %08X %08X\n", or32_opcodes[i].name,
726 138 markom
        or32_opcodes[i].encoding, ti[i].insn_mask, ti[i].insn);*/
727
    }
728 133 markom
 
729
  /* Until all are covered search for best criteria to separate them.  */
730 138 markom
  end = cover_insn (automata, curpass, 0xFFFFFFFF);
731
  if (end - automata > MAX_AUTOMATA_SIZE)
732
    {
733
      fprintf (stderr, "Automata too large. Increase MAX_AUTOMATA_SIZE.");
734
      exit (1);
735
    }
736
  printf("done, num uncovered: %i/%i.\n", nuncovered, num_opcodes);
737 371 markom
 
738 138 markom
  printf("Parsing operands data... ");
739
  op_data = (struct insn_op_struct *) malloc (MAX_OP_TABLE_SIZE * sizeof (struct insn_op_struct));
740
  op_start = (struct insn_op_struct **) malloc (num_opcodes * sizeof (struct insn_op_struct *));
741
  cur = op_data;
742
  for (i = 0; i < num_opcodes; i++)
743
    {
744
      op_start[i] = cur;
745
      cur = parse_params (&or32_opcodes[i], cur);
746
      if (cur - op_data > MAX_OP_TABLE_SIZE)
747
        {
748
          fprintf (stderr, "Operands table too small, increase MAX_OP_TABLE_SIZE.\n");
749
          exit (1);
750
        }
751
    }
752
  printf("done.\n");
753 133 markom
}
754
 
755 138 markom
void destruct_automata ()
756
{
757
  free (ti);
758 133 markom
  free (automata);
759 138 markom
  free (op_data);
760
  free (op_start);
761 133 markom
}
762
 
763
/* Decodes instruction and returns instruction index.  */
764 138 markom
int insn_decode (unsigned int insn)
765
{
766 133 markom
  unsigned long *a = automata;
767 138 markom
  int i;
768
  while (!(*a & LEAF_FLAG))
769
    {
770
      unsigned int first = *a;
771 355 markom
      debug(9, "%i ", a - automata);
772 138 markom
      a++;
773
      i = (insn >> first) & *a;
774
      a++;
775
      if (!*(a + i))
776
        { /* Invalid instruction found?  */
777 355 markom
          debug(9, "XXX\n", i);
778 138 markom
          return -1;
779
        }
780
      a = automata + *(a + i);
781
    }
782
  i = *a & ~LEAF_FLAG;
783 355 markom
  debug(9, "%i\n", i);
784 138 markom
  /* Final check - do we have direct match?
785
     (based on or32_opcodes this should be the only possibility,
786
     but in case of invalid/missing instruction we must perform a check)  */
787
  if ((ti[i].insn_mask & insn) == ti[i].insn)
788
    return i;
789
  else
790
    return -1;
791 133 markom
}
792 371 markom
 
793
static char disassembled_str[50];
794
char *disassembled = &disassembled_str[0];
795
 
796
/* Automagically does zero- or sign- extension and also finds correct
797
   sign bit position if sign extension is correct extension. Which extension
798
   is proper is figured out from letter description. */
799
 
800
unsigned long
801
extend_imm(unsigned long imm, char l)
802
{
803
  unsigned long mask;
804
  int letter_bits;
805
 
806
  /* First truncate all bits above valid range for this letter
807
     in case it is zero extend. */
808
  letter_bits = letter_range(l);
809
  mask = (1 << letter_bits) - 1;
810
  imm &= mask;
811
 
812
  /* Do sign extend if this is the right one. */
813
  if (letter_signed(l) && (imm >> (letter_bits - 1)))
814
    imm |= (~mask);
815
 
816
  return imm;
817
}
818
 
819
static unsigned long
820
or32_extract(param_ch, enc_initial, insn)
821
     char param_ch;
822
     char *enc_initial;
823
     unsigned long insn;
824
{
825
  char *enc;
826
  unsigned long ret = 0;
827
  int opc_pos = 0;
828
  int param_pos = 0;
829
 
830
  for (enc = enc_initial; *enc != '\0'; enc++)
831
    if (*enc == param_ch)
832
      {
833
        if (enc - 2 >= enc_initial && (*(enc - 2) == '0') && (*(enc - 1) == 'x'))
834
          continue;
835
        else
836
          param_pos++;
837
      }
838
 
839
#if DEBUG
840
  printf("or32_extract: %x ", param_pos);
841
#endif
842
  opc_pos = 32;
843
  for (enc = enc_initial; *enc != '\0'; )
844
    if ((*enc == '0') && (*(enc+1) == 'x'))
845
      {
846
        opc_pos -= 4;
847
        if ((param_ch == '0') || (param_ch == '1'))
848
          {
849
            unsigned long tmp = strtol(enc, NULL, 16);
850
#if DEBUG
851
            printf(" enc=%s, tmp=%x ", enc, tmp);
852
#endif
853
            if (param_ch == '0')
854
              tmp = 15 - tmp;
855
            ret |= tmp << opc_pos;
856
          }
857
        enc += 3;
858
      }
859
    else if ((*enc == '0') || (*enc == '1'))
860
      {
861
        opc_pos--;
862
        if (param_ch == *enc)
863
          ret |= 1 << opc_pos;
864
        enc++;
865
      }
866
    else if (*enc == param_ch)
867
      {
868
        opc_pos--;
869
        param_pos--;
870
#if DEBUG
871
        printf("\n  ret=%x opc_pos=%x, param_pos=%x\n", ret, opc_pos, param_pos);
872
#endif  
873
        if (islower(param_ch))
874
          ret -= ((insn >> opc_pos) & 0x1) << param_pos;
875
        else
876
          ret += ((insn >> opc_pos) & 0x1) << param_pos;
877
        enc++;
878
      }
879
    else if (isalpha(*enc))
880
      {
881
        opc_pos--;
882
        enc++;
883
      }
884
    else if (*enc == '-')
885
      {
886
        opc_pos--;
887
        enc++;
888
      }
889
    else
890
      enc++;
891
 
892
#if DEBUG
893
  printf ("ret=%x\n", ret);
894
#endif
895
  return ret;
896
}
897
 
898
/* Print register. Used only by print_insn. */
899
 
900
static void
901
or32_print_register (param_ch, encoding, insn)
902
     char param_ch;
903
     char *encoding;
904
     unsigned long insn;
905
{
906
  int regnum = or32_extract(param_ch, encoding, insn);
907
 
908
   sprintf (disassembled, "%sr%d", disassembled, regnum);
909
}
910
 
911
/* Print immediate. Used only by print_insn. */
912
 
913
static void
914
or32_print_immediate (param_ch, encoding, insn)
915
     char param_ch;
916
     char *encoding;
917
     unsigned long insn;
918
{
919
  int imm = or32_extract (param_ch, encoding, insn);
920
 
921
  imm = extend_imm(imm, param_ch);
922
 
923
  if (letter_signed(param_ch))
924
    {
925
      if (imm < 0)
926
        sprintf (disassembled, "%s%d", disassembled, imm);
927
      else
928
        sprintf (disassembled, "%s0x%x", disassembled, imm);
929
    }
930
  else
931
    sprintf (disassembled, "%s%#x", disassembled, imm);
932
}
933
 
934
/* Disassemble one instruction from insn to disassemble.
935
   Return the size of the instruction.  */
936
 
937
int
938
disassemble_insn (insn)
939
     unsigned long insn;
940
{
941
  int index;
942
  index = insn_decode (insn);
943
 
944
  if (index >= 0)
945
    {
946
      struct or32_opcode const *opcode = &or32_opcodes[index];
947
      char *s;
948
 
949
      sprintf(disassembled, "%s ", opcode->name);
950
      for (s = opcode->args; *s != '\0'; ++s)
951
        {
952
          switch (*s)
953
            {
954
            case '\0':
955
              return 4;
956
 
957
            case 'r':
958
              or32_print_register(*++s, opcode->encoding, insn);
959
              break;
960
 
961
            default:
962
              if (strchr (opcode->encoding, *s))
963
                or32_print_immediate (*s, opcode->encoding, insn);
964
              else
965
                sprintf(disassembled, "%s%c", disassembled, *s);
966
            }
967
        }
968
    }
969
  else
970
    {
971
      /* This used to be %8x for binutils.  */
972
      sprintf(disassembled, "%s.word 0x%08x", disassembled, insn);
973
    }
974
  return insn_len (insn);
975
}

powered by: WebSVN 2.1.0

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