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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_34/] [or1ksim/] [cpu/] [or32/] [execute.c] - Blame information for rev 626

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

Line No. Rev Author Line
1 2 cvs
/* execute.c -- OR1K architecture dependent simulation
2
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
/* Most of the OR1K simulation is done in here. */
21
 
22
#include <stdlib.h>
23
#include <stdio.h>
24
#include <string.h>
25
#include <ctype.h>
26
 
27 123 markom
#include "config.h"
28 2 cvs
#include "arch.h"
29 133 markom
#include "opcode/or32.h"
30 2 cvs
#include "branch_predict.h"
31
#include "abstract.h"
32 261 markom
#include "labels.h"
33 2 cvs
#include "parse.h"
34
#include "execute.h"
35
#include "stats.h"
36 54 lampret
#include "except.h"
37
#include "sprs.h"
38 102 lampret
#include "sim-config.h"
39 123 markom
#include "debug_unit.h"
40 2 cvs
 
41 615 markom
/* Whether instructions set overflow flag */
42
#define SET_OV_FLAG     1
43
 
44
/* Whether arithmethic instructions set flag on zero */
45 620 markom
#define ARITH_SET_FLAG  1
46 615 markom
 
47 2 cvs
/* General purpose registers. */
48
machword reg[MAX_GPRS];
49
 
50
/* Instruction queue */
51
struct iqueue_entry iqueue[20];
52
 
53 83 lampret
/* Is current insn in execution a delay insn? */
54
int delay_insn;
55
 
56 2 cvs
/* Benchmark multi issue execution */
57
int multissue[20];
58
int supercycles;
59 6 lampret
int issued_per_cycle = 4;
60
int hazardwait = 0;
61 2 cvs
 
62 431 markom
/* Whether break was hit - so we can step over a break */
63
static int break_just_hit = 0;
64
 
65 68 lampret
/* freemem 'pointer' */
66
extern unsigned long freemem;
67
 
68 2 cvs
/* Completition queue */
69 138 markom
struct iqueue_entry icomplet[20];
70 2 cvs
 
71 77 lampret
/* Program counter (and translated PC) */
72 2 cvs
unsigned long pc;
73 77 lampret
unsigned long pc_phy;
74 2 cvs
 
75 378 markom
/* Previous program counter */
76 479 markom
unsigned long pcprev = 0;
77 378 markom
 
78 2 cvs
/* Temporary program counter */
79 83 lampret
unsigned long pcnext;
80 2 cvs
 
81 123 markom
/* Delay instruction effective address register */
82
unsigned long pcdelay;
83
 
84 2 cvs
/* CCR */
85
int flag;
86
 
87
/* CCR (for dependency calculation) */
88
char ccr_flag[10] = "flag";
89
 
90
/* Cycles counts fetch stages */
91
int cycles;
92
 
93 537 markom
/* Each cycle has counter of mem_cycles; this value is joined with cycles
94
   at the end of the cycle; no sim originated memory accesses should be
95
   performed inbetween. */
96
int mem_cycles;
97
 
98 535 markom
/* Instructions executed */
99
int instructions;
100
 
101 6 lampret
/* Load and store stalls */
102
int loadcycles, storecycles;
103
 
104 626 markom
/* Store buffer analysis - stores are accumulated and commited when IO is idle */
105
static int sbuf_head = 0, sbuf_tail = 0, sbuf_count = 0;
106
static int sbuf_buf[MAX_SBUF_LEN] = {0};
107
static int sbuf_prev_cycles = 0;
108
 
109
/* Num cycles waiting for stores to complete */
110
int sbuf_wait_cyc = 0;
111
 
112
/* Number of total store cycles */
113
int sbuf_total_cyc = 0;
114
 
115 138 markom
/* Local data needed for execution.  */
116
static struct iqueue_entry *cur;
117
static int next_delay_insn;
118
static int breakpoint;
119
static unsigned long *op;
120
static int num_op;
121
 
122 2 cvs
/* Implementation specific.
123
   Get an actual value of a specific register. */
124
 
125 560 markom
unsigned long evalsim_reg32(int regno)
126 2 cvs
{
127 138 markom
  if (regno < MAX_GPRS) {
128 560 markom
    return reg[regno];
129
  } else {
130
    printf("\nABORT: read out of registers\n");
131
    cont_run = 0;
132
    return 0;
133
  }
134
}
135
 
136
/* Implementation specific.
137
   Set a specific register with value. */
138
 
139
void setsim_reg32(int regno, unsigned long value)
140
{
141
  if (regno == 0)               /* gpr0 is always zero */
142
    value = 0;
143
 
144
  if (regno < MAX_GPRS) {
145
    reg[regno] = value;
146
  } else {
147
    printf("\nABORT: write out of registers\n");
148
    cont_run = 0;
149
  }
150
}
151
 
152
/* Implementation specific.
153
   Get an actual value of a specific register. */
154
 
155
inline static unsigned long eval_reg32(int regno)
156
{
157
  if (regno < MAX_GPRS) {
158
    IFF(config.cpu.raw_range) {
159 535 markom
      int delta = (cycles - raw_stats.reg[regno]);
160 606 markom
      if ((unsigned long)delta < (unsigned long)config.cpu.raw_range)
161 535 markom
        raw_stats.range[delta]++;
162
    }
163 344 markom
    debug(9, "atoi ret1\n");
164 138 markom
    return reg[regno];
165
  } else {
166 393 markom
    printf("\nABORT: read out of registers\n");
167 138 markom
    cont_run = 0;
168
    return 0;
169
  }
170 2 cvs
}
171
 
172
/* Implementation specific.
173
   Set a specific register with value. */
174
 
