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 678

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

powered by: WebSVN 2.1.0

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