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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [cpu/] [common/] [abstract.c] - Blame information for rev 552

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jeremybenn
/* abstract.c -- Abstract entities
2
 
3
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
4
   Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
5
   Copyright (C) 2008 Embecosm Limited
6
 
7
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
   This file is part of OpenRISC 1000 Architectural Simulator.
10
 
11
   This program is free software; you can redistribute it and/or modify it
12
   under the terms of the GNU General Public License as published by the Free
13
   Software Foundation; either version 3 of the License, or (at your option)
14
   any later version.
15
 
16
   This program is distributed in the hope that it will be useful, but WITHOUT
17
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
   more details.
20
 
21
   You should have received a copy of the GNU General Public License along
22
   with this program.  If not, see <http://www.gnu.org/licenses/>. */
23
 
24
/* This program is commented throughout in a fashion suitable for processing
25
   with Doxygen. */
26
 
27
/* Abstract memory and routines that go with this. I need to add all sorts of
28
   other abstract entities. Currently we have only memory. */
29
 
30
 
31
/* Autoconf and/or portability configuration */
32
#include "config.h"
33
#include "port.h"
34
 
35
/* System includes */
36
#include <stdlib.h>
37
 
38
/* Package includes */
39
#include "abstract.h"
40
#include "except.h"
41
#include "support/profile.h"
42
#include "debug-unit.h"
43
#include "icache-model.h"
44
#include "dcache-model.h"
45
#include "labels.h"
46
#include "opcode/or32.h"
47
#include "dmmu.h"
48
#include "immu.h"
49 420 jeremybenn
#include "execute.h"
50 19 jeremybenn
 
51
/*! Global temporary variable to increase speed.  */
52
struct dev_memarea *cur_area;
53
 
54
/* Glboal variables set by MMU if cache inhibit bit is set for current
55
   access.  */
56
int  data_ci;                   /*!< Global var: data cache inhibit bit set */
57
int  insn_ci;                   /*!< Global var: instr cache inhibit bit set */
58
 
59
/* Pointer to memory area descriptions that are assigned to individual
60
   peripheral devices. */
61
static struct dev_memarea *dev_list;
62
 
63
/* Pointer to memory controller device descriptor.  */
64
static struct dev_memarea *mc_area = NULL;
65
 
66
/* Virtual address of current access. */
67
static oraddr_t cur_vadd;
68
 
69
/* Forward declarations */
70
static uint32_t eval_mem_32_inv (oraddr_t, void *);
71
static uint16_t eval_mem_16_inv (oraddr_t, void *);
72
static uint8_t  eval_mem_8_inv (oraddr_t, void *);
73
static uint32_t eval_mem_32_inv_direct (oraddr_t, void *);
74
static uint16_t eval_mem_16_inv_direct (oraddr_t, void *);
75
static uint8_t  eval_mem_8_inv_direct (oraddr_t, void *);
76
static void     set_mem_32_inv (oraddr_t, uint32_t, void *);
77
static void     set_mem_16_inv (oraddr_t, uint16_t, void *);
78
static void     set_mem_8_inv (oraddr_t, uint8_t, void *);
79
static void     set_mem_32_inv_direct (oraddr_t, uint32_t, void *);
80
static void     set_mem_16_inv_direct (oraddr_t, uint16_t, void *);
81
static void     set_mem_8_inv_direct (oraddr_t, uint8_t, void *);
82
 
83
/* Calculates bit mask to fit the data */
84
static unsigned int
85
bit_mask (uint32_t data)
86
{
87
  int i = 0;
88
  data--;
89
  while (data >> i)
90
    data |= 1 << i++;
91
  return data;
92
}
93
 
94
/* Register read and write function for a memory area.
95
   addr is inside the area, if addr & addr_mask == addr_compare
96
   (used also by peripheral devices like 16450 UART etc.) */
97
static struct dev_memarea *
98
register_memoryarea_mask (oraddr_t addr_mask,
99
                          oraddr_t addr_compare,
100
                          uint32_t size, unsigned mc_dev)
101
{
102
  struct dev_memarea **pptmp;
103
  unsigned int size_mask = bit_mask (size);
104
  int found_error = 0;
105
  addr_compare &= addr_mask;
106
 
107
  /* Go to the end of the list. */
108
  for (pptmp = &dev_list; *pptmp; pptmp = &(*pptmp)->next)
109
    if (((addr_compare >= (*pptmp)->addr_compare) &&
110
         (addr_compare < (*pptmp)->addr_compare + (*pptmp)->size)) ||
111
        ((addr_compare + size > (*pptmp)->addr_compare) &&
112
         (addr_compare < (*pptmp)->addr_compare + (*pptmp)->size)))
113
      {
114
        if (!found_error)
115
          {
116
            fprintf (stderr, "ERROR: Overlapping memory area(s):\n");
117
            fprintf (stderr,
118
                     "\taddr & %" PRIxADDR " == %" PRIxADDR " to %" PRIxADDR
119
                     ", size %08" PRIx32 "\n", addr_mask, addr_compare,
120
                     addr_compare | bit_mask (size), size);
121
          }
122
        found_error = 1;
123
        fprintf (stderr,
124
                 "and\taddr & %" PRIxADDR " == %" PRIxADDR " to %" PRIxADDR
125
                 ", size %08" PRIx32 "\n", (*pptmp)->addr_mask,
126
                 (*pptmp)->addr_compare,
127
                 (*pptmp)->addr_compare | (*pptmp)->size_mask,
128
                 (*pptmp)->size);
129
      }
130
 
131
  if (found_error)
132
    exit (-1);
133
 
134
  cur_area = *pptmp =
135
    (struct dev_memarea *) malloc (sizeof (struct dev_memarea));
136
 
137
  if (mc_dev)
138
    mc_area = *pptmp;
139
 
140
  (*pptmp)->addr_mask = addr_mask;
141
  (*pptmp)->addr_compare = addr_compare;
142
  (*pptmp)->size = size;
143
  (*pptmp)->size_mask = size_mask;
144
  (*pptmp)->log = NULL;
145
  (*pptmp)->valid = 1;
146
  (*pptmp)->next = NULL;
147
 
148
  return *pptmp;
149
}
150
 
151
/* Register read and write function for a memory area.
152
   Memory areas should be aligned. Memory area is rounded up to
153
   fit the nearest 2^n aligment.
154
   (used also by peripheral devices like 16450 UART etc.)
155
   If mc_dev is 1, this device will be checked first for a match
156
   and will be accessed in case of overlaping memory areas.
157
   Only one device can have this set to 1 (used for memory controller) */