175 560 markom
inline static void set_reg32(int regno, unsigned long value)
176 2 cvs
{
177 262 markom
#if 0   
178 138 markom
  if (strcmp(regstr, FRAME_REG) == 0) {
179
    printf("FP (%s) modified by insn at %x. ", FRAME_REG, pc);
180
    printf("Old:%.8lx  New:%.8lx\n", eval_reg(regno), value);
181
  }
182
 
183
  if (strcmp(regstr, STACK_REG) == 0) {
184
    printf("SP (%s) modified by insn at %x. ", STACK_REG, pc);
185
    printf("Old:%.8lx  New:%.8lx\n", eval_reg(regmo), value);
186
  }
187 2 cvs
#endif
188 560 markom
 
189 138 markom
  if (regno < MAX_GPRS) {
190
    reg[regno] = value;
191 560 markom
    IFF(config.cpu.raw_range)
192 535 markom
      raw_stats.reg[regno] = cycles;
193 138 markom
  } else {
194 393 markom
    printf("\nABORT: write out of registers\n");
195 138 markom
    cont_run = 0;
196
  }
197 2 cvs
}
198
 
199
/* Does srcoperand depend on computation of dstoperand? Return
200
   non-zero if yes.
201
 
202 262 markom
 Cycle t                 Cycle t+1
203
dst: irrelevant         src: immediate                  always 0
204
dst: reg1 direct        src: reg2 direct                0 if reg1 != reg2
205
dst: reg1 disp          src: reg2 direct                always 0
206
dst: reg1 direct        src: reg2 disp                  0 if reg1 != reg2
207
dst: reg1 disp          src: reg2 disp                  always 1 (store must
208
                                                        finish before load)
209 138 markom
dst: flag               src: flag                       always 1
210 2 cvs
*/
211
 
212 138 markom
int depend_operands(prev, next)
213
     struct iqueue_entry *prev;
214
     struct iqueue_entry *next;
215 2 cvs
{
216 138 markom
  /* Find destination type. */
217
  unsigned long type = 0;
218
  int i = 0;
219
  if (or32_opcodes[prev->insn_index].flags & OR32_W_FLAG
220
      && or32_opcodes[next->insn_index].flags & OR32_R_FLAG)
221
    return 1;
222 2 cvs
 
223 138 markom
  while (!(prev->op[i + MAX_OPERANDS] & OPTYPE_LAST))
224
    if (prev->op[i + MAX_OPERANDS] & OPTYPE_DST)
225
      {
226 262 markom
        type = prev->op[i + MAX_OPERANDS];
227
        break;
228 138 markom
      }
229
    else
230
      i++;
231 560 markom
 
232 138 markom
  /* We search all source operands - if we find confict => return 1 */
233
  i = 0;
234
  while (!(next->op[i + MAX_OPERANDS] & OPTYPE_LAST))
235
    if (!(next->op[i + MAX_OPERANDS] & OPTYPE_DST))
236
      {
237 262 markom
        if (next->op[i + MAX_OPERANDS] & OPTYPE_DIS)
238
          if (type & OPTYPE_DIS)
239
            return 1;
240
          else if (next->op[i] == prev->op[i]
241
                   && (next->op[i + MAX_OPERANDS] & OPTYPE_REG))
242
            return 1;
243
        if (next->op[i] == prev->op[i]
244
            && (next->op[i + MAX_OPERANDS] & OPTYPE_REG)
245
            && (type & OPTYPE_REG))
246
          return 1;
247
        i++;
248 138 markom
      }
249
    else
250
      i++;
251
  return 0;
252
}
253 2 cvs
 
254 138 markom
/* Implementation specific.
255
   Parses and returns operands. */
256 2 cvs
 
257 138 markom
static void
258
eval_operands (unsigned long insn, int insn_index, int* breakpoint)
259
{
260
  struct insn_op_struct *opd = op_start[insn_index];
261
  unsigned long data = 0;
262
  int dis = 0;
263
  int no = 0;
264 560 markom
 
265 138 markom
  while (1)
266
    {
267
      unsigned long tmp = 0, nbits = 0;
268
      while (1)
269 262 markom
        {
270
          tmp |= ((insn  >> (opd->type & OPTYPE_SHR)) & ((1 << opd->data) - 1)) << nbits;
271
          nbits += opd->data;
272
          if (opd->type & OPTYPE_OP)
273
            break;
274
          opd++;
275
        }
276 2 cvs
 
277 138 markom
      /* Do we have to sign extend? */
278
      if (opd->type & OPTYPE_SIG)
279 262 markom
        {
280
          int sbit = (opd->type & OPTYPE_SBIT) >> OPTYPE_SBIT_SHR;
281
          if (tmp & (1 << sbit))
282
            tmp |= 0xFFFFFFFF << sbit;
283
        }
284 138 markom
      if (opd->type & OPTYPE_DIS) {
285 262 markom
        /* We have to read register later.  */
286
        data += tmp;
287
        dis = 1;
288 138 markom
      } else
289 262 markom
        {
290
          if (dis && (opd->type & OPTYPE_REG))
291 560 markom
            op[no] = data + eval_reg32 (tmp);
292 262 markom
          else
293
            op[no] = tmp;
294
          op[no + MAX_OPERANDS] = opd->type | (dis ? OPTYPE_DIS : 0);
295
          no++;
296
          data = 0;
297
          dis = 0;
298
        }
299 138 markom
      if(opd->type & OPTYPE_LAST)
300 262 markom
        return;
301 138 markom
      opd++;
302
    }
303
  num_op = no;
304 2 cvs
}
305
 
306
/* Implementation specific.
307 138 markom
   Evaluates source operand op_no. */
308
 
309 560 markom
inline static unsigned long eval_operand32 (int op_no, int *breakpoint)
310 2 cvs
{
311 344 markom
  debug (9, "%i %08X\n", op_no, op[op_no + MAX_OPERANDS]);
312 538 markom
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
313 560 markom
    /* memory accesses are not cached */
314 138 markom
    return eval_mem32 (op[op_no], breakpoint);
315 560 markom
  else if (op[op_no + MAX_OPERANDS] & OPTYPE_REG) {
316
    return eval_reg32 (op[op_no]);
317
  } else {
318 138 markom
    return op[op_no];
319 560 markom
  }
320 2 cvs
}
321
 
