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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [cpu/] [or32/] [execute.c] - Blame information for rev 1484

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

powered by: WebSVN 2.1.0

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