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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [support/] [dumpverilog.c] - Blame information for rev 1774

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 1748 jeremybenn
 
4 55 lampret
   Copyright (C) 2000 Damjan Lampret, lampret@opencores.org
5 1748 jeremybenn
   Copyright (C) 2008 Embecosm Limited
6 55 lampret
 
7 1748 jeremybenn
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8 55 lampret
 
9 1748 jeremybenn
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
10 55 lampret
 
11 1748 jeremybenn
   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 55 lampret
 
16 1748 jeremybenn
   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 55 lampret
/* Verilog dump can be used for stimulating OpenRISC Verilog RTL models. */
28
 
29
 
30 1748 jeremybenn
/* Autoconf and/or portability configuration */
31 55 lampret
#include "config.h"
32 1350 nogj
 
33 1748 jeremybenn
/* Package includes */
34
#include "sim-config.h"
35 1358 nogj
#include "arch.h"
36 55 lampret
#include "abstract.h"
37 1748 jeremybenn
#include "labels.h"
38 1344 nogj
#include "opcode/or32.h"
39 55 lampret
 
40
 
41 1748 jeremybenn
#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 1751 jeremybenn
"parameter amin = %" PRIdREG ";\n\n"\
57
"parameter amax = %" PRIdREG ";\n\n"\
58 1748 jeremybenn
"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 55 lampret
{
92 138 markom
  unsigned int i, done = 0;
93
  struct label_entry *tmp;
94 1748 jeremybenn
  char dis[DISWIDTH + 100];
95 1604 nogj
  uint32_t insn;
96
  int index;
97 1748 jeremybenn
  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 138 markom
    }
137 1604 nogj
 
138 138 markom
  if (done)
139
    {
140 1748 jeremybenn
      PRINTF (OR1K_MEM_VERILOG_FOOTER);
141 138 markom
      return;
142
    }
143 1748 jeremybenn
 
144 138 markom
  /* this needs to be fixed */
145 1748 jeremybenn
 
146
  for (i = from; i < to; i++)
147 138 markom
    {
148
      if (i % 8 == 0)
149 1748 jeremybenn
        PRINTF ("\n%.8x:  ", i);
150
 
151 138 markom
      /* don't print ascii chars below 0x20. */
152 1748 jeremybenn
      if (eval_direct32 (i, 0, 0) < 0x20)
153
        PRINTF ("0x%.2x     ", (uint8_t) eval_direct32 (i, 0, 0));
154 138 markom
      else
155 1748 jeremybenn
        PRINTF ("0x%.2x'%c'  ", (uint8_t) eval_direct32 (i, 0, 0),
156
                (char) eval_direct32 (i, 0, 0));
157 138 markom
    }
158 1748 jeremybenn
  PRINTF (OR1K_MEM_VERILOG_FOOTER);
159 55 lampret
}
160 85 lampret
 
161 1748 jeremybenn
void
162
dumphex (oraddr_t from, oraddr_t to)
163 85 lampret
{
164 1604 nogj
  oraddr_t i;
165
  uint32_t insn;
166
  int index;
167 1748 jeremybenn
 
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 1604 nogj
    }
183 85 lampret
}

powered by: WebSVN 2.1.0

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