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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [cpu/] [common/] [abstract.c] - Blame information for rev 1584

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

Line No. Rev Author Line
1 2 cvs
/* abstract.c -- Abstract entities
2
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
3 1486 nogj
   Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
4 2 cvs
 
5
This file is part of OpenRISC 1000 Architectural Simulator.
6
 
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
 
21 66 lampret
/* Abstract memory and routines that go with this. I need to
22 2 cvs
add all sorts of other abstract entities. Currently we have
23
only memory. */
24
 
25 221 markom
#include <stdlib.h>
26 2 cvs
#include <stdio.h>
27
#include <ctype.h>
28
#include <string.h>
29
 
30 6 lampret
#include "config.h"
31 1350 nogj
 
32
#ifdef HAVE_INTTYPES_H
33
#include <inttypes.h>
34
#endif
35
 
36
#include "port.h"
37 6 lampret
 
38 1350 nogj
#include "arch.h"
39 2 cvs
#include "parse.h"
40
#include "abstract.h"
41 1358 nogj
#include "sim-config.h"
42 261 markom
#include "labels.h"
43 32 lampret
#include "except.h"
44 123 markom
#include "debug_unit.h"
45 134 markom
#include "opcode/or32.h"
46 1432 nogj
#include "spr_defs.h"
47
#include "execute.h"
48
#include "sprs.h"
49 547 markom
#include "support/profile.h"
50 1308 phoenix
#include "dmmu.h"
51 1446 nogj
#include "immu.h"
52 1308 phoenix
#include "dcache_model.h"
53
#include "icache_model.h"
54
#include "debug.h"
55 1344 nogj
#include "stats.h"
56 2 cvs
 
57 1452 nogj
#if DYNAMIC_EXECUTION
58
#include "dyn_rec.h"
59
#endif
60
 
61 138 markom
extern char *disassembled;
62 2 cvs
 
63 30 lampret
/* Pointer to memory area descriptions that are assigned to individual
64
   peripheral devices. */
65
struct dev_memarea *dev_list;
66
 
67 221 markom
/* Temporary variable to increase speed.  */
68
struct dev_memarea *cur_area;
69
 
70 970 simons
/* Pointer to memory controller device descriptor.  */
71 1486 nogj
struct dev_memarea *mc_area = NULL;
72 970 simons
 
73 638 simons
/* These are set by mmu if cache inhibit bit is set for current acces.  */
74
int data_ci, insn_ci;
75
 
76 525 simons
/* Virtual address of current access. */
77 1486 nogj
static oraddr_t cur_vadd;
78 525 simons
 
79 1486 nogj
/* Read functions */
80
uint32_t eval_mem_32_inv(oraddr_t, void *);
81
uint16_t eval_mem_16_inv(oraddr_t, void *);
82
uint8_t eval_mem_8_inv(oraddr_t, void *);
83
uint32_t eval_mem_32_inv_direct(oraddr_t, void *);
84
uint16_t eval_mem_16_inv_direct(oraddr_t, void *);
85
uint8_t eval_mem_8_inv_direct(oraddr_t, void *);
86
 
87
/* Write functions */
88
void set_mem_32_inv(oraddr_t, uint32_t, void *);
89
void set_mem_16_inv(oraddr_t, uint16_t, void *);
90
void set_mem_8_inv(oraddr_t, uint8_t, void *);
91
void set_mem_32_inv_direct(oraddr_t, uint32_t, void *);
92
void set_mem_16_inv_direct(oraddr_t, uint16_t, void *);
93
void set_mem_8_inv_direct(oraddr_t, uint8_t, void *);
94
 
95 261 markom
/* Calculates bit mask to fit the data */
96 1486 nogj
static unsigned int bit_mask (uint32_t data) {
97 261 markom
  int i = 0;
98
  data--;
99 382 markom
  while (data >> i)
100 261 markom
    data |= 1 << i++;
101
  return data;
102
}
103
 
104
/* Register read and write function for a memory area.
105
   addr is inside the area, if addr & addr_mask == addr_compare
106
   (used also by peripheral devices like 16450 UART etc.) */
107 1486 nogj
struct dev_memarea *register_memoryarea_mask(oraddr_t addr_mask,
108
                                             oraddr_t addr_compare,
109
                                             uint32_t size, unsigned mc_dev)
110 30 lampret
{
111 239 markom
  struct dev_memarea **pptmp;
112 1350 nogj
  unsigned int size_mask = bit_mask (size);
113 261 markom
  int found_error = 0;
114
  addr_compare &= addr_mask;
115 221 markom
 
116 1486 nogj
  debug(5, "addr & %"PRIxADDR" == %"PRIxADDR" to %"PRIxADDR", size %08"PRIx32"\n",
117
        addr_mask, addr_compare, addr_compare | bit_mask (size), size);
118 239 markom
  /* Go to the end of the list. */
119 261 markom
  for(pptmp = &dev_list; *pptmp; pptmp = &(*pptmp)->next)
120 1557 nogj
    if (((addr_compare >= (*pptmp)->addr_compare) &&
121
         (addr_compare < (*pptmp)->addr_compare + (*pptmp)->size)) ||
122
        ((addr_compare + size > (*pptmp)->addr_compare) &&
123
         (addr_compare < (*pptmp)->addr_compare + (*pptmp)->size))) {
124 262 markom
      if (!found_error) {
125 261 markom
        fprintf (stderr, "ERROR: Overlapping memory area(s):\n");
126 1350 nogj
        fprintf (stderr, "\taddr & %"PRIxADDR" == %"PRIxADDR" to %"PRIxADDR
127 1486 nogj
                         ", size %08"PRIx32"\n",
128
                 addr_mask, addr_compare, addr_compare | bit_mask (size), size);
129 262 markom
      }
130 261 markom
      found_error = 1;
131 1350 nogj
      fprintf (stderr, "and\taddr & %"PRIxADDR" == %"PRIxADDR" to %"PRIxADDR
132 1486 nogj
                       ", size %08"PRIx32"\n",
133 1308 phoenix
               (*pptmp)->addr_mask, (*pptmp)->addr_compare,
134 1486 nogj
               (*pptmp)->addr_compare | (*pptmp)->size_mask, (*pptmp)->size);
135 261 markom
    }
136
 
137
  if (found_error)
138
    exit (-1);
139 537 markom
 
140 239 markom
  cur_area = *pptmp = (struct dev_memarea *)malloc(sizeof(struct dev_memarea));
141 970 simons
 
142
  if (mc_dev)
143
    mc_area = *pptmp;
144
 
145 261 markom
  (*pptmp)->addr_mask = addr_mask;
146
  (*pptmp)->addr_compare = addr_compare;
147 239 markom
  (*pptmp)->size = size;
148 261 markom
  (*pptmp)->size_mask = size_mask;
149 1486 nogj
  (*pptmp)->log = NULL;
150
  (*pptmp)->valid = 1;
151 239 markom
  (*pptmp)->next = NULL;
152 1486 nogj
 
153
  return *pptmp;
154 261 markom
}
155 221 markom
 
