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 709

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 706 markom
/* Most of the OR1K simulation is done in here.
21 2 cvs
 
22 706 markom
   When SIMPLE_EXECUTION is defined below a file insnset.c is included!
23
*/
24
 
25 2 cvs
#include <stdlib.h>
26
#include <stdio.h>
27
#include <string.h>
28
#include <ctype.h>
29
 
30 123 markom
#include "config.h"
31 2 cvs
#include "arch.h"
32 133 markom
#include "opcode/or32.h"
33 2 cvs
#include "branch_predict.h"
34
#include "abstract.h"
35 261 markom
#include "labels.h"
36 2 cvs
#include "parse.h"
37
#include "execute.h"
38
#include "stats.h"
39 54 lampret
#include "except.h"
40
#include "sprs.h"
41 102 lampret
#include "sim-config.h"
42 123 markom
#include "debug_unit.h"
43 2 cvs
 
44 615 markom
/* Whether instructions set overflow flag */
45
#define SET_OV_FLAG     1
46
 
47
/* Whether arithmethic instructions set flag on zero */
48 620 markom
#define ARITH_SET_FLAG  1
49 615 markom
 
50 706 markom
/* Specifies, whether we should use generated decode_execute or
51
   runtime generated. In latter case file 'insnset.c' is included
52
   at the bottom of this file */
53
//#define SIMPLE_EXECUTION 1
54
 
55 2 cvs
/* General purpose registers. */
56
machword reg[MAX_GPRS];
57
 
58
/* Instruction queue */
59
struct iqueue_entry iqueue[20];
60
 
61 83 lampret
/* Is current insn in execution a delay insn? */
62
int delay_insn;
63
 
64 2 cvs
/* Benchmark multi issue execution */
65
int multissue[20];
66
int supercycles;
67 6 lampret
int issued_per_cycle = 4;
68
int hazardwait = 0;
69 2 cvs
 
70 431 markom
/* Whether break was hit - so we can step over a break */
71
static int break_just_hit = 0;
72
 
73 68 lampret
/* freemem 'pointer' */
74
extern unsigned long freemem;
75
 
76 2 cvs
/* Completition queue */
77 138 markom
struct iqueue_entry icomplet[20];
78 2 cvs
 
79 77 lampret
/* Program counter (and translated PC) */
80 2 cvs
unsigned long pc;
81 77 lampret
unsigned long pc_phy;
82 2 cvs
 
83 378 markom
/* Previous program counter */
84 479 markom
unsigned long pcprev = 0;
85 378 markom
 
86 2 cvs
/* Temporary program counter */
87 83 lampret
unsigned long pcnext;
88 2 cvs
 
89 123 markom
/* Delay instruction effective address register */
90
unsigned long pcdelay;
91
 
92 2 cvs
/* CCR */
93
int flag;
94
 
95
/* CCR (for dependency calculation) */
96
char ccr_flag[10] = "flag";
97
 
98
/* Cycles counts fetch stages */
99
int cycles;
100
 
101 537 markom
/* Each cycle has counter of mem_cycles; this value is joined with cycles
102
   at the end of the cycle; no sim originated memory accesses should be
103
   performed inbetween. */
104
int mem_cycles;
105
 
106 535 markom
/* Instructions executed */
107
int instructions;
108
 
109 6 lampret
/* Load and store stalls */
110
int loadcycles, storecycles;
111
 
112 626 markom
/* Store buffer analysis - stores are accumulated and commited when IO is idle */
113
static int sbuf_head = 0, sbuf_tail = 0, sbuf_count = 0;
114
static int sbuf_buf[MAX_SBUF_LEN] = {0};
115
static int sbuf_prev_cycles = 0;
116
 
117
/* Num cycles waiting for stores to complete */
118
int sbuf_wait_cyc = 0;
119
 
120
/* Number of total store cycles */
121
int sbuf_total_cyc = 0;
122
 
123 138 markom
/* Local data needed for execution.  */
124
static struct iqueue_entry *cur;
125
static int next_delay_insn;
126
static int breakpoint;
127
static unsigned long *op;
128
static int num_op;
129
 
130 2 cvs
/* Implementation specific.
131
   Get an actual value of a specific register. */
132
 
