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

Subversion Repositories or1k

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

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 label_entry *tmp;
295
    if (verify_memoryarea(pcdelay) && (tmp = get_label (pcdelay)))
296 1343 nogj
      fprintf (runtime.sim.fprof, "+%08llX %08lX %08lX %s\n",
297
               runtime.sim.cycles, pc + 8, pcdelay, tmp->name);
298 706 markom
    else
299 1343 nogj
      fprintf (runtime.sim.fprof, "+%08llX %08lX %08lX @%08lX\n",
300
               runtime.sim.cycles, pc + 8, pcdelay, pcdelay);
301 706 markom
  }
302
}
303
INSTRUCTION (l_jalr) {
304 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_jump;
305 1342 nogj
  pcdelay = PARAM0;
306 706 markom
  set_reg32(LINK_REGNO, pc + 8);
307
  next_delay_insn = 1;
308
}
309
INSTRUCTION (l_jr) {
310 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_jump;
311 1342 nogj
  pcdelay = PARAM0;
312 706 markom
  next_delay_insn = 1;
313
  if (config.sim.profile)
314 1343 nogj
    fprintf (runtime.sim.fprof, "-%08llX %08lX\n", runtime.sim.cycles, pcdelay);
315 706 markom
}
316
INSTRUCTION (l_rfe) {
317 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_exception;
318 706 markom
  pcnext = mfspr(SPR_EPCR_BASE);
319
  mtspr(SPR_SR, mfspr(SPR_ESR_BASE));
320
}
321
INSTRUCTION (l_nop) {
322
  unsigned long stackaddr;
323 1342 nogj
  int k = PARAM0;
324 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_nop;
325 706 markom
  switch (k) {
326
    case NOP_NOP:
327
      break;
328
    case NOP_EXIT:
329 1343 nogj
      PRINTF("exit(%ld)\n", evalsim_reg32 (3));
330
      fprintf(stderr, "@reset : cycles %lld, insn #%lld\n",
331
              runtime.sim.reset_cycles, runtime.cpu.reset_instructions);
332
      fprintf(stderr, "@exit  : cycles %lld, insn #%lld\n", runtime.sim.cycles,
333
              runtime.cpu.instructions);
334
      fprintf(stderr, " diff  : cycles %lld, insn #%lld\n",
335
              runtime.sim.cycles - runtime.sim.reset_cycles,
336
              runtime.cpu.instructions - runtime.cpu.reset_instructions);
337 706 markom
      if (config.debug.gdb_enabled)
338
        set_stall_state (1);
339
      else
340 884 markom
        runtime.sim.cont_run = 0;
341 706 markom
      break;
342 1319 phoenix
    case NOP_CNT_RESET:
343
      PRINTF("****************** counters reset ******************\n");
344
      PRINTF("cycles %lld, insn #%lld\n", runtime.sim.cycles, runtime.cpu.instructions);
345
      PRINTF("****************** counters reset ******************\n");
346
      runtime.sim.reset_cycles = runtime.sim.cycles;
347
      runtime.cpu.reset_instructions = runtime.cpu.instructions;
348
      break;
349 706 markom
    case NOP_PRINTF:
350
      stackaddr = evalsim_reg32(4);
351
      simprintf(stackaddr, evalsim_reg32(3));
352
      debug(5, "simprintf %x\n", stackaddr);
353
      break;
354
    case NOP_REPORT:
355 1343 nogj
      PRINTF("report(0x%lx);\n", evalsim_reg32(3));
356 706 markom
    default:
357
      if (k >= NOP_REPORT_FIRST && k <= NOP_REPORT_LAST)
358 1343 nogj
      PRINTF("report %i (0x%lx);\n", k - NOP_REPORT_FIRST, evalsim_reg32(3));
359 706 markom
      break;
360
  }
361
}
362
INSTRUCTION (l_sfeq) {
363 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
364 1342 nogj
  flag = PARAM0 == PARAM1;
365 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
366
}
367
INSTRUCTION (l_sfne) {
368 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
369 1342 nogj
  flag = PARAM0 != PARAM1;
370 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
371
}
372
INSTRUCTION (l_sfgts) {
373 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
374 1342 nogj
  flag = (signed)PARAM0 > (signed)PARAM1;
375 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
376
}
377
INSTRUCTION (l_sfges) {
378 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
379 1342 nogj
  flag = (signed)PARAM0 >= (signed)PARAM1;
380 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
381
}
382
INSTRUCTION (l_sflts) {
383 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
384 1342 nogj
  flag = (signed)PARAM0 < (signed)PARAM1;
385 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
386
}
387
INSTRUCTION (l_sfles) {
388 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
389 1342 nogj
  flag = (signed)PARAM0 <= (signed)PARAM1;
390 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
391
}
392
INSTRUCTION (l_sfgtu) {
393 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
394 1342 nogj
  flag = (unsigned)PARAM0 > (unsigned)PARAM1;
395 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
396
}
397
INSTRUCTION (l_sfgeu) {
398 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
399 1342 nogj
  flag = (unsigned)PARAM0 >= (unsigned)PARAM1;
400 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
401
}
402
INSTRUCTION (l_sfltu) {
403 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
404 1342 nogj
  flag = (unsigned)PARAM0 < (unsigned)PARAM1;
405 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
406
}
407
INSTRUCTION (l_sfleu) {
408 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_compare;
409 1342 nogj
  flag = (unsigned)PARAM0 <= (unsigned)PARAM1;
410 706 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
411
}
412
INSTRUCTION (l_extbs) {
413
  unsigned char x;
414 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
415 1342 nogj
  x = PARAM1;
416
  SET_PARAM0((signed long)x);
417 706 markom
}
418
INSTRUCTION (l_extbz) {
419
  unsigned char x;
420 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
421 1342 nogj
  x = PARAM1;
422
  SET_PARAM0((unsigned long)x);
423 706 markom
}
424
INSTRUCTION (l_exths) {
425
  unsigned short x;
426 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
427 1342 nogj
  x = PARAM1;
428
  SET_PARAM0((signed long)x);
429 706 markom
}
430
INSTRUCTION (l_exthz) {
431
  unsigned short x;
432 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
433 1342 nogj
  x = PARAM1;
434
  SET_PARAM0((unsigned long)x);
435 706 markom
}
436
INSTRUCTION (l_extws) {
437
  unsigned int x;
438 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
439 1342 nogj
  x = PARAM1;
440
  SET_PARAM0((signed long)x);
441 706 markom
}
442
INSTRUCTION (l_extwz) {
443
  unsigned int x;
444 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
445 1342 nogj
  x = PARAM1;
446
  SET_PARAM0((unsigned long)x);
447 706 markom
}
448
INSTRUCTION (l_mtspr) {
449 1342 nogj
  unsigned long regno = PARAM0 + PARAM2;
450
  unsigned long value = PARAM1;
451 706 markom
 
452
  if (runtime.sim.fspr_log) {
453
    fprintf(runtime.sim.fspr_log, "Write to SPR  : [%08lX] <- [%08lX]\n", regno, value);
454
  }
455
 
456 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
457 706 markom
  if (mfspr(SPR_SR) & SPR_SR_SM)
458
    mtspr(regno, value);
459
  else {
460 997 markom
    PRINTF("WARNING: trying to write SPR while SR[SUPV] is cleared.\n");
461 884 markom
    runtime.sim.cont_run = 0;
462 706 markom
  }
463
}
464
INSTRUCTION (l_mfspr) {
465 1342 nogj
  unsigned long regno = PARAM1 + PARAM2;
466 706 markom
  unsigned long value = mfspr(regno);
467
 
468
  if (runtime.sim.fspr_log) {
469
    fprintf(runtime.sim.fspr_log, "Read from SPR : [%08lX] -> [%08lX]\n", regno, value);
470
  }
471
 
472 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
473 706 markom
  if (mfspr(SPR_SR) & SPR_SR_SM)
474 1342 nogj
    SET_PARAM0(value);
475 706 markom
  else {
476 1342 nogj
    SET_PARAM0(0);
477 997 markom
    PRINTF("WARNING: trying to read SPR while SR[SUPV] is cleared.\n");
478 884 markom
    runtime.sim.cont_run = 0;
479 706 markom
  }
480
}
481
INSTRUCTION (l_sys) {
482
  except_handle(EXCEPT_SYSCALL, mfspr(SPR_EEAR_BASE));
483
}
484
INSTRUCTION (l_trap) {
485
  /* TODO: some SR related code here! */
486
  except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
487
}
488
INSTRUCTION (l_mac) {
489
  sprword lo, hi;
490
  LONGEST l;
491
  long x, y;
492 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_mac;
493 706 markom
  lo = mfspr (SPR_MACLO);
494
  hi = mfspr (SPR_MACHI);
495 1342 nogj
  x = PARAM0;
496
  y = PARAM1;
497 1343 nogj
  PRINTF ("[%08lx,%08lx]\t", (unsigned long)(x), (unsigned long)(y));
498 706 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
499
  l += (LONGEST) x * (LONGEST) y;
500
 
501
  /* This implementation is very fast - it needs only one cycle for mac.  */
502
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
503
  hi = ((LONGEST)l) >> 32;
504
  mtspr (SPR_MACLO, lo);
505
  mtspr (SPR_MACHI, hi);
506 1308 phoenix
  PRINTF ("(%08lx,%08lx)\n", hi, lo);
507 706 markom
}
508
INSTRUCTION (l_msb) {
509
  sprword lo, hi;
510
  LONGEST l;
511
  long x, y;
512 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_mac;
513 706 markom
  lo = mfspr (SPR_MACLO);
514
  hi = mfspr (SPR_MACHI);
515 1342 nogj
  x = PARAM0;
516
  y = PARAM1;
517 1343 nogj
  PRINTF ("[%08lx,%08lx]\t", (unsigned long)(x), (unsigned long)(y));
518 706 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
519 1342 nogj
  l -= x * y;
520 706 markom
 
521
  /* This implementation is very fast - it needs only one cycle for msb.  */
522
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
523
  hi = ((LONGEST)l) >> 32;
524
  mtspr (SPR_MACLO, lo);
525
  mtspr (SPR_MACHI, hi);
526 1308 phoenix
  PRINTF ("(%08lx,%08lx)\n", hi, lo);
527 706 markom
}
528
INSTRUCTION (l_macrc) {
529
  sprword lo, hi;
530
  LONGEST l;
531 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_mac;
532 706 markom
  /* No need for synchronization here -- all MAC instructions are 1 cycle long.  */
533
  lo =  mfspr (SPR_MACLO);
534
  hi =  mfspr (SPR_MACHI);
535
  l = (ULONGEST) lo | ((LONGEST)hi << 32);
536
  l >>= 28;
537 997 markom
  //PRINTF ("<%08x>\n", (unsigned long)l);
538 1342 nogj
  SET_PARAM0((long)l);
539 706 markom
  mtspr (SPR_MACLO, 0);
540
  mtspr (SPR_MACHI, 0);
541
}
542
INSTRUCTION (l_cmov) {
543 713 markom
  IFF (config.cpu.dependstats) current->func_unit = it_move;
544 1342 nogj
  SET_PARAM0(flag ? PARAM1 : PARAM2);
545 706 markom
}
546 1338 andreje
INSTRUCTION (l_ff1) {
547
  IFF (config.cpu.dependstats) current->func_unit = it_arith;
548 1342 nogj
  SET_PARAM0(ffs(PARAM1));
549 1338 andreje
}
550 720 markom
/******* Floating point instructions *******/
551
/* Single precision */
552
INSTRUCTION (lf_add_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
INSTRUCTION (lf_div_s) {
557
  IFF (config.cpu.dependstats) current->func_unit = it_float;
558 1342 nogj
  SET_PARAM0((machword)((float)PARAM1 / (float)PARAM2));
559 720 markom
}
560 1303 phoenix
INSTRUCTION (lf_ftoi_s) {
561 720 markom
  IFF (config.cpu.dependstats) current->func_unit = it_float;
562 1303 phoenix
//  set_operand32(0, freg[get_operand(1)], &breakpoint);
563 720 markom
}
564
INSTRUCTION (lf_itof_s) {
565
  IFF (config.cpu.dependstats) current->func_unit = it_float;
566 1303 phoenix
//  freg[get_operand(0)] = eval_operand32(1, &breakpoint);
567
}
568 720 markom
INSTRUCTION (lf_madd_s) {
569
  IFF (config.cpu.dependstats) current->func_unit = it_float;
570 1342 nogj
  SET_PARAM0((machword)((float)PARAM0 + (float)PARAM1 * (float)PARAM2));
571 720 markom
}
572
INSTRUCTION (lf_mul_s) {
573
  IFF (config.cpu.dependstats) current->func_unit = it_float;
574 1342 nogj
  SET_PARAM0((machword)((float)PARAM1 * (float)PARAM2));
575 720 markom
}
576
INSTRUCTION (lf_rem_s) {
577 1342 nogj
  float temp = (float)PARAM1 / (float)PARAM2;
578 720 markom
  IFF (config.cpu.dependstats) current->func_unit = it_float;
579 1342 nogj
  SET_PARAM0(temp - (machword)temp);
580 720 markom
}
581
INSTRUCTION (lf_sfeq_s) {
582
  IFF (config.cpu.dependstats) current->func_unit = it_float;
583 1342 nogj
  flag = (float)PARAM0 == (float)PARAM1;
584 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
585
}
586
INSTRUCTION (lf_sfge_s) {
587
  IFF (config.cpu.dependstats) current->func_unit = it_float;
588 1342 nogj
  flag = (float)PARAM0 >= (float)PARAM1;
589 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
590
}
591
INSTRUCTION (lf_sfgt_s) {
592
  IFF (config.cpu.dependstats) current->func_unit = it_float;
593 1342 nogj
  flag = (float)PARAM0 > (float)PARAM1;
594 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
595
}
596
INSTRUCTION (lf_sfle_s) {
597
  IFF (config.cpu.dependstats) current->func_unit = it_float;
598 1342 nogj
  flag = (float)PARAM0 <= (float)PARAM1;
599 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
600
}
601
INSTRUCTION (lf_sflt_s) {
602
  IFF (config.cpu.dependstats) current->func_unit = it_float;
603 1342 nogj
  flag = (float)PARAM0 < (float)PARAM1;
604 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
605
}
606
INSTRUCTION (lf_sfne_s) {
607
  IFF (config.cpu.dependstats) current->func_unit = it_float;
608 1342 nogj
  flag = (float)PARAM0 != (float)PARAM1;
609 720 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
610
}
611
INSTRUCTION (lf_sub_s) {
612
  IFF (config.cpu.dependstats) current->func_unit = it_float;
613 1342 nogj
  SET_PARAM0((machword)((float)PARAM1 - (float)PARAM2));
614 720 markom
}
615
 
616
/******* Custom instructions *******/
617 706 markom
INSTRUCTION (l_cust1) {
618 713 markom
  /*int destr = current->insn >> 21;
619
    int src1r = current->insn >> 15;
620
    int src2r = current->insn >> 9;*/
621 706 markom
}
622
INSTRUCTION (l_cust2) {
623
}
624
INSTRUCTION (l_cust3) {
625
}
626
INSTRUCTION (l_cust4) {
627
}

powered by: WebSVN 2.1.0

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