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

Subversion Repositories or1k

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

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 615 markom
/* Whether instructions set overflow flag */
42
#define SET_OV_FLAG     1
43
 
44
/* Whether arithmethic instructions set flag on zero */
45 620 markom
#define ARITH_SET_FLAG  1
46 615 markom
 
47 2 cvs
/* General purpose registers. */
48
machword reg[MAX_GPRS];
49
 
50
/* Instruction queue */
51
struct iqueue_entry iqueue[20];
52
 
53 83 lampret
/* Is current insn in execution a delay insn? */
54
int delay_insn;
55
 
56 2 cvs
/* Benchmark multi issue execution */
57
int multissue[20];
58
int supercycles;
59 6 lampret
int issued_per_cycle = 4;
60
int hazardwait = 0;
61 2 cvs
 
62 431 markom
/* Whether break was hit - so we can step over a break */
63
static int break_just_hit = 0;
64
 
65 68 lampret
/* freemem 'pointer' */
66
extern unsigned long freemem;
67
 
68 2 cvs
/* Completition queue */
69 138 markom
struct iqueue_entry icomplet[20];
70 2 cvs
 
71 77 lampret
/* Program counter (and translated PC) */
72 2 cvs
unsigned long pc;
73 77 lampret
unsigned long pc_phy;
74 2 cvs
 
75 378 markom
/* Previous program counter */
76 479 markom
unsigned long pcprev = 0;
77 378 markom
 
78 2 cvs
/* Temporary program counter */
79 83 lampret
unsigned long pcnext;
80 2 cvs
 
81 123 markom
/* Delay instruction effective address register */
82
unsigned long pcdelay;
83
 
84 2 cvs
/* CCR */
85
int flag;
86
 
87
/* CCR (for dependency calculation) */
88
char ccr_flag[10] = "flag";
89
 
90
/* Cycles counts fetch stages */
91
int cycles;
92
 
93 537 markom
/* Each cycle has counter of mem_cycles; this value is joined with cycles
94
   at the end of the cycle; no sim originated memory accesses should be
95
   performed inbetween. */
96
int mem_cycles;
97
 
98 535 markom
/* Instructions executed */
99
int instructions;
100
 
101 6 lampret
/* Load and store stalls */
102
int loadcycles, storecycles;
103
 
104 626 markom
/* Store buffer analysis - stores are accumulated and commited when IO is idle */
105
static int sbuf_head = 0, sbuf_tail = 0, sbuf_count = 0;
106
static int sbuf_buf[MAX_SBUF_LEN] = {0};
107
static int sbuf_prev_cycles = 0;
108
 
109
/* Num cycles waiting for stores to complete */
110
int sbuf_wait_cyc = 0;
111
 
112
/* Number of total store cycles */
113
int sbuf_total_cyc = 0;
114
 
115 138 markom
/* Local data needed for execution.  */
116
static struct iqueue_entry *cur;
117
static int next_delay_insn;
118
static int breakpoint;
119
static unsigned long *op;
120
static int num_op;
121
 
122 2 cvs
/* Implementation specific.
123
   Get an actual value of a specific register. */
124
 
125 560 markom
unsigned long evalsim_reg32(int regno)
126 2 cvs
{
127 138 markom
  if (regno < MAX_GPRS) {
128 560 markom
    return reg[regno];
129
  } else {
130
    printf("\nABORT: read out of registers\n");
131
    cont_run = 0;
132
    return 0;
133
  }
134
}
135
 
136
/* Implementation specific.
137
   Set a specific register with value. */
138
 
139
void setsim_reg32(int regno, unsigned long value)
140
{
141
  if (regno == 0)               /* gpr0 is always zero */
142
    value = 0;
143
 
144
  if (regno < MAX_GPRS) {
145
    reg[regno] = value;
146
  } else {
147
    printf("\nABORT: write out of registers\n");
148
    cont_run = 0;
149
  }
150
}
151
 
152
/* Implementation specific.
153
   Get an actual value of a specific register. */
154
 
155
inline static unsigned long eval_reg32(int regno)
156
{
157
  if (regno < MAX_GPRS) {
158
    IFF(config.cpu.raw_range) {
159 535 markom
      int delta = (cycles - raw_stats.reg[regno]);
160 606 markom
      if ((unsigned long)delta < (unsigned long)config.cpu.raw_range)
161 535 markom
        raw_stats.range[delta]++;
162
    }
163 344 markom
    debug(9, "atoi ret1\n");
164 138 markom
    return reg[regno];
165
  } else {
166 393 markom
    printf("\nABORT: read out of registers\n");
167 138 markom
    cont_run = 0;
168
    return 0;
169
  }
170 2 cvs
}
171
 
172
/* Implementation specific.
173
   Set a specific register with value. */
174
 
175 560 markom
inline static void set_reg32(int regno, unsigned long value)
176 2 cvs
{
177 262 markom
#if 0   
178 138 markom
  if (strcmp(regstr, FRAME_REG) == 0) {
179
    printf("FP (%s) modified by insn at %x. ", FRAME_REG, pc);
180
    printf("Old:%.8lx  New:%.8lx\n", eval_reg(regno), value);
181
  }
182
 
183
  if (strcmp(regstr, STACK_REG) == 0) {
184
    printf("SP (%s) modified by insn at %x. ", STACK_REG, pc);
185
    printf("Old:%.8lx  New:%.8lx\n", eval_reg(regmo), value);
186
  }
187 2 cvs
#endif
188 560 markom
 
189 138 markom
  if (regno < MAX_GPRS) {
190
    reg[regno] = value;
191 560 markom
    IFF(config.cpu.raw_range)
192 535 markom
      raw_stats.reg[regno] = cycles;
193 138 markom
  } else {
194 393 markom
    printf("\nABORT: write out of registers\n");
195 138 markom
    cont_run = 0;
196
  }
197 2 cvs
}
198
 
199
/* Does srcoperand depend on computation of dstoperand? Return
200
   non-zero if yes.
201
 
202 262 markom
 Cycle t                 Cycle t+1
203
dst: irrelevant         src: immediate                  always 0
204
dst: reg1 direct        src: reg2 direct                0 if reg1 != reg2
205
dst: reg1 disp          src: reg2 direct                always 0
206
dst: reg1 direct        src: reg2 disp                  0 if reg1 != reg2
207
dst: reg1 disp          src: reg2 disp                  always 1 (store must
208
                                                        finish before load)
209 138 markom
dst: flag               src: flag                       always 1
210 2 cvs
*/
211
 
212 138 markom
int depend_operands(prev, next)
213
     struct iqueue_entry *prev;
214
     struct iqueue_entry *next;