156 261 markom
/* Register read and write function for a memory area.
157
   Memory areas should be aligned. Memory area is rounded up to
158
   fit the nearest 2^n aligment.
159 970 simons
   (used also by peripheral devices like 16450 UART etc.)
160 1486 nogj
   If mc_dev is 1, this device will be checked first for a match
161
   and will be accessed in case of overlaping memory areas.
162 970 simons
   Only one device can have this set to 1 (used for memory controller) */
163 1486 nogj
struct dev_memarea *reg_mem_area(oraddr_t addr, uint32_t size, unsigned mc_dev,
164
                                 struct mem_ops *ops)
165 261 markom
{
166 1350 nogj
  unsigned int size_mask = bit_mask (size);
167
  unsigned int addr_mask = ~size_mask;
168 1486 nogj
  struct dev_memarea *mem;
169
 
170
  mem = register_memoryarea_mask(addr_mask, addr & addr_mask, size_mask + 1,
171
                                 mc_dev);
172
 
173
  memcpy(&mem->ops, ops, sizeof(struct mem_ops));
174
  memcpy(&mem->direct_ops, ops, sizeof(struct mem_ops));
175
 
176
  if(!ops->readfunc32) {
177
    mem->ops.readfunc32 = eval_mem_32_inv;
178
    mem->direct_ops.readfunc32 = eval_mem_32_inv_direct;
179
    mem->direct_ops.read_dat32 = mem;
180
  }
181
  if(!ops->readfunc16) {
182
    mem->ops.readfunc16 = eval_mem_16_inv;
183
    mem->direct_ops.readfunc16 = eval_mem_16_inv_direct;
184
    mem->direct_ops.read_dat16 = mem;
185
  }
186
  if(!ops->readfunc8) {
187
    mem->ops.readfunc8 = eval_mem_8_inv;
188
    mem->direct_ops.readfunc8 = eval_mem_8_inv_direct;
189
    mem->direct_ops.read_dat8 = mem;
190
  }
191
 
192
  if(!ops->writefunc32) {
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
    mem->ops.writefunc16 = set_mem_16_inv;
199
    mem->direct_ops.writefunc16 = set_mem_16_inv_direct;
200
    mem->direct_ops.write_dat16 = mem;
201
  }
202
  if(!ops->writefunc8) {
203
    mem->ops.writefunc8 = set_mem_8_inv;
204
    mem->direct_ops.writefunc8 = set_mem_8_inv_direct;
205
    mem->direct_ops.write_dat8 = mem;
206
  }
207
 
208 1556 nogj
  if(!ops->writeprog8) {
209
    mem->ops.writeprog8 = mem->ops.writefunc8;
210
    mem->ops.writeprog8_dat = mem->ops.write_dat8;
211 1486 nogj
  }
212
 
213 1556 nogj
  if(!ops->writeprog32) {
214
    mem->ops.writeprog32 = mem->ops.writefunc32;
215
    mem->ops.writeprog32_dat = mem->ops.write_dat32;
216
  }
217
 
218 1486 nogj
  if(ops->log) {
219
    if(!(mem->log = fopen(ops->log, "w")))
220
      PRINTF("ERR: Unable to open %s to log memory acesses to\n", ops->log);
221
  }
222
 
223
  return mem;
224 30 lampret
}
225
 
226
/* Check if access is to registered area of memory. */
227 1350 nogj
inline struct dev_memarea *verify_memoryarea(oraddr_t addr)
228 30 lampret
{
229 239 markom
  struct dev_memarea *ptmp;
230 221 markom
 
231 970 simons
  /* Check memory controller space first */
232
  if (mc_area && (addr & mc_area->addr_mask) == (mc_area->addr_compare & mc_area->addr_mask))
233
    return cur_area = mc_area;
234
 
235
  /* Check cached value */
236 560 markom
  if (cur_area && (addr & cur_area->addr_mask) == (cur_area->addr_compare & cur_area->addr_mask))
237
    return cur_area;
238
 
239
  /* When mc is enabled, we must check valid also, otherwise we assume it is nonzero */
240 1375 nogj
  /* Check list of registered devices. */
241
  for(ptmp = dev_list; ptmp; ptmp = ptmp->next)
242
    if ((addr & ptmp->addr_mask) == (ptmp->addr_compare & ptmp->addr_mask) && ptmp->valid)
243
      return cur_area = ptmp;
244 239 markom
  return cur_area = NULL;
245 30 lampret
}
246
 
247 1486 nogj
/* Sets the valid bit (Used only by memory controllers) */
248
void set_mem_valid(struct dev_memarea *mem, int valid)
249 882 simons
{
250 1486 nogj
  mem->valid = valid;
251 882 simons
}
252
 
253 1486 nogj
/* Adjusts the read and write delays for the memory area pointed to by mem. */
254
void adjust_rw_delay(struct dev_memarea *mem, int delayr, int delayw)
255 560 markom
{
256 1486 nogj
  mem->ops.delayr = delayr;
257
  mem->ops.delayw = delayw;
258 1319 phoenix
}
259 560 markom
 
260 1486 nogj
uint8_t eval_mem_8_inv(oraddr_t memaddr, void *dat)
261 1319 phoenix
{
262 1486 nogj
  except_handle(EXCEPT_BUSERR, cur_vadd);
263
  return 0;
264 1319 phoenix
}
265
 
266 1486 nogj
uint16_t eval_mem_16_inv(oraddr_t memaddr, void *dat)
267 1319 phoenix
{
268 1486 nogj
  except_handle(EXCEPT_BUSERR, cur_vadd);
269
  return 0;
270
}
271 1319 phoenix
 
