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