Subversion Repositories freemyipod

Rev

Rev 450 | Rev 491 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 450 Rev 466
Line 146... Line 146...
146
#endif
146
#endif
147
 
147
 
148
 
148
 
149
int verbose = 0;      /* extra output when running */
149
int verbose = 0;      /* extra output when running */
150
int pic_with_got = 0; /* do elf/got processing with PIC code */
150
int pic_with_got = 0; /* do elf/got processing with PIC code */
151
int load_to_ram = 0;  /* instruct loader to allocate everything into RAM */
151
int load_to_ram = 1;  /* instruct loader to allocate everything into RAM */
152
int ktrace = 0;       /* instruct loader output kernel trace on load */
152
int ktrace = 0;       /* instruct loader output kernel trace on load */
153
int docompress = 0;   /* 1 = compress everything, 2 = compress data only */
153
int docompress = 0;   /* 1 = compress everything */
-
 
154
int lib = 0;          /* 1 = this is a shared library */
154
int use_resolved = 0; /* If true, get the value of symbol references from */
155
int use_resolved = 0; /* If true, get the value of symbol references from */
155
		      /* the program contents, not from the relocation table. */
156
		      /* the program contents, not from the relocation table. */
156
		      /* In this case, the input ELF file must be already */
157
		      /* In this case, the input ELF file must be already */
157
		      /* fully resolved (using the `-q' flag with recent */
158
		      /* fully resolved (using the `-q' flag with recent */
158
		      /* versions of GNU ld will give you a fully resolved */
159
		      /* versions of GNU ld will give you a fully resolved */
