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

Subversion Repositories or1k

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

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 631 simons
    pc_phy = immu_translate(pc, 0);
423 574 markom
 
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 630 markom
static inline sbuf_store (int cyc) {
477 626 markom
  int delta = cycles - sbuf_prev_cycles;
478
  sbuf_total_cyc += cyc;
479 630 markom
  sbuf_prev_cycles = cycles;
480 626 markom
 
481 630 markom
  //printf (">STORE %i,%i,%i,%i,%i\n", delta, sbuf_count, sbuf_tail, sbuf_head, sbuf_buf[sbuf_tail], sbuf_buf[sbuf_head]);
482
  //printf ("|%i,%i\n", sbuf_total_cyc, sbuf_wait_cyc);
483 626 markom
  /* Take stores from buffer, that occured meanwhile */
484 630 markom
  while (sbuf_count && delta >= sbuf_buf[sbuf_tail]) {
485 626 markom
    delta -= sbuf_buf[sbuf_tail];
486
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
487
    sbuf_count--;
488
  }
489
  if (sbuf_count)
490
    sbuf_buf[sbuf_tail] -= delta;
491 630 markom
 
492 626 markom
  /* Store buffer is full, take one out */
493
  if (sbuf_count >= config.cpu.sbuf_len) {
494
    sbuf_wait_cyc += sbuf_buf[sbuf_tail];
495
    mem_cycles += sbuf_buf[sbuf_tail];
496 630 markom
    sbuf_prev_cycles += sbuf_buf[sbuf_tail];
497 626 markom
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
498
    sbuf_count--;
499
  }
500
  /* Put newest store in the buffer */
501
  sbuf_buf[sbuf_head] = cyc;
502
  sbuf_head = (sbuf_head + 1) % MAX_SBUF_LEN;
503
  sbuf_count++;
504 630 markom
  //printf ("|STORE %i,%i,%i,%i,%i\n", delta, sbuf_count, sbuf_tail, sbuf_head, sbuf_buf[sbuf_tail], sbuf_buf[sbuf_head]);
505 626 markom
}
506 294 markom
 
507 626 markom
/* Store buffer analysis - previous stores should commit, before any load */
508
static inline sbuf_load () {
509 629 markom
  int delta = cycles - sbuf_prev_cycles;
510 630 markom
  sbuf_prev_cycles = cycles;
511
 
512
  //printf (">LOAD  %i,%i,%i,%i,%i\n", delta, sbuf_count, sbuf_tail, sbuf_head, sbuf_buf[sbuf_tail], sbuf_buf[sbuf_head]);
513
  //printf ("|%i,%i\n", sbuf_total_cyc, sbuf_wait_cyc);
514 629 markom
  /* Take stores from buffer, that occured meanwhile */
515 630 markom
  while (sbuf_count && delta >= sbuf_buf[sbuf_tail]) {
516 629 markom
    delta -= sbuf_buf[sbuf_tail];
517
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
518
    sbuf_count--;
519
  }
520
  if (sbuf_count)
521
    sbuf_buf[sbuf_tail] -= delta;
522
 
523 626 markom
  /* Wait for all stores to complete */
524
  while (sbuf_count > 0) {
525
    sbuf_wait_cyc += sbuf_buf[sbuf_tail];
526
    mem_cycles += sbuf_buf[sbuf_tail];
527 630 markom
    sbuf_prev_cycles += sbuf_buf[sbuf_tail];
528 626 markom
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
529
    sbuf_count--;
530
  }
531 630 markom
  //printf ("|LOAD  %i,%i,%i,%i,%i\n", delta, sbuf_count, sbuf_tail, sbuf_head, sbuf_buf[sbuf_tail], sbuf_buf[sbuf_head]);
532 626 markom
}
533
 
534 294 markom
/* Execution logger.  */
535
inline void dump_exe_log()
536
{
537 479 markom
  unsigned long i = iqueue[0].insn_addr;
538 294 markom
 
539 479 markom
  if (i == 0xffffffff) return;
540 361 markom
  fprintf(runtime.sim.fexe_log, "\nEXECUTED(): %.8lx:  ", i);
541
  fprintf(runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i), evalsim_mem8(i + 1));