272 1486 nogj
uint32_t eval_mem_32_inv(oraddr_t memaddr, void *dat)
273
{
274
  except_handle(EXCEPT_BUSERR, cur_vadd);
275
  return 0;
276 560 markom
}
277
 
278 1486 nogj
void set_mem_8_inv(oraddr_t memaddr, uint8_t val, void *dat)
279 560 markom
{
280 1486 nogj
  except_handle(EXCEPT_BUSERR, cur_vadd);
281 1319 phoenix
}
282 560 markom
 
283 1486 nogj
void set_mem_16_inv(oraddr_t memaddr, uint16_t val, void *dat)
284 1319 phoenix
{
285 1486 nogj
  except_handle(EXCEPT_BUSERR, cur_vadd);
286 1319 phoenix
}
287
 
288 1486 nogj
void set_mem_32_inv(oraddr_t memaddr, uint32_t val, void *dat)
289 1319 phoenix
{
290 1486 nogj
  except_handle(EXCEPT_BUSERR, cur_vadd);
291
}
292 1319 phoenix
 
293 1486 nogj
uint8_t eval_mem_8_inv_direct(oraddr_t memaddr, void *dat)
294
{
295
  struct dev_memarea *mem = dat;
296
 
297
  PRINTF("ERROR: Invalid 8-bit direct read from memory %"PRIxADDR"\n",
298
         mem->addr_compare | memaddr);
299
  return 0;
300 560 markom
}
301
 
302 1486 nogj
uint16_t eval_mem_16_inv_direct(oraddr_t memaddr, void *dat)
303 560 markom
{
304 1486 nogj
  struct dev_memarea *mem = dat;
305
 
306
  PRINTF("ERROR: Invalid 16-bit direct read from memory %"PRIxADDR"\n",
307
         mem->addr_compare | memaddr);
308
  return 0;
309 1319 phoenix
}
310 560 markom
 
311 1486 nogj
uint32_t eval_mem_32_inv_direct(oraddr_t memaddr, void *dat)
312 1319 phoenix
{
313 1486 nogj
  struct dev_memarea *mem = dat;
314
 
315
  PRINTF("ERROR: Invalid 32-bit direct read from memory %"PRIxADDR"\n",
316
         mem->addr_compare | memaddr);
317
  return 0;
318 1319 phoenix
}
319
 
320 1486 nogj
void set_mem_8_inv_direct(oraddr_t memaddr, uint8_t val, void *dat)
321 1319 phoenix
{
322 1486 nogj
  struct dev_memarea *mem = dat;
323 1319 phoenix
 
324 1486 nogj
  PRINTF("ERROR: Invalid 32-bit direct write to memory %"PRIxADDR"\n",
325
         mem->addr_compare | memaddr);
326
}
327
 
328
void set_mem_16_inv_direct(oraddr_t memaddr, uint16_t val, void *dat)
329
{
330
  struct dev_memarea *mem = dat;
331
 
332
  PRINTF("ERROR: Invalid 16-bit direct write to memory %"PRIxADDR"\n",
333
         mem->addr_compare | memaddr);
334
}
335
 
336
void set_mem_32_inv_direct(oraddr_t memaddr, uint32_t val, void *dat)
337
{
338
  struct dev_memarea *mem = dat;
339
 
340
  PRINTF("ERROR: Invalid 32-bit direct write to memory %"PRIxADDR"\n",
341
         mem->addr_compare | memaddr);
342
}
343
 
344
/* For cpu accesses
345
 *
346
 * NOTE: This function _is_ only called from eval_mem32 below and
347
 * {i,d}c_simulate_read.  _Don't_ call it from anywere else.
348
 */
349
inline uint32_t evalsim_mem32(oraddr_t memaddr, oraddr_t vaddr)
350
{
351
  struct dev_memarea *mem;
352
 
353
  if((mem = verify_memoryarea(memaddr))) {
354
    runtime.sim.mem_cycles += mem->ops.delayr;
355
    return mem->ops.readfunc32(memaddr & mem->size_mask, mem->ops.read_dat32);
356
  } else {
357
    PRINTF("EXCEPTION: read out of memory (32-bit access to %"PRIxADDR")\n",
358
           memaddr);
359
    except_handle(EXCEPT_BUSERR, vaddr);
360 560 markom
  }
361 1486 nogj
 
362
  return 0;
363 560 markom
}
364
 
365 1486 nogj
/* For cpu accesses
366
 *
367
 * NOTE: This function _is_ only called from eval_mem16 below and
368
 * {i,d}c_simulate_read.  _Don't_ call it from anywere else.
369
 */
370
inline uint16_t evalsim_mem16(oraddr_t memaddr, oraddr_t vaddr)
371
{
372
  struct dev_memarea *mem;
373
 
374
  if((mem = verify_memoryarea(memaddr))) {
375
    runtime.sim.mem_cycles += mem->ops.delayr;
376
    return mem->ops.readfunc16(memaddr & mem->size_mask, mem->ops.read_dat16);
377
  } else {
378
    PRINTF("EXCEPTION: read out of memory (16-bit access to %"PRIxADDR")\n",
379
           memaddr);
380
    except_handle(EXCEPT_BUSERR, vaddr);
381
  }
382
 
383
  return 0;
384
}
385
 
386
/* For cpu accesses
387
 *
388
 * NOTE: This function _is_ only called from eval_mem8 below and
389
 * {i,d}c_simulate_read.  _Don't_ call it from anywere else.
390
 */
391
inline uint8_t evalsim_mem8(oraddr_t memaddr, oraddr_t vaddr)
392
{
393
  struct dev_memarea *mem;
394
 
395
  if((mem = verify_memoryarea(memaddr))) {
396
    runtime.sim.mem_cycles += mem->ops.delayr;
397
    return mem->ops.readfunc8(memaddr & mem->size_mask, mem->ops.read_dat8);
398
  } else {
399
    PRINTF("EXCEPTION: read out of memory (8-bit access to %"PRIxADDR")\n",
400
           memaddr);
401
    except_handle(EXCEPT_BUSERR, vaddr);
402
  }
403
 
404
  return 0;
405
}
406
 
407 1319 phoenix
/* Returns 32-bit values from mem array. Big endian version.
408
 *
409
 * STATISTICS OK (only used for cpu_access, that is architectural access)
410
 */
