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

Subversion Repositories or1k

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 360 to Rev 361
    Reverse comparison

Rev 360 → Rev 361

/trunk/or1ksim/sim-config.h
68,15 → 68,15
int nethernets;
int ethernets_enabled;
struct {
unsigned long baseaddr;
unsigned dma; /* Which controller is this ethernet "connected" to */
unsigned tx_channel; /* DMA channel used for TX */
unsigned rx_channel; /* DMA channel used for RX */
char rxfile[STR_SIZE]; /* Filename for RX */
char txfile[STR_SIZE]; /* File for TX */
unsigned long vapi_id; /* VAPI id for this instance */
} ethernets[NR_ETHERNETS];
struct {
unsigned long baseaddr;
unsigned dma; /* Which controller is this ethernet "connected" to */
unsigned tx_channel; /* DMA channel used for TX */
unsigned rx_channel; /* DMA channel used for RX */
char rxfile[STR_SIZE]; /* Filename for RX */
char txfile[STR_SIZE]; /* File for TX */
unsigned long vapi_id; /* VAPI id for this instance */
} ethernets[NR_ETHERNETS];
struct {
int enabled; /* is MC enabled? */
100,8 → 100,8
unsigned long ver, rev; /* Version register */
int superscalar; /* superscalara analysis */
int hazards; /* dependency hazards analysis */
int history; /* instruction stream history analysis */
int dependstats; /* dependency statistics */
int history; /* instruction stream history analysis */
int dependstats; /* dependency statistics */
int dependency; /* not sure: same as dependency statistics? */
int slp; /* not sure: stack analisys? */
int btic; /* branch prediction target insn cache analysis */
112,14 → 112,12
int debug; /* Simulator debugging */
int verbose; /* Force verbose output */
int iprompt; /* Interactive prompt */
 
int profile; /* Is profiler running */
char prof_fn[STR_SIZE]; /* Profiler filename */
FILE *fprof; /* Profiler file */
int exe_log; /* Print out RTL states? */
int exe_log; /* Print out RTL states? */
char exe_log_fn[STR_SIZE]; /* RTL state comparison filename */
FILE *fexe_log; /* RTL state comparison file */
} sim;
 
struct {
133,11 → 131,21
int server_port; /* A user specified port number for services */
int log_enabled; /* Whether to log the vapi requests */
char vapi_fn[STR_SIZE]; /* vapi log filename */
} vapi;
};
 
struct runtime {
struct {
FILE *fprof; /* Profiler file */
FILE *fexe_log; /* RTL state comparison file */
int init; /* Whether we are still initilizing sim */
int script_file_specified;/* Whether script file was already loaded */
char *filename; /* Original Command Simulator file (CZ) */
} sim;
 
struct { /* Verification API, part of Advanced Core Verification */
FILE *vapi_file; /* vapi file */
} vapi;
 
char *script_file; /* Script file that should be used */
char *filename; /* Original Command Simulator file (CZ) */
};
 
#ifdef DEBUGMOD_OFF
149,6 → 157,10
#endif
 
extern struct config config;
extern struct runtime runtime;
 
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead. */
void read_script_file (char *filename);
 
/* Executes set sim command. Returns nonzero if error. */
void set_config_command (char *s);
/trunk/or1ksim/cpu/or32/execute.c
504,21 → 504,21
/* Execution logger. */
inline void dump_exe_log()
{
int i = iqueue[0].insn_addr;
int i = iqueue[0].insn_addr;
 
fprintf(config.sim.fexe_log, "\nEXECUTED(): %.8lx: ", i);
fprintf(config.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i), evalsim_mem8(i + 1));
fprintf(config.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i + 2), evalsim_mem8(i + 3));
for(i = 0; i < MAX_GPRS; i++) {
if (i % 4 == 0)
fprintf(config.sim.fexe_log, "\n");
fprintf(config.sim.fexe_log, "GPR%2u: %.8lx ", i, reg[i]);
}
fprintf(config.sim.fexe_log, "\n");
fprintf(config.sim.fexe_log, "SR : %.8lx ", mfspr(SPR_SR));
fprintf(config.sim.fexe_log, "EPCR0: %.8lx ", mfspr(SPR_EPCR_BASE));
fprintf(config.sim.fexe_log, "EEAR0: %.8lx ", mfspr(SPR_EEAR_BASE));
fprintf(config.sim.fexe_log, "ESR0 : %.8lx\n", mfspr(SPR_ESR_BASE));
fprintf(runtime.sim.fexe_log, "\nEXECUTED(): %.8lx: ", i);
fprintf(runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i), evalsim_mem8(i + 1));
fprintf(runtime.sim.fexe_log, "%.2x%.2x", evalsim_mem8(i + 2), evalsim_mem8(i + 3));
for(i = 0; i < MAX_GPRS; i++) {
if (i % 4 == 0)
fprintf(runtime.sim.fexe_log, "\n");
fprintf(runtime.sim.fexe_log, "GPR%2u: %.8lx ", i, reg[i]);
}
fprintf(runtime.sim.fexe_log, "\n");
fprintf(runtime.sim.fexe_log, "SR : %.8lx ", mfspr(SPR_SR));
fprintf(runtime.sim.fexe_log, "EPCR0: %.8lx ", mfspr(SPR_EPCR_BASE));
fprintf(runtime.sim.fexe_log, "EEAR0: %.8lx ", mfspr(SPR_EEAR_BASE));
fprintf(runtime.sim.fexe_log, "ESR0 : %.8lx\n", mfspr(SPR_ESR_BASE));
}
 