542
  fprintf(runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i + 2), evalsim_mem8(i + 3));
543
  for(i = 0; i < MAX_GPRS; i++) {
544
    if (i % 4 == 0)
545
      fprintf(runtime.sim.fexe_log, "\n");
546
    fprintf(runtime.sim.fexe_log, "GPR%2u: %.8lx  ", i, reg[i]);
547
  }
548
  fprintf(runtime.sim.fexe_log, "\n");
549
  fprintf(runtime.sim.fexe_log, "SR   : %.8lx  ", mfspr(SPR_SR));
550
  fprintf(runtime.sim.fexe_log, "EPCR0: %.8lx  ", mfspr(SPR_EPCR_BASE));
551
  fprintf(runtime.sim.fexe_log, "EEAR0: %.8lx  ", mfspr(SPR_EEAR_BASE));
552
  fprintf(runtime.sim.fexe_log, "ESR0 : %.8lx\n", mfspr(SPR_ESR_BASE));
553 294 markom
}
554
 
555 537 markom
#if 0
556 535 markom
void print_time (int cycles, char *output)
557
{
558
  int i = 0, c_ps = config.sim.clkcycle_ps;
559
  while (c_ps % 1000 == 0 && i < 2) {
560
    c_ps /= 1000;
561
    i++;
562
  }
563
  c_ps *= cycles;
564
  sprintf (output, "%i%cs", cycles, i == 0 ? 'p' : i == 1 ? 'n': 'u');
565
}
566 537 markom
#endif
567 535 markom
 
568 2 cvs
void dumpreg()
569
{
570 269 markom
  int i;
571 535 markom
  char temp[100];
572 269 markom
 
573 306 markom
  dumpmemory(iqueue[0].insn_addr, iqueue[0].insn_addr + 4, 1, 0);
574 537 markom
  generate_time_pretty (temp, cycles);
575 535 markom
  printf(" (executed) [time %s, #%i]\n", temp, instructions);
576 293 markom
  if (config.cpu.superscalar)
577
    printf ("Superscalar CYCLES: %u", supercycles);
578
  if (config.cpu.hazards)
579
    printf ("  HAZARDWAIT: %u\n", hazardwait);
580
  else
581
    if (config.cpu.superscalar)
582
      printf ("\n");
583
 
584 306 markom
  dumpmemory(pc, pc + 4, 1, 0);
585 269 markom
  printf(" (next insn) %s", (delay_insn?"(delay insn)":""));
586
  for(i = 0; i < MAX_GPRS; i++) {
587
    if (i % 4 == 0)
588
      printf("\n");
589 560 markom
    printf("GPR%.2u: %.8lx  ", i, evalsim_reg32(i));
590 269 markom
  }
591
  printf("flag: %u\n", flag);
592 2 cvs
}
593 123 markom
 