411 1350 nogj
uint32_t eval_mem32(oraddr_t memaddr,int* breakpoint)
412 2 cvs
{
413 1350 nogj
  uint32_t temp;
414 1486 nogj
  oraddr_t phys_memaddr;
415 123 markom
 
416 547 markom
  if (config.sim.mprofile)
417
    mprofile (memaddr, MPROF_32 | MPROF_READ);
418
 
419 538 markom
  if (memaddr & 3) {
420
    except_handle (EXCEPT_ALIGN, memaddr);
421
    return 0;
422
  }
423 557 markom
 
424 631 simons
  if (config.debug.enabled)
425
    *breakpoint += CheckDebugUnit(DebugLoadAddress,memaddr); /* 28/05/01 CZ */
426
 
427 1486 nogj
  phys_memaddr = dmmu_translate(memaddr, 0);
428 1386 nogj
  if (except_pending)
429 574 markom
    return 0;
430
 
431 992 simons
  if (config.dc.enabled)
432 1486 nogj
    temp = dc_simulate_read(phys_memaddr, memaddr, 4);
433
  else
434
    temp = evalsim_mem32(phys_memaddr, memaddr);
435 611 simons
 
436 550 markom
  if (config.debug.enabled)
437 270 markom
    *breakpoint += CheckDebugUnit(DebugLoadData,temp);  /* MM170901 */
438 1486 nogj
 
439 239 markom
  return temp;
440 66 lampret
}
441
 
442 1319 phoenix
/* for simulator accesses, the ones that cpu wouldn't do
443
 *
444
 * STATISTICS OK
445
 */
446 1487 nogj
uint32_t eval_direct32(oraddr_t memaddr, int through_mmu, int through_dc)
447 1240 phoenix
{
448 1486 nogj
  oraddr_t phys_memaddr;
449
  struct dev_memarea *mem;
450 1240 phoenix
 
451
  if (memaddr & 3) {
452
    PRINTF("%s:%d %s(): ERR unaligned access\n", __FILE__, __LINE__, __FUNCTION__);
453 1486 nogj
    return 0;
454 1240 phoenix
  }
455
 
456 1486 nogj
  phys_memaddr = memaddr;
457 1240 phoenix
 
458
  if (through_mmu)
459 1486 nogj
    phys_memaddr = peek_into_dtlb(memaddr, 0, through_dc);
460 1240 phoenix
 
461
  if (through_dc)
462 1486 nogj
    return dc_simulate_read(phys_memaddr, memaddr, 4);
463 1240 phoenix
  else {
464 1486 nogj
    if((mem = verify_memoryarea(phys_memaddr)))
465
      return mem->direct_ops.readfunc32(phys_memaddr & mem->size_mask,
466
                                        mem->direct_ops.read_dat32);
467
    else
468
      PRINTF("ERR: 32-bit read out of memory area: %"PRIxADDR" (physical: %"
469
             PRIxADDR"\n", memaddr, phys_memaddr);
470 1240 phoenix
  }
471
 
472 1486 nogj
  return 0;
473 1240 phoenix
}
474
 
475
 
476 1319 phoenix
/* Returns 32-bit values from mem array. Big endian version.
477
 *
478
 * STATISTICS OK (only used for cpu_access, that is architectural access)
479
 */
480 1386 nogj
uint32_t eval_insn(oraddr_t memaddr, int* breakpoint)
481 349 simons
{
482 1350 nogj
  uint32_t temp;
483 1486 nogj
  oraddr_t phys_memaddr;
484 349 simons
 
485 547 markom
  if (config.sim.mprofile)
486
    mprofile (memaddr, MPROF_32 | MPROF_FETCH);
487 532 markom
//  memaddr = simulate_ic_mmu_fetch(memaddr);
488 1244 hpanther
 
489 1486 nogj
  phys_memaddr = memaddr;
490 1452 nogj
#if !(DYNAMIC_EXECUTION)
491 1486 nogj
  phys_memaddr = immu_translate(memaddr);
492 1386 nogj
 
493
  if (except_pending)
494
    return 0;
495 1452 nogj
#endif
496 1386 nogj
 
497
  if (config.debug.enabled)
498
    *breakpoint += CheckDebugUnit(DebugLoadAddress,memaddr);
499
 
500 631 simons
  if (config.ic.enabled)
501 1486 nogj
    temp = ic_simulate_fetch(phys_memaddr, memaddr);
502
  else
503
    temp = evalsim_mem32(phys_memaddr, memaddr);
504 611 simons
 
505 1386 nogj
  if (config.debug.enabled)
506
    *breakpoint += CheckDebugUnit(DebugLoadData,temp);
507 349 simons
  return temp;
508
}
509
 
510 1452 nogj
/* Returns 32-bit values from mem array. Big endian version.
511
 *
512
 * STATISTICS OK
513
 */
514 1487 nogj
uint32_t eval_insn_direct(oraddr_t memaddr, int through_mmu)
515 1452 nogj
{
516
  if(through_mmu)
517
    memaddr = peek_into_itlb(memaddr);
518
 
519 1487 nogj
  return eval_direct32(memaddr, 0, 0);
520 1452 nogj
}
521
 
522
 
523 1319 phoenix
/* Returns 16-bit values from mem array. Big endian version.
524
 *
525
 * STATISTICS OK (only used for cpu_access, that is architectural access)
526
 */
527 1350 nogj
uint16_t eval_mem16(oraddr_t memaddr,int* breakpoint)
528 2 cvs
{
529 1350 nogj
  uint16_t temp;
530 1486 nogj
  oraddr_t phys_memaddr;
531 547 markom
 
532
  if (config.sim.mprofile)
533
    mprofile (memaddr, MPROF_16 | MPROF_READ);
534
 
535 538 markom
  if (memaddr & 1) {
536
    except_handle (EXCEPT_ALIGN, memaddr);
537
    return 0;
538
  }
539 574 markom
 
540 631 simons
  if (config.debug.enabled)
541
    *breakpoint += CheckDebugUnit(DebugLoadAddress,memaddr); /* 28/05/01 CZ */
542
 
543 1486 nogj
  phys_memaddr = dmmu_translate(memaddr, 0);
544 1386 nogj
  if (except_pending)
545 574 markom
    return 0;
546 66 lampret
 
547 992 simons
  if (config.dc.enabled)
548 1486 nogj
    temp = dc_simulate_read(phys_memaddr, memaddr, 2);
549
  else
550
    temp = evalsim_mem16(phys_memaddr, memaddr);
551 611 simons
 
552 550 markom
  if (config.debug.enabled)
553 270 markom
    *breakpoint += CheckDebugUnit(DebugLoadData,temp);  /* MM170901 */
554 1486 nogj
 
555 239 markom
  return temp;
556 66 lampret
}
557
 
