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 538

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
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
/* Most of the OR1K simulation is done in here. */
21
 
22
#include <stdlib.h>
23
#include <stdio.h>
24
#include <string.h>
25
#include <ctype.h>
26
 
27 123 markom
#include "config.h"
28 2 cvs
#include "arch.h"
29 133 markom
#include "opcode/or32.h"
30 2 cvs
#include "branch_predict.h"
31
#include "abstract.h"
32 261 markom
#include "labels.h"
33 2 cvs
#include "parse.h"
34
#include "execute.h"
35
#include "stats.h"
36 54 lampret
#include "except.h"
37
#include "sprs.h"
38 102 lampret
#include "sim-config.h"
39 123 markom
#include "debug_unit.h"
40 2 cvs
 
41
/* General purpose registers. */
42
machword reg[MAX_GPRS];
43
 
44
/* Instruction queue */
45
struct iqueue_entry iqueue[20];
46
 
47 83 lampret
/* Is current insn in execution a delay insn? */
48
int delay_insn;
49
 
50 2 cvs
/* Benchmark multi issue execution */
51
int multissue[20];
52
int supercycles;
53 6 lampret
int issued_per_cycle = 4;
54
int hazardwait = 0;
55
int nops = 0;
56
int nop_period = 0;
57
int nop_maxperiod = 0;
58 2 cvs
 
59 431 markom
/* Whether break was hit - so we can step over a break */
60
static int break_just_hit = 0;
61
 
62 68 lampret
/* freemem 'pointer' */
63
extern unsigned long freemem;
64
 
65 2 cvs
/* Completition queue */
66 138 markom
struct iqueue_entry icomplet[20];
67 2 cvs
 
68 77 lampret
/* Program counter (and translated PC) */
69 2 cvs
unsigned long pc;
70 77 lampret
unsigned long pc_phy;
71 2 cvs
 
72 378 markom
/* Previous program counter */
73 479 markom
unsigned long pcprev = 0;
74 378 markom
 
75 2 cvs
/* Temporary program counter */
76 83 lampret
unsigned long pcnext;
77 2 cvs
 
78 123 markom
/* Delay instruction effective address register */
79
unsigned long pcdelay;
80
 
81 2 cvs
/* CCR */
82
int flag;
83
 
84
/* CCR (for dependency calculation) */
85
char ccr_flag[10] = "flag";
86
 
87
/* Cycles counts fetch stages */
88
int cycles;
89
 
90 537 markom
/* Each cycle has counter of mem_cycles; this value is joined with cycles
91
   at the end of the cycle; no sim originated memory accesses should be
92
   performed inbetween. */
93
int mem_cycles;
94
 
95 535 markom
/* Instructions executed */
96
int instructions;
97
 
98 6 lampret
/* Load and store stalls */
99
int loadcycles, storecycles;
100
 
101 138 markom
/* Local data needed for execution.  */
102
static struct iqueue_entry *cur;
103
static int next_delay_insn;
104
static int breakpoint;
105
static unsigned long *op;
106
static int num_op;
107
 
108 2 cvs
/* Implementation specific.
109
   Get an actual value of a specific register. */
110
 
111 138 markom
machword eval_reg(int regno)
112 2 cvs
{
113 138 markom
  if (regno < MAX_GPRS) {
114 535 markom
    if (config.cpu.raw_range) {
115
      int delta = (cycles - raw_stats.reg[regno]);
116
      if (delta < config.cpu.raw_range)
117
        raw_stats.range[delta]++;
118
    }
119 344 markom
    debug(9, "atoi ret1\n");
120 138 markom
    return reg[regno];
121
  } else {
122 393 markom
    printf("\nABORT: read out of registers\n");
123 138 markom
    cont_run = 0;
124
    return 0;
125
  }
126 2 cvs
}
127
 
128
/* Implementation specific.
129
   Set a specific register with value. */
130
 
131 138 markom
void set_reg32(int regno, unsigned long value)
132 2 cvs
{
133 262 markom
#if 0   
134 138 markom
  if (strcmp(regstr, FRAME_REG) == 0) {
135
    printf("FP (%s) modified by insn at %x. ", FRAME_REG, pc);
136
    printf("Old:%.8lx  New:%.8lx\n", eval_reg(regno), value);
137
  }
138
 
139
  if (strcmp(regstr, STACK_REG) == 0) {
140
    printf("SP (%s) modified by insn at %x. ", STACK_REG, pc);
141
    printf("Old:%.8lx  New:%.8lx\n", eval_reg(regmo), value);
142
  }
143 2 cvs
#endif
144 262 markom
  if (regno == 0)               /* gpr0 is always zero */
145 138 markom
    value = 0;
146
 
147
  if (regno < MAX_GPRS) {
148
    reg[regno] = value;
149 535 markom
    if (config.cpu.raw_range)
150
      raw_stats.reg[regno] = cycles;
151 138 markom
  } else {
152 393 markom
    printf("\nABORT: write out of registers\n");
153 138 markom
    cont_run = 0;
154
  }
155 2 cvs
}
156
 