594
/* Address calculation changed by CZ on 27/05/01 */
595 560 markom
static inline void decode_execute(struct iqueue_entry *current)
596 123 markom
{
597 560 markom
  int insn_index;
598 123 markom
  next_delay_insn = 0;
599
  breakpoint = 0;
600 560 markom
 
601 550 markom
  if(config.debug.enabled && CheckDebugUnit(DebugInstructionFetch, pc_phy))
602 123 markom
    breakpoint++;
603 138 markom
 
604 560 markom
  IFF (config.cpu.dependstats) current->func_unit = it_unknown;
605
 
606
  current->insn_index = insn_index = insn_decode(current->insn);
607 123 markom
 
608
#ifndef HAS_EXECUTION
609
#error HAS_EXECUTION has to be defined in order to execute programs.
610
#endif
611 133 markom
 
612 560 markom
  cur = current;  /* globals; needed by eval/set_operand */
613
 
614
  if (insn_index < 0)
615 123 markom
    l_invalid();
616 560 markom
  else {
617
    op = &cur->op[0];
618
    eval_operands (cur->insn, insn_index, &breakpoint);
619
    or32_opcodes[insn_index].exec();
620
  }
621
 
622 458 simons
  /* Check for range exception */
623 557 markom
  if (testsprbits (SPR_SR, SPR_SR_OVE) && testsprbits (SPR_SR, SPR_SR_OV))
624 611 simons
    except_handle (EXCEPT_RANGE, mfspr(SPR_EEAR_BASE));
625 458 simons
 
626 263 markom
  if (config.cpu.dependstats) {
627 560 markom
    iqueue[0].insn_index = insn_index;
628 123 markom
    /* Dynamic, dependency stats. */
629 535 markom
    adddstats(icomplet[0].insn_index, iqueue[0].insn_index, 1, check_depend());
630 262 markom
 
631 123 markom
    /* Dynamic, functional units stats. */
632
    addfstats(icomplet[0].func_unit, iqueue[0].func_unit, 1, check_depend());
633 262 markom
 
634 123 markom
    /* Dynamic, single stats. */
635 535 markom
    addsstats(iqueue[0].insn_index, 1);
636 123 markom
  }
637 560 markom
 
638 263 markom
  if (config.cpu.superscalar) {
639 479 markom
    if ((cur->func_unit == it_branch) || (cur->func_unit == it_jump))
640 123 markom
      storecycles += 0;
641
 
642 479 markom
    if (cur->func_unit == it_store)
643 389 lampret
      storecycles += 1;
644 123 markom
 
645 479 markom
    if (cur->func_unit == it_load)
646 389 lampret
      loadcycles += 1;
647
#if 0        
648 479 markom
    if ((icomplet[0].func_unit == it_load) && check_depend())
649 123 markom
      loadcycles++;
650 389 lampret
#endif
651 123 markom
 
652
    /* Pseudo multiple issue benchmark */
653
    if ((multissue[cur->func_unit] < 1) || (check_depend())
654 560 markom
     || (issued_per_cycle < 1)) {
655 123 markom
      int i;
656
      for (i = 0; i < 20; i++)
657 262 markom
        multissue[i] = 2;
658 123 markom
      issued_per_cycle = 2;
659
      supercycles++;
660
      if (check_depend())
661 262 markom
        hazardwait++;
662 479 markom
      multissue[it_unknown] = 2;
663
      multissue[it_shift] = 2;
664
      multissue[it_compare] = 1;
665
      multissue[it_branch] = 1;
666
      multissue[it_jump] = 1;
667
      multissue[it_extend] = 2;
668
      multissue[it_nop] = 2;
669
      multissue[it_move] = 2;
670
      multissue[it_movimm] = 2;
671
      multissue[it_arith] = 2;
672
      multissue[it_store] = 2;
673
      multissue[it_load] = 2;
674 123 markom
    }
675
    multissue[cur->func_unit]--;
676
    issued_per_cycle--;
677
  }
678
  delay_insn = next_delay_insn;
679
 
680
  if(breakpoint)
681 611 simons
    except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
682 123 markom
}
683
 
684 557 markom
void cpu_reset()
685
{
686 606 markom
  int i;
687 557 markom
  cycles = 0;
688
  instructions = 0;
689
  supercycles = 0;
690
  loadcycles = 0;
691
  storecycles = 0;
692 606 markom
  for (i = 0; i < MAX_GPRS; i++)
693
    set_reg32 (i, 0);
694 557 markom
  memset(iqueue, 0, sizeof(iqueue));
695
  memset(icomplet, 0, sizeof(icomplet));
696 626 markom
 
697
  sbuf_head = 0;
698
  sbuf_tail = 0;
699
  sbuf_count = 0;
700
  sbuf_prev_cycles = 0;
701 557 markom
 
702
  /* Cpu configuration */
703
  mtspr(SPR_UPR, config.cpu.upr);
704
  setsprbits(SPR_VR, SPR_VR_VER, config.cpu.ver);
705
  setsprbits(SPR_VR, SPR_VR_REV, config.cpu.rev);
706
  mtspr(SPR_SR, config.cpu.sr);
707
 
708
  pcnext = 0x0; /* MM1409: All programs should start at reset vector entry!  */
709
  printf ("Starting at 0x%08x\n", pcnext);
710
  pc = pcnext;
711
  pc_phy = pc;
712
  pcnext += 4;
713
  debug(1, "reset ...\n");
714
 
715
  /* MM1409: All programs should set their stack pointer!  */
716
  except_handle(EXCEPT_RESET, 0);
717
}
718
 
