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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [or1ksim/] [support/] [dumpverilog.c] - Blame information for rev 178

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

Line No. Rev Author Line
1 19 jeremybenn
/* dumpverilog.c -- Dumps memory region as Verilog representation
2
   or as hex code
3
 
4
   Copyright (C) 2000 Damjan Lampret, lampret@opencores.org
5
   Copyright (C) 2008 Embecosm Limited
6
 
7
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
   This file is part of Or1ksim, the 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
/* Verilog dump can be used for stimulating OpenRISC Verilog RTL models. */
28
 
29
 
30
/* Autoconf and/or portability configuration */
31
#include "config.h"
32
 
33
/* Package includes */
34
#include "sim-config.h"
35
#include "arch.h"
36
#include "abstract.h"
37
#include "labels.h"
38
#include "opcode/or32.h"
39
 
40
 
41
#define DW 32                   /* Data width of mem model generated by */
42
                                /* dumpverilog in bits */
43
#define DWQ (DW/8)              /* Same as DW but units are bytes */
44
#define DISWIDTH 25             /* Width of disassembled message in bytes */
45
 
46
#define OR1K_MEM_VERILOG_HEADER(MODNAME, FROMADDR, TOADDR, DISWIDTH) "\n"\
47
"include \"general.h\"\n\n"\
48
"`timescale 1ns/100ps\n\n"\
49
"// Simple dw-wide Sync SRAM with initial content generated by or1ksim.\n"\
50
"// All control, data in and addr signals are sampled at rising clock edge  \n"\
51
"// Data out is not registered. Address bits specify dw-word (narrowest \n"\
52
"// addressed data is not byte but dw-word !). \n"\
53
"// There are still some bugs in generated output (dump word aligned regions)\n\n"\
54
"module %s(clk, data, addr, ce, we, disout);\n\n"\
55
"parameter dw = 32;\n"\
56
"parameter amin = %" PRIdREG ";\n\n"\
57
"parameter amax = %" PRIdREG ";\n\n"\
58
"input clk;\n"\
59
"inout [dw-1:0] data;\n"\
60
"input [31:0] addr;\n"\
61
"input ce;\n"\
62
"input we;\n"\
63
"output [%d:0] disout;\n\n"\
64
"reg  [%d:0] disout;\n"\
65
"reg  [dw-1:0] mem [amax:amin];\n"\
66
"reg  [%d:0] dis [amax:amin];\n"\
67
"reg  [dw-1:0] dataout;\n"\
68
"tri  [dw-1:0] data = (ce && ~we) ? dataout : 'bz;\n\n"\
69
"initial begin\n", MODNAME, FROMADDR, TOADDR, DISWIDTH-1, DISWIDTH-1, DISWIDTH-1
70
 
71
#define OR1K_MEM_VERILOG_FOOTER "\n\
72
end\n\n\
73
always @(posedge clk) begin\n\
74
        if (ce && ~we) begin\n\
75
                dataout <= #1 mem[addr];\n\
76
                disout <= #1 dis[addr];\n\
77
                $display(\"or1k_mem: reading mem[%%0d]:%%h dis: %%0s\", addr, dataout, dis[addr]);\n\
78
        end else\n\
79
        if (ce && we) begin\n\
80
                mem[addr] <= #1 data;\n\
81
                dis[addr] <= #1 \"(data)\";\n\
82
                $display(\"or1k_mem: writing mem[%%0d]:%%h dis: %%0s\", addr, mem[addr], dis[addr]);\n\
83
        end\n\
84
end\n\n\
85
endmodule\n"
86
 
87
#define LABELEND_CHAR   ":"
88
 
89
void
90
dumpverilog (char *verilog_modname, oraddr_t from, oraddr_t to)
91
{
92
  unsigned int i, done = 0;
93
  struct label_entry *tmp;
94
  char dis[DISWIDTH + 100];
95
  uint32_t insn;
96
  int index;
97
  PRINTF ("// This file was generated by or1ksim version %s\n",
98
          PACKAGE_VERSION);
99
  PRINTF (OR1K_MEM_VERILOG_HEADER
100
          (verilog_modname, from / DWQ, to / DWQ, (DISWIDTH * 8)));
101
 
102
  for (i = from; i < to; i++)
103
    {
104
      if (!(i & 3))
105
        {
106
          insn = eval_direct32 (i, 0, 0);
107
          index = insn_decode (insn);
108
          if (index >= 0)
109
            {
110
              if (verify_memoryarea (i) && (tmp = get_label (i)))
111
                if (tmp)
112
                  PRINTF ("\n//\t%s%s", tmp->name, LABELEND_CHAR);
113
 
114
              PRINTF ("\n\tmem['h%x] = %d'h%.8" PRIx32 ";", i / DWQ, DW,
115
                      eval_direct32 (i, 0, 0));
116
 
117
              disassemble_insn (insn);
118
              strcpy (dis, disassembled);
119
 
120
              if (strlen (dis) < DISWIDTH)
121
                memset (dis + strlen (dis), ' ', DISWIDTH);
122
              dis[DISWIDTH] = '\0';
123
              PRINTF ("\n\tdis['h%x] = {\"%s\"};", i / DWQ, dis);
124
              dis[0] = '\0';
125
              i += insn_len (index) - 1;
126
              done = 1;
127
              continue;
128
            }
129
        }
130
 
131
      if (i % 64 == 0)
132
        PRINTF ("\n");
133
 
134
      PRINTF ("\n\tmem['h%x] = 'h%.2x;", i / DWQ, eval_direct8 (i, 0, 0));
135
      done = 1;
136
    }
137
 
138
  if (done)
139
    {
140
      PRINTF (OR1K_MEM_VERILOG_FOOTER);
141
      return;
142
    }
143
 
144
  /* this needs to be fixed */
145
 
146
  for (i = from; i < to; i++)
147
    {
148
      if (i % 8 == 0)
149
        PRINTF ("\n%.8x:  ", i);
150
 
151
      /* don't print ascii chars below 0x20. */
152
      if (eval_direct32 (i, 0, 0) < 0x20)
153
        PRINTF ("0x%.2x     ", (uint8_t) eval_direct32 (i, 0, 0));
154
      else
155
        PRINTF ("0x%.2x'%c'  ", (uint8_t) eval_direct32 (i, 0, 0),
156
                (char) eval_direct32 (i, 0, 0));
157
    }
158
  PRINTF (OR1K_MEM_VERILOG_FOOTER);
159
}
160
 
161
void
162
dumphex (oraddr_t from, oraddr_t to)
163
{
164
  oraddr_t i;
165
  uint32_t insn;
166
  int index;
167
 
168
  for (i = from; i < to; i++)
169
    {
170
      if (!(i & 3))
171
        {
172
          insn = eval_direct32 (i, 0, 0);
173
          index = insn_decode (insn);
174
          if (index >= 0)
175
            {
176
              PRINTF ("%.8" PRIx32 "\n", eval_direct32 (i, 0, 0));
177
              i += insn_len (index) - 1;
178
              continue;
179
            }
180
        }
181
      PRINTF ("%.2x\n", eval_direct8 (i, 0, 0));
182
    }
183
}

powered by: WebSVN 2.1.0

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