158
struct dev_memarea *
159
reg_mem_area (oraddr_t addr, uint32_t size, unsigned mc_dev,
160
              struct mem_ops *ops)
161
{
162
  unsigned int size_mask = bit_mask (size);
163
  unsigned int addr_mask = ~size_mask;
164
  struct dev_memarea *mem;
165
 
166
  mem = register_memoryarea_mask (addr_mask, addr & addr_mask, size_mask + 1,
167
                                  mc_dev);
168
 
169
  memcpy (&mem->ops, ops, sizeof (struct mem_ops));
170
  memcpy (&mem->direct_ops, ops, sizeof (struct mem_ops));
171
 
172
  if (!ops->readfunc32)
173
    {
174
      mem->ops.readfunc32 = eval_mem_32_inv;
175
      mem->direct_ops.readfunc32 = eval_mem_32_inv_direct;
176
      mem->direct_ops.read_dat32 = mem;
177
    }
178
  if (!ops->readfunc16)
179
    {
180
      mem->ops.readfunc16 = eval_mem_16_inv;
181
      mem->direct_ops.readfunc16 = eval_mem_16_inv_direct;
182
      mem->direct_ops.read_dat16 = mem;
183
    }
184
  if (!ops->readfunc8)
185
    {
186
      mem->ops.readfunc8 = eval_mem_8_inv;
187
      mem->direct_ops.readfunc8 = eval_mem_8_inv_direct;
188
      mem->direct_ops.read_dat8 = mem;
189
    }
190
 
191
  if (!ops->writefunc32)
192
    {
193
      mem->ops.writefunc32 = set_mem_32_inv;
194
      mem->direct_ops.writefunc32 = set_mem_32_inv_direct;
195
      mem->direct_ops.write_dat32 = mem;
196
    }
197
  if (!ops->writefunc16)
198
    {
199
      mem->ops.writefunc16 = set_mem_16_inv;
200
      mem->direct_ops.writefunc16 = set_mem_16_inv_direct;
201
      mem->direct_ops.write_dat16 = mem;
202
    }
203
  if (!ops->writefunc8)
204
    {
205
      mem->ops.writefunc8 = set_mem_8_inv;
206
      mem->direct_ops.writefunc8 = set_mem_8_inv_direct;
207
      mem->direct_ops.write_dat8 = mem;
208
    }
209
 
210
  if (!ops->writeprog8)
211
    {
212
      mem->ops.writeprog8 = mem->ops.writefunc8;
213
      mem->ops.writeprog8_dat = mem->ops.write_dat8;
214
    }
215
 
216
  if (!ops->writeprog32)
217
    {
218
      mem->ops.writeprog32 = mem->ops.writefunc32;
219
      mem->ops.writeprog32_dat = mem->ops.write_dat32;
220
    }
221
 
222
  if (ops->log)
223
    {
224
      if (!(mem->log = fopen (ops->log, "w")))
225
        PRINTF ("ERR: Unable to open %s to log memory acesses to\n",
226
                ops->log);
227
    }
228
 
229
  return mem;
230
}
231
 
232
/* Check if access is to registered area of memory. */
233
struct dev_memarea *
234
verify_memoryarea (oraddr_t addr)
235
{
236
  struct dev_memarea *ptmp;
237
 
238
  /* Check memory controller space first */
239
  if (mc_area
240
      && (addr & mc_area->addr_mask) ==
241
      (mc_area->addr_compare & mc_area->addr_mask))
242 98 jeremybenn
    {
243
      return cur_area = mc_area;
244
    }
245 19 jeremybenn
 
246
  /* Check cached value */
247
  if (cur_area
248
      && (addr & cur_area->addr_mask) ==
249
      (cur_area->addr_compare & cur_area->addr_mask))
250 98 jeremybenn
    {
251
      return cur_area;
252
    }
253 19 jeremybenn
 
254
  /* When mc is enabled, we must check valid also, otherwise we assume it is
255
     nonzero */
256
  /* Check list of registered devices. */
257
  for (ptmp = dev_list; ptmp; ptmp = ptmp->next)
258 98 jeremybenn
    {
259
      if ((addr & ptmp->addr_mask) == (ptmp->addr_compare & ptmp->addr_mask)
260
          && ptmp->valid)
261
        {
262
          return cur_area = ptmp;
263
        }
264
    }
265
 
266 19 jeremybenn
  return cur_area = NULL;
267
}
268
 
269
/* Sets the valid bit (Used only by memory controllers) */
270
void
271
set_mem_valid (struct dev_memarea *mem, int valid)
272
{
273
  mem->valid = valid;
274
}
275
 
276
/* Adjusts the read and write delays for the memory area pointed to by mem. */
277
void
278
adjust_rw_delay (struct dev_memarea *mem, int delayr, int delayw)
279
{
280
  mem->ops.delayr = delayr;
281
  mem->ops.delayw = delayw;
282
}
283
 
284
static uint8_t
285
eval_mem_8_inv (oraddr_t memaddr, void *dat)
286
{
287
  except_handle (EXCEPT_BUSERR, cur_vadd);
288
  return 0;
289
}
290
 
291
static uint16_t
292
eval_mem_16_inv (oraddr_t memaddr, void *dat)
293
{
294
  except_handle (EXCEPT_BUSERR, cur_vadd);
295
  return 0;
296
}
297
 
298
static uint32_t
299
eval_mem_32_inv (oraddr_t memaddr, void *dat)
300
{
301
  except_handle (EXCEPT_BUSERR, cur_vadd);
302
  return 0;
303
}
304
 
305
static void
306
set_mem_8_inv (oraddr_t memaddr, uint8_t val, void *dat)
307
{
308
  except_handle (EXCEPT_BUSERR, cur_vadd);
309
}
310
 
311
static void
312
set_mem_16_inv (oraddr_t memaddr, uint16_t val, void *dat)
313
{
314
  except_handle (EXCEPT_BUSERR, cur_vadd);
315
}
316
 
317
static void
318
set_mem_32_inv (oraddr_t memaddr, uint32_t val, void *dat)
319
{
320
  except_handle (EXCEPT_BUSERR, cur_vadd);
321
}
322
 
323
uint8_t
324
eval_mem_8_inv_direct (oraddr_t memaddr, void *dat)
325
{
326
  struct dev_memarea *mem = dat;
327
 
328
  PRINTF ("ERROR: Invalid 8-bit direct read from memory %" PRIxADDR "\n",
329
          mem->addr_compare | memaddr);
330
  return 0;
331
}
332
 