133 560 markom
unsigned long evalsim_reg32(int regno)
134 2 cvs
{
135 138 markom
  if (regno < MAX_GPRS) {
136 560 markom
    return reg[regno];
137
  } else {
138
    printf("\nABORT: read out of registers\n");
139
    cont_run = 0;
140
    return 0;
141
  }
142
}
143
 
144
/* Implementation specific.
145
   Set a specific register with value. */
146
 
147
void setsim_reg32(int regno, unsigned long value)
148
{
149
  if (regno == 0)               /* gpr0 is always zero */
150
    value = 0;
151
 
152
  if (regno < MAX_GPRS) {
153
    reg[regno] = value;
154
  } else {
155
    printf("\nABORT: write out of registers\n");
156
    cont_run = 0;
157
  }
158
}
159
 
160
/* Implementation specific.
161
   Get an actual value of a specific register. */
162
 
163
inline static unsigned long eval_reg32(int regno)
164
{
165
  if (regno < MAX_GPRS) {
166
    IFF(config.cpu.raw_range) {
167 535 markom
      int delta = (cycles - raw_stats.reg[regno]);
168 606 markom
      if ((unsigned long)delta < (unsigned long)config.cpu.raw_range)
169 535 markom
        raw_stats.range[delta]++;
170
    }
171 138 markom
    return reg[regno];
172
  } else {
173 393 markom
    printf("\nABORT: read out of registers\n");
174 138 markom
    cont_run = 0;
175
    return 0;
176
  }
177 2 cvs
}
178
 
179
/* Implementation specific.
180
   Set a specific register with value. */
181
 
182 560 markom
inline static void set_reg32(int regno, unsigned long value)
183 2 cvs
{
184 262 markom
#if 0   
185 138 markom
  if (strcmp(regstr, FRAME_REG) == 0) {
186
    printf("FP (%s) modified by insn at %x. ", FRAME_REG, pc);
187
    printf("Old:%.8lx  New:%.8lx\n", eval_reg(regno), value);
188
  }
189
 
190
  if (strcmp(regstr, STACK_REG) == 0) {
191
    printf("SP (%s) modified by insn at %x. ", STACK_REG, pc);
192
    printf("Old:%.8lx  New:%.8lx\n", eval_reg(regmo), value);
193
  }
194 2 cvs
#endif
195 560 markom
 
196 138 markom
  if (regno < MAX_GPRS) {
197
    reg[regno] = value;
198 560 markom
    IFF(config.cpu.raw_range)
199 535 markom
      raw_stats.reg[regno] = cycles;
200 138 markom
  } else {
201 393 markom
    printf("\nABORT: write out of registers\n");
202 138 markom
    cont_run = 0;
203
  }
204 2 cvs
}
205
 
206
/* Does srcoperand depend on computation of dstoperand? Return
207
   non-zero if yes.
208
 
209 262 markom
 Cycle t                 Cycle t+1
210
dst: irrelevant         src: immediate                  always 0
211
dst: reg1 direct        src: reg2 direct                0 if reg1 != reg2
212
dst: reg1 disp          src: reg2 direct                always 0
213
dst: reg1 direct        src: reg2 disp                  0 if reg1 != reg2
214
dst: reg1 disp          src: reg2 disp                  always 1 (store must
215
                                                        finish before load)
216 138 markom
dst: flag               src: flag                       always 1
217 2 cvs
*/
218
 
219 138 markom
int depend_operands(prev, next)
220
     struct iqueue_entry *prev;
221
     struct iqueue_entry *next;
