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

Subversion Repositories or1k

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

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