/* dumpverilog.c -- Dumps memory region as Verilog representation
|
/* dumpverilog.c -- Dumps memory region as Verilog representation
|
or as hex code
|
or as hex code
|
Copyright (C) 2000 Damjan Lampret, lampret@opencores.org
|
Copyright (C) 2000 Damjan Lampret, lampret@opencores.org
|
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
|
|
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
(at your option) any later version.
|
(at your option) any later version.
|
|
|
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU General Public License for more details.
|
GNU General Public License for more details.
|
|
|
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
/* Verilog dump can be used for stimulating OpenRISC Verilog RTL models. */
|
/* Verilog dump can be used for stimulating OpenRISC Verilog RTL models. */
|
|
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <ctype.h>
|
#include <ctype.h>
|
#include <string.h>
|
#include <string.h>
|
|
|
#include "config.h"
|
#include "config.h"
|
|
|
#ifdef HAVE_INTTYPES_H
|
#ifdef HAVE_INTTYPES_H
|
#include <inttypes.h>
|
#include <inttypes.h>
|
#endif
|
#endif
|
|
|
#include "port.h"
|
#include "port.h"
|
#include "arch.h"
|
#include "arch.h"
|
#include "sim-config.h"
|
#include "sim-config.h"
|
#include "parse.h"
|
#include "parse.h"
|
#include "abstract.h"
|
#include "abstract.h"
|
#include "opcode/or32.h"
|
#include "opcode/or32.h"
|
#include "spr_defs.h"
|
#include "spr_defs.h"
|
#include "labels.h"
|
#include "labels.h"
|
#include "execute.h"
|
#include "execute.h"
|
#include "sprs.h"
|
#include "sprs.h"
|
#include "stats.h"
|
#include "stats.h"
|
#include "except.h"
|
#include "except.h"
|
#include "dumpverilog.h"
|
#include "dumpverilog.h"
|
|
|
extern char *or1ksim_ver;
|
extern char *or1ksim_ver;
|
extern char *disassembled;
|
extern char *disassembled;
|
|
|
void dumpverilog(char *verilog_modname, unsigned int from, unsigned int to)
|
void dumpverilog(char *verilog_modname, unsigned int from, unsigned int to)
|
{
|
{
|
unsigned int i, done = 0;
|
unsigned int i, done = 0;
|
struct label_entry *tmp;
|
struct label_entry *tmp;
|
char dis[DISWIDTH + 100];
|
char dis[DISWIDTH + 100];
|
PRINTF("// This file was generated by or1ksim version %s\n", or1ksim_ver);
|
PRINTF("// This file was generated by or1ksim version %s\n", or1ksim_ver);
|
PRINTF(OR1K_MEM_VERILOG_HEADER(verilog_modname, from/DWQ, to/DWQ, (DISWIDTH*8)));
|
PRINTF(OR1K_MEM_VERILOG_HEADER(verilog_modname, from/DWQ, to/DWQ, (DISWIDTH*8)));
|
|
|
for(i = from; i < to; i++)
|
for(i = from; i < to; i++)
|
{
|
{
|
unsigned int _insn = eval_direct32 (i, 0, 0);
|
unsigned int _insn = eval_direct32 (i, 0, 0);
|
int index = insn_decode(_insn);
|
int index = insn_decode(_insn);
|
if (index >= 0)
|
if (index >= 0)
|
{
|
{
|
if (verify_memoryarea(i) && (tmp = get_label(i)))
|
if (verify_memoryarea(i) && (tmp = get_label(i)))
|
if (tmp)
|
if (tmp)
|
PRINTF("\n//\t%s%s", tmp->name, LABELEND_CHAR);
|
PRINTF("\n//\t%s%s", tmp->name, LABELEND_CHAR);
|
|
|
PRINTF("\n\tmem['h%x] = %d'h%.8"PRIx32";", i/DWQ, DW,
|
PRINTF("\n\tmem['h%x] = %d'h%.8"PRIx32";", i/DWQ, DW,
|
eval_direct32(i, 0, 0));
|
eval_direct32(i, 0, 0));
|
|
|
disassemble_insn (_insn);
|
disassemble_insn (_insn);
|
strcpy (dis, disassembled);
|
strcpy (dis, disassembled);
|
|
|
if (strlen(dis) < DISWIDTH)
|
if (strlen(dis) < DISWIDTH)
|
memset(dis + strlen(dis), ' ', DISWIDTH);
|
memset(dis + strlen(dis), ' ', DISWIDTH);
|
dis[DISWIDTH] = '\0';
|
dis[DISWIDTH] = '\0';
|
PRINTF("\n\tdis['h%x] = {\"%s\"};", i/DWQ, dis);
|
PRINTF("\n\tdis['h%x] = {\"%s\"};", i/DWQ, dis);
|
dis[0] = '\0';
|
dis[0] = '\0';
|
i += insn_len(index) - 1;
|
i += insn_len(index) - 1;
|
} else {
|
} else {
|
if (i % 64 == 0)
|
if (i % 64 == 0)
|
PRINTF("\n");
|
PRINTF("\n");
|
|
|
PRINTF("\n\tmem['h%x] = 'h%.2x;", i/DWQ,
|
PRINTF("\n\tmem['h%x] = 'h%.2x;", i/DWQ,
|
eval_direct8(i, 0, 0));
|
eval_direct8(i, 0, 0));
|
}
|
}
|
done = 1;
|
done = 1;
|
}
|
}
|
|
|
if (done)
|
if (done)
|
{
|
{
|
PRINTF(OR1K_MEM_VERILOG_FOOTER);
|
PRINTF(OR1K_MEM_VERILOG_FOOTER);
|
return;
|
return;
|
}
|
}
|
|
|
/* this needs to be fixed */
|
/* this needs to be fixed */
|
|
|
for(i = from; i < to; i++)
|
for(i = from; i < to; i++)
|
{
|
{
|
if (i % 8 == 0)
|
if (i % 8 == 0)
|
PRINTF("\n%.8x: ", i);
|
PRINTF("\n%.8x: ", i);
|
|
|
/* don't print ascii chars below 0x20. */
|
/* don't print ascii chars below 0x20. */
|
if (eval_direct32(i, 0, 0) < 0x20)
|
if (eval_direct32(i, 0, 0) < 0x20)
|
PRINTF("0x%.2x ", (uint8_t)eval_direct32(i, 0, 0));
|
PRINTF("0x%.2x ", (uint8_t)eval_direct32(i, 0, 0));
|
else
|
else
|
PRINTF("0x%.2x'%c' ", (uint8_t)eval_direct32(i, 0, 0),
|
PRINTF("0x%.2x'%c' ", (uint8_t)eval_direct32(i, 0, 0),
|
(char)eval_direct32(i, 0, 0));
|
(char)eval_direct32(i, 0, 0));
|
}
|
}
|
PRINTF(OR1K_MEM_VERILOG_FOOTER);
|
PRINTF(OR1K_MEM_VERILOG_FOOTER);
|
}
|
}
|
|
|
void dumphex(unsigned int from, unsigned int to)
|
void dumphex(unsigned int from, unsigned int to)
|
{
|
{
|
unsigned int i;
|
unsigned int i;
|
|
|
for(i = from; i < to; i++) {
|
for(i = from; i < to; i++) {
|
unsigned int _insn = eval_direct32 (i, 0, 0);
|
unsigned int _insn = eval_direct32 (i, 0, 0);
|
int index = insn_decode(_insn);
|
int index = insn_decode(_insn);
|
if (index >= 0)
|
if (index >= 0)
|
{
|
{
|
PRINTF("%.8"PRIx32"\n", eval_direct32(i, 0, 0));
|
PRINTF("%.8"PRIx32"\n", eval_direct32(i, 0, 0));
|
|
|
i += insn_len(index) - 1;
|
i += insn_len(index) - 1;
|
}
|
}
|
else
|
else
|
PRINTF("%.2x\n", eval_direct8(i, 0, 0));
|
PRINTF("%.2x\n", eval_direct8(i, 0, 0));
|
}
|
}
|
}
|
}
|
|
|