void dumpreg()
819,9 → 819,9
struct mem_entry *entry;
struct label_entry *tmp;
if (verify_memoryarea(pcdelay) && (tmp = get_label (pcdelay)))
fprintf (config.sim.fprof, "+%08X %08X %08X %s\n", cycles, pc + 8, pcdelay, tmp->name);
fprintf (runtime.sim.fprof, "+%08X %08X %08X %s\n", cycles, pc + 8, pcdelay, tmp->name);
else
fprintf (config.sim.fprof, "+%08X %08X %08X @%08X\n", cycles, pc + 8, pcdelay, pcdelay);
fprintf (runtime.sim.fprof, "+%08X %08X %08X @%08X\n", cycles, pc + 8, pcdelay, pcdelay);
}
}
void l_jalr() {
833,7 → 833,7
if (temp_disable_except == 0)
temp_disable_except = 1;
if (config.sim.profile)
fprintf (config.sim.fprof, "-%08X %08X\n", cycles, pcdelay);
fprintf (runtime.sim.fprof, "-%08X %08X\n", cycles, pcdelay);
}
void l_jr() {
cur->func_unit = jump;
/trunk/or1ksim/cpu/common/abstract.c
55,56 → 55,6
/* Temporary variable to increase speed. */
struct dev_memarea *cur_area;
 
void dumpmemory(unsigned int from, unsigned int to, int disasm, int nl)
{
unsigned int i, j;
struct label_entry *tmp;
int breakpoint = 0;
int ilen = disasm ? 4 : 16;
 
for(i = from; i < to; i += ilen) {
printf("%.8x: ", i);
for (j = 0; j < ilen;) {
int data = -1;
if (!disasm) {
tmp = NULL;
if (verify_memoryarea(i+j)) {
struct label_entry *entry;
entry = get_label(i + j);
if (entry)
printf("(%s)", entry->name);
printf("%02x ", data = evalsim_mem8(i+j));
} else printf("XX ");
j++;
} else {
int breakpoint;
unsigned int _insn = read_mem(i, &breakpoint);
int index = insn_decode (_insn);
int len = insn_len (index);
tmp = NULL;
if (verify_memoryarea(i+j)) {
struct label_entry *entry;
entry = get_label(i + j);
if (entry)
printf("(%s)", entry->name);
 
printf(": %08x ", (unsigned long)_insn);
if (index >= 0) {
disassemble_insn (_insn);
printf(" %s", disassembled);
} else
printf("<invalid>");
} else printf("XXXXXXXX");
j += len;
}
}
if (nl)
printf ("\n");
}
}
 
 
/* It returns physical address. */
unsigned long translate_vrt_to_phy_add(unsigned long virtaddr)
{
279,7 → 229,6
/* Returns 32-bit values from mem array. Big endian version. */
unsigned long read_mem(unsigned long memaddr,int* breakpoint)
{
unsigned long temp;
struct dev_memarea *dev;
540,6 → 489,56
}
}
 
void dumpmemory(unsigned int from, unsigned int to, int disasm, int nl)
{
unsigned int i, j;
struct label_entry *tmp;
int breakpoint = 0;
int ilen = disasm ? 4 : 16;
 
for(i = from; i < to; i += ilen) {
printf("%.8x: ", i);
for (j = 0; j < ilen;) {
int data = -1;
if (!disasm) {
tmp = NULL;
if (verify_memoryarea(i+j)) {
struct label_entry *entry;
entry = get_label(i + j);
if (entry)
printf("(%s)", entry->name);
printf("%02x ", data = evalsim_mem8(i+j));
} else printf("XX ");
j++;
} else {
int breakpoint;
unsigned int _insn = read_mem(i, &breakpoint);
int index = insn_decode (_insn);
int len = insn_len (index);
tmp = NULL;
if (verify_memoryarea(i+j)) {
struct label_entry *entry;
entry = get_label(i + j);
if (entry)
printf("(%s)", entry->name);
 
printf(": %08x ", (unsigned long)_insn);
if (index >= 0) {
disassemble_insn (_insn);
printf(" %s", disassembled);
} else
printf("<invalid>");
} else printf("XXXXXXXX");
j += len;
}
}
if (nl)
printf ("\n");
}
}
 
 
unsigned long simmem_read_byte(unsigned long addr) {
return simmem[cur_area->misc + (addr & cur_area->size_mask)].data;
}
/trunk/or1ksim/cpu/common/parse.c
32,7 → 32,7
#include "sim-config.h"
 
#define MEMORY_LEN 0x100000000
#define MAXLINE_LEN 18000
#define MAXLINE_LEN 18000
 
extern char *disassembled;
 
49,24 → 49,24
 
char *strtoken(char *in, char *out, int which)
{
char *super;
char *sub;
char *newline;
super = strdup(in);
sub = strtok(super, " \t");
while (sub && --which)
sub = strtok(NULL, " \t");
if (sub && !which) {
if ((newline = strchr(sub, '\n')))
newline[0] = '\0';
strcpy(out, sub);
} else
out[0] = '\0';
free(super);
if ((newline = strchr(out, '\r'))) /* get rid of CR */
newline[0] = '\0';
return(out);
char *super;
char *sub;
char *newline;
super = strdup(in);
sub = strtok(super, " \t");
while (sub && --which)
sub = strtok(NULL, " \t");
if (sub && !which) {
if ((newline = strchr(sub, '\n')))
newline[0] = '\0';
strcpy(out, sub);
} else
out[0] = '\0';
free(super);
if ((newline = strchr(out, '\r'))) /* get rid of CR */
newline[0] = '\0';
return(out);
}
 
char *
106,41 → 106,41
equal to logical. */
static unsigned int translate(unsigned int laddr,int* breakpoint)
{
int i;
/* No translation (i.e. when loading kernel into simulator)
/* printf("transl_table=%x laddr=%x\n", transl_table, laddr);
printf("laddr=%x\n", laddr);*/
if (transl_table == 0)
return laddr;
/* Try to find our translation in the table. */
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
if ((laddr & ~(PAGE_SIZE - 1)) == evalsim_mem32(transl_table + i)) {
setsim_mem32(transl_table + i + 8, -2); /* Page modified */
printf("found paddr=%x\n", evalsim_mem32(transl_table + i + 4) | (laddr & (PAGE_SIZE - 1)));
return (unsigned long)evalsim_mem32(transl_table + i + 4) | (laddr & (unsigned long)(PAGE_SIZE - 1));
}
int i;
/* No translation (i.e. when loading kernel into simulator)
/* printf("transl_table=%x laddr=%x\n", transl_table, laddr);
printf("laddr=%x\n", laddr);*/
if (transl_table == 0)
return laddr;
/* Try to find our translation in the table. */
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
if ((laddr & ~(PAGE_SIZE - 1)) == evalsim_mem32(transl_table + i)) {
setsim_mem32(transl_table + i + 8, -2); /* Page modified */
printf("found paddr=%x\n", evalsim_mem32(transl_table + i + 4) | (laddr & (PAGE_SIZE - 1)));
return (unsigned long)evalsim_mem32(transl_table + i + 4) | (laddr & (unsigned long)(PAGE_SIZE - 1));
}
 
/* Allocate new phy page for us. */
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
if (evalsim_mem32(transl_table + i + 8) == 0) {
setsim_mem32(transl_table + i, laddr & ~(PAGE_SIZE - 1)); /* VPN */
setsim_mem32(transl_table + i + 4, (i/16) * PAGE_SIZE); /* PPN */
setsim_mem32(transl_table + i + 8, -2); /* Page modified */
printf("newly allocated ppn=%x\n", (unsigned long)evalsim_mem32(transl_table + i + 4));
printf("newly allocated .ppn=%x\n", (unsigned long)transl_table + i + 4);
printf("newly allocated ofs=%x\n", (unsigned long)(laddr & (PAGE_SIZE - 1)));
printf("newly allocated paddr=%x\n", (unsigned long)evalsim_mem32(transl_table + i + 4) | (laddr & (PAGE_SIZE - 1)));
return (unsigned long)evalsim_mem32(transl_table + i + 4) | (laddr & (unsigned long)(PAGE_SIZE - 1));
}
/* If we come this far then all phy memory is used and we can't find our page
nor allocate new page. */
transl_error = 1;
printf("can't translate\n", laddr);
exit(1);
return -1;
/* Allocate new phy page for us. */
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
if (evalsim_mem32(transl_table + i + 8) == 0) {
setsim_mem32(transl_table + i, laddr & ~(PAGE_SIZE - 1)); /* VPN */
setsim_mem32(transl_table + i + 4, (i/16) * PAGE_SIZE); /* PPN */
setsim_mem32(transl_table + i + 8, -2); /* Page modified */
printf("newly allocated ppn=%x\n", (unsigned long)evalsim_mem32(transl_table + i + 4));
printf("newly allocated .ppn=%x\n", (unsigned long)transl_table + i + 4);
printf("newly allocated ofs=%x\n", (unsigned long)(laddr & (PAGE_SIZE - 1)));
printf("newly allocated paddr=%x\n", (unsigned long)evalsim_mem32(transl_table + i + 4) | (laddr & (PAGE_SIZE - 1)));
return (unsigned long)evalsim_mem32(transl_table + i + 4) | (laddr & (unsigned long)(PAGE_SIZE - 1));
}
/* If we come this far then all phy memory is used and we can't find our page
nor allocate new page. */
transl_error = 1;
printf("can't translate\n", laddr);
exit(1);
return -1;
}
 
char null_str[1] = "\0";
152,13 → 152,13
void addprogram(unsigned long address, unsigned long insn, int* breakpoint)
{
char insn_first2_char[3];
int vaddr = (!config.filename) ? translate(address,breakpoint) : translate(freemem,breakpoint);
int vaddr = (!runtime.sim.filename) ? translate(address,breakpoint) : translate(freemem,breakpoint);
debug(9,"addprogram 1\n");
 
setsim_mem32 (vaddr, insn);
 
if(config.filename)
if(runtime.sim.filename)
freemem += insn_len (insn_decode (insn));
}
 
166,121 → 166,121
 
void readfile_coff(char *filename, short sections)
{
FILE *inputfs;
char inputbuf[4];
unsigned long insn;
signed long sectsize;
COFF_AOUTHDR coffaouthdr;
struct COFF_scnhdr coffscnhdr;
int len;
char item[MAXLINE_LEN];
char item2[MAXLINE_LEN];
int firstthree = 0;
int breakpoint = 0;
FILE *inputfs;
char inputbuf[4];
unsigned long insn;
signed long sectsize;
COFF_AOUTHDR coffaouthdr;
struct COFF_scnhdr coffscnhdr;
int len;
char item[MAXLINE_LEN];
char item2[MAXLINE_LEN];
int firstthree = 0;
int breakpoint = 0;
 
if (!(inputfs = fopen(filename, "r"))) {
perror("readfile_coff");
exit(1);
}
if (!(inputfs = fopen(filename, "r"))) {
perror("readfile_coff");
exit(1);
}
 
if (fseek(inputfs, sizeof(struct COFF_filehdr), SEEK_SET) == -1) {
fclose(inputfs);
perror("readfile_coff");
exit(1);
}
if (fseek(inputfs, sizeof(struct COFF_filehdr), SEEK_SET) == -1) {
fclose(inputfs);
perror("readfile_coff");
exit(1);
}
 
if (fread(&coffaouthdr, sizeof(coffaouthdr), 1, inputfs) != 1) {
fclose(inputfs);
perror("readfile_coff");
exit(1);
}
while(sections--) {
long scnhdr_pos = sizeof(struct COFF_filehdr) + sizeof(coffaouthdr)
+ sizeof(struct COFF_scnhdr) * firstthree;
if (fseek(inputfs, scnhdr_pos, SEEK_SET) == -1) {
fclose(inputfs);
perror("readfile_coff");
exit(1);
}
if (fread(&coffscnhdr, sizeof(struct COFF_scnhdr), 1, inputfs) != 1) {
fclose(inputfs);
perror("readfile_coff");
exit(1);
}
printf("Section: %s,", coffscnhdr.s_name);
printf(" paddr: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_paddr));
printf(" vaddr: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_vaddr));
printf(" size: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_size));
printf(" scnptr: 0x%.8x\n", COFF_LONG_H(coffscnhdr.s_scnptr));
sectsize = COFF_LONG_H(coffscnhdr.s_size);
if (fread(&coffaouthdr, sizeof(coffaouthdr), 1, inputfs) != 1) {
fclose(inputfs);
perror("readfile_coff");
exit(1);
}
while(sections--) {
long scnhdr_pos = sizeof(struct COFF_filehdr) + sizeof(coffaouthdr)
+ sizeof(struct COFF_scnhdr) * firstthree;
if (fseek(inputfs, scnhdr_pos, SEEK_SET) == -1) {
fclose(inputfs);
perror("readfile_coff");
exit(1);
}
if (fread(&coffscnhdr, sizeof(struct COFF_scnhdr), 1, inputfs) != 1) {
fclose(inputfs);
perror("readfile_coff");
exit(1);
}
printf("Section: %s,", coffscnhdr.s_name);
printf(" paddr: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_paddr));
printf(" vaddr: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_vaddr));
printf(" size: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_size));
printf(" scnptr: 0x%.8x\n", COFF_LONG_H(coffscnhdr.s_scnptr));
sectsize = COFF_LONG_H(coffscnhdr.s_size);
#if 0
/* A couple of sanity checks. */
if (translate(COFF_LONG_H(coffscnhdr.s_vaddr),&breakpoint) < MEMORY_START) {
printf("Section %s starts out of ", coffscnhdr.s_name);
printf("memory (at %x)\n", COFF_LONG_H(coffscnhdr.s_vaddr));
exit(1);
}
if (translate(COFF_LONG_H(coffscnhdr.s_vaddr) + sectsize,&breakpoint) >
MEMORY_START + MEMORY_LEN) {
printf("Section %s ends out of ", coffscnhdr.s_name);
printf("memory.\n");
exit(1);
}
/* A couple of sanity checks. */
if (translate(COFF_LONG_H(coffscnhdr.s_vaddr),&breakpoint) < MEMORY_START) {
printf("Section %s starts out of ", coffscnhdr.s_name);
printf("memory (at %x)\n", COFF_LONG_H(coffscnhdr.s_vaddr));
exit(1);
}
if (translate(COFF_LONG_H(coffscnhdr.s_vaddr) + sectsize,&breakpoint) >
MEMORY_START + MEMORY_LEN) {
printf("Section %s ends out of ", coffscnhdr.s_name);
printf("memory.\n");
exit(1);
}
#endif
#if 0
if (++firstthree == 1 && strcmp(coffscnhdr.s_name, ".text") != 0) {
printf("First section should be .text (%s instead)\n", coffscnhdr.s_name);
exit(1);
}
if (firstthree == 2 && strcmp(coffscnhdr.s_name, ".data") != 0) {
printf("Second section should be .data (%s instead)\n", coffscnhdr.s_name);
exit(1);
}
if (firstthree == 3 && strcmp(coffscnhdr.s_name, ".bss") != 0) {
printf("Third section should be .bss (%s instead)\n", coffscnhdr.s_name);
exit(1);
}
if (++firstthree == 1 && strcmp(coffscnhdr.s_name, ".text") != 0) {
printf("First section should be .text (%s instead)\n", coffscnhdr.s_name);
exit(1);
}
if (firstthree == 2 && strcmp(coffscnhdr.s_name, ".data") != 0) {
printf("Second section should be .data (%s instead)\n", coffscnhdr.s_name);
exit(1);
}
if (firstthree == 3 && strcmp(coffscnhdr.s_name, ".bss") != 0) {
printf("Third section should be .bss (%s instead)\n", coffscnhdr.s_name);
exit(1);
}
#else
++firstthree;
++firstthree;
#endif
 
/* loading section */
freemem = COFF_LONG_H(coffscnhdr.s_paddr);
debug(2,"Starting to load at 0x%x\n", freemem);
if (fseek(inputfs, COFF_LONG_H(coffscnhdr.s_scnptr), SEEK_SET) == -1) {
fclose(inputfs);
perror("readfile_coff");
exit(1);
}
while (sectsize > 0 && (len = fread(&inputbuf, sizeof(inputbuf), 1, inputfs))) {
insn = COFF_LONG_H(inputbuf);
len = insn_len (insn_decode (insn));
if (len == 2)
{
fseek(inputfs, -2, SEEK_CUR);
debug(8,"readfile_coff: %x 0x%x \n", sectsize, insn >> 16);
}
else
debug(8,"readfile_coff: %x 0x%x \n", sectsize, insn);
addprogram (freemem, insn, &breakpoint);
sectsize -= len;
}
}
if (firstthree < 3) {
printf("One or more missing sections. At least");
printf(" three sections expected (.text, .data, .bss).\n");
exit(1);
}
if (firstthree > 3) {
printf("Warning: one or more extra sections. These");
printf(" sections were handled as .data sections.\n");
}
/* loading section */
freemem = COFF_LONG_H(coffscnhdr.s_paddr);
debug(2,"Starting to load at 0x%x\n", freemem);
if (fseek(inputfs, COFF_LONG_H(coffscnhdr.s_scnptr), SEEK_SET) == -1) {
fclose(inputfs);
perror("readfile_coff");
exit(1);
}
while (sectsize > 0 && (len = fread(&inputbuf, sizeof(inputbuf), 1, inputfs))) {
insn = COFF_LONG_H(inputbuf);
len = insn_len (insn_decode (insn));
if (len == 2)
{
fseek(inputfs, -2, SEEK_CUR);
debug(8,"readfile_coff: %x 0x%x \n", sectsize, insn >> 16);
}
else
debug(8,"readfile_coff: %x 0x%x \n", sectsize, insn);
addprogram (freemem, insn, &breakpoint);
sectsize -= len;
}
}
if (firstthree < 3) {
printf("One or more missing sections. At least");
printf(" three sections expected (.text, .data, .bss).\n");
exit(1);
}
if (firstthree > 3) {
printf("Warning: one or more extra sections. These");
printf(" sections were handled as .data sections.\n");
}
 
fclose(inputfs);
printf("Finished loading COFF.\n");
return;
fclose(inputfs);
printf("Finished loading COFF.\n");
return;
}
 
/* Load symbols from big-endian COFF file. */
316,21 → 316,21
if (COFF_SHORT_H(coffsymhdr.e_type) & COFF_N_TMASK & COFF_STYP_TEXT) {
if (*((unsigned long *)coffsymhdr.e.e.e_zeroes)) {
if (strlen(coffsymhdr.e.e_name) && strlen(coffsymhdr.e.e_name) < 9)
add_label(COFF_LONG_H(coffsymhdr.e_value), coffsymhdr.e.e_name);
debug(8, "[%i] Symbol: %s,", count++, coffsymhdr.e.e_name);
if (strlen(coffsymhdr.e.e_name) && strlen(coffsymhdr.e.e_name) < 9)
add_label(COFF_LONG_H(coffsymhdr.e_value), coffsymhdr.e.e_name);
debug(8, "[%i] Symbol: %s,", count++, coffsymhdr.e.e_name);
} else {
long fpos = ftell (inputfs);
if (fseek(inputfs, symptr + nsyms * COFF_SYMESZ + COFF_LONG_H(coffsymhdr.e.e.e_offset), SEEK_SET) == 0) {
char tmp[33], *s = &tmp[0];
while (s != &tmp[32])
if ((*(s++) = fgetc(inputfs)) == 0) break;
tmp[32] = 0;
add_label(COFF_LONG_H(coffsymhdr.e_value), &tmp[0]);
debug(8, "[%i] Symbol: %s,", count++, &tmp[0]);
}
fseek(inputfs, fpos, SEEK_SET);
long fpos = ftell (inputfs);
if (fseek(inputfs, symptr + nsyms * COFF_SYMESZ + COFF_LONG_H(coffsymhdr.e.e.e_offset), SEEK_SET) == 0) {
char tmp[33], *s = &tmp[0];
while (s != &tmp[32])
if ((*(s++) = fgetc(inputfs)) == 0) break;
tmp[32] = 0;
add_label(COFF_LONG_H(coffsymhdr.e_value), &tmp[0]);
debug(8, "[%i] Symbol: %s,", count++, &tmp[0]);
}
fseek(inputfs, fpos, SEEK_SET);
}
debug(9, " val: 0x%.8x,", COFF_LONG_H(coffsymhdr.e_value));
339,9 → 339,9
 
for (i = 0; i < n; i++)
if (fread(&coffsymhdr, COFF_SYMESZ, 1, inputfs) != 1) {
fclose(inputfs);
perror("readsyms_coff3");
exit(1);
fclose(inputfs);
perror("readsyms_coff3");
exit(1);
}
syms -= n;
count += n;
357,53 → 357,53
 
void identifyfile(char *filename)
{
FILE *inputfs;
struct COFF_filehdr coffhdr;
size_t len;
if (!(inputfs = fopen(filename, "r"))) {
fprintf(stderr, "xx %s", filename);
perror("identifyfile1");
fflush(stdout);
fflush(stderr);
exit(1);
}
if (fread(&coffhdr, sizeof(coffhdr), 1, inputfs) == 1) {
if (COFF_SHORT_H(coffhdr.f_magic) == 0x17a) {
unsigned long opthdr_size;
printf("COFF magic: 0x%.4x\n", COFF_SHORT_H(coffhdr.f_magic));
printf("COFF flags: 0x%.4x\n", COFF_SHORT_H(coffhdr.f_flags));
printf("COFF symptr: 0x%.8x\n", COFF_LONG_H(coffhdr.f_symptr));
if ((COFF_SHORT_H(coffhdr.f_flags) & COFF_F_EXEC) != COFF_F_EXEC) {
printf("This COFF is not an executable.\n");
exit(1);
}
opthdr_size = COFF_SHORT_H(coffhdr.f_opthdr);
if (opthdr_size != sizeof(COFF_AOUTHDR)) {
printf("COFF optional header is missing or not recognized.\n");
printf("COFF f_opthdr: 0x%.2x\n", opthdr_size);
exit(1);
}
fclose(inputfs);
readfile_coff(filename, COFF_SHORT_H(coffhdr.f_nscns));
readsyms_coff(filename, COFF_LONG_H(coffhdr.f_symptr), COFF_LONG_H(coffhdr.f_nsyms));
return;
}
else {
printf("Not COFF, quiting.\n");
fclose(inputfs);
exit (1);
}
}
else {
printf("yy %s", filename);
perror("identifyfile2");
}
fclose(inputfs);
FILE *inputfs;
struct COFF_filehdr coffhdr;
size_t len;
if (!(inputfs = fopen(filename, "r"))) {
fprintf(stderr, "xx %s", filename);
perror("identifyfile1");
fflush(stdout);
fflush(stderr);
exit(1);
}
if (fread(&coffhdr, sizeof(coffhdr), 1, inputfs) == 1) {
if (COFF_SHORT_H(coffhdr.f_magic) == 0x17a) {
unsigned long opthdr_size;
printf("COFF magic: 0x%.4x\n", COFF_SHORT_H(coffhdr.f_magic));
printf("COFF flags: 0x%.4x\n", COFF_SHORT_H(coffhdr.f_flags));
printf("COFF symptr: 0x%.8x\n", COFF_LONG_H(coffhdr.f_symptr));
if ((COFF_SHORT_H(coffhdr.f_flags) & COFF_F_EXEC) != COFF_F_EXEC) {
printf("This COFF is not an executable.\n");
exit(1);
}
opthdr_size = COFF_SHORT_H(coffhdr.f_opthdr);
if (opthdr_size != sizeof(COFF_AOUTHDR)) {
printf("COFF optional header is missing or not recognized.\n");
printf("COFF f_opthdr: 0x%.2x\n", opthdr_size);
exit(1);
}
fclose(inputfs);
readfile_coff(filename, COFF_SHORT_H(coffhdr.f_nscns));
readsyms_coff(filename, COFF_LONG_H(coffhdr.f_symptr), COFF_LONG_H(coffhdr.f_nsyms));
return;
}
else {
printf("Not COFF, quiting.\n");
fclose(inputfs);
exit (1);
}
}
else {
printf("yy %s", filename);
perror("identifyfile2");
}
fclose(inputfs);
 
return;
return;
}
 
 
412,13 → 412,13
{
int breakpoint = 0;
 
transl_error = 0;
transl_table = virtphy_transl;
freemem = startaddr;
printf("loadcode: filename %s startaddr=%x virtphy_transl=%x", filename, startaddr, virtphy_transl);
identifyfile(filename);
if (transl_error)
return -1;
else
return translate(freemem,&breakpoint);
transl_error = 0;
transl_table = virtphy_transl;
freemem = startaddr;
printf("loadcode: filename %s startaddr=%x virtphy_transl=%x", filename, startaddr, virtphy_transl);
identifyfile(filename);
if (transl_error)
return -1;
else
return translate(freemem,&breakpoint);
}
/trunk/or1ksim/testbench/acv_uart.c
256,9 → 256,9
s++;
}
ASSERT (!(getreg (UART_LSR) & LSR_DR));
/* this should break the * char, so it should not be received */
setreg (UART_LCR, LCR_BREAK);
setreg (UART_THR, '*');
/* this should break the current char, so no * should be received */
setreg (UART_LCR, LCR_BREAK);
/* uart should hold line long enough even if we drop it immediately */
setreg (UART_LCR, 0);
NO_ERROR();
/trunk/or1ksim/testbench/acv_uart.cfg
40,7 → 40,7
end
 
section sim
debug = 4
debug = 0
profile = 0
prof_fn = "sim.profile"
/trunk/or1ksim/peripheral/16450.c
238,7 → 238,7
} else if (config.uarts[i].txfile) { /* MM: Try to create stream. */
if (!(uarts[i].rxfs = fopen(config.uarts[i].rxfile, "r"))
&& !(uarts[i].rxfs = fopen(config.uarts[i].rxfile, "r+"))) {
fprintf(stderr, "WARNING: UART%d has problems with RX file stream.\n", i);
debug (0, "WARNING: UART%d has problems with RX file stream.\n", i);
continue;
}
uarts[i].txfs = fopen(config.uarts[i].txfile, "a");
246,7 → 246,7
printf("UART%d at 0x%.8x uses ", i, config.uarts[i].baseaddr);
printf("%s for RX and %s for TX.\n", config.uarts[i].rxfile, config.uarts[i].txfile);
} else
fprintf(stderr, "WARNING: UART%d has problems with TX file stream.\n", i);
debug (1, "WARNING: UART%d has problems with TX file stream.\n", i);
register_memoryarea(config.uarts[i].baseaddr, UART_ADDR_SPACE, 1, uart_read_byte, uart_write_byte);
}
295,15 → 295,15
/* Send to either VAPI or to file */
if (config.uarts[i].vapi_id) {
int par, pe, fe, nbits = (uarts[i].regs.lcr & UART_LCR_WLEN8) + 5;
int i, data;
int j, data;
unsigned long packet = 0;
 
/* Encode a packet */
packet = uarts[i].regs.lcr & ((1 << nbits) - 1);
packet = uarts[i].iregs.txser & ((1 << nbits) - 1);
 
/* Calculate parity */
for (i = 0; i < nbits; i++)
par ^= (packet >> i) & 1;
for (j = 0, par = 0; j < nbits; j++)
par ^= (packet >> j) & 1;
 
if (uarts[i].regs.lcr & UART_LCR_PARITY) {
if (uarts[i].regs.lcr & UART_LCR_SPAR) {
325,8 → 325,8
data = packet & ((1 << nbits) - 1);
/* Calculate parity, including parity bit */
for (i = 0; i < nbits + 1; i++)
par ^= (packet >> i) & 1;
for (j = 0, par = 0; j < nbits + 1; j++)
par ^= (packet >> j) & 1;
if (uarts[i].vapi.lcr & UART_LCR_PARITY) {
if (uarts[i].vapi.lcr & UART_LCR_SPAR) {
341,11 → 341,11
} else
pe = 0;
fe |= ((packet >> (nbits++)) & 1) ^ 1;
fe = ((packet >> (nbits++)) & 1) ^ 1;
if (uarts[i].vapi.lcr & UART_LCR_STOP)
fe |= ((packet >> (nbits++)) & 1) ^ 1;
 
printf ("%08x %08x\n", config.uarts[i].vapi_id, data | (uarts[i].vapi.lcr << 8) | (pe << 16) | (fe << 17));
debug (4, "vapi_send (%08x, %08x)\n", config.uarts[i].vapi_id, data | (uarts[i].vapi.lcr << 8) | (pe << 16) | (fe << 17));
vapi_send (config.uarts[i].vapi_id, data | (uarts[i].vapi.lcr << 8) | (pe << 16) | (fe << 17));
} else {
fputc((int)(uarts[i].iregs.txser & 0xFF), uarts[i].txfs);
385,6 → 385,9
uarts[i].istat.rxser_full = 1;
} else { /* VAPI */
int received = 0;
/* do not handle commands while receiving */
if (uarts[i].istat.rxser_full)
break;
while (!received) {
if (uarts[i].vapi_buf_head_ptr != uarts[i].vapi_buf_tail_ptr) {
unsigned long data = uarts[i].vapi_buf[uarts[i].vapi_buf_tail_ptr];
396,7 → 399,7
uarts[i].vapi.char_clks = char_clks (uarts[i].vapi.dll, uarts[i].vapi.dlh, uarts[i].vapi.lcr);
if (uarts[i].vapi.lcr != uarts[i].regs.lcr || uarts[i].vapi.char_clks != uarts[i].char_clks
|| uarts[i].vapi.skew < -MAX_SKEW || uarts[i].vapi.skew > MAX_SKEW) {
fprintf (stderr, "WARNING: unmatched VAPI and uart modes.\n");
debug (3, "WARNING: unmatched VAPI and uart modes.\n");
/* Set error bits */
uarts[i].regs.lsr |= UART_LSR_PARITY | UART_LSR_FRAME;
break;
411,13 → 414,13
uarts[i].vapi.dlh = (data >> 8) & 0xff;
break;
case 0x02:
uarts[i].vapi.lcr = data & 0xff;
uarts[i].vapi.lcr = (data >> 8) & 0xff;
break;
case 0x03:
uarts[i].vapi.skew = (signed short)(data & 0xffff);
break;
default:
fprintf (stderr, "WARNING: Invalid vapi command %02x\n", data >> 24);
debug (0, "WARNING: Invalid vapi command %02x\n", data >> 24);
break;
}
} else break;
/trunk/or1ksim/vapi/vapi.c
397,12 → 397,13
perror("vapi read");
close(t->fd);
t->fd = 0;
rebuild_fds ();
}
return;
}
 
if (config.vapi.vapi_file)
fprintf (config.vapi.vapi_file, "1%08x\n", data);
if (runtime.vapi.vapi_file)
fprintf (runtime.vapi.vapi_file, "0%08x\n", data);
debug (4, "[%08x, %08x]\n", t->id, data);
if (!t->read_func)
fprintf (stderr, "WARNING: packet sent to undefined id %x, %x\n", t->id, data);
419,7 → 420,7
exit (1);
}
 
debug(4, ".");
debug(5, ".");
 
/* Handle everything in queue. */
while(1) {
480,7 → 481,7
 
rebuild_fds ();
if ((config.vapi.vapi_file = fopen (config.vapi.vapi_fn, "wt+")) == NULL)
if ((runtime.vapi.vapi_file = fopen (config.vapi.vapi_fn, "wt+")) == NULL)
fprintf (stderr, "WARNING: cannot open VAPI log file\n");
 
return 0;
500,8 → 501,11
serverIP = 0;
free (fds);
fds = 0;
if (config.vapi.vapi_file)
fclose (config.vapi.vapi_file);
if (runtime.vapi.vapi_file) {
/* Mark end of simulation */
fprintf (runtime.vapi.vapi_file, "2%08x", 0);
fclose (runtime.vapi.vapi_file);
}
 
while (vapi_handler) {
t = vapi_handler;
558,8 → 562,8
int vapi_send (unsigned long id, unsigned long data)
{
debug (4, "vapi_send [%08x %08x]\n", id, data);
if (config.vapi.vapi_file)
fprintf (config.vapi.vapi_file, "0%08x\n", data);
if (runtime.vapi.vapi_file)
fprintf (runtime.vapi.vapi_file, "1%08x\n", data);
write_packet (id, data);
}
 
/trunk/or1ksim/toplevel.c
52,7 → 52,7
#include "gdbcomm.h"
 
/* CVS revision number. */
const char rcsrev[] = "$Revision: 1.45 $";
const char rcsrev[] = "$Revision: 1.46 $";
 
/* Continuos run versus single step tracing switch. */
int cont_run;
61,24 → 61,9
int histexec[HISTEXEC_LEN];
 
char *sim_commands [] = {
"q",
"t",
"help",
"de",
"dm",
"run",
"pr",
"pm",
"pc",
"reset",
"break",
"hist",
"stats",
"stall"
"info",
"r",
"dv",
0
"q", "t", "help", "de", "dm", "run", "pr", "pm", "pc",
"reset", "break", "hist", "stats", "stall" "info",
"r", "dv", "set", 0
};
 
inline void debug(int level, const char *format, ...)
121,46 → 106,47
 
void version()
{
printf ("\n");
printf ("OpenRISC 1000 (OR16+OR32) Architectural Simulator, %s\n", rcsrev);
printf ("Copyright (C) 1999 Damjan Lampret, lampret@opencores.org\n");
printf ("Copyright (C) 2000 Damjan Lampret, lampret@opencores.org\n");
printf (" Jimmy Chen-Min Chen, jimmy@ee.nctu.edu.tw\n");
printf (" Johan Rydberg, johan.rydberg@insight.se\n");
printf (" Marko Mlinar, markom@opencores.org\n");
printf ("\n");
printf ("OpenRISC 1000 (OR16+OR32) Architectural Simulator, %s\n", rcsrev);
printf ("Copyright (C) 1999 Damjan Lampret, lampret@opencores.org\n");
printf ("Copyright (C) 2000 Damjan Lampret, lampret@opencores.org\n");
printf (" Jimmy Chen-Min Chen, jimmy@ee.nctu.edu.tw\n");
printf (" Johan Rydberg, johan.rydberg@insight.se\n");
printf (" Marko Mlinar, markom@opencores.org\n");
printf ("Copyright (C) 2001 Simon Srot, simons@opencores.org\n");
printf (" Marko Mlinar, markom@opencores.org\n");
printf ("Visit http://www.opencores.org for more information about ");
printf ("OpenRISC 1000 and\nother open source cores.\n\n");
printf ("This software comes with ABSOLUTELY NO WARRANTY; for ");
printf ("details see COPYING.\nThis is free software, and you ");
printf ("are welcome to redistribute it under certain\nconditions; ");
printf ("for details see COPYING.\n");
printf ("Visit http://www.opencores.org for more information about ");
printf ("OpenRISC 1000 and\nother open source cores.\n\n");
printf ("This software comes with ABSOLUTELY NO WARRANTY; for ");
printf ("details see COPYING.\nThis is free software, and you ");
printf ("are welcome to redistribute it under certain\nconditions; ");
printf ("for details see COPYING.\n");
}
 
void
help()
{
printf("q - quit simulator\n");
printf("r - display all registers\n");
printf("t - execute next instruction\n");
printf("run <cycles> [<hush>] - execute <cycles> instructions, no reg dump if hush\n");
printf("pr <r> <value> - patch register <r> with <value>\n");
printf("dm <fromaddr> [<toaddr>] - display memory from <fromaddr> to <toaddr>\n");
printf("de <fromaddr> [<toaddr>] - debug insn memory\n");
printf("pm <addr> <value> - patch memory location <addr> with <value>\n");
printf("pc <value> - patch PC register with <value>\n");
printf("break <addr> - toggle breakpoint at address <addr>\n");
printf("reset - simulator reset\n");
printf("hist - execution history\n");
printf("stall - stalls the processor and gives control to the debugger\n");
printf("stats <num|clear> - execution statistics num or clear it.\n");
printf("info - configuration info (caches etc.)\n");
printf("dv <fromaddr> [<toaddr>] [<modname>] - dumps memory as verilog (use redirect)\n");
printf("dh <fromaddr> [<toaddr>] - dumps memory as hex code (use redirect)\n");
printf("<cmd> > <filename> - redirect simulator stdout to <filename> (and not emulated printf)\n");
printf("debug - toggles simulator debug mode\n");
printf("help - available commands (this list)\n");
printf("q - quit simulator\n");
printf("r - display all registers\n");
printf("t - execute next instruction\n");
printf("run <cycles> [<hush>] - execute <cycles> instructions, no reg dump if hush\n");
printf("pr <r> <value> - patch register <r> with <value>\n");
printf("dm <fromaddr> [<toaddr>] - display memory from <fromaddr> to <toaddr>\n");
printf("de <fromaddr> [<toaddr>] - debug insn memory\n");
printf("pm <addr> <value> - patch memory location <addr> with <value>\n");
printf("pc <value> - patch PC register with <value>\n");
printf("break <addr> - toggle breakpoint at address <addr>\n");
printf("reset - simulator reset\n");
printf("hist - execution history\n");
printf("stall - stalls the processor and gives control to the debugger\n");
printf("stats <num|clear> - execution statistics num or clear it.\n");
printf("info - configuration info (caches etc.)\n");
printf("dv <fromaddr> [<toaddr>] [<modname>] - dumps memory as verilog (use redirect)\n");
printf("dh <fromaddr> [<toaddr>] - dumps memory as hex code (use redirect)\n");
printf("set <section> <item> = <param> - set configuration. See sim.cfg for more information.\n");
printf("<cmd> > <filename> - redirect simulator stdout to <filename> (and not emulated printf)\n");
printf("debug - toggles simulator debug mode\n");
printf("help - available commands (this list)\n");
}
 
void debugmem( unsigned long from, unsigned long to );
170,24 → 156,24
{
init_labels();
init_breakpoints();
initstats();
build_automata();
initstats();
build_automata();
if (GDB_ENABLED)
gdbcomm_init ();
 
if (config.sim.profile) {
config.sim.fprof = fopen(config.sim.prof_fn, "wt+");
if(!config.sim.fprof) {
runtime.sim.fprof = fopen(config.sim.prof_fn, "wt+");
if(!runtime.sim.fprof) {
config.sim.profile = 0;
fprintf(stderr, "WARNING: Problems opening profile file. Profiling disabled. \n");
} else
fprintf(config.sim.fprof, "+00000000 FFFFFFFF FFFFFFFF main\n");
fprintf(runtime.sim.fprof, "+00000000 FFFFFFFF FFFFFFFF main\n");
}
if (config.sim.exe_log) {
config.sim.fexe_log = fopen(config.sim.exe_log_fn, "wt+");
if(!config.sim.fexe_log) {
runtime.sim.fexe_log = fopen(config.sim.exe_log_fn, "wt+");
if(!runtime.sim.fexe_log) {
config.sim.exe_log = 0;
printf("WARNING: Problems opening exe_log file. Execution logging disabled. \n");
}
195,109 → 181,111
 
/* Initialize memory */
{
extern struct dev_memarea *dev_list;
int i;
if (config.memory.type == MT_RANDOM) {
unsigned int val = 0;
extern struct dev_memarea *dev_list;
int i;
if (config.memory.type == MT_RANDOM) {
unsigned int val = 0;
 
if (config.memory.random_seed == -1) {
config.memory.random_seed = time(NULL);
/* Print out the seed just in case we ever need to debug */
printf("Seeding random generator with value %d\n", config.memory.random_seed);
}
srandom(config.memory.random_seed);
printf("Seeding random generator with value %d\n", config.memory.random_seed);
}
srandom(config.memory.random_seed);
 
for (cur_area = dev_list; cur_area; cur_area = cur_area->next)
for (cur_area = dev_list; cur_area; cur_area = cur_area->next)
for(i = 0; i < cur_area->size; i++) {
val = random();
setsim_mem8(i + cur_area->addr_compare, val & 0xFF);
}
} else if(config.memory.type == MT_PATTERN) {
for (cur_area = dev_list; cur_area; cur_area = cur_area->next)
for (cur_area = dev_list; cur_area; cur_area = cur_area->next)
for(i = 0; i < cur_area->size; i++)
setsim_mem8(i + cur_area->addr_compare, config.memory.pattern);
} else if (config.memory.type != MT_UNKNOWN) {
fprintf(stderr, "Invalid memory configuration type.\n");
exit(1);
exit(1);
}
}
 
if(config.filename) {
unsigned long endaddr = 0xFFFFFFFF;
endaddr = loadcode(config.filename, 0, 0); /* MM170901 always load at address zero. */
if (endaddr == -1) {
fprintf(stderr, "Problems loading boot code.\n");
exit(1);
}
}
/* Disable gdb debugging, if debug module is not available. */
if (config.debug.gdb_enabled && !config.debug.enabled) {
config.debug.gdb_enabled = 0;
if (config.sim.verbose)
fprintf (stderr, "WARNING: Debug module not enabled, cannot start gdb.\n");
}
/* Enable dependency stats, if we want to do history analisis */
if (config.cpu.history && !config.cpu.dependency) {
config.cpu.dependency = 1;
if (config.sim.verbose)
fprintf (stderr, "WARNING: dependency stats must be enabled to do history analisis.\n");
}
/* Debug forces verbose */
if (config.sim.debug && !config.sim.verbose) {
config.sim.verbose = 1;
fprintf (stderr, "WARNING: verbose turned on.\n");
}
/* Start VAPI before device initialization. */
if (config.vapi.enabled) {
vapi_init ();
if (config.sim.verbose)
printf ("VAPI started, waiting for clients.\n");
}
uart_reset();
dma_reset();
eth_reset();
tick_reset();
pm_reset();
pic_reset();
mc_reset();
reset();
/* Wait till all test are connected. */
if (config.vapi.enabled) {
int numu = vapi_num_unconnected (0);
if (numu) {
printf ("\nWaiting for VAPI tests with ids:\n");
vapi_num_unconnected (1);
printf ("\n");
while (numu = vapi_num_unconnected (0)) {
vapi_check ();
printf ("\rStill waiting for %i VAPI test(s) to connect. ", numu);
usleep (100);
}
printf ("\n");
}
printf ("All devices connected \n");
}
if(runtime.sim.filename) {
unsigned long endaddr = 0xFFFFFFFF;
endaddr = loadcode(runtime.sim.filename, 0, 0); /* MM170901 always load at address zero. */
if (endaddr == -1) {
fprintf(stderr, "Problems loading boot code.\n");
exit(1);
}
}
/* Disable gdb debugging, if debug module is not available. */
if (config.debug.gdb_enabled && !config.debug.enabled) {
config.debug.gdb_enabled = 0;
if (config.sim.verbose)
fprintf (stderr, "WARNING: Debug module not enabled, cannot start gdb.\n");
}
/* Enable dependency stats, if we want to do history analisis */
if (config.cpu.history && !config.cpu.dependency) {
config.cpu.dependency = 1;
if (config.sim.verbose)
fprintf (stderr, "WARNING: dependency stats must be enabled to do history analisis.\n");
}
/* Debug forces verbose */
if (config.sim.debug && !config.sim.verbose) {
config.sim.verbose = 1;
fprintf (stderr, "WARNING: verbose turned on.\n");
}
/* Start VAPI before device initialization. */
if (config.vapi.enabled) {
vapi_init ();
if (config.sim.verbose)
printf ("VAPI started, waiting for clients.\n");
}
uart_reset();
dma_reset();
eth_reset();
tick_reset();
pm_reset();
pic_reset();
mc_reset();
reset();
/* Wait till all test are connected. */
if (config.vapi.enabled) {
int numu = vapi_num_unconnected (0);
if (numu) {
printf ("\nWaiting for VAPI tests with ids:\n");
vapi_num_unconnected (1);
printf ("\n");
while (numu = vapi_num_unconnected (0)) {
vapi_check ();
printf ("\rStill waiting for %i VAPI test(s) to connect. ", numu);
usleep (100);
}
printf ("\n");
}
printf ("All devices connected \n");
}
/* simulator is initialized */
runtime.sim.init = 0;
}
 
/* Display info about various modules */
void sim_info () {
itlb_status(-1);
dtlb_status(-1);
ic_info();
dc_info();
sprs_status();
if (config.cpu.bpb) bpb_info();
if (config.cpu.btic) btic_info();
if (config.uarts_enabled) uart_status();
if (config.dmas_enabled) dma_status();
if (config.ethernets_enabled) eth_status();
dtlb_status(-1);
ic_info();
dc_info();
sprs_status();
if (config.cpu.bpb) bpb_info();
if (config.cpu.btic) btic_info();
if (config.uarts_enabled) uart_status();
if (config.dmas_enabled) dma_status();
if (config.ethernets_enabled) eth_status();
}
 
/* Cleanup */
305,10 → 293,10
{
if (config.sim.profile) {
extern int cycles;
fprintf(config.sim.fprof,"-%08X FFFFFFFF\n", cycles);
fclose(config.sim.fprof);
fprintf(runtime.sim.fprof,"-%08X FFFFFFFF\n", cycles);
fclose(runtime.sim.fprof);
}
if (config.sim.exe_log) fclose(config.sim.fexe_log);
if (config.sim.exe_log) fclose(runtime.sim.fexe_log);
if (config.vapi.enabled) vapi_done ();
exit(0);
}
317,319 → 305,326
int argc;
char *argv[];
{
char *linestr;
char item1[500], b2[500], prev_str[500] = "";
char *redirstr;
int hush = 0;
int first_prompt = 1;
int trace_fd = 0;
char *linestr;
char item1[500], b2[500], prev_str[500] = "";
char *redirstr;
int hush = 0;
int first_prompt = 1;
int trace_fd = 0;
 
srand(getpid());
init_defconfig();
if (parse_args(argc, argv)) {
printf("Usage: %s [options] <filename>\n", argv[0]);
printf("Options:\n");
printf(" -v version and copyright note\n");
printf(" -i enable interactive command prompt\n");
printf(" -f or --file change script file [sim.cfg]\n");
printf(" --nosrv do not launch JTAG proxy server\n"); /* (CZ) */
printf(" --srv <n> launch JTAG proxy server on port <n>; [random]\n"); /* (CZ) */
printf(" --profile enable profiling\n");
exit(-1);
}
srand(getpid());
init_defconfig();
if (parse_args(argc, argv)) {
printf("Usage: %s [options] <filename>\n", argv[0]);
printf("Options:\n");
printf(" -v version and copyright note\n");
printf(" -i enable interactive command prompt\n");
printf(" -f or --file load script file [sim.cfg]\n");
printf(" --nosrv do not launch JTAG proxy server\n"); /* (CZ) */
printf(" --srv <n> launch JTAG proxy server on port <n>; [random]\n"); /* (CZ) */
printf(" --profile enable profiling\n");
exit(-1);
}
 
#ifdef HAVE_LIBREADLINE
initialize_readline (); /* Bind our completer. */
initialize_readline (); /* Bind our completer. */
#endif
 
/* Read configuration file. */
read_script_file (config.script_file);
if (!runtime.sim.script_file_specified)
read_script_file ("sim.cfg");
print_config();
sim_init ();
signal(SIGINT, ctrl_c);
 
while(1) {
if (config.sim.iprompt) {
if (GDB_ENABLED)
{
printf ("(sim) ");
fflush(stdout);
HandleServerSocket(true); /* block & check_stdin = true */
}
while(1) {
if (config.sim.iprompt) {
if (GDB_ENABLED)
{
printf ("(sim) ");
fflush(stdout);
HandleServerSocket(true); /* block & check_stdin = true */
}
#ifdef HAVE_LIBREADLINE
/* Must disable readline in new mode. It isn't compatible
with non blocking environments */
if(!GDB_ENABLED)
linestr = readline("(sim) ");
else
linestr = fgets(b2, sizeof b2, stdin);
/* Must disable readline in new mode. It isn't compatible
with non blocking environments */
if(!GDB_ENABLED)
linestr = readline("(sim) ");
else
linestr = fgets(b2, sizeof b2, stdin);
#else
if(!GDB_ENABLED)
printf ("(sim) ");
linestr = fgets(b2, sizeof b2, stdin);
if(!GDB_ENABLED)
printf ("(sim) ");
linestr = fgets(b2, sizeof b2, stdin);
#endif
} else
strcpy(linestr = b2, "run -1 hush");
} else
strcpy(linestr = b2, "run -1 hush");
 
if (!linestr)
break;
linestr = stripwhite (linestr);
if (!linestr)
break;
linestr = stripwhite (linestr);
 
#ifdef HAVE_LIBREADLINE
/* Readline only works in the old mode */
if(!server_fd)
{
if (strlen(linestr) == 0) {
char *l = repeat_last_command ();
if (l) {
free (linestr);
linestr = l;
}
}
if (*linestr) {
add_history (linestr);
}
}
/* Readline only works in the old mode */
if(!server_fd)
{
if (strlen(linestr) == 0) {
char *l = repeat_last_command ();
if (l) {
free (linestr);
linestr = l;
}
}
if (*linestr) {
add_history (linestr);
}
}
#endif /* HAVE_LIBREADLINE */
if (redirstr = strstr(linestr, ">")) {
*redirstr = '\0';
strtoken(&redirstr[1], item1, 1);
freopen(item1, "w+", stdout);
}
if (linestr[0] == '\n')
strcpy (linestr, &prev_str[0]);
else
strcpy (&prev_str[0], linestr);
strtoken(linestr, item1, 1);
if (strcmp(item1, "q") == 0) { /* quit */
printf ("\n");
sim_done ();
} else
if (strcmp(item1, "help") == 0) /* help */
help();
else
if (strcmp(item1, "t") == 0) { /* trace */
cont_run = 1;
} else
if (strcmp(item1, "dm") == 0) { /* dump memory */
char item2[20];
char item3[20];
static int from = 0, to = 0;
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
if (strlen(item2)) {
if (item2[0] == '_')
from = eval_label(item2);
else
from = strtoul(item2, NULL, 0);
to = from + 0x40;
}
if (strlen(item3))
to = strtoul(item3, NULL, 0);
dumpmemory(from, to, 0, 1);
printf("\n");
} else
if (strcmp(item1, "dv") == 0) {/* dump memory as verilog*/
char item2[20];
char item3[20];
char item4[20];
static int from = 0, to = 0;
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
strtoken(linestr, item4, 4);
if (strlen(item2)) {
if (item2[0] == '_')
from = eval_label(item2);
else
from = strtoul(item2, NULL, 0);
to = from + 0x40;
}
if (strlen(item3))
to = strtoul(item3, NULL, 0);
if (!strlen(item4))
strcpy(item4, "or1k_mem");
dumpverilog(item4, from, to);
printf("\n");
} else
if (strcmp(item1, "dh") == 0) {/* dump memory as hex*/
char item2[20];
char item3[20];
static int from = 0, to = 0;
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
if (strlen(item2)) {
if (item2[0] == '_')
from = eval_label(item2);
else
from = strtoul(item2, NULL, 0);
to = from + 0x40;
}
if (strlen(item3))
to = strtoul(item3, NULL, 0);
dumphex(from, to);
printf("\n");
} else
if (strcmp(item1, "pm") == 0) { /* patch memory */
char item2[20];
char item3[20];
static int addr = 0;
int breakpoint = 0;
if (redirstr = strstr(linestr, ">")) {
*redirstr = '\0';
strtoken(&redirstr[1], item1, 1);
freopen(item1, "w+", stdout);
}
if (linestr[0] == '\n')
strcpy (linestr, &prev_str[0]);
else
strcpy (&prev_str[0], linestr);
strtoken(linestr, item1, 1);
if (strcmp(item1, "q") == 0) { /* quit */
printf ("\n");
sim_done ();
} else
if (strcmp(item1, "help") == 0) /* help */
help();
else
if (strcmp(item1, "t") == 0) { /* trace */
cont_run = 1;
} else
if (strcmp(item1, "dm") == 0) { /* dump memory */
char item2[20];
char item3[20];
static int from = 0, to = 0;
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
if (strlen(item2)) {
if (item2[0] == '_')
from = eval_label(item2);
else
from = strtoul(item2, NULL, 0);
to = from + 0x40;
}
if (strlen(item3))
to = strtoul(item3, NULL, 0);
dumpmemory(from, to, 0, 1);
printf("\n");
} else
if (strcmp(item1, "dv") == 0) {/* dump memory as verilog*/
char item2[20];
char item3[20];
char item4[20];
static int from = 0, to = 0;
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
strtoken(linestr, item4, 4);
if (strlen(item2)) {
if (item2[0] == '_')
from = eval_label(item2);
else
from = strtoul(item2, NULL, 0);
to = from + 0x40;
}
if (strlen(item3))
to = strtoul(item3, NULL, 0);
if (!strlen(item4))
strcpy(item4, "or1k_mem");
dumpverilog(item4, from, to);
printf("\n");
} else
if (strcmp(item1, "dh") == 0) {/* dump memory as hex*/
char item2[20];
char item3[20];
static int from = 0, to = 0;
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
if (strlen(item2)) {
if (item2[0] == '_')
from = eval_label(item2);
else
from = strtoul(item2, NULL, 0);
to = from + 0x40;
}
if (strlen(item3))
to = strtoul(item3, NULL, 0);
dumphex(from, to);
printf("\n");
} else
if (strcmp(item1, "pm") == 0) { /* patch memory */
char item2[20];
char item3[20];
static int addr = 0;
int breakpoint = 0;
 
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
if (strlen(item2))
if (item2[0] == '_')
addr = eval_label(item2);
else
addr = strtoul(item2, NULL, 0);
set_mem32(addr, strtoul(item3, NULL, 0), &breakpoint);
} else
if (strcmp(item1, "pr") == 0) { /* patch regs */
char item2[20];
char item3[20];
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
set_reg32(strtoul(item2, NULL,0), strtoul(item3, NULL, 0));
} else
if (strcmp(item1, "pc") == 0) { /* patch PC */
char item2[20];
strtoken(linestr, item2, 2);
pcnext = strtoul(item2, NULL, 0);
} else
if (strcmp(item1, "break") == 0) { /* set/clear breakpoint */
char item2[20];
strtoken(linestr, item2, 2);
set_insnbrkpoint(strtoul(item2, NULL, 0));
} else
if (strcmp(item1, "r") == 0) { /* dump regs */
dumpreg();
} else
if (strcmp(item1, "de") == 0) { /* reset simulator */
char item2[20];
char item3[20];
static int from = 0, to = 0;
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
if (strlen(item2)) {
if (item2[0] == '_')
from = eval_label(item2);
else
from = strtoul(item2, NULL, 0);
to = from + 0x40;
}
if (strlen(item3))
to = strtoul(item3, NULL, 0);
debugmem(from, to);
printf("\n");
} else
if (strcmp(item1, "reset") == 0) { /* reset simulator */
uart_reset();
dma_reset();
eth_reset();
tick_reset();
pm_reset();
pic_reset();
reset(); /* Old or new mode */
} else
if (strcmp(item1, "debug") == 0) { /* debug mode */
config.sim.debug ^= 1;
} else
if (strcmp(item1, "hist") == 0) { /* dump history */
int i;
for(i = HISTEXEC_LEN; i; i--)
dumpmemory(histexec[i - 1], histexec[i - 1] + 4, 1, 1);
printf("\n");
} else
if (strcmp(item1, "run") == 0) { /* run */
char item2[20];
char item3[20];
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
if (strcmp(item3, "hush") == 0)
hush = 1;
else
hush = 0;
cont_run = strtol(item2, NULL, 0);
} else
if(!strcmp(item1, "stall")) { /* Added by CZ 210801 */
extern int cpu_stalled; /* CZ from debug_interface */
cpu_stalled = 1;
config.sim.iprompt = 0;
cont_run = -1;
hush = 1;
} else
if (!strcmp(item1, "trace")) { /* Added by CZ 210801 */
char item2[256];
strtoken(linestr, item2, 2);
if(trace_fd)
{
close(trace_fd);
trace_fd = 0;
}
if(strcmp(item2,"off")) /* if we're not being turned off */
{
if(item2[0])
trace_fd = open(item2,O_CREAT | O_NOCTTY |
O_TRUNC | O_WRONLY, 0644);
else
trace_fd = dup(1);
if(trace_fd < 0)
{
perror(item2[0]?item2:"stdout");
trace_fd = 0;
}
}
} else
if (strcmp(item1, "stats") == 0) { /* stats */
char item2[20];
int i = 0;
strtoken(linestr, item2, 2);
if (strcmp(item2, "clear") == 0) {
initstats();
printf("Cleared.\n");
} else {
i = strtoul(item2, NULL, 0);
printstats(i);
}
} else
if (strcmp(item1, "info") == 0) /* configuration info */
sim_info ();
else
printf("%s: Unknown command.\n", linestr);
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
if (strlen(item2))
if (item2[0] == '_')
addr = eval_label(item2);
else
addr = strtoul(item2, NULL, 0);
set_mem32(addr, strtoul(item3, NULL, 0), &breakpoint);
} else
if (strcmp(item1, "pr") == 0) { /* patch regs */
char item2[20];
char item3[20];
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
set_reg32(strtoul(item2, NULL,0), strtoul(item3, NULL, 0));
} else
if (strcmp(item1, "pc") == 0) { /* patch PC */
char item2[20];
strtoken(linestr, item2, 2);
pcnext = strtoul(item2, NULL, 0);
} else
if (strcmp(item1, "break") == 0) { /* set/clear breakpoint */
char item2[20];
strtoken(linestr, item2, 2);
set_insnbrkpoint(strtoul(item2, NULL, 0));
} else
if (strcmp(item1, "r") == 0) { /* dump regs */
dumpreg();
} else
if (strcmp(item1, "de") == 0) { /* reset simulator */
char item2[20];
char item3[20];
static int from = 0, to = 0;
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
if (strlen(item2)) {
if (item2[0] == '_')
from = eval_label(item2);
else
from = strtoul(item2, NULL, 0);
to = from + 0x40;
}
if (strlen(item3))
to = strtoul(item3, NULL, 0);
debugmem(from, to);
printf("\n");
} else
if (strcmp(item1, "reset") == 0) { /* reset simulator */
uart_reset();
dma_reset();
eth_reset();
tick_reset();
pm_reset();
pic_reset();
reset(); /* Old or new mode */
} else
if (strcmp(item1, "debug") == 0) { /* debug mode */
config.sim.debug ^= 1;
} else
if (strcmp(item1, "hist") == 0) { /* dump history */
int i;
for(i = HISTEXEC_LEN; i; i--)
dumpmemory(histexec[i - 1], histexec[i - 1] + 4, 1, 1);
printf("\n");
} else
if (strcmp(item1, "run") == 0) { /* run */
char item2[20];
char item3[20];
strtoken(linestr, item2, 2);
strtoken(linestr, item3, 3);
if (strcmp(item3, "hush") == 0)
hush = 1;
else
hush = 0;
cont_run = strtol(item2, NULL, 0);
} else
if(!strcmp(item1, "stall")) { /* Added by CZ 210801 */
extern int cpu_stalled; /* CZ from debug_interface */
cpu_stalled = 1;
config.sim.iprompt = 0;
cont_run = -1;
hush = 1;
} else
if (!strcmp(item1, "trace")) { /* Added by CZ 210801 */
char item2[256];
strtoken(linestr, item2, 2);
if(trace_fd) {
close(trace_fd);
trace_fd = 0;
}
if(strcmp(item2,"off")) /* if we're not being turned off */
{
if(item2[0])
trace_fd = open(item2,O_CREAT | O_NOCTTY |
O_TRUNC | O_WRONLY, 0644);
else
trace_fd = dup(1);
if(trace_fd < 0) {
perror(item2[0]?item2:"stdout");
trace_fd = 0;
}
}
} else
if (strcmp(item1, "stats") == 0) { /* stats */
char item2[20];
int i = 0;
strtoken(linestr, item2, 2);
if (strcmp(item2, "clear") == 0) {
initstats();
printf("Cleared.\n");
} else {
i = strtoul(item2, NULL, 0);
printstats(i);
}
} else
if (strcmp(item1, "info") == 0) /* configuration info */
sim_info ();
else
if (strcmp(item1, "set") == 0) { /* configuration info */
char *s = linestr;
int i;
extern section;
extern struct section sections[];
while (*s != ' ' && *s) s++;
set_config_command (s);
} else
printf("%s: Unknown command.\n", linestr);
 
 
/* MM: 'run -1' means endless execution. */
while(cont_run != 0) {
int debug_slowdown = DEBUG_SLOWDOWN;
extern int cycle_delay; /* Added by CZ 27/05/01. Set during exception. */
extern int cpu_stalled; /* CZ from debug_interface */
/* MM: 'run -1' means endless execution. */
while(cont_run != 0) {
int debug_slowdown = DEBUG_SLOWDOWN;
extern int cycle_delay; /* Added by CZ 27/05/01. Set during exception. */
extern int cpu_stalled; /* CZ from debug_interface */
 
if (cpu_stalled)
if(GDB_ENABLED) {
BlockJTAG();
HandleServerSocket(false);
continue;
} else
fprintf (stderr, "WARNING: CPU stalled and gdb connection not enabled.");
if(GDB_ENABLED) {
BlockJTAG();
HandleServerSocket(false);
continue;
} else
fprintf (stderr, "WARNING: CPU stalled and gdb connection not enabled.");
 
if (!testsprbits(SPR_PMR, SPR_PMR_DME | SPR_PMR_SME)) {
if(cycle_delay <= 0) {
694,23 → 689,23
if (config.vapi.enabled) vapi_check();
if (GDB_ENABLED && debug_slowdown-- == 0) {
debug_slowdown = DEBUG_SLOWDOWN;
HandleServerSocket(false); /* block & check_stdin = false */
}
}
hush = 0;
fflush(stdout);
freopen("/dev/fd/0", "w+", stdout);
HandleServerSocket(false); /* block & check_stdin = false */
}
}
hush = 0;
fflush(stdout);
freopen("/dev/fd/0", "w+", stdout);
 
if (!config.sim.iprompt) /* non-interactive quit */
sim_done();
if (!config.sim.iprompt) /* non-interactive quit */
sim_done();
 
#ifdef HAVE_LIBREADLINE
if (linestr)
free (linestr);
if (linestr)
free (linestr);
#endif
 
}
sim_done();
}
sim_done();
}
 
#ifdef HAVE_LIBREADLINE
816,6 → 811,6
iqueue[0].insn_index = insn_decode(_insn);
disassemble_insn (_insn);
printf("%08x %s\n", _insn, disassembled);
i += insn_len( iqueue[0].insn_index );
i += insn_len( iqueue[0].insn_index );
}
}
/trunk/or1ksim/sim-config.c
26,9 → 26,11
#include "pic.h"
 
#define WARNING(s) fprintf (stderr, "WARNING: config.%s: %s\n", sections[section], s)
#define ERROR(s) {fprintf (stderr, "ERROR: %s\n", s); exit (1);}
#define ERROR(s) {fprintf (stderr, "ERROR: %s\n", s); if (runtime.sim.init) exit (1);}
 
struct config config;
struct runtime runtime;
 
int section = 0;
extern struct section {
char *name;
40,11 → 42,10
unsigned long val;
memset(&config, 0, sizeof(config));
memset(&runtime, 0, sizeof(runtime));
/* Sim */
config.script_file = "sim.cfg";
config.sim.exe_log = 0;
config.sim.fexe_log = 0;
runtime.sim.fexe_log = NULL;
strcpy (config.sim.exe_log_fn, "executed.log");
config.sim.debug = 0;
52,8 → 53,10
config.sim.iprompt = 0;
config.sim.profile = 0;
config.sim.fprof = 0;
runtime.sim.fprof = NULL;
strcpy (config.sim.prof_fn, "sim.profile");
runtime.sim.init = 1;
runtime.sim.script_file_specified = 0;
/* Memory */
config.memory.type = MT_PATTERN;
91,7 → 94,7
/* VAPI */
config.vapi.enabled = 0;
strcpy (config.vapi.vapi_fn, "vapi.log");
config.vapi.vapi_file = NULL;
runtime.vapi.vapi_file = NULL;
/* Ethernet */
config.ethernets_enabled = 0;
112,13 → 115,13
argv++; argc--;
while (argc) {
if (argc && (*argv[0] != '-')) {
config.filename = argv[0];
runtime.sim.filename = argv[0];
argc--;
argv++;
} else
if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0) {
argv++; argc--;
config.script_file = argv[0];
read_script_file(argv[0]);
argv++; argc--;
} else
if (strcmp(*argv, "--nosrv") == 0) { /* (CZ) */
162,7 → 165,7
#define CNV(x) ((isblank(x) || (x) == 0) ? ' ' : (x))
 
/* Substitute for less powerful fscanf */
int fscanf_ex (FILE *f, char *fmt, void *buf) {
int fscanf_ex (FILE *f, char *fmt, void *buf, char *str) {
char tmp[STR_SIZE];
char ch;
int i = 0;
175,11 → 178,14
if (tmp[i - 1] == 's') {
char *cbuf = (char *)buf;
i = 0;
while (ch = fgetc (f), isblank(ch))
if (feof (f)) return 1;
ungetc (ch, f);
while ((*(cbuf++) = ch = fgetc (f), CNV(ch) ) != *fmt) {
if (feof (f)) return 1;
while (ch = (f ? fgetc (f) : *str++), isblank(ch))
if (f ? feof (f) : *str) return 1;
if (f)
ungetc (ch, f);
else
str--;
while ((*(cbuf++) = ch = (f ? fgetc (f) : *str++), CNV(ch) ) != *fmt) {
if ((f ? feof (f) : *str)) return 1;
if (++i >= STR_SIZE) {
fprintf (stderr, "ERROR: string too long.\n");
return 1;
189,17 → 195,20
fmt++;
} else {
tmp[i++] = 0;
fscanf (f, tmp, buf);
if (f)
fscanf (f, tmp, buf);
else
sscanf (str, tmp, buf);
}
break;
default:
while ((ch = fgetc (f)) != *fmt) {
while ((ch = (f ? fgetc (f) : *str++)) != *fmt) {
if (!isblank (ch)) {
char tmp[200];
sprintf (tmp, "unexpected char '%c' (expecting '%c')\n", ch, *fmt);
WARNING(tmp);
}
if (feof (f)) return 1;
if ((f ? feof (f) : *str)) return 1;
}
fmt++;
break;
210,33 → 219,36
 
void print_config()
{
printf("Machine initialization...\n");
if (testsprbits(SPR_UPR, SPR_UPR_DCP))
printf("Data cache tag: %s\n", config.dc.tagtype == VIRTUAL ? "virtual" : "physical");
else
printf("No data cache.\n");
if (testsprbits(SPR_UPR, SPR_UPR_ICP))
printf("Insn cache tag: %s\n", config.ic.tagtype == VIRTUAL ? "virtual" : "physical");
else
printf("No instruction cache.\n");
/*if (config.cpu.bpb_sim)
printf("BPB simulation on.\n");
else
printf("BPB simulation off.\n");
if (config.cpu.btic_sim)
printf("BTIC simulation on.\n");
else
printf("BTIC simulation off.\n");*/
printf("Clock cycle: %d ns\n", config.clkcycle_ns);
if (config.sim.debug)
printf("simdebug on, ");
else
printf("simdebug off, ");
if (config.sim.iprompt)
printf("interactive prompt on\n");
else
printf("interactive prompt off\n");
if (config.sim.verbose) {
printf("Verbose on, ");
if (config.sim.debug)
printf("simdebug on, ");
else
printf("simdebug off, ");
if (config.sim.iprompt)
printf("interactive prompt on\n");
else
printf("interactive prompt off\n");
printf("Machine initialization...\n");
printf("Clock cycle: %d ns\n", config.clkcycle_ns);
if (testsprbits(SPR_UPR, SPR_UPR_DCP))
printf("Data cache tag: %s\n", config.dc.tagtype == VIRTUAL ? "virtual" : "physical");
else
printf("No data cache.\n");
if (testsprbits(SPR_UPR, SPR_UPR_ICP))
printf("Insn cache tag: %s\n", config.ic.tagtype == VIRTUAL ? "virtual" : "physical");
else
printf("No instruction cache.\n");
if (config.cpu.bpb)
printf("BPB simulation on.\n");
else
printf("BPB simulation off.\n");
if (config.cpu.btic)
printf("BTIC simulation on.\n");
else
printf("BTIC simulation off.\n");
}
}
 
void change_device ();
286,84 → 298,85
/* Parameter definitions */
struct config_params {
int section;
int attr;
char *name;
char *type;
void (*func)();
void *addr;
} config_params[] = {
{1, "enabled", "=%i", NULL, (void *)(&config.mc.enabled)},
{1, "baseaddr", "=0x%x", NULL, (void *)(&config.mc.baseaddr)},
{1, "POC", "=0x%x", NULL, (void *)(&config.mc.POC)},
{2, "enabled", "=%i", NULL, (void *)(&config.uarts_enabled)},
{2, "nuarts", "=%i", NULL, (void *)(&config.nuarts)},
{2, "device", "%i", change_device, (void *)(&tempL)},
{2, "enddevice", "", end_device, NULL},
{2, "baseaddr", "=0x%x", uart_baseaddr, (void *)(&tempUL)},
{2, "irq", "=%i", uart_irq, (void *)(&tempL)},
{2, "16550", "=%i", uart_16550, (void *)(&tempL)},
{2, "jitter", "=%i", uart_jitter, (void *)(&tempL)},
{2, "rxfile", "=\"%s\"", uart_rxfile, (void *)(&tempS[0])},
{2, "txfile", "=\"%s\"", uart_txfile, (void *)(&tempS[0])},
{2, "vapi_id", "=0x%x", uart_vapi_id, (void *)(&tempUL)},
{3, "enabled", "=%i", NULL, (void *)(&config.dmas_enabled)},
{3, "ndmas", "=%i", NULL, (void *)(&config.ndmas)},
{3, "device", "%i", change_device, (void *)(&tempL)},
{3, "enddevice", "", end_device, NULL},
{3, "baseaddr", "=0x%x", dma_baseaddr, (void *)(&tempUL)},
{3, "irq", "=%i", dma_baseaddr, (void *)(&tempL)},
{3, "vapi_id", "=0x%x", dma_vapi_id, (void *)(&tempUL)},
{4, "memory_table_file", "=\"%s\"", NULL, (void *)(&config.memory.memory_table_file[0])},
{4, "random_seed", "=%i", NULL, (void *)(&config.memory.random_seed)},
{4, "pattern", "=%i", NULL, (void *)(&config.memory.pattern)},
{4, "type", "=%s ", memory_type, (void *)(&tempS[0])},
{5, "ver", "=0x%x", NULL, (void *)(&config.cpu.ver)},
{5, "rev", "=0x%x", NULL, (void *)(&config.cpu.rev)},
{5, "upr", "=0x%x", NULL, (void *)(&config.cpu.upr)},
{5, "hazards", "=%i", NULL, (void *)(&config.cpu.hazards)},
{5, "history", "=%i", NULL, (void *)(&config.cpu.history)},
{5, "superscalar", "=%i", NULL, (void *)(&config.cpu.superscalar)},
{5, "dependstats", "=%i", NULL, (void *)(&config.cpu.dependstats)},
{5, "dependency", "=%i", NULL, (void *)(&config.cpu.dependency)},
{5, "slp", "=%i", NULL, (void *)(&config.cpu.slp)},
{5, "bpb", "=%i", NULL, (void *)(&config.cpu.bpb)},
{5, "btic", "=%i", NULL, (void *)(&config.cpu.btic)},
{6, "debug", "=%i", NULL, (void *)(&config.sim.debug)},
{6, "iprompt", "=%i", NULL, (void *)(&config.sim.iprompt)},
{6, "verbose", "=%i", NULL, (void *)(&config.sim.verbose)},
{6, "profile", "=%i", NULL, (void *)(&config.sim.profile)},
{6, "prof_fn", "=\"%s\"", NULL, (void *)(&config.sim.prof_fn[0])},
{6, "exe_log", "=%i", NULL, (void *)(&config.sim.exe_log)},
{6, "exe_log_fn", "=\"%s\"", NULL, (void *)(&config.sim.exe_log_fn[0])},
{7, "enabled", "=%i", NULL, (void *)(&config.debug.enabled)},
{7, "gdb_enabled", "=%i", NULL, (void *)(&config.debug.gdb_enabled)},
{7, "server_port", "=%i", NULL, (void *)(&config.debug.server_port)},
{8, "enabled", "=%i", NULL, (void *)(&config.vapi.enabled)},
{8, "server_port", "=%i", NULL, (void *)(&config.vapi.server_port)},
{8, "log_enabled", "=%i", NULL, (void *)(&config.vapi.log_enabled)},
{8, "vapi_log_fn", "=\"%s\"", NULL, (void *)(&config.vapi.vapi_fn[0])},
{9, "enabled", "=%i", NULL, (void *)(&config.ethernets_enabled)},
{9, "nethernets", "=%i", NULL, (void *)(&config.nethernets)},
{9, "device", "%i", change_device, (void *)(&tempL)},
{9, "enddevice", "", end_device, NULL},
{9, "baseaddr", "=0x%x", eth_baseaddr, (void *)(&tempUL)},
{9, "dma", "=%i", eth_dma, (void *)(&tempL)},
{9, "rx_channel", "=%i", eth_rx_channel,(void *)(&tempL)},
{9, "tx_channel", "=%i", eth_tx_channel,(void *)(&tempL)},
{9, "rxfile", "=\"%s\"", eth_rxfile, (void *)(&tempS[0])},
{9, "txfile", "=\"%s\"", eth_txfile, (void *)(&tempS[0])},
{9, "vapi_id", "=0x%x", eth_vapi_id, (void *)(&tempUL)},
{10, "enabled", "=%i", NULL, (void *)(&config.tick.enabled)},
{10, "irq", "=%i", NULL, (void *)(&config.tick.irq)},
{1, 0, "enabled", "=%i", NULL, (void *)(&config.mc.enabled)},
{1, 0, "baseaddr", "=0x%x", NULL, (void *)(&config.mc.baseaddr)},
{1, 0, "POC", "=0x%x", NULL, (void *)(&config.mc.POC)},
 
{2, 0, "enabled", "=%i", NULL, (void *)(&config.uarts_enabled)},
{2, 0, "nuarts", "=%i", NULL, (void *)(&config.nuarts)},
{2, 0, "device", "%i", change_device, (void *)(&tempL)},
{2, 0, "enddevice", "", end_device, NULL},
{2, 0, "baseaddr", "=0x%x", uart_baseaddr, (void *)(&tempUL)},
{2, 0, "irq", "=%i", uart_irq, (void *)(&tempL)},
{2, 0, "16550", "=%i", uart_16550, (void *)(&tempL)},
{2, 0, "jitter", "=%i", uart_jitter, (void *)(&tempL)},
{2, 0, "rxfile", "=\"%s\"", uart_rxfile, (void *)(&tempS[0])},
{2, 0, "txfile", "=\"%s\"", uart_txfile, (void *)(&tempS[0])},
{2, 0, "vapi_id", "=0x%x", uart_vapi_id, (void *)(&tempUL)},
 
{3, 0, "enabled", "=%i", NULL, (void *)(&config.dmas_enabled)},
{3, 0, "ndmas", "=%i", NULL, (void *)(&config.ndmas)},
{3, 0, "device", "%i", change_device, (void *)(&tempL)},
{3, 0, "enddevice", "", end_device, NULL},
{3, 0, "baseaddr", "=0x%x", dma_baseaddr, (void *)(&tempUL)},
{3, 0, "irq", "=%i", dma_baseaddr, (void *)(&tempL)},
{3, 0, "vapi_id", "=0x%x", dma_vapi_id, (void *)(&tempUL)},
 
{4, 0, "memory_table_file", "=\"%s\"", NULL, (void *)(&config.memory.memory_table_file[0])},
{4, 0, "random_seed", "=%i", NULL, (void *)(&config.memory.random_seed)},
{4, 0, "pattern", "=%i", NULL, (void *)(&config.memory.pattern)},
{4, 0, "type", "=%s ", memory_type, (void *)(&tempS[0])},
 
{5, 0, "ver", "=0x%x", NULL, (void *)(&config.cpu.ver)},
{5, 0, "rev", "=0x%x", NULL, (void *)(&config.cpu.rev)},
{5, 0, "upr", "=0x%x", NULL, (void *)(&config.cpu.upr)},
{5, 0, "hazards", "=%i", NULL, (void *)(&config.cpu.hazards)},
{5, 0, "history", "=%i", NULL, (void *)(&config.cpu.history)},
{5, 0, "superscalar", "=%i", NULL, (void *)(&config.cpu.superscalar)},
{5, 0, "dependstats", "=%i", NULL, (void *)(&config.cpu.dependstats)},
{5, 0, "dependency", "=%i", NULL, (void *)(&config.cpu.dependency)},
{5, 0, "slp", "=%i", NULL, (void *)(&config.cpu.slp)},
{5, 0, "bpb", "=%i", NULL, (void *)(&config.cpu.bpb)},
{5, 0, "btic", "=%i", NULL, (void *)(&config.cpu.btic)},
 
{6, 0, "debug", "=%i", NULL, (void *)(&config.sim.debug)},
{6, 0, "iprompt", "=%i", NULL, (void *)(&config.sim.iprompt)},
{6, 0, "verbose", "=%i", NULL, (void *)(&config.sim.verbose)},
{6, 0, "profile", "=%i", NULL, (void *)(&config.sim.profile)},
{6, 0, "prof_fn", "=\"%s\"", NULL, (void *)(&config.sim.prof_fn[0])},
 
{6, 0, "exe_log", "=%i", NULL, (void *)(&config.sim.exe_log)},
{6, 0, "exe_log_fn", "=\"%s\"", NULL, (void *)(&config.sim.exe_log_fn[0])},
 
{7, 0, "enabled", "=%i", NULL, (void *)(&config.debug.enabled)},
{7, 0, "gdb_enabled", "=%i", NULL, (void *)(&config.debug.gdb_enabled)},
{7, 0, "server_port", "=%i", NULL, (void *)(&config.debug.server_port)},
 
{8, 0, "enabled", "=%i", NULL, (void *)(&config.vapi.enabled)},
{8, 0, "server_port", "=%i", NULL, (void *)(&config.vapi.server_port)},
{8, 0, "log_enabled", "=%i", NULL, (void *)(&config.vapi.log_enabled)},
{8, 0, "vapi_log_fn", "=\"%s\"", NULL, (void *)(&config.vapi.vapi_fn[0])},
 
{9, 0, "enabled", "=%i", NULL, (void *)(&config.ethernets_enabled)},
{9, 0, "nethernets", "=%i", NULL, (void *)(&config.nethernets)},
{9, 0, "device", "%i", change_device, (void *)(&tempL)},
{9, 0, "enddevice", "", end_device, NULL},
{9, 0, "baseaddr", "=0x%x", eth_baseaddr, (void *)(&tempUL)},
{9, 0, "dma", "=%i", eth_dma, (void *)(&tempL)},
{9, 0, "rx_channel", "=%i", eth_rx_channel,(void *)(&tempL)},
{9, 0, "tx_channel", "=%i", eth_tx_channel,(void *)(&tempL)},
{9, 0, "rxfile", "=\"%s\"", eth_rxfile, (void *)(&tempS[0])},
{9, 0, "txfile", "=\"%s\"", eth_txfile, (void *)(&tempS[0])},
{9, 0, "vapi_id", "=0x%x", eth_vapi_id, (void *)(&tempUL)},
 
{10,0, "enabled", "=%i", NULL, (void *)(&config.tick.enabled)},
{10,0, "irq", "=%i", NULL, (void *)(&config.tick.irq)},
};
 
/* *INDENT-ON* */
603,7 → 616,7
/* Parse parameter value */
{
if (config_params[found].type[0])
if(fscanf_ex (f, config_params[found].type, config_params[found].addr))
if(fscanf_ex (f, config_params[found].type, config_params[found].addr, 0))
exit (1);
}
if (config_params[found].func)
617,4 → 630,81
 
/* Initialize memory table. */
sim_read_memory_table (config.memory.memory_table_file);
runtime.sim.script_file_specified = 1;
}
 
/* Utility for execution of set sim command. */
static int set_config (char *s)
{
char *sec, *item, *params;
int noparams = 0, i, noitem = 0;
while (*s && isblank (*s)) s++;
sec = s;
printf ("s:%s\n", s);
while (*s && *s != ' ') s++;
if (!(*s)) noitem = 1;
*s = 0;
printf ("sec:%s\n", sec);
section = 0;
for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
if (strcmp (sections[i].name, sec) == 0) {
section = i;
break;
}
 
if (!section) return 1;
if (noitem) return 2;
item = ++s;
 
while (*s && *s != ' ') s++;
if (!(*s)) {
noparams = 1;
params = "";
} else
params = s + 1;
*s = 0;
printf ("item:%s\n", item);
printf ("params:%s\n", params);
{
int i, found = -1;
for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
if (config_params[i].section == section && strcmp (config_params[i].name, item) == 0) {
found = i;
break;
}
if (found < 0) return 2;
/* Parse parameter value */
if (config_params[found].type[0])
if(fscanf_ex (0, config_params[found].type, config_params[found].addr, params))
return 3;
if (config_params[found].func)
config_params[found].func();
}
return 0;
}
 
/* Executes set sim command, displays error. */
void set_config_command(char *s)
{
int i;
switch (set_config (s)) {
case 1:
printf ("Invalid or missing section name. One of valid sections must be specified:\n");
for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
printf ("%s ", sections[i].name);
printf ("\n");
break;
case 2:
printf ("Invalid or missing item name. One of valid items must be specified:\n");
for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
if (config_params[i].section == section)
printf ("%s ", config_params[i].name);
printf ("\n");
break;
case 3:
printf ("Invalid parameters specified.\n");
break;
}
}

powered by: WebSVN 2.1.0

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