157
/* Does srcoperand depend on computation of dstoperand? Return
158
   non-zero if yes.
159
 
160 262 markom
 Cycle t                 Cycle t+1
161
dst: irrelevant         src: immediate                  always 0
162
dst: reg1 direct        src: reg2 direct                0 if reg1 != reg2
163
dst: reg1 disp          src: reg2 direct                always 0
164
dst: reg1 direct        src: reg2 disp                  0 if reg1 != reg2
165
dst: reg1 disp          src: reg2 disp                  always 1 (store must
166
                                                        finish before load)
167 138 markom
dst: flag               src: flag                       always 1
168 2 cvs
*/
169
 
170 138 markom
int depend_operands(prev, next)
171
     struct iqueue_entry *prev;
172
     struct iqueue_entry *next;
173 2 cvs
{
174 138 markom
  /* Find destination type. */
175
  unsigned long type = 0;
176
  int i = 0;
177
  if (or32_opcodes[prev->insn_index].flags & OR32_W_FLAG
178
      && or32_opcodes[next->insn_index].flags & OR32_R_FLAG)
179
    return 1;
180 2 cvs
 
181 138 markom
  while (!(prev->op[i + MAX_OPERANDS] & OPTYPE_LAST))
182
    if (prev->op[i + MAX_OPERANDS] & OPTYPE_DST)
183
      {
184 262 markom
        type = prev->op[i + MAX_OPERANDS];
185
        break;
186 138 markom
      }
187
    else
188
      i++;
189
 
190
  /* We search all source operands - if we find confict => return 1 */
191
  i = 0;
192
  while (!(next->op[i + MAX_OPERANDS] & OPTYPE_LAST))
193
    if (!(next->op[i + MAX_OPERANDS] & OPTYPE_DST))
194
      {
195 262 markom
        if (next->op[i + MAX_OPERANDS] & OPTYPE_DIS)
196
          if (type & OPTYPE_DIS)
197
            return 1;
198
          else if (next->op[i] == prev->op[i]
199
                   && (next->op[i + MAX_OPERANDS] & OPTYPE_REG))
200
            return 1;
201
        if (next->op[i] == prev->op[i]
202
            && (next->op[i + MAX_OPERANDS] & OPTYPE_REG)
203
            && (type & OPTYPE_REG))
204
          return 1;
205
        i++;
206 138 markom
      }
207
    else
208
      i++;
209
  return 0;
210
}
211 2 cvs
 
212 138 markom
/* Implementation specific.
213
   Parses and returns operands. */
214 2 cvs
 
215 138 markom
static void
216
eval_operands (unsigned long insn, int insn_index, int* breakpoint)
217
{
218
  struct insn_op_struct *opd = op_start[insn_index];
219
  unsigned long data = 0;
220
  int dis = 0;
221
  int no = 0;
222
  while (1)
223
    {
224
      unsigned long tmp = 0, nbits = 0;
225
      while (1)
226 262 markom
        {
227
          tmp |= ((insn  >> (opd->type & OPTYPE_SHR)) & ((1 << opd->data) - 1)) << nbits;
228
          nbits += opd->data;
229
          if (opd->type & OPTYPE_OP)
230
            break;
231
          opd++;
232
        }
233 2 cvs
 
234 138 markom
      /* Do we have to sign extend? */
235
      if (opd->type & OPTYPE_SIG)
236 262 markom
        {
237
          int sbit = (opd->type & OPTYPE_SBIT) >> OPTYPE_SBIT_SHR;
238
          if (tmp & (1 << sbit))
239
            tmp |= 0xFFFFFFFF << sbit;
240
        }
241 138 markom
      if (opd->type & OPTYPE_DIS) {
242 262 markom
        /* We have to read register later.  */
243
        data += tmp;
244
        dis = 1;
245 138 markom
      } else
246 262 markom
        {
247
          if (dis && (opd->type & OPTYPE_REG))
248
            op[no] = data + eval_reg (tmp);
249
          else
250
            op[no] = tmp;
251
          op[no + MAX_OPERANDS] = opd->type | (dis ? OPTYPE_DIS : 0);
252
          no++;
253
          data = 0;
254
          dis = 0;
255
        }
256 138 markom
      if(opd->type & OPTYPE_LAST)
257 262 markom
        return;
258 138 markom
      opd++;
259
    }
260
  num_op = no;
261 2 cvs
}
262
 
263
/* Implementation specific.
264 138 markom
   Evaluates source operand op_no. */
265
 
266 221 markom
unsigned long eval_operand32 (int op_no, int *breakpoint)
267 2 cvs
{
268 344 markom
  debug (9, "%i %08X\n", op_no, op[op_no + MAX_OPERANDS]);
269 538 markom
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
270 138 markom
    return eval_mem32 (op[op_no], breakpoint);
271
  else if (op[op_no + MAX_OPERANDS] & OPTYPE_REG)
272
    return eval_reg (op[op_no]);
273
  else
274
    return op[op_no];
275 2 cvs
}
276
 
277
/* Implementation specific.
278 221 markom
   Evaluates source operand op_no. */
279
 
280
unsigned long eval_operand16 (int op_no, int *breakpoint)
281
{
282 344 markom
  debug (9, "%i %08X\n", op_no, op[op_no + MAX_OPERANDS]);
283 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
284
    if (op[op_no] & 0x01) {
285
      return 0;
286
    }
287 221 markom
    return eval_mem16 (op[op_no], breakpoint);
288 458 simons
  }
289 221 markom
  else {
290
    fprintf (stderr, "Invalid operand type.\n");
291
    exit (1);
292
  }
