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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_56/] [gen_or1k_isa/] [sources/] [opcode/] [or32.c] - Blame information for rev 1114

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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