322
/* Implementation specific.
323 221 markom
   Evaluates source operand op_no. */
324
 
325 560 markom
static unsigned long eval_operand16 (int op_no, int *breakpoint)
326 221 markom
{
327 344 markom
  debug (9, "%i %08X\n", op_no, op[op_no + MAX_OPERANDS]);
328 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
329 221 markom
    return eval_mem16 (op[op_no], breakpoint);
330 458 simons
  }
331 221 markom
  else {
332
    fprintf (stderr, "Invalid operand type.\n");
333
    exit (1);
334
  }
335
}
336
 
337
/* Implementation specific.
338
   Evaluates source operand op_no. */
339
 
340 560 markom
static unsigned long eval_operand8 (int op_no, int *breakpoint)
341 221 markom
{
342 344 markom
  debug (9, "%i %08X\n", op_no, op[op_no + MAX_OPERANDS]);
343 221 markom
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
344
    return eval_mem8 (op[op_no], breakpoint);
345
  else {
346
    fprintf (stderr, "Invalid operand type.\n");
347
    exit (1);
348
  }
349
}
350
 
351
/* Implementation specific.
352 2 cvs
   Set destination operand (register direct, register indirect
353
   (with displacement) with value. */
354
 
355 560 markom
inline static void set_operand32(int op_no, unsigned long value, int* breakpoint)
356 2 cvs
{
357 138 markom
  /* Mark this as destination operand.  */
358 560 markom
  IFF (config.cpu.dependstats) op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
359 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
360 138 markom
    set_mem32(op[op_no], value, breakpoint);
361 560 markom
  } else if (op[op_no + MAX_OPERANDS] & OPTYPE_REG) {
362 138 markom
    set_reg32(op[op_no], value);
363 560 markom
  } else {
364
    fprintf (stderr, "Invalid operand type.\n");
365
    exit (1);
366 458 simons
  }
367 2 cvs
}
368
 
369 221 markom
/* Implementation specific.
370
   Set destination operand (register direct, register indirect
371
   (with displacement) with value. */
372
 
373
void set_operand16(int op_no, unsigned long value, int* breakpoint)
374
{
375
  /* Mark this as destination operand.  */
376 560 markom
  op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
377 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
378 221 markom
    set_mem16(op[op_no], value, breakpoint);
379 458 simons
  }
380 574 markom
  else
381 221 markom
    {
382
      fprintf (stderr, "Invalid operand type.\n");
383
      exit (1);
384
    }
385
}
386
 
387
/* Implementation specific.
388
   Set destination operand (register direct, register indirect
389
   (with displacement) with value. */
390
 
391
void set_operand8(int op_no, unsigned long value, int* breakpoint)
392
{
393
  /* Mark this as destination operand.  */
394
  op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
395
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
396
    set_mem8(op[op_no], value, breakpoint);
397
  else
398
    {
399
      fprintf (stderr, "Invalid operand type.\n");
400
      exit (1);
401
    }
402
}
403
 
404 605 markom
/* Sets a new SPR_SR_OV value, based on next register value */
405
static inline unsigned long set_ov_flag (unsigned long value)
406
{
407 615 markom
#if SET_OV_FLAG
408 605 markom
  value & 0x80000000 ? setsprbits (SPR_SR, SPR_SR_OV, 1) : setsprbits (SPR_SR, SPR_SR_OV, 0);
409 615 markom
#endif
410 605 markom
  return value;
411
}
412
 
413 123 markom
/* Modified by CZ 26/05/01 for new mode execution */
414
/* Fetch returns nonzero if instruction should NOT be executed.  */
415 557 markom
static inline int fetch()
416
{
417 221 markom
  struct mem_entry *entry;
418 344 markom
  debug(5, "fetch()\n");
419 123 markom
 
420 557 markom
  /* Update the pc for pending exceptions, or get physical pc */
421 574 markom
  if (!pending.valid)
422
    pc_phy = translate_vrt_to_phy_add(pc);
423
 
424 557 markom
  if(pending.valid)
425
    except_handle_backend(pending.type, pending.address, pending.saved);
426 464 simons
 
427 557 markom
  if (CHECK_BREAKPOINTS) {
428
    /* MM: Check for breakpoint.  This has to be done in fetch cycle,
429
       because of peripheria.
430
       MM1709: if we cannot access the memory entry, we could not set the
431
       breakpoint earlier, so just chech the breakpoint list.  */
432
    if (has_breakpoint (pc_phy) && !break_just_hit) {
433
      break_just_hit = 1;
434
      return 1; /* Breakpoint set. */
435
    }
436
    break_just_hit = 0;
437 431 markom
  }
438 535 markom
  instructions++;
439 378 markom
 
440 538 markom
  pc_phy &= ~0x03;
441
 
442 378 markom
  /* Fetch instruction. */
443 560 markom
  iqueue[0].insn_addr = pc;
444
  iqueue[0].insn = eval_insn (pc_phy, &breakpoint);;
445 557 markom
 
446 378 markom
  /* update_pc will be called after execution */
447 77 lampret
 
448 378 markom
  return 0;
449 2 cvs
}
450
 
451 479 markom
/* This code actually updates the PC value.  */
452 626 markom
static inline void update_pc ()
453 142 chris
{
454 479 markom
  pcprev = pc; /* Store value for later */
455
  pc = pcnext;
456
  pcnext = delay_insn ? pcdelay : pcnext + 4;
457 2 cvs
}
458
 
459 626 markom
static inline void analysis ()
460 2 cvs
{
461 394 markom
  if (config.cpu.dependstats)
462 123 markom
    /* Instruction waits in completition buffer until retired. */
463 138 markom
    memcpy (&icomplet[0], &iqueue[0], sizeof (struct iqueue_entry));
464
 
465 394 markom
  if (config.sim.history) {
466 263 markom
    int i;
467
 
468 123 markom
    /* History of execution */
469
    for (i = HISTEXEC_LEN - 1; i; i--)
470
      histexec[i] = histexec[i - 1];
471 262 markom
    histexec[0] = icomplet[0].insn_addr;        /* add last insn */
472 123 markom
  }
473 2 cvs
}
474
 
