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