Line 178... |
Line 178... |
if (!found_error) {
|
if (!found_error) {
|
fprintf (stderr, "ERROR: Overlapping memory area(s):\n");
|
fprintf (stderr, "ERROR: Overlapping memory area(s):\n");
|
fprintf (stderr, "\taddr & %08x == %08x to %08x, size %08x, gran %iB\n", addr_mask, addr_compare, addr_compare | bit_mask (size), size, granularity);
|
fprintf (stderr, "\taddr & %08x == %08x to %08x, size %08x, gran %iB\n", addr_mask, addr_compare, addr_compare | bit_mask (size), size, granularity);
|
}
|
}
|
found_error = 1;
|
found_error = 1;
|
printf ("and\taddr & %08x == %08x to %08x, size %08x, gran %iB\n", (*pptmp)->addr_mask, (*pptmp)->addr_compare,
|
fprintf (stderr, "and\taddr & %08x == %08x to %08x, size %08x, gran %iB\n", (*pptmp)->addr_mask, (*pptmp)->addr_compare,
|
(*pptmp)->addr_compare | (*pptmp)->size_mask, (*pptmp)->size, (*pptmp)->granularity);
|
(*pptmp)->addr_compare | (*pptmp)->size_mask, (*pptmp)->size, (*pptmp)->granularity);
|
}
|
}
|
|
|
if (found_error)
|
if (found_error)
|
exit (-1);
|
exit (-1);
|
Line 547... |
Line 547... |
|
|
void simmem_write_byte(unsigned long addr, unsigned long value) {
|
void simmem_write_byte(unsigned long addr, unsigned long value) {
|
simmem[cur_area->misc + (addr & cur_area->size_mask)].data = (unsigned char)value;
|
simmem[cur_area->misc + (addr & cur_area->size_mask)].data = (unsigned char)value;
|
}
|
}
|
|
|
/* Initialize memory table from a file. Syntax:
|
unsigned long simmem_read_zero(unsigned long addr) {
|
start_address1 length1 type1 [ce1 [delayr1 [delayw1]]]
|
if (config.sim.verbose)
|
start_address2 length2 type2 [ce2 [delayr2 [delayw2]]]
|
fprintf (stderr, "WARNING: memory read from non-read memory area 0x%08x.\n", addr);
|
start_address3 length3 type3 [ce3 [delayr3 [delayw3]]]
|
return 0;
|
|
}
|
Example:
|
|
00000100 00001F00 flash 3 100
|
void simmem_write_null(unsigned long addr, unsigned long value) {
|
80000000 00010000 RAM
|
if (config.sim.verbose)
|
*/
|
fprintf (stderr, "WARNING: memory write to 0x%08x, non-write memory area (value 0x%08x).\n", addr, value);
|
void sim_read_memory_table (char *filename)
|
}
|
|
|
|
/* Initialize memory table from a config struct */
|
|
|
|
void init_memory_table ()
|
{
|
{
|
FILE *f;
|
|
unsigned long memory_needed = 0;
|
unsigned long memory_needed = 0;
|
char *home = getenv("HOME");
|
/* If nothing was defined, use default memory block */
|
char ctmp[256];
|
if (config.memory.nmemories) {
|
int local = 1;
|
int i;
|
int gce = -1;
|
for (i = 0; i < config.memory.nmemories; i++) {
|
sprintf(ctmp, "%s/.or1k/%s", home, filename);
|
unsigned long start = config.memory.table[i].baseaddr;
|
if ((f = fopen (filename, "rt")) != NULL
|
unsigned long length = config.memory.table[i].size;
|
|| home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
|
char *type = config.memory.table[i].name;
|
unsigned long start, length;
|
int rd = config.memory.table[i].delayr;
|
char type[100];
|
int wd = config.memory.table[i].delayw;
|
int nparam;
|
int ce = config.memory.table[i].ce;
|
int rd, wd, ce;
|
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
printf ("Reading memory table from '%s':\n", local ? filename : ctmp);
|
debug (1, "%08X %08X (%i KB): %s (activated by CE%i; read delay = %icyc, write delay = %icyc)\n",
|
while ((nparam = fscanf (f, ">%08x %08x %s %i %i %i\n", &start, &length, &type, &ce, &rd, &wd)) >= 3 && nparam <= 6) {
|
|
if (nparam < 4)
|
|
ce = gce + 1;
|
|
if (nparam < 5)
|
|
rd = 1;
|
|
if (nparam < 6)
|
|
wd = 1;
|
|
|
|
gce = ce;
|
|
printf ("%08X %08X (%i KB): %s (activated by CE%i; read delay = %icyc, write delay = %icyc)\n",
|
|
start, length, length >> 10, type, ce, rd, wd);
|
start, length, length >> 10, type, ce, rd, wd);
|
register_memoryarea(start, length, 1, &simmem_read_byte, &simmem_write_byte);
|
register_memoryarea(start, length, 1, &simmem_read_byte, &simmem_write_byte);
|
cur_area->misc = memory_needed;
|
cur_area->misc = memory_needed;
|
|
cur_area->delayw = wd;
|
|
cur_area->delayr = rd;
|
memory_needed += cur_area->size;
|
memory_needed += cur_area->size;
|
}
|
}
|
fclose (f);
|
|
printf ("\n");
|
printf ("\n");
|
} else {
|
} else {
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
fprintf (stderr, "WARNING: Cannot read memory table from '%s',\nneither '%s', assuming standard configuration.\n", filename, ctmp);
|
fprintf (stderr, "WARNING: Memory not defined, assuming standard configuration.\n");
|
register_memoryarea(DEFAULT_MEMORY_START, DEFAULT_MEMORY_LEN, 1, &simmem_read_byte, &simmem_write_byte);
|
register_memoryarea(DEFAULT_MEMORY_START, DEFAULT_MEMORY_LEN, 1, &simmem_read_byte, &simmem_write_byte);
|
memory_needed += cur_area->size;
|
memory_needed += cur_area->size;
|
}
|
}
|
|
|
simmem = (struct mem_entry *) malloc (sizeof (struct mem_entry) * memory_needed);
|
simmem = (struct mem_entry *) malloc (sizeof (struct mem_entry) * memory_needed);
|
Line 604... |
Line 597... |
fprintf (stderr, "Failed to allocate sim memory. Aborting\n");
|
fprintf (stderr, "Failed to allocate sim memory. Aborting\n");
|
exit (-1);
|
exit (-1);
|
}
|
}
|
}
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|
|
/* Changes read/write memory in read/write only */
|
|
|
|
void lock_memory_table ()
|
|
{
|
|
struct dev_memarea *ptmp;
|
|
|
|
/* Check list of registered devices. */
|
|
for(ptmp = dev_list; ptmp; ptmp = ptmp->next) {
|
|
if (ptmp->delayr < 0 && ptmp->readfunc == &simmem_read_byte)
|
|
ptmp->readfunc = &simmem_read_zero;
|
|
if (ptmp->delayw < 0 && ptmp->writefunc == &simmem_write_byte)
|
|
ptmp->writefunc = &simmem_write_null;
|
|
}
|
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|