222 2 cvs
{
223 138 markom
  /* Find destination type. */
224
  unsigned long type = 0;
225
  int i = 0;
226
  if (or32_opcodes[prev->insn_index].flags & OR32_W_FLAG
227
      && or32_opcodes[next->insn_index].flags & OR32_R_FLAG)
228
    return 1;
229 2 cvs
 
230 138 markom
  while (!(prev->op[i + MAX_OPERANDS] & OPTYPE_LAST))
231
    if (prev->op[i + MAX_OPERANDS] & OPTYPE_DST)
232
      {
233 262 markom
        type = prev->op[i + MAX_OPERANDS];
234
        break;
235 138 markom
      }
236
    else
237
      i++;
238 560 markom
 
239 138 markom
  /* We search all source operands - if we find confict => return 1 */
240
  i = 0;
241
  while (!(next->op[i + MAX_OPERANDS] & OPTYPE_LAST))
242
    if (!(next->op[i + MAX_OPERANDS] & OPTYPE_DST))
243
      {
244 262 markom
        if (next->op[i + MAX_OPERANDS] & OPTYPE_DIS)
245
          if (type & OPTYPE_DIS)
246
            return 1;
247
          else if (next->op[i] == prev->op[i]
248
                   && (next->op[i + MAX_OPERANDS] & OPTYPE_REG))
249
            return 1;
250
        if (next->op[i] == prev->op[i]
251
            && (next->op[i + MAX_OPERANDS] & OPTYPE_REG)
252
            && (type & OPTYPE_REG))
253
          return 1;
254
        i++;
255 138 markom
      }
256
    else
257
      i++;
258
  return 0;
259
}
260 2 cvs
 
261 138 markom
/* Implementation specific.
262
   Parses and returns operands. */
263 2 cvs
 
264 138 markom
static void
265
eval_operands (unsigned long insn, int insn_index, int* breakpoint)
266
{
267
  struct insn_op_struct *opd = op_start[insn_index];
268
  unsigned long data = 0;
269
  int dis = 0;
270
  int no = 0;
271 560 markom
 
272 138 markom
  while (1)
273
    {
274
      unsigned long tmp = 0, nbits = 0;
275
      while (1)
276 262 markom
        {
277
          tmp |= ((insn  >> (opd->type & OPTYPE_SHR)) & ((1 << opd->data) - 1)) << nbits;
278
          nbits += opd->data;
279
          if (opd->type & OPTYPE_OP)
280
            break;
281
          opd++;
282
        }
283 2 cvs
 
284 138 markom
      /* Do we have to sign extend? */
285
      if (opd->type & OPTYPE_SIG)
286 262 markom
        {
287
          int sbit = (opd->type & OPTYPE_SBIT) >> OPTYPE_SBIT_SHR;
288
          if (tmp & (1 << sbit))
289
            tmp |= 0xFFFFFFFF << sbit;
290
        }
291 138 markom
      if (opd->type & OPTYPE_DIS) {
292 262 markom
        /* We have to read register later.  */
293
        data += tmp;
294
        dis = 1;
295 138 markom
      } else
296 262 markom
        {
297
          if (dis && (opd->type & OPTYPE_REG))
298 560 markom
            op[no] = data + eval_reg32 (tmp);
299 262 markom
          else
300
            op[no] = tmp;
301
          op[no + MAX_OPERANDS] = opd->type | (dis ? OPTYPE_DIS : 0);
302
          no++;
303
          data = 0;
304
          dis = 0;
305
        }
306 693 markom
      if(opd->type & OPTYPE_LAST) {
307
        num_op = no;
308 262 markom
        return;
309 693 markom
      }
310 138 markom
      opd++;
311
    }
312
  num_op = no;
313 2 cvs
}
314
 
315
/* Implementation specific.
316 138 markom
   Evaluates source operand op_no. */
317
 
318 560 markom
inline static unsigned long eval_operand32 (int op_no, int *breakpoint)
319 2 cvs
{
320 538 markom
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
321 560 markom
    /* memory accesses are not cached */
322 138 markom
    return eval_mem32 (op[op_no], breakpoint);
323 560 markom
  else if (op[op_no + MAX_OPERANDS] & OPTYPE_REG) {
324
    return eval_reg32 (op[op_no]);
325
  } else {
326 138 markom
    return op[op_no];
327 560 markom
  }
328 2 cvs
}
329
 
330
/* Implementation specific.
331 221 markom
   Evaluates source operand op_no. */
332
 
333 560 markom
static unsigned long eval_operand16 (int op_no, int *breakpoint)
334 221 markom
{
335 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
336 221 markom
    return eval_mem16 (op[op_no], breakpoint);
337 458 simons
  }
338 221 markom
  else {
339
    fprintf (stderr, "Invalid operand type.\n");
340
    exit (1);
341
  }
342
}
343
 
344
/* Implementation specific.
345
   Evaluates source operand op_no. */
346
 
