Changeset 144
- Timestamp:
- May 15, 2003, 4:25:00 PM (22 years ago)
- 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
to1.3
r143 r144 27 27 28 28 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 41 29 /* Perform initializations for the bind operation. */ 42 30 … … 64 52 65 53 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 77 54 /* Strip the symbols from a bound executable. */ 78 55 … … 96 73 97 74 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 150 75 void cmd (int mode) 151 76 { 152 77 switch (mode) 153 78 { 154 case 'a':155 156 /* Alter emxbind options. */157 158 check_bound ();159 alter ();160 break;161 162 79 case 'b': 163 80 … … 166 83 init_bind (); 167 84 init_os2_header (); 168 read_ emx();85 read_stub (); 169 86 read_a_out_header (); 170 87 if (opt_c != NULL) … … 176 93 set_exe_header (); 177 94 set_os2_header (); 178 set_dos_bind_header ();179 95 write_header (); 180 96 write_res (); 181 97 copy_a_out (); 182 98 write_nonres (); 183 write_bind_header ();184 99 if (opt_m != NULL) 185 100 write_map (opt_m); … … 190 105 /* Set the OS/2 application type. */ 191 106 192 check_bound ();193 107 exe_type (); 194 break;195 196 #if LIST_OPT197 case 'L':198 199 /* List the headers. */200 201 check_bound ();202 list ();203 break;204 #endif205 case 'i':206 207 /* Show the emxbind options. */208 209 check_bound ();210 show ();211 108 break; 212 109 … … 215 112 /* Strip symbols. */ 216 113 217 check_bound ();218 114 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 ();239 115 break; 240 116 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxbind/emxbind.c
-
Property cvs2svn:cvs-rev
changed from
1.3
to1.4
r143 r144 42 42 "Copyright (c) 1991-1997 by Eberhard Mattes"; 43 43 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 55 46 def_fname the name of the module definition file (-d option). */ 56 47 57 48 static char inp_fname[FNAME_SIZE]; 58 static char emx_fname[FNAME_SIZE];49 static char stub_fname[FNAME_SIZE]; 59 50 static char def_fname[FNAME_SIZE]; 60 51 … … 65 56 static char **gargv; 66 57 67 /* Automatically locate emxl.exe if this flag is true. Otherwise, use68 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 76 58 77 59 /* Give the user a short reminder about how to call this program. */ … … 81 63 puts (title); 82 64 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>"); 86 67 puts (" emxbind -e [<options>] <input>[.exe]"); 87 68 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_OPT92 puts (" emxbind -L [<options>] <input>[.exe]");93 #endif94 69 puts ("\nCommands:"); 95 70 puts (" -b bind .exe (default)"); 96 puts (" -u update emx in .exe");97 71 puts (" -e set OS/2 .exe flags: -f, -p or -w"); 98 72 puts (" -s strip symbols"); 99 puts (" -x extract a.out");100 puts (" -i show options");101 puts (" -a alter options");102 #if LIST_OPT103 puts (" -L list headers");104 #endif105 73 puts ("\nOptions:"); 106 74 puts (" -f application type: full screen (-b and -e)"); … … 110 78 puts (" -v be verbose"); 111 79 puts (" -s strip symbols (-b only)"); 112 puts (" -C use old method for creating preloaded executables");113 80 puts (" -c[<core>] add data from core dump file (-b only)"); 114 81 puts (" -d[<def>] read module definition file (-b only)"); 115 puts (" -E<dll> use <dll> instead of emx.dll (-b only)");116 82 puts (" -h<size> set heap size for OS/2 (-b only)"); 117 83 puts (" -k<size> set stack size for OS/2 (-b only)"); … … 270 236 271 237 if (!stmt->stub.none) 272 stub_fname = xstrdup (stmt->stub.name);238 _strncpy (stub_fname, stmt->stub.name, sizeof (stub_fname)); 273 239 break; 274 240 … … 343 309 344 310 345 /* Scan the remaining command line arguments as emx options and store346 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 427 311 /* Parse the command line. */ 428 312 … … 450 334 451 335 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) 453 337 { 454 338 switch (c) 455 339 { 456 340 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 } 464 348 case 'b': 465 349 case 'e': 466 #if LIST_OPT467 case 'L':468 #endif469 case 'i':470 case 'u':471 case 'x':472 350 if (mode != 0) 473 351 error ("multiple commands specified"); … … 479 357 opt_c = (optarg != NULL ? optarg : ""); 480 358 break; 481 case 'C':482 old_heap = TRUE;483 break;484 359 case 'd': 485 360 if (opt_d != NULL) … … 487 362 opt_d = (optarg != NULL ? optarg : ""); 488 363 break; 489 case 'E':490 if (emx_dll != NULL)491 error ("multiple -E options");492 emx_dll = optarg;493 break;494 364 case 'f': 495 365 opt_f = TRUE; … … 567 437 opt_c = "core"; 568 438 439 /* Set the default path to the DOS stub */ 440 _execname (stub_fname, sizeof (stub_fname)); 441 strcpy (_getname (stub_fname), "os2stub.bin"); 442 569 443 /* If the -E option is not given and the name is not given by the 570 444 EMXBIND_DLL environment variable, "emx.dll" will be used. */ 571 445 572 if (emx_dll == NULL)573 emx_dll = getenv ("EMXBIND_DLL");574 if (emx_dll == NULL)575 emx_dll = "emx";576 577 446 /* Parse the rest of the command line, depending on the command 578 447 option. */ 579 448 580 449 switch (mode) 581 { 582 case 'a': 583 file_name (inp_fname, "exe", NULL); 584 emx_options (); 585 break; 586 450 { 587 451 case 'b': 588 452 if (gargc - optind <= 1 || gargv[optind+1][0] == '-') 589 auto_emxl = TRUE;453 ; 590 454 else if (opt_o != NULL) 591 455 error ("Too many file names specified"); 592 456 else 593 file_name ( emx_fname, "exe", NULL);457 file_name (stub_fname, "exe", NULL); 594 458 file_name (inp_fname, NULL, NULL); 595 459 if (opt_d != NULL) … … 605 469 read_def_file (); 606 470 } 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 else616 {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 }624 471 file_name (out_fname, (dll_flag ? "dll" : "exe"), 625 472 (opt_o != NULL ? opt_o : inp_fname)); 626 473 if (_fncmp (inp_fname, out_fname) == 0) 627 474 error ("The input and output files have the same name"); 628 emx_options ();629 475 break; 630 476 631 477 case 'e': 632 case 'L':633 case 'i':634 478 case 's': 635 479 file_name (inp_fname, "exe", NULL); 636 480 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 } 650 482 651 483 /* Complain if there are any unprocessed arguments left. */ … … 670 502 switch (mode) 671 503 { 672 case 'a':673 case 'e':674 case 's':675 my_open (&inp_file, inp_fname, open_read_write);676 break;677 504 case 'b': 678 505 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); 680 507 if (opt_c != NULL) 681 508 my_open (&core_file, opt_c, open_read); … … 684 511 my_open (&out_file, out_fname, create_write); 685 512 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': 691 515 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);697 516 break; 698 517 } … … 706 525 my_close (&out_file); 707 526 my_close (&inp_file); 708 my_close (& emx_file);527 my_close (&stub_file); 709 528 my_close (&core_file); 710 529 my_close (&res_file); … … 732 551 path name of emxl.exe. */ 733 552 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); 736 555 737 556 /* Open the files. */ -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxbind/emxbind.h
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r143 r144 31 31 /* By default, don't implement the -L option (for listing the headers 32 32 of an EXE file). */ 33 34 #if !defined (LIST_OPT)35 #define LIST_OPT FALSE36 #endif37 33 38 34 /* This is the version number. */ … … 173 169 EXTERN int verbosity INIT (1); 174 170 175 /* The name of an emx.dll replacement (set by the -E option) or NULL176 (for emx.dll). */177 178 EXTERN char *emx_dll INIT (NULL);179 180 171 /* The OS/2 heap size, in bytes. The default value is 32 MB. The 181 172 heap size can be changed with the -h option. */ … … 223 214 EXTERN int opt_w INIT (FALSE); 224 215 225 /* If this flag is set, create an `empty' heap object and let emx.dll226 load the heap pages at run-time (that's what previous versions of227 emxbind did for historical reasons; now that's used only for228 creating EXE files for testing emx.dll or for saving memory if229 MEMMAN=COMMIT is in effect). Otherwise, create a heap object which230 contains the data pages of the core dump file. Of course, all this231 applies only if the -c option is given. This flag is set by the -C232 option. */233 234 EXTERN int old_heap INIT (FALSE);235 236 216 /* The module name. */ 237 217 … … 278 258 EXTERN struct file out_file INIT ({FALSE}); 279 259 280 /* File structure for emxl.exe or emx.exe. Note that the `ok' field260 /* File structure for the DOS stub file. Note that the `ok' field 281 261 is initialized to FALSE to avoid closing an unopened file. */ 282 262 283 EXTERN struct file emx_file INIT ({FALSE});263 EXTERN struct file stub_file INIT ({FALSE}); 284 264 285 265 /* File structure for the core dump file (-c option). Note that the … … 298 278 EXTERN struct a_out_header a_in_h; 299 279 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 305 280 /* The fixed part of the LX header. */ 306 281 307 282 EXTERN struct os2_header os2_h; 308 309 /* This flag is set by check_bound() to indicate whether the input310 file is a bound executable or not. Only the -L option (for listing311 the headers) can process executables which are not bound. */312 313 EXTERN int is_bound;314 283 315 284 /* The location of the a.out header in the source file. */ … … 439 408 EXTERN struct exe2_header out_h2; 440 409 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 449 410 /* The location of the LX header of the output executable. */ 450 411 … … 502 463 /* exec.c */ 503 464 504 void check_bound (void); 505 void read_emx (void); 465 void read_stub (void); 506 466 void read_a_out_header (void); 507 467 void read_core (void); … … 511 471 void read_os2_header (void); 512 472 void exe_flags (void); 513 void set_dos_bind_header (void);514 473 void set_options (void); 515 474 void set_exe_header (void); … … 522 481 void write_header (void); 523 482 void write_nonres (void); 524 void write_bind_header (void);525 483 void copy_a_out (void); 526 484 void fill (long count); … … 556 514 557 515 /* list.c */ 558 559 #if LIST_OPT560 void list (void);561 #endif562 516 563 517 /* map.c */ -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxbind/emxbind.smak
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r143 r144 7 7 .TKIND := $(TOOLFMT) 8 8 .TSRC := $(wildcard src/emxbind/*.c) 9 .TCF := -DLIST_OPT=110 9 .TLDF := -lmoddef 11 10 include mkexe.smak -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxbind/exec.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r143 r144 34 34 35 35 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 the41 version number. */42 43 static char *version = "emx " VERSION;44 45 36 /* The first DOS EXE header read from emxl.exe or emx.exe. */ 46 37 47 static struct exe1_header emx_h1;38 static struct exe1_header stub_h1; 48 39 49 40 /* The a.out header to be written to the output executable. */ … … 83 74 static long dst_image; 84 75 85 /* The size of the emxl.exe or emx.exeimage. */86 87 static long emx_size;76 /* The size of the DOS stub image. */ 77 78 static long stub_size; 88 79 89 80 /* The size of the LX EXE header of the output executable. */ … … 162 153 163 154 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_BASE169 || 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 178 155 /* Read EXE header and emxbind DOS header of emx.exe */ 179 156 180 void read_ emx(void)181 { 182 my_read (& emx_h1, sizeof (emx_h1), &emx_file);183 if ( emx_h1.magic != 0x5a4d)157 void read_stub (void) 158 { 159 my_read (&stub_h1, sizeof (stub_h1), &stub_file); 160 if (stub_h1.magic != 0x5a4d) 184 161 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; 199 166 } 200 167 … … 216 183 my_seek (&inp_file, A_OUT_OFFSET); 217 184 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)");221 185 a_in_text = A_OUT_OFFSET; 222 186 a_in_data = a_in_text + round_page (a_in_h.text_size); … … 225 189 a_in_sym = a_in_dr + a_in_h.drsize; 226 190 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)");231 191 text_off = a_in_pos + a_in_text - TEXT_BASE; 232 192 data_off = a_in_pos + a_in_data - data_base; … … 357 317 358 318 359 /* Read the DOS EXE header of the input executable. Fail if isn't a360 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)) != 0371 || dos_bind_h.bind_flag == 0)372 {373 is_bound = FALSE;374 if (mode != 'L')375 error ("invalid .exe file");376 }377 else378 {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 to418 dos_bind_h and os2_bind_h, respectively. Fail if the strings are419 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 434 319 /* Setup the DOS EXE headers for the destination executable. Compute 435 320 the location of the LX header. */ … … 439 324 long i; 440 325 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); 442 327 #if 1 443 328 dst_image = (i + 0x0f) & ~0x0f; … … 446 331 #endif 447 332 fill1 = dst_image - i; 448 out_h1 = emx_h1;333 out_h1 = stub_h1; 449 334 out_h1.reloc_ptr = sizeof (out_h1) + sizeof (out_h2); 450 335 out_h1.hdr_size = dst_image >> 4; … … 452 337 memset (out_h2.res1, 0, sizeof (out_h2.res1)); 453 338 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; 455 340 if (os2_hdr_pos & 0x1ff) 456 341 os2_hdr_pos = (os2_hdr_pos + 0x1ff) & ~0x1ff; … … 514 399 { 515 400 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; 526 408 } 527 409 else … … 721 603 put_res_obj (obj_stk0.map_first + obj_stk0.map_count); 722 604 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_OFFSET732 + round_page (a_in_h.text_size)733 + round_segment (a_in_h.data_size + a_in_h.bss_size);734 }735 else736 {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 }742 605 } 743 606 … … 817 680 obj_heap.virt_size = heap_size; 818 681 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 */ 823 683 obj_heap.map_first = X; 824 684 obj_heap.map_count = X; … … 880 740 881 741 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. */ 884 743 885 744 void write_header (void) … … 887 746 my_write (&out_h1, sizeof (out_h1), &out_file); 888 747 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); 891 750 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); 894 753 fill (fill2); 895 754 if (mode != 'u') … … 898 757 fill (fill3); 899 758 } 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_OFFSET910 + round_page (a_out_h.text_size));911 my_write (&os2_bind_h, sizeof (os2_bind_h), &out_file);912 759 } 913 760 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/emxbind/fixup.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r143 r144 41 41 }; 42 42 43 44 /* The module number of EMX for importing emx_init and emx_syscall45 from emx.dll. */46 47 static int mod_emx;48 43 49 44 /* This table holds the modules for method (I1). module_size is the … … 585 580 byte proc_name[256]; 586 581 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); 591 593 my_read (&set_len, sizeof (set_len), &inp_file); 592 594 if (set_len == 0xffffffff) 593 595 { 594 596 /* 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); 596 598 my_read (&set_len, sizeof (set_len), &inp_file); 597 599 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.