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

Subversion Repositories or1k

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

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 138 markom
int depend_operands(prev, next)
208
     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
    adddstats(icomplet[0].insn_index, current->insn_index, 1, check_depend());
327
 
328
    /* Dynamic, functional units stats. */
329 1344 nogj
    addfstats(or32_opcodes[icomplet[0].insn_index].func_unit,
330
              or32_opcodes[current->insn_index].func_unit, 1, check_depend());
331 713 markom
 
332
    /* Dynamic, single stats. */
333
    addsstats(current->insn_index, 1);
334
  }
335
 
336
  if (config.cpu.superscalar) {
337 1344 nogj
    if ((or32_opcodes[current->insn_index].func_unit == it_branch) ||
338
        (or32_opcodes[current->insn_index].func_unit == it_jump))
339 884 markom
      runtime.sim.storecycles += 0;
340 713 markom
 
341 1344 nogj
    if (or32_opcodes[current->insn_index].func_unit == it_store)
342 884 markom
      runtime.sim.storecycles += 1;
343 713 markom
 
344 1344 nogj
    if (or32_opcodes[current->insn_index].func_unit == it_load)
345 884 markom
      runtime.sim.loadcycles += 1;
346 713 markom
#if 0        
347
    if ((icomplet[0].func_unit == it_load) && check_depend())
348 884 markom
      runtime.sim.loadcycles++;
349 713 markom
#endif
350
 
351
    /* Pseudo multiple issue benchmark */
352 1344 nogj
    if ((multissue[or32_opcodes[current->insn_index].func_unit] < 1) ||
353
        (check_depend()) || (issued_per_cycle < 1)) {
354 713 markom
      int i;
355
      for (i = 0; i < 20; i++)
356
        multissue[i] = 2;
357
      issued_per_cycle = 2;
358 884 markom
      runtime.cpu.supercycles++;
359 713 markom
      if (check_depend())
360 884 markom
        runtime.cpu.hazardwait++;
361 713 markom
      multissue[it_unknown] = 2;
362
      multissue[it_shift] = 2;
363
      multissue[it_compare] = 1;
364
      multissue[it_branch] = 1;
365
      multissue[it_jump] = 1;
366
      multissue[it_extend] = 2;
367
      multissue[it_nop] = 2;
368
      multissue[it_move] = 2;
369
      multissue[it_movimm] = 2;
370
      multissue[it_arith] = 2;
371
      multissue[it_store] = 2;
372
      multissue[it_load] = 2;
373
    }
374 1344 nogj
    multissue[or32_opcodes[current->insn_index].func_unit]--;
375 713 markom
    issued_per_cycle--;
376
  }
377
 
378 394 markom
  if (config.cpu.dependstats)
379 123 markom
    /* Instruction waits in completition buffer until retired. */
380 713 markom
    memcpy (&icomplet[0], current, sizeof (struct iqueue_entry));
381 138 markom
 
382 394 markom
  if (config.sim.history) {
383 123 markom
    /* History of execution */
384 1352 nogj
    hist_exec_tail = hist_exec_tail->next;
385
    hist_exec_tail->addr = icomplet[0].insn_addr;
386 123 markom
  }
387 714 markom
 
388
  if (config.sim.exe_log) dump_exe_log();
389 2 cvs
}
390
 
391 626 markom
/* Store buffer analysis - stores are accumulated and commited when IO is idle */
392 1308 phoenix
static inline void sbuf_store (int cyc) {
393 884 markom
  int delta = runtime.sim.cycles - sbuf_prev_cycles;
394 626 markom
  sbuf_total_cyc += cyc;
395 884 markom
  sbuf_prev_cycles = runtime.sim.cycles;
396 626 markom
 
397 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]);
398
  //PRINTF ("|%i,%i\n", sbuf_total_cyc, sbuf_wait_cyc);
399 626 markom
  /* Take stores from buffer, that occured meanwhile */
400 630 markom
  while (sbuf_count && delta >= sbuf_buf[sbuf_tail]) {
401 626 markom
    delta -= sbuf_buf[sbuf_tail];
402
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
403
    sbuf_count--;
404
  }
405
  if (sbuf_count)
406
    sbuf_buf[sbuf_tail] -= delta;
407 630 markom
 