475 626 markom
/* Store buffer analysis - stores are accumulated and commited when IO is idle */
476
static inline sbuf_store () {
477
  int delta = cycles - sbuf_prev_cycles;
478
  int cyc = mem_cycles;
479
  sbuf_total_cyc += cyc;
480
  mem_cycles = 0;
481
 
482
  /* Take stores from buffer, that occured meanwhile */
483
  while (delta >= sbuf_buf[sbuf_tail] && sbuf_count) {
484
    delta -= sbuf_buf[sbuf_tail];
485
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
486
    sbuf_count--;
487
  }
488
  if (sbuf_count)
489
    sbuf_buf[sbuf_tail] -= delta;
490
 
491
  /* Store buffer is full, take one out */
492
  if (sbuf_count >= config.cpu.sbuf_len) {
493
    sbuf_wait_cyc += sbuf_buf[sbuf_tail];
494
    mem_cycles += sbuf_buf[sbuf_tail];
495
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
496
    sbuf_count--;
497
  }
498
  /* Put newest store in the buffer */
499
  sbuf_buf[sbuf_head] = cyc;
500
  sbuf_head = (sbuf_head + 1) % MAX_SBUF_LEN;
501
  sbuf_count++;
502
  sbuf_prev_cycles = cycles;
503
}
504 294 markom
 
505 626 markom
/* Store buffer analysis - previous stores should commit, before any load */
506
static inline sbuf_load () {
507
  /* Wait for all stores to complete */
508
  while (sbuf_count > 0) {
509
    sbuf_wait_cyc += sbuf_buf[sbuf_tail];
510
    mem_cycles += sbuf_buf[sbuf_tail];
511
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
512
    sbuf_count--;
513
  }
514
}
515
 
516 294 markom
/* Execution logger.  */
517
inline void dump_exe_log()
518
{
519 479 markom
  unsigned long i = iqueue[0].insn_addr;
520 294 markom
 
521 479 markom
  if (i == 0xffffffff) return;
522 361 markom
  fprintf(runtime.sim.fexe_log, "\nEXECUTED(): %.8lx:  ", i);
523
  fprintf(runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i), evalsim_mem8(i + 1));
524
  fprintf(runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i + 2), evalsim_mem8(i + 3));
525
  for(i = 0; i < MAX_GPRS; i++) {
526
    if (i % 4 == 0)
527
      fprintf(runtime.sim.fexe_log, "\n");
528
    fprintf(runtime.sim.fexe_log, "GPR%2u: %.8lx  ", i, reg[i]);
529
  }
530
  fprintf(runtime.sim.fexe_log, "\n");
531
  fprintf(runtime.sim.fexe_log, "SR   : %.8lx  ", mfspr(SPR_SR));
532
  fprintf(runtime.sim.fexe_log, "EPCR0: %.8lx  ", mfspr(SPR_EPCR_BASE));
533
  fprintf(runtime.sim.fexe_log, "EEAR0: %.8lx  ", mfspr(SPR_EEAR_BASE));
534
  fprintf(runtime.sim.fexe_log, "ESR0 : %.8lx\n", mfspr(SPR_ESR_BASE));
535 294 markom
}
536
 
537 537 markom
#if 0
538 535 markom
void print_time (int cycles, char *output)
539
{
540
  int i = 0, c_ps = config.sim.clkcycle_ps;
541
  while (c_ps % 1000 == 0 && i < 2) {
542
    c_ps /= 1000;
543
    i++;
544
  }
545
  c_ps *= cycles;
546
  sprintf (output, "%i%cs", cycles, i == 0 ? 'p' : i == 1 ? 'n': 'u');
547
}
548 537 markom
#endif
549 535 markom
 
550 2 cvs
void dumpreg()
551
{
552 269 markom
  int i;
553 535 markom
  char temp[100];
554 269 markom
 
555 306 markom
  dumpmemory(iqueue[0].insn_addr, iqueue[0].insn_addr + 4, 1, 0);
556 537 markom
  generate_time_pretty (temp, cycles);
557 535 markom
  printf(" (executed) [time %s, #%i]\n", temp, instructions);
558 293 markom
  if (config.cpu.superscalar)
559
    printf ("Superscalar CYCLES: %u", supercycles);
560
  if (config.cpu.hazards)
561
    printf ("  HAZARDWAIT: %u\n", hazardwait);
562
  else
563
    if (config.cpu.superscalar)
564
      printf ("\n");
565
 
566 306 markom
  dumpmemory(pc, pc + 4, 1, 0);
567 269 markom
  printf(" (next insn) %s", (delay_insn?"(delay insn)":""));
568
  for(i = 0; i < MAX_GPRS; i++) {
569
    if (i % 4 == 0)
570
      printf("\n");
571 560 markom
    printf("GPR%.2u: %.8lx  ", i, evalsim_reg32(i));
572 269 markom
  }
573
  printf("flag: %u\n", flag);
574 2 cvs
}
575 123 markom
 