Line 1588... Line 1589...
1588
static void usage(void)
1589
static void usage(void)
1589
{
1590
{
1590
    fprintf(stderr, "Usage: %s [vrzd] [-p <abs-pic-file>] [-s stack-size] "
1591
    fprintf(stderr, "Usage: %s [vrzd] [-p <abs-pic-file>] [-s stack-size] "
1591
	"[-o <output-file>] <elf-file>\n\n"
1592
	"[-o <output-file>] <elf-file>\n\n"
1592
	"       -v              : verbose operation\n"
1593
	"       -v              : verbose operation\n"
1593
	"       -r              : force load to RAM\n"
-
 
1594
	"       -k              : enable kernel trace on load (for debug)\n"
1594
	"       -l              : the file to be processed is a shared library\n"
1595
	"       -z              : compress code/data/relocs\n"
1595
	"       -z              : compress code/data/relocs\n"
1596
	"       -d              : compress data/relocs\n"
-
 
1597
	"       -a              : use existing symbol references\n"
1596
	"       -a              : use existing symbol references\n"
1598
	"                         instead of recalculating from\n"
1597
	"                         instead of recalculating from\n"
1599
	"                         relocation info\n"
1598
	"                         relocation info\n"
1600
    "       -R reloc-file   : read relocations from a separate file\n"
1599
    "       -R reloc-file   : read relocations from a separate file\n"
1601
	"       -p abs-pic-file : GOT/PIC processing with files\n"
1600
	"       -p abs-pic-file : GOT/PIC processing with files\n"
Line 1667... Line 1666...
1667
  stack = 4096;
1666
  stack = 4096;
1668
#else /* We need plenty of stack for both of them (Aggregate and Register) */
1667
#else /* We need plenty of stack for both of them (Aggregate and Register) */
1669
  stack = 0x2020;
1668
  stack = 0x2020;
1670
#endif
1669
#endif
1671
 
1670
 
1672
  while ((opt = getopt(argc, argv, "avzdrkp:s:o:R:")) != -1) {
1671
  while ((opt = getopt(argc, argv, "avzlp:s:o:R:")) != -1) {
1673
    switch (opt) {
1672
    switch (opt) {
1674
    case 'v':
1673
    case 'v':
1675
      verbose++;
1674
      verbose++;
1676
      break;
1675
      break;
1677
    case 'r':
1676
    case 'l':
1678
      load_to_ram++;
-
 
1679
      break;
1677
      lib = 1;
1680
    case 'k':
-
 
1681
      ktrace++;
-
 
1682
      break;
1678
      break;
1683
    case 'z':
1679
    case 'z':
1684
      docompress = 1;
1680
      docompress = 1;
1685
      break;
1681
      break;
1686
    case 'd':
-
 
1687
      docompress = 2;
-
 
1688
      break;
-
 
1689
    case 'p':
1682
    case 'p':
1690
      pfile = optarg;
1683
      pfile = optarg;
1691
      break;
1684
      break;
1692
    case 'o':
1685
    case 'o':
1693
      ofile = optarg;
1686
      ofile = optarg;
Line 1709... Line 1702...
1709
      usage();
1702
      usage();
1710
      break;
1703
      break;
1711
    }
1704
    }
1712
  }
1705
  }
1713
  
1706
  
1714
  /*
-
 
1715
   * if neither the -r or -p options was given,  default to
-
 
1716
   * a RAM load as that is the only option that makes sense.
-
 
1717
   */
-
 
1718
  if (!load_to_ram && !pfile)
-
 
1719
    load_to_ram = 1;
-
 
1720
 
1707
 
1721
  fname = argv[argc-1];
1708
  fname = argv[argc-1];
1722
 
1709
 
1723
  if (pfile) {
1710
  if (pfile) {
1724
    pic_with_got = 1;
1711
    pic_with_got = 1;
Line 1863... Line 1850...
1863
 
1850
 
1864
  text_offs = real_address_bits(text_vma);
1851
  text_offs = real_address_bits(text_vma);
1865
 
1852
 
1866
  /* Fill in the binflt_flat header */
1853
  /* Fill in the binflt_flat header */
1867
  memcpy(hdr.signature, "emCOexec", 8);
1854
  memcpy(hdr.signature, "emCOexec", 8);
1868
  hdr.version = EMCOREAPP_HEADER_VERSION;
1855
  hdr.version = EMCOREAPP_HEADER_VERSION;
1869
  hdr.textstart = sizeof(hdr);
1856
  hdr.textstart = sizeof(hdr);
1870
  hdr.textsize = text_len + data_len;
1857
  hdr.textsize = text_len + data_len;
1871
  hdr.bsssize = bss_len;
1858
  hdr.bsssize = bss_len;
1872
  hdr.stacksize = stack;
1859
  hdr.stacksize = stack;
1873
  hdr.entrypoint = bfd_get_start_address(abs_bfd);
1860
  hdr.entrypoint = bfd_get_start_address(abs_bfd);
1874
  hdr.relocstart = sizeof(hdr) + text_len + data_len;
1861
  hdr.relocstart = sizeof(hdr) + text_len + data_len;
1875
  hdr.reloccount = reloc_len;
1862
  hdr.reloccount = reloc_len;
1876
  hdr.flags = docompress ? EMCOREAPP_FLAG_COMPRESSED : 0;
1863
  hdr.flags = (docompress ? EMCOREAPP_FLAG_COMPRESSED : 0)
-
 
1864
            | (lib ? EMCOREAPP_FLAG_LIBRARY : 0);
1877
  hdr.creationtime = (uint32_t)time(NULL);
1865
  hdr.creationtime = (uint32_t)time(NULL);
1878
 
1866
 
1879
  for (i=0; i<reloc_len; i++) reloc[i] = reloc[i];
1867
  for (i=0; i<reloc_len; i++) reloc[i] = reloc[i];
1880
 
1868
 
1881
  if (verbose) {
1869
  if (verbose) {
1882
    printf("SIZE: .text=0x%04x, .data=0x%04x, .bss=0x%04x",
1870
    printf("SIZE: .text=0x%04x, .data=0x%04x, .bss=0x%04x",
Line 1887... Line 1875...
1887
  }
1875
  }
1888
  
1876
  
1889
  if (!ofile) {
1877
  if (!ofile) {
1890
    ofile = xmalloc(strlen(fname) + 10 + 1); /* 10 to add suffix */
1878
    ofile = xmalloc(strlen(fname) + 10 + 1); /* 10 to add suffix */
1891
    strcpy(ofile, fname);
1879
    strcpy(ofile, fname);
-
 
1880
    if (lib) strcat(ofile, ".emcorelib");
1892
    strcat(ofile, ".emcoreapp");
1881
    else strcat(ofile, ".emcoreapp");
1893
  }
1882
  }
1894
 
1883
 
1895
  if ((fd = open (ofile, O_WRONLY|O_BINARY|O_CREAT|O_TRUNC, 0744)) < 0)
1884
  if ((fd = open (ofile, O_WRONLY|O_BINARY|O_CREAT|O_TRUNC, 0744)) < 0)
1896
    fatal_perror("Can't open output file %s", ofile);
1885
    fatal_perror("Can't open output file %s", ofile);
1897
 
1886