Changeset 144


Ignore:
Timestamp:
May 15, 2003, 4:25:00 PM (22 years ago)
Author:
zap
Message:

Removed EMX.DLL dependency and EMXL.EXE dependency.

Location:
trunk/src/emx/src/emxbind
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/emxbind/cmd.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r143 r144  
    2727
    2828
    29 /* Alter the emx options of a bound executable. */
    30 
    31 static void alter (void)
    32 {
    33   set_options ();
    34   my_seek (&inp_file, patch_pos);
    35   my_write (&dos_bind_h, sizeof (dos_bind_h), &inp_file);
    36   my_seek (&inp_file, a_in_pos + a_in_data);
    37   my_write (&os2_bind_h, sizeof (os2_bind_h), &inp_file);
    38 }
    39 
    40 
    4129/* Perform initializations for the bind operation. */
    4230
     
    6452
    6553
    66 /* Show the emx options of a bound executable. */
    67 
    68 static void show (void)
    69 {
    70   if (dos_bind_h.options[0] != 0)
    71     printf ("emx options for MS-DOS: %s\n", (char *)dos_bind_h.options);
    72   if (os2_bind_h.options[0] != 0)
    73     printf ("emx options for OS/2:   %s\n", (char *)os2_bind_h.options);
    74 }
    75 
    76 
    7754/* Strip the symbols from a bound executable. */
    7855
     
    9673
    9774
    98 /* Update emxl.exe or emx.exe in a bound executable. */
    99 
    100 static void update (void)
    101 {
    102   long size, i;
    103   byte *buf;
    104 
    105   read_os2_header ();
    106   set_exe_header ();
    107   i = (inp_os2_pos & 0xfff) - (os2_hdr_pos & 0xfff);
    108   if (i != 0)
    109     {
    110       if (i < 0)
    111         i += 0x1000;
    112       os2_hdr_pos += i; fill2 += i;
    113     }
    114   out_h2.new_lo = LOWORD (os2_hdr_pos);
    115   out_h2.new_hi = HIWORD (os2_hdr_pos);
    116   size = my_size (&inp_file) - inp_os2_pos - sizeof (os2_h);
    117   a_out_pos = a_in_pos - inp_os2_pos + os2_hdr_pos;
    118   os2_h.enum_offset += os2_hdr_pos - inp_os2_pos;
    119   if (os2_h.nonresname_size != 0)
    120     os2_h.nonresname_offset += os2_hdr_pos - inp_os2_pos;
    121   dos_bind_h.hdr_loc_lo = LOWORD (a_out_pos);
    122   dos_bind_h.hdr_loc_hi = HIWORD (a_out_pos);
    123   os2_bind_h.heap_off += os2_hdr_pos - inp_os2_pos;
    124   memmove (dos_bind_h.hdr, emx_bind_h.hdr, sizeof (dos_bind_h.hdr));
    125   buf = xmalloc (size);
    126   my_seek (&inp_file, inp_os2_pos + sizeof (os2_h));
    127   my_read (buf, size, &inp_file);
    128   my_change (&out_file, &inp_file);
    129   write_header ();
    130   my_write (&os2_h, sizeof (os2_h), &out_file);
    131   my_write (buf, size, &out_file);
    132   my_trunc (&out_file);
    133   write_bind_header ();
    134 }
    135 
    136 
    137 /* Extract the a.out subfile of a bound executable. */
    138 
    139 static void extract (void)
    140 {
    141   long hdr_loc, size;
    142 
    143   hdr_loc = COMBINE (dos_bind_h.hdr_loc_lo, dos_bind_h.hdr_loc_hi);
    144   size = my_size (&inp_file) - hdr_loc;
    145   my_seek (&inp_file, hdr_loc);
    146   copy (&inp_file, size);
    147 }
    148 
    149 
    15075void cmd (int mode)
    15176{
    15277  switch (mode)
    15378    {
    154     case 'a':
    155 
    156       /* Alter emxbind options. */
    157 
    158       check_bound ();
    159       alter ();
    160       break;
    161 
    16279    case 'b':
    16380
     
    16683      init_bind ();
    16784      init_os2_header ();
    168       read_emx ();
     85      read_stub ();
    16986      read_a_out_header ();
    17087      if (opt_c != NULL)
     
    17693      set_exe_header ();
    17794      set_os2_header ();
    178       set_dos_bind_header ();
    17995      write_header ();
    18096      write_res ();
    18197      copy_a_out ();
    18298      write_nonres ();
    183       write_bind_header ();
    18499      if (opt_m != NULL)
    185100        write_map (opt_m);
     
    190105      /* Set the OS/2 application type. */
    191106
    192       check_bound ();
    193107      exe_type ();
    194       break;
    195 
    196 #if LIST_OPT
    197     case 'L':
    198 
    199       /* List the headers. */
    200 
    201       check_bound ();
    202       list ();
    203       break;
    204 #endif
    205     case 'i':
    206 
    207       /* Show the emxbind options. */
    208 
    209       check_bound ();
    210       show ();
    211108      break;
    212109
     
    215112      /* Strip symbols. */
    216113
    217       check_bound ();
    218114      strip_symbols ();
    219       break;
    220 
    221     case 'u':
    222 
    223       /* Update emxl.exe or emx.exe in a bound executable. */
    224 
    225       read_emx ();
    226 
    227       /* Call check_bound() *after* read_emx() as it needs dos_bind_h! */
    228 
    229       check_bound ();
    230       update ();
    231       break;
    232 
    233     case 'x':
    234 
    235       /* Extract the a.out file of a bound executable. */
    236 
    237       check_bound ();
    238       extract ();
    239115      break;
    240116
  • trunk/src/emx/src/emxbind/emxbind.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r143 r144  
    4242                     "Copyright (c) 1991-1997 by Eberhard Mattes";
    4343
    44 /* These strings contain the valid option letters of the DOS and OS/2
    45    versions of emx, respectively.  Depending on the string in which an
    46    option is found, the option is put into the DOS or OS/2 emxbind
    47    header.  Option letters which don't appear in any of the strings
    48    are invalid. */
    49 
    50 static char *valid_dos_options = "CLRZacdehopqst";
    51 static char *valid_os2_options = "EKchnqtx";
    52 
    53 /* File names of various files.  inp_fname holds the name of the input
    54    executable, emx_fname the name of the emxl.exe or emx.exe file, and
     44/* File names of various files.  inp_fname holds the name of the
     45   input executable, stub_fname the name of the DOS stub file and
    5546   def_fname the name of the module definition file (-d option). */
    5647
    5748static char inp_fname[FNAME_SIZE];
    58 static char emx_fname[FNAME_SIZE];
     49static char stub_fname[FNAME_SIZE];
    5950static char def_fname[FNAME_SIZE];
    6051
     
    6556static char **gargv;
    6657
    67 /* Automatically locate emxl.exe if this flag is true.  Otherwise, use
    68    the path name given on the command line. */
    69 
    70 static int auto_emxl = FALSE;
    71 
    72 /* The file name given by the STUB statement. */
    73 
    74 static char *stub_fname = NULL;
    75 
    7658
    7759/* Give the user a short reminder about how to call this program. */
     
    8163  puts (title);
    8264  puts ("\nUsage:");
    83   puts ("  emxbind [-b] [<options>] <emx>[.exe] <input> [<output>[.exe]] [<emx_opt>]");
    84   puts ("  emxbind [-b] [<options>] [-o <output>[.exe]] <input> [<emx_opt>]");
    85   puts ("  emxbind -u [<options>] <emx>[.exe] <input>[.exe]");
     65  puts ("  emxbind [-b] [<options>] <stub>[.exe] <input> [<output>[.exe]]");
     66  puts ("  emxbind [-b] [<options>] [-o <output>[.exe]] <input>");
    8667  puts ("  emxbind -e [<options>] <input>[.exe]");
    8768  puts ("  emxbind -s [<options>] <input>[.exe]");
    88   puts ("  emxbind -x [<options>] <input>[.exe] <output>");
    89   puts ("  emxbind -i [<options>] <input>[.exe]");
    90   puts ("  emxbind -a [<options>] <input>[.exe] [<emx_opt>]");
    91 #if LIST_OPT
    92   puts ("  emxbind -L [<options>] <input>[.exe]");
    93 #endif
    9469  puts ("\nCommands:");
    9570  puts ("  -b          bind .exe (default)");
    96   puts ("  -u          update emx in .exe");
    9771  puts ("  -e          set OS/2 .exe flags: -f, -p or -w");
    9872  puts ("  -s          strip symbols");
    99   puts ("  -x          extract a.out");
    100   puts ("  -i          show options");
    101   puts ("  -a          alter options");
    102 #if LIST_OPT
    103   puts ("  -L          list headers");
    104 #endif
    10573  puts ("\nOptions:");
    10674  puts ("  -f          application type: full screen (-b and -e)");
     
    11078  puts ("  -v          be verbose");
    11179  puts ("  -s          strip symbols (-b only)");
    112   puts ("  -C          use old method for creating preloaded executables");
    11380  puts ("  -c[<core>]  add data from core dump file (-b only)");
    11481  puts ("  -d[<def>]   read module definition file (-b only)");
    115   puts ("  -E<dll>     use <dll> instead of emx.dll (-b only)");
    11682  puts ("  -h<size>    set heap size for OS/2 (-b only)");
    11783  puts ("  -k<size>    set stack size for OS/2 (-b only)");
     
    270236
    271237      if (!stmt->stub.none)
    272         stub_fname = xstrdup (stmt->stub.name);
     238        _strncpy (stub_fname, stmt->stub.name, sizeof (stub_fname));
    273239      break;
    274240
     
    343309
    344310
    345 /* Scan the remaining command line arguments as emx options and store
    346    them to options_for_dos and options_for_os2. */
    347 
    348 static void emx_options (void)
    349 {
    350   char c;
    351   int dos_flag, os2_flag;
    352   int i, index_dos, index_os2;
    353   char *array_dos[100];
    354   char *array_os2[100];
    355 
    356   /* Collect the options in array_dos and array_os2. */
    357 
    358   index_dos = index_os2 = 0;
    359   while (optind < gargc)
    360     {
    361       if (gargv[optind][0] != '-')
    362         error ("emx option expected");
    363       c = gargv[optind][1];
    364       dos_flag = (strchr (valid_dos_options, c) != NULL);
    365       os2_flag = (strchr (valid_os2_options, c) != NULL);
    366       if (!dos_flag && !os2_flag)
    367         {
    368           if (verbosity > 0) puts (title);
    369           error ("invalid emx option: %s", gargv[optind]);
    370         }
    371       if (dos_flag)
    372         {
    373           for (i = 0; i < index_dos; ++i)
    374             if (memcmp (array_dos[i], gargv[optind],
    375                         gargv[optind][1] == 'R' ? 3 : 2) == 0)
    376               break;
    377           if (i >= index_dos)
    378             i = index_dos++;
    379           array_dos[i] = gargv[optind];
    380         }
    381       if (os2_flag)
    382         {
    383           for (i = 0; i < index_os2; ++i)
    384             if (memcmp (array_os2[i], gargv[optind], 2) == 0)
    385               break;
    386           if (i >= index_os2)
    387             i = index_os2++;
    388           array_os2[i] = gargv[optind];
    389         }
    390       ++optind;
    391     }
    392 
    393   /* Concatenate the options for DOS. */
    394 
    395   options_for_dos[0] = 0;
    396   for (i = 0; i < index_dos; ++i)
    397     {
    398       if (strlen (options_for_dos) + strlen (array_dos[i])
    399           > sizeof (options_for_dos) - 3)
    400         {
    401           if (verbosity > 0) puts (title);
    402           error ("too many emx options for MS-DOS");
    403         }
    404       if (options_for_dos[0] != 0)
    405         strcat (options_for_dos, " ");
    406       strcat (options_for_dos, array_dos[i]);
    407     }
    408 
    409   /* Concatenate the options for OS/2. */
    410 
    411   options_for_os2[0] = 0;
    412   for (i = 0; i < index_os2; ++i)
    413     {
    414       if (strlen (options_for_os2) + strlen (array_os2[i])
    415           > sizeof (options_for_os2) - 3)
    416         {
    417           if (verbosity > 0) puts (title);
    418           error ("too many emx options for OS/2");
    419         }
    420       if (options_for_os2[0] != 0)
    421         strcat (options_for_os2, " ");
    422       strcat (options_for_os2, array_os2[i]);
    423     }
    424 }
    425 
    426 
    427311/* Parse the command line. */
    428312
     
    450334
    451335  while ((c = getopt (gargc, gargv,
    452                       "abc::Cd::eE:fh:ik:lLm:o:pqr:suvwx")) != -1)
     336                      "bc::d::fh:k:m:o:pqr:svw")) != -1)
    453337    {
    454338      switch (c)
    455339        {
    456340        case 's':
    457           if (mode == 'b')
    458             {
    459               opt_s = TRUE;
    460               break;
    461             }
    462           /*NOBREAK*/
    463         case 'a':
     341          /* -s after -b selects 'strip on bind' mode.
     342             -s without -b selects the 'strip in a executable' mode */
     343          if (mode == 'b')
     344          {
     345            opt_s = TRUE;
     346            break;
     347          }
    464348        case 'b':
    465349        case 'e':
    466 #if LIST_OPT
    467         case 'L':
    468 #endif
    469         case 'i':
    470         case 'u':
    471         case 'x':
    472350          if (mode != 0)
    473351            error ("multiple commands specified");
     
    479357          opt_c = (optarg != NULL ? optarg : "");
    480358          break;
    481         case 'C':
    482           old_heap = TRUE;
    483           break;
    484359        case 'd':
    485360          if (opt_d != NULL)
     
    487362          opt_d = (optarg != NULL ? optarg : "");
    488363          break;
    489         case 'E':
    490           if (emx_dll != NULL)
    491             error ("multiple -E options");
    492           emx_dll = optarg;
    493           break;
    494364        case 'f':
    495365          opt_f = TRUE;
     
    567437    opt_c = "core";
    568438
     439  /* Set the default path to the DOS stub */
     440  _execname (stub_fname, sizeof (stub_fname));
     441  strcpy (_getname (stub_fname), "os2stub.bin");
     442
    569443  /* If the -E option is not given and the name is not given by the
    570444     EMXBIND_DLL environment variable, "emx.dll" will be used. */
    571445
    572   if (emx_dll == NULL)
    573     emx_dll = getenv ("EMXBIND_DLL");
    574   if (emx_dll == NULL)
    575     emx_dll = "emx";
    576 
    577446  /* Parse the rest of the command line, depending on the command
    578447     option. */
    579448
    580449  switch (mode)
    581     {
    582     case 'a':
    583       file_name (inp_fname, "exe", NULL);
    584       emx_options ();
    585       break;
    586 
     450  {
    587451    case 'b':
    588452      if (gargc - optind <= 1 || gargv[optind+1][0] == '-')
    589         auto_emxl = TRUE;
     453        ;
    590454      else if (opt_o != NULL)
    591455        error ("Too many file names specified");
    592456      else
    593         file_name (emx_fname, "exe", NULL);
     457        file_name (stub_fname, "exe", NULL);
    594458      file_name (inp_fname, NULL, NULL);
    595459      if (opt_d != NULL)
     
    605469          read_def_file ();
    606470        }
    607       if (auto_emxl)
    608         {
    609           if (stub_fname != NULL)
    610             {
    611               if (_path (emx_fname, stub_fname) != 0)
    612                 _strncpy (emx_fname, stub_fname, sizeof (emx_fname));
    613               auto_emxl = FALSE;
    614             }
    615           else
    616             {
    617               strcpy (emx_fname, "\\emx\\bin\\emxl.exe");
    618               if (!my_readable (emx_fname))
    619                 if (_path (emx_fname, "emxl.exe") != 0)
    620                   strcpy (emx_fname, "emxl.exe");
    621               auto_emxl = TRUE;
    622             }
    623         }
    624471      file_name (out_fname, (dll_flag ? "dll" : "exe"),
    625472                 (opt_o != NULL ? opt_o : inp_fname));
    626473      if (_fncmp (inp_fname, out_fname) == 0)
    627474        error ("The input and output files have the same name");
    628       emx_options ();
    629475      break;
    630476
    631477    case 'e':
    632     case 'L':
    633     case 'i':
    634478    case 's':
    635479      file_name (inp_fname, "exe", NULL);
    636480      break;
    637 
    638     case 'u':
    639       file_name (emx_fname, "exe", NULL);
    640       file_name (inp_fname, "exe", NULL);
    641       break;
    642 
    643     case 'x':
    644       file_name (inp_fname, "exe", NULL);
    645       file_name (out_fname, NULL, NULL);
    646       if (_fncmp (inp_fname, out_fname) == 0)
    647         error ("The input and output files have the same name");
    648       break;
    649     }
     481  }
    650482
    651483  /* Complain if there are any unprocessed arguments left. */
     
    670502  switch (mode)
    671503    {
    672     case 'a':
    673     case 'e':
    674     case 's':
    675       my_open (&inp_file, inp_fname, open_read_write);
    676       break;
    677504    case 'b':
    678505      my_open (&inp_file, inp_fname, open_read);
    679       my_open (&emx_file, emx_fname, open_read);
     506      my_open (&stub_file, stub_fname, open_read);
    680507      if (opt_c != NULL)
    681508        my_open (&core_file, opt_c, open_read);
     
    684511      my_open (&out_file, out_fname, create_write);
    685512      break;
    686     case 'L':
    687     case 'i':
    688       my_open (&inp_file, inp_fname, open_read);
    689       break;
    690     case 'u':
     513    case 'e':
     514    case 's':
    691515      my_open (&inp_file, inp_fname, open_read_write);
    692       my_open (&emx_file, emx_fname, open_read);
    693       break;
    694     case 'x':
    695       my_open (&inp_file, inp_fname, open_read);
    696       my_open (&out_file, out_fname, create_write);
    697516      break;
    698517    }
     
    706525  my_close (&out_file);
    707526  my_close (&inp_file);
    708   my_close (&emx_file);
     527  my_close (&stub_file);
    709528  my_close (&core_file);
    710529  my_close (&res_file);
     
    732551     path name of emxl.exe. */
    733552
    734   if (verbosity >= 2 && auto_emxl)
    735     printf ("Loader program for DOS: %s\n", emx_fname);
     553  if (verbosity >= 2)
     554    printf ("Loader program for DOS: %s\n", stub_fname);
    736555
    737556  /* Open the files. */
  • trunk/src/emx/src/emxbind/emxbind.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r143 r144  
    3131/* By default, don't implement the -L option (for listing the headers
    3232   of an EXE file). */
    33 
    34 #if !defined (LIST_OPT)
    35 #define LIST_OPT FALSE
    36 #endif
    3733
    3834/* This is the version number. */
     
    173169EXTERN int verbosity INIT (1);
    174170
    175 /* The name of an emx.dll replacement (set by the -E option) or NULL
    176    (for emx.dll). */
    177 
    178 EXTERN char *emx_dll INIT (NULL);
    179 
    180171/* The OS/2 heap size, in bytes.  The default value is 32 MB.  The
    181172   heap size can be changed with the -h option. */
     
    223214EXTERN int opt_w INIT (FALSE);
    224215
    225 /* If this flag is set, create an `empty' heap object and let emx.dll
    226    load the heap pages at run-time (that's what previous versions of
    227    emxbind did for historical reasons; now that's used only for
    228    creating EXE files for testing emx.dll or for saving memory if
    229    MEMMAN=COMMIT is in effect).  Otherwise, create a heap object which
    230    contains the data pages of the core dump file.  Of course, all this
    231    applies only if the -c option is given.  This flag is set by the -C
    232    option. */
    233 
    234 EXTERN int old_heap INIT (FALSE);
    235 
    236216/* The module name. */
    237217
     
    278258EXTERN struct file out_file INIT ({FALSE});
    279259
    280 /* File structure for emxl.exe or emx.exe.  Note that the `ok' field
     260/* File structure for the DOS stub file.  Note that the `ok' field
    281261   is initialized to FALSE to avoid closing an unopened file. */
    282262
    283 EXTERN struct file emx_file INIT ({FALSE});
     263EXTERN struct file stub_file INIT ({FALSE});
    284264
    285265/* File structure for the core dump file (-c option).  Note that the
     
    298278EXTERN struct a_out_header a_in_h;
    299279
    300 /* The DOS and OS/2 emxbind headers, respectively. */
    301 
    302 EXTERN struct dos_bind_header dos_bind_h;
    303 EXTERN struct os2_bind_header os2_bind_h;
    304 
    305280/* The fixed part of the LX header. */
    306281
    307282EXTERN struct os2_header os2_h;
    308 
    309 /* This flag is set by check_bound() to indicate whether the input
    310    file is a bound executable or not.  Only the -L option (for listing
    311    the headers) can process executables which are not bound. */
    312 
    313 EXTERN int is_bound;
    314283
    315284/* The location of the a.out header in the source file. */
     
    439408EXTERN struct exe2_header out_h2;
    440409
    441 /* The emxbind DOS header of emxl.exe or emx.exe. */
    442 
    443 EXTERN struct dos_bind_header emx_bind_h;
    444 
    445 /* The bytes address of the DOS patch area in the input executable. */
    446 
    447 EXTERN long patch_pos;
    448 
    449410/* The location of the LX header of the output executable. */
    450411
     
    502463/* exec.c */
    503464
    504 void check_bound (void);
    505 void read_emx (void);
     465void read_stub (void);
    506466void read_a_out_header (void);
    507467void read_core (void);
     
    511471void read_os2_header (void);
    512472void exe_flags (void);
    513 void set_dos_bind_header (void);
    514473void set_options (void);
    515474void set_exe_header (void);
     
    522481void write_header (void);
    523482void write_nonres (void);
    524 void write_bind_header (void);
    525483void copy_a_out (void);
    526484void fill (long count);
     
    556514
    557515/* list.c */
    558 
    559 #if LIST_OPT
    560 void list (void);
    561 #endif
    562516
    563517/* map.c */
  • trunk/src/emx/src/emxbind/emxbind.smak

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r143 r144  
    77.TKIND  := $(TOOLFMT)
    88.TSRC   := $(wildcard src/emxbind/*.c)
    9 .TCF    := -DLIST_OPT=1
    109.TLDF   := -lmoddef
    1110include mkexe.smak
  • trunk/src/emx/src/emxbind/exec.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r143 r144  
    3434
    3535
    36 /* String for relaxed checking of emxl.exe or emx.exe. */
    37 
    38 static char *relaxed = "emx ";
    39 
    40 /* String for strict checking of emxl.exe or emx.exe, including the
    41    version number. */
    42 
    43 static char *version = "emx " VERSION;
    44 
    4536/* The first DOS EXE header read from emxl.exe or emx.exe. */
    4637
    47 static struct exe1_header emx_h1;
     38static struct exe1_header stub_h1;
    4839
    4940/* The a.out header to be written to the output executable. */
     
    8374static long dst_image;
    8475
    85 /* The size of the emxl.exe or emx.exe image. */
    86 
    87 static long emx_size;
     76/* The size of the DOS stub image. */
     77
     78static long stub_size;
    8879
    8980/* The size of the LX EXE header of the output executable. */
     
    162153
    163154
    164 /* Check the OS/2 emxbind header (patch area).  See also crt0.s. */
    165 
    166 static int check_os2_bind_header (void)
    167 {
    168   if (os2_bind_h.text_base != TEXT_BASE
    169       || round_page (os2_bind_h.text_end) != TEXT_BASE + round_page (a_in_h.text_size)
    170       || os2_bind_h.data_base != data_base)
    171     return FALSE;
    172   if (memchr (os2_bind_h.options, 0, sizeof (os2_bind_h.options)) == NULL)
    173     return FALSE;
    174   return TRUE;
    175 }
    176 
    177 
    178155/* Read EXE header and emxbind DOS header of emx.exe */
    179156
    180 void read_emx (void)
    181 {
    182   my_read (&emx_h1, sizeof (emx_h1), &emx_file);
    183   if (emx_h1.magic != 0x5a4d)
     157void read_stub (void)
     158{
     159  my_read (&stub_h1, sizeof (stub_h1), &stub_file);
     160  if (stub_h1.magic != 0x5a4d)
    184161    error ("invalid <emx>.exe");
    185   src_image = (long)emx_h1.hdr_size << 4;
    186   emx_size = ((long)emx_h1.pages << 9) - src_image;
    187   if (emx_h1.last_page != 0)
    188     emx_size += emx_h1.last_page - 512;
    189 
    190   my_seek (&emx_file, src_image);
    191   my_read (&emx_bind_h, sizeof (emx_bind_h), &emx_file);
    192 
    193   if (memcmp (emx_bind_h.hdr, relaxed, strlen (relaxed)) != 0
    194       || emx_bind_h.bind_flag != 0)
    195     error ("invalid <emx>.exe");
    196   if (memcmp (emx_bind_h.hdr, version, strlen (version)) != 0)
    197     fputs ("emxbind: emx version mismatch (warning)\n", stderr);
    198   dos_bind_h = emx_bind_h;
     162  src_image = (long)stub_h1.hdr_size << 4;
     163  stub_size = ((long)stub_h1.pages << 9) - src_image;
     164  if (stub_h1.last_page != 0)
     165    stub_size += stub_h1.last_page - 512;
    199166}
    200167
     
    216183  my_seek (&inp_file, A_OUT_OFFSET);
    217184  my_read (buf, sizeof (buf), &inp_file);
    218   /*            PUSH              CALL               JMP                CALL */
    219   if (buf[0] != 0x68 || buf[5] != 0xe8 || buf[10] != 0xeb || buf[12] != 0xe8)
    220     error ("invalid a.out file (startup code)");
    221185  a_in_text = A_OUT_OFFSET;
    222186  a_in_data = a_in_text + round_page (a_in_h.text_size);
     
    225189  a_in_sym = a_in_dr + a_in_h.drsize;
    226190  data_base = round_segment (TEXT_BASE + a_in_h.text_size);
    227   my_seek (&inp_file, a_in_data);
    228   my_read (&os2_bind_h, sizeof (os2_bind_h), &inp_file);
    229   if (!check_os2_bind_header ())
    230     error ("invalid a.out file (startup data)");
    231191  text_off = a_in_pos + a_in_text - TEXT_BASE;
    232192  data_off = a_in_pos + a_in_data - data_base;
     
    357317
    358318
    359 /* Read the DOS EXE header of the input executable.  Fail if isn't a
    360    bound executable file (unless the -L command option is in effect). */
    361 
    362 void check_bound (void)
    363 {
    364   my_read (&inp_h1, sizeof (inp_h1), &inp_file);
    365   if (inp_h1.magic != 0x5a4d)
    366     error ("not an .exe file");
    367   patch_pos = (long)inp_h1.hdr_size << 4;
    368   my_seek (&inp_file, patch_pos);
    369   my_read (&dos_bind_h, sizeof (dos_bind_h), &inp_file);
    370   if (memcmp (dos_bind_h.hdr, relaxed, strlen (relaxed)) != 0
    371       || dos_bind_h.bind_flag == 0)
    372     {
    373       is_bound = FALSE;
    374       if (mode != 'L')
    375         error ("invalid .exe file");
    376     }
    377   else
    378     {
    379       is_bound = TRUE;
    380       if (mode != 'u' && mode != 'L' &&
    381           memcmp (dos_bind_h.hdr, version, strlen (version)) != 0)
    382         fputs ("emxbind: emx version mismatch in .exe file (warning)\n",
    383                stderr);
    384       a_in_pos = COMBINE (dos_bind_h.hdr_loc_lo, dos_bind_h.hdr_loc_hi);
    385       my_seek (&inp_file, a_in_pos);
    386       my_read (&a_in_h, sizeof (a_in_h), &inp_file);
    387       a_out_h = a_in_h;
    388       if (a_in_h.magic != A_OUT_MAGIC || a_in_h.entry != TEXT_BASE)
    389         error ("invalid .exe file (a.out header)");
    390       a_out_h.drsize = 0;
    391       a_out_h.trsize = 0;
    392       a_in_text = A_OUT_OFFSET;
    393       a_in_data = a_in_text + round_page (a_in_h.text_size);
    394       a_in_tr = a_in_data + round_page (a_in_h.data_size);
    395       a_in_dr = a_in_tr + a_in_h.trsize;
    396       a_in_sym = a_in_dr + a_in_h.drsize;
    397       data_base = round_segment (TEXT_BASE + a_in_h.text_size);
    398       my_seek (&inp_file, a_in_pos + a_in_data);
    399       my_read (&os2_bind_h, sizeof (os2_bind_h), &inp_file);
    400       if (!check_os2_bind_header ())
    401         error ("invalid .exe file (startup data)");
    402     }
    403 }
    404 
    405 
    406 /* Setup the DOS emxbind header, including emx options. */
    407 
    408 void set_dos_bind_header (void)
    409 {
    410   dos_bind_h.bind_flag = 0xff;
    411   dos_bind_h.hdr_loc_lo = LOWORD (a_out_pos);
    412   dos_bind_h.hdr_loc_hi = HIWORD (a_out_pos);
    413   set_options ();
    414 }
    415 
    416 
    417 /* Copy the emx options from options_for_dos and options_for_os2 to
    418    dos_bind_h and os2_bind_h, respectively.  Fail if the strings are
    419    too long. */
    420 
    421 void set_options (void)
    422 {
    423   if (strlen (options_for_dos) > sizeof (dos_bind_h.options) - 1)
    424     error ("too many emx options for MS-DOS");
    425   memset (dos_bind_h.options, 0, sizeof (dos_bind_h.options));
    426   strcpy ((char *)dos_bind_h.options, options_for_dos);
    427   if (strlen (options_for_os2) > sizeof (os2_bind_h.options) - 1)
    428     error ("too many emx options for OS/2");
    429   memset (os2_bind_h.options, 0, sizeof (os2_bind_h.options));
    430   strcpy ((char *)os2_bind_h.options, options_for_os2);
    431 }
    432 
    433 
    434319/* Setup the DOS EXE headers for the destination executable.  Compute
    435320   the location of the LX header. */
     
    439324  long i;
    440325
    441   i = (emx_h1.reloc_size << 2) + sizeof (out_h1) + sizeof (out_h2);
     326  i = (stub_h1.reloc_size << 2) + sizeof (out_h1) + sizeof (out_h2);
    442327#if 1
    443328  dst_image = (i + 0x0f) & ~0x0f;
     
    446331#endif
    447332  fill1 = dst_image - i;
    448   out_h1 = emx_h1;
     333  out_h1 = stub_h1;
    449334  out_h1.reloc_ptr = sizeof (out_h1) + sizeof (out_h2);
    450335  out_h1.hdr_size = dst_image >> 4;
     
    452337  memset (out_h2.res1, 0, sizeof (out_h2.res1));
    453338  out_h2.new_lo = out_h2.new_hi = 0;
    454   i = os2_hdr_pos = dst_image + emx_size;
     339  i = os2_hdr_pos = dst_image + stub_size;
    455340  if (os2_hdr_pos & 0x1ff)
    456341    os2_hdr_pos = (os2_hdr_pos + 0x1ff) & ~0x1ff;
     
    514399    {
    515400      data_pages = npages (a_in_h.data_size + a_in_h.bss_size);
    516       if (!old_heap)
    517         {
    518           heap_pages = npages (core_h.u_heap_brk - core_h.u_heap_base);
    519 
    520           /* Compute the number of pages between the last data page
    521              and the first heap page, for padding the a.out subfile.
    522              These pages are not mapped to any object.  Round down! */
    523 
    524           gap_pages = (core_h.u_heap_base - core_h.u_data_end) / 0x1000;
    525         }
     401      heap_pages = npages (core_h.u_heap_brk - core_h.u_heap_base);
     402
     403      /* Compute the number of pages between the last data page
     404         and the first heap page, for padding the a.out subfile.
     405         These pages are not mapped to any object.  Round down! */
     406
     407      gap_pages = (core_h.u_heap_base - core_h.u_data_end) / 0x1000;
    526408    }
    527409  else
     
    721603  put_res_obj (obj_stk0.map_first + obj_stk0.map_count);
    722604  header.len = os2_hdr_size;
    723   if (opt_c != NULL)
    724     {
    725       os2_bind_h.data_end = os2_bind_h.data_base + a_in_h.data_size + a_in_h.bss_size;
    726       os2_bind_h.bss_base = os2_bind_h.data_end;
    727       os2_bind_h.bss_end  = os2_bind_h.bss_base;
    728       os2_bind_h.heap_base = core_h.u_heap_base;
    729       os2_bind_h.heap_end  = core_h.u_heap_end;
    730       os2_bind_h.heap_brk = core_h.u_heap_brk;
    731       os2_bind_h.heap_off = a_out_pos + A_OUT_OFFSET
    732         + round_page (a_in_h.text_size)
    733           + round_segment (a_in_h.data_size + a_in_h.bss_size);
    734     }
    735   else
    736     {
    737       os2_bind_h.heap_base = obj_heap.virt_base;
    738       os2_bind_h.heap_end  = OBJ_END (obj_heap);
    739       os2_bind_h.heap_brk  = 0;
    740       os2_bind_h.heap_off  = 0;
    741     }
    742605}
    743606
     
    817680  obj_heap.virt_size  = heap_size;
    818681  obj_heap.virt_base  = 0;
    819   if (old_heap || opt_c == NULL)
    820     obj_heap.attr_flags = 0x2083;     /* readable, writable, big, invalid */
    821   else
    822     obj_heap.attr_flags = 0x2003;     /* readable, writable, big */
     682  obj_heap.attr_flags = 0x2003;       /* readable, writable, big */
    823683  obj_heap.map_first  = X;
    824684  obj_heap.map_count  = X;
     
    880740
    881741
    882 /* Write the DOS EXE headers, the emxl.exe or emx.exe image, and the
    883    OS/2 LX header. */
     742/* Write the DOS EXE headers, the stub image, and the OS/2 LX header. */
    884743
    885744void write_header (void)
     
    887746  my_write (&out_h1, sizeof (out_h1), &out_file);
    888747  my_write (&out_h2, sizeof (out_h2), &out_file);
    889   my_seek (&emx_file, emx_h1.reloc_ptr);
    890   copy (&emx_file, emx_h1.reloc_size * 4);
     748  my_seek (&stub_file, stub_h1.reloc_ptr);
     749  copy (&stub_file, stub_h1.reloc_size * 4);
    891750  fill (fill1);
    892   my_seek (&emx_file, src_image);
    893   copy (&emx_file, emx_size);
     751  my_seek (&stub_file, src_image);
     752  copy (&stub_file, stub_size);
    894753  fill (fill2);
    895754  if (mode != 'u')
     
    898757      fill (fill3);
    899758    }
    900 }
    901 
    902 
    903 /* Write the emxbind headers (patch areas). */
    904 
    905 void write_bind_header (void)
    906 {
    907   my_seek (&out_file, dst_image);
    908   my_write (&dos_bind_h, sizeof (dos_bind_h), &out_file);
    909   my_seek (&out_file, a_out_pos + A_OUT_OFFSET
    910            + round_page (a_out_h.text_size));
    911   my_write (&os2_bind_h, sizeof (os2_bind_h), &out_file);
    912759}
    913760
  • trunk/src/emx/src/emxbind/fixup.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r143 r144  
    4141};
    4242
    43 
    44 /* The module number of EMX for importing emx_init and emx_syscall
    45    from emx.dll. */
    46 
    47 static int mod_emx;
    4843
    4944/* This table holds the modules for method (I1).  module_size is the
     
    585580  byte proc_name[256];
    586581
    587   mod_emx = find_module (emx_dll, NO_ADDR);
    588   ref_proc ("_emx_init", OBJ_TEXT, 6, mod_emx, NULL, 1, FIXUP_REL, 0);
    589   ref_proc ("_emx_syscall", OBJ_TEXT, 13, mod_emx, NULL, 2, FIXUP_REL, 0);
    590   my_seek (&inp_file, data_off + os2_bind_h.os2_dll);
     582  /* The very first DWORD in data segment is the __os2_dll set.
     583     It contains a list of fixups to be replaced by OS/2 DLL references. */
     584  my_seek (&inp_file, data_base + data_off);
     585  my_read (&set_len, sizeof (set_len), &inp_file);
     586  if (set_len != DATASEG_MAGIC)
     587    error ("invalid data segment (does not start with 0x%x)", DATASEG_MAGIC);
     588  /* Now read the offset to the __os2_dll set */
     589  my_read (&set_len, sizeof (set_len), &inp_file);
     590
     591  /* Start scanning the set */
     592  my_seek (&inp_file, set_len + data_off);
    591593  my_read (&set_len, sizeof (set_len), &inp_file);
    592594  if (set_len == 0xffffffff)
    593595    {
    594596      /* I think this is a bug in GNU ld */
    595       my_seek (&inp_file, data_off + os2_bind_h.os2_dll - 4);
     597      my_seek (&inp_file, data_off - 4);
    596598      my_read (&set_len, sizeof (set_len), &inp_file);
    597599    }
Note: See TracChangeset for help on using the changeset viewer.