558 1319 phoenix
/* for simulator accesses, the ones that cpu wouldn't do
559
 *
560
 * STATISTICS OK.
561
 */
562 1487 nogj
uint16_t eval_direct16(oraddr_t memaddr, int through_mmu, int through_dc)
563 1240 phoenix
{
564 1486 nogj
  oraddr_t phys_memaddr;
565
  struct dev_memarea *mem;
566 1240 phoenix
 
567 1324 phoenix
  if (memaddr & 1) {
568 1240 phoenix
    PRINTF("%s:%d %s(): ERR unaligned access\n", __FILE__, __LINE__, __FUNCTION__);
569 1486 nogj
    return 0;
570 1240 phoenix
  }
571
 
572 1486 nogj
  phys_memaddr = memaddr;
573 1240 phoenix
 
574
  if (through_mmu)
575 1486 nogj
    phys_memaddr = peek_into_dtlb(memaddr, 0, through_dc);
576 1240 phoenix
 
577
  if (through_dc)
578 1486 nogj
    return dc_simulate_read(phys_memaddr, memaddr, 2);
579 1240 phoenix
  else {
580 1486 nogj
    if((mem = verify_memoryarea(phys_memaddr)))
581
      return mem->direct_ops.readfunc16(phys_memaddr & mem->size_mask,
582
                                        mem->direct_ops.read_dat16);
583
    else
584
      PRINTF("ERR: 16-bit read out of memory area: %"PRIxADDR" (physical: %"
585
             PRIxADDR"\n", memaddr, phys_memaddr);
586 1240 phoenix
  }
587
 
588 1486 nogj
  return 0;
589 1240 phoenix
}
590
 
591 1319 phoenix
/* Returns 8-bit values from mem array.
592
 *
593
 * STATISTICS OK (only used for cpu_access, that is architectural access)
594
 */
595 1350 nogj
uint8_t eval_mem8(oraddr_t memaddr,int* breakpoint)
596 221 markom
{
597 1350 nogj
  uint8_t temp;
598 1486 nogj
  oraddr_t phys_memaddr;
599 547 markom
 
600
  if (config.sim.mprofile)
601
    mprofile (memaddr, MPROF_8 | MPROF_READ);
602
 
603 631 simons
  if (config.debug.enabled)
604
    *breakpoint += CheckDebugUnit(DebugLoadAddress,memaddr);  /* 28/05/01 CZ */
605
 
606 1486 nogj
  phys_memaddr = dmmu_translate(memaddr, 0);
607 1386 nogj
  if (except_pending)
608 458 simons
    return 0;
609 6 lampret
 
610 992 simons
  if (config.dc.enabled)
611 1486 nogj
    temp = dc_simulate_read(phys_memaddr, memaddr, 1);
612
  else
613
    temp = evalsim_mem8(phys_memaddr, memaddr);
614 611 simons
 
615 550 markom
  if (config.debug.enabled)
616 270 markom
    *breakpoint += CheckDebugUnit(DebugLoadData,temp);  /* MM170901 */
617 239 markom
  return temp;
618 66 lampret
}
619
 
620 1319 phoenix
/* for simulator accesses, the ones that cpu wouldn't do
621
 *
622
 * STATISTICS OK.
623
 */
624 1487 nogj
uint8_t eval_direct8(oraddr_t memaddr, int through_mmu, int through_dc)
625 1240 phoenix
{
626 1486 nogj
  oraddr_t phys_memaddr;
627
  struct dev_memarea *mem;
628 1240 phoenix
 
629 1486 nogj
  phys_memaddr = memaddr;
630 1240 phoenix
 
631
  if (through_mmu)
632 1486 nogj
    phys_memaddr = peek_into_dtlb(memaddr, 0, through_dc);
633 1240 phoenix
 
634
  if (through_dc)
635 1486 nogj
    return dc_simulate_read(phys_memaddr, memaddr, 1);
636 1240 phoenix
  else {
637 1486 nogj
    if((mem = verify_memoryarea(phys_memaddr)))
638
      return mem->direct_ops.readfunc8(phys_memaddr & mem->size_mask,
639
                                       mem->direct_ops.read_dat8);
640
    else
641
      PRINTF("ERR: 8-bit read out of memory area: %"PRIxADDR" (physical: %"
642
             PRIxADDR"\n", memaddr, phys_memaddr);
643 1240 phoenix
  }
644
 
645 1486 nogj
  return 0;
646 1319 phoenix
}
647 1240 phoenix
 
648 1486 nogj
/* For cpu accesses
649
 *
650
 * NOTE: This function _is_ only called from set_mem32 below and
651
 * dc_simulate_write.  _Don't_ call it from anywere else.
652
 */
653
inline void setsim_mem32(oraddr_t memaddr, oraddr_t vaddr, uint32_t value)
654 66 lampret
{
655 1486 nogj
  struct dev_memarea *mem;
656 1319 phoenix
 
657 1486 nogj
  if((mem = verify_memoryarea(memaddr))) {
658
    cur_vadd = vaddr;
659
    runtime.sim.mem_cycles += mem->ops.delayw;
660
    mem->ops.writefunc32(memaddr & mem->size_mask, value, mem->ops.write_dat32);
661 1452 nogj
#if DYNAMIC_EXECUTION
662 1486 nogj
    dyn_checkwrite(memaddr);
663 1452 nogj
#endif
664 239 markom
  } else {
665 1350 nogj
    PRINTF("EXCEPTION: write out of memory (32-bit access to %"PRIxADDR")\n",
666
           memaddr);
667 1486 nogj
    except_handle(EXCEPT_BUSERR, vaddr);
668 239 markom
  }
669 2 cvs
}
670
 
671 1486 nogj
/* For cpu accesses
672
 *
673
 * NOTE: This function _is_ only called from set_mem16 below and
674
 * dc_simulate_write.  _Don't_ call it from anywere else.
675
 */