408 626 markom
  /* Store buffer is full, take one out */
409
  if (sbuf_count >= config.cpu.sbuf_len) {
410
    sbuf_wait_cyc += sbuf_buf[sbuf_tail];
411 884 markom
    runtime.sim.mem_cycles += sbuf_buf[sbuf_tail];
412 630 markom
    sbuf_prev_cycles += sbuf_buf[sbuf_tail];
413 626 markom
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
414
    sbuf_count--;
415
  }
416
  /* Put newest store in the buffer */
417
  sbuf_buf[sbuf_head] = cyc;
418
  sbuf_head = (sbuf_head + 1) % MAX_SBUF_LEN;
419
  sbuf_count++;
420 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]);
421 626 markom
}
422 294 markom
 
423 626 markom
/* Store buffer analysis - previous stores should commit, before any load */
424 1308 phoenix
static inline void sbuf_load () {
425 884 markom
  int delta = runtime.sim.cycles - sbuf_prev_cycles;
426
  sbuf_prev_cycles = runtime.sim.cycles;
427 630 markom
 
428 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]);
429
  //PRINTF ("|%i,%i\n", sbuf_total_cyc, sbuf_wait_cyc);
430 629 markom
  /* Take stores from buffer, that occured meanwhile */
431 630 markom
  while (sbuf_count && delta >= sbuf_buf[sbuf_tail]) {
432 629 markom
    delta -= sbuf_buf[sbuf_tail];
433
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
434
    sbuf_count--;
435
  }
436
  if (sbuf_count)
437
    sbuf_buf[sbuf_tail] -= delta;
438
 
439 626 markom
  /* Wait for all stores to complete */
440
  while (sbuf_count > 0) {
441
    sbuf_wait_cyc += sbuf_buf[sbuf_tail];
442 884 markom
    runtime.sim.mem_cycles += sbuf_buf[sbuf_tail];
443 630 markom
    sbuf_prev_cycles += sbuf_buf[sbuf_tail];
444 626 markom
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
445
    sbuf_count--;
446
  }
447 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]);
448 626 markom
}
449
 
