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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_52/] [or1ksim/] [cpu/] [or32/] [insnset.c] - Blame information for rev 1342

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

Line No. Rev Author Line
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 1342 nogj
  temp2 = (signed long)PARAM2;
27
  temp3 = (signed long)PARAM1;
28 1170 csanchez
  temp1 = temp2 + temp3;
29 1342 nogj
  SET_PARAM0(temp1);
30 706 markom
  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 1342 nogj
  temp2 = (signed long)PARAM2;
50
  temp3 = (signed long)PARAM1;
51 1170 csanchez
  temp1 = temp2 + temp3 + getsprbits(SPR_SR, SPR_SR_CY);
52 1342 nogj
  SET_PARAM0(temp1);
53 1170 csanchez
  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 1342 nogj
  set_mem32(PARAM0, PARAM1, &breakpoint);
72 706 markom
  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 1342 nogj
  set_mem8(PARAM0, PARAM1, &breakpoint);
83 706 markom
  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 1342 nogj
  set_mem16(PARAM0, PARAM1, &breakpoint);
94 706 markom
  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 1342 nogj
  val = eval_mem32(PARAM1, &breakpoint);
105 706 markom
  /* If eval operand produced exception don't set anything */
106
  if (!pending.valid)
107 1342 nogj
    SET_PARAM0(val);
108 706 markom
}
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 1342 nogj
  val = eval_mem8(PARAM1, &breakpoint);
114 706 markom
  /* If eval opreand produced exception don't set anything */
115
  if (!pending.valid)
116 1342 nogj
    SET_PARAM0(val);
117 706 markom
}
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 1342 nogj
  val = eval_mem8(PARAM1, &breakpoint);
123 706 markom
  /* If eval opreand produced exception don't set anything */
124
  if (!pending.valid)
125 1342 nogj
    SET_PARAM0(val);
126 706 markom
}
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 1342 nogj
  val = eval_mem16(PARAM1, &breakpoint);
132 706 markom
  /* If eval opreand produced exception don't set anything */
133
  if (!pending.valid)
134 1342 nogj
    SET_PARAM0(val);
135 706 markom
}
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 1342 nogj
  val = eval_mem16(PARAM1, &breakpoint);
141 706 markom
  /* If eval opreand produced exception don't set anything */
142
  if (!pending.valid)
143 1342 nogj
    SET_PARAM0(val);