676
inline void setsim_mem16(oraddr_t memaddr, oraddr_t vaddr, uint16_t value)
677 66 lampret
{
678 1486 nogj
  struct dev_memarea *mem;
679 1319 phoenix
 
680 1486 nogj
  if((mem = verify_memoryarea(memaddr))) {
681
    cur_vadd = vaddr;
682
    runtime.sim.mem_cycles += mem->ops.delayw;
683
    mem->ops.writefunc16(memaddr & mem->size_mask, value, mem->ops.write_dat16);
684 1452 nogj
#if DYNAMIC_EXECUTION
685 1486 nogj
    dyn_checkwrite(memaddr);
686 1452 nogj
#endif
687 239 markom
  } else {
688 1350 nogj
    PRINTF("EXCEPTION: write out of memory (16-bit access to %"PRIxADDR")\n",
689
           memaddr);
690 1486 nogj
    except_handle(EXCEPT_BUSERR, vaddr);
691 239 markom
  }
692 2 cvs
}
693
 
694 1486 nogj
/* For cpu accesses
695
 *
696
 * NOTE: This function _is_ only called from set_mem8 below and
697
 * dc_simulate_write.  _Don't_ call it from anywere else.
698
 */
699
inline void setsim_mem8(oraddr_t memaddr, oraddr_t vaddr, uint8_t value)
700 66 lampret
{
701 1486 nogj
  struct dev_memarea *mem;
702 1319 phoenix
 
703 1486 nogj
  if((mem = verify_memoryarea(memaddr))) {
704
    cur_vadd = vaddr;
705
    runtime.sim.mem_cycles += mem->ops.delayw;
706
    mem->ops.writefunc8(memaddr & mem->size_mask, value, mem->ops.write_dat8);
707 1452 nogj
#if DYNAMIC_EXECUTION
708 1486 nogj
    dyn_checkwrite(memaddr);
709 1452 nogj
#endif
710 239 markom
  } else {
711 1350 nogj
    PRINTF("EXCEPTION: write out of memory (8-bit access to %"PRIxADDR")\n",
712
           memaddr);
713 1486 nogj
    except_handle(EXCEPT_BUSERR, vaddr);
714 239 markom
  }
715 2 cvs
}
716 30 lampret
 
717 1319 phoenix
/* Set mem, 32-bit. Big endian version.
718
 *
719 1446 nogj
 * STATISTICS OK. (the only suspicious usage is in sim-cmd.c,
720 1319 phoenix
 *                 where this instruction is used for patching memory,
721
 *                 wether this is cpu or architectual access is yet to
722
 *                 be decided)
723
 */
724 1350 nogj
void set_mem32(oraddr_t memaddr, uint32_t value, int* breakpoint)
725 587 markom
{
726 1486 nogj
  oraddr_t phys_memaddr;
727
 
728 587 markom
  if (config.sim.mprofile)
729
    mprofile (memaddr, MPROF_32 | MPROF_WRITE);
730
 
731
  if (memaddr & 3) {
732
    except_handle (EXCEPT_ALIGN, memaddr);
733
    return;
734
  }
735
 
736 1486 nogj
  phys_memaddr = dmmu_translate(memaddr, 1);;
737 587 markom
  /* If we produced exception don't set anything */
738 1386 nogj
  if (except_pending)
739 587 markom
    return;
740
 
741
  if (config.debug.enabled) {
742
    *breakpoint += CheckDebugUnit(DebugStoreAddress,memaddr);  /* 28/05/01 CZ */
743
    *breakpoint += CheckDebugUnit(DebugStoreData,value);
744
  }
745
 
746 1486 nogj
  if(config.dc.enabled)
747
    dc_simulate_write(phys_memaddr, memaddr, value, 4);
748
  else
749
    setsim_mem32(phys_memaddr, memaddr, value);
750 992 simons
 
751 1218 phoenix
  if (cur_area && cur_area->log)
752 1350 nogj
    fprintf (cur_area->log, "[%"PRIxADDR"] -> write %08"PRIx32"\n", memaddr,
753
             value);
754 587 markom
}
755
 
756 1319 phoenix
/*
757
 * STATISTICS NOT OK.
758
 */
759 1487 nogj
void set_direct32(oraddr_t memaddr, uint32_t value, int through_mmu,
760
                  int through_dc)
761 1240 phoenix
{
762 1486 nogj
  oraddr_t phys_memaddr;
763
  struct dev_memarea *mem;
764 1240 phoenix
 
765
  if (memaddr & 3) {
766
    PRINTF("%s:%d %s(): ERR unaligned access\n", __FILE__, __LINE__, __FUNCTION__);
767
    return;
768
  }
769
 
770 1486 nogj
  phys_memaddr = memaddr;
771 1240 phoenix
 
772
  if (through_mmu) {
773
    /* 0 - no write access, we do not want a DPF exception do we ;)
774
     */
775 1486 nogj
    phys_memaddr = peek_into_dtlb(memaddr, 1, through_dc);
776 1240 phoenix
  }
777
 
778 1486 nogj
  if(through_dc)
779
    dc_simulate_write(memaddr, memaddr, value, 4);
780
  else {
781
    if((mem = verify_memoryarea(phys_memaddr)))
782
      mem->direct_ops.writefunc32(phys_memaddr & mem->size_mask, value,
783
                                  mem->direct_ops.write_dat32);
784
    else
785
      PRINTF("ERR: 32-bit write out of memory area: %"PRIxADDR" (physical: %"
786
             PRIxADDR")\n", memaddr, phys_memaddr);
787
  }
788 1240 phoenix
 
789
  if (cur_area && cur_area->log)
790 1350 nogj
    fprintf (cur_area->log, "[%"PRIxADDR"] -> DIRECT write %08"PRIx32"\n",
791
             memaddr, value);
792 1240 phoenix
}
793
 
794
 
795 587 markom
/* Set mem, 16-bit. Big endian version. */
796
 
