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 703

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 676 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 676 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 676 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 676 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 676 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 676 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 676 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 676 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 676 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 676 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 676 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 703 markom
/* Simple cache for letter ranges */
373
static int range_cache[256] = {0};
374
 
375 133 markom
/* Number of letters in the individual lettered operand. */
376 138 markom
int
377
letter_range(char l)
378 133 markom
{
379
  CONST struct or32_opcode *pinsn;
380
  char *enc;
381
  int range = 0;
382 703 markom
 
383
  /* Is value cached? */
384
  if (range = range_cache[(unsigned char)l]) return range;
385 133 markom
 
386 138 markom
  for(pinsn = or32_opcodes; strlen(pinsn->name); pinsn++)
387
    {
388
      if (strchr(pinsn->encoding,l))
389
        {
390
          for (enc = pinsn->encoding; *enc != '\0'; enc++)
391
            if ((*enc == '0') && (*(enc+1) == 'x'))
392
              enc += 2;
393
            else if (*enc == l)
394
              range++;
395 703 markom
          return range_cache[(unsigned char)l] = range;
396 133 markom
        }
397
    }
398 703 markom
 
399 133 markom
  printf("\nABORT: letter_range(%c): Never used letter.\n", l);
400
  exit(1);
401
}
402
 
403
/* MM: Returns index of given instruction name.  */
404 138 markom
int
405
insn_index (char *insn)
406
{
407 133 markom
  int i, found = -1;
408 371 markom
  for (i = 0; i < num_opcodes; i++)
409 138 markom
    if (!strcmp (or32_opcodes[i].name, insn))
410
      {
411
        found = i;
412
        break;
413
      }
414 133 markom
  return found;
415
}
416
 
417 138 markom
CONST char *insn_name(int index)
418
{
419 371 markom
  if (index >= 0 && index < num_opcodes)
420 133 markom
    return or32_opcodes[index].name;
421
  else
422
    return "???";
423
}
424
 
425 138 markom
void l_none()
426
{
427 133 markom
}
428
 
429
 
430
/*** Finite automata for instruction decoding building code ***/
431
 
432
/* Find simbols in encoding.  */
433
static unsigned long
434
insn_extract(param_ch, enc_initial)
435
     char param_ch;
436
     char *enc_initial;
437
{
438
  char *enc;
439
  unsigned long ret = 0;
440
  unsigned opc_pos = 32;
441
  for (enc = enc_initial; *enc != '\0'; )
442
    if ((*enc == '0') && (*(enc+1) == 'x'))
443
      {
444
        unsigned long tmp = strtol(enc+2, NULL, 16);
445
        opc_pos -= 4;
446 138 markom
        if (param_ch == '0' || param_ch == '1')
447
          {
448
            if (param_ch == '0')
449
              tmp = 15 - tmp;
450
            ret |= tmp << opc_pos;
451
          }
452 133 markom
        enc += 3;
453
      }
454 138 markom
    else
455
      {
456
        if (*enc == '0' || *enc == '1' || *enc == '-' || isalpha(*enc) )
457
          {
458
            opc_pos--;
459
            if (param_ch == *enc)
460
              ret |= 1 << opc_pos;
461
          }
462
        enc++;
463 133 markom
      }
464
  return ret;
465
}
466
 
467 138 markom
#define MAX_AUTOMATA_SIZE (1200)
468
#define MAX_OP_TABLE_SIZE (1200)
469 133 markom
#define LEAF_FLAG         (0x80000000)
470
#define MAX_LEN           (8)
471
 
472
#ifndef MIN
473
# define MIN(x,y)          ((x) < (y) ? (x) : (y))
474
#endif
475
 
476
unsigned long *automata;
477
int nuncovered;
478
int curpass = 0;
479
 
480 138 markom
/* MM: Struct that hold runtime build information about instructions.  */
481
struct temp_insn_struct
482
{
483
  unsigned long insn;
484
  unsigned long insn_mask;
485
  int in_pass;
486
} *ti;
487
 
488
struct insn_op_struct *op_data, **op_start;
489
 
490
/* Recursive utility function used to find best match and to build automata.  */
491
 
