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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [cpu/] [common/] [parse.c] - Diff between revs 897 and 997

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

Rev 897 Rev 997
Line 138... Line 138...
static unsigned int translate(unsigned int laddr,int* breakpoint)
static unsigned int translate(unsigned int laddr,int* breakpoint)
{
{
  int i;
  int i;
 
 
  /* No translation (i.e. when loading kernel into simulator)
  /* No translation (i.e. when loading kernel into simulator)
/*  printf("transl_table=%x  laddr=%x\n", transl_table, laddr);
/*  PRINTF("transl_table=%x  laddr=%x\n", transl_table, laddr);
  printf("laddr=%x\n", laddr);*/
  PRINTF("laddr=%x\n", laddr);*/
  if (transl_table == 0)
  if (transl_table == 0)
    return laddr;
    return laddr;
 
 
  /* Try to find our translation in the table. */
  /* Try to find our translation in the table. */
  for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
  for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
    if ((laddr & ~(PAGE_SIZE - 1)) == evalsim_mem32(transl_table + i)) {
    if ((laddr & ~(PAGE_SIZE - 1)) == evalsim_mem32(transl_table + i)) {
      setsim_mem32(transl_table + i + 8, -2); /* Page modified */
      setsim_mem32(transl_table + i + 8, -2); /* Page modified */
      printf("found paddr=%x\n", evalsim_mem32(transl_table + i + 4) | (laddr & (PAGE_SIZE - 1)));
      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));
      return (unsigned long)evalsim_mem32(transl_table + i + 4) | (laddr & (unsigned long)(PAGE_SIZE - 1));
    }
    }
 
 
  /* Allocate new phy page for us. */
  /* Allocate new phy page for us. */
  for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
  for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
    if (evalsim_mem32(transl_table + i + 8) == 0) {
    if (evalsim_mem32(transl_table + i + 8) == 0) {
      setsim_mem32(transl_table + i, laddr & ~(PAGE_SIZE - 1)); /* VPN */
      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 + 4, (i/16) * PAGE_SIZE); /* PPN */
      setsim_mem32(transl_table + i + 8, -2); /* Page modified */
      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)evalsim_mem32(transl_table + i + 4));
      printf("newly allocated .ppn=%x\n", (unsigned long)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 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)));
      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));
      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
  /* If we come this far then all phy memory is used and we can't find our page
     nor allocate new page. */
     nor allocate new page. */
  transl_error = 1;
  transl_error = 1;
 
 
  printf("can't translate\n", laddr);
  PRINTF("can't translate\n", laddr);
  exit(1);
  exit(1);
  return -1;
  return -1;
}
}
 
 
#if IMM_STATS
#if IMM_STATS
Line 225... Line 225...
            if (!dis) data = tmp;
            if (!dis) data = tmp;
            if (strcmp (name, "l.movhi") == 0) {
            if (strcmp (name, "l.movhi") == 0) {
              movhi = data << 16;
              movhi = data << 16;
            } else {
            } else {
              data |= movhi;
              data |= movhi;
              //printf ("%08x %s\n", data, name);
              //PRINTF ("%08x %s\n", data, name);
              if (!(or32_opcodes[insn_index].flags & OR32_IF_DELAY)) {
              if (!(or32_opcodes[insn_index].flags & OR32_IF_DELAY)) {
                bcnt[bits(data)][0]++; bsum[0]++;
                bcnt[bits(data)][0]++; bsum[0]++;
              } else {
              } else {
                if (strcmp (name, "l.bf") == 0 || strcmp (name, "l.bnf") == 0) {
                if (strcmp (name, "l.bf") == 0 || strcmp (name, "l.bnf") == 0) {
                  bcnt[bits(data)][1]++; bsum[1]++;
                  bcnt[bits(data)][1]++; bsum[1]++;
Line 312... Line 312...
    if (fread(&coffscnhdr, sizeof(struct COFF_scnhdr), 1, inputfs) != 1) {
    if (fread(&coffscnhdr, sizeof(struct COFF_scnhdr), 1, inputfs) != 1) {
      fclose(inputfs);
      fclose(inputfs);
      perror("readfile_coff");
      perror("readfile_coff");
      exit(1);
      exit(1);
    }
    }
    printf("Section: %s,", coffscnhdr.s_name);
    PRINTF("Section: %s,", coffscnhdr.s_name);
    printf(" paddr: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_paddr));
    PRINTF(" paddr: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_paddr));
    printf(" vaddr: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_vaddr));
    PRINTF(" vaddr: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_vaddr));
    printf(" size: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_size));
    PRINTF(" size: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_size));
    printf(" scnptr: 0x%.8x\n", COFF_LONG_H(coffscnhdr.s_scnptr));
    PRINTF(" scnptr: 0x%.8x\n", COFF_LONG_H(coffscnhdr.s_scnptr));
 
 
    sectsize = COFF_LONG_H(coffscnhdr.s_size);
    sectsize = COFF_LONG_H(coffscnhdr.s_size);
#if 0
#if 0
    /* A couple of sanity checks. */
    /* A couple of sanity checks. */
    if (translate(COFF_LONG_H(coffscnhdr.s_vaddr),&breakpoint) < MEMORY_START) {
    if (translate(COFF_LONG_H(coffscnhdr.s_vaddr),&breakpoint) < MEMORY_START) {
      printf("Section %s starts out of ", coffscnhdr.s_name);
      PRINTF("Section %s starts out of ", coffscnhdr.s_name);
      printf("memory (at %x)\n", COFF_LONG_H(coffscnhdr.s_vaddr));
      PRINTF("memory (at %x)\n", COFF_LONG_H(coffscnhdr.s_vaddr));
      exit(1);
      exit(1);
    }
    }
    if (translate(COFF_LONG_H(coffscnhdr.s_vaddr) + sectsize,&breakpoint) >
    if (translate(COFF_LONG_H(coffscnhdr.s_vaddr) + sectsize,&breakpoint) >
        MEMORY_START + MEMORY_LEN) {
        MEMORY_START + MEMORY_LEN) {
      printf("Section %s ends out of ", coffscnhdr.s_name);
      PRINTF("Section %s ends out of ", coffscnhdr.s_name);
      printf("memory.\n");
      PRINTF("memory.\n");
      exit(1);
      exit(1);
    }
    }
#endif
#endif
#if 0
#if 0
    if (++firstthree == 1 && strcmp(coffscnhdr.s_name, ".text") != 0) {
    if (++firstthree == 1 && strcmp(coffscnhdr.s_name, ".text") != 0) {
      printf("First section should be .text (%s instead)\n", coffscnhdr.s_name);
      PRINTF("First section should be .text (%s instead)\n", coffscnhdr.s_name);
      exit(1);
      exit(1);
    }
    }
    if (firstthree == 2 && strcmp(coffscnhdr.s_name, ".data") != 0) {
    if (firstthree == 2 && strcmp(coffscnhdr.s_name, ".data") != 0) {
      printf("Second section should be .data (%s instead)\n", coffscnhdr.s_name);
      PRINTF("Second section should be .data (%s instead)\n", coffscnhdr.s_name);
      exit(1);
      exit(1);
    }
    }
    if (firstthree == 3 && strcmp(coffscnhdr.s_name, ".bss") != 0) {
    if (firstthree == 3 && strcmp(coffscnhdr.s_name, ".bss") != 0) {
      printf("Third section should be .bss (%s instead)\n", coffscnhdr.s_name);
      PRINTF("Third section should be .bss (%s instead)\n", coffscnhdr.s_name);
      exit(1);
      exit(1);
    }
    }
#else
#else
    ++firstthree;
    ++firstthree;
#endif
#endif
Line 373... Line 373...
      addprogram (freemem, insn, &breakpoint);
      addprogram (freemem, insn, &breakpoint);
      sectsize -= len;
      sectsize -= len;
    }
    }
  }
  }
  if (firstthree < 3) {
  if (firstthree < 3) {
    printf("One or more missing sections. At least");
    PRINTF("One or more missing sections. At least");
    printf(" three sections expected (.text, .data, .bss).\n");
    PRINTF(" three sections expected (.text, .data, .bss).\n");
    exit(1);
    exit(1);
  }
  }
  if (firstthree > 3) {
  if (firstthree > 3) {
    printf("Warning: one or more extra sections. These");
    PRINTF("Warning: one or more extra sections. These");
    printf(" sections were handled as .data sections.\n");
    PRINTF(" sections were handled as .data sections.\n");
  }
  }
 
 
  fclose(inputfs);
  fclose(inputfs);
  printf("Finished loading COFF.\n");
  PRINTF("Finished loading COFF.\n");
  return;
  return;
}
}
 
 
/* Load symbols from big-endian COFF file. */
/* Load symbols from big-endian COFF file. */
 
 
Line 457... Line 457...
    syms -= n;
    syms -= n;
    count += n;
    count += n;
  }
  }
 
 
  fclose(inputfs);
  fclose(inputfs);
  printf("Finished loading symbols.\n");
  PRINTF("Finished loading symbols.\n");
  return;
  return;
}
}
 
 
void readfile_elf(char *filename)
void readfile_elf(char *filename)
{
{
Line 595... Line 595...
      }
      }
 
 
 
 
 
 
      if (ELF_LONG_H(elf_spnt->sh_name) && s_str)
      if (ELF_LONG_H(elf_spnt->sh_name) && s_str)
        printf("Section: %s,", &s_str[ELF_LONG_H(elf_spnt->sh_name)]);
        PRINTF("Section: %s,", &s_str[ELF_LONG_H(elf_spnt->sh_name)]);
      else
      else
        printf("Section: noname,");
        PRINTF("Section: noname,");
      printf(" vaddr: 0x%.8x,", ELF_LONG_H(elf_spnt->sh_addr));
      PRINTF(" vaddr: 0x%.8x,", ELF_LONG_H(elf_spnt->sh_addr));
      printf(" paddr: 0x%.8x,", padd);
      PRINTF(" paddr: 0x%.8x,", padd);
      printf(" offset: 0x%.8x,", ELF_LONG_H(elf_spnt->sh_offset));
      PRINTF(" offset: 0x%.8x,", ELF_LONG_H(elf_spnt->sh_offset));
      printf(" size: 0x%.8x\n", ELF_LONG_H(elf_spnt->sh_size));
      PRINTF(" size: 0x%.8x\n", ELF_LONG_H(elf_spnt->sh_size));
 
 
      freemem = padd;
      freemem = padd;
      sectsize = ELF_LONG_H(elf_spnt->sh_size);
      sectsize = ELF_LONG_H(elf_spnt->sh_size);
 
 
      if (fseek(inputfs, ELF_LONG_H(elf_spnt->sh_offset), SEEK_SET) != 0) {
      if (fseek(inputfs, ELF_LONG_H(elf_spnt->sh_offset), SEEK_SET) != 0) {
Line 657... Line 657...
  }
  }
 
 
  if (fread(&coffhdr, sizeof(coffhdr), 1, inputfs) == 1) {
  if (fread(&coffhdr, sizeof(coffhdr), 1, inputfs) == 1) {
    if (COFF_SHORT_H(coffhdr.f_magic) == 0x17a) {
    if (COFF_SHORT_H(coffhdr.f_magic) == 0x17a) {
          unsigned long opthdr_size;
          unsigned long opthdr_size;
      printf("COFF magic: 0x%.4x\n", COFF_SHORT_H(coffhdr.f_magic));
      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 flags: 0x%.4x\n", COFF_SHORT_H(coffhdr.f_flags));
      printf("COFF symptr: 0x%.8x\n", COFF_LONG_H(coffhdr.f_symptr));
      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) {
      if ((COFF_SHORT_H(coffhdr.f_flags) & COFF_F_EXEC) != COFF_F_EXEC) {
        printf("This COFF is not an executable.\n");
        PRINTF("This COFF is not an executable.\n");
        exit(1);
        exit(1);
      }
      }
      opthdr_size = COFF_SHORT_H(coffhdr.f_opthdr);
      opthdr_size = COFF_SHORT_H(coffhdr.f_opthdr);
      if (opthdr_size != sizeof(COFF_AOUTHDR)) {
      if (opthdr_size != sizeof(COFF_AOUTHDR)) {
        printf("COFF optional header is missing or not recognized.\n");
        PRINTF("COFF optional header is missing or not recognized.\n");
        printf("COFF f_opthdr: 0x%.2x\n", opthdr_size);
        PRINTF("COFF f_opthdr: 0x%.2x\n", opthdr_size);
        exit(1);
        exit(1);
      }
      }
      fclose(inputfs);
      fclose(inputfs);
      readfile_coff(filename, COFF_SHORT_H(coffhdr.f_nscns));
      readfile_coff(filename, COFF_SHORT_H(coffhdr.f_nscns));
      readsyms_coff(filename, COFF_LONG_H(coffhdr.f_symptr), COFF_LONG_H(coffhdr.f_nsyms));
      readsyms_coff(filename, COFF_LONG_H(coffhdr.f_symptr), COFF_LONG_H(coffhdr.f_nsyms));
      return;
      return;
    }
    }
    else {
    else {
      printf("Not COFF file format\n");
      PRINTF("Not COFF file format\n");
      fseek(inputfs, 0, SEEK_SET);
      fseek(inputfs, 0, SEEK_SET);
    }
    }
  }
  }
  if (fread(&elfhdr, sizeof(elfhdr), 1, inputfs) == 1) {
  if (fread(&elfhdr, sizeof(elfhdr), 1, inputfs) == 1) {
    if (elfhdr.e_ident[0] == 0x7f && elfhdr.e_ident[1] == 0x45 && elfhdr.e_ident[2] == 0x4c && elfhdr.e_ident[3] == 0x46) {
    if (elfhdr.e_ident[0] == 0x7f && elfhdr.e_ident[1] == 0x45 && elfhdr.e_ident[2] == 0x4c && elfhdr.e_ident[3] == 0x46) {
      printf("ELF type: 0x%.4x\n", ELF_SHORT_H(elfhdr.e_type));
      PRINTF("ELF type: 0x%.4x\n", ELF_SHORT_H(elfhdr.e_type));
      printf("ELF machine: 0x%.4x\n", ELF_SHORT_H(elfhdr.e_machine));
      PRINTF("ELF machine: 0x%.4x\n", ELF_SHORT_H(elfhdr.e_machine));
      printf("ELF version: 0x%.8x\n", ELF_LONG_H(elfhdr.e_version));
      PRINTF("ELF version: 0x%.8x\n", ELF_LONG_H(elfhdr.e_version));
      printf("ELF sec = %d\n", ELF_SHORT_H(elfhdr.e_shnum));
      PRINTF("ELF sec = %d\n", ELF_SHORT_H(elfhdr.e_shnum));
      if (ELF_SHORT_H(elfhdr.e_type) != ET_EXEC ) {
      if (ELF_SHORT_H(elfhdr.e_type) != ET_EXEC ) {
        printf("This ELF is not an executable.\n");
        PRINTF("This ELF is not an executable.\n");
        exit(1);
        exit(1);
      }
      }
      fclose(inputfs);
      fclose(inputfs);
      readfile_elf(filename);
      readfile_elf(filename);
      return;
      return;
    }
    }
    else {
    else {
      printf("Not ELF file format.\n");
      PRINTF("Not ELF file format.\n");
      fseek(inputfs, 0, SEEK_SET);
      fseek(inputfs, 0, SEEK_SET);
    }
    }
  }
  }
 
 
  perror("identifyfile2");
  perror("identifyfile2");
Line 715... Line 715...
  int breakpoint = 0;
  int breakpoint = 0;
 
 
  transl_error = 0;
  transl_error = 0;
  transl_table = virtphy_transl;
  transl_table = virtphy_transl;
  freemem = startaddr;
  freemem = startaddr;
  printf("loadcode: filename %s  startaddr=%x  virtphy_transl=%x\n", filename, startaddr, virtphy_transl);
  PRINTF("loadcode: filename %s  startaddr=%x  virtphy_transl=%x\n", filename, startaddr, virtphy_transl);
  identifyfile(filename);
  identifyfile(filename);
 
 
#if IMM_STATS  
#if IMM_STATS  
  {
  {
    int i = 0, a = 0, b = 0, c = 0;
    int i = 0, a = 0, b = 0, c = 0;
    printf ("index:arith/branch/jump\n");
    PRINTF ("index:arith/branch/jump\n");
    for (i = 0; i < 33; i++) printf ("%2i:\t%3.0f%% / %3.0f%%/ %3.0f%%\t%5i / %5i / %5i\n", i, 100.* (a += bcnt[i][0])/bsum[0],
    for (i = 0; i < 33; i++) PRINTF ("%2i:\t%3.0f%% / %3.0f%%/ %3.0f%%\t%5i / %5i / %5i\n", i, 100.* (a += bcnt[i][0])/bsum[0],
        100.* (b += bcnt[i][1])/bsum[1], 100.* (c += bcnt[i][2])/bsum[2], bcnt[i][0], bcnt[i][1], bcnt[i][2]);
        100.* (b += bcnt[i][1])/bsum[1], 100.* (c += bcnt[i][2])/bsum[2], bcnt[i][0], bcnt[i][1], bcnt[i][2]);
    printf ("\nsum %i %i %i\n", bsum[0], bsum[1], bsum[2]);
    PRINTF ("\nsum %i %i %i\n", bsum[0], bsum[1], bsum[2]);
  }
  }
#endif
#endif
 
 
  if (transl_error)
  if (transl_error)
    return -1;
    return -1;

powered by: WebSVN 2.1.0

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