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 123

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 123 markom
#include "or32.h"
40 55 lampret
 
41
extern struct mem_entry mem[MEMORY_LEN];
42
extern char rcsrev[];
43
 
44
void dumpverilog(char *verilog_modname, unsigned int from, unsigned int to)
45
{
46
        unsigned int i, done = 0;
47
        struct label_entry *tmp;
48 60 lampret
        char dis[DISWIDTH + 100];
49 123 markom
        int breakpoint = 0;
50
 
51 55 lampret
        printf("// This file was generated by or1ksim %s\n", rcsrev);
52 60 lampret
        printf(OR1K_MEM_VERILOG_HEADER(verilog_modname, from/DWQ, to/DWQ, (DISWIDTH*8)));
53 55 lampret
 
54
        for(i = from; i < to && i < (MEMORY_START + MEMORY_LEN); i++) {
55 123 markom
                if (mem[i].insn->insn_index >= 0) {
56 55 lampret
                        tmp = mem[i].label;
57
                        for(; tmp; tmp = tmp->next)
58
                                printf("\n//\t%s%s", tmp->name, LABELEND_CHAR);
59
 
60
                        printf("\n\tmem['h%x] = %d'h%.2x%.2x", i/DWQ, DW, mem[i].data, mem[i+1].data);
61
                        printf("%.2x%.2x;", mem[i+2].data, mem[i+3].data);
62
                        if (mem[i].insn)
63 123 markom
                                sprintf(dis, "%s  %s", insn_name(mem[i].insn->insn_index), mem[i].insn->op1);
64 55 lampret
                        if (strlen(mem[i].insn->op2))
65 60 lampret
                                sprintf(dis, "%s%s%s", dis, OPERAND_DELIM, mem[i].insn->op2);
66 55 lampret
                        if (strlen(mem[i].insn->op3))
67 60 lampret
                                sprintf(dis, "%s%s%s", dis, OPERAND_DELIM, mem[i].insn->op3);
68 55 lampret
                        if (strlen(mem[i].insn->op4))
69 60 lampret
                                sprintf(dis, "%s%s%s", dis, OPERAND_DELIM, mem[i].insn->op4);
70
                        if (strlen(dis) < DISWIDTH)
71
                                memset(dis + strlen(dis), ' ', DISWIDTH);
72
                        dis[DISWIDTH] = '\0';
73
                        printf("\n\tdis['h%x] = {\"%s\"};", i/DWQ, dis);
74
                        dis[0] = '\0';
75 123 markom
                        i += (insn_len(mem[i].insn->insn_index) - 1);
76 55 lampret
                } else
77
                {
78
                        if (i % 64 == 0)
79
                                printf("\n");
80
 
81
                        printf("\n\tmem['h%x] = 'h%.2x;", i/DWQ, (unsigned char)mem[i].data);
82
                }
83
                done = 1;
84
        }
85
 
86
        if (done) {
87
                printf(OR1K_MEM_VERILOG_FOOTER);
88
                return;
89
        }
90
 
91
        /* this needs to be fixed */
92
 
93
        for(i = from; i < to; i++) {
94
                if (i % 8 == 0)
95
                        printf("\n%.8x:  ", i);
96
 
97
                /* don't print ascii chars below 0x20. */
98 123 markom
                if (evalsim_mem32(i,&breakpoint) < 0x20)
99
                        printf("0x%.2x     ", (unsigned char)evalsim_mem32(i,&breakpoint));
100 55 lampret
                else
101 123 markom
                        printf("0x%.2x'%c'  ", (unsigned char)evalsim_mem32(i,&breakpoint), (unsigned char)evalsim_mem32(i,&breakpoint));
102 55 lampret
 
103
        }
104
        printf(OR1K_MEM_VERILOG_FOOTER);
105
}
106 85 lampret
 
107
 
108
void dumphex(unsigned int from, unsigned int to)
109
{
110
        unsigned int i, done = 0;
111 123 markom
        int breakpoint = 0;
112
 
113 85 lampret
        for(i = from; i < to && i < (MEMORY_START + MEMORY_LEN); i++) {
114
                if (mem[i].insn) {
115
                        printf("%.2x%.2x", mem[i].data, mem[i+1].data);
116
                        printf("%.2x%.2x\n", mem[i+2].data, mem[i+3].data);
117 123 markom
                        i += (insn_len(mem[i].insn->insn_index) - 1);
118 85 lampret
                } else
119
                {
120
                        printf("%.2x\n", (unsigned char)mem[i].data);
121
                }
122
                done = 1;
123
        }
124
 
125
        if (done) {
126
                return;
127
        }
128
 
129
        /* this needs to be fixed */
130
 
131
        for(i = from; i < to; i++) {
132 123 markom
                        printf("%.2x", (unsigned char)evalsim_mem32(i,&breakpoint));
133 85 lampret
        }
134
}

powered by: WebSVN 2.1.0

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