797 1350 nogj
void set_mem16(oraddr_t memaddr, uint16_t value, int* breakpoint)
798 587 markom
{
799 1486 nogj
  oraddr_t phys_memaddr;
800
 
801 587 markom
  if (config.sim.mprofile)
802
    mprofile (memaddr, MPROF_16 | MPROF_WRITE);
803
 
804
  if (memaddr & 1) {
805
    except_handle (EXCEPT_ALIGN, memaddr);
806
    return;
807
  }
808
 
809 1486 nogj
  phys_memaddr = dmmu_translate(memaddr, 1);;
810 587 markom
  /* If we produced exception don't set anything */
811 1386 nogj
  if (except_pending)
812 587 markom
    return;
813
 
814
  if (config.debug.enabled) {
815
    *breakpoint += CheckDebugUnit(DebugStoreAddress,memaddr);  /* 28/05/01 CZ */
816
    *breakpoint += CheckDebugUnit(DebugStoreData,value);
817
  }
818
 
819 1486 nogj
  if(config.dc.enabled)
820
    dc_simulate_write(phys_memaddr, memaddr, value, 2);
821
  else
822
    setsim_mem16(phys_memaddr, memaddr, value);
823 992 simons
 
824 1218 phoenix
  if (cur_area && cur_area->log)
825 1350 nogj
    fprintf (cur_area->log, "[%"PRIxADDR"] -> write %04"PRIx16"\n", memaddr,
826
             value);
827 587 markom
}
828
 
829 1319 phoenix
/*
830
 * STATISTICS NOT OK.
831
 */
832 1487 nogj
void set_direct16(oraddr_t memaddr, uint16_t value, int through_mmu,
833
                  int through_dc)
834 1240 phoenix
{
835 1486 nogj
  oraddr_t phys_memaddr;
836
  struct dev_memarea *mem;
837 1240 phoenix
 
838 1324 phoenix
  if (memaddr & 1) {
839 1240 phoenix
    PRINTF("%s:%d %s(): ERR unaligned access\n", __FILE__, __LINE__, __FUNCTION__);
840
    return;
841
  }
842
 
843 1486 nogj
  phys_memaddr = memaddr;
844 1240 phoenix
 
845
  if (through_mmu) {
846
    /* 0 - no write access, we do not want a DPF exception do we ;)
847
     */
848 1486 nogj
    phys_memaddr = peek_into_dtlb(memaddr, 0, through_dc);
849 1240 phoenix
  }
850
 
851 1486 nogj
  if(through_dc)
852
    dc_simulate_write(memaddr, memaddr, value, 2);
853
  else {
854
    if((mem = verify_memoryarea(phys_memaddr)))
855
      mem->direct_ops.writefunc16(phys_memaddr & mem->size_mask, value,
856
                                  mem->direct_ops.write_dat16);
857
    else
858
      PRINTF("ERR: 16-bit write out of memory area: %"PRIxADDR" (physical: %"
859
             PRIxADDR"\n", memaddr, phys_memaddr);
860
  }
861 1240 phoenix
 
862
  if (cur_area && cur_area->log)
863 1350 nogj
    fprintf (cur_area->log, "[%"PRIxADDR"] -> DIRECT write %04"PRIx16"\n",
864
             memaddr, value);
865 1240 phoenix
}
866
 
867 587 markom
/* Set mem, 8-bit. */
868 1350 nogj
void set_mem8(oraddr_t memaddr, uint8_t value, int* breakpoint)
869 587 markom
{
870 1486 nogj
  oraddr_t phys_memaddr;
871
 
872 587 markom
  if (config.sim.mprofile)
873
    mprofile (memaddr, MPROF_8 | MPROF_WRITE);
874
 
875 1486 nogj
  phys_memaddr = memaddr;
876
 
877
  phys_memaddr = dmmu_translate(memaddr, 1);;
878 587 markom
  /* If we produced exception don't set anything */
879 1386 nogj
  if (except_pending) return;
880 587 markom
 
881
  if (config.debug.enabled) {
882
    *breakpoint += CheckDebugUnit(DebugStoreAddress,memaddr);  /* 28/05/01 CZ */
883
    *breakpoint += CheckDebugUnit(DebugStoreData,value);
884
  }
885
 
886 1486 nogj
  if(config.dc.enabled)
887
    dc_simulate_write(phys_memaddr, memaddr, value, 1);
888
  else
889
    setsim_mem8(phys_memaddr, memaddr, value);
890 992 simons
 
891 1218 phoenix
  if (cur_area && cur_area->log)
892 1350 nogj
    fprintf (cur_area->log, "[%"PRIxADDR"] -> write %02"PRIx8"\n", memaddr,
893
             value);
894 587 markom
}
895
 
896 1319 phoenix
/*
897
 * STATISTICS NOT OK.
898
 */
899 1487 nogj
void set_direct8(oraddr_t memaddr, uint8_t value, int through_mmu,
900
                 int through_dc)
901 1240 phoenix
{
902 1486 nogj
  oraddr_t phys_memaddr;
903
  struct dev_memarea *mem;
904 1240 phoenix
 
905 1486 nogj
  phys_memaddr = memaddr;
906 1240 phoenix
 
907
  if (through_mmu) {
908
    /* 0 - no write access, we do not want a DPF exception do we ;)
909
     */
910 1486 nogj
    phys_memaddr = peek_into_dtlb(memaddr, 0, through_dc);
911 1240 phoenix
  }
912
 
913 1486 nogj
  if(through_dc)
914
    dc_simulate_write(phys_memaddr, memaddr, value, 1);
915
  else {
916
    if((mem = verify_memoryarea(phys_memaddr)))
917
      mem->direct_ops.writefunc8(phys_memaddr & mem->size_mask, value,
918
                                 mem->direct_ops.write_dat8);
919
    else
920
      PRINTF("ERR: 8-bit write out of memory area: %"PRIxADDR" (physical: %"
921
             PRIxADDR"\n", memaddr, phys_memaddr);
922
  }
923 1240 phoenix
 
924
  if (cur_area && cur_area->log)
925 1350 nogj
    fprintf (cur_area->log, "[%"PRIxADDR"] -> DIRECT write %02"PRIx8"\n",
926
             memaddr, value);
927 1240 phoenix
}
928
 
929
 
930 1486 nogj
/* set_program32 - same as set_direct32, but it also writes to memory that is
931
 *                 non-writeable to the rest of the sim.  Used to do program
932
 *                 loading.
933
 */