347 560 markom
static unsigned long eval_operand8 (int op_no, int *breakpoint)
348 221 markom
{
349
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
350
    return eval_mem8 (op[op_no], breakpoint);
351
  else {
352
    fprintf (stderr, "Invalid operand type.\n");
353
    exit (1);
354
  }
355
}
356
 
357
/* Implementation specific.
358 2 cvs
   Set destination operand (register direct, register indirect
359
   (with displacement) with value. */
360
 
361 560 markom
inline static void set_operand32(int op_no, unsigned long value, int* breakpoint)
362 2 cvs
{
363 138 markom
  /* Mark this as destination operand.  */
364 560 markom
  IFF (config.cpu.dependstats) op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
365 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
366 138 markom
    set_mem32(op[op_no], value, breakpoint);
367 560 markom
  } else if (op[op_no + MAX_OPERANDS] & OPTYPE_REG) {
368 138 markom
    set_reg32(op[op_no], value);
369 560 markom
  } else {
370
    fprintf (stderr, "Invalid operand type.\n");
371
    exit (1);
372 458 simons
  }
373 2 cvs
}
374
 
375 221 markom
/* Implementation specific.
376
   Set destination operand (register direct, register indirect
377
   (with displacement) with value. */
378
 
379
void set_operand16(int op_no, unsigned long value, int* breakpoint)
380
{
381
  /* Mark this as destination operand.  */
382 560 markom
  op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
383 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
384 221 markom
    set_mem16(op[op_no], value, breakpoint);
385 458 simons
  }
386 574 markom
  else
387 221 markom
    {
388
      fprintf (stderr, "Invalid operand type.\n");
389
      exit (1);
390
    }
391
}
392
 
393
/* Implementation specific.
394
   Set destination operand (register direct, register indirect
395
   (with displacement) with value. */
396
 
397
void set_operand8(int op_no, unsigned long value, int* breakpoint)
398
{
399
  /* Mark this as destination operand.  */
400
  op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
401
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
402
    set_mem8(op[op_no], value, breakpoint);
403
  else
404
    {
405
      fprintf (stderr, "Invalid operand type.\n");
406
      exit (1);
407
    }
408
}
409
 
410 605 markom
/* Sets a new SPR_SR_OV value, based on next register value */
411
static inline unsigned long set_ov_flag (unsigned long value)
412
{
413 615 markom
#if SET_OV_FLAG
414 605 markom
  value & 0x80000000 ? setsprbits (SPR_SR, SPR_SR_OV, 1) : setsprbits (SPR_SR, SPR_SR_OV, 0);
415 615 markom
#endif
416 605 markom
  return value;
417
}
418
 
419 123 markom
/* Modified by CZ 26/05/01 for new mode execution */
420
/* Fetch returns nonzero if instruction should NOT be executed.  */
421 557 markom
static inline int fetch()
422
{
423 221 markom
  struct mem_entry *entry;
424 344 markom
  debug(5, "fetch()\n");
425 123 markom
 
426 557 markom
  /* Update the pc for pending exceptions, or get physical pc */
427 574 markom
  if (!pending.valid)
428 631 simons
    pc_phy = immu_translate(pc, 0);
429 574 markom
 
430 557 markom
  if(pending.valid)
431
    except_handle_backend(pending.type, pending.address, pending.saved);
432 464 simons
 
433 557 markom
  if (CHECK_BREAKPOINTS) {
434
    /* MM: Check for breakpoint.  This has to be done in fetch cycle,
435
       because of peripheria.
436
       MM1709: if we cannot access the memory entry, we could not set the
437
       breakpoint earlier, so just chech the breakpoint list.  */
438
    if (has_breakpoint (pc_phy) && !break_just_hit) {
439
      break_just_hit = 1;
440
      return 1; /* Breakpoint set. */
441
    }
442
    break_just_hit = 0;
443 431 markom
  }
444 535 markom
  instructions++;
445 378 markom
 
446 538 markom
  pc_phy &= ~0x03;
447
 
448 378 markom
  /* Fetch instruction. */
449 560 markom
  iqueue[0].insn_addr = pc;
450
  iqueue[0].insn = eval_insn (pc_phy, &breakpoint);;
451 557 markom
 
452 378 markom
  /* update_pc will be called after execution */
453 77 lampret
 
454 378 markom
  return 0;
455 2 cvs
}
456
 