492
static unsigned long *
493
cover_insn (unsigned long *cur, int pass, unsigned int mask)
494
{
495 133 markom
  int best_first = 0, best_len = 0, i, last_match = -1, ninstr = 0;
496
  unsigned long cur_mask = mask;
497
  unsigned long *next;
498
 
499
  for (i = 0; i < num_opcodes; i++)
500 138 markom
    if (ti[i].in_pass == pass)
501
      {
502
        cur_mask &= ti[i].insn_mask;
503
        ninstr++;
504
        last_match = i;
505
      }
506
 
507 344 markom
  debug(8, "%08X %08X\n", mask, cur_mask);
508 138 markom
  if (ninstr == 0)
509
    return 0;
510
  if (ninstr == 1)
511
    {
512
      /* Leaf holds instruction index. */
513 344 markom
      debug(8, "%i>I%i %s\n", cur - automata, last_match, or32_opcodes[last_match].name);
514 138 markom
      *cur = LEAF_FLAG | last_match;
515
      cur++;
516
      nuncovered--;
517
    } else {
518
      /* Find longest match.  */
519
      for (i = 0; i < 32; i++)
520
        {
521
          int len;
522
          for (len = best_len + 1; len < MIN(MAX_LEN, 33 - i); len++)
523
            {
524
              unsigned long m = (1UL << ((unsigned long)len)) - 1;
525 344 markom
              debug(9, " (%i(%08X & %08X>>%i = %08X, %08X)",len,m, cur_mask, i, (cur_mask >> (unsigned)i), (cur_mask >> (unsigned)i) & m);
526 138 markom
              if ((m & (cur_mask >> (unsigned)i)) == m)
527
                {
528
                  best_len = len;
529
                  best_first = i;
530 344 markom
                  debug(9, "!");
531 138 markom
                }
532
              else
533
                break;
534
            }
535
        }
536 344 markom
      debug(9, "\n");
537 138 markom
      if (!best_len)
538
        {
539
          fprintf (stderr, "%i instructions match mask 0x%08X:\n", ninstr, mask);
540
          for (i = 0; i < num_opcodes; i++)
541
            if (ti[i].in_pass == pass)
542
              fprintf (stderr, "%s ", or32_opcodes[i].name);
543
 
544
          fprintf (stderr, "\n");
545
          exit (1);
546
        }
547 344 markom
      debug(8, "%i> #### %i << %i (%i) ####\n", cur - automata, best_len, best_first, ninstr);
548 138 markom
      *cur = best_first;
549
      cur++;
550
      *cur = (1 << best_len) - 1;
551
      cur++;
552
      next = cur;
553
      /* Allocate space for pointers.  */
554
      cur += 1 << best_len;
555
      cur_mask = (1 << (unsigned long)best_len) - 1;
556
 
557
      for (i = 0; i < (1 << (unsigned long)best_len); i++)
558
        {
559
          int j;
560
          unsigned long *c;
561
          curpass++;
562
          for (j = 0; j < num_opcodes; j++)
563
            if (ti[j].in_pass == pass
564 371 markom
                && ((ti[j].insn >> best_first) & cur_mask) == (unsigned long) i
565 138 markom
                && ((ti[j].insn_mask >> best_first) & cur_mask) == cur_mask)
566
              ti[j].in_pass = curpass;
567
 
568 344 markom
          debug(9, "%08X %08X %i\n", mask, cur_mask, best_first);
569 138 markom
          c = cover_insn (cur, curpass, mask & (~(cur_mask << best_first)));
570
          if (c)
571
            {
572 344 markom
              debug(8, "%i> #%X -> %u\n", next - automata, i, cur - automata);
573 138 markom
              *next = cur - automata;
574
              cur = c;
575
            }
576
          else
577
            {
578 344 markom
              debug(8, "%i> N/A\n", next - automata);
579 138 markom
              *next = 0;
580
            }
581
          next++;
582
        }
583 133 markom
    }
584 138 markom
  return cur;
585
}
586 133 markom
 
587 138 markom
/* Returns number of nonzero bits. */
588
static int
589
num_ones (unsigned long value)
590
{
591
  int c = 0;
592
  while (value)
593
    {
594
      if (value & 1)
595
        c++;
596
      value >>= 1;
597 133 markom
    }
598 138 markom
  return c;
599
}
600 133 markom
 
601 138 markom
/* Utility function, which converts parameters from or32_opcode format to more binary form.
602
   Parameters are stored in ti struct.  */
603
 