333
uint16_t
334
eval_mem_16_inv_direct (oraddr_t memaddr, void *dat)
335
{
336
  struct dev_memarea *mem = dat;
337
 
338
  PRINTF ("ERROR: Invalid 16-bit direct read from memory %" PRIxADDR "\n",
339
          mem->addr_compare | memaddr);
340
  return 0;
341
}
342
 
343
uint32_t
344
eval_mem_32_inv_direct (oraddr_t memaddr, void *dat)
345
{
346
  struct dev_memarea *mem = dat;
347
 
348
  PRINTF ("ERROR: Invalid 32-bit direct read from memory %" PRIxADDR "\n",
349
          mem->addr_compare | memaddr);
350
  return 0;
351
}
352
 
353
void
354
set_mem_8_inv_direct (oraddr_t memaddr, uint8_t val, void *dat)
355
{
356
  struct dev_memarea *mem = dat;
357
 
358
  PRINTF ("ERROR: Invalid 32-bit direct write to memory %" PRIxADDR "\n",
359
          mem->addr_compare | memaddr);
360
}
361
 
362
void
363
set_mem_16_inv_direct (oraddr_t memaddr, uint16_t val, void *dat)
364
{
365
  struct dev_memarea *mem = dat;
366
 
367
  PRINTF ("ERROR: Invalid 16-bit direct write to memory %" PRIxADDR "\n",
368
          mem->addr_compare | memaddr);
369
}
370
 
371
void
372
set_mem_32_inv_direct (oraddr_t memaddr, uint32_t val, void *dat)
373
{
374
  struct dev_memarea *mem = dat;
375
 
376
  PRINTF ("ERROR: Invalid 32-bit direct write to memory %" PRIxADDR "\n",
377
          mem->addr_compare | memaddr);
378
}
379
 
380
/* For cpu accesses
381
 *
382
 * NOTE: This function _is_ only called from eval_mem32 below and
383
 * {i,d}c_simulate_read.  _Don't_ call it from anywere else.
384
 */
385
uint32_t
386
evalsim_mem32 (oraddr_t memaddr, oraddr_t vaddr)
387
{
388
  struct dev_memarea *mem;
389
 
390
  if ((mem = verify_memoryarea (memaddr)))
391
    {
392
      runtime.sim.mem_cycles += mem->ops.delayr;
393
      return mem->ops.readfunc32 (memaddr & mem->size_mask,
394
                                  mem->ops.read_dat32);
395
    }
396
  else
397
    {
398 220 jeremybenn
      if (config.sim.report_mem_errs)
399
        {
400
          PRINTF ("EXCEPTION: read out of memory (32-bit access to %" PRIxADDR
401
                  ")\n", memaddr);
402
        }
403
 
404 19 jeremybenn
      except_handle (EXCEPT_BUSERR, vaddr);
405
    }
406
 
407
  return 0;
408
}
409
 
410
/* For cpu accesses
411
 *
412
 * NOTE: This function _is_ only called from eval_mem16 below and
413
 * {i,d}c_simulate_read.  _Don't_ call it from anywere else.
414
 */
415
uint16_t
416
evalsim_mem16 (oraddr_t memaddr, oraddr_t vaddr)
417
{
418
  struct dev_memarea *mem;
419
 
420
  if ((mem = verify_memoryarea (memaddr)))
421
    {
422
      runtime.sim.mem_cycles += mem->ops.delayr;
423
      return mem->ops.readfunc16 (memaddr & mem->size_mask,
424
                                  mem->ops.read_dat16);
425
    }
426
  else
427
    {
428 220 jeremybenn
      if (config.sim.report_mem_errs)
429
        {
430
          PRINTF ("EXCEPTION: read out of memory (16-bit access to %" PRIxADDR
431
                  ")\n", memaddr);
432
        }
433
 
434 19 jeremybenn
      except_handle (EXCEPT_BUSERR, vaddr);
435
    }
436
 
437
  return 0;
438
}
439
 
440
/* For cpu accesses
441
 *
442
 * NOTE: This function _is_ only called from eval_mem8 below and
443
 * {i,d}c_simulate_read.  _Don't_ call it from anywere else.
444
 */
445
uint8_t
446
evalsim_mem8 (oraddr_t memaddr, oraddr_t vaddr)
447
{
448
  struct dev_memarea *mem;
449
 
450
  if ((mem = verify_memoryarea (memaddr)))
451
    {
452
      runtime.sim.mem_cycles += mem->ops.delayr;
453
      return mem->ops.readfunc8 (memaddr & mem->size_mask,
454
                                 mem->ops.read_dat8);
455
    }
456
  else
457
    {
458 220 jeremybenn
      if (config.sim.report_mem_errs)
459
        {
460
          PRINTF ("EXCEPTION: read out of memory (8-bit access to %" PRIxADDR
461
                  ")\n", memaddr);
462
        }
463
 
464 19 jeremybenn
      except_handle (EXCEPT_BUSERR, vaddr);
465
    }
466
 
467
  return 0;
468
}
469
 
470
/* Returns 32-bit values from mem array. Big endian version.
471
 *
472
 * STATISTICS OK (only used for cpu_access, that is architectural access)
473
 */
474
uint32_t
475
eval_mem32 (oraddr_t memaddr, int *breakpoint)
476
{
477
  uint32_t temp;
478
  oraddr_t phys_memaddr;
479
 
480
  if (config.sim.mprofile)
481
    mprofile (memaddr, MPROF_32 | MPROF_READ);
482
 
483
  if (memaddr & 3)
484
    {
485
      except_handle (EXCEPT_ALIGN, memaddr);
486
      return 0;
487
    }
488
 
489
  if (config.debug.enabled)
490
    *breakpoint += check_debug_unit (DebugLoadAddress, memaddr);        /* 28/05/01 CZ */
491
 
492
  phys_memaddr = dmmu_translate (memaddr, 0);
493
  if (except_pending)
494
    return 0;
495
 
496
  if (config.dc.enabled)
497
    temp = dc_simulate_read (phys_memaddr, memaddr, 4);
498
  else
499
    temp = evalsim_mem32 (phys_memaddr, memaddr);
500
 
501
  if (config.debug.enabled)
502
    *breakpoint += check_debug_unit (DebugLoadData, temp);      /* MM170901 */
503
 
504
  return temp;
505
}
506
 
507
/* for simulator accesses, the ones that cpu wouldn't do
508
 *
509
 * STATISTICS OK
510
 */