457 479 markom
/* This code actually updates the PC value.  */
458 626 markom
static inline void update_pc ()
459 142 chris
{
460 479 markom
  pcprev = pc; /* Store value for later */
461
  pc = pcnext;
462
  pcnext = delay_insn ? pcdelay : pcnext + 4;
463 2 cvs
}
464
 
465 626 markom
static inline void analysis ()
466 2 cvs
{
467 394 markom
  if (config.cpu.dependstats)
468 123 markom
    /* Instruction waits in completition buffer until retired. */
469 138 markom
    memcpy (&icomplet[0], &iqueue[0], sizeof (struct iqueue_entry));
470
 
471 394 markom
  if (config.sim.history) {
472 263 markom
    int i;
473
 
474 123 markom
    /* History of execution */
475
    for (i = HISTEXEC_LEN - 1; i; i--)
476
      histexec[i] = histexec[i - 1];
477 262 markom
    histexec[0] = icomplet[0].insn_addr;        /* add last insn */
478 123 markom
  }
479 2 cvs
}
480
 
481 626 markom
/* Store buffer analysis - stores are accumulated and commited when IO is idle */
482 630 markom
static inline sbuf_store (int cyc) {
483 626 markom
  int delta = cycles - sbuf_prev_cycles;
484
  sbuf_total_cyc += cyc;
485 630 markom
  sbuf_prev_cycles = cycles;
486 626 markom
 
487 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]);
488
  //printf ("|%i,%i\n", sbuf_total_cyc, sbuf_wait_cyc);
489 626 markom
  /* Take stores from buffer, that occured meanwhile */
490 630 markom
  while (sbuf_count && delta >= sbuf_buf[sbuf_tail]) {
491 626 markom
    delta -= sbuf_buf[sbuf_tail];
492
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
493
    sbuf_count--;
494
  }
495
  if (sbuf_count)
496
    sbuf_buf[sbuf_tail] -= delta;
497 630 markom
 
498 626 markom
  /* Store buffer is full, take one out */
499
  if (sbuf_count >= config.cpu.sbuf_len) {
500
    sbuf_wait_cyc += sbuf_buf[sbuf_tail];
501
    mem_cycles += sbuf_buf[sbuf_tail];
502 630 markom
    sbuf_prev_cycles += sbuf_buf[sbuf_tail];
503 626 markom
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
504
    sbuf_count--;
505
  }
506
  /* Put newest store in the buffer */
507
  sbuf_buf[sbuf_head] = cyc;
508
  sbuf_head = (sbuf_head + 1) % MAX_SBUF_LEN;
509
  sbuf_count++;
510 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]);
511 626 markom
}
512 294 markom
 
513 626 markom
/* Store buffer analysis - previous stores should commit, before any load */
514
static inline sbuf_load () {
515 629 markom
  int delta = cycles - sbuf_prev_cycles;
516 630 markom
  sbuf_prev_cycles = cycles;
517
 
518
  //printf (">LOAD  %i,%i,%i,%i,%i\n", delta, sbuf_count, sbuf_tail, sbuf_head, sbuf_buf[sbuf_tail], sbuf_buf[sbuf_head]);
519
  //printf ("|%i,%i\n", sbuf_total_cyc, sbuf_wait_cyc);
520 629 markom
  /* Take stores from buffer, that occured meanwhile */
521 630 markom
  while (sbuf_count && delta >= sbuf_buf[sbuf_tail]) {
522 629 markom
    delta -= sbuf_buf[sbuf_tail];
523
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
524
    sbuf_count--;
525
  }
526
  if (sbuf_count)
527
    sbuf_buf[sbuf_tail] -= delta;
528
 
529 626 markom
  /* Wait for all stores to complete */
530
  while (sbuf_count > 0) {
531
    sbuf_wait_cyc += sbuf_buf[sbuf_tail];
532
    mem_cycles += sbuf_buf[sbuf_tail];
533 630 markom
    sbuf_prev_cycles += sbuf_buf[sbuf_tail];
534 626 markom
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
535
    sbuf_count--;
536
  }
537 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]);
538 626 markom
}
539
 