576
/* Address calculation changed by CZ on 27/05/01 */
577 560 markom
static inline void decode_execute(struct iqueue_entry *current)
578 123 markom
{
579 560 markom
  int insn_index;
580 123 markom
  next_delay_insn = 0;
581
  breakpoint = 0;
582 560 markom
 
583 550 markom
  if(config.debug.enabled && CheckDebugUnit(DebugInstructionFetch, pc_phy))
584 123 markom
    breakpoint++;
585 138 markom
 
586 560 markom
  IFF (config.cpu.dependstats) current->func_unit = it_unknown;
587
 
588
  current->insn_index = insn_index = insn_decode(current->insn);
589 123 markom
 
590
#ifndef HAS_EXECUTION
591
#error HAS_EXECUTION has to be defined in order to execute programs.
592
#endif
593 133 markom
 
594 560 markom
  cur = current;  /* globals; needed by eval/set_operand */
595
 
596
  if (insn_index < 0)
597 123 markom
    l_invalid();
598 560 markom
  else {
599
    op = &cur->op[0];
600
    eval_operands (cur->insn, insn_index, &breakpoint);
601
    or32_opcodes[insn_index].exec();
602
  }
603
 
604 458 simons
  /* Check for range exception */
605 557 markom
  if (testsprbits (SPR_SR, SPR_SR_OVE) && testsprbits (SPR_SR, SPR_SR_OV))
606 611 simons
    except_handle (EXCEPT_RANGE, mfspr(SPR_EEAR_BASE));
607 458 simons
 
608 263 markom
  if (config.cpu.dependstats) {
609 560 markom
    iqueue[0].insn_index = insn_index;
610 123 markom
    /* Dynamic, dependency stats. */
611 535 markom
    adddstats(icomplet[0].insn_index, iqueue[0].insn_index, 1, check_depend());
612 262 markom
 
613 123 markom
    /* Dynamic, functional units stats. */
614
    addfstats(icomplet[0].func_unit, iqueue[0].func_unit, 1, check_depend());
615 262 markom
 
616 123 markom
    /* Dynamic, single stats. */
617 535 markom
    addsstats(iqueue[0].insn_index, 1);
618 123 markom
  }
619 560 markom
 
620 263 markom
  if (config.cpu.superscalar) {
621 479 markom
    if ((cur->func_unit == it_branch) || (cur->func_unit == it_jump))
622 123 markom
      storecycles += 0;
623
 
624 479 markom
    if (cur->func_unit == it_store)
625 389 lampret
      storecycles += 1;
626 123 markom
 
627 479 markom
    if (cur->func_unit == it_load)
628 389 lampret
      loadcycles += 1;
629
#if 0        
630 479 markom
    if ((icomplet[0].func_unit == it_load) && check_depend())
631 123 markom
      loadcycles++;
632 389 lampret
#endif
633 123 markom
 
634
    /* Pseudo multiple issue benchmark */
635
    if ((multissue[cur->func_unit] < 1) || (check_depend())
636 560 markom
     || (issued_per_cycle < 1)) {
637 123 markom
      int i;
638
      for (i = 0; i < 20; i++)
639 262 markom
        multissue[i] = 2;
640 123 markom
      issued_per_cycle = 2;
641
      supercycles++;
642
      if (check_depend())
643 262 markom
        hazardwait++;
644 479 markom
      multissue[it_unknown] = 2;
645
      multissue[it_shift] = 2;
646
      multissue[it_compare] = 1;
647
      multissue[it_branch] = 1;
648
      multissue[it_jump] = 1;
649
      multissue[it_extend] = 2;
650
      multissue[it_nop] = 2;
651
      multissue[it_move] = 2;
652
      multissue[it_movimm] = 2;
653
      multissue[it_arith] = 2;
654
      multissue[it_store] = 2;
655
      multissue[it_load] = 2;
656 123 markom
    }
657
    multissue[cur->func_unit]--;
658
    issued_per_cycle--;
659
  }
660
  delay_insn = next_delay_insn;
661
 
662
  if(breakpoint)
663 611 simons
    except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
664 123 markom
}
665
 
666 557 markom
void cpu_reset()
667
{
668 606 markom
  int i;
669 557 markom
  cycles = 0;
670
  instructions = 0;
671
  supercycles = 0;
672
  loadcycles = 0;
673
  storecycles = 0;
674 606 markom
  for (i = 0; i < MAX_GPRS; i++)
675
    set_reg32 (i, 0);
676 557 markom
  memset(iqueue, 0, sizeof(iqueue));
677
  memset(icomplet, 0, sizeof(icomplet));
678 626 markom
 
679
  sbuf_head = 0;
680
  sbuf_tail = 0;
681
  sbuf_count = 0;
682
  sbuf_prev_cycles = 0;
683 557 markom
 
684
  /* Cpu configuration */
685
  mtspr(SPR_UPR, config.cpu.upr);
686
  setsprbits(SPR_VR, SPR_VR_VER, config.cpu.ver);
687
  setsprbits(SPR_VR, SPR_VR_REV, config.cpu.rev);
688
  mtspr(SPR_SR, config.cpu.sr);
689
 
690
  pcnext = 0x0; /* MM1409: All programs should start at reset vector entry!  */
691
  printf ("Starting at 0x%08x\n", pcnext);
692
  pc = pcnext;
693
  pc_phy = pc;
694
  pcnext += 4;
695
  debug(1, "reset ...\n");
696
 
697
  /* MM1409: All programs should set their stack pointer!  */
698
  except_handle(EXCEPT_RESET, 0);
699
}
700
 
701
inline int cpu_clock ()
702
{
703
  if(fetch()) {
704
    printf ("Breakpoint hit.\n");
705
    cont_run = 0; /* memory breakpoint encountered */
706
    return 1;
707
  }
708
  decode_execute(&iqueue[0]);
709
  update_pc();
710
  analysis();
711
  if (config.sim.exe_log) dump_exe_log();
712
  return 0;
713
}
714
 
715 123 markom
/******************************************
716
 *    Instruction specific functions.     *
717
 ******************************************/
718
 
719
void l_add() {
720 221 markom
  signed long temp1;
721 123 markom
  signed char temp4;
722
 
723 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
724 221 markom
  temp1 = (signed long)eval_operand32(2, &breakpoint)+(signed long)eval_operand32(1, &breakpoint);
725
  set_operand32(0, temp1, &breakpoint);
726 605 markom
  set_ov_flag (temp1);
727 620 markom
  if (ARITH_SET_FLAG) {
728
    flag = temp1 == 0;
729
    setsprbits(SPR_SR, SPR_SR_F, flag);
730
  }
731 615 markom
 
732 123 markom
  temp4 = temp1;
733
  if (temp4 == temp1)
734
    mstats.byteadd++;
735
}
736 557 markom
void l_sw() {
737 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_store;
738 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint), &breakpoint);
739 626 markom
  if (config.cpu.sbuf_len) sbuf_store (mem_cycles);