293
}
294
 
295
/* Implementation specific.
296
   Evaluates source operand op_no. */
297
 
298
unsigned long eval_operand8 (int op_no, int *breakpoint)
299
{
300 344 markom
  debug (9, "%i %08X\n", op_no, op[op_no + MAX_OPERANDS]);
301 221 markom
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
302
    return eval_mem8 (op[op_no], breakpoint);
303
  else {
304
    fprintf (stderr, "Invalid operand type.\n");
305
    exit (1);
306
  }
307
}
308
 
309
/* Implementation specific.
310 2 cvs
   Set destination operand (register direct, register indirect
311
   (with displacement) with value. */
312
 
313 221 markom
void set_operand32(int op_no, unsigned long value, int* breakpoint)
314 2 cvs
{
315 138 markom
  /* Mark this as destination operand.  */
316
  op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
317 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
318
    if (op[op_no] & 0x03) {
319
      except_handle (EXCEPT_ALIGN, op[op_no]);
320 464 simons
      return;
321 458 simons
    }
322 138 markom
    set_mem32(op[op_no], value, breakpoint);
323 458 simons
  }
324
  else if (op[op_no + MAX_OPERANDS] & OPTYPE_REG) {
325 138 markom
    set_reg32(op[op_no], value);
326 458 simons
    value & 0x80000000 ? setsprbits (SPR_SR, SPR_SR_OV, 1) : setsprbits (SPR_SR, SPR_SR_OV, 0);
327
  }
328 138 markom
  else
329
    {
330
      fprintf (stderr, "Invalid operand type.\n");
331
      exit (1);
332
    }
333 2 cvs
}
334
 
335 221 markom
/* Implementation specific.
336
   Set destination operand (register direct, register indirect
337
   (with displacement) with value. */
338
 
339
void set_operand16(int op_no, unsigned long value, int* breakpoint)
340
{
341
  /* Mark this as destination operand.  */
342
   op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
343 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
344
     if (op[op_no] & 0x01) {
345
      except_handle (EXCEPT_ALIGN, op[op_no]);
346 464 simons
      return;
347 458 simons
    }
348 221 markom
    set_mem16(op[op_no], value, breakpoint);
349 458 simons
  }
350 221 markom
  else
351
    {
352
      fprintf (stderr, "Invalid operand type.\n");
353
      exit (1);
354
    }
355
}
356
 
357
/* Implementation specific.
358
   Set destination operand (register direct, register indirect
359
   (with displacement) with value. */
360
 
361
void set_operand8(int op_no, unsigned long value, int* breakpoint)
362
{
363
  /* Mark this as destination operand.  */
364
  op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
365
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
366
    set_mem8(op[op_no], value, breakpoint);
367
  else
368
    {
369
      fprintf (stderr, "Invalid operand type.\n");
370
      exit (1);
371
    }
372
}
373
 
374 2 cvs
void reset()
375
{
376 138 markom
  cycles = 0;
377 535 markom
  instructions = 0;
378 138 markom
  supercycles = 0;
379
  loadcycles = 0;
380
  storecycles = 0;
381
  memset(reg, 0, sizeof(reg));
382
  memset(iqueue, 0, sizeof(iqueue));
383
  memset(icomplet, 0, sizeof(icomplet));
384 263 markom
 
385
  /* Cpu configuration */
386
  mtspr(SPR_UPR, config.cpu.upr);
387
  setsprbits(SPR_VR, SPR_VR_VER, config.cpu.ver);
388
  setsprbits(SPR_VR, SPR_VR_REV, config.cpu.rev);
389
 
390 221 markom
  pcnext = 0x0; /* MM1409: All programs should start at reset vector entry!  */
391 174 markom
  printf ("Starting at 0x%08x\n", pcnext);
392 138 markom
  pc = pcnext;
393
  pc_phy = pc;
394
  pcnext += 4;
395 344 markom
  debug(1, "reset ...\n");
396 221 markom
 
397
  /* MM1409: All programs should set their stack pointer!  */
398
  except_handle(EXCEPT_RESET, 0);
399 2 cvs
}
400
 
401 123 markom
/* Modified by CZ 26/05/01 for new mode execution */
402
/* Fetch returns nonzero if instruction should NOT be executed.  */
403 138 markom
inline int fetch() {
404 221 markom
  struct mem_entry *entry;
405 344 markom
  debug(5, "fetch()\n");
406 123 markom
 
407 464 simons
  if (!pending.valid)
408
    pc_phy = translate_vrt_to_phy_add(pc);
409
 
410 479 markom
  /* Update the pc for pending exceptions */
411
  if(pending.valid)
412
    except_handle_backend(pending.type,pending.address,pending.saved);
413 142 chris
 
414 378 markom
  /* MM: Check for breakpoint.  This has to be done in fetch cycle,
415
     because of peripheria.
416
     MM1709: if we cannot access the memory entry, we could not set the
417
     breakpoint earlier, so just chech the breakpoint list.  */
418 431 markom
  if(has_breakpoint (pc_phy) && !break_just_hit) {
419
    break_just_hit = 1;
420 378 markom
    return 1; /* Breakpoint set. */
421 431 markom
  }
422
  break_just_hit = 0;
423 123 markom
 
424 535 markom
  instructions++;
425 378 markom
 
426 538 markom
  pc_phy &= ~0x03;
427
 
428 221 markom
#if 0
429 378 markom
  if(pc_phy > MEMORY_START + MEMORY_LEN)
430
    pc_phy %= MEMORY_START + MEMORY_LEN;
431 221 markom
#endif 
432 2 cvs
 
433 378 markom
  /* Fetch instruction. */
434
  {
435
    unsigned int _insn;
436
 
437 479 markom
    _insn = eval_insn (pc_phy, &breakpoint);
438
    iqueue[0].insn_addr = pc;
439
 
440 378 markom
    iqueue[0].insn_index = insn_decode(_insn);
441
    iqueue[0].insn = _insn;
442
  }
443 261 markom
 
444 378 markom
  /* update_pc will be called after execution */
445 77 lampret
 
446 378 markom
  return 0;
447 2 cvs
}
448
 