144 706 markom
}
145
INSTRUCTION (l_movhi) {
146 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_movimm;
147 1342 nogj
  SET_PARAM0(PARAM1 << 16);
148 706 markom
}
149
INSTRUCTION (l_and) {
150
  unsigned long temp1;
151 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_arith;
152 1342 nogj
  temp1 = PARAM1 & PARAM2;
153
  set_ov_flag (temp1);
154
  SET_PARAM0(temp1);
155 706 markom
  if (ARITH_SET_FLAG) {
156
    flag = temp1 == 0;
157
    setsprbits(SPR_SR, SPR_SR_F, flag);
158
  }
159
}
160
INSTRUCTION (l_or) {
161 1342 nogj
  unsigned long temp1;
162 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_arith;
163 1342 nogj
  temp1 = PARAM1 | PARAM2;
164
  set_ov_flag (temp1);
165
  SET_PARAM0(temp1);
166 706 markom
}
167
INSTRUCTION (l_xor) {
168 1342 nogj
  unsigned long temp1;
169 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_arith;
170 1342 nogj
  temp1 = PARAM1 ^ PARAM2;
171
  set_ov_flag (temp1);
172
  SET_PARAM0(temp1);
173 706 markom
}
174
INSTRUCTION (l_sub) {
175 1342 nogj
  signed long temp1;
176 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_arith;
177 1342 nogj
  temp1 = (signed long)PARAM1 - (signed long)PARAM2;
178
  set_ov_flag (temp1);
179
  SET_PARAM0(temp1);
180 706 markom
}
181
/*int mcount = 0;*/
182
INSTRUCTION (l_mul) {
183 1342 nogj
  signed long temp1;
184 706 markom
 
185 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_arith;
186 1342 nogj
 
187
  temp1 = PARAM1 * PARAM2;
188
  set_ov_flag (temp1);
189
  SET_PARAM0(temp1);
190 706 markom
  /*if (!(mcount++ & 1023)) {
191 997 markom
    PRINTF ("[%i]\n",mcount);
192 706 markom
    }*/
193
}
194
INSTRUCTION (l_div) {
195
  signed long temp3, temp2, temp1;
196
 
197 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_arith;
198 1342 nogj
  temp3 = PARAM2;
199
  temp2 = PARAM1;
200 706 markom
  if (temp3)
201
    temp1 = temp2 / temp3;
202
  else {
203
    except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
204
    return;
205
  }
206 1342 nogj
  set_ov_flag (temp1);
207
  SET_PARAM0(temp1);
208 706 markom
}
209
INSTRUCTION (l_divu) {
210
  unsigned long temp3, temp2, temp1;
211
 
212 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_arith;
213 1342 nogj
  temp3 = PARAM2;
214
  temp2 = PARAM1;
215
  if (temp3)
216
    temp1 = temp2 / temp3;
217
  else {
218
    except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
219
    return;
220
  }
221
  set_ov_flag (temp1);
222
  SET_PARAM0(temp1);
223 884 markom
  /* runtime.sim.cycles += 16; */
224 706 markom
}
225
INSTRUCTION (l_sll) {
226 1342 nogj
  unsigned long temp1;
227
 
228 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_shift;
229 1342 nogj
 
230
  temp1 = PARAM1 << PARAM2;
231
  set_ov_flag (temp1);
232
  SET_PARAM0(temp1);
233 884 markom
  /* runtime.sim.cycles += 2; */
234 706 markom
}
235
INSTRUCTION (l_sra) {
236 1342 nogj
  signed long temp1;
237 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_shift;
238 706 markom
 
239 1342 nogj
  temp1 = (signed)PARAM1 >> PARAM2;
240
  set_ov_flag (temp1);
241
  SET_PARAM0(temp1);
242 884 markom
  /* runtime.sim.cycles += 2; */
243 706 markom
}
244
INSTRUCTION (l_srl) {
245 1342 nogj
  unsigned long temp1;
246 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_shift;
247 1342 nogj
  temp1 = PARAM1 >> PARAM2;
248
  set_ov_flag (temp1);
249
  SET_PARAM0(temp1);
250 884 markom
  /* runtime.sim.cycles += 2; */
251 706 markom
}
252
INSTRUCTION (l_bf) {
253
  if (config.bpb.enabled) {
254 1342 nogj
    int fwd = (PARAM0 >= pc) ? 1 : 0;
255 713 markom
    IFF (config.cpu.dependstats) current->func_unit = it_branch;
256 1244 hpanther
    or1k_mstats.bf[flag][fwd]++;
257 713 markom
    bpb_update(current->insn_addr, flag);
258 706 markom
  }
259
  if (flag) {
260 1342 nogj
    pcdelay = pc + (signed)PARAM0 * 4;
261 706 markom
    btic_update(pcnext);
262
    next_delay_insn = 1;
263
  } else {
264
    btic_update(pc);
265
  }
266
}
267
INSTRUCTION (l_bnf) {
268
  if (config.bpb.enabled) {
269 1342 nogj
    int fwd = (PARAM0 >= pc) ? 1 : 0;
270 713 markom
    IFF (config.cpu.dependstats) current->func_unit = it_branch;
271 1244 hpanther
    or1k_mstats.bnf[!flag][fwd]++;
272 713 markom
    bpb_update(current->insn_addr, flag == 0);
273 706 markom
  }
274
  if (flag == 0) {
275 1342 nogj
    pcdelay = pc + (signed)PARAM0 * 4;
276 706 markom
    btic_update(pcnext);
277
    next_delay_insn = 1;
278
  } else {
279
    btic_update(pc);
280
  }
281
}
282
INSTRUCTION (l_j) {
283 1342 nogj
  pcdelay = pc + (signed)PARAM0 * 4;
284 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_jump;
285 706 markom
  next_delay_insn = 1;
286
}
287
INSTRUCTION (l_jal) {
288 1342 nogj
  pcdelay = pc + (signed)PARAM0 * 4;
289 706 markom
 
290 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_jump;
291 706 markom
  set_reg32(LINK_REGNO, pc + 8);
292
  next_delay_insn = 1;
293
  if (config.sim.profile) {
294
    struct mem_entry *entry;
295
    struct label_entry *tmp;
296
    if (verify_memoryarea(pcdelay) && (tmp = get_label (pcdelay)))
297 1342 nogj
      fprintf (runtime.sim.fprof, "+%08X %08lX %08X %s\n", runtime.sim.cycles, pc + 8, pcdelay, tmp->name);
298 706 markom
    else
299 884 markom
      fprintf (runtime.sim.fprof, "+%08X %08X %08X @%08X\n", runtime.sim.cycles, pc + 8, pcdelay, pcdelay);
300 706 markom
  }
301
}
302
INSTRUCTION (l_jalr) {
303 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_jump;
304 1342 nogj
  pcdelay = PARAM0;
305 706 markom
  set_reg32(LINK_REGNO, pc + 8);
306
  next_delay_insn = 1;
307
}
308
INSTRUCTION (l_jr) {
309 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_jump;
310 1342 nogj
  pcdelay = PARAM0;
311 706 markom
  next_delay_insn = 1;
312
  if (config.sim.profile)
313 884 markom
    fprintf (runtime.sim.fprof, "-%08X %08X\n", runtime.sim.cycles, pcdelay);
314 706 markom
}
315
INSTRUCTION (l_rfe) {
316 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_exception;
317 706 markom
  pcnext = mfspr(SPR_EPCR_BASE);
318
  mtspr(SPR_SR, mfspr(SPR_ESR_BASE));
319
}
320
INSTRUCTION (l_nop) {
321
  unsigned long stackaddr;
322 1342 nogj
  int k = PARAM0;
323 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_nop;
324 706 markom
  switch (k) {
325
    case NOP_NOP:
326
      break;
327
    case NOP_EXIT:
328 997 markom
      PRINTF("exit(%d)\n", evalsim_reg32 (3));
329 1321 phoenix
      fprintf(stderr, "@reset : cycles %lld, insn #%lld\n", runtime.sim.reset_cycles, runtime.cpu.reset_instructions);
330
      fprintf(stderr, "@exit  : cycles %lld, insn #%lld\n", runtime.sim.cycles, runtime.cpu.instructions);
331 1342 nogj
      fprintf(stderr, " diff  : cycles %lld, insn #%lld\n", runtime.sim.cycles,
332
 runtime.sim.reset_cycles, runtime.cpu.instructions - runtime.cpu.reset_instructions);
333 706 markom
      if (config.debug.gdb_enabled)
334
        set_stall_state (1);
335
      else
336 884 markom
        runtime.sim.cont_run = 0;
337 706 markom
      break;
338 1319 phoenix
    case NOP_CNT_RESET:
339
      PRINTF("****************** counters reset ******************\n");
340
      PRINTF("cycles %lld, insn #%lld\n", runtime.sim.cycles, runtime.cpu.instructions);
341
      PRINTF("****************** counters reset ******************\n");
342
      runtime.sim.reset_cycles = runtime.sim.cycles;
343
      runtime.cpu.reset_instructions = runtime.cpu.instructions;
344
      break;
345 706 markom
    case NOP_PRINTF:
346
      stackaddr = evalsim_reg32(4);
347
      simprintf(stackaddr, evalsim_reg32(3));
348
      debug(5, "simprintf %x\n", stackaddr);
349
      break;
350
    case NOP_REPORT:
351 997 markom
      PRINTF("report(0x%x);\n", evalsim_reg32(3));
352 706 markom
    default:
353
      if (k >= NOP_REPORT_FIRST && k <= NOP_REPORT_LAST)
354 997 markom
      PRINTF("report %i (0x%x);\n", k - NOP_REPORT_FIRST, evalsim_reg32(3));
355 706 markom
      break;
356
  }
357
}
358
INSTRUCTION (l_sfeq) {
359 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
360 1342 nogj
  flag = PARAM0 == PARAM1;
361 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
362
}
363
INSTRUCTION (l_sfne) {
364 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
365 1342 nogj
  flag = PARAM0 != PARAM1;
366 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
367
}
368
INSTRUCTION (l_sfgts) {
369 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
370 1342 nogj
  flag = (signed)PARAM0 > (signed)PARAM1;
371 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
372
}
373
INSTRUCTION (l_sfges) {
374 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
375 1342 nogj
  flag = (signed)PARAM0 >= (signed)PARAM1;
376 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
377
}
378
INSTRUCTION (l_sflts) {
379 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
380 1342 nogj
  flag = (signed)PARAM0 < (signed)PARAM1;
381 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
382
}
383
INSTRUCTION (l_sfles) {
384 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
385 1342 nogj
  flag = (signed)PARAM0 <= (signed)PARAM1;
386 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
387
}
388
INSTRUCTION (l_sfgtu) {
389 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
390 1342 nogj
  flag = (unsigned)PARAM0 > (unsigned)PARAM1;
391 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
392
}
393
INSTRUCTION (l_sfgeu) {
394 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
395 1342 nogj
  flag = (unsigned)PARAM0 >= (unsigned)PARAM1;
396 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
397
}
398
INSTRUCTION (l_sfltu) {
399 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
400 1342 nogj
  flag = (unsigned)PARAM0 < (unsigned)PARAM1;
401 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
402
}
403
INSTRUCTION (l_sfleu) {
404 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
405 1342 nogj
  flag = (unsigned)PARAM0 <= (unsigned)PARAM1;
406 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
407
}
408
INSTRUCTION (l_extbs) {
409
  unsigned char x;
410 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
411 1342 nogj
  x = PARAM1;
412
  SET_PARAM0((signed long)x);
413 706 markom
}
414
INSTRUCTION (l_extbz) {
415
  unsigned char x;
416 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
417 1342 nogj
  x = PARAM1;
418
  SET_PARAM0((unsigned long)x);
419 706 markom
}
420
INSTRUCTION (l_exths) {
421
  unsigned short x;
422 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
423 1342 nogj
  x = PARAM1;
424
  SET_PARAM0((signed long)x);
425 706 markom
}
426
INSTRUCTION (l_exthz) {
427
  unsigned short x;
428 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
429 1342 nogj
  x = PARAM1;
430
  SET_PARAM0((unsigned long)x);
431 706 markom
}
432
INSTRUCTION (l_extws) {
433
  unsigned int x;
434 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
435 1342 nogj
  x = PARAM1;
436
  SET_PARAM0((signed long)x);
437 706 markom
}
438
INSTRUCTION (l_extwz) {
439
  unsigned int x;
440 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
441 1342 nogj
  x = PARAM1;
442
  SET_PARAM0((unsigned long)x);
443 706 markom
}
444
INSTRUCTION (l_mtspr) {
445 1342 nogj
  unsigned long regno = PARAM0 + PARAM2;
446
  unsigned long value = PARAM1;
447 706 markom
 
448
  if (runtime.sim.fspr_log) {
449
    fprintf(runtime.sim.fspr_log, "Write to SPR  : [%08lX] <- [%08lX]\n", regno, value);
450
  }
451
 
452 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
453 706 markom
  if (mfspr(SPR_SR) & SPR_SR_SM)
454
    mtspr(regno, value);
455
  else {
456 997 markom
    PRINTF("WARNING: trying to write SPR while SR[SUPV] is cleared.\n");
457 884 markom
    runtime.sim.cont_run = 0;
458 706 markom
  }
459
}
460
INSTRUCTION (l_mfspr) {
461 1342 nogj
  unsigned long regno = PARAM1 + PARAM2;
462 706 markom
  unsigned long value = mfspr(regno);
463
 
464
  if (runtime.sim.fspr_log) {
465
    fprintf(runtime.sim.fspr_log, "Read from SPR : [%08lX] -> [%08lX]\n", regno, value);
466
  }
467
 
468 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
469 706 markom
  if (mfspr(SPR_SR) & SPR_SR_SM)
470 1342 nogj
    SET_PARAM0(value);
471 706 markom
  else {
472 1342 nogj
    SET_PARAM0(0);
473 997 markom
    PRINTF("WARNING: trying to read SPR while SR[SUPV] is cleared.\n");
474 884 markom
    runtime.sim.cont_run = 0;
475 706 markom
  }
476
}
477
INSTRUCTION (l_sys) {
478
  except_handle(EXCEPT_SYSCALL, mfspr(SPR_EEAR_BASE));
479
}
480
INSTRUCTION (l_trap) {
481
  /* TODO: some SR related code here! */
482
  except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
483
}
484
INSTRUCTION (l_mac) {
485
  sprword lo, hi;
486
  LONGEST l;
487
  long x, y;
488 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_mac;
489 706 markom
  lo = mfspr (SPR_MACLO);
490
  hi = mfspr (SPR_MACHI);
491 1342 nogj
  x = PARAM0;
492
  y = PARAM1;
493 997 markom
  PRINTF ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));
