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 713

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

powered by: WebSVN 2.1.0

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