source: trunk/emx/src/emxbind/emxbind.h@ 2446

Last change on this file since 2446 was 2300, checked in by bird, 20 years ago

Default stack size set to 1MB.
The old defaults were 8MB (emxbind) and 8KB (emxomfld).

  • Property cvs2svn:cvs-rev set to 1.8
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 14.0 KB
Line 
1/* emxbind.h -- Global header file for emxbind
2 Copyright (c) 1991-1998 Eberhard Mattes
3
4This file is part of emxbind.
5
6emxbind is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11emxbind is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with emxbind; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21
22#include "a_out.h"
23#include <sys/param.h>
24
25#if defined (EXTERN)
26#define INIT(X) = X
27#define INIT_GROW = GROW_INIT
28#else
29#define INIT(X)
30#define INIT_GROW
31#define EXTERN extern
32#endif
33
34/* By default, don't implement the -L option (for listing the headers
35 of an EXE file). */
36
37/* Put this at the end of a function declaration to tell the compiler
38 that the function never returns. */
39
40#define NORETURN2 __attribute__ ((noreturn))
41
42/* Number of characters in a file name. */
43
44#define FNAME_SIZE 512
45
46/* This is the default value for the -h option (heap size). */
47
48#define DEFAULT_HEAP_SIZE 0x02000000 /* 32 MB */
49
50/* This is the default value for the -k option (stack size). */
51
52#define DEFAULT_STACK_SIZE (1024*1024)
53
54/* A_OUT_OFFSET is the offset from the start of the a.out file to the
55 text segment in the file. */
56
57#define A_OUT_OFFSET 0x0400
58
59/* This is the start address (in memory) of the text segment. */
60
61#define TEXT_BASE 0x00010000
62
63/* We use up to 4 memory objects in an LX executable file. */
64
65#define OBJECTS 4
66
67/* Source types for LX fixup records. */
68
69#define NRSTYP 0x0f /* Mask */
70#define NRSBYT 0x00 /* 8-bit byte (8-bits) */
71#define NRSSEG 0x02 /* 16-bit selector (16-bits) */
72#define NRSPTR 0x03 /* 16:16 pointer (32-bits) */
73#define NRSOFF 0x05 /* 16-bit offset (16-bits) */
74#define NRPTR48 0x06 /* 16:32 pointer (48-bits) */
75#define NROFF32 0x07 /* 32-bit offset (32-bits) */
76#define NRSOFF32 0x08 /* 32-bit self-relative offset (32-bits) */
77
78#define NRALIAS 0x10 /* Fixup to 16:16 alias */
79#define NRCHAIN 0x20 /* List of source offsets follows */
80
81/* Reference types for LX fixup records. */
82
83#define NRRTYP 0x03 /* Mask */
84#define NRRINT 0x00 /* Internal reference */
85#define NRRORD 0x01 /* Import by ordinal */
86#define NRRNAM 0x02 /* Import by name */
87
88/* Flags for LX fixup records. */
89
90#define NRADD 0x04 /* Additive fixup */
91#define NR32BITOFF 0x10 /* 32-bit target offset */
92#define NR32BITADD 0x20 /* 32-bit additive fixup */
93#define NR16OBJMOD 0x40 /* 16-bit object/module ordinal */
94#define NR8BITORD 0x80 /* 8-bit import ordinal */
95
96
97/* How to open a file. This type is used for my_open(). */
98
99enum open_mode
100{
101 open_read, create_write, open_read_write
102};
103
104/* A file. OK is non-zero if the file is open. DEL is not yet used.
105 F is the stream. NAME is the name of the file. */
106
107struct file
108{
109 int ok, del;
110 FILE *f;
111 const char *name;
112};
113
114
115/* Internal representation of fixups. */
116
117#define FIXUP_ABS 0
118#define FIXUP_REL 1
119#define FIXUP_FAR16 2
120
121#define TARGET_ORD 0
122#define TARGET_NAME 1
123#define TARGET_ADDR 2
124
125struct fixup
126{
127 int type; /* fixup type, see constants above */
128 int target; /* fixup target, see constants above */
129 dword addr; /* address of patch */
130 int obj; /* object number (where to patch) */
131 int mod; /* module number or object (target) */
132 dword dst; /* name or ordinal or address */
133 dword add; /* additive fixup if non-zero */
134};
135
136/* Internal representation of an export definition. */
137
138struct export
139{
140 char *entryname;
141 char *internalname;
142 long ord;
143 int resident;
144 dword offset;
145 int object;
146 int flags;
147};
148
149/* A growable buffer. */
150
151#define GROW_INIT {NULL, 0, 0}
152
153struct grow
154{
155 byte *data;
156 size_t size;
157 size_t len;
158};
159
160
161/* This variable holds the command code. For instance, it is 'b' for
162 binding. */
163
164EXTERN int mode INIT (0);
165
166/* Verbosity level. */
167
168EXTERN int verbosity INIT (1);
169
170/* The OS/2 heap size, in bytes. The default value is 32 MB. The
171 heap size can be changed with the -h option. */
172
173EXTERN long heap_size INIT (DEFAULT_HEAP_SIZE);
174
175/* The OS/2 stack size, in bytes. The default value is 8 MB. The
176 stack size can be changed with the -k option and the STACKSIZE
177 module statement. */
178
179EXTERN long stack_size INIT (DEFAULT_STACK_SIZE);
180
181/* The name of the core dump file (set by the -c option) or NULL (if
182 there is no core dump file). */
183
184EXTERN char *opt_c INIT (NULL);
185
186/* Create a full-screen application. This flag is set by the -f
187 option. */
188
189EXTERN int opt_f INIT (FALSE);
190
191/* Create a Presentation Manager application. This flag is set by the
192 -p option. */
193
194EXTERN int opt_p INIT (FALSE);
195
196/* The name of the map file (set by the -m option) or NULL (if no .map
197 file should be written). */
198
199EXTERN char *opt_m INIT (NULL);
200
201/* The name of the binary resource file (set by the -r option) or NULL
202 (if there is no binary resource file). */
203
204EXTERN char *opt_r INIT (NULL);
205
206/* Strip symbols. This flag is set by the -s option. */
207
208EXTERN int opt_s INIT (FALSE);
209
210/* Create a windowed application. This flag is set by the -w
211 option. */
212
213EXTERN int opt_w INIT (FALSE);
214
215/* The module name. */
216
217EXTERN char *module_name INIT (NULL);
218
219/* The application type. */
220
221EXTERN int app_type INIT (_MDT_DEFAULT);
222
223/* INITINSTANCE, INITGLOBAL, TERMINSTANCE and TERMGLOBAL. */
224
225EXTERN int init_global INIT (TRUE);
226EXTERN int term_global INIT (TRUE);
227
228/* The description string. */
229
230EXTERN char *description INIT (NULL);
231
232/* The emx options for DOS and OS/2, respectively, are stored in these
233 buffers, before being written to the emxbind headers. */
234
235EXTERN char options_for_dos[512];
236EXTERN char options_for_os2[512];
237
238/* The name of the output file. */
239
240EXTERN char out_fname[FNAME_SIZE];
241
242/* File structure for the input executable. Note that the `ok' field
243 is initialized to FALSE to avoid closing an unopened file. */
244
245EXTERN struct file inp_file INIT ({FALSE});
246
247/* File structure for the binary resource file (-r option). Note that
248 the `ok' field is initialized to FALSE to avoid closing an unopened
249 file. */
250
251EXTERN struct file res_file INIT ({FALSE});
252
253/* File structure for the destination executable file. Note that the
254 `ok' field is initialized to FALSE to avoid closing an unopened
255 file. */
256
257EXTERN struct file out_file INIT ({FALSE});
258
259/* File structure for the DOS stub file. Note that the `ok' field
260 is initialized to FALSE to avoid closing an unopened file. */
261
262EXTERN struct file stub_file INIT ({FALSE});
263
264/* File structure for the core dump file (-c option). Note that the
265 `ok' field is initialized to FALSE to avoid closing an unopened
266 file. */
267
268EXTERN struct file core_file INIT ({FALSE});
269
270/* The DOS EXE headers read from the input executable. */
271
272EXTERN struct exe1_header inp_h1;
273EXTERN struct exe2_header inp_h2;
274
275/* The a.out header read from the source a.out (sub)file. */
276
277EXTERN struct exec a_in_h;
278
279/* The fixed part of the LX header. */
280
281EXTERN struct os2_header os2_h;
282
283/* The location of the a.out header in the source file. */
284
285EXTERN long a_in_pos;
286
287/* The size of the string table in the source a.out (sub)file. */
288
289EXTERN long a_in_str_size;
290
291/* The offsets of the data section and symbol table, respectively, of
292 the source a.out (sub)file. */
293
294EXTERN long a_in_data;
295EXTERN long a_in_sym;
296
297/* This table contains all the fixups of the module, in an internal
298 format. fixup_size is the number of entries allocated, fixup_len
299 is the number of entries used. */
300
301EXTERN struct fixup *fixup_data INIT (NULL);
302EXTERN int fixup_size INIT (0);
303EXTERN int fixup_len INIT (0);
304
305/* procs holds the import procedure name table (table of import symbol
306 names) of the executable, in LX EXE format, while it is being
307 built. */
308
309EXTERN struct grow procs INIT_GROW;
310
311/* Create a relocatable executable if this flag is true. This flag is
312 set when creating a DLL. */
313
314EXTERN int relocatable INIT (FALSE);
315
316/* The base address of the initialized data segment. */
317
318EXTERN dword data_base;
319
320/* Add one of these offsets to an text or data address, respectively,
321 to get the location in the input executable. */
322
323EXTERN long text_off;
324EXTERN long data_off;
325
326/* These arrays contain the text and data sections, respectively, of
327 the source a.out file. */
328
329EXTERN byte *text_image INIT (NULL);
330EXTERN byte *data_image INIT (NULL);
331
332/* These arrays contain the text and data relocation tables,
333 respectively, as read from the source a.out file. */
334
335EXTERN struct relocation_info *tr_image INIT (NULL);
336EXTERN struct relocation_info *dr_image INIT (NULL);
337
338/* This array contains the symbol table, as read from the source a.out
339 file. */
340
341EXTERN struct nlist *sym_image INIT (NULL);
342
343/* This array contains the string table, as read from the source a.out
344 file. */
345
346EXTERN byte *str_image INIT (NULL);
347
348/* This is the number of symbols of the source a.out file. */
349
350EXTERN int sym_count INIT (-1);
351
352/* This array holds the object table entries. Usually, the entries
353 are accessed via aliases, such as obj_text. */
354
355EXTERN struct object obj_h[OBJECTS];
356
357/* These are indices for the obj_h array. */
358
359#define OBJ_TEXT 0
360#define OBJ_DATA 1
361#define OBJ_HEAP 2
362#define OBJ_STK0 3
363
364/* Define shortcuts for the elements of the obj_h array. */
365
366#define obj_text obj_h[OBJ_TEXT]
367#define obj_data obj_h[OBJ_DATA]
368#define obj_heap obj_h[OBJ_HEAP]
369#define obj_stk0 obj_h[OBJ_STK0]
370
371/* This is the number of resource objects. */
372
373EXTERN int res_obj_count;
374
375/* This is the number of resources. */
376
377EXTERN int res_count;
378
379/* This is the number of resource pages. */
380
381EXTERN int res_pages;
382
383/* This is the number of preload resource pages. */
384
385EXTERN int res_preload_pages;
386
387/* entry_tab holds the entry table (table of exports) of the
388 executable, in LX EXE format, while it is being built. */
389
390EXTERN struct grow entry_tab INIT_GROW;
391
392/* resnames holds the resident name table (table of export symbol
393 names) of the executable, in LX EXE format, while it is being
394 built. */
395
396EXTERN struct grow resnames INIT_GROW;
397
398/* nonresnames holds the non-resident name table (table of export
399 symbol names) of the executable, in LX EXE format, while it is
400 being built. */
401
402EXTERN struct grow nonresnames INIT_GROW;
403
404/* The DOS EXE headers to be written to the output executable. */
405
406EXTERN struct exe1_header out_h1;
407EXTERN struct exe2_header out_h2;
408
409/* The location of the LX header of the output executable. */
410
411EXTERN long os2_hdr_pos;
412
413/* The location of the LX header in the input executable. */
414
415EXTERN long inp_os2_pos;
416
417/* The location of the a.out header in the output executable. */
418
419EXTERN long a_out_pos;
420
421/* The number of zero bytes to insert between the emx.exe or emxl.exe
422 image and the LX header. */
423
424EXTERN long fill2;
425
426/* This flag is set if a LIBRARY statement is seen in the module
427 definition file. */
428
429EXTERN int dll_flag INIT (FALSE);
430
431
432/* Round up to the next multiple of 4. */
433
434#define round_4(X) ((((X)-1) & ~3) + 4)
435
436/* Divide by the page size, rounding down. */
437
438#define div_page(X) ((X) >> 12)
439
440/* Compute the number of pages required for X bytes. */
441
442#define npages(X) div_page (round_page (X))
443
444/* Return the low 16-bit word of a 32-bit word. */
445
446#define LOWORD(X) ((X) & 0xffff)
447
448/* Return the high 16-bit word of a 32-bit word. */
449
450#define HIWORD(X) ((X) >> 16)
451
452/* Combine two 16-bit words (low word L and high word H) into a 32-bit
453 word. */
454
455#define COMBINE(L,H) ((L) | (long)((H) << 16))
456
457
458/* exec.c */
459
460void read_stub (void);
461void read_a_out_header (void);
462void read_core (void);
463void read_segs (void);
464void read_reloc (void);
465void read_sym (void);
466void read_os2_header (void);
467void exe_flags (void);
468void set_options (void);
469void set_exe_header (void);
470void put_header_byte (byte x);
471void put_header_word (word x);
472void put_header_dword (dword x);
473void put_header_bytes (const void *src, size_t size);
474void init_os2_header (void);
475void set_os2_header (void);
476void write_header (void);
477void write_nonres (void);
478void copy_a_out (void);
479void fill (long count);
480void copy (struct file *src, long size);
481
482/* fixup.c */
483
484void build_sym_hash_table (void);
485struct nlist *find_symbol (const char *name);
486void sort_fixup (void);
487void create_fixup (const struct fixup *fp, int neg);
488void relocations (void);
489void os2_fixup (void);
490void put_impmod (void);
491
492/* export.c */
493
494void add_export (const struct export *exp);
495void entry_name (struct grow *table, const char *name, int ord);
496void exports (void);
497const struct export *get_export (int i);
498
499/* resource.c */
500
501void read_res (void);
502void put_rsctab (void);
503void put_res_obj (int map);
504void write_res (void);
505
506/* cmd.c */
507
508void cmd (int mode);
509
510/* list.c */
511
512/* map.c */
513
514void write_map (const char *fname);
515void map_import (const char *sym_name, const char *mod, const char *name,
516 int ord);
517
518/* utils.c */
519
520void error (const char *fmt, ...) NORETURN2;
521void my_read (void *dst, size_t size, struct file *f);
522void my_read_str (byte *dst, size_t size, struct file *f);
523void my_write (const void *src, size_t size, struct file *f);
524void my_seek (struct file *f, long pos);
525void my_skip (struct file *f, long pos);
526long my_size (struct file *f);
527long my_tell (struct file *f);
528void my_trunc (struct file *f);
529void my_change (struct file *dst, struct file *src);
530void my_open (struct file *f, const char *name, enum open_mode mode);
531void my_close (struct file *f);
532void my_remove (struct file *f);
533int my_readable (const char *name);
534void *xmalloc (size_t n);
535void *xrealloc (void *p, size_t n);
536char *xstrdup (const char *p);
537void put_grow (struct grow *dst, const void *src, size_t size);
538const char *plural_s (long n);
Note: See TracBrowser for help on using the repository browser.