740 123 markom
}
741
void l_sb() {
742 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_store;
743 221 markom
  set_operand8(0, eval_operand32(1, &breakpoint), &breakpoint);
744 626 markom
  if (config.cpu.sbuf_len) sbuf_store (mem_cycles);
745 123 markom
}
746
void l_sh() {
747 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_store;
748 221 markom
  set_operand16(0, eval_operand32(1, &breakpoint), &breakpoint);
749 626 markom
  if (config.cpu.sbuf_len) sbuf_store (mem_cycles);
750 123 markom
}
751
void l_lwz() {
752 437 simons
  unsigned long val;
753 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
754 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
755 437 simons
  val = eval_operand32(1, &breakpoint);
756 619 markom
  /* If eval operand produced exception don't set anything */
757 558 markom
  if (!pending.valid)
758
    set_operand32(0, val, &breakpoint);
759 123 markom
}
760
void l_lbs() {
761 437 simons
  signed char val;
762 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
763 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
764 437 simons
  val = eval_operand8(1, &breakpoint);
765
  /* If eval opreand produced exception don't set anything */
766 558 markom
  if (!pending.valid)
767
    set_operand32(0, val, &breakpoint);
768 123 markom
}
769 221 markom
void l_lbz() {
770 437 simons
  unsigned char val;
771 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
772 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
773 437 simons
  val = eval_operand8(1, &breakpoint);
774
  /* If eval opreand produced exception don't set anything */
775 558 markom
  if (!pending.valid)
776
    set_operand32(0, val, &breakpoint);
777 123 markom
}
778 221 markom
void l_lhs() {
779 437 simons
  signed short val;
780 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
781 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
782 437 simons
  val = eval_operand16(1, &breakpoint);
783
  /* If eval opreand produced exception don't set anything */
784 558 markom
  if (!pending.valid)
785
    set_operand32(0, val, &breakpoint);
786 123 markom
}
787 221 markom
void l_lhz() {
788 437 simons
  unsigned short val;
789 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
790 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
791 437 simons
  val = eval_operand16(1, &breakpoint);
792
  /* If eval opreand produced exception don't set anything */
793 558 markom
  if (!pending.valid)
794
    set_operand32(0, val, &breakpoint);
795 123 markom
}
796
void l_movhi() {
797 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_movimm;
798 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint) << 16, &breakpoint);
799 123 markom
}
800
void l_and() {
801 615 markom
  unsigned long temp1;
802 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
803 615 markom
  set_operand32(0, temp1 = set_ov_flag (eval_operand32(1, &breakpoint) & (unsigned)eval_operand32(2, &breakpoint)), &breakpoint);
804 620 markom
  if (ARITH_SET_FLAG) {
805
    flag = temp1 == 0;
806
    setsprbits(SPR_SR, SPR_SR_F, flag);
807
  }
808 123 markom
}
809
void l_or() {
810 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
811 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) | (unsigned)eval_operand32(2, &breakpoint)), &breakpoint);
812 123 markom
}
813
void l_xor() {
814 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
815 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) ^ (signed)eval_operand32(2, &breakpoint)), &breakpoint);
816 123 markom
}
817
void l_sub() {
818 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
819 605 markom
  set_operand32(0, set_ov_flag ((signed long)eval_operand32(1, &breakpoint) - (signed long)eval_operand32(2, &breakpoint)), &breakpoint);
820 123 markom
}
821 174 markom
/*int mcount = 0;*/
822 123 markom
void l_mul() {
823
  signed long temp3, temp2, temp1;
824
 
825 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
826 605 markom
  set_operand32(0, set_ov_flag ((signed long)eval_operand32(1, &breakpoint) * (signed long)eval_operand32(2, &breakpoint)), &breakpoint);
827 174 markom
  /*if (!(mcount++ & 1023)) {
828
    printf ("[%i]\n",mcount);
829
    }*/
830 123 markom
}
831
void l_div() {
832
  signed long temp3, temp2, temp1;
833
 
834 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
835 221 markom
  temp3 = eval_operand32(2, &breakpoint);
836
  temp2 = eval_operand32(1, &breakpoint);
837 123 markom
  if (temp3)
838
    temp1 = temp2 / temp3;
839 458 simons
  else {
840
    except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
841
    return;
842
  }
843 605 markom
  set_operand32(0, set_ov_flag (temp1), &breakpoint);
844 123 markom
}
845
void l_divu() {
846
  unsigned long temp3, temp2, temp1;
847
 
848 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
849 221 markom
  temp3 = eval_operand32(2, &breakpoint);
850
  temp2 = eval_operand32(1, &breakpoint);
851 123 markom
  temp1 = temp2 / temp3;
852
  /* cycles += 16; */
853 605 markom
  set_operand32(0, set_ov_flag (temp1), &breakpoint);
854 123 markom
}
855
void l_sll() {
856
  int sign = 1;
857 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_shift;
858 221 markom
  if ((signed)eval_operand32(1, &breakpoint) < 0)
859 123 markom
    sign = -1;
860
  /* cycles += 2; */
861 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) << eval_operand32(2, &breakpoint)), &breakpoint);
862 123 markom
}
863
void l_sra() {
864
  unsigned long sign = 0;
865 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_shift;
866 123 markom
 
867 221 markom
  if ((signed)eval_operand32(1, &breakpoint) < 0)
868 123 markom
    sign = -1;
869
  /* cycles += 2; */
870 605 markom
  set_operand32(0, set_ov_flag ((signed)eval_operand32(1, &breakpoint) >> eval_operand32(2, &breakpoint)), &breakpoint);
871 123 markom
}
872
void l_srl() {
873 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_shift;
874 123 markom
  /* cycles += 2; */
875 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) >> eval_operand32(2, &breakpoint)), &breakpoint);
876 123 markom
}
877 535 markom
void l_bf() {
878 541 markom
  if (config.bpb.enabled) {
879 535 markom
    int fwd = (eval_operand32(0, &breakpoint) >= pc) ? 1 : 0;
880 558 markom
    IFF (config.cpu.dependstats) cur->func_unit = it_branch;
881 535 markom
    mstats.bf[flag][fwd]++;
882
    bpb_update(cur->insn_addr, flag);
883
  }
884
  if (flag) {
885
    debug(5, "\nl.bf relative: pc=%x pcnext=%x\n", pc, pcnext);
886
    pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
887
    btic_update(pcnext);
888
    next_delay_insn = 1;
889
  } else {
890
    btic_update(pc);
891
  }
892
}
893
void l_bnf() {
894 541 markom
  if (config.bpb.enabled) {
895 535 markom
    int fwd = (eval_operand32(0, &breakpoint) >= pc) ? 1 : 0;
896 558 markom
    IFF (config.cpu.dependstats) cur->func_unit = it_branch;
897 535 markom
    mstats.bnf[!flag][fwd]++;
898
    bpb_update(cur->insn_addr, flag == 0);
899
  }
900
  if (flag == 0) {
901
    debug(5, "\nl.bnf relative: pc=%x pcnext=%x\n", pc, pcnext);
902
    pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
903
    btic_update(pcnext);
904
    next_delay_insn = 1;
905
  } else {
906
    btic_update(pc);
907
  }
908
}
909 123 markom
void l_j() {
910 344 markom
  debug(5, "\nl.j relative: pc=%x pcnext=%x\n", pc, pcnext);
911 221 markom
  pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
912 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
913 123 markom
  next_delay_insn = 1;
914
}
915
void l_jal() {
916 344 markom
  debug(5, "\nl.jal relative: pc=%x pcnext=%x\n", pc, pcnext);
917 221 markom
  pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
918 123 markom
 
919 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
920 138 markom
  set_reg32(LINK_REGNO, pc + 8);
921 123 markom
  next_delay_insn = 1;
922 264 markom
  if (config.sim.profile) {
923 262 markom
    struct mem_entry *entry;
924 221 markom
    struct label_entry *tmp;
925 261 markom
    if (verify_memoryarea(pcdelay) && (tmp = get_label (pcdelay)))
926 361 markom
      fprintf (runtime.sim.fprof, "+%08X %08X %08X %s\n", cycles, pc + 8, pcdelay, tmp->name);
927 221 markom
    else
928 361 markom
      fprintf (runtime.sim.fprof, "+%08X %08X %08X @%08X\n", cycles, pc + 8, pcdelay, pcdelay);
929 173 markom
  }
930 123 markom
}
931
void l_jalr() {
932 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
933 221 markom
  pcdelay = eval_operand32(0, &breakpoint);
934 138 markom
  set_reg32(LINK_REGNO, pc + 8);
935 123 markom
  next_delay_insn = 1;
936
}
937
void l_jr() {
938 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
939 221 markom
  pcdelay = eval_operand32(0, &breakpoint);
940 123 markom
  next_delay_insn = 1;
941 482 markom
  if (config.sim.profile)
942
    fprintf (runtime.sim.fprof, "-%08X %08X\n", cycles, pcdelay);
943 123 markom
}
944
void l_rfe() {
945 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_exception;
946 416 simons
  pcnext = mfspr(SPR_EPCR_BASE);
947
  mtspr(SPR_SR, mfspr(SPR_ESR_BASE));
948
}
949 123 markom
void l_nop() {
950 511 markom
  unsigned long stackaddr;
951
  int k = eval_operand32(0, &breakpoint);
952 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_nop;
953 511 markom
  switch (k) {
954
    case NOP_NOP:
955
      break;
956
    case NOP_EXIT:
957 560 markom
      printf("exit(%d)\n", evalsim_reg32 (3));
958 511 markom
      if (config.debug.gdb_enabled)
959
        set_stall_state (1);
960
      else
961
        cont_run = 0;
962
      break;
963
    case NOP_PRINTF:
964 560 markom
      stackaddr = evalsim_reg32(4);
965
      simprintf(stackaddr, evalsim_reg32(3));
966 511 markom
      debug(5, "simprintf %x\n", stackaddr);
967
      break;
968
    case NOP_REPORT:
969 560 markom
      printf("report(0x%x);\n", evalsim_reg32(3));
970 511 markom
    default:
971
      if (k >= NOP_REPORT_FIRST && k <= NOP_REPORT_LAST)
972 604 markom
      printf("report %i (0x%x);\n", k - NOP_REPORT_FIRST, evalsim_reg32(3));
973 511 markom
      break;
974
  }
975 123 markom
}
976
void l_sfeq() {
977 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
978 221 markom
  flag = eval_operand32(0, &breakpoint) == eval_operand32(1, &breakpoint);
979 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
980
}
981 535 markom
void l_sfne() {
982 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
983 535 markom
  flag = eval_operand32(0, &breakpoint) != eval_operand32(1, &breakpoint);
984
  setsprbits(SPR_SR, SPR_SR_F, flag);
985
}
986 123 markom
void l_sfgts() {
987 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
988 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) > (signed)eval_operand32(1, &breakpoint);
989 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
990
}
991
void l_sfges() {
992 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
993 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) >= (signed)eval_operand32(1, &breakpoint);
994 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
995
}
996
void l_sflts() {
997 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
998 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) < (signed)eval_operand32(1, &breakpoint);
999 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1000
}
1001
void l_sfles() {
1002 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1003 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) <= (signed)eval_operand32(1, &breakpoint);
1004 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1005
}
1006
void l_sfgtu() {
1007 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1008 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) > (unsigned)eval_operand32(1, &breakpoint);
1009 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1010
}
1011
void l_sfgeu() {
1012 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1013 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) >= (unsigned) eval_operand32(1, &breakpoint);
1014 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1015
}
1016
void l_sfltu() {
1017 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1018 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) < (unsigned)eval_operand32(1, &breakpoint);
1019 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1020
}
1021
void l_sfleu() {
1022 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1023 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) <= (unsigned)eval_operand32(1, &breakpoint);
1024 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1025
}
1026 615 markom
void l_extbs() {
1027
  unsigned char x;
1028
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1029
  x = eval_operand32(1, &breakpoint);
1030
  set_operand32(0, (signed long)x, &breakpoint);
1031
}
1032
void l_extbz() {
1033
  unsigned char x;
1034
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1035
  x = eval_operand32(1, &breakpoint);
1036
  set_operand32(0, (unsigned long)x, &breakpoint);
1037
}
1038
void l_exths() {
1039
  unsigned short x;
1040
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1041
  x = eval_operand32(1, &breakpoint);
1042
  set_operand32(0, (signed long)x, &breakpoint);
1043
}
1044
void l_exthz() {
1045
  unsigned short x;
1046
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1047
  x = eval_operand32(1, &breakpoint);
1048
  set_operand32(0, (unsigned long)x, &breakpoint);
1049
}
1050
void l_extws() {
1051
  unsigned int x;
1052
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1053
  x = eval_operand32(1, &breakpoint);
1054
  set_operand32(0, (signed long)x, &breakpoint);
1055
}
1056
void l_extwz() {
1057
  unsigned int x;
1058
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1059
  x = eval_operand32(1, &breakpoint);
1060
  set_operand32(0, (unsigned long)x, &breakpoint);
1061
}
1062 123 markom
void l_mtspr() {
1063 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1064 600 simons
  if (mfspr(SPR_SR) & SPR_SR_SM)
1065 221 markom
    mtspr(eval_operand32(0, &breakpoint) + eval_operand32(2, &breakpoint), eval_operand32(1, &breakpoint));
1066 123 markom
  else {
1067
    printf("WARNING: trying to write SPR while SR[SUPV] is cleared.\n");
1068
    cont_run = 0;
1069
  }
1070
}
1071
void l_mfspr() {
1072 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1073 600 simons
  if (mfspr(SPR_SR) & SPR_SR_SM)
1074 221 markom
    set_operand32(0, mfspr(eval_operand32(1, &breakpoint) + eval_operand32(2, &breakpoint)), &breakpoint);
1075 123 markom
  else {
1076 221 markom
    set_operand32(0, 0, &breakpoint);
1077 123 markom
    printf("WARNING: trying to read SPR while SR[SUPV] is cleared.\n");
1078
    cont_run = 0;
1079
  }
1080
}
1081
void l_sys() {
1082 611 simons
  except_handle(EXCEPT_SYSCALL, mfspr(SPR_EEAR_BASE));
1083 123 markom
}
1084 142 chris
void l_trap() {
1085 479 markom
  /* TODO: some SR related code here! */
1086 611 simons
  except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
1087 142 chris
}
1088 123 markom
void l_mac() {
1089
  sprword lo, hi;
1090
  LONGEST l;
1091 604 markom
  long x, y;
1092 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_mac;
1093 123 markom
  lo = mfspr (SPR_MACLO);
1094
  hi = mfspr (SPR_MACHI);
1095 221 markom
  x = eval_operand32(0, &breakpoint);
1096
  y = eval_operand32(1, &breakpoint);
1097 498 lampret
  printf ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));