215 2 cvs
{
216 138 markom
  /* Find destination type. */
217
  unsigned long type = 0;
218
  int i = 0;
219
  if (or32_opcodes[prev->insn_index].flags & OR32_W_FLAG
220
      && or32_opcodes[next->insn_index].flags & OR32_R_FLAG)
221
    return 1;
222 2 cvs
 
223 138 markom
  while (!(prev->op[i + MAX_OPERANDS] & OPTYPE_LAST))
224
    if (prev->op[i + MAX_OPERANDS] & OPTYPE_DST)
225
      {
226 262 markom
        type = prev->op[i + MAX_OPERANDS];
227
        break;
228 138 markom
      }
229
    else
230
      i++;
231 560 markom
 
232 138 markom
  /* We search all source operands - if we find confict => return 1 */
233
  i = 0;
234
  while (!(next->op[i + MAX_OPERANDS] & OPTYPE_LAST))
235
    if (!(next->op[i + MAX_OPERANDS] & OPTYPE_DST))
236
      {
237 262 markom
        if (next->op[i + MAX_OPERANDS] & OPTYPE_DIS)
238
          if (type & OPTYPE_DIS)
239
            return 1;
240
          else if (next->op[i] == prev->op[i]
241
                   && (next->op[i + MAX_OPERANDS] & OPTYPE_REG))
242
            return 1;
243
        if (next->op[i] == prev->op[i]
244
            && (next->op[i + MAX_OPERANDS] & OPTYPE_REG)
245
            && (type & OPTYPE_REG))
246
          return 1;
247
        i++;
248 138 markom
      }
249
    else
250
      i++;
251
  return 0;
252
}
253 2 cvs
 
254 138 markom
/* Implementation specific.
255
   Parses and returns operands. */
256 2 cvs
 
257 138 markom
static void
258
eval_operands (unsigned long insn, int insn_index, int* breakpoint)
259
{
260
  struct insn_op_struct *opd = op_start[insn_index];
261
  unsigned long data = 0;
262
  int dis = 0;
263
  int no = 0;
264 560 markom
 
265 138 markom
  while (1)
266
    {
267
      unsigned long tmp = 0, nbits = 0;
268
      while (1)
269 262 markom
        {
270
          tmp |= ((insn  >> (opd->type & OPTYPE_SHR)) & ((1 << opd->data) - 1)) << nbits;
271
          nbits += opd->data;
272
          if (opd->type & OPTYPE_OP)
273
            break;
274
          opd++;
275
        }
276 2 cvs
 
277 138 markom
      /* Do we have to sign extend? */
278
      if (opd->type & OPTYPE_SIG)
279 262 markom
        {
280
          int sbit = (opd->type & OPTYPE_SBIT) >> OPTYPE_SBIT_SHR;
281
          if (tmp & (1 << sbit))
282
            tmp |= 0xFFFFFFFF << sbit;
283
        }
284 138 markom
      if (opd->type & OPTYPE_DIS) {
285 262 markom
        /* We have to read register later.  */
286
        data += tmp;
287
        dis = 1;
288 138 markom
      } else
289 262 markom
        {
290
          if (dis && (opd->type & OPTYPE_REG))
291 560 markom
            op[no] = data + eval_reg32 (tmp);
292 262 markom
          else
293
            op[no] = tmp;
294
          op[no + MAX_OPERANDS] = opd->type | (dis ? OPTYPE_DIS : 0);
295
          no++;
296
          data = 0;
297
          dis = 0;
298
        }
299 693 markom
      if(opd->type & OPTYPE_LAST) {
300
        num_op = no;
301 262 markom
        return;
302 693 markom
      }
303 138 markom
      opd++;
304
    }
305
  num_op = no;
306 2 cvs
}
307
 
308
/* Implementation specific.
309 138 markom
   Evaluates source operand op_no. */
310
 
311 560 markom
inline static unsigned long eval_operand32 (int op_no, int *breakpoint)
312 2 cvs
{
313 344 markom
  debug (9, "%i %08X\n", op_no, op[op_no + MAX_OPERANDS]);
314 538 markom
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
315 560 markom
    /* memory accesses are not cached */
316 138 markom
    return eval_mem32 (op[op_no], breakpoint);
317 560 markom
  else if (op[op_no + MAX_OPERANDS] & OPTYPE_REG) {
318
    return eval_reg32 (op[op_no]);
319
  } else {
320 138 markom
    return op[op_no];
321 560 markom
  }
322 2 cvs
}
323
 
324
/* Implementation specific.
325 221 markom
   Evaluates source operand op_no. */
326
 
327 560 markom
static unsigned long eval_operand16 (int op_no, int *breakpoint)
328 221 markom
{
329 344 markom
  debug (9, "%i %08X\n", op_no, op[op_no + MAX_OPERANDS]);
330 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
331 221 markom
    return eval_mem16 (op[op_no], breakpoint);
332 458 simons
  }
333 221 markom
  else {
334
    fprintf (stderr, "Invalid operand type.\n");
335
    exit (1);
336
  }
337
}
338
 
339
/* Implementation specific.
340
   Evaluates source operand op_no. */
341
 
342 560 markom
static unsigned long eval_operand8 (int op_no, int *breakpoint)
343 221 markom
{
344 344 markom
  debug (9, "%i %08X\n", op_no, op[op_no + MAX_OPERANDS]);
345 221 markom
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
346
    return eval_mem8 (op[op_no], breakpoint);
347
  else {
348
    fprintf (stderr, "Invalid operand type.\n");
349
    exit (1);
350
  }
351
}
352
 
353
/* Implementation specific.
354 2 cvs
   Set destination operand (register direct, register indirect
355
   (with displacement) with value. */
356
 
357 560 markom
inline static void set_operand32(int op_no, unsigned long value, int* breakpoint)
358 2 cvs
{
359 138 markom
  /* Mark this as destination operand.  */
360 560 markom
  IFF (config.cpu.dependstats) op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
361 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
362 138 markom
    set_mem32(op[op_no], value, breakpoint);
363 560 markom
  } else if (op[op_no + MAX_OPERANDS] & OPTYPE_REG) {
364 138 markom
    set_reg32(op[op_no], value);
365 560 markom
  } else {
366
    fprintf (stderr, "Invalid operand type.\n");
367
    exit (1);
368 458 simons
  }
369 2 cvs
}
370
 
371 221 markom
/* Implementation specific.
372
   Set destination operand (register direct, register indirect
373
   (with displacement) with value. */
374
 
375
void set_operand16(int op_no, unsigned long value, int* breakpoint)
376
{
377
  /* Mark this as destination operand.  */
378 560 markom
  op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
379 458 simons
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS) {
380 221 markom
    set_mem16(op[op_no], value, breakpoint);
381 458 simons
  }
382 574 markom
  else
383 221 markom
    {
384
      fprintf (stderr, "Invalid operand type.\n");
385
      exit (1);
386
    }
387
}
388
 