511
uint32_t
512
eval_direct32 (oraddr_t memaddr, int through_mmu, int through_dc)
513
{
514
  oraddr_t phys_memaddr;
515
  struct dev_memarea *mem;
516
 
517
  if (memaddr & 3)
518
    {
519
      PRINTF ("%s:%d %s(): ERR unaligned access\n", __FILE__, __LINE__,
520
              __FUNCTION__);
521
      return 0;
522
    }
523
 
524
  phys_memaddr = memaddr;
525
 
526
  if (through_mmu)
527
    phys_memaddr = peek_into_dtlb (memaddr, 0, through_dc);
528
 
529
  if (through_dc)
530
    return dc_simulate_read (phys_memaddr, memaddr, 4);
531
  else
532
    {
533
      if ((mem = verify_memoryarea (phys_memaddr)))
534
        return mem->direct_ops.readfunc32 (phys_memaddr & mem->size_mask,
535
                                           mem->direct_ops.read_dat32);
536
      else
537 220 jeremybenn
        fprintf (stderr, "ERR: 32-bit read out of memory area: %" PRIxADDR
538
                 " (physical: %" PRIxADDR ")\n", memaddr, phys_memaddr);
539 19 jeremybenn
    }
540
 
541
  return 0;
542
}
543
 
544
 
545
/* Returns 32-bit values from mem array. Big endian version.
546
 *
547
 * STATISTICS OK (only used for cpu_access, that is architectural access)
548
 */
549
uint32_t
550
eval_insn (oraddr_t memaddr, int *breakpoint)
551
{
552
  uint32_t temp;
553
  oraddr_t phys_memaddr;
554
 
555
  if (config.sim.mprofile)
556
    mprofile (memaddr, MPROF_32 | MPROF_FETCH);
557
 
558
  phys_memaddr = memaddr;
559
  phys_memaddr = immu_translate (memaddr);
560
 
561
  if (except_pending)
562
    return 0;
563
 
564
  if (config.debug.enabled)
565
    *breakpoint += check_debug_unit (DebugInstructionFetch, memaddr);
566
 
567
  if ((NULL != ic_state) && ic_state->enabled)
568
    temp = ic_simulate_fetch (phys_memaddr, memaddr);
569
  else
570
    temp = evalsim_mem32 (phys_memaddr, memaddr);
571
 
572
  if (config.debug.enabled)
573
    *breakpoint += check_debug_unit (DebugLoadData, temp);
574
  return temp;
575
}
576
 
577
/* Returns 16-bit values from mem array. Big endian version.
578
 *
579
 * STATISTICS OK (only used for cpu_access, that is architectural access)
580
 */
581
uint16_t
582
eval_mem16 (oraddr_t memaddr, int *breakpoint)
583
{
584
  uint16_t temp;
585
  oraddr_t phys_memaddr;
586
 
587
  if (config.sim.mprofile)
588
    mprofile (memaddr, MPROF_16 | MPROF_READ);
589
 
590
  if (memaddr & 1)
591
    {
592
      except_handle (EXCEPT_ALIGN, memaddr);
593
      return 0;
594
    }
595
 
596
  if (config.debug.enabled)
597
    *breakpoint += check_debug_unit (DebugLoadAddress, memaddr);        /* 28/05/01 CZ */
598
 
599
  phys_memaddr = dmmu_translate (memaddr, 0);
600
  if (except_pending)
601
    return 0;
602
 
603
  if (config.dc.enabled)
604
    temp = dc_simulate_read (phys_memaddr, memaddr, 2);
605
  else
606
    temp = evalsim_mem16 (phys_memaddr, memaddr);
607
 
608
  if (config.debug.enabled)
609
    *breakpoint += check_debug_unit (DebugLoadData, temp);      /* MM170901 */
610
 
611
  return temp;
612
}
613
 
614
/* for simulator accesses, the ones that cpu wouldn't do
615
 *
616
 * STATISTICS OK.
617
 */
618
uint16_t
619
eval_direct16 (oraddr_t memaddr, int through_mmu, int through_dc)
620
{
621
  oraddr_t phys_memaddr;
622
  struct dev_memarea *mem;
623
 
624
  if (memaddr & 1)
625
    {
626
      PRINTF ("%s:%d %s(): ERR unaligned access\n", __FILE__, __LINE__,
627
              __FUNCTION__);
628
      return 0;
629
    }
630
 
631
  phys_memaddr = memaddr;
632
 
633
  if (through_mmu)
634
    phys_memaddr = peek_into_dtlb (memaddr, 0, through_dc);
635
 
636
  if (through_dc)
637
    return dc_simulate_read (phys_memaddr, memaddr, 2);
638
  else
639
    {
640
      if ((mem = verify_memoryarea (phys_memaddr)))
641
        return mem->direct_ops.readfunc16 (phys_memaddr & mem->size_mask,
642
                                           mem->direct_ops.read_dat16);
643
      else
644 220 jeremybenn
        fprintf (stderr, "ERR: 16-bit read out of memory area: %" PRIxADDR
645
                 " (physical: %" PRIxADDR "\n", memaddr, phys_memaddr);
646 19 jeremybenn
    }
647
 
648
  return 0;
649
}
650
 
651
/* Returns 8-bit values from mem array.
652
 *
653
 * STATISTICS OK (only used for cpu_access, that is architectural access)
654
 */
655
uint8_t
656
eval_mem8 (oraddr_t memaddr, int *breakpoint)
657
{
658
  uint8_t temp;
659
  oraddr_t phys_memaddr;
660
 
661
  if (config.sim.mprofile)
662
    mprofile (memaddr, MPROF_8 | MPROF_READ);
663
 
664
  if (config.debug.enabled)
665
    *breakpoint += check_debug_unit (DebugLoadAddress, memaddr);        /* 28/05/01 CZ */
666
 
667
  phys_memaddr = dmmu_translate (memaddr, 0);
668
  if (except_pending)
669
    return 0;
670
 
671
  if (config.dc.enabled)
672
    temp = dc_simulate_read (phys_memaddr, memaddr, 1);
673
  else
674
    temp = evalsim_mem8 (phys_memaddr, memaddr);
675
 
676
  if (config.debug.enabled)
677
    *breakpoint += check_debug_unit (DebugLoadData, temp);      /* MM170901 */
678
  return temp;
679
}
680
 
681
/* for simulator accesses, the ones that cpu wouldn't do
682
 *
683
 * STATISTICS OK.
684
 */
685
uint8_t
686
eval_direct8 (oraddr_t memaddr, int through_mmu, int through_dc)
687
{
688
  oraddr_t phys_memaddr;
689
  struct dev_memarea *mem;
690
 
691
  phys_memaddr = memaddr;
692
 
693
  if (through_mmu)
694
    phys_memaddr = peek_into_dtlb (memaddr, 0, through_dc);
695
 
696
  if (through_dc)
697
    return dc_simulate_read (phys_memaddr, memaddr, 1);
698
  else
699
    {
700
      if ((mem = verify_memoryarea (phys_memaddr)))
701
        return mem->direct_ops.readfunc8 (phys_memaddr & mem->size_mask,
702
                                          mem->direct_ops.read_dat8);
703
      else
704 220 jeremybenn
        fprintf (stderr, "ERR: 8-bit read out of memory area: %" PRIxADDR
705
                 " (physical: %" PRIxADDR "\n", memaddr, phys_memaddr);
706 19 jeremybenn
    }
707
 
708
  return 0;
709
}
710
 