719
inline int cpu_clock ()
720
{
721
  if(fetch()) {
722
    printf ("Breakpoint hit.\n");
723
    cont_run = 0; /* memory breakpoint encountered */
724
    return 1;
725
  }
726
  decode_execute(&iqueue[0]);
727
  update_pc();
728
  analysis();
729
  if (config.sim.exe_log) dump_exe_log();
730
  return 0;
731
}
732
 
733 123 markom
/******************************************
734
 *    Instruction specific functions.     *
735
 ******************************************/
736
 
737
void l_add() {
738 221 markom
  signed long temp1;
739 123 markom
  signed char temp4;
740
 
741 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
742 221 markom
  temp1 = (signed long)eval_operand32(2, &breakpoint)+(signed long)eval_operand32(1, &breakpoint);
743
  set_operand32(0, temp1, &breakpoint);
744 605 markom
  set_ov_flag (temp1);
745 620 markom
  if (ARITH_SET_FLAG) {
746
    flag = temp1 == 0;
747
    setsprbits(SPR_SR, SPR_SR_F, flag);
748
  }
749 615 markom
 
750 123 markom
  temp4 = temp1;
751
  if (temp4 == temp1)
752
    mstats.byteadd++;
753
}
754 557 markom
void l_sw() {
755 630 markom
  int old_cyc = 0;
756 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_store;
757 630 markom
  IFF (config.cpu.sbuf_len) old_cyc = mem_cycles;
758 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint), &breakpoint);
759 630 markom
  if (config.cpu.sbuf_len) {
760
    int t = mem_cycles;
761
    mem_cycles = old_cyc;
762
    sbuf_store (t - old_cyc);
763
  }