389
/* Implementation specific.
390
   Set destination operand (register direct, register indirect
391
   (with displacement) with value. */
392
 
393
void set_operand8(int op_no, unsigned long value, int* breakpoint)
394
{
395
  /* Mark this as destination operand.  */
396
  op[op_no + MAX_OPERANDS] |= OPTYPE_DST;
397
  if (op[op_no + MAX_OPERANDS] & OPTYPE_DIS)
398
    set_mem8(op[op_no], value, breakpoint);
399
  else
400
    {
401
      fprintf (stderr, "Invalid operand type.\n");
402
      exit (1);
403
    }
404
}
405
 
406 605 markom
/* Sets a new SPR_SR_OV value, based on next register value */
407
static inline unsigned long set_ov_flag (unsigned long value)
408
{
409 615 markom
#if SET_OV_FLAG
410 605 markom
  value & 0x80000000 ? setsprbits (SPR_SR, SPR_SR_OV, 1) : setsprbits (SPR_SR, SPR_SR_OV, 0);
411 615 markom
#endif
412 605 markom
  return value;
413
}
414
 
415 123 markom
/* Modified by CZ 26/05/01 for new mode execution */
416
/* Fetch returns nonzero if instruction should NOT be executed.  */
417 557 markom
static inline int fetch()
418
{
419 221 markom
  struct mem_entry *entry;
420 344 markom
  debug(5, "fetch()\n");
421 123 markom
 
422 557 markom
  /* Update the pc for pending exceptions, or get physical pc */
423 574 markom
  if (!pending.valid)
424 631 simons
    pc_phy = immu_translate(pc, 0);
425 574 markom
 
426 557 markom
  if(pending.valid)
427
    except_handle_backend(pending.type, pending.address, pending.saved);
428 464 simons
 
429 557 markom
  if (CHECK_BREAKPOINTS) {
430
    /* MM: Check for breakpoint.  This has to be done in fetch cycle,
431
       because of peripheria.
432
       MM1709: if we cannot access the memory entry, we could not set the
433
       breakpoint earlier, so just chech the breakpoint list.  */
434
    if (has_breakpoint (pc_phy) && !break_just_hit) {
435
      break_just_hit = 1;
436
      return 1; /* Breakpoint set. */
437
    }
438
    break_just_hit = 0;
439 431 markom
  }
440 535 markom
  instructions++;
441 378 markom
 
442 538 markom
  pc_phy &= ~0x03;
443
 
444 378 markom
  /* Fetch instruction. */
445 560 markom
  iqueue[0].insn_addr = pc;
446
  iqueue[0].insn = eval_insn (pc_phy, &breakpoint);;
447 557 markom
 
448 378 markom
  /* update_pc will be called after execution */
449 77 lampret
 
450 378 markom
  return 0;
451 2 cvs
}
452
 
453 479 markom
/* This code actually updates the PC value.  */
454 626 markom
static inline void update_pc ()
455 142 chris
{
456 479 markom
  pcprev = pc; /* Store value for later */
457
  pc = pcnext;
458
  pcnext = delay_insn ? pcdelay : pcnext + 4;
459 2 cvs
}
460
 
461 626 markom
static inline void analysis ()
462 2 cvs
{
463 394 markom
  if (config.cpu.dependstats)
464 123 markom
    /* Instruction waits in completition buffer until retired. */
465 138 markom
    memcpy (&icomplet[0], &iqueue[0], sizeof (struct iqueue_entry));
466
 
467 394 markom
  if (config.sim.history) {
468 263 markom
    int i;
469
 
470 123 markom
    /* History of execution */
471
    for (i = HISTEXEC_LEN - 1; i; i--)
472
      histexec[i] = histexec[i - 1];
473 262 markom
    histexec[0] = icomplet[0].insn_addr;        /* add last insn */
474 123 markom
  }
475 2 cvs
}
476
 
477 626 markom
/* Store buffer analysis - stores are accumulated and commited when IO is idle */
478 630 markom
static inline sbuf_store (int cyc) {
479 626 markom
  int delta = cycles - sbuf_prev_cycles;
480
  sbuf_total_cyc += cyc;
481 630 markom
  sbuf_prev_cycles = cycles;
482 626 markom
 
483 630 markom
  //printf (">STORE %i,%i,%i,%i,%i\n", delta, sbuf_count, sbuf_tail, sbuf_head, sbuf_buf[sbuf_tail], sbuf_buf[sbuf_head]);
484
  //printf ("|%i,%i\n", sbuf_total_cyc, sbuf_wait_cyc);
485 626 markom
  /* Take stores from buffer, that occured meanwhile */
486 630 markom
  while (sbuf_count && delta >= sbuf_buf[sbuf_tail]) {
487 626 markom
    delta -= sbuf_buf[sbuf_tail];
488
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
489
    sbuf_count--;
490
  }
491
  if (sbuf_count)
492
    sbuf_buf[sbuf_tail] -= delta;
493 630 markom
 
494 626 markom
  /* Store buffer is full, take one out */
495
  if (sbuf_count >= config.cpu.sbuf_len) {
496
    sbuf_wait_cyc += sbuf_buf[sbuf_tail];
497
    mem_cycles += sbuf_buf[sbuf_tail];
498 630 markom
    sbuf_prev_cycles += sbuf_buf[sbuf_tail];
499 626 markom
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
500
    sbuf_count--;
501
  }
502
  /* Put newest store in the buffer */
503
  sbuf_buf[sbuf_head] = cyc;
504
  sbuf_head = (sbuf_head + 1) % MAX_SBUF_LEN;
505
  sbuf_count++;
506 630 markom
  //printf ("|STORE %i,%i,%i,%i,%i\n", delta, sbuf_count, sbuf_tail, sbuf_head, sbuf_buf[sbuf_tail], sbuf_buf[sbuf_head]);
507 626 markom
}
508 294 markom
 
509 626 markom
/* Store buffer analysis - previous stores should commit, before any load */
510
static inline sbuf_load () {
511 629 markom
  int delta = cycles - sbuf_prev_cycles;
512 630 markom
  sbuf_prev_cycles = cycles;
513
 
514
  //printf (">LOAD  %i,%i,%i,%i,%i\n", delta, sbuf_count, sbuf_tail, sbuf_head, sbuf_buf[sbuf_tail], sbuf_buf[sbuf_head]);
515
  //printf ("|%i,%i\n", sbuf_total_cyc, sbuf_wait_cyc);
516 629 markom
  /* Take stores from buffer, that occured meanwhile */
517 630 markom
  while (sbuf_count && delta >= sbuf_buf[sbuf_tail]) {
518 629 markom
    delta -= sbuf_buf[sbuf_tail];
519
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
520
    sbuf_count--;
521
  }
522
  if (sbuf_count)
523
    sbuf_buf[sbuf_tail] -= delta;
524
 
525 626 markom
  /* Wait for all stores to complete */
526
  while (sbuf_count > 0) {
527
    sbuf_wait_cyc += sbuf_buf[sbuf_tail];
528
    mem_cycles += sbuf_buf[sbuf_tail];
529 630 markom
    sbuf_prev_cycles += sbuf_buf[sbuf_tail];
530 626 markom
    sbuf_tail = (sbuf_tail + 1) % MAX_SBUF_LEN;
531
    sbuf_count--;
532
  }
533 630 markom
  //printf ("|LOAD  %i,%i,%i,%i,%i\n", delta, sbuf_count, sbuf_tail, sbuf_head, sbuf_buf[sbuf_tail], sbuf_buf[sbuf_head]);
534 626 markom
}
535
 