449 479 markom
/* This code actually updates the PC value.  */
450 142 chris
inline void update_pc()
451
{
452 479 markom
  pcprev = pc; /* Store value for later */
453
  pc = pcnext;
454
  pcnext = delay_insn ? pcdelay : pcnext + 4;
455 123 markom
  nop_period++;
456 2 cvs
}
457
 
458 138 markom
inline void analysis()
459 2 cvs
{
460 394 markom
  if (config.cpu.dependstats)
461 123 markom
    /* Instruction waits in completition buffer until retired. */
462 138 markom
    memcpy (&icomplet[0], &iqueue[0], sizeof (struct iqueue_entry));
463
 
464 394 markom
  if (config.sim.history) {
465 263 markom
    int i;
466
 
467 123 markom
    /* History of execution */
468
    for (i = HISTEXEC_LEN - 1; i; i--)
469
      histexec[i] = histexec[i - 1];
470 262 markom
    histexec[0] = icomplet[0].insn_addr;        /* add last insn */
471 123 markom
  }
472 2 cvs
}
473
 
474 294 markom
 
475
/* Execution logger.  */
476
inline void dump_exe_log()
477
{
478 479 markom
  unsigned long i = iqueue[0].insn_addr;
479 294 markom
 
480 479 markom
  if (i == 0xffffffff) return;
481 361 markom
  fprintf(runtime.sim.fexe_log, "\nEXECUTED(): %.8lx:  ", i);
482
  fprintf(runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i), evalsim_mem8(i + 1));
483
  fprintf(runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i + 2), evalsim_mem8(i + 3));
484
  for(i = 0; i < MAX_GPRS; i++) {
485
    if (i % 4 == 0)
486
      fprintf(runtime.sim.fexe_log, "\n");
487
    fprintf(runtime.sim.fexe_log, "GPR%2u: %.8lx  ", i, reg[i]);
488
  }
489
  fprintf(runtime.sim.fexe_log, "\n");
490
  fprintf(runtime.sim.fexe_log, "SR   : %.8lx  ", mfspr(SPR_SR));
491
  fprintf(runtime.sim.fexe_log, "EPCR0: %.8lx  ", mfspr(SPR_EPCR_BASE));
492
  fprintf(runtime.sim.fexe_log, "EEAR0: %.8lx  ", mfspr(SPR_EEAR_BASE));
493
  fprintf(runtime.sim.fexe_log, "ESR0 : %.8lx\n", mfspr(SPR_ESR_BASE));
494 294 markom
}
495
 
496 537 markom
#if 0
497 535 markom
void print_time (int cycles, char *output)
498
{
499
  int i = 0, c_ps = config.sim.clkcycle_ps;
500
  while (c_ps % 1000 == 0 && i < 2) {
501
    c_ps /= 1000;
502
    i++;
503
  }
504
  c_ps *= cycles;
505
  sprintf (output, "%i%cs", cycles, i == 0 ? 'p' : i == 1 ? 'n': 'u');
506
}
507 537 markom
#endif
508 535 markom
 
509 2 cvs
void dumpreg()
510
{
511 269 markom
  int i;
512 535 markom
  char temp[100];
513 269 markom
 
514 306 markom
  dumpmemory(iqueue[0].insn_addr, iqueue[0].insn_addr + 4, 1, 0);
515 537 markom
  generate_time_pretty (temp, cycles);
516 535 markom
  printf(" (executed) [time %s, #%i]\n", temp, instructions);
517 293 markom
  if (config.cpu.superscalar)
518
    printf ("Superscalar CYCLES: %u", supercycles);
519
  if (config.cpu.hazards)
520
    printf ("  HAZARDWAIT: %u\n", hazardwait);
521
  else
522
    if (config.cpu.superscalar)
523
      printf ("\n");
524
 
525 306 markom
  dumpmemory(pc, pc + 4, 1, 0);
526 269 markom
  printf(" (next insn) %s", (delay_insn?"(delay insn)":""));
527
  for(i = 0; i < MAX_GPRS; i++) {
528
    if (i % 4 == 0)
529
      printf("\n");
530
    printf("GPR%.2u: %.8lx  ", i, reg[i]);
531
  }
532
  printf("flag: %u\n", flag);
533 2 cvs
}
534 123 markom
 