764 123 markom
}
765
void l_sb() {
766 630 markom
  int old_cyc = 0;
767 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_store;
768 630 markom
  IFF (config.cpu.sbuf_len) old_cyc = mem_cycles;
769 221 markom
  set_operand8(0, eval_operand32(1, &breakpoint), &breakpoint);
770 630 markom
  if (config.cpu.sbuf_len) {
771
    int t = mem_cycles;
772
    mem_cycles = old_cyc;
773
    sbuf_store (t- old_cyc);
774
  }
775 123 markom
}
776
void l_sh() {
777 630 markom
  int old_cyc = 0;
778 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_store;
779 630 markom
  IFF (config.cpu.sbuf_len) old_cyc = mem_cycles;
780 221 markom
  set_operand16(0, eval_operand32(1, &breakpoint), &breakpoint);
781 630 markom
  if (config.cpu.sbuf_len) {
782
    int t = mem_cycles;
783
    mem_cycles = old_cyc;
784
    sbuf_store (t - old_cyc);
785
  }
786 123 markom
}
787
void l_lwz() {
788 437 simons
  unsigned long 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_operand32(1, &breakpoint);
792 619 markom
  /* If eval operand produced exception don't set anything */
793 558 markom
  if (!pending.valid)
794
    set_operand32(0, val, &breakpoint);
795 123 markom
}
796
void l_lbs() {
797 437 simons
  signed char val;
798 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
799 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
800 437 simons
  val = eval_operand8(1, &breakpoint);
801
  /* If eval opreand produced exception don't set anything */
802 558 markom
  if (!pending.valid)
803
    set_operand32(0, val, &breakpoint);
804 123 markom
}
805 221 markom
void l_lbz() {
806 437 simons
  unsigned char val;
807 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
808 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
809 437 simons
  val = eval_operand8(1, &breakpoint);
810
  /* If eval opreand produced exception don't set anything */
811 558 markom
  if (!pending.valid)
812
    set_operand32(0, val, &breakpoint);
813 123 markom
}
814 221 markom
void l_lhs() {
815 437 simons
  signed short val;
816 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
817 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
818 437 simons
  val = eval_operand16(1, &breakpoint);
819
  /* If eval opreand produced exception don't set anything */
820 558 markom
  if (!pending.valid)
821
    set_operand32(0, val, &breakpoint);
822 123 markom
}
823 221 markom
void l_lhz() {
824 437 simons
  unsigned short val;
825 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
826 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
827 437 simons
  val = eval_operand16(1, &breakpoint);
828
  /* If eval opreand produced exception don't set anything */
829 558 markom
  if (!pending.valid)
830
    set_operand32(0, val, &breakpoint);
831 123 markom
}
832
void l_movhi() {
833 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_movimm;
834 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint) << 16, &breakpoint);
835 123 markom
}
836
void l_and() {
837 615 markom
  unsigned long temp1;
838 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
839 615 markom
  set_operand32(0, temp1 = set_ov_flag (eval_operand32(1, &breakpoint) & (unsigned)eval_operand32(2, &breakpoint)), &breakpoint);
840 620 markom
  if (ARITH_SET_FLAG) {
841
    flag = temp1 == 0;
842
    setsprbits(SPR_SR, SPR_SR_F, flag);
843
  }
844 123 markom
}
845
void l_or() {
846 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
847 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) | (unsigned)eval_operand32(2, &breakpoint)), &breakpoint);
848 123 markom
}
849
void l_xor() {
850 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
851 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) ^ (signed)eval_operand32(2, &breakpoint)), &breakpoint);
852 123 markom
}
853
void l_sub() {
854 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
855 605 markom
  set_operand32(0, set_ov_flag ((signed long)eval_operand32(1, &breakpoint) - (signed long)eval_operand32(2, &breakpoint)), &breakpoint);
856 123 markom
}
857 174 markom
/*int mcount = 0;*/
858 123 markom
void l_mul() {
859
  signed long temp3, temp2, temp1;
860
 
861 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
862 605 markom
  set_operand32(0, set_ov_flag ((signed long)eval_operand32(1, &breakpoint) * (signed long)eval_operand32(2, &breakpoint)), &breakpoint);
863 174 markom
  /*if (!(mcount++ & 1023)) {
864
    printf ("[%i]\n",mcount);
865
    }*/
866 123 markom
}
867
void l_div() {
868
  signed long temp3, temp2, temp1;
869
 
870 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
871 221 markom
  temp3 = eval_operand32(2, &breakpoint);
872
  temp2 = eval_operand32(1, &breakpoint);
873 123 markom
  if (temp3)
874
    temp1 = temp2 / temp3;
875 458 simons
  else {
876
    except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
877
    return;
878
  }
879 605 markom
  set_operand32(0, set_ov_flag (temp1), &breakpoint);
880 123 markom
}
881
void l_divu() {
882
  unsigned long temp3, temp2, temp1;
883
 
884 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
885 221 markom
  temp3 = eval_operand32(2, &breakpoint);
886
  temp2 = eval_operand32(1, &breakpoint);
887 123 markom
  temp1 = temp2 / temp3;
888
  /* cycles += 16; */
889 605 markom
  set_operand32(0, set_ov_flag (temp1), &breakpoint);
890 123 markom
}
891
void l_sll() {
892
  int sign = 1;
893 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_shift;
894 221 markom
  if ((signed)eval_operand32(1, &breakpoint) < 0)
895 123 markom
    sign = -1;
896
  /* cycles += 2; */
897 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) << eval_operand32(2, &breakpoint)), &breakpoint);
898 123 markom
}
899
void l_sra() {
900
  unsigned long sign = 0;
901 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_shift;
902 123 markom
 
903 221 markom
  if ((signed)eval_operand32(1, &breakpoint) < 0)
904 123 markom
    sign = -1;
905
  /* cycles += 2; */
906 605 markom
  set_operand32(0, set_ov_flag ((signed)eval_operand32(1, &breakpoint) >> eval_operand32(2, &breakpoint)), &breakpoint);
907 123 markom
}
908
void l_srl() {
909 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_shift;
910 123 markom
  /* cycles += 2; */
911 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) >> eval_operand32(2, &breakpoint)), &breakpoint);
912 123 markom
}
913 535 markom
void l_bf() {
914 541 markom
  if (config.bpb.enabled) {
915 535 markom
    int fwd = (eval_operand32(0, &breakpoint) >= pc) ? 1 : 0;
916 558 markom
    IFF (config.cpu.dependstats) cur->func_unit = it_branch;
917 535 markom
    mstats.bf[flag][fwd]++;
918
    bpb_update(cur->insn_addr, flag);
919
  }
920
  if (flag) {
921
    debug(5, "\nl.bf relative: pc=%x pcnext=%x\n", pc, pcnext);
922
    pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
923
    btic_update(pcnext);
924
    next_delay_insn = 1;
925
  } else {
926
    btic_update(pc);
927
  }
928
}
929
void l_bnf() {
930 541 markom
  if (config.bpb.enabled) {
931 535 markom
    int fwd = (eval_operand32(0, &breakpoint) >= pc) ? 1 : 0;
932 558 markom
    IFF (config.cpu.dependstats) cur->func_unit = it_branch;
933 535 markom
    mstats.bnf[!flag][fwd]++;
934
    bpb_update(cur->insn_addr, flag == 0);
935
  }
936
  if (flag == 0) {
937
    debug(5, "\nl.bnf relative: pc=%x pcnext=%x\n", pc, pcnext);
938
    pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
939
    btic_update(pcnext);
940
    next_delay_insn = 1;
941
  } else {
942
    btic_update(pc);
943
  }
944
}
945 123 markom
void l_j() {
946 344 markom
  debug(5, "\nl.j relative: pc=%x pcnext=%x\n", pc, pcnext);
947 221 markom
  pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
948 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
949 123 markom
  next_delay_insn = 1;
950
}
951
void l_jal() {
952 344 markom
  debug(5, "\nl.jal relative: pc=%x pcnext=%x\n", pc, pcnext);
953 221 markom
  pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
954 123 markom
 
955 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
956 138 markom
  set_reg32(LINK_REGNO, pc + 8);
957 123 markom
  next_delay_insn = 1;
958 264 markom
  if (config.sim.profile) {
959 262 markom
    struct mem_entry *entry;
960 221 markom
    struct label_entry *tmp;
961 261 markom
    if (verify_memoryarea(pcdelay) && (tmp = get_label (pcdelay)))
962 361 markom
      fprintf (runtime.sim.fprof, "+%08X %08X %08X %s\n", cycles, pc + 8, pcdelay, tmp->name);
963 221 markom
    else
964 361 markom
      fprintf (runtime.sim.fprof, "+%08X %08X %08X @%08X\n", cycles, pc + 8, pcdelay, pcdelay);
965 173 markom
  }
966 123 markom
}
967
void l_jalr() {
968 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
969 221 markom
  pcdelay = eval_operand32(0, &breakpoint);
970 138 markom
  set_reg32(LINK_REGNO, pc + 8);
971 123 markom
  next_delay_insn = 1;
972
}
973
void l_jr() {
974 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
975 221 markom
  pcdelay = eval_operand32(0, &breakpoint);
976 123 markom
  next_delay_insn = 1;
977 482 markom
  if (config.sim.profile)
978
    fprintf (runtime.sim.fprof, "-%08X %08X\n", cycles, pcdelay);
979 123 markom
}
980
void l_rfe() {
981 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_exception;
982 416 simons
  pcnext = mfspr(SPR_EPCR_BASE);
983
  mtspr(SPR_SR, mfspr(SPR_ESR_BASE));
984
}
985 123 markom
void l_nop() {
986 511 markom
  unsigned long stackaddr;
987
  int k = eval_operand32(0, &breakpoint);
988 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_nop;
989 511 markom
  switch (k) {
990
    case NOP_NOP:
991
      break;
992
    case NOP_EXIT:
993 560 markom
      printf("exit(%d)\n", evalsim_reg32 (3));
994 511 markom
      if (config.debug.gdb_enabled)
995
        set_stall_state (1);
996
      else
997
        cont_run = 0;
998
      break;
999
    case NOP_PRINTF:
1000 560 markom
      stackaddr = evalsim_reg32(4);
1001
      simprintf(stackaddr, evalsim_reg32(3));
1002 511 markom
      debug(5, "simprintf %x\n", stackaddr);
1003
      break;
1004
    case NOP_REPORT:
1005 560 markom
      printf("report(0x%x);\n", evalsim_reg32(3));
1006 511 markom
    default:
1007
      if (k >= NOP_REPORT_FIRST && k <= NOP_REPORT_LAST)
1008 604 markom
      printf("report %i (0x%x);\n", k - NOP_REPORT_FIRST, evalsim_reg32(3));
1009 511 markom
      break;
1010
  }
1011 123 markom
}
1012
void l_sfeq() {
1013 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1014 221 markom
  flag = eval_operand32(0, &breakpoint) == eval_operand32(1, &breakpoint);
1015 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1016
}
1017 535 markom
void l_sfne() {
1018 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1019 535 markom
  flag = eval_operand32(0, &breakpoint) != eval_operand32(1, &breakpoint);
1020
  setsprbits(SPR_SR, SPR_SR_F, flag);
1021
}
1022 123 markom
void l_sfgts() {
1023 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1024 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) > (signed)eval_operand32(1, &breakpoint);
1025 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1026
}
1027
void l_sfges() {
1028 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1029 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) >= (signed)eval_operand32(1, &breakpoint);
1030 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1031
}
1032
void l_sflts() {
1033 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1034 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) < (signed)eval_operand32(1, &breakpoint);
1035 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1036
}
1037
void l_sfles() {
1038 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1039 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) <= (signed)eval_operand32(1, &breakpoint);
1040 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1041
}
1042
void l_sfgtu() {
1043 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1044 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) > (unsigned)eval_operand32(1, &breakpoint);
1045 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1046
}
1047
void l_sfgeu() {
1048 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1049 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) >= (unsigned) eval_operand32(1, &breakpoint);
1050 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1051
}
1052
void l_sfltu() {
1053 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1054 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) < (unsigned)eval_operand32(1, &breakpoint);
1055 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1056
}
1057
void l_sfleu() {
1058 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1059 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) <= (unsigned)eval_operand32(1, &breakpoint);
1060 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1061
}
1062 615 markom
void l_extbs() {
1063
  unsigned char x;
1064
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1065
  x = eval_operand32(1, &breakpoint);
1066
  set_operand32(0, (signed long)x, &breakpoint);
1067
}
1068
void l_extbz() {
1069
  unsigned char x;
1070
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1071
  x = eval_operand32(1, &breakpoint);
1072
  set_operand32(0, (unsigned long)x, &breakpoint);
1073
}
1074
void l_exths() {
1075
  unsigned short x;
1076
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1077
  x = eval_operand32(1, &breakpoint);
1078
  set_operand32(0, (signed long)x, &breakpoint);
1079
}
1080
void l_exthz() {
1081
  unsigned short x;
1082
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1083
  x = eval_operand32(1, &breakpoint);
1084
  set_operand32(0, (unsigned long)x, &breakpoint);
1085
}
1086
void l_extws() {
1087
  unsigned int x;
1088
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1089
  x = eval_operand32(1, &breakpoint);
1090
  set_operand32(0, (signed long)x, &breakpoint);
1091
}
1092
void l_extwz() {
1093
  unsigned int x;
1094
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1095
  x = eval_operand32(1, &breakpoint);
1096
  set_operand32(0, (unsigned long)x, &breakpoint);
1097
}
1098 123 markom
void l_mtspr() {
1099 641 ivang
  unsigned long regno = eval_operand32(0, &breakpoint) + eval_operand32(2, &breakpoint);
1100
  unsigned long value = eval_operand32(1, &breakpoint);
1101
 
1102
  if (runtime.sim.fspr_log) {
1103
    fprintf(runtime.sim.fspr_log, "Write to SPR  : [%08lX] <- [%08lX]\n", regno, value);
1104
  }
1105
 
1106 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1107 600 simons
  if (mfspr(SPR_SR) & SPR_SR_SM)
1108 641 ivang
    mtspr(regno, value);
1109 123 markom
  else {
1110
    printf("WARNING: trying to write SPR while SR[SUPV] is cleared.\n");
1111
    cont_run = 0;
1112
  }
1113
}
1114
void l_mfspr() {
1115 641 ivang
  unsigned long regno = eval_operand32(1, &breakpoint) + eval_operand32(2, &breakpoint);
1116
  unsigned long value = mfspr(regno);
1117
 
1118
  if (runtime.sim.fspr_log) {
1119
    fprintf(runtime.sim.fspr_log, "Read from SPR : [%08lX] -> [%08lX]\n", regno, value);
1120
  }
1121
 
1122 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1123 600 simons
  if (mfspr(SPR_SR) & SPR_SR_SM)
1124 641 ivang
    set_operand32(0, value, &breakpoint);
1125 123 markom
  else {
1126 221 markom
    set_operand32(0, 0, &breakpoint);
1127 123 markom
    printf("WARNING: trying to read SPR while SR[SUPV] is cleared.\n");
1128
    cont_run = 0;
1129
  }
1130
}
1131
void l_sys() {
1132 611 simons
  except_handle(EXCEPT_SYSCALL, mfspr(SPR_EEAR_BASE));
1133 123 markom
}
1134 142 chris
void l_trap() {
1135 479 markom
  /* TODO: some SR related code here! */
1136 611 simons
  except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
1137 142 chris
}
1138 123 markom
void l_mac() {
1139
  sprword lo, hi;
1140
  LONGEST l;
1141 604 markom
  long x, y;
1142 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_mac;
1143 123 markom
  lo = mfspr (SPR_MACLO);
1144
  hi = mfspr (SPR_MACHI);
1145 221 markom
  x = eval_operand32(0, &breakpoint);
1146
  y = eval_operand32(1, &breakpoint);
1147 498 lampret
  printf ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));