604
static struct insn_op_struct *
605
parse_params (CONST struct or32_opcode *opcode, struct insn_op_struct *cur)
606
{
607
  char *args = opcode->args;
608
  int i, type;
609
 
610
  i = 0;
611
  type = 0;
612 262 markom
  /* In case we don't have any parameters, we add dummy read from r0.  */
613
  if (!(*args)) {
614 263 markom
    cur->type = OPTYPE_REG | OPTYPE_OP | OPTYPE_LAST;
615 262 markom
    cur->data = 0;
616 355 markom
    debug(9, "#%08X %08X\n", cur->type, cur->data);
617 262 markom
    cur++;
618
    return cur;
619
  }
620
 
621 138 markom
  while (*args != '\0')
622
    {
623
      if (*args == 'r')
624
        {
625
          args++;
626
          type |= OPTYPE_REG;
627 133 markom
        }
628 138 markom
      else if (isalpha (*args))
629
        {
630
          unsigned long arg;
631
          arg = insn_extract(*args, opcode->encoding);
632 355 markom
          debug(9, "%s : %08X ------\n", opcode->name, arg);
633 138 markom
          if (letter_signed (*args))
634
            {
635
              type |= OPTYPE_SIG;
636
              type |= ((num_ones (arg) - 1) << OPTYPE_SBIT_SHR) & OPTYPE_SBIT;
637
            }
638
 
639
          /* Split argument to sequences of consecutive ones.  */
640
          while (arg)
641
            {
642
              int shr = 0;
643
              unsigned long tmp = arg, mask = 0;
644
              while ((tmp & 1) == 0)
645
                {
646
                  shr++;
647
                  tmp >>= 1;
648
                }
649
              while (tmp & 1)
650
                {
651
                  mask++;
652
                  tmp >>= 1;
653
                }
654
              cur->type = type | shr;
655
              cur->data = mask;
656
              arg &= ~(((1 << mask) - 1) << shr);
657 355 markom
              debug(6, "|%08X %08X\n", cur->type, cur->data);
658 138 markom
              cur++;
659
            }
660
          args++;
661
        }
662
      else if (*args == '(')
663
        {
664
          /* Next param is displacement.  Later we will treat them as one operand.  */
665
          cur--;
666
          cur->type = type | cur->type | OPTYPE_DIS | 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 == OPERAND_DELIM)
674
        {
675
          cur--;
676
          cur->type = type | cur->type | OPTYPE_OP;
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 == '0')
684
        {
685
          cur->type = type;
686
          cur->data = 0;
687 355 markom
          debug(9, ">%08X %08X\n", cur->type, cur->data);
688 138 markom
          cur++;
689
          type = 0;
690
          i++;
691
          args++;
692
        }
693
      else if (*args == ')')
694
        args++;
695
      else
696
        {
697
          fprintf (stderr, "%s : parse error in args.\n", opcode->name);
698
          exit (1);
699
        }
700 133 markom
    }
701 138 markom
  cur--;
702
  cur->type = type | cur->type | OPTYPE_OP | OPTYPE_LAST;
703 355 markom
  debug(9, "#%08X %08X\n", cur->type, cur->data);
704 138 markom
  cur++;
705 133 markom
  return cur;
706
}
707
 
708 138 markom
/* Constructs new automata based on or32_opcodes array.  */
709
 
710
void
711
build_automata()
712
{
713 371 markom
  int i;
714 133 markom
  unsigned long *end;
715 138 markom
  struct insn_op_struct *cur;
716
 
717 133 markom
  automata = (unsigned long *) malloc (MAX_AUTOMATA_SIZE * sizeof (unsigned long));
718 138 markom
  ti = (struct temp_insn_struct *) malloc (sizeof (struct temp_insn_struct) * num_opcodes);
719 133 markom
 
720
  nuncovered = num_opcodes;
721 138 markom
  printf("Building automata... ");
722 133 markom
  /* Build temporary information about instructions.  */
723 138 markom
  for (i = 0; i < num_opcodes; i++)
724
    {
725
      unsigned long ones, zeros;
726
      char *encoding = or32_opcodes[i].encoding;
727
      ones  = insn_extract('1', encoding);
728
      zeros = insn_extract('0', encoding);
729
      ti[i].insn_mask = ones | zeros;
730
      ti[i].insn = ones;
731
      ti[i].in_pass = curpass = 0;
732 344 markom
      /*debug(9, "%s: %s %08X %08X\n", or32_opcodes[i].name,
733 138 markom
        or32_opcodes[i].encoding, ti[i].insn_mask, ti[i].insn);*/
734
    }
735 133 markom
 
736
  /* Until all are covered search for best criteria to separate them.  */
737 138 markom
  end = cover_insn (automata, curpass, 0xFFFFFFFF);
738
  if (end - automata > MAX_AUTOMATA_SIZE)
739
    {
740
      fprintf (stderr, "Automata too large. Increase MAX_AUTOMATA_SIZE.");
741
      exit (1);
742
    }
743
  printf("done, num uncovered: %i/%i.\n", nuncovered, num_opcodes);
744 371 markom
 
745 138 markom
  printf("Parsing operands data... ");
746
  op_data = (struct insn_op_struct *) malloc (MAX_OP_TABLE_SIZE * sizeof (struct insn_op_struct));
747
  op_start = (struct insn_op_struct **) malloc (num_opcodes * sizeof (struct insn_op_struct *));
748
  cur = op_data;
749
  for (i = 0; i < num_opcodes; i++)
750
    {
751
      op_start[i] = cur;
752
      cur = parse_params (&or32_opcodes[i], cur);
753
      if (cur - op_data > MAX_OP_TABLE_SIZE)
754
        {
755
          fprintf (stderr, "Operands table too small, increase MAX_OP_TABLE_SIZE.\n");
756
          exit (1);
757
        }
758
    }
759
  printf("done.\n");
760 133 markom
}
761
 