535
/* Address calculation changed by CZ on 27/05/01 */
536 494 markom
inline void decode_execute(struct iqueue_entry *current)
537 123 markom
{
538
  next_delay_insn = 0;
539
  breakpoint = 0;
540
 
541 479 markom
  if(DEBUG_ENABLED && CheckDebugUnit(DebugInstructionFetch, pc_phy))
542 123 markom
    breakpoint++;
543 138 markom
 
544
  cur = current;
545 479 markom
  cur->func_unit = it_unknown;
546 138 markom
  op = &cur->op[0];
547 123 markom
 
548
  /* printf("0x%04x: Executing \"%s\"\n",pc,cur->insn); */
549
 
550
#ifndef HAS_EXECUTION
551
#error HAS_EXECUTION has to be defined in order to execute programs.
552
#endif
553 133 markom
 
554 123 markom
  if (cur->insn_index < 0)
555
    l_invalid();
556
  else
557 138 markom
    {
558
      eval_operands (cur->insn, cur->insn_index, &breakpoint);
559
      or32_opcodes[cur->insn_index].exec();
560
    }
561 123 markom
 
562 458 simons
  /* Check for range exception */
563
  if (getsprbits (SPR_SR, SPR_SR_OV) && getsprbits (SPR_SR, SPR_SR_OVE))
564
    except_handle (EXCEPT_RANGE, 0);
565
 
566 263 markom
  if (config.cpu.dependstats) {
567 123 markom
    /* Dynamic, dependency stats. */
568 535 markom
    adddstats(icomplet[0].insn_index, iqueue[0].insn_index, 1, check_depend());
569 262 markom
 
570 123 markom
    /* Dynamic, functional units stats. */
571
    addfstats(icomplet[0].func_unit, iqueue[0].func_unit, 1, check_depend());
572 262 markom
 
573 123 markom
    /* Dynamic, single stats. */
574 535 markom
    addsstats(iqueue[0].insn_index, 1);
575 123 markom
  }
576
 
577 263 markom
  if (config.cpu.superscalar) {
578 479 markom
    if ((cur->func_unit == it_branch) || (cur->func_unit == it_jump))
579 123 markom
      storecycles += 0;
580
 
581 479 markom
    if (cur->func_unit == it_store)
582 389 lampret
      storecycles += 1;
583 123 markom
 
584 479 markom
    if (cur->func_unit == it_load)
585 389 lampret
      loadcycles += 1;
586
#if 0        
587 479 markom
    if ((icomplet[0].func_unit == it_load) && check_depend())
588 123 markom
      loadcycles++;
589 389 lampret
#endif
590 123 markom
 
591
    /* Pseudo multiple issue benchmark */
592
    if ((multissue[cur->func_unit] < 1) || (check_depend())
593 262 markom
                    || (issued_per_cycle < 1)
594
        ) {
595 123 markom
      int i;
596
      for (i = 0; i < 20; i++)
597 262 markom
        multissue[i] = 2;
598 123 markom
      issued_per_cycle = 2;
599
      supercycles++;
600
      if (check_depend())
601 262 markom
        hazardwait++;
602 479 markom
      multissue[it_unknown] = 2;
603
      multissue[it_shift] = 2;
604
      multissue[it_compare] = 1;
605
      multissue[it_branch] = 1;
606
      multissue[it_jump] = 1;
607
      multissue[it_extend] = 2;
608
      multissue[it_nop] = 2;
609
      multissue[it_move] = 2;
610
      multissue[it_movimm] = 2;
611
      multissue[it_arith] = 2;
612
      multissue[it_store] = 2;
613
      multissue[it_load] = 2;
614 123 markom
    }
615
    multissue[cur->func_unit]--;
616
    issued_per_cycle--;
617
  }
618
  delay_insn = next_delay_insn;
619
 
620
  if(breakpoint)
621 479 markom
    except_handle(EXCEPT_TRAP, 0);
622 123 markom
}
623
 
624
/******************************************
625
 *    Instruction specific functions.     *
626
 ******************************************/
627
 