1148 221 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
1149
  l += (LONGEST) x * (LONGEST) y;
1150 123 markom
 
1151
  /* This implementation is very fast - it needs only one cycle for mac.  */
1152 221 markom
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
1153
  hi = ((LONGEST)l) >> 32;
1154 123 markom
  mtspr (SPR_MACLO, lo);
1155
  mtspr (SPR_MACHI, hi);
1156 498 lampret
  printf ("(%08x,%08x)\n", hi, lo);
1157 123 markom
}
1158
void l_msb() {
1159 221 markom
  sprword lo, hi;
1160 123 markom
  LONGEST l;
1161 604 markom
  long x, y;
1162 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_mac;
1163 123 markom
  lo = mfspr (SPR_MACLO);
1164
  hi = mfspr (SPR_MACHI);
1165 604 markom
  x = eval_operand32(0, &breakpoint);
1166
  y = eval_operand32(1, &breakpoint);
1167
  printf ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));
1168 221 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
1169
  l -= (LONGEST) eval_operand32(0, &breakpoint) * (LONGEST)eval_operand32(1, &breakpoint);
1170 123 markom
 
1171
  /* This implementation is very fast - it needs only one cycle for msb.  */
1172 221 markom
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
1173
  hi = ((LONGEST)l) >> 32;