711
/* For cpu accesses
712
 *
713
 * NOTE: This function _is_ only called from set_mem32 below and
714
 * dc_simulate_write.  _Don't_ call it from anywere else.
715
 */
716
void
717
setsim_mem32 (oraddr_t memaddr, oraddr_t vaddr, uint32_t value)
718
{
719
  struct dev_memarea *mem;
720
 
721
  if ((mem = verify_memoryarea (memaddr)))
722
    {
723
      cur_vadd = vaddr;
724
      runtime.sim.mem_cycles += mem->ops.delayw;
725
      mem->ops.writefunc32 (memaddr & mem->size_mask, value,
726
                            mem->ops.write_dat32);
727
    }
728
  else
729
    {
730 220 jeremybenn
      if (config.sim.report_mem_errs)
731
        {
732
          PRINTF ("EXCEPTION: write out of memory (32-bit access to %" PRIxADDR
733
                  ")\n", memaddr);
734
        }
735
 
736 19 jeremybenn
      except_handle (EXCEPT_BUSERR, vaddr);
737
    }
738
}
739
 
740
/* For cpu accesses
741
 *
742
 * NOTE: This function _is_ only called from set_mem16 below and
743
 * dc_simulate_write.  _Don't_ call it from anywere else.
744
 */
745
void
746
setsim_mem16 (oraddr_t memaddr, oraddr_t vaddr, uint16_t value)
747
{
748
  struct dev_memarea *mem;
749
 
750
  if ((mem = verify_memoryarea (memaddr)))
751
    {
752
      cur_vadd = vaddr;
753
      runtime.sim.mem_cycles += mem->ops.delayw;
754
      mem->ops.writefunc16 (memaddr & mem->size_mask, value,
755
                            mem->ops.write_dat16);
756
    }
757
  else
758
    {
759 220 jeremybenn
      if (config.sim.report_mem_errs)
760
        {
761
          PRINTF ("EXCEPTION: write out of memory (16-bit access to %" PRIxADDR
762
                  ")\n", memaddr);
763
        }
764
 
765 19 jeremybenn
      except_handle (EXCEPT_BUSERR, vaddr);
766
    }
767
}
768
 
769
/* For cpu accesses
770
 *
771
 * NOTE: This function _is_ only called from set_mem8 below and
772
 * dc_simulate_write.  _Don't_ call it from anywere else.
773
 */
774
void
775
setsim_mem8 (oraddr_t memaddr, oraddr_t vaddr, uint8_t value)
776
{
777
  struct dev_memarea *mem;
778
 
779
  if ((mem = verify_memoryarea (memaddr)))
780
    {
781
      cur_vadd = vaddr;
782
      runtime.sim.mem_cycles += mem->ops.delayw;
783
      mem->ops.writefunc8 (memaddr & mem->size_mask, value,
784
                           mem->ops.write_dat8);
785
    }
786
  else
787
    {
788 220 jeremybenn
      if (config.sim.report_mem_errs)
789
        {
790
          PRINTF ("EXCEPTION: write out of memory (8-bit access to %" PRIxADDR
791
                  ")\n", memaddr);
792
        }
793
 
794 19 jeremybenn
      except_handle (EXCEPT_BUSERR, vaddr);
795
    }
796
}
797
 
798
/* Set mem, 32-bit. Big endian version.
799
 *
800
 * STATISTICS OK. (the only suspicious usage is in sim-cmd.c,
801
 *                 where this instruction is used for patching memory,
802
 *                 wether this is cpu or architectual access is yet to
803
 *                 be decided)
804
 */
805
void
806
set_mem32 (oraddr_t memaddr, uint32_t value, int *breakpoint)
807
{
808
  oraddr_t phys_memaddr;
809
 
810
  if (config.sim.mprofile)
811
    mprofile (memaddr, MPROF_32 | MPROF_WRITE);
812
 
813
  if (memaddr & 3)
814
    {
815
      except_handle (EXCEPT_ALIGN, memaddr);
816
      return;
817
    }
818
 
819
  phys_memaddr = dmmu_translate (memaddr, 1);;
820
  /* If we produced exception don't set anything */
821
  if (except_pending)
822
    return;
823
 
824
  if (config.debug.enabled)
825
    {
826
      *breakpoint += check_debug_unit (DebugStoreAddress, memaddr);     /* 28/05/01 CZ */
827
      *breakpoint += check_debug_unit (DebugStoreData, value);
828
    }
829
 
830
  if (config.dc.enabled)
831
    dc_simulate_write (phys_memaddr, memaddr, value, 4);
832
  else
833
    setsim_mem32 (phys_memaddr, memaddr, value);
834
 
835
  if (cur_area && cur_area->log)
836
    fprintf (cur_area->log, "[%" PRIxADDR "] -> write %08" PRIx32 "\n",
837
             memaddr, value);
838
}
839
 
840
/*
841
 * STATISTICS NOT OK.
842
 */
843
void
844
set_direct32 (oraddr_t memaddr, uint32_t value, int through_mmu,
845
              int through_dc)
846
{
847
  oraddr_t phys_memaddr;
848
  struct dev_memarea *mem;
849
 
850
  if (memaddr & 3)
851
    {
852
      PRINTF ("%s:%d %s(): ERR unaligned access\n", __FILE__, __LINE__,
853
              __FUNCTION__);
854
      return;
855
    }
856
 
857
  phys_memaddr = memaddr;
858
 
859
  if (through_mmu)
860
    {
861
      /* 0 - no write access, we do not want a DPF exception do we ;)
862
       */
863
      phys_memaddr = peek_into_dtlb (memaddr, 1, through_dc);
864
    }
865
 
866
  if (through_dc)
867
    dc_simulate_write (memaddr, memaddr, value, 4);
868
  else
869
    {
870
      if ((mem = verify_memoryarea (phys_memaddr)))
871
        mem->direct_ops.writefunc32 (phys_memaddr & mem->size_mask, value,
872
                                     mem->direct_ops.write_dat32);
873
      else
874 220 jeremybenn
        fprintf (stderr, "ERR: 32-bit write out of memory area: %" PRIxADDR
875 19 jeremybenn
                " (physical: %" PRIxADDR ")\n", memaddr, phys_memaddr);
876
    }
877
 
878
  if (cur_area && cur_area->log)
879
    fprintf (cur_area->log, "[%" PRIxADDR "] -> DIRECT write %08" PRIx32 "\n",
880
             memaddr, value);
881
}
882
 
