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 1346

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