540 294 markom
/* Execution logger.  */
541
inline void dump_exe_log()
542
{
543 479 markom
  unsigned long i = iqueue[0].insn_addr;
544 294 markom
 
545 479 markom
  if (i == 0xffffffff) return;
546 672 markom
  if (config.sim.exe_log_start <= instructions && (config.sim.exe_log_end <= 0 || instructions <= config.sim.exe_log_end)) {
547 693 markom
    if (config.sim.exe_log_marker && instructions % config.sim.exe_log_marker == 0) {
548
      fprintf (runtime.sim.fexe_log, "--------------------- %8i instruction ---------------------\n", instructions);
549
    }
550 672 markom
    switch (config.sim.exe_log_type) {
551
    case EXE_LOG_HARDWARE:
552
      fprintf (runtime.sim.fexe_log, "\nEXECUTED(): %.8lx:  ", i);
553
      fprintf (runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i), evalsim_mem8(i + 1));
554
      fprintf (runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i + 2), evalsim_mem8(i + 3));
555
      for(i = 0; i < MAX_GPRS; i++) {
556
        if (i % 4 == 0)
557
          fprintf(runtime.sim.fexe_log, "\n");
558
        fprintf (runtime.sim.fexe_log, "GPR%2u: %.8lx  ", i, reg[i]);
559
      }
560
      fprintf (runtime.sim.fexe_log, "\n");
561
      fprintf (runtime.sim.fexe_log, "SR   : %.8lx  ", mfspr(SPR_SR));
562
      fprintf (runtime.sim.fexe_log, "EPCR0: %.8lx  ", mfspr(SPR_EPCR_BASE));
563
      fprintf (runtime.sim.fexe_log, "EEAR0: %.8lx  ", mfspr(SPR_EEAR_BASE));
564
      fprintf (runtime.sim.fexe_log, "ESR0 : %.8lx\n", mfspr(SPR_ESR_BASE));
565
      break;
566 675 markom
    case EXE_LOG_SIMPLE:
567 672 markom
    case EXE_LOG_SOFTWARE:
568
      {
569
        int labels = 0;
570
        if (verify_memoryarea(i)) {
571
          struct label_entry *entry;
572
          entry = get_label(i);
573
          if (entry) {
574 675 markom
            fprintf (runtime.sim.fexe_log, "%s: ", entry->name);
575 672 markom
            labels++;
576
          }
577
        } else {
578 675 markom
          fprintf (runtime.sim.fexe_log, "<invalid addr>: ");
579 672 markom
          labels++;
580
        }
581 675 markom
 
582 672 markom
        if (labels) fprintf (runtime.sim.fexe_log, "\n");
583 675 markom
 
584
        if (config.sim.exe_log_type == EXE_LOG_SOFTWARE) {
585 678 markom
          int i;
586
          for (i = 0; i < num_op; i++)
587 677 markom
            if (op[i + MAX_OPERANDS] & OPTYPE_DIS) {
588
              fprintf (runtime.sim.fexe_log, "EA =%08x ", op[i]);
589
            } else if ((op[i + MAX_OPERANDS] & OPTYPE_REG) && op[i]) {
590
              fprintf (runtime.sim.fexe_log, "r%-2i=%08x ", op[i], evalsim_reg32 (op[i]));
591
            } else
592 675 markom
            fprintf (runtime.sim.fexe_log, "             ");
593 678 markom
          for (; i < 3; i++)
594
            fprintf (runtime.sim.fexe_log, "             ");
595 675 markom
        }
596
 
597 677 markom
        fprintf (runtime.sim.fexe_log, "%.8lx ", i);
598 672 markom
        if (index >= 0) {
599
          extern char *disassembled;
600 703 markom
          disassemble_index (iqueue[0].insn, iqueue[0].insn_index);
601 677 markom
          fprintf (runtime.sim.fexe_log, "%s\n", disassembled);
602 672 markom
        } else
603 677 markom
          fprintf (runtime.sim.fexe_log, "<invalid>\n");
604 672 markom
      }
605
    }
606
  }
607 294 markom
}
608
 
609 537 markom
#if 0
610 535 markom
void print_time (int cycles, char *output)
611
{
612
  int i = 0, c_ps = config.sim.clkcycle_ps;
613
  while (c_ps % 1000 == 0 && i < 2) {
614
    c_ps /= 1000;
615
    i++;
616
  }
617
  c_ps *= cycles;
618
  sprintf (output, "%i%cs", cycles, i == 0 ? 'p' : i == 1 ? 'n': 'u');
619
}
620 537 markom
#endif
621 535 markom
 
