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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_52/] [or1ksim/] [support/] [dumpverilog.c] - Blame information for rev 85

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

Line No. Rev Author Line
1 55 lampret
/* dumpverilog.c -- Dumps memory region as Verilog representation
2 85 lampret
   or as hex code
3 55 lampret
   Copyright (C) 2000 Damjan Lampret, lampret@opencores.org
4
 
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
/* Verilog dump can be used for stimulating OpenRISC Verilog RTL models. */
22
 
23
#include <stdio.h>
24
#include <ctype.h>
25
#include <string.h>
26
 
27
#include "config.h"
28
#include "sim-config.h"
29
 
30
#include "parse.h"
31
#include "abstract.h"
32
#include "arch.h"
33
#include "trace.h"
34
#include "execute.h"
35
#include "sprs.h"
36
#include "stats.h"
37
#include "except.h"
38
#include "dumpverilog.h"
39
 
40
extern struct mem_entry mem[MEMORY_LEN];
41
extern char rcsrev[];
42
 
43
void dumpverilog(char *verilog_modname, unsigned int from, unsigned int to)
44
{
45
        unsigned int i, done = 0;
46
        struct label_entry *tmp;
47 60 lampret
        char dis[DISWIDTH + 100];
48 55 lampret
 
49
        printf("// This file was generated by or1ksim %s\n", rcsrev);
50 60 lampret
        printf(OR1K_MEM_VERILOG_HEADER(verilog_modname, from/DWQ, to/DWQ, (DISWIDTH*8)));
51 55 lampret
 
52
        for(i = from; i < to && i < (MEMORY_START + MEMORY_LEN); i++) {
53
                if (mem[i].insn) {
54
                        tmp = mem[i].label;
55
                        for(; tmp; tmp = tmp->next)
56
                                printf("\n//\t%s%s", tmp->name, LABELEND_CHAR);
57
 
58
                        printf("\n\tmem['h%x] = %d'h%.2x%.2x", i/DWQ, DW, mem[i].data, mem[i+1].data);
59
                        printf("%.2x%.2x;", mem[i+2].data, mem[i+3].data);
60
                        if (mem[i].insn)
61 60 lampret
                                sprintf(dis, "%s  %s", mem[i].insn->insn, mem[i].insn->op1);
62 55 lampret
                        if (strlen(mem[i].insn->op2))
63 60 lampret
                                sprintf(dis, "%s%s%s", dis, OPERAND_DELIM, mem[i].insn->op2);
64 55 lampret
                        if (strlen(mem[i].insn->op3))
65 60 lampret
                                sprintf(dis, "%s%s%s", dis, OPERAND_DELIM, mem[i].insn->op3);
66 55 lampret
                        if (strlen(mem[i].insn->op4))
67 60 lampret
                                sprintf(dis, "%s%s%s", dis, OPERAND_DELIM, mem[i].insn->op4);
68
                        if (strlen(dis) < DISWIDTH)
69
                                memset(dis + strlen(dis), ' ', DISWIDTH);
70
                        dis[DISWIDTH] = '\0';
71
                        printf("\n\tdis['h%x] = {\"%s\"};", i/DWQ, dis);
72
                        dis[0] = '\0';
73 55 lampret
                        i += (insn_len(mem[i].insn->insn) - 1);
74
                } else
75
                {
76
                        if (i % 64 == 0)
77
                                printf("\n");
78
 
79
                        printf("\n\tmem['h%x] = 'h%.2x;", i/DWQ, (unsigned char)mem[i].data);
80
                }
81
                done = 1;
82
        }
83
 
84
        if (done) {
85
                printf(OR1K_MEM_VERILOG_FOOTER);
86
                return;
87
        }
88
 
89
        /* this needs to be fixed */
90
 
91
        for(i = from; i < to; i++) {
92
                if (i % 8 == 0)
93
                        printf("\n%.8x:  ", i);
94
 
95
                /* don't print ascii chars below 0x20. */
96 75 lampret
                if (evalsim_mem32(i) < 0x20)
97
                        printf("0x%.2x     ", (unsigned char)evalsim_mem32(i));
98 55 lampret
                else
99 75 lampret
                        printf("0x%.2x'%c'  ", (unsigned char)evalsim_mem32(i), (unsigned char)evalsim_mem32(i));
100 55 lampret
 
101
        }
102
        printf(OR1K_MEM_VERILOG_FOOTER);
103
}
104 85 lampret
 
105
 
106
void dumphex(unsigned int from, unsigned int to)
107
{
108
        unsigned int i, done = 0;
109
 
110
        for(i = from; i < to && i < (MEMORY_START + MEMORY_LEN); i++) {
111
                if (mem[i].insn) {
112
                        printf("%.2x%.2x", mem[i].data, mem[i+1].data);
113
                        printf("%.2x%.2x\n", mem[i+2].data, mem[i+3].data);
114
                        i += (insn_len(mem[i].insn->insn) - 1);
115
                } else
116
                {
117
                        printf("%.2x\n", (unsigned char)mem[i].data);
118
                }
119
                done = 1;
120
        }
121
 
122
        if (done) {
123
                return;
124
        }
125
 
126
        /* this needs to be fixed */
127
 
128
        for(i = from; i < to; i++) {
129
                        printf("%.2x", (unsigned char)evalsim_mem32(i));
130
        }
131
}

powered by: WebSVN 2.1.0

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