536 294 markom
/* Execution logger.  */
537
inline void dump_exe_log()
538
{
539 479 markom
  unsigned long i = iqueue[0].insn_addr;
540 294 markom
 
541 479 markom
  if (i == 0xffffffff) return;
542 672 markom
  if (config.sim.exe_log_start <= instructions && (config.sim.exe_log_end <= 0 || instructions <= config.sim.exe_log_end)) {
543 693 markom
    if (config.sim.exe_log_marker && instructions % config.sim.exe_log_marker == 0) {
544
      fprintf (runtime.sim.fexe_log, "--------------------- %8i instruction ---------------------\n", instructions);
545
    }
546 672 markom
    switch (config.sim.exe_log_type) {
547
    case EXE_LOG_HARDWARE:
548
      fprintf (runtime.sim.fexe_log, "\nEXECUTED(): %.8lx:  ", i);
549
      fprintf (runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i), evalsim_mem8(i + 1));
550
      fprintf (runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i + 2), evalsim_mem8(i + 3));
551
      for(i = 0; i < MAX_GPRS; i++) {
552
        if (i % 4 == 0)
553
          fprintf(runtime.sim.fexe_log, "\n");
554
        fprintf (runtime.sim.fexe_log, "GPR%2u: %.8lx  ", i, reg[i]);
555
      }
556
      fprintf (runtime.sim.fexe_log, "\n");
557
      fprintf (runtime.sim.fexe_log, "SR   : %.8lx  ", mfspr(SPR_SR));
558
      fprintf (runtime.sim.fexe_log, "EPCR0: %.8lx  ", mfspr(SPR_EPCR_BASE));
559
      fprintf (runtime.sim.fexe_log, "EEAR0: %.8lx  ", mfspr(SPR_EEAR_BASE));
560
      fprintf (runtime.sim.fexe_log, "ESR0 : %.8lx\n", mfspr(SPR_ESR_BASE));
561
      break;
562 675 markom
    case EXE_LOG_SIMPLE:
563 672 markom
    case EXE_LOG_SOFTWARE:
564
      {
565
        int labels = 0;
566
        if (verify_memoryarea(i)) {
567
          struct label_entry *entry;
568
          entry = get_label(i);
569
          if (entry) {
570 675 markom
            fprintf (runtime.sim.fexe_log, "%s: ", entry->name);
571 672 markom
            labels++;
572
          }
573
        } else {
574 675 markom
          fprintf (runtime.sim.fexe_log, "<invalid addr>: ");
575 672 markom
          labels++;
576
        }
577 675 markom
 
578 672 markom
        if (labels) fprintf (runtime.sim.fexe_log, "\n");
579 675 markom
 
580
        if (config.sim.exe_log_type == EXE_LOG_SOFTWARE) {
581 678 markom
          int i;
582
          for (i = 0; i < num_op; i++)
583 677 markom
            if (op[i + MAX_OPERANDS] & OPTYPE_DIS) {
584
              fprintf (runtime.sim.fexe_log, "EA =%08x ", op[i]);
585
            } else if ((op[i + MAX_OPERANDS] & OPTYPE_REG) && op[i]) {
586
              fprintf (runtime.sim.fexe_log, "r%-2i=%08x ", op[i], evalsim_reg32 (op[i]));
587
            } else
588 675 markom
            fprintf (runtime.sim.fexe_log, "             ");
589 678 markom
          for (; i < 3; i++)
590
            fprintf (runtime.sim.fexe_log, "             ");
591 675 markom
        }
592
 
593 677 markom
        fprintf (runtime.sim.fexe_log, "%.8lx ", i);
594 672 markom
        if (index >= 0) {
595
          extern char *disassembled;
596 677 markom
          disassemble_insn (iqueue[0].insn);
597
          fprintf (runtime.sim.fexe_log, "%s\n", disassembled);
598 672 markom
        } else
599 677 markom
          fprintf (runtime.sim.fexe_log, "<invalid>\n");
600 672 markom
      }
601
    }
602
  }
603 294 markom
}
604
 
605 537 markom
#if 0
606 535 markom
void print_time (int cycles, char *output)
607
{
608
  int i = 0, c_ps = config.sim.clkcycle_ps;
609
  while (c_ps % 1000 == 0 && i < 2) {
610
    c_ps /= 1000;
611
    i++;
612
  }
613
  c_ps *= cycles;
614
  sprintf (output, "%i%cs", cycles, i == 0 ? 'p' : i == 1 ? 'n': 'u');
615
}
616 537 markom
#endif
617 535 markom
 
618 2 cvs
void dumpreg()
619
{
620 269 markom
  int i;
621 535 markom
  char temp[100];
622 269 markom
 
623 306 markom
  dumpmemory(iqueue[0].insn_addr, iqueue[0].insn_addr + 4, 1, 0);
624 537 markom
  generate_time_pretty (temp, cycles);
625 535 markom
  printf(" (executed) [time %s, #%i]\n", temp, instructions);
626 293 markom
  if (config.cpu.superscalar)
627
    printf ("Superscalar CYCLES: %u", supercycles);
628
  if (config.cpu.hazards)
629
    printf ("  HAZARDWAIT: %u\n", hazardwait);
630
  else
631
    if (config.cpu.superscalar)
632
      printf ("\n");
633
 
634 306 markom
  dumpmemory(pc, pc + 4, 1, 0);
635 269 markom
  printf(" (next insn) %s", (delay_insn?"(delay insn)":""));
636
  for(i = 0; i < MAX_GPRS; i++) {
637
    if (i % 4 == 0)
638
      printf("\n");
639 560 markom
    printf("GPR%.2u: %.8lx  ", i, evalsim_reg32(i));
640 269 markom
  }
641
  printf("flag: %u\n", flag);
642 2 cvs
}
643 123 markom
 
