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

Subversion Repositories or1k

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

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
          while(j < 3) {
523 678 markom
            fprintf (runtime.sim.fexe_log, "             ");
524 1346 nogj
            j++;
525
          }
526 675 markom
        }
527 1350 nogj
        fprintf (runtime.sim.fexe_log, "%"PRIxADDR" ", insn_addr);
528 713 markom
        fprintf (runtime.sim.fexe_log, "%s\n", disassembled);
529 672 markom
      }
530
    }
531
  }
532 294 markom
}
533
 
534 713 markom
/* Dump registers - 'r' or 't' command */
535 2 cvs
void dumpreg()
536
{
537 269 markom
  int i;
538 1350 nogj
  oraddr_t physical_pc;
539 269 markom
 
540 1308 phoenix
  if ((physical_pc = peek_into_itlb(iqueue[0].insn_addr))) {
541 1178 phoenix
    /*
542
     * PRINTF("\t\t\tEA: %08x <--> PA: %08x\n", iqueue[0].insn_addr, physical_pc);
543
     */
544
    dumpmemory(physical_pc, physical_pc + 4, 1, 0);
545
  }
546
  else {
547
    PRINTF("INTERNAL SIMULATOR ERROR:\n");
548
    PRINTF("no translation for currently executed instruction\n");
549
  }
550
 
551 1319 phoenix
  // generate_time_pretty (temp, runtime.sim.cycles * config.sim.clkcycle_ps);
552 1350 nogj
  PRINTF(" (executed) [cycle %lld, #%lld]\n", runtime.sim.cycles,
553
         runtime.cpu.instructions);
554 293 markom
  if (config.cpu.superscalar)
555 997 markom
    PRINTF ("Superscalar CYCLES: %u", runtime.cpu.supercycles);
556 293 markom
  if (config.cpu.hazards)
557 997 markom
    PRINTF ("  HAZARDWAIT: %u\n", runtime.cpu.hazardwait);
558 293 markom
  else
559
    if (config.cpu.superscalar)
560 997 markom
      PRINTF ("\n");
561 293 markom
 
562 1308 phoenix
  if ((physical_pc = peek_into_itlb(pc))) {
563 1178 phoenix
    /*
564
     * PRINTF("\t\t\tEA: %08x <--> PA: %08x\n", pc, physical_pc);
565
     */
566
    dumpmemory(physical_pc, physical_pc + 4, 1, 0);
567
  }
568 1174 phoenix
  else
569 1350 nogj
    PRINTF("%"PRIxADDR": : xxxxxxxx  ITLB miss follows", pc);
570 1174 phoenix
 
571 997 markom
  PRINTF(" (next insn) %s", (delay_insn?"(delay insn)":""));
572 269 markom
  for(i = 0; i < MAX_GPRS; i++) {
573
    if (i % 4 == 0)
574 997 markom
      PRINTF("\n");
575 1350 nogj
    PRINTF("GPR%.2u: %"PRIxREG"  ", i, evalsim_reg(i));
576 269 markom
  }
577 997 markom
  PRINTF("flag: %u\n", flag);
578 2 cvs
}
579 123 markom
 
580 713 markom
/* Generated/built in decoding/executing function */
581 712 markom
static inline void decode_execute (struct iqueue_entry *current);
582 706 markom
 
583
/* Wrapper around real decode_execute function -- some statistics here only */
584
static inline void decode_execute_wrapper (struct iqueue_entry *current)
585 123 markom
{
586 712 markom
  breakpoint = 0;
587 138 markom
 
588 123 markom
#ifndef HAS_EXECUTION
589
#error HAS_EXECUTION has to be defined in order to execute programs.
590
#endif
591 706 markom
 
592 712 markom
  decode_execute (current);
593 706 markom
 
594 717 markom
#if SET_OV_FLAG
595 458 simons
  /* Check for range exception */
596 557 markom
  if (testsprbits (SPR_SR, SPR_SR_OVE) && testsprbits (SPR_SR, SPR_SR_OV))
597 611 simons
    except_handle (EXCEPT_RANGE, mfspr(SPR_EEAR_BASE));
598 717 markom
#endif
599 458 simons
 
600 123 markom
  if(breakpoint)
601 611 simons
    except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
602 123 markom
}
603
 