883
 
884
/* Set mem, 16-bit. Big endian version. */
885
 
886
void
887
set_mem16 (oraddr_t memaddr, uint16_t value, int *breakpoint)
888
{
889
  oraddr_t phys_memaddr;
890
 
891
  if (config.sim.mprofile)
892
    mprofile (memaddr, MPROF_16 | MPROF_WRITE);
893
 
894
  if (memaddr & 1)
895
    {
896
      except_handle (EXCEPT_ALIGN, memaddr);
897
      return;
898
    }
899
 
900
  phys_memaddr = dmmu_translate (memaddr, 1);;
901
  /* If we produced exception don't set anything */
902
  if (except_pending)
903
    return;
904
 
905
  if (config.debug.enabled)
906
    {
907
      *breakpoint += check_debug_unit (DebugStoreAddress, memaddr);     /* 28/05/01 CZ */
908
      *breakpoint += check_debug_unit (DebugStoreData, value);
909
    }
910
 
911
  if (config.dc.enabled)
912
    dc_simulate_write (phys_memaddr, memaddr, value, 2);
913
  else
914
    setsim_mem16 (phys_memaddr, memaddr, value);
915
 
916
  if (cur_area && cur_area->log)
917
    fprintf (cur_area->log, "[%" PRIxADDR "] -> write %04" PRIx16 "\n",
918
             memaddr, value);
919
}
920
 
921
/*
922
 * STATISTICS NOT OK.
923
 */
924
void
925
set_direct16 (oraddr_t memaddr, uint16_t value, int through_mmu,
926
              int through_dc)
927
{
928
  oraddr_t phys_memaddr;
929
  struct dev_memarea *mem;
930
 
931
  if (memaddr & 1)
932
    {
933
      PRINTF ("%s:%d %s(): ERR unaligned access\n", __FILE__, __LINE__,
934
              __FUNCTION__);
935
      return;
936
    }
937
 
938
  phys_memaddr = memaddr;
939
 
940
  if (through_mmu)
941
    {
942
      /* 0 - no write access, we do not want a DPF exception do we ;)
943
       */
944
      phys_memaddr = peek_into_dtlb (memaddr, 0, through_dc);
945
    }
946
 
947
  if (through_dc)
948
    dc_simulate_write (memaddr, memaddr, value, 2);
949
  else
950
    {
951
      if ((mem = verify_memoryarea (phys_memaddr)))
952
        mem->direct_ops.writefunc16 (phys_memaddr & mem->size_mask, value,
953
                                     mem->direct_ops.write_dat16);
954
      else
955 220 jeremybenn
        fprintf (stderr, "ERR: 16-bit write out of memory area: %" PRIxADDR
956
                 " (physical: %" PRIxADDR "\n", memaddr, phys_memaddr);
957 19 jeremybenn
    }
958
 
959
  if (cur_area && cur_area->log)
960
    fprintf (cur_area->log, "[%" PRIxADDR "] -> DIRECT write %04" PRIx16 "\n",
961
             memaddr, value);
962
}
963
 
964
/* Set mem, 8-bit. */
965
void
966
set_mem8 (oraddr_t memaddr, uint8_t value, int *breakpoint)
967
{
968
  oraddr_t phys_memaddr;
969
 
970
  if (config.sim.mprofile)
971
    mprofile (memaddr, MPROF_8 | MPROF_WRITE);
972
 
973
  phys_memaddr = memaddr;
974
 
975
  phys_memaddr = dmmu_translate (memaddr, 1);;
976
  /* If we produced exception don't set anything */
977
  if (except_pending)
978
    return;
979
 
980
  if (config.debug.enabled)
981
    {
982
      *breakpoint += check_debug_unit (DebugStoreAddress, memaddr);     /* 28/05/01 CZ */
983
      *breakpoint += check_debug_unit (DebugStoreData, value);
984
    }
985
 
986
  if (config.dc.enabled)
987
    dc_simulate_write (phys_memaddr, memaddr, value, 1);
988
  else
989
    setsim_mem8 (phys_memaddr, memaddr, value);
990
 
991
  if (cur_area && cur_area->log)
992
    fprintf (cur_area->log, "[%" PRIxADDR "] -> write %02" PRIx8 "\n",
993
             memaddr, value);
994
}
995
 
996
/*
997
 * STATISTICS NOT OK.
998
 */
999
void
1000
set_direct8 (oraddr_t memaddr, uint8_t value, int through_mmu, int through_dc)
1001
{
1002
  oraddr_t phys_memaddr;
1003
  struct dev_memarea *mem;
1004
 
1005
  phys_memaddr = memaddr;
1006
 
1007
  if (through_mmu)
1008
    {
1009
      /* 0 - no write access, we do not want a DPF exception do we ;)
1010
       */
1011
      phys_memaddr = peek_into_dtlb (memaddr, 0, through_dc);
1012
    }
1013
 
1014
  if (through_dc)
1015
    dc_simulate_write (phys_memaddr, memaddr, value, 1);
1016
  else
1017
    {
1018
      if ((mem = verify_memoryarea (phys_memaddr)))
1019
        mem->direct_ops.writefunc8 (phys_memaddr & mem->size_mask, value,
1020
                                    mem->direct_ops.write_dat8);
1021
      else
1022 220 jeremybenn
        fprintf (stderr, "ERR: 8-bit write out of memory area: %" PRIxADDR
1023
                 " (physical: %" PRIxADDR "\n", memaddr, phys_memaddr);
1024 19 jeremybenn
    }
1025
 
1026
  if (cur_area && cur_area->log)
1027
    fprintf (cur_area->log, "[%" PRIxADDR "] -> DIRECT write %02" PRIx8 "\n",
1028
             memaddr, value);
1029
}
1030
 
1031
 
1032
/* set_program32 - same as set_direct32, but it also writes to memory that is
1033
 *                 non-writeable to the rest of the sim.  Used to do program
1034
 *                 loading.
1035
 */
1036
void
1037
set_program32 (oraddr_t memaddr, uint32_t value)
1038
{
1039
  struct dev_memarea *mem;
1040
 
1041
  if (memaddr & 3)
1042
    {
1043
      PRINTF ("%s(): ERR unaligned 32-bit program write\n", __FUNCTION__);
1044
      return;
1045
    }
1046
 
1047
  if ((mem = verify_memoryarea (memaddr)))
1048
    {
1049
      mem->ops.writeprog32 (memaddr & mem->size_mask, value,
1050
                            mem->ops.writeprog32_dat);
1051
    }
1052
  else
1053
    PRINTF ("ERR: 32-bit program load out of memory area: %" PRIxADDR "\n",
1054
            memaddr);
1055
}
1056
 
