1 |
706 |
markom |
/* execute.c -- Instruction specific functions.
|
2 |
|
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
3 |
|
|
2000-2002 Marko Mlinar, markom@opencores.org
|
4 |
|
|
|
5 |
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
6 |
|
|
|
7 |
|
|
This program is free software; you can redistribute it and/or modify
|
8 |
|
|
it under the terms of the GNU General Public License as published by
|
9 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
10 |
|
|
(at your option) any later version.
|
11 |
|
|
|
12 |
|
|
This program is distributed in the hope that it will be useful,
|
13 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
|
|
GNU General Public License for more details.
|
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU General Public License
|
18 |
|
|
along with this program; if not, write to the Free Software
|
19 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
20 |
|
|
|
21 |
|
|
INSTRUCTION (l_add) {
|
22 |
1170 |
csanchez |
signed long temp1, temp2, temp3;
|
23 |
706 |
markom |
signed char temp4;
|
24 |
|
|
|
25 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_arith;
|
26 |
1170 |
csanchez |
temp2 = (signed long)eval_operand32(2, &breakpoint);
|
27 |
|
|
temp3 = (signed long)eval_operand32(1, &breakpoint);
|
28 |
|
|
temp1 = temp2 + temp3;
|
29 |
706 |
markom |
set_operand32(0, temp1, &breakpoint);
|
30 |
|
|
set_ov_flag (temp1);
|
31 |
|
|
if (ARITH_SET_FLAG) {
|
32 |
|
|
flag = temp1 == 0;
|
33 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
34 |
|
|
}
|
35 |
1170 |
csanchez |
if ((unsigned long) temp1 < (unsigned long) temp2)
|
36 |
|
|
setsprbits(SPR_SR, SPR_SR_CY, 1);
|
37 |
|
|
else
|
38 |
|
|
setsprbits(SPR_SR, SPR_SR_CY, 0);
|
39 |
706 |
markom |
|
40 |
|
|
temp4 = temp1;
|
41 |
|
|
if (temp4 == temp1)
|
42 |
1244 |
hpanther |
or1k_mstats.byteadd++;
|
43 |
706 |
markom |
}
|
44 |
1170 |
csanchez |
INSTRUCTION (l_addc) {
|
45 |
|
|
signed long temp1, temp2, temp3;
|
46 |
|
|
signed char temp4;
|
47 |
|
|
|
48 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_arith;
|
49 |
|
|
temp2 = (signed long)eval_operand32(2, &breakpoint);
|
50 |
|
|
temp3 = (signed long)eval_operand32(1, &breakpoint);
|
51 |
|
|
temp1 = temp2 + temp3 + getsprbits(SPR_SR, SPR_SR_CY);
|
52 |
|
|
set_operand32(0, temp1, &breakpoint);
|
53 |
|
|
set_ov_flag (temp1);
|
54 |
|
|
if (ARITH_SET_FLAG) {
|
55 |
|
|
flag = temp1 == 0;
|
56 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
57 |
|
|
}
|
58 |
|
|
if ((unsigned long) temp1 < (unsigned long) temp2)
|
59 |
|
|
setsprbits(SPR_SR, SPR_SR_CY, 1);
|
60 |
|
|
else
|
61 |
|
|
setsprbits(SPR_SR, SPR_SR_CY, 0);
|
62 |
|
|
|
63 |
|
|
temp4 = temp1;
|
64 |
|
|
if (temp4 == temp1)
|
65 |
1244 |
hpanther |
or1k_mstats.byteadd++;
|
66 |
1170 |
csanchez |
}
|
67 |
706 |
markom |
INSTRUCTION (l_sw) {
|
68 |
|
|
int old_cyc = 0;
|
69 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_store;
|
70 |
884 |
markom |
IFF (config.cpu.sbuf_len) old_cyc = runtime.sim.mem_cycles;
|
71 |
706 |
markom |
set_operand32(0, eval_operand32(1, &breakpoint), &breakpoint);
|
72 |
|
|
if (config.cpu.sbuf_len) {
|
73 |
884 |
markom |
int t = runtime.sim.mem_cycles;
|
74 |
|
|
runtime.sim.mem_cycles = old_cyc;
|
75 |
706 |
markom |
sbuf_store (t - old_cyc);
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
|
|
INSTRUCTION (l_sb) {
|
79 |
|
|
int old_cyc = 0;
|
80 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_store;
|
81 |
884 |
markom |
IFF (config.cpu.sbuf_len) old_cyc = runtime.sim.mem_cycles;
|
82 |
706 |
markom |
set_operand8(0, eval_operand32(1, &breakpoint), &breakpoint);
|
83 |
|
|
if (config.cpu.sbuf_len) {
|
84 |
884 |
markom |
int t = runtime.sim.mem_cycles;
|
85 |
|
|
runtime.sim.mem_cycles = old_cyc;
|
86 |
706 |
markom |
sbuf_store (t- old_cyc);
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
INSTRUCTION (l_sh) {
|
90 |
|
|
int old_cyc = 0;
|
91 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_store;
|
92 |
884 |
markom |
IFF (config.cpu.sbuf_len) old_cyc = runtime.sim.mem_cycles;
|
93 |
706 |
markom |
set_operand16(0, eval_operand32(1, &breakpoint), &breakpoint);
|
94 |
|
|
if (config.cpu.sbuf_len) {
|
95 |
884 |
markom |
int t = runtime.sim.mem_cycles;
|
96 |
|
|
runtime.sim.mem_cycles = old_cyc;
|
97 |
706 |
markom |
sbuf_store (t - old_cyc);
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
INSTRUCTION (l_lwz) {
|
101 |
|
|
unsigned long val;
|
102 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_load;
|
103 |
706 |
markom |
if (config.cpu.sbuf_len) sbuf_load ();
|
104 |
|
|
val = eval_operand32(1, &breakpoint);
|
105 |
|
|
/* If eval operand produced exception don't set anything */
|
106 |
|
|
if (!pending.valid)
|
107 |
|
|
set_operand32(0, val, &breakpoint);
|
108 |
|
|
}
|
109 |
|
|
INSTRUCTION (l_lbs) {
|
110 |
|
|
signed char val;
|
111 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_load;
|
112 |
706 |
markom |
if (config.cpu.sbuf_len) sbuf_load ();
|
113 |
|
|
val = eval_operand8(1, &breakpoint);
|
114 |
|
|
/* If eval opreand produced exception don't set anything */
|
115 |
|
|
if (!pending.valid)
|
116 |
|
|
set_operand32(0, val, &breakpoint);
|
117 |
|
|
}
|
118 |
|
|
INSTRUCTION (l_lbz) {
|
119 |
|
|
unsigned char val;
|
120 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_load;
|
121 |
706 |
markom |
if (config.cpu.sbuf_len) sbuf_load ();
|
122 |
|
|
val = eval_operand8(1, &breakpoint);
|
123 |
|
|
/* If eval opreand produced exception don't set anything */
|
124 |
|
|
if (!pending.valid)
|
125 |
|
|
set_operand32(0, val, &breakpoint);
|
126 |
|
|
}
|
127 |
|
|
INSTRUCTION (l_lhs) {
|
128 |
|
|
signed short val;
|
129 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_load;
|
130 |
706 |
markom |
if (config.cpu.sbuf_len) sbuf_load ();
|
131 |
|
|
val = eval_operand16(1, &breakpoint);
|
132 |
|
|
/* If eval opreand produced exception don't set anything */
|
133 |
|
|
if (!pending.valid)
|
134 |
|
|
set_operand32(0, val, &breakpoint);
|
135 |
|
|
}
|
136 |
|
|
INSTRUCTION (l_lhz) {
|
137 |
|
|
unsigned short val;
|
138 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_load;
|
139 |
706 |
markom |
if (config.cpu.sbuf_len) sbuf_load ();
|
140 |
|
|
val = eval_operand16(1, &breakpoint);
|
141 |
|
|
/* If eval opreand produced exception don't set anything */
|
142 |
|
|
if (!pending.valid)
|
143 |
|
|
set_operand32(0, val, &breakpoint);
|
144 |
|
|
}
|
145 |
|
|
INSTRUCTION (l_movhi) {
|
146 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_movimm;
|
147 |
706 |
markom |
set_operand32(0, eval_operand32(1, &breakpoint) << 16, &breakpoint);
|
148 |
|
|
}
|
149 |
|
|
INSTRUCTION (l_and) {
|
150 |
|
|
unsigned long temp1;
|
151 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_arith;
|
152 |
706 |
markom |
set_operand32(0, temp1 = set_ov_flag (eval_operand32(1, &breakpoint) & (unsigned)eval_operand32(2, &breakpoint)), &breakpoint);
|
153 |
|
|
if (ARITH_SET_FLAG) {
|
154 |
|
|
flag = temp1 == 0;
|
155 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
INSTRUCTION (l_or) {
|
159 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_arith;
|
160 |
706 |
markom |
set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) | (unsigned)eval_operand32(2, &breakpoint)), &breakpoint);
|
161 |
|
|
}
|
162 |
|
|
INSTRUCTION (l_xor) {
|
163 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_arith;
|
164 |
706 |
markom |
set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) ^ (signed)eval_operand32(2, &breakpoint)), &breakpoint);
|
165 |
|
|
}
|
166 |
|
|
INSTRUCTION (l_sub) {
|
167 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_arith;
|
168 |
706 |
markom |
set_operand32(0, set_ov_flag ((signed long)eval_operand32(1, &breakpoint) - (signed long)eval_operand32(2, &breakpoint)), &breakpoint);
|
169 |
|
|
}
|
170 |
|
|
/*int mcount = 0;*/
|
171 |
|
|
INSTRUCTION (l_mul) {
|
172 |
|
|
signed long temp3, temp2, temp1;
|
173 |
|
|
|
174 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_arith;
|
175 |
706 |
markom |
set_operand32(0, set_ov_flag ((signed long)eval_operand32(1, &breakpoint) * (signed long)eval_operand32(2, &breakpoint)), &breakpoint);
|
176 |
|
|
/*if (!(mcount++ & 1023)) {
|
177 |
997 |
markom |
PRINTF ("[%i]\n",mcount);
|
178 |
706 |
markom |
}*/
|
179 |
|
|
}
|
180 |
|
|
INSTRUCTION (l_div) {
|
181 |
|
|
signed long temp3, temp2, temp1;
|
182 |
|
|
|
183 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_arith;
|
184 |
706 |
markom |
temp3 = eval_operand32(2, &breakpoint);
|
185 |
|
|
temp2 = eval_operand32(1, &breakpoint);
|
186 |
|
|
if (temp3)
|
187 |
|
|
temp1 = temp2 / temp3;
|
188 |
|
|
else {
|
189 |
|
|
except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
|
190 |
|
|
return;
|
191 |
|
|
}
|
192 |
|
|
set_operand32(0, set_ov_flag (temp1), &breakpoint);
|
193 |
|
|
}
|
194 |
|
|
INSTRUCTION (l_divu) {
|
195 |
|
|
unsigned long temp3, temp2, temp1;
|
196 |
|
|
|
197 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_arith;
|
198 |
706 |
markom |
temp3 = eval_operand32(2, &breakpoint);
|
199 |
|
|
temp2 = eval_operand32(1, &breakpoint);
|
200 |
|
|
temp1 = temp2 / temp3;
|
201 |
884 |
markom |
/* runtime.sim.cycles += 16; */
|
202 |
706 |
markom |
set_operand32(0, set_ov_flag (temp1), &breakpoint);
|
203 |
|
|
}
|
204 |
|
|
INSTRUCTION (l_sll) {
|
205 |
|
|
int sign = 1;
|
206 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_shift;
|
207 |
706 |
markom |
if ((signed)eval_operand32(1, &breakpoint) < 0)
|
208 |
|
|
sign = -1;
|
209 |
884 |
markom |
/* runtime.sim.cycles += 2; */
|
210 |
706 |
markom |
set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) << eval_operand32(2, &breakpoint)), &breakpoint);
|
211 |
|
|
}
|
212 |
|
|
INSTRUCTION (l_sra) {
|
213 |
|
|
unsigned long sign = 0;
|
214 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_shift;
|
215 |
706 |
markom |
|
216 |
|
|
if ((signed)eval_operand32(1, &breakpoint) < 0)
|
217 |
|
|
sign = -1;
|
218 |
884 |
markom |
/* runtime.sim.cycles += 2; */
|
219 |
706 |
markom |
set_operand32(0, set_ov_flag ((signed)eval_operand32(1, &breakpoint) >> eval_operand32(2, &breakpoint)), &breakpoint);
|
220 |
|
|
}
|
221 |
|
|
INSTRUCTION (l_srl) {
|
222 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_shift;
|
223 |
884 |
markom |
/* runtime.sim.cycles += 2; */
|
224 |
706 |
markom |
set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) >> eval_operand32(2, &breakpoint)), &breakpoint);
|
225 |
|
|
}
|
226 |
|
|
INSTRUCTION (l_bf) {
|
227 |
|
|
if (config.bpb.enabled) {
|
228 |
|
|
int fwd = (eval_operand32(0, &breakpoint) >= pc) ? 1 : 0;
|
229 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_branch;
|
230 |
1244 |
hpanther |
or1k_mstats.bf[flag][fwd]++;
|
231 |
713 |
markom |
bpb_update(current->insn_addr, flag);
|
232 |
706 |
markom |
}
|
233 |
|
|
if (flag) {
|
234 |
|
|
pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
|
235 |
|
|
btic_update(pcnext);
|
236 |
|
|
next_delay_insn = 1;
|
237 |
|
|
} else {
|
238 |
|
|
btic_update(pc);
|
239 |
|
|
}
|
240 |
|
|
}
|
241 |
|
|
INSTRUCTION (l_bnf) {
|
242 |
|
|
if (config.bpb.enabled) {
|
243 |
|
|
int fwd = (eval_operand32(0, &breakpoint) >= pc) ? 1 : 0;
|
244 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_branch;
|
245 |
1244 |
hpanther |
or1k_mstats.bnf[!flag][fwd]++;
|
246 |
713 |
markom |
bpb_update(current->insn_addr, flag == 0);
|
247 |
706 |
markom |
}
|
248 |
|
|
if (flag == 0) {
|
249 |
|
|
pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
|
250 |
|
|
btic_update(pcnext);
|
251 |
|
|
next_delay_insn = 1;
|
252 |
|
|
} else {
|
253 |
|
|
btic_update(pc);
|
254 |
|
|
}
|
255 |
|
|
}
|
256 |
|
|
INSTRUCTION (l_j) {
|
257 |
|
|
pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
|
258 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_jump;
|
259 |
706 |
markom |
next_delay_insn = 1;
|
260 |
|
|
}
|
261 |
|
|
INSTRUCTION (l_jal) {
|
262 |
|
|
pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
|
263 |
|
|
|
264 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_jump;
|
265 |
706 |
markom |
set_reg32(LINK_REGNO, pc + 8);
|
266 |
|
|
next_delay_insn = 1;
|
267 |
|
|
if (config.sim.profile) {
|
268 |
|
|
struct mem_entry *entry;
|
269 |
|
|
struct label_entry *tmp;
|
270 |
|
|
if (verify_memoryarea(pcdelay) && (tmp = get_label (pcdelay)))
|
271 |
884 |
markom |
fprintf (runtime.sim.fprof, "+%08X %08X %08X %s\n", runtime.sim.cycles, pc + 8, pcdelay, tmp->name);
|
272 |
706 |
markom |
else
|
273 |
884 |
markom |
fprintf (runtime.sim.fprof, "+%08X %08X %08X @%08X\n", runtime.sim.cycles, pc + 8, pcdelay, pcdelay);
|
274 |
706 |
markom |
}
|
275 |
|
|
}
|
276 |
|
|
INSTRUCTION (l_jalr) {
|
277 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_jump;
|
278 |
706 |
markom |
pcdelay = eval_operand32(0, &breakpoint);
|
279 |
|
|
set_reg32(LINK_REGNO, pc + 8);
|
280 |
|
|
next_delay_insn = 1;
|
281 |
|
|
}
|
282 |
|
|
INSTRUCTION (l_jr) {
|
283 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_jump;
|
284 |
706 |
markom |
pcdelay = eval_operand32(0, &breakpoint);
|
285 |
|
|
next_delay_insn = 1;
|
286 |
|
|
if (config.sim.profile)
|
287 |
884 |
markom |
fprintf (runtime.sim.fprof, "-%08X %08X\n", runtime.sim.cycles, pcdelay);
|
288 |
706 |
markom |
}
|
289 |
|
|
INSTRUCTION (l_rfe) {
|
290 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_exception;
|
291 |
706 |
markom |
pcnext = mfspr(SPR_EPCR_BASE);
|
292 |
|
|
mtspr(SPR_SR, mfspr(SPR_ESR_BASE));
|
293 |
|
|
}
|
294 |
|
|
INSTRUCTION (l_nop) {
|
295 |
|
|
unsigned long stackaddr;
|
296 |
|
|
int k = eval_operand32(0, &breakpoint);
|
297 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_nop;
|
298 |
706 |
markom |
switch (k) {
|
299 |
|
|
case NOP_NOP:
|
300 |
|
|
break;
|
301 |
|
|
case NOP_EXIT:
|
302 |
997 |
markom |
PRINTF("exit(%d)\n", evalsim_reg32 (3));
|
303 |
706 |
markom |
if (config.debug.gdb_enabled)
|
304 |
|
|
set_stall_state (1);
|
305 |
|
|
else
|
306 |
884 |
markom |
runtime.sim.cont_run = 0;
|
307 |
706 |
markom |
break;
|
308 |
|
|
case NOP_PRINTF:
|
309 |
|
|
stackaddr = evalsim_reg32(4);
|
310 |
|
|
simprintf(stackaddr, evalsim_reg32(3));
|
311 |
|
|
debug(5, "simprintf %x\n", stackaddr);
|
312 |
|
|
break;
|
313 |
|
|
case NOP_REPORT:
|
314 |
997 |
markom |
PRINTF("report(0x%x);\n", evalsim_reg32(3));
|
315 |
706 |
markom |
default:
|
316 |
|
|
if (k >= NOP_REPORT_FIRST && k <= NOP_REPORT_LAST)
|
317 |
997 |
markom |
PRINTF("report %i (0x%x);\n", k - NOP_REPORT_FIRST, evalsim_reg32(3));
|
318 |
706 |
markom |
break;
|
319 |
|
|
}
|
320 |
|
|
}
|
321 |
|
|
INSTRUCTION (l_sfeq) {
|
322 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_compare;
|
323 |
706 |
markom |
flag = eval_operand32(0, &breakpoint) == eval_operand32(1, &breakpoint);
|
324 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
325 |
|
|
}
|
326 |
|
|
INSTRUCTION (l_sfne) {
|
327 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_compare;
|
328 |
706 |
markom |
flag = eval_operand32(0, &breakpoint) != eval_operand32(1, &breakpoint);
|
329 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
330 |
|
|
}
|
331 |
|
|
INSTRUCTION (l_sfgts) {
|
332 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_compare;
|
333 |
706 |
markom |
flag = (signed)eval_operand32(0, &breakpoint) > (signed)eval_operand32(1, &breakpoint);
|
334 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
335 |
|
|
}
|
336 |
|
|
INSTRUCTION (l_sfges) {
|
337 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_compare;
|
338 |
706 |
markom |
flag = (signed)eval_operand32(0, &breakpoint) >= (signed)eval_operand32(1, &breakpoint);
|
339 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
340 |
|
|
}
|
341 |
|
|
INSTRUCTION (l_sflts) {
|
342 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_compare;
|
343 |
706 |
markom |
flag = (signed)eval_operand32(0, &breakpoint) < (signed)eval_operand32(1, &breakpoint);
|
344 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
345 |
|
|
}
|
346 |
|
|
INSTRUCTION (l_sfles) {
|
347 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_compare;
|
348 |
706 |
markom |
flag = (signed)eval_operand32(0, &breakpoint) <= (signed)eval_operand32(1, &breakpoint);
|
349 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
350 |
|
|
}
|
351 |
|
|
INSTRUCTION (l_sfgtu) {
|
352 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_compare;
|
353 |
706 |
markom |
flag = (unsigned)eval_operand32(0, &breakpoint) > (unsigned)eval_operand32(1, &breakpoint);
|
354 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
355 |
|
|
}
|
356 |
|
|
INSTRUCTION (l_sfgeu) {
|
357 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_compare;
|
358 |
706 |
markom |
flag = (unsigned)eval_operand32(0, &breakpoint) >= (unsigned) eval_operand32(1, &breakpoint);
|
359 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
360 |
|
|
}
|
361 |
|
|
INSTRUCTION (l_sfltu) {
|
362 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_compare;
|
363 |
706 |
markom |
flag = (unsigned)eval_operand32(0, &breakpoint) < (unsigned)eval_operand32(1, &breakpoint);
|
364 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
365 |
|
|
}
|
366 |
|
|
INSTRUCTION (l_sfleu) {
|
367 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_compare;
|
368 |
706 |
markom |
flag = (unsigned)eval_operand32(0, &breakpoint) <= (unsigned)eval_operand32(1, &breakpoint);
|
369 |
|
|
setsprbits(SPR_SR, SPR_SR_F, flag);
|
370 |
|
|
}
|
371 |
|
|
INSTRUCTION (l_extbs) {
|
372 |
|
|
unsigned char x;
|
373 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_move;
|
374 |
706 |
markom |
x = eval_operand32(1, &breakpoint);
|
375 |
|
|
set_operand32(0, (signed long)x, &breakpoint);
|
376 |
|
|
}
|
377 |
|
|
INSTRUCTION (l_extbz) {
|
378 |
|
|
unsigned char x;
|
379 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_move;
|
380 |
706 |
markom |
x = eval_operand32(1, &breakpoint);
|
381 |
|
|
set_operand32(0, (unsigned long)x, &breakpoint);
|
382 |
|
|
}
|
383 |
|
|
INSTRUCTION (l_exths) {
|
384 |
|
|
unsigned short x;
|
385 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_move;
|
386 |
706 |
markom |
x = eval_operand32(1, &breakpoint);
|
387 |
|
|
set_operand32(0, (signed long)x, &breakpoint);
|
388 |
|
|
}
|
389 |
|
|
INSTRUCTION (l_exthz) {
|
390 |
|
|
unsigned short x;
|
391 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_move;
|
392 |
706 |
markom |
x = eval_operand32(1, &breakpoint);
|
393 |
|
|
set_operand32(0, (unsigned long)x, &breakpoint);
|
394 |
|
|
}
|
395 |
|
|
INSTRUCTION (l_extws) {
|
396 |
|
|
unsigned int x;
|
397 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_move;
|
398 |
706 |
markom |
x = eval_operand32(1, &breakpoint);
|
399 |
|
|
set_operand32(0, (signed long)x, &breakpoint);
|
400 |
|
|
}
|
401 |
|
|
INSTRUCTION (l_extwz) {
|
402 |
|
|
unsigned int x;
|
403 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_move;
|
404 |
706 |
markom |
x = eval_operand32(1, &breakpoint);
|
405 |
|
|
set_operand32(0, (unsigned long)x, &breakpoint);
|
406 |
|
|
}
|
407 |
|
|
INSTRUCTION (l_mtspr) {
|
408 |
|
|
unsigned long regno = eval_operand32(0, &breakpoint) + eval_operand32(2, &breakpoint);
|
409 |
|
|
unsigned long value = eval_operand32(1, &breakpoint);
|
410 |
|
|
|
411 |
|
|
if (runtime.sim.fspr_log) {
|
412 |
|
|
fprintf(runtime.sim.fspr_log, "Write to SPR : [%08lX] <- [%08lX]\n", regno, value);
|
413 |
|
|
}
|
414 |
|
|
|
415 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_move;
|
416 |
706 |
markom |
if (mfspr(SPR_SR) & SPR_SR_SM)
|
417 |
|
|
mtspr(regno, value);
|
418 |
|
|
else {
|
419 |
997 |
markom |
PRINTF("WARNING: trying to write SPR while SR[SUPV] is cleared.\n");
|
420 |
884 |
markom |
runtime.sim.cont_run = 0;
|
421 |
706 |
markom |
}
|
422 |
|
|
}
|
423 |
|
|
INSTRUCTION (l_mfspr) {
|
424 |
|
|
unsigned long regno = eval_operand32(1, &breakpoint) + eval_operand32(2, &breakpoint);
|
425 |
|
|
unsigned long value = mfspr(regno);
|
426 |
|
|
|
427 |
|
|
if (runtime.sim.fspr_log) {
|
428 |
|
|
fprintf(runtime.sim.fspr_log, "Read from SPR : [%08lX] -> [%08lX]\n", regno, value);
|
429 |
|
|
}
|
430 |
|
|
|
431 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_move;
|
432 |
706 |
markom |
if (mfspr(SPR_SR) & SPR_SR_SM)
|
433 |
|
|
set_operand32(0, value, &breakpoint);
|
434 |
|
|
else {
|
435 |
|
|
set_operand32(0, 0, &breakpoint);
|
436 |
997 |
markom |
PRINTF("WARNING: trying to read SPR while SR[SUPV] is cleared.\n");
|
437 |
884 |
markom |
runtime.sim.cont_run = 0;
|
438 |
706 |
markom |
}
|
439 |
|
|
}
|
440 |
|
|
INSTRUCTION (l_sys) {
|
441 |
|
|
except_handle(EXCEPT_SYSCALL, mfspr(SPR_EEAR_BASE));
|
442 |
|
|
}
|
443 |
|
|
INSTRUCTION (l_trap) {
|
444 |
|
|
/* TODO: some SR related code here! */
|
445 |
|
|
except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
|
446 |
|
|
}
|
447 |
|
|
INSTRUCTION (l_mac) {
|
448 |
|
|
sprword lo, hi;
|
449 |
|
|
LONGEST l;
|
450 |
|
|
long x, y;
|
451 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_mac;
|
452 |
706 |
markom |
lo = mfspr (SPR_MACLO);
|
453 |
|
|
hi = mfspr (SPR_MACHI);
|
454 |
|
|
x = eval_operand32(0, &breakpoint);
|
455 |
|
|
y = eval_operand32(1, &breakpoint);
|
456 |
997 |
markom |
PRINTF ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));
|
457 |
706 |
markom |
l = (ULONGEST)lo | ((LONGEST)hi << 32);
|
458 |
|
|
l += (LONGEST) x * (LONGEST) y;
|
459 |
|
|
|
460 |
|
|
/* This implementation is very fast - it needs only one cycle for mac. */
|
461 |
|
|
lo = ((ULONGEST)l) & 0xFFFFFFFF;
|
462 |
|
|
hi = ((LONGEST)l) >> 32;
|
463 |
|
|
mtspr (SPR_MACLO, lo);
|
464 |
|
|
mtspr (SPR_MACHI, hi);
|
465 |
997 |
markom |
PRINTF ("(%08x,%08x)\n", hi, lo);
|
466 |
706 |
markom |
}
|
467 |
|
|
INSTRUCTION (l_msb) {
|
468 |
|
|
sprword lo, hi;
|
469 |
|
|
LONGEST l;
|
470 |
|
|
long x, y;
|
471 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_mac;
|
472 |
706 |
markom |
lo = mfspr (SPR_MACLO);
|
473 |
|
|
hi = mfspr (SPR_MACHI);
|
474 |
|
|
x = eval_operand32(0, &breakpoint);
|
475 |
|
|
y = eval_operand32(1, &breakpoint);
|
476 |
997 |
markom |
PRINTF ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));
|
477 |
706 |
markom |
l = (ULONGEST)lo | ((LONGEST)hi << 32);
|
478 |
|
|
l -= (LONGEST) eval_operand32(0, &breakpoint) * (LONGEST)eval_operand32(1, &breakpoint);
|
479 |
|
|
|
480 |
|
|
/* This implementation is very fast - it needs only one cycle for msb. */
|
481 |
|
|
lo = ((ULONGEST)l) & 0xFFFFFFFF;
|
482 |
|
|
hi = ((LONGEST)l) >> 32;
|
483 |
|
|
mtspr (SPR_MACLO, lo);
|
484 |
|
|
mtspr (SPR_MACHI, hi);
|
485 |
997 |
markom |
PRINTF ("(%08x,%08x)\n", hi, lo);
|
486 |
706 |
markom |
}
|
487 |
|
|
INSTRUCTION (l_macrc) {
|
488 |
|
|
sprword lo, hi;
|
489 |
|
|
LONGEST l;
|
490 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_mac;
|
491 |
706 |
markom |
/* No need for synchronization here -- all MAC instructions are 1 cycle long. */
|
492 |
|
|
lo = mfspr (SPR_MACLO);
|
493 |
|
|
hi = mfspr (SPR_MACHI);
|
494 |
|
|
l = (ULONGEST) lo | ((LONGEST)hi << 32);
|
495 |
|
|
l >>= 28;
|
496 |
997 |
markom |
//PRINTF ("<%08x>\n", (unsigned long)l);
|
497 |
706 |
markom |
set_operand32(0, (long)l, &breakpoint);
|
498 |
|
|
mtspr (SPR_MACLO, 0);
|
499 |
|
|
mtspr (SPR_MACHI, 0);
|
500 |
|
|
}
|
501 |
|
|
INSTRUCTION (l_cmov) {
|
502 |
713 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_move;
|
503 |
712 |
markom |
set_operand32(0, flag ? eval_operand32(1, &breakpoint) : eval_operand32(2, &breakpoint), &breakpoint);
|
504 |
706 |
markom |
}
|
505 |
720 |
markom |
/******* Floating point instructions *******/
|
506 |
|
|
/* Single precision */
|
507 |
|
|
INSTRUCTION (lf_add_s) {
|
508 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
509 |
722 |
markom |
set_operand32(0, (machword)((float)eval_operand32(1, &breakpoint) + (float)eval_operand32(2, &breakpoint)), &breakpoint);
|
510 |
720 |
markom |
}
|
511 |
|
|
INSTRUCTION (lf_div_s) {
|
512 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
513 |
722 |
markom |
set_operand32(0, (machword)((float)eval_operand32(1, &breakpoint) / (float)eval_operand32(2, &breakpoint)), &breakpoint);
|
514 |
720 |
markom |
}
|
515 |
722 |
markom |
/*INSTRUCTION (lf_ftoi_s) {
|
516 |
720 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
517 |
|
|
set_operand32(0, freg[get_operand(1)], &breakpoint);
|
518 |
|
|
}
|
519 |
|
|
INSTRUCTION (lf_itof_s) {
|
520 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
521 |
|
|
freg[get_operand(0)] = eval_operand32(1, &breakpoint);
|
522 |
722 |
markom |
}*/
|
523 |
720 |
markom |
INSTRUCTION (lf_madd_s) {
|
524 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
525 |
722 |
markom |
set_operand32(0, (machword)((float)eval_operand32(0, &breakpoint) + (float)eval_operand32(1, &breakpoint) * (float)eval_operand32(2, &breakpoint)), &breakpoint);
|
526 |
720 |
markom |
}
|
527 |
|
|
INSTRUCTION (lf_mul_s) {
|
528 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
529 |
722 |
markom |
set_operand32(0, (machword)((float)eval_operand32(1, &breakpoint) * (float)eval_operand32(2, &breakpoint)), &breakpoint);
|
530 |
720 |
markom |
}
|
531 |
|
|
INSTRUCTION (lf_rem_s) {
|
532 |
722 |
markom |
float temp = (float)eval_operand32(1, &breakpoint) / (float)eval_operand32(2, &breakpoint);
|
533 |
720 |
markom |
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
534 |
722 |
markom |
set_operand32(0, temp - (machword)temp, &breakpoint);
|
535 |
720 |
markom |
}
|
536 |
|
|
INSTRUCTION (lf_sfeq_s) {
|
537 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
538 |
722 |
markom |
flag = (float)eval_operand32(0, &breakpoint) == (float)eval_operand32(1, &breakpoint);
|
539 |
720 |
markom |
setsprbits(SPR_SR, SPR_SR_F, flag);
|
540 |
|
|
}
|
541 |
|
|
INSTRUCTION (lf_sfge_s) {
|
542 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
543 |
722 |
markom |
flag = (float)eval_operand32(0, &breakpoint) >= (float)eval_operand32(1, &breakpoint);
|
544 |
720 |
markom |
setsprbits(SPR_SR, SPR_SR_F, flag);
|
545 |
|
|
}
|
546 |
|
|
INSTRUCTION (lf_sfgt_s) {
|
547 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
548 |
722 |
markom |
flag = (float)eval_operand32(0, &breakpoint) > (float)eval_operand32(1, &breakpoint);
|
549 |
720 |
markom |
setsprbits(SPR_SR, SPR_SR_F, flag);
|
550 |
|
|
}
|
551 |
|
|
INSTRUCTION (lf_sfle_s) {
|
552 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
553 |
722 |
markom |
flag = (float)eval_operand32(0, &breakpoint) <= (float)eval_operand32(1, &breakpoint);
|
554 |
720 |
markom |
setsprbits(SPR_SR, SPR_SR_F, flag);
|
555 |
|
|
}
|
556 |
|
|
INSTRUCTION (lf_sflt_s) {
|
557 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
558 |
722 |
markom |
flag = (float)eval_operand32(0, &breakpoint) < (float)eval_operand32(1, &breakpoint);
|
559 |
720 |
markom |
setsprbits(SPR_SR, SPR_SR_F, flag);
|
560 |
|
|
}
|
561 |
|
|
INSTRUCTION (lf_sfne_s) {
|
562 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
563 |
722 |
markom |
flag = (float)eval_operand32(0, &breakpoint) != (float)eval_operand32(1, &breakpoint);
|
564 |
720 |
markom |
setsprbits(SPR_SR, SPR_SR_F, flag);
|
565 |
|
|
}
|
566 |
|
|
INSTRUCTION (lf_sub_s) {
|
567 |
|
|
IFF (config.cpu.dependstats) current->func_unit = it_float;
|
568 |
722 |
markom |
set_operand32(0, (machword)((float)eval_operand32(1, &breakpoint) - (float)eval_operand32(2, &breakpoint)), &breakpoint);
|
569 |
720 |
markom |
}
|
570 |
|
|
|
571 |
|
|
/******* Custom instructions *******/
|
572 |
706 |
markom |
INSTRUCTION (l_cust1) {
|
573 |
713 |
markom |
/*int destr = current->insn >> 21;
|
574 |
|
|
int src1r = current->insn >> 15;
|
575 |
|
|
int src2r = current->insn >> 9;*/
|
576 |
706 |
markom |
}
|
577 |
|
|
INSTRUCTION (l_cust2) {
|
578 |
|
|
}
|
579 |
|
|
INSTRUCTION (l_cust3) {
|
580 |
|
|
}
|
581 |
|
|
INSTRUCTION (l_cust4) {
|
582 |
|
|
}
|