494 706 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
495
  l += (LONGEST) x * (LONGEST) y;
496
 
497
  /* This implementation is very fast - it needs only one cycle for mac.  */
498
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
499
  hi = ((LONGEST)l) >> 32;
500
  mtspr (SPR_MACLO, lo);
501
  mtspr (SPR_MACHI, hi);
502 1308 phoenix
  PRINTF ("(%08lx,%08lx)\n", hi, lo);
503 706 markom
}
504
INSTRUCTION (l_msb) {
505
  sprword lo, hi;
506
  LONGEST l;
507
  long x, y;
508 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_mac;
509 706 markom
  lo = mfspr (SPR_MACLO);
510
  hi = mfspr (SPR_MACHI);
511 1342 nogj
  x = PARAM0;
512
  y = PARAM1;
513 997 markom
  PRINTF ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));
514 706 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
515 1342 nogj
  l -= x * y;
516 706 markom
 
517
  /* This implementation is very fast - it needs only one cycle for msb.  */
518
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
519
  hi = ((LONGEST)l) >> 32;
520
  mtspr (SPR_MACLO, lo);
521
  mtspr (SPR_MACHI, hi);
522 1308 phoenix
  PRINTF ("(%08lx,%08lx)\n", hi, lo);
523 706 markom
}
524
INSTRUCTION (l_macrc) {
525
  sprword lo, hi;
526
  LONGEST l;
527 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_mac;
528 706 markom
  /* No need for synchronization here -- all MAC instructions are 1 cycle long.  */
529
  lo =  mfspr (SPR_MACLO);
530
  hi =  mfspr (SPR_MACHI);
531
  l = (ULONGEST) lo | ((LONGEST)hi << 32);
532
  l >>= 28;
533 997 markom
  //PRINTF ("<%08x>\n", (unsigned long)l);
534 1342 nogj
  SET_PARAM0((long)l);
535 706 markom
  mtspr (SPR_MACLO, 0);
536
  mtspr (SPR_MACHI, 0);
537
}
538
INSTRUCTION (l_cmov) {
539 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
540 1342 nogj
  SET_PARAM0(flag ? PARAM1 : PARAM2);
541 706 markom
}
542 1338 andreje
INSTRUCTION (l_ff1) {
543
  IFF (config.cpu.dependstats) current->func_unit = it_arith;
544 1342 nogj
  SET_PARAM0(ffs(PARAM1));
545 1338 andreje
}
546 720 markom
/******* Floating point instructions *******/
547
/* Single precision */
548
INSTRUCTION (lf_add_s) {
549
  IFF (config.cpu.dependstats) current->func_unit = it_float;
550 1342 nogj
  SET_PARAM0((machword)((float)PARAM1 + (float)PARAM2));
551 720 markom
}
552
INSTRUCTION (lf_div_s) {
553
  IFF (config.cpu.dependstats) current->func_unit = it_float;
554 1342 nogj
  SET_PARAM0((machword)((float)PARAM1 / (float)PARAM2));
555 720 markom
}
556 1303 phoenix
INSTRUCTION (lf_ftoi_s) {
557 720 markom
  IFF (config.cpu.dependstats) current->func_unit = it_float;
558 1303 phoenix
//  set_operand32(0, freg[get_operand(1)], &breakpoint);
559 720 markom
}
560
INSTRUCTION (lf_itof_s) {
561
  IFF (config.cpu.dependstats) current->func_unit = it_float;
562 1303 phoenix
//  freg[get_operand(0)] = eval_operand32(1, &breakpoint);
563
}
564 720 markom
INSTRUCTION (lf_madd_s) {
565
  IFF (config.cpu.dependstats) current->func_unit = it_float;
566 1342 nogj
  SET_PARAM0((machword)((float)PARAM0 + (float)PARAM1 * (float)PARAM2));
567 720 markom
}
568
INSTRUCTION (lf_mul_s) {
569
  IFF (config.cpu.dependstats) current->func_unit = it_float;
570 1342 nogj
  SET_PARAM0((machword)((float)PARAM1 * (float)PARAM2));
571 720 markom
}
572
INSTRUCTION (lf_rem_s) {
573 1342 nogj
  float temp = (float)PARAM1 / (float)PARAM2;
574 720 markom
  IFF (config.cpu.dependstats) current->func_unit = it_float;
575 1342 nogj
  SET_PARAM0(temp - (machword)temp);
576 720 markom
}
577
INSTRUCTION (lf_sfeq_s) {
578
  IFF (config.cpu.dependstats) current->func_unit = it_float;
579 1342 nogj
  flag = (float)PARAM0 == (float)PARAM1;
580 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
581
}
582
INSTRUCTION (lf_sfge_s) {
583
  IFF (config.cpu.dependstats) current->func_unit = it_float;
584 1342 nogj
  flag = (float)PARAM0 >= (float)PARAM1;
585 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
586
}
587
INSTRUCTION (lf_sfgt_s) {
588
  IFF (config.cpu.dependstats) current->func_unit = it_float;
589 1342 nogj
  flag = (float)PARAM0 > (float)PARAM1;
590 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
591
}
592
INSTRUCTION (lf_sfle_s) {
593
  IFF (config.cpu.dependstats) current->func_unit = it_float;
594 1342 nogj
  flag = (float)PARAM0 <= (float)PARAM1;
595 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
596
}
597
INSTRUCTION (lf_sflt_s) {
598
  IFF (config.cpu.dependstats) current->func_unit = it_float;
599 1342 nogj
  flag = (float)PARAM0 < (float)PARAM1;
600 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
601
}
602
INSTRUCTION (lf_sfne_s) {
603
  IFF (config.cpu.dependstats) current->func_unit = it_float;
604 1342 nogj
  flag = (float)PARAM0 != (float)PARAM1;
605 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
606
}
607
INSTRUCTION (lf_sub_s) {
608
  IFF (config.cpu.dependstats) current->func_unit = it_float;
609 1342 nogj
  SET_PARAM0((machword)((float)PARAM1 - (float)PARAM2));
610 720 markom
}
611
 
612
/******* Custom instructions *******/
613 706 markom
INSTRUCTION (l_cust1) {
614 713 markom
  /*int destr = current->insn >> 21;
615
    int src1r = current->insn >> 15;
616
    int src2r = current->insn >> 9;*/
617 706 markom
}
618
INSTRUCTION (l_cust2) {
619
}
620
INSTRUCTION (l_cust3) {
621
}
622
INSTRUCTION (l_cust4) {
623
}

powered by: WebSVN 2.1.0

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