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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc1/] [or1ksim/] [cpu/] [or32/] [insnset.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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