622 2 cvs
void dumpreg()
623
{
624 269 markom
  int i;
625 535 markom
  char temp[100];
626 269 markom
 
627 306 markom
  dumpmemory(iqueue[0].insn_addr, iqueue[0].insn_addr + 4, 1, 0);
628 537 markom
  generate_time_pretty (temp, cycles);
629 535 markom
  printf(" (executed) [time %s, #%i]\n", temp, instructions);
630 293 markom
  if (config.cpu.superscalar)
631
    printf ("Superscalar CYCLES: %u", supercycles);
632
  if (config.cpu.hazards)
633
    printf ("  HAZARDWAIT: %u\n", hazardwait);
634
  else
635
    if (config.cpu.superscalar)
636
      printf ("\n");
637
 
638 306 markom
  dumpmemory(pc, pc + 4, 1, 0);
639 269 markom
  printf(" (next insn) %s", (delay_insn?"(delay insn)":""));
640
  for(i = 0; i < MAX_GPRS; i++) {
641
    if (i % 4 == 0)
642
      printf("\n");
643 560 markom
    printf("GPR%.2u: %.8lx  ", i, evalsim_reg32(i));
644 269 markom
  }
645
  printf("flag: %u\n", flag);
646 2 cvs
}
647 123 markom
 
648 706 markom
static inline void decode_execute (struct iqueue_entry *current, int *breakpoint);
649
 
650
/* Wrapper around real decode_execute function -- some statistics here only */
651
static inline void decode_execute_wrapper (struct iqueue_entry *current)
652 123 markom
{
653 706 markom
  int breakpoint = 0;
654 123 markom
  next_delay_insn = 0;
655 138 markom
 
656 123 markom
#ifndef HAS_EXECUTION
657
#error HAS_EXECUTION has to be defined in order to execute programs.
658
#endif
659 706 markom
 
660
  IFF (config.cpu.dependstats) current->func_unit = it_unknown;
661 133 markom
 
662 706 markom
  if(config.debug.enabled && CheckDebugUnit(DebugInstructionFetch, pc_phy))
663
    breakpoint++;
664
 
665 560 markom
  cur = current;  /* globals; needed by eval/set_operand */
666 706 markom
  decode_execute (current, &breakpoint);
667
 
668 458 simons
  /* Check for range exception */
669 557 markom
  if (testsprbits (SPR_SR, SPR_SR_OVE) && testsprbits (SPR_SR, SPR_SR_OV))
670 611 simons
    except_handle (EXCEPT_RANGE, mfspr(SPR_EEAR_BASE));
671 458 simons
 
672 263 markom
  if (config.cpu.dependstats) {
673 706 markom
    iqueue[0].insn_index = current->insn_index;
674 123 markom
    /* Dynamic, dependency stats. */
675 535 markom
    adddstats(icomplet[0].insn_index, iqueue[0].insn_index, 1, check_depend());
676 675 markom
 
677 123 markom
    /* Dynamic, functional units stats. */
678
    addfstats(icomplet[0].func_unit, iqueue[0].func_unit, 1, check_depend());
679 675 markom
 
680 123 markom
    /* Dynamic, single stats. */
681 535 markom
    addsstats(iqueue[0].insn_index, 1);
682 123 markom
  }
683 560 markom
 
684 263 markom
  if (config.cpu.superscalar) {
685 479 markom
    if ((cur->func_unit == it_branch) || (cur->func_unit == it_jump))
686 123 markom
      storecycles += 0;
687
 
688 479 markom
    if (cur->func_unit == it_store)
689 389 lampret
      storecycles += 1;
690 123 markom
 
691 479 markom
    if (cur->func_unit == it_load)
692 389 lampret
      loadcycles += 1;
693
#if 0        
694 479 markom
    if ((icomplet[0].func_unit == it_load) && check_depend())
695 123 markom
      loadcycles++;
696 389 lampret
#endif
697 123 markom
 
698
    /* Pseudo multiple issue benchmark */
699
    if ((multissue[cur->func_unit] < 1) || (check_depend())
700 560 markom
     || (issued_per_cycle < 1)) {
701 123 markom
      int i;
702
      for (i = 0; i < 20; i++)
703 262 markom
        multissue[i] = 2;
704 123 markom
      issued_per_cycle = 2;
705
      supercycles++;
706
      if (check_depend())
707 262 markom
        hazardwait++;
708 479 markom
      multissue[it_unknown] = 2;
709
      multissue[it_shift] = 2;
710
      multissue[it_compare] = 1;
711
      multissue[it_branch] = 1;
712
      multissue[it_jump] = 1;
713
      multissue[it_extend] = 2;
714
      multissue[it_nop] = 2;
715
      multissue[it_move] = 2;
716
      multissue[it_movimm] = 2;
717
      multissue[it_arith] = 2;
718
      multissue[it_store] = 2;
719
      multissue[it_load] = 2;
720 123 markom
    }
721
    multissue[cur->func_unit]--;
722
    issued_per_cycle--;
723
  }
724
  delay_insn = next_delay_insn;
725
 
726
  if(breakpoint)
727 611 simons
    except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
728 123 markom
}
729
 