1098 221 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
1099
  l += (LONGEST) x * (LONGEST) y;
1100 123 markom
 
1101
  /* This implementation is very fast - it needs only one cycle for mac.  */
1102 221 markom
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
1103
  hi = ((LONGEST)l) >> 32;
1104 123 markom
  mtspr (SPR_MACLO, lo);
1105
  mtspr (SPR_MACHI, hi);
1106 498 lampret
  printf ("(%08x,%08x)\n", hi, lo);
1107 123 markom
}
1108
void l_msb() {
1109 221 markom
  sprword lo, hi;
1110 123 markom
  LONGEST l;
1111 604 markom
  long x, y;
1112 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_mac;
1113 123 markom
  lo = mfspr (SPR_MACLO);
1114
  hi = mfspr (SPR_MACHI);
1115 604 markom
  x = eval_operand32(0, &breakpoint);
1116
  y = eval_operand32(1, &breakpoint);
1117
  printf ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));
1118 221 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
1119
  l -= (LONGEST) eval_operand32(0, &breakpoint) * (LONGEST)eval_operand32(1, &breakpoint);
1120 123 markom
 
1121
  /* This implementation is very fast - it needs only one cycle for msb.  */
1122 221 markom
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
1123
  hi = ((LONGEST)l) >> 32;