762 138 markom
void destruct_automata ()
763
{
764
  free (ti);
765 133 markom
  free (automata);
766 138 markom
  free (op_data);
767
  free (op_start);
768 133 markom
}
769
 
770
/* Decodes instruction and returns instruction index.  */
771 138 markom
int insn_decode (unsigned int insn)
772
{
773 133 markom
  unsigned long *a = automata;
774 138 markom
  int i;
775
  while (!(*a & LEAF_FLAG))
776
    {
777
      unsigned int first = *a;
778 703 markom
      //debug(9, "%i ", a - automata);
779 138 markom
      a++;
780
      i = (insn >> first) & *a;
781
      a++;
782
      if (!*(a + i))
783
        { /* Invalid instruction found?  */
784 703 markom
          //debug(9, "XXX\n", i);
785 138 markom
          return -1;
786
        }
787
      a = automata + *(a + i);
788
    }
789
  i = *a & ~LEAF_FLAG;
790 703 markom
  //debug(9, "%i\n", i);
791 138 markom
  /* Final check - do we have direct match?
792
     (based on or32_opcodes this should be the only possibility,
793
     but in case of invalid/missing instruction we must perform a check)  */
794
  if ((ti[i].insn_mask & insn) == ti[i].insn)
795
    return i;
796
  else
797
    return -1;
798 133 markom
}
799 371 markom
 
800
static char disassembled_str[50];
801
char *disassembled = &disassembled_str[0];
802
 
803
/* Automagically does zero- or sign- extension and also finds correct
804
   sign bit position if sign extension is correct extension. Which extension
805
   is proper is figured out from letter description. */
806
 
807 703 markom
static unsigned long
808 371 markom
extend_imm(unsigned long imm, char l)
809
{
810
  unsigned long mask;
811
  int letter_bits;
812
 
813
  /* First truncate all bits above valid range for this letter
814
     in case it is zero extend. */
815
  letter_bits = letter_range(l);
816
  mask = (1 << letter_bits) - 1;
817
  imm &= mask;
818
 
819
  /* Do sign extend if this is the right one. */
820
  if (letter_signed(l) && (imm >> (letter_bits - 1)))
821
    imm |= (~mask);
822
 
823
  return imm;
824
}
825
 
826
static unsigned long
827
or32_extract(param_ch, enc_initial, insn)
828
     char param_ch;
829
     char *enc_initial;
830
     unsigned long insn;