644
/* Address calculation changed by CZ on 27/05/01 */
645 560 markom
static inline void decode_execute(struct iqueue_entry *current)
646 123 markom
{
647 560 markom
  int insn_index;
648 123 markom
  next_delay_insn = 0;
649
  breakpoint = 0;
650 560 markom
 
651 550 markom
  if(config.debug.enabled && CheckDebugUnit(DebugInstructionFetch, pc_phy))
652 123 markom
    breakpoint++;
653 138 markom
 
654 560 markom
  IFF (config.cpu.dependstats) current->func_unit = it_unknown;
655
 
656
  current->insn_index = insn_index = insn_decode(current->insn);
657 123 markom
 
658
#ifndef HAS_EXECUTION
659
#error HAS_EXECUTION has to be defined in order to execute programs.
660
#endif
661 133 markom
 
662 560 markom
  cur = current;  /* globals; needed by eval/set_operand */
663
 
664
  if (insn_index < 0)
665 123 markom
    l_invalid();
666 560 markom
  else {
667
    op = &cur->op[0];
668
    eval_operands (cur->insn, insn_index, &breakpoint);
669
    or32_opcodes[insn_index].exec();
670
  }
671 675 markom
 
672 458 simons
  /* Check for range exception */
673 557 markom
  if (testsprbits (SPR_SR, SPR_SR_OVE) && testsprbits (SPR_SR, SPR_SR_OV))
674 611 simons
    except_handle (EXCEPT_RANGE, mfspr(SPR_EEAR_BASE));
675 458 simons
 
676 263 markom
  if (config.cpu.dependstats) {
677 560 markom
    iqueue[0].insn_index = insn_index;
678 123 markom
    /* Dynamic, dependency stats. */
679 535 markom
    adddstats(icomplet[0].insn_index, iqueue[0].insn_index, 1, check_depend());
680 675 markom
 
681 123 markom
    /* Dynamic, functional units stats. */
682
    addfstats(icomplet[0].func_unit, iqueue[0].func_unit, 1, check_depend());
683 675 markom
 
684 123 markom
    /* Dynamic, single stats. */
685 535 markom
    addsstats(iqueue[0].insn_index, 1);
686 123 markom
  }
687 560 markom
 
688 263 markom
  if (config.cpu.superscalar) {
689 479 markom
    if ((cur->func_unit == it_branch) || (cur->func_unit == it_jump))
690 123 markom
      storecycles += 0;
691
 
692 479 markom
    if (cur->func_unit == it_store)
693 389 lampret
      storecycles += 1;
694 123 markom
 
695 479 markom
    if (cur->func_unit == it_load)
696 389 lampret
      loadcycles += 1;
697
#if 0        
698 479 markom
    if ((icomplet[0].func_unit == it_load) && check_depend())
699 123 markom
      loadcycles++;
700 389 lampret
#endif
701 123 markom
 
702
    /* Pseudo multiple issue benchmark */
703
    if ((multissue[cur->func_unit] < 1) || (check_depend())
704 560 markom
     || (issued_per_cycle < 1)) {
705 123 markom
      int i;
706
      for (i = 0; i < 20; i++)
707 262 markom
        multissue[i] = 2;
708 123 markom
      issued_per_cycle = 2;
709
      supercycles++;
710
      if (check_depend())
711 262 markom
        hazardwait++;
712 479 markom
      multissue[it_unknown] = 2;
713
      multissue[it_shift] = 2;
714
      multissue[it_compare] = 1;
715
      multissue[it_branch] = 1;
716
      multissue[it_jump] = 1;
717
      multissue[it_extend] = 2;
718
      multissue[it_nop] = 2;
719
      multissue[it_move] = 2;
720
      multissue[it_movimm] = 2;
721
      multissue[it_arith] = 2;
722
      multissue[it_store] = 2;
723
      multissue[it_load] = 2;
724 123 markom
    }
725
    multissue[cur->func_unit]--;
726
    issued_per_cycle--;
727
  }
728
  delay_insn = next_delay_insn;
729
 
730
  if(breakpoint)
731 611 simons
    except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
732 123 markom
}
733
 
734 557 markom
void cpu_reset()
735
{
736 606 markom
  int i;
737 557 markom
  cycles = 0;
738
  instructions = 0;
739
  supercycles = 0;
740
  loadcycles = 0;
741
  storecycles = 0;
742 606 markom
  for (i = 0; i < MAX_GPRS; i++)
743
    set_reg32 (i, 0);
744 557 markom
  memset(iqueue, 0, sizeof(iqueue));
745
  memset(icomplet, 0, sizeof(icomplet));
746 626 markom
 
747
  sbuf_head = 0;
748
  sbuf_tail = 0;
749
  sbuf_count = 0;
750
  sbuf_prev_cycles = 0;
751 557 markom
 
752
  /* Cpu configuration */
753
  mtspr(SPR_UPR, config.cpu.upr);
754
  setsprbits(SPR_VR, SPR_VR_VER, config.cpu.ver);
755
  setsprbits(SPR_VR, SPR_VR_REV, config.cpu.rev);
756
  mtspr(SPR_SR, config.cpu.sr);
757
 
758
  pcnext = 0x0; /* MM1409: All programs should start at reset vector entry!  */
759
  printf ("Starting at 0x%08x\n", pcnext);
760
  pc = pcnext;
761
  pc_phy = pc;
762
  pcnext += 4;
763
  debug(1, "reset ...\n");
764
 
765
  /* MM1409: All programs should set their stack pointer!  */
766
  except_handle(EXCEPT_RESET, 0);
767
}
768
 
769
inline int cpu_clock ()
770
{
771
  if(fetch()) {
772
    printf ("Breakpoint hit.\n");
773
    cont_run = 0; /* memory breakpoint encountered */
774
    return 1;
775
  }
776
  decode_execute(&iqueue[0]);
777
  update_pc();
778
  analysis();
779
  if (config.sim.exe_log) dump_exe_log();
780
  return 0;
781
}
782
 
783 123 markom
/******************************************
784
 *    Instruction specific functions.     *
785
 ******************************************/
786
 
787
void l_add() {
788 221 markom
  signed long temp1;
789 123 markom
  signed char temp4;
790
 
791 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
792 221 markom
  temp1 = (signed long)eval_operand32(2, &breakpoint)+(signed long)eval_operand32(1, &breakpoint);
793
  set_operand32(0, temp1, &breakpoint);
794 605 markom
  set_ov_flag (temp1);
795 620 markom
  if (ARITH_SET_FLAG) {
796
    flag = temp1 == 0;
797
    setsprbits(SPR_SR, SPR_SR_F, flag);
798
  }
799 615 markom
 
800 123 markom
  temp4 = temp1;
801
  if (temp4 == temp1)
802
    mstats.byteadd++;
803
}
804 557 markom
void l_sw() {
805 630 markom
  int old_cyc = 0;
806 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_store;
807 630 markom
  IFF (config.cpu.sbuf_len) old_cyc = mem_cycles;
808 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint), &breakpoint);
809 630 markom
  if (config.cpu.sbuf_len) {
810
    int t = mem_cycles;
811
    mem_cycles = old_cyc;
812
    sbuf_store (t - old_cyc);
813
  }