1057
/* set_program8 - same as set_direct8, but it also writes to memory that is
1058
 *                non-writeable to the rest of the sim.  Used to do program
1059
 *                loading.
1060
 */
1061
void
1062
set_program8 (oraddr_t memaddr, uint8_t value)
1063
{
1064
  struct dev_memarea *mem;
1065
 
1066
  if ((mem = verify_memoryarea (memaddr)))
1067
    {
1068
      mem->ops.writeprog8 (memaddr & mem->size_mask, value,
1069
                           mem->ops.writeprog8_dat);
1070
    }
1071
  else
1072
    PRINTF ("ERR: 8-bit program load out of memory area: %" PRIxADDR "\n",
1073
            memaddr);
1074
}
1075
 
1076
 
1077
/*---------------------------------------------------------------------------*/
1078
/*!Dump memory to the current output
1079
 
1080
   Output format is hex bytes, 16 bytes per line. Start each line with its
1081
   address and (optionally) its symbolic name. Always end with a newline.
1082
 
1083
   There are all sorts of ways to trip this up, but they are unlikely. The
1084
   validity of a memory area is taken from the address of the start of a line
1085
   to be printed, so assumes the following 15 bytes are present. This could be
1086
   fooled by ridiculous memory declarations.
1087
 
1088
   @param[in] from    Start address of the area of memory
1089
   @param[in] to      End address of the area of memory                      */
1090
/*---------------------------------------------------------------------------*/
1091
void
1092
dump_memory (oraddr_t from, oraddr_t to)
1093
{
1094
  const int ROW_LEN = 16;
1095
  oraddr_t i;                   /* Row counter */
1096
 
1097
  for (i = from; i < to; i += ROW_LEN)
1098
    {
1099
      struct label_entry *entry = get_label (i);
1100
      oraddr_t j;               /* Index in row */
1101
 
1102
      PRINTF ("%" PRIxADDR, i);
1103
 
1104
      if (NULL != entry)
1105
        {
1106
          int padding = 11 - strlen (entry->name);
1107
 
1108
          PRINTF (" <%s>: ", entry->name);
1109
          PRINTF ("%*s ", padding < 0 ? 0 : padding, " ");
1110
        }
1111
      else
1112
        {
1113
          PRINTF (":                ");
1114
        }
1115
 
1116
 
1117
      for (j = 0; j < ROW_LEN; j++)
1118
        {
1119
          if (verify_memoryarea (i + j))
1120
            {
1121
              PRINTF ("%02" PRIx8 " ", eval_direct8 (i + j, 0, 0));
1122
            }
1123
          else
1124
            {
1125
              /* Not a valid memory area. Print Xs as required */
1126
              PRINTF ("XX ");
1127
            }
1128
        }
1129
 
1130
      PRINTF ("\n");
1131
    }
1132
}                               /* dump_memory() */
1133
 
1134
 
1135
/*---------------------------------------------------------------------------*/
1136
/*!Disassemble memory to the current output
1137
 
1138
   Output format is symbolic disassembly, one instruction per line. Start each
1139
   line with its address and (optionally) its symbolic name.
1140
 
1141
   There are all sorts of ways to trip this up, but they are unlikely. The
1142
   validity of a memory area is taken from the address of the start of a line
1143
   to be printed, so assumes the following 3 bytes are present. This could be
1144
   fooled by ridiculous memory declarations.
1145
 
1146
   @param[in] from    Start address of the area of memory
1147
   @param[in] to      End address of the area of memory
1148
   @param[in] nl      If non-zero (true) print a newline at the end of each
1149
                      line                                                   */
1150
/*---------------------------------------------------------------------------*/
1151
void
1152
disassemble_memory (oraddr_t from, oraddr_t to, int nl)
1153
{
1154
  const int INSTR_LEN = 4;
1155
  oraddr_t i;                   /* Row counter */
1156
 
1157
  for (i = from; i < to; i += INSTR_LEN)
1158
    {
1159
      struct label_entry *entry = get_label (i);
1160
 
1161
      PRINTF ("%" PRIxADDR, i);
1162
 
1163
      if (NULL != entry)
1164
        {
1165
          int padding = 11 - strlen (entry->name);
1166
 
1167
          PRINTF (" <%s>: ", entry->name);
1168
          PRINTF ("%*s ", padding < 0 ? 0 : padding, " ");
1169
        }
1170
      else
1171
        {
1172
          PRINTF (":                ");
1173
        }
1174
 
1175
      if (verify_memoryarea (i))
1176
        {
1177
          uint32_t insn = eval_direct32 (i, 0, 0);
1178 230 jeremybenn
          int index = or1ksim_insn_decode (insn);
1179 19 jeremybenn
 
1180
          PRINTF ("%08" PRIx32 " ", insn);
1181
 
1182
          if (index >= 0)
1183
            {
1184 230 jeremybenn
              or1ksim_disassemble_insn (insn);
1185
              PRINTF (" %s", or1ksim_disassembled);
1186 19 jeremybenn
            }
1187
          else
1188
            {
1189
              PRINTF ("<invalid>");
1190
            }
1191
 
1192
        }
1193
      else
1194
        {
1195
          /* Not a valid memory area. Print Xs as required */
1196
          PRINTF ("XXXXXXXX");
1197
        }
1198
 
1199
      if (nl)
1200
        {
1201
          PRINTF ("\n");
1202
        }
1203
    }
1204 420 jeremybenn
}       /* disassemble_memory() */
1205 19 jeremybenn
 
1206
 
1207 420 jeremybenn
/*---------------------------------------------------------------------------*/
1208
/*!Trace the current instr to output
1209
 
1210
   This is a simpler form of disassemble_memory for GDB instruction tracing.
1211
 
1212
   Output format is symbolic disassembly, one instruction per line. Start each
1213 472 jeremybenn
   line with a flag to indicate supervisor or user mode then its hex address
1214
   (physical and/or virtual in that order). At the end print the value of any
1215
   destination register, the flag and the number of cycles executed.
1216 420 jeremybenn
 
1217
   There are all sorts of ways to trip this up, but they are unlikely. The
1218
   validity of a memory area is taken from the address of the start of a line
1219
   to be printed, so assumes the following 3 bytes are present. This could be
1220
   fooled by ridiculous memory declarations.
1221
 
1222 472 jeremybenn
   @param[in] phyaddr   Physical address of the instruction to trace
1223
   @param[in] virtaddr  Virtual address of the instruction to trace
1224
   @param[in] insn      The instruction just fetched and possibly executed.  */
