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 1350

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

powered by: WebSVN 2.1.0

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