450 712 markom
/* Outputs dissasembled instruction */
451 713 markom
void dump_exe_log ()
452 294 markom
{
453 1350 nogj
  oraddr_t insn_addr = iqueue[0].insn_addr;
454
  unsigned int i, j;
455
  uorreg_t operand;
456 294 markom
 
457 1346 nogj
  if (insn_addr == 0xffffffff) return;
458
  if ((config.sim.exe_log_start <= runtime.cpu.instructions) &&
459
      ((config.sim.exe_log_end <= 0) ||
460
       (runtime.cpu.instructions <= config.sim.exe_log_end))) {
461
    if (config.sim.exe_log_marker &&
462
        !(runtime.cpu.instructions % config.sim.exe_log_marker)) {
463 1343 nogj
      fprintf (runtime.sim.fexe_log, "--------------------- %8lli instruction ---------------------\n", runtime.cpu.instructions);
464 693 markom
    }
465 672 markom
    switch (config.sim.exe_log_type) {
466
    case EXE_LOG_HARDWARE:
467 1350 nogj
      fprintf (runtime.sim.fexe_log, "\nEXECUTED(%11llu): %"PRIxADDR":  ",
468 1346 nogj
               runtime.cpu.instructions, insn_addr);
469
      fprintf (runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8_void(insn_addr),
470
               evalsim_mem8_void(insn_addr + 1));
471
      fprintf (runtime.sim.fexe_log, "%.2x%.2x",
472
               evalsim_mem8_void(insn_addr + 2),
473
               evalsim_mem8_void(insn_addr + 3));
474 672 markom
      for(i = 0; i < MAX_GPRS; i++) {
475
        if (i % 4 == 0)
476
          fprintf(runtime.sim.fexe_log, "\n");
477 1350 nogj
        fprintf (runtime.sim.fexe_log, "GPR%2u: %"PRIxREG"  ", i, reg[i]);
478 672 markom
      }
479
      fprintf (runtime.sim.fexe_log, "\n");
480
      fprintf (runtime.sim.fexe_log, "SR   : %.8lx  ", mfspr(SPR_SR));
481
      fprintf (runtime.sim.fexe_log, "EPCR0: %.8lx  ", mfspr(SPR_EPCR_BASE));
482
      fprintf (runtime.sim.fexe_log, "EEAR0: %.8lx  ", mfspr(SPR_EEAR_BASE));
483
      fprintf (runtime.sim.fexe_log, "ESR0 : %.8lx\n", mfspr(SPR_ESR_BASE));
484
      break;
485 675 markom
    case EXE_LOG_SIMPLE:
486 672 markom
    case EXE_LOG_SOFTWARE:
487
      {
488 713 markom
        extern char *disassembled;
489
        disassemble_index (iqueue[0].insn, iqueue[0].insn_index);
490 714 markom
        {
491 672 markom
          struct label_entry *entry;
492 1346 nogj
          entry = get_label(insn_addr);
493 714 markom
          if (entry)
494
            fprintf (runtime.sim.fexe_log, "%s:\n", entry->name);
495 672 markom
        }
496 714 markom
 
497 675 markom
        if (config.sim.exe_log_type == EXE_LOG_SOFTWARE) {
498 1346 nogj
          struct insn_op_struct *opd = op_start[iqueue[0].insn_index];
499 1204 phoenix
 
500 1346 nogj
          j = 0;
501
          while (1) {
502 1350 nogj
            operand = eval_operand_val (iqueue[0].insn, opd);
503 1346 nogj
            while (!(opd->type & OPTYPE_OP))
504
              opd++;
505
            if (opd->type & OPTYPE_DIS) {
506 1350 nogj
              fprintf (runtime.sim.fexe_log, "EA =%"PRIxADDR" PA =%"PRIxADDR" ",
507
                       insn_ea, peek_into_dtlb(insn_ea,0,0));
508 1346 nogj
              opd++; /* Skip of register operand */
509
              j++;
510 1350 nogj
            } else if ((opd->type & OPTYPE_REG) && operand) {
511
              fprintf (runtime.sim.fexe_log, "r%-2i=%"PRIxREG" ",
512
                       (int)operand, evalsim_reg (operand));
513 677 markom
            } else
514 1204 phoenix
              fprintf (runtime.sim.fexe_log, "             ");
515 1346 nogj
            j++;
516
            if(opd->type & OPTYPE_LAST)
517
              break;
518
            opd++;
519
          }
520
          while(j < 3) {
521 678 markom
            fprintf (runtime.sim.fexe_log, "             ");
522 1346 nogj
            j++;
523
          }
524 675 markom
        }
525 1350 nogj
        fprintf (runtime.sim.fexe_log, "%"PRIxADDR" ", insn_addr);
526 713 markom
        fprintf (runtime.sim.fexe_log, "%s\n", disassembled);
527 672 markom
      }
528
    }
529
  }
530 294 markom
}
531
 
532 713 markom
/* Dump registers - 'r' or 't' command */
533 2 cvs
void dumpreg()
534
{
535 269 markom
  int i;
536 1350 nogj
  oraddr_t physical_pc;
537 269 markom
 
538 1308 phoenix
  if ((physical_pc = peek_into_itlb(iqueue[0].insn_addr))) {
539 1178 phoenix
    /*
540
     * PRINTF("\t\t\tEA: %08x <--> PA: %08x\n", iqueue[0].insn_addr, physical_pc);
541
     */
542
    dumpmemory(physical_pc, physical_pc + 4, 1, 0);
543
  }
544
  else {
545
    PRINTF("INTERNAL SIMULATOR ERROR:\n");
546
    PRINTF("no translation for currently executed instruction\n");
547
  }
548
 
549 1319 phoenix
  // generate_time_pretty (temp, runtime.sim.cycles * config.sim.clkcycle_ps);
550 1350 nogj
  PRINTF(" (executed) [cycle %lld, #%lld]\n", runtime.sim.cycles,
551
         runtime.cpu.instructions);
552 293 markom
  if (config.cpu.superscalar)
553 997 markom
    PRINTF ("Superscalar CYCLES: %u", runtime.cpu.supercycles);
554 293 markom
  if (config.cpu.hazards)
555 997 markom
    PRINTF ("  HAZARDWAIT: %u\n", runtime.cpu.hazardwait);
556 293 markom
  else
557
    if (config.cpu.superscalar)
558 997 markom
      PRINTF ("\n");
559 293 markom
 
560 1308 phoenix
  if ((physical_pc = peek_into_itlb(pc))) {
561 1178 phoenix
    /*
562
     * PRINTF("\t\t\tEA: %08x <--> PA: %08x\n", pc, physical_pc);
563
     */
564
    dumpmemory(physical_pc, physical_pc + 4, 1, 0);
565
  }
566 1174 phoenix
  else
567 1350 nogj
    PRINTF("%"PRIxADDR": : xxxxxxxx  ITLB miss follows", pc);
568 1174 phoenix
 
569 997 markom
  PRINTF(" (next insn) %s", (delay_insn?"(delay insn)":""));
570 269 markom
  for(i = 0; i < MAX_GPRS; i++) {
571
    if (i % 4 == 0)
572 997 markom
      PRINTF("\n");
573 1350 nogj
    PRINTF("GPR%.2u: %"PRIxREG"  ", i, evalsim_reg(i));
574 269 markom
  }
575 997 markom
  PRINTF("flag: %u\n", flag);
576 2 cvs
}
577 123 markom
 