1225 420 jeremybenn
/*---------------------------------------------------------------------------*/
1226
void
1227 472 jeremybenn
disassemble_instr (oraddr_t  phyaddr,
1228
                   oraddr_t  virtaddr,
1229
                   uint32_t  insn)
1230 420 jeremybenn
{
1231 472 jeremybenn
  /* Log whether we are supervisor mode */
1232
  printf ("%c ",
1233
          (SPR_SR_SM == (cpu_state.sprs[SPR_SR] & SPR_SR_SM)) ? 'S' : 'U');
1234
 
1235
  /* The address */
1236
  if (runtime.sim.trace_phy)
1237
    {
1238
      PRINTF ("%" PRIxADDR ": ", phyaddr);
1239
    }
1240 420 jeremybenn
 
1241 472 jeremybenn
  if (runtime.sim.trace_virt)
1242 420 jeremybenn
    {
1243 472 jeremybenn
      PRINTF ("%" PRIxADDR ": ", virtaddr);
1244
    }
1245 420 jeremybenn
 
1246 472 jeremybenn
  /* The instruction details */
1247
  int  index = or1ksim_insn_decode (insn);
1248 420 jeremybenn
 
1249 472 jeremybenn
  PRINTF ("%08" PRIx32 " ", insn);
1250
 
1251
  if (index >= 0)
1252
    {
1253
      or1ksim_disassemble_trace_index (insn, index);
1254
      PRINTF ("%-24s", or1ksim_disassembled);
1255
 
1256
      /* Put either the register assignment, SPR value, or store */
1257
      if (-1 != trace_dest_spr)
1258 420 jeremybenn
        {
1259 472 jeremybenn
          PRINTF ("SPR[%04x]  = %08x", (trace_dest_spr |
1260
                                        evalsim_reg (trace_dest_reg)),
1261
                  cpu_state.sprs[(trace_dest_spr |
1262
                                  evalsim_reg (trace_dest_reg))]);
1263 420 jeremybenn
 
1264 472 jeremybenn
        }
1265
      else if (-1 != trace_dest_reg)
1266
        {
1267
          PRINTF ("r%-2u        = %" PRIxREG "", trace_dest_reg,
1268
                  evalsim_reg (trace_dest_reg));
1269
        }
1270
      else
1271
        {
1272
          uorreg_t  store_val  = 0;
1273
          oraddr_t  store_addr = 0;
1274
 
1275
          if (0 != trace_store_width)
1276 420 jeremybenn
            {
1277 472 jeremybenn
              store_val  = evalsim_reg (trace_store_val_reg);
1278
              store_addr = evalsim_reg (trace_store_addr_reg) +
1279
                trace_store_imm;
1280 420 jeremybenn
            }
1281 472 jeremybenn
 
1282
          switch (trace_store_width)
1283 420 jeremybenn
            {
1284 472 jeremybenn
            case 1:
1285
              PRINTF ("[%" PRIxADDR "] = %02x      ", store_addr,
1286
                      store_val);
1287
              break;
1288 420 jeremybenn
 
1289 472 jeremybenn
            case 2:
1290
              PRINTF ("[%" PRIxADDR "] = %04x    ", store_addr, store_val);
1291
              break;
1292 420 jeremybenn
 
1293 472 jeremybenn
            case 4:
1294
              PRINTF ("[%" PRIxADDR "] = %08x", store_addr, store_val);
1295
              break;
1296 420 jeremybenn
 
1297 472 jeremybenn
            default:
1298
              PRINTF ("                     ");
1299
              break;
1300 420 jeremybenn
            }
1301 472 jeremybenn
        }
1302 458 julius
 
1303 420 jeremybenn
 
1304 472 jeremybenn
      /* Print the flag */
1305
      PRINTF ("  flag: %u\n", cpu_state.sprs[SPR_SR] & SPR_SR_F ? 1 : 0);
1306 420 jeremybenn
 
1307
    }
1308
  else
1309
    {
1310 472 jeremybenn
      PRINTF ("<invalid>\n");
1311 420 jeremybenn
    }
1312
}       /* disassemble_instr() */
1313
 
1314
 
1315 19 jeremybenn
/* Closes files, etc. */
1316
 
1317
void
1318
done_memory_table ()
1319
{
1320
  struct dev_memarea *ptmp;
1321
 
1322
  /* Check list of registered devices. */
1323
  for (ptmp = dev_list; ptmp; ptmp = ptmp->next)
1324
    {
1325
      if (ptmp->log)
1326
        fclose (ptmp->log);
1327
    }
1328
}
1329
 
1330
/* Displays current memory configuration */
1331
 
1332
void
1333
memory_table_status (void)
1334
{
1335
  struct dev_memarea *ptmp;
1336
 
1337
  /* Check list of registered devices. */
1338
  for (ptmp = dev_list; ptmp; ptmp = ptmp->next)
1339
    {
1340
      PRINTF ("addr & %" PRIxADDR " == %" PRIxADDR " to %" PRIxADDR ", size %"
1341
              PRIx32 "\n", ptmp->addr_mask, ptmp->addr_compare,
1342
              ptmp->addr_compare | bit_mask (ptmp->size), ptmp->size);
1343
      PRINTF ("\t");
1344
      if (ptmp->ops.delayr >= 0)
1345
        PRINTF ("read delay = %i cycles, ", ptmp->ops.delayr);
1346
      else
1347
        PRINTF ("reads not possible, ");
1348
 
1349
      if (ptmp->ops.delayw >= 0)
1350
        PRINTF ("write delay = %i cycles", ptmp->ops.delayw);
1351
      else
1352
        PRINTF ("writes not possible");
1353
 
1354
      if (ptmp->log)
1355
        PRINTF (", (logged)\n");
1356
      else
1357
        PRINTF ("\n");
1358
    }
1359
}
1360
 
1361
/* Outputs time in pretty form to dest string */
1362
 
1363
char *
1364
generate_time_pretty (char *dest, long time_ps)
1365
{
1366
  int exp3 = 0;
1367
  if (time_ps)
1368
    {
1369
      while ((time_ps % 1000) == 0)
1370
        {
1371
          time_ps /= 1000;
1372
          exp3++;
1373
        }
1374
    }
1375
  sprintf (dest, "%li%cs", time_ps, "pnum"[exp3]);
1376
  return dest;
1377
}

powered by: WebSVN 2.1.0

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