934
void set_program32(oraddr_t memaddr, uint32_t value)
935
{
936
  struct dev_memarea *mem;
937
 
938 1556 nogj
  if(memaddr & 3) {
939
    PRINTF("%s(): ERR unaligned 32-bit program write\n", __FUNCTION__);
940 1486 nogj
    return;
941
  }
942
 
943
  if((mem = verify_memoryarea(memaddr))) {
944 1556 nogj
    mem->ops.writeprog32(memaddr & mem->size_mask, value,
945
                         mem->ops.writeprog32_dat);
946 1486 nogj
  } else
947
    PRINTF("ERR: 32-bit program load out of memory area: %"PRIxADDR"\n",
948
           memaddr);
949
}
950
 
951 1556 nogj
/* set_program8 - same as set_direct8, but it also writes to memory that is
952
 *                non-writeable to the rest of the sim.  Used to do program
953
 *                loading.
954
 */
955
void set_program8(oraddr_t memaddr, uint8_t value)
956
{
957
  struct dev_memarea *mem;
958
 
959
  if((mem = verify_memoryarea(memaddr))) {
960
    mem->ops.writeprog8(memaddr & mem->size_mask, value,
961
                        mem->ops.writeprog8_dat);
962
  } else
963
    PRINTF("ERR: 8-bit program load out of memory area: %"PRIxADDR"\n",
964
           memaddr);
965
}
966
 
967 1350 nogj
void dumpmemory(oraddr_t from, oraddr_t to, int disasm, int nl)
968 361 markom
{
969 1350 nogj
  oraddr_t i, j;
970 361 markom
  struct label_entry *tmp;
971
  int ilen = disasm ? 4 : 16;
972
 
973
  for(i = from; i < to; i += ilen) {
974 1584 phoenix
 
975 361 markom
    for (j = 0; j < ilen;) {
976
      if (!disasm) {
977
        tmp = NULL;
978 1350 nogj
        if (verify_memoryarea(i + j)) {
979 361 markom
          struct label_entry *entry;
980
          entry = get_label(i + j);
981 1584 phoenix
 
982
          if (entry) {
983
            PRINTF("\n%"PRIxADDR": ", i);
984
            PRINTF("\n<%s>:\n", entry->name);
985
            PRINTF("%"PRIxADDR": ", i);
986
          } else {
987
            PRINTF("%"PRIxADDR": ", i);
988
          }
989
 
990 1487 nogj
          PRINTF("%02"PRIx8" ", eval_direct8(i + j, 0, 0));
991 997 markom
        } else PRINTF("XX ");
992 361 markom
        j++;
993
      } else {
994 1487 nogj
        uint32_t _insn = eval_direct32(i, 0, 0);
995 361 markom
        int index = insn_decode (_insn);
996
        int len = insn_len (index);
997
 
998
        tmp = NULL;
999 1350 nogj
        if (verify_memoryarea(i + j)) {
1000 361 markom
          struct label_entry *entry;
1001
          entry = get_label(i + j);
1002 1584 phoenix
 
1003
          if (entry) {
1004
            PRINTF("\n%"PRIxADDR": ", i);
1005
            PRINTF("<%s>:\n", entry->name);
1006
            PRINTF("%"PRIxADDR": ", i);
1007
          } else {
1008
            PRINTF("%"PRIxADDR": ", i);
1009
          }
1010 361 markom
 
1011 1584 phoenix
          PRINTF("%08"PRIx32" ", _insn);
1012 361 markom
          if (index >= 0) {
1013
            disassemble_insn (_insn);
1014 997 markom
            PRINTF(" %s", disassembled);
1015 361 markom
          } else
1016 997 markom
            PRINTF("<invalid>");
1017
        } else PRINTF("XXXXXXXX");
1018 361 markom
        j += len;
1019
      }
1020
    }
1021
    if (nl)
1022 997 markom
      PRINTF ("\n");
1023 361 markom
  }
1024
}
1025
 
1026 426 markom
/* Closes files, etc. */
1027
 
1028 1486 nogj
void done_memory_table (void)
1029 426 markom
{
1030
  struct dev_memarea *ptmp;
1031
 
1032
  /* Check list of registered devices. */
1033
  for(ptmp = dev_list; ptmp; ptmp = ptmp->next) {
1034
    if (ptmp->log)
1035
      fclose (ptmp->log);
1036
  }
1037
}
1038 427 markom
 
1039
/* Displays current memory configuration */
1040
 
1041 1486 nogj
void memory_table_status (void)
1042 427 markom
{
1043
  struct dev_memarea *ptmp;
1044
 
1045
  /* Check list of registered devices. */
1046
  for(ptmp = dev_list; ptmp; ptmp = ptmp->next) {
1047 1486 nogj
    PRINTF ("addr & %"PRIxADDR" == %"PRIxADDR" to %"PRIxADDR", size %"PRIx32"\n",
1048 427 markom
      ptmp->addr_mask, ptmp->addr_compare, ptmp->addr_compare | bit_mask (ptmp->size),
1049 1486 nogj
      ptmp->size);
1050 997 markom
    PRINTF ("\t");
1051 1486 nogj
    if (ptmp->ops.delayr >= 0)
1052
      PRINTF ("read delay = %i cycles, ", ptmp->ops.delayr);
1053 427 markom
    else
1054 997 markom
      PRINTF ("reads not possible, ");
1055 427 markom
 
1056 1486 nogj
    if (ptmp->ops.delayw >= 0)
1057
      PRINTF ("write delay = %i cycles", ptmp->ops.delayw);
1058 427 markom
    else
1059 997 markom
      PRINTF ("writes not possible");
1060 427 markom
 
1061
    if (ptmp->log)
1062 997 markom
      PRINTF (", (logged)\n");
1063 427 markom
    else
1064 997 markom
      PRINTF ("\n");
1065 427 markom
  }
1066
}
1067 433 markom
 
1068
/* Outputs time in pretty form to dest string */
1069
 
1070 897 markom
char *generate_time_pretty (char *dest, long time_ps)
1071 433 markom
{
1072
  int exp3 = 0;
1073
  if (time_ps) {
1074
    while ((time_ps % 1000) == 0) {
1075
      time_ps /= 1000;
1076
      exp3++;
1077
    }
1078
  }
1079 1308 phoenix
  sprintf (dest, "%li%cs", time_ps, "pnum"[exp3]);
1080 897 markom
  return dest;
1081 433 markom
}

powered by: WebSVN 2.1.0

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