578 713 markom
/* Generated/built in decoding/executing function */
579 712 markom
static inline void decode_execute (struct iqueue_entry *current);
580 706 markom
 
581
/* Wrapper around real decode_execute function -- some statistics here only */
582
static inline void decode_execute_wrapper (struct iqueue_entry *current)
583 123 markom
{
584 712 markom
  breakpoint = 0;
585 138 markom
 
586 123 markom
#ifndef HAS_EXECUTION
587
#error HAS_EXECUTION has to be defined in order to execute programs.
588
#endif
589 706 markom
 
590 712 markom
  decode_execute (current);
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 557 markom
  memset(iqueue, 0, sizeof(iqueue));
618
  memset(icomplet, 0, sizeof(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
  mtspr(SPR_UPR, config.cpu.upr);
646
  setsprbits(SPR_VR, SPR_VR_VER, config.cpu.ver);
647
  setsprbits(SPR_VR, SPR_VR_REV, config.cpu.rev);
648
  mtspr(SPR_SR, config.cpu.sr);
649
 
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 557 markom
  pc = pcnext;
653
  pcnext += 4;
654
  debug(1, "reset ...\n");
655
 
656
  /* MM1409: All programs should set their stack pointer!  */
657
  except_handle(EXCEPT_RESET, 0);
658 1386 nogj
  update_pc();
659
  except_pending = 0;
660 557 markom
}
661
 
662 713 markom
/* Simulates one CPU clock cycle */
663 557 markom
inline int cpu_clock ()
664
{
665 1386 nogj
  except_pending = 0;
666
  next_delay_insn = 0;
667 557 markom
  if(fetch()) {
668 997 markom
    PRINTF ("Breakpoint hit.\n");
669 884 markom
    runtime.sim.cont_run = 0; /* memory breakpoint encountered */
670 557 markom
    return 1;
671
  }
672 1386 nogj
 
673
  if(except_pending) {
674
    update_pc();
675
    except_pending = 0;
676
    return 0;
677
  }
678
 
679
  if(breakpoint) {
680
    except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
681
    update_pc();
682
    except_pending = 0;
683
    return 0;
684
  }
685
 
686 706 markom
  decode_execute_wrapper (&iqueue[0]);
687 557 markom
  update_pc();
688
  return 0;
689
}
690
 
691 713 markom
/* If decoding cannot be found, call this function */
692 1342 nogj
#if SIMPLE_EXECUTION
693
void l_invalid (struct iqueue_entry *current) {
694
#else
695 706 markom
void l_invalid () {
696 1342 nogj
#endif
697 706 markom
  except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
698 123 markom
}
699 641 ivang
 
700 717 markom
#if !SIMPLE_EXECUTION
701
 
702
/* Include decode_execute function */
703
#include "execgen.c"
704
 
705
#else /* SIMPLE_EXECUTION */
706
 
707 720 markom
 
708 1342 nogj
#define INSTRUCTION(name) void name (struct iqueue_entry *current)
709 641 ivang
 
710 717 markom
/* Implementation specific.
711 1350 nogj
   Get an actual value of a specific register. */
712
 
713
static uorreg_t eval_reg(unsigned int regno)
714
{
715
  if (regno < MAX_GPRS) {
716
#if RAW_RANGE_STATS
717
      int delta = (runtime.sim.cycles - raw_stats.reg[regno]);
718
      if ((unsigned long)delta < (unsigned long)MAX_RAW_RANGE)
719
        raw_stats.range[delta]++;
720
#endif /* RAW_RANGE */
721
    return reg[regno];
722
  } else {
723
    PRINTF("\nABORT: read out of registers\n");
724
    runtime.sim.cont_run = 0;
725
    return 0;
726
  }
727
}
728
 
729
/* Implementation specific.
730 1346 nogj
   Evaluates source operand op_no. */
731 641 ivang
 
732 1350 nogj
static uorreg_t eval_operand (int op_no, unsigned long insn_index, uint32_t insn)
733 717 markom
{
734
  struct insn_op_struct *opd = op_start[insn_index];
735 1350 nogj
  uorreg_t ret;
736 717 markom
 
737 1346 nogj
  while (op_no) {
738
    if(opd->type & OPTYPE_LAST) {
739
      fprintf (stderr, "Instruction requested more operands than it has\n");
740
      exit (1);
741 717 markom
    }
742 1346 nogj
    if((opd->type & OPTYPE_OP) && !(opd->type & OPTYPE_DIS))
743
      op_no--;
744
    opd++;
745
  }
746 717 markom
 
747 1346 nogj
  if (opd->type & OPTYPE_DIS) {
748
    ret = eval_operand_val (insn, opd);
749
    while (!(opd->type & OPTYPE_OP))
750
      opd++;
751
    opd++;
752 1350 nogj
    ret += eval_reg (eval_operand_val (insn, opd));
753 1346 nogj
    insn_ea = ret;
754
    return ret;
755
  }
756
  if (opd->type & OPTYPE_REG)
757 1350 nogj
    return eval_reg (eval_operand_val (insn, opd));
758 717 markom
 
759 1346 nogj
  return eval_operand_val (insn, opd);
760 717 markom
}
761
 
762
/* Implementation specific.
763 1342 nogj
   Set destination operand (reister direct) with value. */
764 717 markom
 
765 1350 nogj
inline static void set_operand(int op_no, orreg_t value,
766
                               unsigned long insn_index, uint32_t insn)
767 717 markom
{
768 1346 nogj
  struct insn_op_struct *opd = op_start[insn_index];
769
 
770
  while (op_no) {
771
    if(opd->type & OPTYPE_LAST) {
772
      fprintf (stderr, "Instruction requested more operands than it has\n");
773
      exit (1);
774
    }
775
    if((opd->type & OPTYPE_OP) && !(opd->type & OPTYPE_DIS))
776
      op_no--;
777
    opd++;
778
  }
779
 
780
  if (!(opd->type & OPTYPE_REG)) {
781 1342 nogj
    fprintf (stderr, "Trying to set a non-register operand\n");
782 717 markom
    exit (1);
783
  }
784 1350 nogj
  set_reg (eval_operand_val (insn, opd), value);
785 717 markom
}
786
 
787 713 markom
/* Simple and rather slow decoding function based on built automata. */
788 712 markom
static inline void decode_execute (struct iqueue_entry *current)
789 706 markom
{
790
  int insn_index;
791
 
792
  current->insn_index = insn_index = insn_decode(current->insn);
793 641 ivang
 
794 706 markom
  if (insn_index < 0)
795 1342 nogj
    l_invalid(current);
796 123 markom
  else {
797 1342 nogj
    or32_opcodes[insn_index].exec(current);
798 123 markom
  }
799 717 markom
  if (do_stats) analysis(&iqueue[0]);
800 123 markom
}
801
 
802 1346 nogj
#define SET_PARAM0(val) set_operand(0, val, current->insn_index, current->insn)
803 1342 nogj
 
804 1346 nogj
#define PARAM0 eval_operand(0, current->insn_index, current->insn)
805
#define PARAM1 eval_operand(1, current->insn_index, current->insn)
806
#define PARAM2 eval_operand(2, current->insn_index, current->insn)
807 1342 nogj
 
808 720 markom
#include "insnset.c"
809
 
810 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.