628
void l_add() {
629 221 markom
  signed long temp1;
630 123 markom
  signed char temp4;
631
 
632 479 markom
  cur->func_unit = it_arith;
633 221 markom
  temp1 = (signed long)eval_operand32(2, &breakpoint)+(signed long)eval_operand32(1, &breakpoint);
634
  set_operand32(0, temp1, &breakpoint);
635 123 markom
 
636
  temp4 = temp1;
637
  if (temp4 == temp1)
638
    mstats.byteadd++;
639
}
640 221 markom
void l_sw() {
641 479 markom
  cur->func_unit = it_store;
642 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint), &breakpoint);
643 123 markom
}
644
void l_sb() {
645 479 markom
  cur->func_unit = it_store;
646 221 markom
  set_operand8(0, eval_operand32(1, &breakpoint), &breakpoint);
647 123 markom
}
648
void l_sh() {
649 479 markom
  cur->func_unit = it_store;
650 221 markom
  set_operand16(0, eval_operand32(1, &breakpoint), &breakpoint);
651 123 markom
}
652
void l_lwz() {
653 437 simons
  unsigned long val;
654 479 markom
  cur->func_unit = it_load;
655 437 simons
  val = eval_operand32(1, &breakpoint);
656
  /* If eval opreand produced exception don't set anything */
657
  if (pending.valid == 1)
658
    return;
659
  set_operand32(0, val, &breakpoint);
660 123 markom
}
661
void l_lbs() {
662 437 simons
  signed char val;
663 479 markom
  cur->func_unit = it_load;
664 437 simons
  val = eval_operand8(1, &breakpoint);
665
  /* If eval opreand produced exception don't set anything */
666
  if (pending.valid == 1)
667
    return;
668
  set_operand32(0, val, &breakpoint);
669 123 markom
}
670 221 markom
void l_lbz() {
671 437 simons
  unsigned char val;
672 479 markom
  cur->func_unit = it_load;
673 437 simons
  val = eval_operand8(1, &breakpoint);
674
  /* If eval opreand produced exception don't set anything */
675
  if (pending.valid == 1)
676
    return;
677
  set_operand32(0, val, &breakpoint);
678 123 markom
}
679 221 markom
void l_lhs() {
680 437 simons
  signed short val;
681 479 markom
  cur->func_unit = it_load;
682 437 simons
  val = eval_operand16(1, &breakpoint);
683
  /* If eval opreand produced exception don't set anything */
684
  if (pending.valid == 1)
685
    return;
686
  set_operand32(0, val, &breakpoint);
687 123 markom
}
688 221 markom
void l_lhz() {
689 437 simons
  unsigned short val;
690 479 markom
  cur->func_unit = it_load;
691 437 simons
  val = eval_operand16(1, &breakpoint);
692
  /* If eval opreand produced exception don't set anything */
693
  if (pending.valid == 1)
694
    return;
695
  set_operand32(0, val, &breakpoint);
696 123 markom
}
697
void l_movhi() {
698 479 markom
  cur->func_unit = it_movimm;
699 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint) << 16, &breakpoint);
700 123 markom
}
701
void l_and() {
702 479 markom
  cur->func_unit = it_arith;
703 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint) & (unsigned)eval_operand32(2, &breakpoint), &breakpoint);
704 123 markom
}
705
void l_or() {
706 479 markom
  cur->func_unit = it_arith;
707 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint) | (unsigned)eval_operand32(2, &breakpoint), &breakpoint);
708 123 markom
}
709
void l_xor() {
710 479 markom
  cur->func_unit = it_arith;
711 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint) ^ (signed)eval_operand32(2, &breakpoint), &breakpoint);
712 123 markom
}
713
void l_sub() {
714 479 markom
  cur->func_unit = it_arith;
715 221 markom
  set_operand32(0, (signed long)eval_operand32(1, &breakpoint) - (signed long)eval_operand32(2, &breakpoint), &breakpoint);
716 123 markom
}
717 174 markom
/*int mcount = 0;*/
718 123 markom
void l_mul() {
719
  signed long temp3, temp2, temp1;
720
 
721 479 markom
  cur->func_unit = it_arith;
722 221 markom
  set_operand32(0, (signed long)eval_operand32(1, &breakpoint) * (signed long)eval_operand32(2, &breakpoint), &breakpoint);
723 174 markom
  /*if (!(mcount++ & 1023)) {
724
    printf ("[%i]\n",mcount);
725
    }*/
726 123 markom
}
727
void l_div() {
728
  signed long temp3, temp2, temp1;
729
 
730 479 markom
  cur->func_unit = it_arith;
731 221 markom
  temp3 = eval_operand32(2, &breakpoint);
732
  temp2 = eval_operand32(1, &breakpoint);
733 123 markom
  if (temp3)
734
    temp1 = temp2 / temp3;
735 458 simons
  else {
736
    except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
737
    return;
738
  }
739 221 markom
  set_operand32(0, temp1, &breakpoint);
740 123 markom
}
741
void l_divu() {
742
  unsigned long temp3, temp2, temp1;
743
 
744 479 markom
  cur->func_unit = it_arith;
745 221 markom
  temp3 = eval_operand32(2, &breakpoint);
746
  temp2 = eval_operand32(1, &breakpoint);
747 123 markom
  temp1 = temp2 / temp3;
748
  /* cycles += 16; */
749 221 markom
  set_operand32(0, temp1, &breakpoint);
750 123 markom
}
751
void l_sll() {
752
  int sign = 1;
753 479 markom
  cur->func_unit = it_shift;
754 221 markom
  if ((signed)eval_operand32(1, &breakpoint) < 0)
755 123 markom
    sign = -1;
756
  /* cycles += 2; */
757 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint) << eval_operand32(2, &breakpoint), &breakpoint);
758 123 markom
}
759
void l_sra() {
760
  unsigned long sign = 0;
761 479 markom
  cur->func_unit = it_shift;
762 123 markom
 
763 221 markom
  if ((signed)eval_operand32(1, &breakpoint) < 0)
764 123 markom
    sign = -1;
765
  /* cycles += 2; */
766 221 markom
  set_operand32(0, (signed)eval_operand32(1, &breakpoint) >> eval_operand32(2, &breakpoint), &breakpoint);
767 123 markom
}
768
void l_srl() {
769 479 markom
  cur->func_unit = it_shift;
770 123 markom
  /* cycles += 2; */
771 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint) >> eval_operand32(2, &breakpoint), &breakpoint);
772 123 markom
}
773 535 markom
void l_bf() {
774
  if (config.cpu.bpb) {
775
    int fwd = (eval_operand32(0, &breakpoint) >= pc) ? 1 : 0;
776
    cur->func_unit = it_branch;
777
    mstats.bf[flag][fwd]++;
778
    bpb_update(cur->insn_addr, flag);
779
  }
780
  if (flag) {
781
    debug(5, "\nl.bf relative: pc=%x pcnext=%x\n", pc, pcnext);
782
    pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
783
    btic_update(pcnext);
784
    next_delay_insn = 1;
785
  } else {
786
    btic_update(pc);
787
  }
788
}
789
void l_bnf() {
790
  if (config.cpu.bpb) {
791
    int fwd = (eval_operand32(0, &breakpoint) >= pc) ? 1 : 0;
792
    cur->func_unit = it_branch;
793
    mstats.bnf[!flag][fwd]++;
794
    bpb_update(cur->insn_addr, flag == 0);
795
  }
796
  if (flag == 0) {
797
    debug(5, "\nl.bnf relative: pc=%x pcnext=%x\n", pc, pcnext);
798
    pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
799
    btic_update(pcnext);
800
    next_delay_insn = 1;
801
  } else {
802
    btic_update(pc);
803
  }
804
}
805 123 markom
void l_j() {
806 344 markom
  debug(5, "\nl.j relative: pc=%x pcnext=%x\n", pc, pcnext);
807 221 markom
  pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
808 479 markom
  cur->func_unit = it_jump;
809 123 markom
  next_delay_insn = 1;
810
}
811
void l_jal() {
812 344 markom
  debug(5, "\nl.jal relative: pc=%x pcnext=%x\n", pc, pcnext);
813 221 markom
  pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
814 123 markom
 
815 479 markom
  cur->func_unit = it_jump;
816 138 markom
  set_reg32(LINK_REGNO, pc + 8);
817 123 markom
  next_delay_insn = 1;
818 264 markom
  if (config.sim.profile) {
819 262 markom
    struct mem_entry *entry;
820 221 markom
    struct label_entry *tmp;
821 261 markom
    if (verify_memoryarea(pcdelay) && (tmp = get_label (pcdelay)))
822 361 markom
      fprintf (runtime.sim.fprof, "+%08X %08X %08X %s\n", cycles, pc + 8, pcdelay, tmp->name);
823 221 markom
    else
824 361 markom
      fprintf (runtime.sim.fprof, "+%08X %08X %08X @%08X\n", cycles, pc + 8, pcdelay, pcdelay);
825 173 markom
  }
826 123 markom
}
827
void l_jalr() {
828 479 markom
  cur->func_unit = it_jump;
829 221 markom
  pcdelay = eval_operand32(0, &breakpoint);
830 138 markom
  set_reg32(LINK_REGNO, pc + 8);
831 123 markom
  next_delay_insn = 1;
832
}
833
void l_jr() {
834 479 markom
  cur->func_unit = it_jump;
835 221 markom
  pcdelay = eval_operand32(0, &breakpoint);
836 123 markom
  next_delay_insn = 1;
837 482 markom
  if (config.sim.profile)
838
    fprintf (runtime.sim.fprof, "-%08X %08X\n", cycles, pcdelay);
839 123 markom
}
840
void l_rfe() {
841 479 markom
  cur->func_unit = it_exception;
842 416 simons
  pcnext = mfspr(SPR_EPCR_BASE);
843
  mtspr(SPR_SR, mfspr(SPR_ESR_BASE));
844
}
845 123 markom
void l_nop() {
846 511 markom
  unsigned long stackaddr;
847
  int k = eval_operand32(0, &breakpoint);
848 479 markom
  cur->func_unit = it_nop;
849 123 markom
  if (nop_period > nop_maxperiod)
850
    nop_maxperiod = nop_period;
851
  nop_period = 0;
852
  nops++;
853 511 markom
  switch (k) {
854
    case NOP_NOP:
855
      break;
856
    case NOP_EXIT:
857
      printf("exit(%d)\n", eval_reg (3));
858
      if (config.debug.gdb_enabled)
859
        set_stall_state (1);
860
      else
861
        cont_run = 0;
862
      break;
863
    case NOP_PRINTF:
864
      stackaddr = eval_reg(4);
865
      simprintf(stackaddr, eval_reg(3));
866
      debug(5, "simprintf %x\n", stackaddr);
867
      break;
868
    case NOP_REPORT:
869
      printf("report(0x%x);\n", eval_reg(3));
870
    default:
871
      if (k >= NOP_REPORT_FIRST && k <= NOP_REPORT_LAST)
872
      printf("report %i (0x%x);\n", k - NOP_REPORT_FIRST, eval_reg(3));
873
      break;
874
  }
875 123 markom
}
876
void l_sfeq() {
877 479 markom
  cur->func_unit = it_compare;
878 221 markom
  flag = eval_operand32(0, &breakpoint) == eval_operand32(1, &breakpoint);
879 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
880
}
881 535 markom
void l_sfne() {
882
  cur->func_unit = it_compare;
883
  flag = eval_operand32(0, &breakpoint) != eval_operand32(1, &breakpoint);
884
  setsprbits(SPR_SR, SPR_SR_F, flag);
885
}
886 123 markom
void l_sfgts() {
887 479 markom
  cur->func_unit = it_compare;
888 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) > (signed)eval_operand32(1, &breakpoint);
889 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
890
}
891
void l_sfges() {
892 479 markom
  cur->func_unit = it_compare;
893 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) >= (signed)eval_operand32(1, &breakpoint);
894 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
895
}
896
void l_sflts() {
897 479 markom
  cur->func_unit = it_compare;
898 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) < (signed)eval_operand32(1, &breakpoint);
899 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
900
}
901
void l_sfles() {
902 479 markom
  cur->func_unit = it_compare;
903 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) <= (signed)eval_operand32(1, &breakpoint);
904 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
905
}
906
void l_sfgtu() {
907 479 markom
  cur->func_unit = it_compare;
908 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) > (unsigned)eval_operand32(1, &breakpoint);
909 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
910
}
911
void l_sfgeu() {
912 479 markom
  cur->func_unit = it_compare;
913 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) >= (unsigned) eval_operand32(1, &breakpoint);
914 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
915
}
916
void l_sfltu() {
917 479 markom
  cur->func_unit = it_compare;
918 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) < (unsigned)eval_operand32(1, &breakpoint);
919 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
920
}
921
void l_sfleu() {
922 479 markom
  cur->func_unit = it_compare;
923 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) <= (unsigned)eval_operand32(1, &breakpoint);
924 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
925
}
926
void l_mtspr() {
927 479 markom
  cur->func_unit = it_move;
928 123 markom
  if (mfspr(SPR_SR) & SPR_SR_SUPV)
929 221 markom
    mtspr(eval_operand32(0, &breakpoint) + eval_operand32(2, &breakpoint), eval_operand32(1, &breakpoint));
930 123 markom
  else {
931
    printf("WARNING: trying to write SPR while SR[SUPV] is cleared.\n");
932
    cont_run = 0;
933
  }
934
}
935
void l_mfspr() {
936 479 markom
  cur->func_unit = it_move;
937 123 markom
  if (mfspr(SPR_SR) & SPR_SR_SUPV)
938 221 markom
    set_operand32(0, mfspr(eval_operand32(1, &breakpoint) + eval_operand32(2, &breakpoint)), &breakpoint);
939 123 markom
  else {
940 221 markom
    set_operand32(0, 0, &breakpoint);
941 123 markom
    printf("WARNING: trying to read SPR while SR[SUPV] is cleared.\n");
942
    cont_run = 0;
943
  }
944
}
945
void l_sys() {
946 511 markom
  except_handle(EXCEPT_SYSCALL, 0);
947 123 markom
}
948 142 chris
 
