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

Removed EMX.DLL dependency and EMXL.EXE dependency.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 _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 image. */
     77
     78static long _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_ (void)
     158{
     159  my_read (&_file);
     160  if (_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 = (_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 = _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 + _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 (&_h1.reloc_ptr);
     749  copy (&_h1.reloc_size * 4);
    891750  fill (fill1);
    892   my_seek (&emx_file, src_image);
    893   copy (&emx_file, emx_size);
     751  my_seek (&_file, src_image);
     752  copy (&_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
Note: See TracChangeset for help on using the changeset viewer.