1124 123 markom
  mtspr (SPR_MACLO, lo);
1125 221 markom
  mtspr (SPR_MACHI, hi);
1126 604 markom
  printf ("(%08x,%08x)\n", hi, lo);
1127 123 markom
}
1128
void l_macrc() {
1129
  sprword lo, hi;
1130
  LONGEST l;
1131 615 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_mac;
1132 123 markom
  /* No need for synchronization here -- all MAC instructions are 1 cycle long.  */
1133
  lo =  mfspr (SPR_MACLO);
1134 221 markom
  hi =  mfspr (SPR_MACHI);
1135
  l = (ULONGEST) lo | ((LONGEST)hi << 32);
1136
  l >>= 28;
1137
  //printf ("<%08x>\n", (unsigned long)l);
1138
  set_operand32(0, (long)l, &breakpoint);
1139 123 markom
  mtspr (SPR_MACLO, 0);
1140 221 markom
  mtspr (SPR_MACHI, 0);
1141 123 markom
}
1142 615 markom
void l_cmov() {
1143
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1144
  set_operand32 (0, flag ? eval_operand32(1, &breakpoint) : eval_operand32(2, &breakpoint), &breakpoint);
1145
}
1146 174 markom
void l_cust1() {
1147
  /*int destr = cur->insn >> 21;
1148
    int src1r = cur->insn >> 15;
1149
    int src2r = cur->insn >> 9;*/
1150
}
1151
void l_cust2() {
1152
}
1153
void l_cust3() {
1154
}
1155
void l_cust4() {
1156
}
1157 123 markom
void l_invalid() {
1158 458 simons
  except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
1159 123 markom
}

powered by: WebSVN 2.1.0

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