604 706 markom
/* Reset the CPU */
605 557 markom
void cpu_reset()
606
{
607 606 markom
  int i;
608 1352 nogj
  struct hist_exec *hist_exec_head = NULL;
609
  struct hist_exec *hist_exec_new;
610
 
611 884 markom
  runtime.sim.cycles = 0;
612
  runtime.sim.loadcycles = 0;
613
  runtime.sim.storecycles = 0;
614
  runtime.cpu.instructions = 0;
615
  runtime.cpu.supercycles = 0;
616
  runtime.cpu.hazardwait = 0;
617 606 markom
  for (i = 0; i < MAX_GPRS; i++)
618 1350 nogj
    set_reg (i, 0);
619 557 markom
  memset(iqueue, 0, sizeof(iqueue));
620
  memset(icomplet, 0, sizeof(icomplet));
621 626 markom
 
622
  sbuf_head = 0;
623
  sbuf_tail = 0;
624
  sbuf_count = 0;
625
  sbuf_prev_cycles = 0;
626 557 markom
 
627 1352 nogj
  /* Initialise execution history circular buffer */
628
  for (i = 0; i < HISTEXEC_LEN; i++) {
629
    hist_exec_new = malloc(sizeof(struct hist_exec));
630
    if(!hist_exec_new) {
631
      fprintf(stderr, "Out-of-memory\n");
632
      exit(1);
633
    }
634
    if(!hist_exec_head)
635
      hist_exec_head = hist_exec_new;
636
    else
637
      hist_exec_tail->next = hist_exec_new;
638
 
639
    hist_exec_new->prev = hist_exec_tail;
640
    hist_exec_tail = hist_exec_new;
641
  }
642
  /* Make hist_exec_tail->next point to hist_exec_head */
643
  hist_exec_tail->next = hist_exec_head;
644
  hist_exec_head->prev = hist_exec_tail;
645
 
646 557 markom
  /* Cpu configuration */
647
  mtspr(SPR_UPR, config.cpu.upr);
648
  setsprbits(SPR_VR, SPR_VR_VER, config.cpu.ver);
649
  setsprbits(SPR_VR, SPR_VR_REV, config.cpu.rev);
650
  mtspr(SPR_SR, config.cpu.sr);
651
 
652
  pcnext = 0x0; /* MM1409: All programs should start at reset vector entry!  */
653 1350 nogj
  if (config.sim.verbose) PRINTF ("Starting at 0x%"PRIxADDR"\n", pcnext);
654 557 markom
  pc = pcnext;
655
  pcnext += 4;
656
  debug(1, "reset ...\n");
657
 
658
  /* MM1409: All programs should set their stack pointer!  */
659
  except_handle(EXCEPT_RESET, 0);
660 1386 nogj
  update_pc();
661
  except_pending = 0;
662 557 markom
}
663
 
664 713 markom
/* Simulates one CPU clock cycle */
665 557 markom
inline int cpu_clock ()
666
{
667 1386 nogj
  except_pending = 0;
668
  next_delay_insn = 0;
669 557 markom
  if(fetch()) {
670 997 markom
    PRINTF ("Breakpoint hit.\n");
671 884 markom
    runtime.sim.cont_run = 0; /* memory breakpoint encountered */
672 557 markom
    return 1;
673
  }
674 1386 nogj
 
675
  if(except_pending) {
676
    update_pc();
677
    except_pending = 0;
678
    return 0;
679
  }
680
 
681
  if(breakpoint) {
682
    except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
683
    update_pc();
684
    except_pending = 0;
685
    return 0;
686
  }
687
 
688 706 markom
  decode_execute_wrapper (&iqueue[0]);
689 557 markom
  update_pc();
690
  return 0;
691
}
692
 
