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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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