730 706 markom
/* Reset the CPU */
731 557 markom
void cpu_reset()
732
{
733 606 markom
  int i;
734 557 markom
  cycles = 0;
735
  instructions = 0;
736
  supercycles = 0;
737
  loadcycles = 0;
738
  storecycles = 0;
739 606 markom
  for (i = 0; i < MAX_GPRS; i++)
740
    set_reg32 (i, 0);
741 557 markom
  memset(iqueue, 0, sizeof(iqueue));
742
  memset(icomplet, 0, sizeof(icomplet));
743 626 markom
 
744
  sbuf_head = 0;
745
  sbuf_tail = 0;
746
  sbuf_count = 0;
747
  sbuf_prev_cycles = 0;
748 557 markom
 
749
  /* Cpu configuration */
750
  mtspr(SPR_UPR, config.cpu.upr);
751
  setsprbits(SPR_VR, SPR_VR_VER, config.cpu.ver);
752
  setsprbits(SPR_VR, SPR_VR_REV, config.cpu.rev);
753
  mtspr(SPR_SR, config.cpu.sr);
754
 
755
  pcnext = 0x0; /* MM1409: All programs should start at reset vector entry!  */
756
  printf ("Starting at 0x%08x\n", pcnext);
757
  pc = pcnext;
758
  pc_phy = pc;
759
  pcnext += 4;
760
  debug(1, "reset ...\n");
761
 
762
  /* MM1409: All programs should set their stack pointer!  */
763
  except_handle(EXCEPT_RESET, 0);
764
}
765
 
766
inline int cpu_clock ()
767
{
768
  if(fetch()) {
769
    printf ("Breakpoint hit.\n");
770
    cont_run = 0; /* memory breakpoint encountered */
771
    return 1;
772
  }
773 706 markom
  decode_execute_wrapper (&iqueue[0]);
774 557 markom
  update_pc();
775
  analysis();
776
  if (config.sim.exe_log) dump_exe_log();
777
  return 0;
778
}
779
 
780 706 markom
void l_invalid () {
781
  except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
782 123 markom
}
783 641 ivang
 
784 709 markom
#if SIMPLE_EXECUTION
785 706 markom
#define INSTRUCTION(name) void name ()
786
#include "insnset.c"
787 709 markom
#endif /* SIMPLE_EXECUTION */
788 641 ivang
 
789
 
790 706 markom
#if SIMPLE_EXECUTION
791
/* Address calculation changed by CZ on 27/05/01 */
792
static inline void decode_execute (struct iqueue_entry *current, int *breakpoint)
793
{
794
  int insn_index;
795
 
796
  current->insn_index = insn_index = insn_decode(current->insn);
797 641 ivang
 
798 706 markom
  if (insn_index < 0)
799
    l_invalid();
800 123 markom
  else {
801 706 markom
    op = &cur->op[0];
802
    eval_operands (cur->insn, insn_index, breakpoint);
803
    or32_opcodes[insn_index].exec();
804 123 markom
  }
805
}
806
 
807 706 markom
#else /* SIMPLE_EXECUTION */
808 123 markom
 
809 706 markom
/* Include decode_execute function */
810
#include "execgen.c"
811
#endif /* SIMPLE_EXECUTION */

powered by: WebSVN 2.1.0

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