814 123 markom
}
815
void l_sb() {
816 630 markom
  int old_cyc = 0;
817 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_store;
818 630 markom
  IFF (config.cpu.sbuf_len) old_cyc = mem_cycles;
819 221 markom
  set_operand8(0, eval_operand32(1, &breakpoint), &breakpoint);
820 630 markom
  if (config.cpu.sbuf_len) {
821
    int t = mem_cycles;
822
    mem_cycles = old_cyc;
823
    sbuf_store (t- old_cyc);
824
  }
825 123 markom
}
826
void l_sh() {
827 630 markom
  int old_cyc = 0;
828 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_store;
829 630 markom
  IFF (config.cpu.sbuf_len) old_cyc = mem_cycles;
830 221 markom
  set_operand16(0, eval_operand32(1, &breakpoint), &breakpoint);
831 630 markom
  if (config.cpu.sbuf_len) {
832
    int t = mem_cycles;
833
    mem_cycles = old_cyc;
834
    sbuf_store (t - old_cyc);
835
  }
836 123 markom
}
837
void l_lwz() {
838 437 simons
  unsigned long val;
839 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
840 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
841 437 simons
  val = eval_operand32(1, &breakpoint);
842 619 markom
  /* If eval operand produced exception don't set anything */
843 558 markom
  if (!pending.valid)
844
    set_operand32(0, val, &breakpoint);
845 123 markom
}
846
void l_lbs() {
847 437 simons
  signed char val;
848 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
849 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
850 437 simons
  val = eval_operand8(1, &breakpoint);
851
  /* If eval opreand produced exception don't set anything */
852 558 markom
  if (!pending.valid)
853
    set_operand32(0, val, &breakpoint);
854 123 markom
}
855 221 markom
void l_lbz() {
856 437 simons
  unsigned char val;
857 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
858 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
859 437 simons
  val = eval_operand8(1, &breakpoint);
860
  /* If eval opreand produced exception don't set anything */
861 558 markom
  if (!pending.valid)
862
    set_operand32(0, val, &breakpoint);
863 123 markom
}
864 221 markom
void l_lhs() {
865 437 simons
  signed short val;
866 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
867 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
868 437 simons
  val = eval_operand16(1, &breakpoint);
869
  /* If eval opreand produced exception don't set anything */
870 558 markom
  if (!pending.valid)
871
    set_operand32(0, val, &breakpoint);
872 123 markom
}
873 221 markom
void l_lhz() {
874 437 simons
  unsigned short val;
875 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_load;
876 626 markom
  if (config.cpu.sbuf_len) sbuf_load ();
877 437 simons
  val = eval_operand16(1, &breakpoint);
878
  /* If eval opreand produced exception don't set anything */
879 558 markom
  if (!pending.valid)
880
    set_operand32(0, val, &breakpoint);
881 123 markom
}
882
void l_movhi() {
883 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_movimm;
884 221 markom
  set_operand32(0, eval_operand32(1, &breakpoint) << 16, &breakpoint);
885 123 markom
}
886
void l_and() {
887 615 markom
  unsigned long temp1;
888 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
889 615 markom
  set_operand32(0, temp1 = set_ov_flag (eval_operand32(1, &breakpoint) & (unsigned)eval_operand32(2, &breakpoint)), &breakpoint);
890 620 markom
  if (ARITH_SET_FLAG) {
891
    flag = temp1 == 0;
892
    setsprbits(SPR_SR, SPR_SR_F, flag);
893
  }
894 123 markom
}
895
void l_or() {
896 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
897 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) | (unsigned)eval_operand32(2, &breakpoint)), &breakpoint);
898 123 markom
}
899
void l_xor() {
900 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
901 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) ^ (signed)eval_operand32(2, &breakpoint)), &breakpoint);
902 123 markom
}
903
void l_sub() {
904 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
905 605 markom
  set_operand32(0, set_ov_flag ((signed long)eval_operand32(1, &breakpoint) - (signed long)eval_operand32(2, &breakpoint)), &breakpoint);
906 123 markom
}
907 174 markom
/*int mcount = 0;*/
908 123 markom
void l_mul() {
909
  signed long temp3, temp2, temp1;
910
 
911 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
912 605 markom
  set_operand32(0, set_ov_flag ((signed long)eval_operand32(1, &breakpoint) * (signed long)eval_operand32(2, &breakpoint)), &breakpoint);
913 174 markom
  /*if (!(mcount++ & 1023)) {
914
    printf ("[%i]\n",mcount);
915
    }*/
916 123 markom
}
917
void l_div() {
918
  signed long temp3, temp2, temp1;
919
 
920 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
921 221 markom
  temp3 = eval_operand32(2, &breakpoint);
922
  temp2 = eval_operand32(1, &breakpoint);
923 123 markom
  if (temp3)
924
    temp1 = temp2 / temp3;
925 458 simons
  else {
926
    except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
927
    return;
928
  }
929 605 markom
  set_operand32(0, set_ov_flag (temp1), &breakpoint);
930 123 markom
}
931
void l_divu() {
932
  unsigned long temp3, temp2, temp1;
933
 
934 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_arith;
935 221 markom
  temp3 = eval_operand32(2, &breakpoint);
936
  temp2 = eval_operand32(1, &breakpoint);
937 123 markom
  temp1 = temp2 / temp3;
938
  /* cycles += 16; */
939 605 markom
  set_operand32(0, set_ov_flag (temp1), &breakpoint);
940 123 markom
}
941
void l_sll() {
942
  int sign = 1;
943 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_shift;
944 221 markom
  if ((signed)eval_operand32(1, &breakpoint) < 0)
945 123 markom
    sign = -1;
946
  /* cycles += 2; */
947 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) << eval_operand32(2, &breakpoint)), &breakpoint);
948 123 markom
}
949
void l_sra() {
950
  unsigned long sign = 0;
951 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_shift;
952 123 markom
 
953 221 markom
  if ((signed)eval_operand32(1, &breakpoint) < 0)
954 123 markom
    sign = -1;
955
  /* cycles += 2; */
956 605 markom
  set_operand32(0, set_ov_flag ((signed)eval_operand32(1, &breakpoint) >> eval_operand32(2, &breakpoint)), &breakpoint);
957 123 markom
}
958
void l_srl() {
959 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_shift;
960 123 markom
  /* cycles += 2; */
961 605 markom
  set_operand32(0, set_ov_flag (eval_operand32(1, &breakpoint) >> eval_operand32(2, &breakpoint)), &breakpoint);
962 123 markom
}
963 535 markom
void l_bf() {
964 541 markom
  if (config.bpb.enabled) {
965 535 markom
    int fwd = (eval_operand32(0, &breakpoint) >= pc) ? 1 : 0;
966 558 markom
    IFF (config.cpu.dependstats) cur->func_unit = it_branch;
967 535 markom
    mstats.bf[flag][fwd]++;
968
    bpb_update(cur->insn_addr, flag);
969
  }
970
  if (flag) {
971
    debug(5, "\nl.bf relative: pc=%x pcnext=%x\n", pc, pcnext);
972
    pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
973
    btic_update(pcnext);
974
    next_delay_insn = 1;
975
  } else {
976
    btic_update(pc);
977
  }
978
}
979
void l_bnf() {
980 541 markom
  if (config.bpb.enabled) {
981 535 markom
    int fwd = (eval_operand32(0, &breakpoint) >= pc) ? 1 : 0;
982 558 markom
    IFF (config.cpu.dependstats) cur->func_unit = it_branch;
983 535 markom
    mstats.bnf[!flag][fwd]++;
984
    bpb_update(cur->insn_addr, flag == 0);
985
  }
986
  if (flag == 0) {
987
    debug(5, "\nl.bnf relative: pc=%x pcnext=%x\n", pc, pcnext);
988
    pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
989
    btic_update(pcnext);
990
    next_delay_insn = 1;
991
  } else {
992
    btic_update(pc);
993
  }
994
}
995 123 markom
void l_j() {
996 344 markom
  debug(5, "\nl.j relative: pc=%x pcnext=%x\n", pc, pcnext);
997 221 markom
  pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
998 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
999 123 markom
  next_delay_insn = 1;
1000
}
1001
void l_jal() {
1002 344 markom
  debug(5, "\nl.jal relative: pc=%x pcnext=%x\n", pc, pcnext);
1003 221 markom
  pcdelay = pc + (signed)eval_operand32(0, &breakpoint) * 4;
1004 123 markom
 
1005 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
1006 138 markom
  set_reg32(LINK_REGNO, pc + 8);
1007 123 markom
  next_delay_insn = 1;
1008 264 markom
  if (config.sim.profile) {
1009 262 markom
    struct mem_entry *entry;
1010 221 markom
    struct label_entry *tmp;
1011 261 markom
    if (verify_memoryarea(pcdelay) && (tmp = get_label (pcdelay)))
1012 361 markom
      fprintf (runtime.sim.fprof, "+%08X %08X %08X %s\n", cycles, pc + 8, pcdelay, tmp->name);
1013 221 markom
    else
1014 361 markom
      fprintf (runtime.sim.fprof, "+%08X %08X %08X @%08X\n", cycles, pc + 8, pcdelay, pcdelay);
1015 173 markom
  }
1016 123 markom
}
1017
void l_jalr() {
1018 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
1019 221 markom
  pcdelay = eval_operand32(0, &breakpoint);
1020 138 markom
  set_reg32(LINK_REGNO, pc + 8);
1021 123 markom
  next_delay_insn = 1;
1022
}
1023
void l_jr() {
1024 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_jump;
1025 221 markom
  pcdelay = eval_operand32(0, &breakpoint);
1026 123 markom
  next_delay_insn = 1;
1027 482 markom
  if (config.sim.profile)
1028
    fprintf (runtime.sim.fprof, "-%08X %08X\n", cycles, pcdelay);
1029 123 markom
}
1030
void l_rfe() {
1031 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_exception;
1032 416 simons
  pcnext = mfspr(SPR_EPCR_BASE);
1033
  mtspr(SPR_SR, mfspr(SPR_ESR_BASE));
1034
}
1035 123 markom
void l_nop() {
1036 511 markom
  unsigned long stackaddr;
1037
  int k = eval_operand32(0, &breakpoint);
1038 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_nop;
1039 511 markom
  switch (k) {
1040
    case NOP_NOP:
1041
      break;
1042
    case NOP_EXIT:
1043 560 markom
      printf("exit(%d)\n", evalsim_reg32 (3));
1044 511 markom
      if (config.debug.gdb_enabled)
1045
        set_stall_state (1);
1046
      else
1047
        cont_run = 0;
1048
      break;
1049
    case NOP_PRINTF:
1050 560 markom
      stackaddr = evalsim_reg32(4);
1051
      simprintf(stackaddr, evalsim_reg32(3));
1052 511 markom
      debug(5, "simprintf %x\n", stackaddr);
1053
      break;
1054
    case NOP_REPORT:
1055 560 markom
      printf("report(0x%x);\n", evalsim_reg32(3));
1056 511 markom
    default:
1057
      if (k >= NOP_REPORT_FIRST && k <= NOP_REPORT_LAST)
1058 604 markom
      printf("report %i (0x%x);\n", k - NOP_REPORT_FIRST, evalsim_reg32(3));
1059 511 markom
      break;
1060
  }
1061 123 markom
}
1062
void l_sfeq() {
1063 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1064 221 markom
  flag = eval_operand32(0, &breakpoint) == eval_operand32(1, &breakpoint);
1065 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1066
}
1067 535 markom
void l_sfne() {
1068 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1069 535 markom
  flag = eval_operand32(0, &breakpoint) != eval_operand32(1, &breakpoint);
1070
  setsprbits(SPR_SR, SPR_SR_F, flag);
1071
}
1072 123 markom
void l_sfgts() {
1073 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1074 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) > (signed)eval_operand32(1, &breakpoint);
1075 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1076
}
1077
void l_sfges() {
1078 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1079 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) >= (signed)eval_operand32(1, &breakpoint);
1080 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1081
}
1082
void l_sflts() {
1083 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1084 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) < (signed)eval_operand32(1, &breakpoint);
1085 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1086
}
1087
void l_sfles() {
1088 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1089 221 markom
  flag = (signed)eval_operand32(0, &breakpoint) <= (signed)eval_operand32(1, &breakpoint);
1090 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1091
}
1092
void l_sfgtu() {
1093 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1094 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) > (unsigned)eval_operand32(1, &breakpoint);
1095 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1096
}
1097
void l_sfgeu() {
1098 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1099 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) >= (unsigned) eval_operand32(1, &breakpoint);
1100 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1101
}
1102
void l_sfltu() {
1103 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1104 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) < (unsigned)eval_operand32(1, &breakpoint);
1105 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1106
}
1107
void l_sfleu() {
1108 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_compare;
1109 221 markom
  flag = (unsigned)eval_operand32(0, &breakpoint) <= (unsigned)eval_operand32(1, &breakpoint);
1110 123 markom
  setsprbits(SPR_SR, SPR_SR_F, flag);
1111
}
1112 615 markom
void l_extbs() {
1113
  unsigned char x;
1114
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1115
  x = eval_operand32(1, &breakpoint);
1116
  set_operand32(0, (signed long)x, &breakpoint);
1117
}
1118
void l_extbz() {
1119
  unsigned char x;
1120
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1121
  x = eval_operand32(1, &breakpoint);
1122
  set_operand32(0, (unsigned long)x, &breakpoint);
1123
}
1124
void l_exths() {
1125
  unsigned short x;
1126
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1127
  x = eval_operand32(1, &breakpoint);
1128
  set_operand32(0, (signed long)x, &breakpoint);
1129
}
1130
void l_exthz() {
1131
  unsigned short x;
1132
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1133
  x = eval_operand32(1, &breakpoint);
1134
  set_operand32(0, (unsigned long)x, &breakpoint);
1135
}
1136
void l_extws() {
1137
  unsigned int x;
1138
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1139
  x = eval_operand32(1, &breakpoint);
1140
  set_operand32(0, (signed long)x, &breakpoint);
1141
}
1142
void l_extwz() {
1143
  unsigned int x;
1144
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1145
  x = eval_operand32(1, &breakpoint);
1146
  set_operand32(0, (unsigned long)x, &breakpoint);
1147
}
1148 123 markom
void l_mtspr() {
1149 641 ivang
  unsigned long regno = eval_operand32(0, &breakpoint) + eval_operand32(2, &breakpoint);
1150
  unsigned long value = eval_operand32(1, &breakpoint);
1151
 
1152
  if (runtime.sim.fspr_log) {
1153
    fprintf(runtime.sim.fspr_log, "Write to SPR  : [%08lX] <- [%08lX]\n", regno, value);
1154
  }
1155
 
1156 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1157 600 simons
  if (mfspr(SPR_SR) & SPR_SR_SM)
1158 641 ivang
    mtspr(regno, value);
1159 123 markom
  else {
1160
    printf("WARNING: trying to write SPR while SR[SUPV] is cleared.\n");
1161
    cont_run = 0;
1162
  }
1163
}
1164
void l_mfspr() {
1165 641 ivang
  unsigned long regno = eval_operand32(1, &breakpoint) + eval_operand32(2, &breakpoint);
1166
  unsigned long value = mfspr(regno);
1167
 
1168
  if (runtime.sim.fspr_log) {
1169
    fprintf(runtime.sim.fspr_log, "Read from SPR : [%08lX] -> [%08lX]\n", regno, value);
1170
  }
1171
 
1172 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1173 600 simons
  if (mfspr(SPR_SR) & SPR_SR_SM)
1174 641 ivang
    set_operand32(0, value, &breakpoint);
1175 123 markom
  else {
1176 221 markom
    set_operand32(0, 0, &breakpoint);
1177 123 markom
    printf("WARNING: trying to read SPR while SR[SUPV] is cleared.\n");
1178
    cont_run = 0;
1179
  }
1180
}
1181
void l_sys() {
1182 611 simons
  except_handle(EXCEPT_SYSCALL, mfspr(SPR_EEAR_BASE));
1183 123 markom
}
1184 142 chris
void l_trap() {
1185 479 markom
  /* TODO: some SR related code here! */
1186 611 simons
  except_handle(EXCEPT_TRAP, mfspr(SPR_EEAR_BASE));
1187 142 chris
}
1188 123 markom
void l_mac() {
1189
  sprword lo, hi;
1190
  LONGEST l;
1191 604 markom
  long x, y;
1192 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_mac;
1193 123 markom
  lo = mfspr (SPR_MACLO);
1194
  hi = mfspr (SPR_MACHI);
1195 221 markom
  x = eval_operand32(0, &breakpoint);
1196
  y = eval_operand32(1, &breakpoint);
1197 498 lampret
  printf ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));