693 713 markom
/* If decoding cannot be found, call this function */
694 1342 nogj
#if SIMPLE_EXECUTION
695
void l_invalid (struct iqueue_entry *current) {
696
#else
697 706 markom
void l_invalid () {
698 1342 nogj
#endif
699 706 markom
  except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
700 123 markom
}
701 641 ivang
 
702 717 markom
#if !SIMPLE_EXECUTION
703
 
704
/* Include decode_execute function */
705
#include "execgen.c"
706
 
707
#else /* SIMPLE_EXECUTION */
708
 
709 720 markom
 
710 1342 nogj
#define INSTRUCTION(name) void name (struct iqueue_entry *current)
711 641 ivang
 
712 717 markom
/* Implementation specific.
713 1350 nogj
   Get an actual value of a specific register. */
714
 
715
static uorreg_t eval_reg(unsigned int regno)
716
{
717
  if (regno < MAX_GPRS) {
718
#if RAW_RANGE_STATS
719
      int delta = (runtime.sim.cycles - raw_stats.reg[regno]);
720
      if ((unsigned long)delta < (unsigned long)MAX_RAW_RANGE)
721
        raw_stats.range[delta]++;
722
#endif /* RAW_RANGE */
723
    return reg[regno];
724
  } else {
725
    PRINTF("\nABORT: read out of registers\n");
726
    runtime.sim.cont_run = 0;
727
    return 0;
728
  }
729
}
730
 
731
/* Implementation specific.
732 1346 nogj
   Evaluates source operand op_no. */
733 641 ivang
 
734 1350 nogj
static uorreg_t eval_operand (int op_no, unsigned long insn_index, uint32_t insn)
735 717 markom
{
736
  struct insn_op_struct *opd = op_start[insn_index];
737 1350 nogj
  uorreg_t ret;
738 717 markom
 
739 1346 nogj
  while (op_no) {
740
    if(opd->type & OPTYPE_LAST) {
741
      fprintf (stderr, "Instruction requested more operands than it has\n");
742
      exit (1);
743 717 markom
    }
744 1346 nogj
    if((opd->type & OPTYPE_OP) && !(opd->type & OPTYPE_DIS))
745
      op_no--;
746
    opd++;
747
  }
748 717 markom
 
749 1346 nogj
  if (opd->type & OPTYPE_DIS) {
750
    ret = eval_operand_val (insn, opd);
751
    while (!(opd->type & OPTYPE_OP))
752
      opd++;
753
    opd++;
754 1350 nogj
    ret += eval_reg (eval_operand_val (insn, opd));
755 1346 nogj
    insn_ea = ret;
756
    return ret;
757
  }
758
  if (opd->type & OPTYPE_REG)
759 1350 nogj
    return eval_reg (eval_operand_val (insn, opd));
760 717 markom
 
761 1346 nogj
  return eval_operand_val (insn, opd);
762 717 markom
}
763
 
764
/* Implementation specific.
765 1342 nogj
   Set destination operand (reister direct) with value. */
766 717 markom
 
767 1350 nogj
inline static void set_operand(int op_no, orreg_t value,
768
                               unsigned long insn_index, uint32_t insn)
769 717 markom
{
770 1346 nogj
  struct insn_op_struct *opd = op_start[insn_index];
771
 
772
  while (op_no) {
773
    if(opd->type & OPTYPE_LAST) {
774
      fprintf (stderr, "Instruction requested more operands than it has\n");
775
      exit (1);
776
    }
777
    if((opd->type & OPTYPE_OP) && !(opd->type & OPTYPE_DIS))
778
      op_no--;
779
    opd++;
780
  }
781
 
782
  if (!(opd->type & OPTYPE_REG)) {
783 1342 nogj
    fprintf (stderr, "Trying to set a non-register operand\n");
784 717 markom
    exit (1);
785
  }
786 1350 nogj
  set_reg (eval_operand_val (insn, opd), value);
787 717 markom
}
788
 
789 713 markom
/* Simple and rather slow decoding function based on built automata. */
790 712 markom
static inline void decode_execute (struct iqueue_entry *current)
791 706 markom
{
792
  int insn_index;
793
 
794
  current->insn_index = insn_index = insn_decode(current->insn);
795 641 ivang
 
796 706 markom
  if (insn_index < 0)
797 1342 nogj
    l_invalid(current);
798 123 markom
  else {
799 1342 nogj
    or32_opcodes[insn_index].exec(current);
800 123 markom
  }
801 717 markom
  if (do_stats) analysis(&iqueue[0]);
802 123 markom
}
803
 
804 1346 nogj
#define SET_PARAM0(val) set_operand(0, val, current->insn_index, current->insn)
805 1342 nogj
 
806 1346 nogj
#define PARAM0 eval_operand(0, current->insn_index, current->insn)
807
#define PARAM1 eval_operand(1, current->insn_index, current->insn)
808
#define PARAM2 eval_operand(2, current->insn_index, current->insn)
809 1342 nogj
 
810 720 markom
#include "insnset.c"
811
 
812 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.