831
{
832
  char *enc;
833
  unsigned long ret = 0;
834
  int opc_pos = 0;
835
  int param_pos = 0;
836
 
837
  for (enc = enc_initial; *enc != '\0'; enc++)
838
    if (*enc == param_ch)
839
      {
840
        if (enc - 2 >= enc_initial && (*(enc - 2) == '0') && (*(enc - 1) == 'x'))
841
          continue;
842
        else
843
          param_pos++;
844
      }
845
 
846
#if DEBUG
847
  printf("or32_extract: %x ", param_pos);
848
#endif
849
  opc_pos = 32;
850
  for (enc = enc_initial; *enc != '\0'; )
851
    if ((*enc == '0') && (*(enc+1) == 'x'))
852
      {
853
        opc_pos -= 4;
854
        if ((param_ch == '0') || (param_ch == '1'))
855
          {
856
            unsigned long tmp = strtol(enc, NULL, 16);
857
#if DEBUG
858
            printf(" enc=%s, tmp=%x ", enc, tmp);
859
#endif
860
            if (param_ch == '0')
861
              tmp = 15 - tmp;
862
            ret |= tmp << opc_pos;
863
          }
864
        enc += 3;
865
      }
866
    else if ((*enc == '0') || (*enc == '1'))
867
      {
868
        opc_pos--;
869
        if (param_ch == *enc)
870
          ret |= 1 << opc_pos;
871
        enc++;
872
      }
873
    else if (*enc == param_ch)
874
      {
875
        opc_pos--;
876
        param_pos--;
877
#if DEBUG
878
        printf("\n  ret=%x opc_pos=%x, param_pos=%x\n", ret, opc_pos, param_pos);
879
#endif  
880
        if (islower(param_ch))
881
          ret -= ((insn >> opc_pos) & 0x1) << param_pos;
882
        else
883
          ret += ((insn >> opc_pos) & 0x1) << param_pos;
884
        enc++;
885
      }
886
    else if (isalpha(*enc))
887
      {
888
        opc_pos--;
889
        enc++;
890
      }
891
    else if (*enc == '-')
892
      {
893
        opc_pos--;
894
        enc++;
895
      }
896
    else
897
      enc++;
898
 
899
#if DEBUG
900
  printf ("ret=%x\n", ret);
901
#endif
902
  return ret;
903
}
904
 
905
/* Print register. Used only by print_insn. */
906
 
907 703 markom
static char *
908
or32_print_register (dest, param_ch, encoding, insn)
909
     char *dest;
910 371 markom
     char param_ch;
911
     char *encoding;
912
     unsigned long insn;
913
{
914
  int regnum = or32_extract(param_ch, encoding, insn);
915
 
916 703 markom
  sprintf (dest, "r%d", regnum);
917
  while (*dest) dest++;
918
  return dest;
919 371 markom
}
920
 
921
/* Print immediate. Used only by print_insn. */
922
 
923 703 markom
static char *
924
or32_print_immediate (dest, param_ch, encoding, insn)
925
     char *dest;
926 371 markom
     char param_ch;
927
     char *encoding;
928
     unsigned long insn;
929
{
930
  int imm = or32_extract (param_ch, encoding, insn);
931
 
932
  imm = extend_imm(imm, param_ch);
933
 
934
  if (letter_signed(param_ch))
935
    {
936
      if (imm < 0)
937 703 markom
        sprintf (dest, "%d", imm);
938 371 markom
      else
939 703 markom
        sprintf (dest, "0x%x", imm);
940 371 markom
    }
941
  else
942 703 markom
    sprintf (dest, "%#x", imm);
943
  while (*dest) dest++;
944
  return dest;
945 371 markom
}
946
 
947
/* Disassemble one instruction from insn to disassemble.
948
   Return the size of the instruction.  */
949
 
950
int
951
disassemble_insn (insn)
952
     unsigned long insn;
953
{
954
  int index;
955 703 markom
  return disassemble_index (insn, insn_decode (insn));
956
}
957 371 markom
 
958 703 markom
/* Disassemble one instruction from insn index.
959
   Return the size of the instruction.  */
960
 
961
int
962
disassemble_index (insn, index)
963
     unsigned long insn;
964
     int index;
965
{
966
  char *dest = disassembled;
967 371 markom
  if (index >= 0)
968
    {
969
      struct or32_opcode const *opcode = &or32_opcodes[index];
970
      char *s;
971
 
972 703 markom
      strcpy (dest, opcode->name);
973
      while (*dest) dest++;
974
      *dest++ = ' ';
975
      *dest = 0;
976
 
977 371 markom
      for (s = opcode->args; *s != '\0'; ++s)
978
        {
979
          switch (*s)
980
            {
981
            case '\0':
982 703 markom
              return insn_len (insn);
983 371 markom
 
984
            case 'r':
985 703 markom
              dest = or32_print_register(dest, *++s, opcode->encoding, insn);
986 371 markom
              break;
987
 
988
            default:
989
              if (strchr (opcode->encoding, *s))
990 703 markom
                dest = or32_print_immediate (dest, *s, opcode->encoding, insn);
991
              else {
992
                *dest++ = *s;
993
                *dest = 0;
994
              }
995 371 markom
            }
996
        }
997
    }
998
  else
999
    {
1000
      /* This used to be %8x for binutils.  */
1001 703 markom
      sprintf(dest, ".word 0x%08x", insn);
1002
      while (*dest) dest++;
1003 371 markom
    }
1004
  return insn_len (insn);
1005
}

powered by: WebSVN 2.1.0

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