1198 221 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
1199
  l += (LONGEST) x * (LONGEST) y;
1200 123 markom
 
1201
  /* This implementation is very fast - it needs only one cycle for mac.  */
1202 221 markom
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
1203
  hi = ((LONGEST)l) >> 32;
1204 123 markom
  mtspr (SPR_MACLO, lo);
1205
  mtspr (SPR_MACHI, hi);
1206 498 lampret
  printf ("(%08x,%08x)\n", hi, lo);
1207 123 markom
}
1208
void l_msb() {
1209 221 markom
  sprword lo, hi;
1210 123 markom
  LONGEST l;
1211 604 markom
  long x, y;
1212 558 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_mac;
1213 123 markom
  lo = mfspr (SPR_MACLO);
1214
  hi = mfspr (SPR_MACHI);
1215 604 markom
  x = eval_operand32(0, &breakpoint);
1216
  y = eval_operand32(1, &breakpoint);
1217
  printf ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));
1218 221 markom
  l = (ULONGEST)lo | ((LONGEST)hi << 32);
1219
  l -= (LONGEST) eval_operand32(0, &breakpoint) * (LONGEST)eval_operand32(1, &breakpoint);
1220 123 markom
 
1221
  /* This implementation is very fast - it needs only one cycle for msb.  */
