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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [sim/] [memory.c] - Diff between revs 25 and 91

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 25 Rev 91
Line 28... Line 28...
static unsigned int memSize;
static unsigned int memSize;
static FILE *romImage;
static FILE *romImage;
static unsigned int romSize;
static unsigned int romSize;
static FILE *progImage;
static FILE *progImage;
static unsigned int progSize;
static unsigned int progSize;
 
static unsigned int progAddr;
 
 
 
 
Word memoryReadWord(Word pAddr) {
Word memoryReadWord(Word pAddr) {
  Word data;
  Word data;
 
 
Line 206... Line 207...
    mem[i] = rand();
    mem[i] = rand();
  }
  }
  cPrintf("%6d MB RAM installed", memSize / M);
  cPrintf("%6d MB RAM installed", memSize / M);
  if (progImage != NULL) {
  if (progImage != NULL) {
    fseek(progImage, 0, SEEK_SET);
    fseek(progImage, 0, SEEK_SET);
    if (fread(mem, progSize, 1, progImage) != 1) {
    if (fread(mem + progAddr, progSize, 1, progImage) != 1) {
      error("cannot read program image file");
      error("cannot read program image file");
    }
    }
    cPrintf(", %d bytes loaded", progSize);
    cPrintf(", %d bytes loaded", progSize);
  }
  }
  cPrintf(".\n");
  cPrintf(".\n");
Line 228... Line 229...
}
}
 
 
 
 
void memoryInit(unsigned int memorySize,
void memoryInit(unsigned int memorySize,
                char *progImageName,
                char *progImageName,
 
                unsigned int loadAddr,
                char *romImageName) {
                char *romImageName) {
  /* allocate RAM */
  /* allocate RAM */
  memSize = memorySize;
  memSize = memorySize;
  mem = malloc(memSize);
  mem = malloc(memSize);
  if (mem == NULL) {
  if (mem == NULL) {
Line 247... Line 249...
    if (progImage == NULL) {
    if (progImage == NULL) {
      error("cannot open program file '%s'", progImageName);
      error("cannot open program file '%s'", progImageName);
    }
    }
    fseek(progImage, 0, SEEK_END);
    fseek(progImage, 0, SEEK_END);
    progSize = ftell(progImage);
    progSize = ftell(progImage);
    if (progSize > memSize) {
    progAddr = loadAddr;
      error("program file too big");
    if (progAddr + progSize > memSize) {
 
      error("program file or load address too big");
    }
    }
    /* do actual loading of image in memoryReset() */
    /* do actual loading of image in memoryReset() */
  }
  }
  /* allocate ROM */
  /* allocate ROM */
  rom = malloc(ROM_SIZE);
  rom = malloc(ROM_SIZE);

powered by: WebSVN 2.1.0

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