949
void l_trap() {
950 479 markom
  /* TODO: some SR related code here! */
951 458 simons
  except_handle(EXCEPT_TRAP, 0);
952 142 chris
}
953
 
954 123 markom
void l_mac() {
955
  sprword lo, hi;
956
  LONGEST l;
957 498 lampret
  LONGEST x, y;
958 479 markom
  cur->func_unit = it_mac;
959 123 markom
  lo = mfspr (SPR_MACLO);
960
  hi = mfspr (SPR_MACHI);
961 221 markom
  x = eval_operand32(0, &breakpoint);
962
  y = eval_operand32(1, &breakpoint);
963 498 lampret
  printf ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));
964 221 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
965
  l += (LONGEST) x * (LONGEST) y;
966 123 markom
 
967
  /* This implementation is very fast - it needs only one cycle for mac.  */
968 221 markom
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
969
  hi = ((LONGEST)l) >> 32;
970 123 markom
  mtspr (SPR_MACLO, lo);
971
  mtspr (SPR_MACHI, hi);
972 498 lampret
  printf ("(%08x,%08x)\n", hi, lo);
973 123 markom
}
974
void l_msb() {
975 221 markom
  sprword lo, hi;
976 123 markom
  LONGEST l;
977 479 markom
  cur->func_unit = it_mac;
978 123 markom
  lo = mfspr (SPR_MACLO);
979
  hi = mfspr (SPR_MACHI);
980 221 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
981
  l -= (LONGEST) eval_operand32(0, &breakpoint) * (LONGEST)eval_operand32(1, &breakpoint);
982 123 markom
 
983
  /* This implementation is very fast - it needs only one cycle for msb.  */
984 221 markom
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
985
  hi = ((LONGEST)l) >> 32;
986 123 markom
  mtspr (SPR_MACLO, lo);
987 221 markom
  mtspr (SPR_MACHI, hi);
988 123 markom
}
989
void l_macrc() {
990
  sprword lo, hi;
991
  LONGEST l;
992
  /* No need for synchronization here -- all MAC instructions are 1 cycle long.  */
993
  lo =  mfspr (SPR_MACLO);
994 221 markom
  hi =  mfspr (SPR_MACHI);
995
  l = (ULONGEST) lo | ((LONGEST)hi << 32);
996
  l >>= 28;
997
  //printf ("<%08x>\n", (unsigned long)l);
998
  set_operand32(0, (long)l, &breakpoint);
999 123 markom
  mtspr (SPR_MACLO, 0);
1000 221 markom
  mtspr (SPR_MACHI, 0);
1001 123 markom
}
1002 174 markom
void l_cust1() {
1003
  /*int destr = cur->insn >> 21;
1004
    int src1r = cur->insn >> 15;
1005
    int src2r = cur->insn >> 9;*/
1006
}
1007
void l_cust2() {
1008
}
1009
void l_cust3() {
1010
}
1011
void l_cust4() {
1012
}
1013 123 markom
void l_invalid() {
1014 458 simons
  except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
1015 123 markom
}

powered by: WebSVN 2.1.0

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