1174 123 markom
  mtspr (SPR_MACLO, lo);
1175 221 markom
  mtspr (SPR_MACHI, hi);
1176 604 markom
  printf ("(%08x,%08x)\n", hi, lo);
1177 123 markom
}
1178
void l_macrc() {
1179
  sprword lo, hi;
1180
  LONGEST l;
1181 615 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_mac;
1182 123 markom
  /* No need for synchronization here -- all MAC instructions are 1 cycle long.  */
1183
  lo =  mfspr (SPR_MACLO);
1184 221 markom
  hi =  mfspr (SPR_MACHI);
1185
  l = (ULONGEST) lo | ((LONGEST)hi << 32);
1186
  l >>= 28;
1187
  //printf ("<%08x>\n", (unsigned long)l);
1188
  set_operand32(0, (long)l, &breakpoint);
1189 123 markom
  mtspr (SPR_MACLO, 0);
1190 221 markom
  mtspr (SPR_MACHI, 0);
1191 123 markom
}
1192 615 markom
void l_cmov() {
1193
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1194
  set_operand32 (0, flag ? eval_operand32(1, &breakpoint) : eval_operand32(2, &breakpoint), &breakpoint);
1195
}
1196 174 markom
void l_cust1() {
1197
  /*int destr = cur->insn >> 21;
1198
    int src1r = cur->insn >> 15;
1199
    int src2r = cur->insn >> 9;*/
1200
}
1201
void l_cust2() {
1202
}
1203
void l_cust3() {
1204
}
1205
void l_cust4() {
1206
}
1207 123 markom
void l_invalid() {
1208 458 simons
  except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
1209 123 markom
}

powered by: WebSVN 2.1.0

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