1222 221 markom
  lo = ((ULONGEST)l) & 0xFFFFFFFF;
1223
  hi = ((LONGEST)l) >> 32;
1224 123 markom
  mtspr (SPR_MACLO, lo);
1225 221 markom
  mtspr (SPR_MACHI, hi);
1226 604 markom
  printf ("(%08x,%08x)\n", hi, lo);
1227 123 markom
}
1228
void l_macrc() {
1229
  sprword lo, hi;
1230
  LONGEST l;
1231 615 markom
  IFF (config.cpu.dependstats) cur->func_unit = it_mac;
1232 123 markom
  /* No need for synchronization here -- all MAC instructions are 1 cycle long.  */
1233
  lo =  mfspr (SPR_MACLO);
1234 221 markom
  hi =  mfspr (SPR_MACHI);
1235
  l = (ULONGEST) lo | ((LONGEST)hi << 32);
1236
  l >>= 28;
1237
  //printf ("<%08x>\n", (unsigned long)l);
1238
  set_operand32(0, (long)l, &breakpoint);
1239 123 markom
  mtspr (SPR_MACLO, 0);
1240 221 markom
  mtspr (SPR_MACHI, 0);
1241 123 markom
}
1242 615 markom
void l_cmov() {
1243
  IFF (config.cpu.dependstats) cur->func_unit = it_move;
1244
  set_operand32 (0, flag ? eval_operand32(1, &breakpoint) : eval_operand32(2, &breakpoint), &breakpoint);
1245
}
1246 174 markom
void l_cust1() {
1247
  /*int destr = cur->insn >> 21;
1248
    int src1r = cur->insn >> 15;
1249
    int src2r = cur->insn >> 9;*/
1250
}
1251
void l_cust2() {
1252
}
1253
void l_cust3() {
1254
}
1255
void l_cust4() {
1256
}
1257 123 markom
void l_invalid() {
1258 458 simons
  except_handle(EXCEPT_ILLEGAL, iqueue[0].insn_addr);
1259 123 markom
}

powered by: WebSVN 2.1.0

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