4 * header file for debug.c (exception handling and debugging).
7 * Note: Version numbering in this file relates to XWorkplace version
10 *@@changed V0.9.0: included contents of newexe.h
12 *@@include #define INCL_BASE
13 *@@include #include <os2.h>
14 *@@include #include <stdio.h>
15 *@@include #include "helpers\debug.h"
19 * This file incorporates code from the following:
20 * -- Marc Fiammante, John Currier, Kim Rasmussen,
21 * Anthony Cruise (EXCEPT3.ZIP package for a generic
22 * exception handling DLL, available at Hobbes).
24 * This file Copyright (C) 1992-99 Ulrich M”ller,
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation, in version 2 as it comes in the COPYING
32 * file of the XFolder main distribution.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
39 #ifndef DEBUG_HEADER_INCLUDED
40 #define DEBUG_HEADER_INCLUDED
42 /********************************************************************
44 * SYM file declarations
46 ********************************************************************/
48 // Pointer means offset from beginning of file or beginning of struct
53 unsigned short int ppNextMap
; // paragraph pointer to next map
54 unsigned char bFlags
; // symbol types
55 unsigned char bReserved1
; // reserved
56 unsigned short int pSegEntry
; // segment entry point value
57 unsigned short int cConsts
; // count of constants in map
58 unsigned short int pConstDef
; // pointer to constant chain
59 unsigned short int cSegs
; // count of segments in map
60 unsigned short int ppSegDef
; // paragraph pointer to first segment
61 unsigned char cbMaxSym
; // maximum symbol-name length
62 unsigned char cbModName
; // length of module name
63 char achModName
[1]; // cbModName Bytes of module-name member
68 unsigned short int ppNextMap
; // always zero
69 unsigned char release
; // release number (minor version number)
70 unsigned char version
; // major version number
75 unsigned short int ppNextSeg
; // paragraph pointer to next segment
76 unsigned short int cSymbols
; // count of symbols in list
77 unsigned short int pSymDef
; // offset of symbol chain
78 unsigned short int wReserved1
; // reserved
79 unsigned short int wReserved2
; // reserved
80 unsigned short int wReserved3
; // reserved
81 unsigned short int wReserved4
; // reserved
82 unsigned char bFlags
; // symbol types; bit 0 signals 32-bit (*UM)
83 unsigned char bReserved1
; // reserved
84 unsigned short int ppLineDef
; // offset of line number record
85 unsigned char bReserved2
; // reserved
86 unsigned char bReserved3
; // reserved
87 unsigned char cbSegName
; // length of segment name
88 char achSegName
[1]; /* cbSegName Bytes of segment-name member*/
93 unsigned short int wSymVal
; // symbol address or constant
94 unsigned char cbSymName
; // length of symbol name
95 char achSymName
[1]; // cbSymName Bytes of symbol-name member
100 unsigned int wSymVal
; // symbol address or constant
101 unsigned char cbSymName
; // length of symbol name
102 char achSymName
[1]; // cbSymName Bytes of symbol-name member
107 unsigned short int ppNextLine
; // ptr to next linedef (0 if last)
108 unsigned short int wReserved1
; // reserved
109 unsigned short int pLines
; // pointer to line numbers
110 unsigned short int cLines
; // reserved
111 unsigned char cbFileName
; // length of filename
112 char achFileName
[1];// cbFileName Bytes of filename
117 unsigned short int wCodeOffset
; // executable offset
118 unsigned short int dwFileOffset
; // source offset
121 #define SEGDEFOFFSET(MapDef) (MapDef.ppSegDef*16)
122 #define NEXTSEGDEFOFFSET(SegDef) (SegDef.ppNextSeg*16)
124 #define ASYMPTROFFSET(SegDefOffset,Segdef) (SegDefOffset+SegDef.pSymDef)
125 #define SYMDEFOFFSET(SegDefOffset,SegDef,n) (ASYMPTROFFSET(SegDefOffset,SegDef)+(n)*(sizeof(unsigned short int)))
127 #define ACONSTPTROFFSET(MapDef) (MapDef.ppConstDef)
128 #define CONSTDEFOFFSET(MapDef,n) ((MapDef.ppConstDef)+(n)*(sizeof(unsigned short int)))
130 #define LINEDEFOFFSET(SegDef) (SegDef.ppLineDef*16)
131 #define NEXTLINEDEFOFFSET(LineDef) (LineDef.ppNextLine*16)
132 #define LINESOFFSET(LinedefOffset,LineDef) ((LinedefOffset)+LineDef.pLines)
134 /********************************************************************
136 * EXE declarations taken from exe.h
138 ********************************************************************/
141 typedef unsigned short WORD
;
147 WORD eid
; // contains EXEID, below
148 WORD elast
; // # of bytes in last page
149 WORD epagsiz
; // # of pages in whole file
150 WORD erelcnt
; // # of relocation entrys
151 WORD ehdrsiz
; // size of header, in paragraphs
152 WORD eminfre
; // min # of free paragraphs needed
153 WORD emaxfre
; // max # of free paragraphs needed
154 WORD eiSS
; // initial SS value
155 WORD eiSP
; // initial SP value
156 WORD enegsum
; // negative sum of entire file
157 WORD eiIP
; // initial IP value
158 WORD eiCS
; // initial CS value
159 WORD ereloff
; // offset in file of relocation table
160 WORD eovlnum
; // number of the overlay
162 /* the following fields may not be present.
163 * ereloff = 28 not present
164 * = 30 exe.ever present and valid
165 * = 32 exe.ever field contains garbage
166 * ereloff > 32 exe.ever present and valid
167 * = 0 if "don't know"
170 WORD ever
; // version # of producing linker
173 /* the following fields may not be present - if the exe.ereloff
174 * value encompasses the fields then they are present and valid.
177 bbmask ebb
; // behavior bits
178 WORD dumy2
[7]; // must be 0 until defined
182 #define EXEID 0x5a4d // magic ID value
184 /********************************************************************
186 * Object Module Format (OMF) declarations
188 ********************************************************************/
192 BYTE signature
[2]; // Must be "MZ"
193 USHORT image_len
; // Image Length
194 USHORT pages
; // Pages
195 USHORT reloc_items
; // Relocation table items
196 USHORT min_paragraphs
; // Mininum 16-bytes paragraphs
197 USHORT max_paragraphs
; // Maximum 16-bytes paragraphs
198 USHORT stack_pos
; // Stack position
199 USHORT offset_in_sp
; // Offset in SP
200 USHORT checksum
; // Checksum
201 USHORT offset_in_ip
; // Offset in IP
202 USHORT code_pos
; // Code segment pos.
203 USHORT reloc_item_pos
; // Position of first relocation item
204 USHORT overlay_number
; // Overlay number
205 BYTE unused
[8]; // Unused bytes
206 USHORT oem_id
; // OEM Identifier
207 BYTE oem_info
[24]; // OEM Info
208 ULONG lexe_offset
; // Offset to linear header
213 BYTE signature
[2]; // Must be "LX"
214 BYTE b_ord
; // Byte ordering
215 BYTE w_ord
; // Word ordering
216 ULONG format_level
; // Format level
217 USHORT cpu_type
; // CPU Type
218 USHORT os_type
; // Operating system
219 ULONG module_version
; // Module version
220 ULONG mod_flags
; // Module flags
221 ULONG mod_pages
; // Module pages
222 ULONG EIP_object
; // EIP Object no.
223 ULONG EIP
; // EIP Value
224 ULONG ESP_object
; // ESP Object no
225 ULONG ESP
; // ESP Value
226 ULONG page_size
; // Page size
227 ULONG page_ofs_shift
; // Page offset shift
228 ULONG fixup_sect_size
; // Fixup section size
229 ULONG fixup_sect_checksum
; // Fixup section checksum
230 ULONG loader_sect_size
; // Loader section size
231 ULONG loader_sect_checksum
; // Loader section checksum
232 ULONG obj_table_ofs
; // Object table offset
233 ULONG obj_count
; // Object count
234 ULONG obj_page_tab_ofs
; // Object page table offset
235 ULONG obj_iter_page_ofs
; // Object iteration pages offset
236 ULONG res_tab_ofs
; // Resource table offset
237 ULONG res_table_entries
; // Resource table entries
238 ULONG res_name_tab_ofs
; // Resident name table offset;
239 ULONG ent_tab_ofs
; // Entry table offset
240 ULONG mod_dir_ofs
; // Module directives offset
241 ULONG mod_dir_count
; // Number of module directives
242 ULONG fixup_page_tab_ofs
; // Fixup page table offset
243 ULONG fixup_rec_tab_ofs
; // Fixup record table offset
244 ULONG imp_tab_ofs
; // Import module table offset
245 ULONG imp_mod_entries
; // Import module entries
246 ULONG imp_proc_tab_ofs
; // Import proc table offset
247 ULONG per_page_check_ofs
; // Per page checksum offset
248 ULONG data_page_offset
; // Data pages offset
249 ULONG preload_page_count
; // Preload pages count
250 ULONG nonres_tab_ofs
; // Nonresident name table offset
251 ULONG nonres_tab_len
; // Nonresident name table len
252 ULONG nonres_tab_check
; // Nonresident tables checksum
253 ULONG auto_ds_objectno
; // Auto DS object number
254 ULONG debug_info_ofs
; // Debug info offset
255 ULONG debug_info_len
; // Debug info length
256 ULONG inst_preload_count
; // Instance preload count
257 ULONG inst_demand_count
; // Instance demand count
258 ULONG heapsize
; // Heap size
259 ULONG stacksize
; // Stack size
262 struct debug_head_rec
264 BYTE signature
[3]; // Debug signature
265 BYTE type
; // Debug info type
270 USHORT dirstruct_size
; // Size of directory structure
271 USHORT number_of_entries
; // Number of dnt_rec's in the array
272 USHORT unknown
; // Unknown data
273 // Followed by an array of dnt_rec structures
278 USHORT subsect_type
; // sst Subsection type
279 USHORT mod_index
; // Module index (1-based)
280 ULONG offset
; // Offset of start of section
281 ULONG size
; // Size of section
284 // Modules subsection
287 USHORT code_seg_base
; // Code segment base
288 ULONG code_seg_offset
; // Code segment offset
289 ULONG code_seg_len
; // Code segment length
290 USHORT overlay_no
; // Overlay number
291 USHORT lib_idx
; // Index into library section or 0
292 BYTE segments
; // Number of segments
294 BYTE debug_style
[2]; // "HL" for HLL, "CV" or 0 for CodeView
295 BYTE debug_version
[2]; // 00 01 or 00 03 for HLL, 00 00 for CV
296 BYTE name_len
; // Length of name (which follows)
299 // Publics subsection
302 ULONG offset
; // Offset
303 USHORT segment
; // Segment
304 USHORT type
; // Type index
305 BYTE name_len
; // Length of name (wich follows)
309 // Linenumbers header
312 BYTE id
; // 0x95 for flat mem, 32 bit progs
313 USHORT length
; // Record length
314 USHORT base_group
; // Base group
315 USHORT base_segment
; // Base segment
319 // First linenumber record
322 USHORT lineno
; // Line number (0)
323 BYTE entry_type
; // Entry type
324 BYTE reserved
; // Reserved
325 USHORT entries_count
; // Number of table entries
326 USHORT segment_no
; // Segment number
327 ULONG filename_tabsize
; // File names table size
330 // Source line numbers
333 USHORT source_line
; // Source file line number
334 USHORT source_idx
; // Source file index
335 ULONG offset
; // Offset into segment
338 // Listing statement numbers
341 ULONG list_line
; // Listing file linenumber
342 ULONG statement
; // Listing file statement number
343 ULONG offset
; // Offset into segment
346 // Source and Listing statement numbers
347 struct linsourcelist_rec
349 USHORT source_line
; // Source file line number
350 USHORT source_idx
; // Source file index
351 ULONG list_line
; // Listing file linenumber
352 ULONG statement
; // Listing file statement number
353 ULONG offset
; // Offset into segment
359 ULONG offset
; // Offset into segment
360 USHORT path_code
; // Path code
361 USHORT source_idx
; // Source file index
367 ULONG first_char
; // First displayable char in list file
368 ULONG disp_chars
; // Number of displayable chars in list line
369 ULONG filecount
; // Number of source/listing files
373 #define SYM_BEGIN 0x00 // Begin block
374 #define SYM_PROC 0x01 // Function
375 #define SYM_END 0x02 // End block of function
376 #define SYM_AUTO 0x04 // Auto variable
377 #define SYM_STATIC 0x05 // Static variable
378 #define SYM_LABEL 0x0B // Label
379 #define SYM_WITH 0x0C // With start symbol (not used)
380 #define SYM_REG 0x0D // Register variable
381 #define SYM_CONST 0x0E // Constant
382 #define SYM_ENTRY 0x0F // Secondary entry (not in C)
383 #define SYM_SKIP 0x10 // For incremental linking (not used)
384 #define SYM_CHANGESEG 0x11 // Change segment (#pragma alloc_text)
385 #define SYM_TYPEDEF 0x12 // Typedef variable
386 #define SYM_PUBLIC 0x13 // Public reference
387 #define SYM_MEMBER 0x14 // Member of minor or major structure
388 #define SYM_BASED 0x15 // Based variable
389 #define SYM_TAG 0x16 // Tag in struct, union, enum ...
390 #define SYM_TABLE 0x17 // Table (used in RPG - not C)
391 #define SYM_MAP 0x18 // Map variable (extern in C)
392 #define SYM_CLASS 0x19 // Class symbol (C++)
393 #define SYM_MEMFUNC 0x1A // Member function
394 #define SYM_AUTOSCOPE 0x1B // Scoped auto for C++ (not used)
395 #define SYM_STATICSCOPE 0x1C // scoped static for C++ (not used)
396 #define SYM_CPPPROC 0x1D // C++ Proc
397 #define SYM_CPPSTAT 0x1E // C++ Static var
398 #define SYM_COMP 0x40 // Compiler information
400 // Symbolic begin record
403 ULONG offset
; // Segment offset
404 ULONG length
; // Length of block
405 BYTE name_len
; // Length of block name
406 // Block name follows
409 // Symbolic auto var record
412 ULONG stack_offset
; // Stack offset
413 USHORT type_idx
; // Type index
414 BYTE name_len
; // Length of name
418 // Symbolic procedure record
421 ULONG offset
; // Segment offset
422 USHORT type_idx
; // Type index
423 ULONG length
; // Length of procedure
424 USHORT pro_len
; // Length of prologue
425 ULONG pro_bodylen
; // Length of prologue + body
426 USHORT class_type
; // Class type
427 BYTE near_far
; // Near or far
428 BYTE name_len
; // Length of name
429 // Function name follows
432 // Symbolic static var record
435 ULONG offset
; // Segment offset
436 USHORT segaddr
; // Segment address
437 USHORT type_idx
; // Type index
438 BYTE name_len
; // Length of name
442 // Symbolic label var record
445 ULONG offset
; // Segment offset
446 BYTE near_far
; // Near or far
447 BYTE name_len
; // Length of name
451 // Symbolic register var record
454 USHORT type_idx
; // Type index
455 BYTE reg_no
; // Register number
456 BYTE name_len
; // Length of name
460 // Symbolic change-segment record
463 USHORT seg_no
; // Segment number
466 // Symbolic typedef record
467 struct symtypedef_rec
469 USHORT type_idx
; // Type index
470 BYTE name_len
; // Length of name
474 // Symbolic public record
477 ULONG offset
; // Segment offset
478 USHORT segaddr
; // Segment address
479 USHORT type_idx
; // Type index
480 BYTE name_len
; // Length of name
484 // Symbolic member record
487 ULONG offset
; // Offset to subrecord
488 BYTE name_len
; // Length of name
492 // Symbolic based record
495 ULONG offset
; // Offset to subrecord
496 USHORT type_idx
; // Type index
497 BYTE name_len
; // Length of name
501 // Symbolic tag record
504 USHORT type_idx
; // Type index
505 BYTE name_len
; // Length of name
509 // Symbolic table record
512 ULONG offset
; // Segment offset
513 USHORT segaddr
; // Segment address
514 USHORT type_idx
; // Type index
515 ULONG idx_ofs
; // Index offset to subrecord
516 BYTE name_len
; // Length of name
523 USHORT length
; // Length of sub-record
524 BYTE type
; // Sub-record type
525 BYTE type_qual
; // Type qualifier
529 #define TYPE_CLASS 0x40 // Class
530 #define TYPE_BASECLASS 0x41 // Base class
531 #define TYPE_FRIEND 0x42 // Friend
532 #define TYPE_CLASSDEF 0x43 // Class definition
533 #define TYPE_MEMBERFUNC 0x45 // Member function
534 #define TYPE_CLASSMEMBER 0x46 // Class member
535 #define TYPE_REF 0x48 // Reference
536 #define TYPE_MEMBERPTR 0x49 // Member pointer
537 #define TYPE_SCALARS 0x51 // Scalars
538 #define TYPE_SET 0x52 // Set
539 #define TYPE_ENTRY 0x53 // Entry
540 #define TYPE_FUNCTION 0x54 // Function
541 #define TYPE_AREA 0x55 // Area
542 #define TYPE_LOGICAL 0x56 // Logical
543 #define TYPE_STACK 0x57 // Stack
544 #define TYPE_MACRO 0x59 // Macro
545 #define TYPE_BITSTRING 0x5C // Bit string
546 #define TYPE_USERDEF 0x5D // User defined
547 #define TYPE_CHARSTR 0x60 // Character string
548 #define TYPE_PICTURE 0x61 // Picture
549 #define TYPE_GRAPHIC 0x62 // Graphic
550 #define TYPE_FORMATLAB 0x65 // Format label
551 #define TYPE_FILE 0x67 // File
552 #define TYPE_SUBRANGE 0x6F // Subrange
553 #define TYPE_CODELABEL 0x72 // Code label
554 #define TYPE_PROCEDURE 0x75 // Procedure
555 #define TYPE_ARRAY 0x78 // Array
556 #define TYPE_STRUCT 0x79 // Structure / Union / Record
557 #define TYPE_POINTER 0x7A // Pointer
558 #define TYPE_ENUM 0x7B // Enum
559 #define TYPE_LIST 0x7F // List
562 struct type_userdefrec
564 BYTE FID_index
; // Field ID
565 USHORT type_index
; // Type index
566 BYTE FID_string
; // String ID
567 BYTE name_len
; // Length of name which follows
575 BYTE FID_index
; // Field ID
576 USHORT type_index
; // Type index of return value
577 BYTE FID_index1
; // String ID
578 USHORT typelist_index
; // Index of list of params
582 struct type_structrec
584 ULONG size
; // Size of structure
585 USHORT field_count
; // Number of fields in structure
586 BYTE FID_index
; // Field ID
587 USHORT type_list_idx
; // Index to type list
588 BYTE FID_index1
; // Field ID
589 USHORT type_name_idx
; // Index to names / offsets
590 BYTE dont_know
; // Haven't a clue, but it seems to be needed
591 BYTE name_len
; // Length of structure name which follows
594 // Type list, type qualifier 1: contains types for structures
595 // This record is repeated for the number of items in the structure definition
598 BYTE FID_index
; // Field identifier for index
599 USHORT type_index
; // Type index.
602 // Type list, type qualifier 2: contains names and offsets for structure items
603 // This record is repeated for the number of items in the structure definition
606 BYTE FID_string
; // String identifier
607 BYTE name_len
; // Length of name which follows
610 // Type list, subrecord to the above, contains offset of variable in the structure
613 BYTE FID_span
; // Defines what type of variable follows
622 struct type_pointerrec
624 BYTE FID_index
; // Index identifier
625 USHORT type_index
; // Type index
626 BYTE FID_string
; // String identifier
627 BYTE name_len
; // Length of name which follows
630 /********************************************************************
634 ********************************************************************/
636 BOOL
dbgPrintStackFrame(FILE *LogFile
,
637 PSZ pszModuleName
, // in: module name (fully q'fied)
641 VOID
dbgPrintStack(FILE *file
,
645 PUSHORT ExceptionAddress
);
647 APIRET APIENTRY
DosQueryModFromEIP(HMODULE
*phMod
, // out: trapping module
648 ULONG
*pulObjNum
, // out: object/segment number
649 ULONG ulBuffLen
, // in: sizeof(*pszBuff)
650 CHAR
*pszBuff
, // out: module name
651 ULONG
*pulOffset
, // out: offset in module
652 ULONG ulAddress
); // in: address to be analyzed
654 APIRET APIENTRY
DOSQUERYMODFROMEIP(HMODULE
* phMod
,
661 typedef ULONG
*_Seg16 PULONG16
;
662 APIRET16 APIENTRY16
DOS16SIZESEG(USHORT Seg
, PULONG16 Size
);
663 typedef APIRET16(APIENTRY16 _PFN16
) (VOID
);
664 ULONG APIENTRY
DosSelToFlat(ULONG
);
666 APIRET16 APIENTRY16
DOSQPROCSTATUS(ULONG
* _Seg16 pBuf
, USHORT cbBuf
);
668 #define CONVERT(fp,QSsel) MAKEP((QSsel),OFFSETOF(fp))
670 #pragma pack() // added V0.9.0
673 /********************************************************************
675 * Executable definitions
677 ********************************************************************/
686 /*_________________________________________________________________*
689 | DOS3 .EXE FILE HEADER DEFINITION |
691 |_________________________________________________________________|
695 #define EMAGIC 0x5A4D // Old magic number
696 #define ENEWEXE sizeof(struct exe_hdr)
697 // Value of E_LFARLC for new .EXEs
698 #define ENEWHDR 0x003C // Offset in old hdr. of ptr. to new
699 #define ERESWDS 0x0010 // No. of reserved words (OLD)
700 #define ERES1WDS 0x0004 // No. of reserved words in e_res
701 #define ERES2WDS 0x000A // No. of reserved words in e_res2
702 #define ECP 0x0004 // Offset in struct of E_CP
703 #define ECBLP 0x0002 // Offset in struct of E_CBLP
704 #define EMINALLOC 0x000A // Offset in struct of E_MINALLOC
708 * DOS 1, 2, 3 .EXE header.
713 unsigned short e_magic
; // Magic number
714 unsigned short e_cblp
; // Bytes on last page of file
715 unsigned short e_cp
; // Pages in file
716 unsigned short e_crlc
; // Relocations
717 unsigned short e_cparhdr
; // Size of header in paragraphs
718 unsigned short e_minalloc
; // Minimum extra paragraphs needed
719 unsigned short e_maxalloc
; // Maximum extra paragraphs needed
720 unsigned short e_ss
; // Initial (relative) SS value
721 unsigned short e_sp
; // Initial SP value
722 unsigned short e_csum
; // Checksum
723 unsigned short e_ip
; // Initial IP value
724 unsigned short e_cs
; // Initial (relative) CS value
725 unsigned short e_lfarlc
; // File address of relocation table
726 unsigned short e_ovno
; // Overlay number
727 unsigned short e_res
[ERES1WDS
];// Reserved words
728 unsigned short e_oemid
; // OEM identifier (for e_oeminfo)
729 unsigned short e_oeminfo
; // OEM information; e_oemid specific
730 unsigned short e_res2
[ERES2WDS
];// Reserved words
731 long e_lfanew
; // File address of new exe header
734 #define E_MAGIC(x) (x).e_magic
735 #define E_CBLP(x) (x).e_cblp
736 #define E_CP(x) (x).e_cp
737 #define E_CRLC(x) (x).e_crlc
738 #define E_CPARHDR(x) (x).e_cparhdr
739 #define E_MINALLOC(x) (x).e_minalloc
740 #define E_MAXALLOC(x) (x).e_maxalloc
741 #define E_SS(x) (x).e_ss
742 #define E_SP(x) (x).e_sp
743 #define E_CSUM(x) (x).e_csum
744 #define E_IP(x) (x).e_ip
745 #define E_CS(x) (x).e_cs
746 #define E_LFARLC(x) (x).e_lfarlc
747 #define E_OVNO(x) (x).e_ovno
748 #define E_RES(x) (x).e_res
749 #define E_OEMID(x) (x).e_oemid
750 #define E_OEMINFO(x) (x).e_oeminfo
751 #define E_RES2(x) (x).e_res2
752 #define E_LFANEW(x) (x).e_lfanew
755 /*_________________________________________________________________*
758 | OS/2 & WINDOWS .EXE FILE HEADER DEFINITION - 286 version |
760 |_________________________________________________________________|
763 #define NEMAGIC 0x454E // New magic number
764 #define NERESBYTES 8 // Eight bytes reserved (now)
765 #define NECRC 8 // Offset into new header of NE_CRC
769 * New Executable (NE) header.
770 * Follows DOS header in the executable file.
775 unsigned short ne_magic
; // Magic number NE_MAGIC
776 unsigned char ne_ver
; // Version number
777 unsigned char ne_rev
; // Revision number
778 unsigned short ne_enttab
; // Offset of Entry Table
779 unsigned short ne_cbenttab
; // Number of bytes in Entry Table
780 long ne_crc
; // Checksum of whole file
781 unsigned short ne_flags
; // Flag word
782 unsigned short ne_autodata
; // Automatic data segment number
783 unsigned short ne_heap
; // Initial heap allocation
784 unsigned short ne_stack
; // Initial stack allocation
785 long ne_csip
; // Initial CS:IP setting
786 long ne_sssp
; // Initial SS:SP setting
787 unsigned short ne_cseg
; // Count of file segments
788 unsigned short ne_cmod
; // Entries in Module Reference Table
789 unsigned short ne_cbnrestab
; // Size of non-resident name table
790 unsigned short ne_segtab
; // Offset of Segment Table
791 unsigned short ne_rsrctab
; // Offset of Resource Table
792 unsigned short ne_restab
; // Offset of resident name table
793 unsigned short ne_modtab
; // Offset of Module Reference Table
794 unsigned short ne_imptab
; // Offset of Imported Names Table
795 long ne_nrestab
; // Offset of Non-resident Names Table
796 unsigned short ne_cmovent
; // Count of movable entries
797 unsigned short ne_align
; // Segment alignment shift count
798 unsigned short ne_cres
; // Count of resource entries
799 unsigned char ne_exetyp
; // Target operating system
800 unsigned char ne_flagsothers
; // Other .EXE flags
801 char ne_res
[NERESBYTES
]; // Pad structure to 64 bytes
806 #define NE_MAGIC(x) (x).ne_magic
807 #define NE_VER(x) (x).ne_ver
808 #define NE_REV(x) (x).ne_rev
809 #define NE_ENTTAB(x) (x).ne_enttab
810 #define NE_CBENTTAB(x) (x).ne_cbenttab
811 #define NE_CRC(x) (x).ne_crc
812 #define NE_FLAGS(x) (x).ne_flags
813 #define NE_AUTODATA(x) (x).ne_autodata
814 #define NE_HEAP(x) (x).ne_heap
815 #define NE_STACK(x) (x).ne_stack
816 #define NE_CSIP(x) (x).ne_csip
817 #define NE_SSSP(x) (x).ne_sssp
818 #define NE_CSEG(x) (x).ne_cseg
819 #define NE_CMOD(x) (x).ne_cmod
820 #define NE_CBNRESTAB(x) (x).ne_cbnrestab
821 #define NE_SEGTAB(x) (x).ne_segtab
822 #define NE_RSRCTAB(x) (x).ne_rsrctab
823 #define NE_RESTAB(x) (x).ne_restab
824 #define NE_MODTAB(x) (x).ne_modtab
825 #define NE_IMPTAB(x) (x).ne_imptab
826 #define NE_NRESTAB(x) (x).ne_nrestab
827 #define NE_CMOVENT(x) (x).ne_cmovent
828 #define NE_ALIGN(x) (x).ne_align
829 #define NE_CRES(x) (x).ne_cres
830 #define NE_RES(x) (x).ne_res
831 #define NE_EXETYP(x) (x).ne_exetyp
832 #define NE_FLAGSOTHERS(x) (x).ne_flagsothers
834 #define NE_USAGE(x) (WORD)*((WORD *)(x)+1)
835 #define NE_PNEXTEXE(x) (WORD)(x).ne_cbenttab
836 #define NE_ONEWEXE(x) (WORD)(x).ne_crc
837 #define NE_PFILEINFO(x) (WORD)((DWORD)(x).ne_crc >> 16)
841 * Target operating systems
844 #define NE_UNKNOWN 0x0 /* Unknown (any "new-format" OS) */
845 #define NE_OS2 0x1 /* OS/2 (default) */
846 #define NE_WINDOWS 0x2 /* Windows */
847 #define NE_DOS4 0x3 /* DOS 4.x */
848 #define NE_DEV386 0x4 /* Windows 386 */
852 * Format of NE_FLAGS(x):
859 * ttt Application type
860 * f Floating-point instructions
863 * 0 8086 instructions
864 * P Protected mode only
865 * p Per-process library initialization
869 #define NENOTP 0x8000 /* Not a process */
870 #define NEIERR 0x2000 /* Errors in image */
871 #define NEBOUND 0x0800 /* Bound Family/API */
872 #define NEAPPTYP 0x0700 /* Application type mask */
873 #define NENOTWINCOMPAT 0x0100 /* Not compatible with P.M. Windowing */
874 #define NEWINCOMPAT 0x0200 /* Compatible with P.M. Windowing */
875 #define NEWINAPI 0x0300 /* Uses P.M. Windowing API */
876 #define NEFLTP 0x0080 /* Floating-point instructions */
877 #define NEI386 0x0040 /* 386 instructions */
878 #define NEI286 0x0020 /* 286 instructions */
879 #define NEI086 0x0010 /* 8086 instructions */
880 #define NEPROT 0x0008 /* Runs in protected mode only */
881 #define NEPPLI 0x0004 /* Per-Process Library Initialization */
882 #define NEINST 0x0002 /* Instance data */
883 #define NESOLO 0x0001 /* Solo data */
886 * Format of NE_FLAGSOTHERS(x):
888 * 7 6 5 4 3 2 1 0 - bit no
890 * | | | +---------------- Support for long file names
891 * | | +------------------ Windows 2.x app runs in prot mode
892 * | +-------------------- Windows 2.x app gets prop. font
893 * +------------------------------ WLO appl on OS/2 (markwlo.exe)
897 #define NELONGNAMES 0x01
898 #define NEWINISPROT 0x02
899 #define NEWINGETPROPFON 0x04
900 #define NEWLOAPPL 0x80
904 struct new_seg
/* New .EXE segment table entry */
906 unsigned short ns_sector
; /* File sector of start of segment */
907 unsigned short ns_cbseg
; /* Number of bytes in file */
908 unsigned short ns_flags
; /* Attribute flags */
909 unsigned short ns_minalloc
; /* Minimum allocation in bytes */
912 #define NS_SECTOR(x) (x).ns_sector
913 #define NS_CBSEG(x) (x).ns_cbseg
914 #define NS_FLAGS(x) (x).ns_flags
915 #define NS_MINALLOC(x) (x).ns_minalloc
919 * Format of NS_FLAGS(x)
921 * Flag word has the following format:
923 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - bit no
924 * | | | | | | | | | | | | | | |
925 * | | | | | | | | | | | | +-+-+--- Segment type DATA/CODE
926 * | | | | | | | | | | | +--------- Iterated segment
927 * | | | | | | | | | | +----------- Movable segment
928 * | | | | | | | | | +------------- Segment can be shared
929 * | | | | | | | | +--------------- Preload segment
930 * | | | | | | | +----------------- Execute/read-only for code/data segment
931 * | | | | | | +------------------- Segment has relocations
932 * | | | | | +--------------------- Code conforming/Data is expand down
933 * | | | +--+----------------------- I/O privilege level
934 * | | +----------------------------- Discardable segment
935 * | +-------------------------------- 32-bit code segment
936 * +----------------------------------- Huge segment/GDT allocation requested
940 #define NSTYPE 0x0007 /* Segment type mask */
943 #define NSCODE 0x0000 /* Code segment */
944 #define NSDATA 0x0001 /* Data segment */
945 #define NSITER 0x0008 /* Iterated segment flag */
946 #define NSMOVE 0x0010 /* Movable segment flag */
947 #define NSSHARED 0x0020 /* Shared segment flag */
948 #define NSPRELOAD 0x0040 /* Preload segment flag */
949 #define NSEXRD 0x0080 /* Execute-only (code segment), or
950 * read-only (data segment)
952 #define NSRELOC 0x0100 /* Segment has relocations */
953 #define NSCONFORM 0x0200 /* Conforming segment */
954 #define NSEXPDOWN 0x0200 /* Data segment is expand down */
955 #define NSDPL 0x0C00 /* I/O privilege level (286 DPL bits) */
956 #define SHIFTDPL 10 /* Left shift count for SEGDPL field */
957 #define NSDISCARD 0x1000 /* Segment is discardable */
958 #define NS32BIT 0x2000 /* 32-bit code segment */
959 #define NSHUGE 0x4000 /* Huge memory segment, length of
960 * segment and minimum allocation
961 * size are in segment sector units
963 #define NSGDT 0x8000 /* GDT allocation requested */
965 #define NSPURE NSSHARED /* For compatibility */
967 #define NSALIGN 9 /* Segment data aligned on 512 byte boundaries */
969 #define NSLOADED 0x0004 /* ns_sector field contains memory addr */
973 struct new_segdata
/* Segment data */
979 unsigned short ns_niter
; /* number of iterations */
980 unsigned short ns_nbytes
; /* number of bytes */
981 char ns_iterdata
; /* iterated data bytes */
985 char ns_data
; /* data bytes */
990 struct new_rlcinfo
/* Relocation info */
992 unsigned short nr_nreloc
; /* number of relocation items that */
998 struct new_rlc
/* Relocation item */
1000 char nr_stype
; /* Source type */
1001 char nr_flags
; /* Flag byte */
1002 unsigned short nr_soff
; /* Source offset */
1007 char nr_segno
; /* Target segment number */
1008 char nr_res
; /* Reserved */
1009 unsigned short nr_entry
; /* Target Entry Table offset */
1010 } nr_intref
; /* Internal reference */
1013 unsigned short nr_mod
; /* Index into Module Reference Table */
1014 unsigned short nr_proc
; /* Procedure ordinal or name offset */
1015 } nr_import
; /* Import */
1018 unsigned short nr_ostype
; /* OSFIXUP type */
1019 unsigned short nr_osres
; /* reserved */
1020 } nr_osfix
; /* Operating system fixup */
1021 } nr_union
; /* Union */
1027 #define NR_STYPE(x) (x).nr_stype
1028 #define NR_FLAGS(x) (x).nr_flags
1029 #define NR_SOFF(x) (x).nr_soff
1030 #define NR_SEGNO(x) (x).nr_union.nr_intref.nr_segno
1031 #define NR_RES(x) (x).nr_union.nr_intref.nr_res
1032 #define NR_ENTRY(x) (x).nr_union.nr_intref.nr_entry
1033 #define NR_MOD(x) (x).nr_union.nr_import.nr_mod
1034 #define NR_PROC(x) (x).nr_union.nr_import.nr_proc
1035 #define NR_OSTYPE(x) (x).nr_union.nr_osfix.nr_ostype
1036 #define NR_OSRES(x) (x).nr_union.nr_osfix.nr_osres
1041 * Format of NR_STYPE(x) and R32_STYPE(x):
1043 * 7 6 5 4 3 2 1 0 - bit no
1045 * +-+-+-+--- source type
1049 #define NRSTYP 0x0f /* Source type mask */
1050 #define NRSBYT 0x00 /* lo byte (8-bits)*/
1051 #define NRSSEG 0x02 /* 16-bit segment (16-bits) */
1052 #define NRSPTR 0x03 /* 16:16 pointer (32-bits) */
1053 #define NRSOFF 0x05 /* 16-bit offset (16-bits) */
1054 #define NRPTR48 0x06 /* 16:32 pointer (48-bits) */
1055 #define NROFF32 0x07 /* 32-bit offset (32-bits) */
1056 #define NRSOFF32 0x08 /* 32-bit self-relative offset (32-bits) */
1060 * Format of NR_FLAGS(x) and R32_FLAGS(x):
1062 * 7 6 5 4 3 2 1 0 - bit no
1064 * | +-+--- Reference type
1065 * +------- Additive fixup
1068 #define NRADD 0x04 /* Additive fixup */
1069 #define NRRTYP 0x03 /* Reference type mask */
1070 #define NRRINT 0x00 /* Internal reference */
1071 #define NRRORD 0x01 /* Import by ordinal */
1072 #define NRRNAM 0x02 /* Import by name */
1073 #define NRROSF 0x03 /* Operating system fixup */
1078 /* Resource type or name string */
1081 char rs_len
; /* number of bytes in string */
1082 char rs_string
[ 1 ]; /* text of string */
1085 #define RS_LEN( x ) (x).rs_len
1086 #define RS_STRING( x ) (x).rs_string
1088 /* Resource type information block */
1089 struct rsrc_typeinfo
1091 unsigned short rt_id
;
1092 unsigned short rt_nres
;
1096 #define RT_ID( x ) (x).rt_id
1097 #define RT_NRES( x ) (x).rt_nres
1098 #define RT_PROC( x ) (x).rt_proc
1100 /* Resource name information block */
1101 struct rsrc_nameinfo
1103 /* The following two fields must be shifted left by the value of */
1104 /* the rs_align field to compute their actual value. This allows */
1105 /* resources to be larger than 64k, but they do not need to be */
1106 /* aligned on 512 byte boundaries, the way segments are */
1107 unsigned short rn_offset
; /* file offset to resource data */
1108 unsigned short rn_length
; /* length of resource data */
1109 unsigned short rn_flags
; /* resource flags */
1110 unsigned short rn_id
; /* resource name id */
1111 unsigned short rn_handle
; /* If loaded, then global handle */
1112 unsigned short rn_usage
; /* Initially zero. Number of times */
1113 /* the handle for this resource has */
1114 /* been given out */
1117 #define RN_OFFSET( x ) (x).rn_offset
1118 #define RN_LENGTH( x ) (x).rn_length
1119 #define RN_FLAGS( x ) (x).rn_flags
1120 #define RN_ID( x ) (x).rn_id
1121 #define RN_HANDLE( x ) (x).rn_handle
1122 #define RN_USAGE( x ) (x).rn_usage
1124 #define RSORDID 0x8000 /* if high bit of ID set then integer id */
1125 /* otherwise ID is offset of string from
1126 the beginning of the resource table */
1128 /* Ideally these are the same as the */
1129 /* corresponding segment flags */
1130 #define RNMOVE 0x0010 /* Moveable resource */
1131 #define RNPURE 0x0020 /* Pure (read-only) resource */
1132 #define RNPRELOAD 0x0040 /* Preloaded resource */
1133 #define RNDISCARD 0xF000 /* Discard priority level for resource */
1135 /* Resource table */
1138 unsigned short rs_align
; /* alignment shift count for resources */
1139 struct rsrc_typeinfo rs_typeinfo
;
1142 #define RS_ALIGN( x ) (x).rs_align
1145 #endif /* NOT EXE386 */
1147 #endif /* __NEWEXE__ */
1150 #define DWORD long int
1154 #define WORD short int
1160 #pragma pack(1) /* Force byte alignment */
1162 /*_________________________________________________________________*
1165 | OS/2 .EXE FILE HEADER DEFINITION - 386 version 0:32 |
1167 |_________________________________________________________________|
1170 #define BITPERWORD 16
1171 #define BITPERBYTE 8
1172 #define OBJPAGELEN 4096
1173 #define E32MAGIC1 'L' /* New magic number "LX" */
1174 #define E32MAGIC2 'X' /* New magic number "LX" */
1175 #define E32MAGIC 0x584c /* New magic number "LX" */
1176 #define E32RESBYTES1 0 /* First bytes reserved */
1177 #define E32RESBYTES2 0 /* Second bytes reserved */
1178 #define E32RESBYTES3 20 /* Third bytes reserved */
1179 #define E32LEBO 0x00 /* Little Endian Byte Order */
1180 #define E32BEBO 0x01 /* Big Endian Byte Order */
1181 #define E32LEWO 0x00 /* Little Endian Word Order */
1182 #define E32BEWO 0x01 /* Big Endian Word Order */
1183 #define E32LEVEL 0L /* 32-bit EXE format level */
1184 #define E32CPU286 0x001 /* Intel 80286 or upwardly compatibile */
1185 #define E32CPU386 0x002 /* Intel 80386 or upwardly compatibile */
1186 #define E32CPU486 0x003 /* Intel 80486 or upwardly compatibile */
1190 struct e32_exe
/* New 32-bit .EXE header */
1192 unsigned char e32_magic
[2]; /* Magic number E32_MAGIC */
1193 unsigned char e32_border
; /* The byte ordering for the .EXE */
1194 unsigned char e32_worder
; /* The word ordering for the .EXE */
1195 unsigned long e32_level
; /* The EXE format level for now = 0 */
1196 unsigned short e32_cpu
; /* The CPU type */
1197 unsigned short e32_os
; /* The OS type */
1198 unsigned long e32_ver
; /* Module version */
1199 unsigned long e32_mflags
; /* Module flags */
1200 unsigned long e32_mpages
; /* Module # pages */
1201 unsigned long e32_startobj
; /* Object # for instruction pointer */
1202 unsigned long e32_eip
; /* Extended instruction pointer */
1203 unsigned long e32_stackobj
; /* Object # for stack pointer */
1204 unsigned long e32_esp
; /* Extended stack pointer */
1205 unsigned long e32_pagesize
; /* .EXE page size */
1206 unsigned long e32_pageshift
; /* Page alignment shift in .EXE */
1207 unsigned long e32_fixupsize
; /* Fixup section size */
1208 unsigned long e32_fixupsum
; /* Fixup section checksum */
1209 unsigned long e32_ldrsize
; /* Loader section size */
1210 unsigned long e32_ldrsum
; /* Loader section checksum */
1211 unsigned long e32_objtab
; /* Object table offset */
1212 unsigned long e32_objcnt
; /* Number of objects in module */
1213 unsigned long e32_objmap
; /* Object page map offset */
1214 unsigned long e32_itermap
; /* Object iterated data map offset */
1215 unsigned long e32_rsrctab
; /* Offset of Resource Table */
1216 unsigned long e32_rsrccnt
; /* Number of resource entries */
1217 unsigned long e32_restab
; /* Offset of resident name table */
1218 unsigned long e32_enttab
; /* Offset of Entry Table */
1219 unsigned long e32_dirtab
; /* Offset of Module Directive Table */
1220 unsigned long e32_dircnt
; /* Number of module directives */
1221 unsigned long e32_fpagetab
; /* Offset of Fixup Page Table */
1222 unsigned long e32_frectab
; /* Offset of Fixup Record Table */
1223 unsigned long e32_impmod
; /* Offset of Import Module Name Table */
1224 unsigned long e32_impmodcnt
; /* Number of entries in Import Module Name Table */
1225 unsigned long e32_impproc
; /* Offset of Import Procedure Name Table */
1226 unsigned long e32_pagesum
; /* Offset of Per-Page Checksum Table */
1227 unsigned long e32_datapage
; /* Offset of Enumerated Data Pages */
1228 unsigned long e32_preload
; /* Number of preload pages */
1229 unsigned long e32_nrestab
; /* Offset of Non-resident Names Table */
1230 unsigned long e32_cbnrestab
; /* Size of Non-resident Name Table */
1231 unsigned long e32_nressum
; /* Non-resident Name Table Checksum */
1232 unsigned long e32_autodata
; /* Object # for automatic data object */
1233 unsigned long e32_debuginfo
; /* Offset of the debugging information */
1234 unsigned long e32_debuglen
; /* The length of the debugging info. in bytes */
1235 unsigned long e32_instpreload
;/* Number of instance pages in preload section of .EXE file */
1236 unsigned long e32_instdemand
; /* Number of instance pages in demand load section of .EXE file */
1237 unsigned long e32_heapsize
; /* Size of heap - for 16-bit apps */
1238 unsigned long e32_stacksize
; /* Size of stack */
1239 unsigned char e32_res3
[E32RESBYTES3
];
1240 /* Pad structure to 196 bytes */
1245 #define E32_MAGIC1(x) (x).e32_magic[0]
1246 #define E32_MAGIC2(x) (x).e32_magic[1]
1247 #define E32_BORDER(x) (x).e32_border
1248 #define E32_WORDER(x) (x).e32_worder
1249 #define E32_LEVEL(x) (x).e32_level
1250 #define E32_CPU(x) (x).e32_cpu
1251 #define E32_OS(x) (x).e32_os
1252 #define E32_VER(x) (x).e32_ver
1253 #define E32_MFLAGS(x) (x).e32_mflags
1254 #define E32_MPAGES(x) (x).e32_mpages
1255 #define E32_STARTOBJ(x) (x).e32_startobj
1256 #define E32_EIP(x) (x).e32_eip
1257 #define E32_STACKOBJ(x) (x).e32_stackobj
1258 #define E32_ESP(x) (x).e32_esp
1259 #define E32_PAGESIZE(x) (x).e32_pagesize
1260 #define E32_PAGESHIFT(x) (x).e32_pageshift
1261 #define E32_FIXUPSIZE(x) (x).e32_fixupsize
1262 #define E32_FIXUPSUM(x) (x).e32_fixupsum
1263 #define E32_LDRSIZE(x) (x).e32_ldrsize
1264 #define E32_LDRSUM(x) (x).e32_ldrsum
1265 #define E32_OBJTAB(x) (x).e32_objtab
1266 #define E32_OBJCNT(x) (x).e32_objcnt
1267 #define E32_OBJMAP(x) (x).e32_objmap
1268 #define E32_ITERMAP(x) (x).e32_itermap
1269 #define E32_RSRCTAB(x) (x).e32_rsrctab
1270 #define E32_RSRCCNT(x) (x).e32_rsrccnt
1271 #define E32_RESTAB(x) (x).e32_restab
1272 #define E32_ENTTAB(x) (x).e32_enttab
1273 #define E32_DIRTAB(x) (x).e32_dirtab
1274 #define E32_DIRCNT(x) (x).e32_dircnt
1275 #define E32_FPAGETAB(x) (x).e32_fpagetab
1276 #define E32_FRECTAB(x) (x).e32_frectab
1277 #define E32_IMPMOD(x) (x).e32_impmod
1278 #define E32_IMPMODCNT(x) (x).e32_impmodcnt
1279 #define E32_IMPPROC(x) (x).e32_impproc
1280 #define E32_PAGESUM(x) (x).e32_pagesum
1281 #define E32_DATAPAGE(x) (x).e32_datapage
1282 #define E32_PRELOAD(x) (x).e32_preload
1283 #define E32_NRESTAB(x) (x).e32_nrestab
1284 #define E32_CBNRESTAB(x) (x).e32_cbnrestab
1285 #define E32_NRESSUM(x) (x).e32_nressum
1286 #define E32_AUTODATA(x) (x).e32_autodata
1287 #define E32_DEBUGINFO(x) (x).e32_debuginfo
1288 #define E32_DEBUGLEN(x) (x).e32_debuglen
1289 #define E32_INSTPRELOAD(x) (x).e32_instpreload
1290 #define E32_INSTDEMAND(x) (x).e32_instdemand
1291 #define E32_HEAPSIZE(x) (x).e32_heapsize
1292 #define E32_STACKSIZE(x) (x).e32_stacksize
1297 * Format of E32_MFLAGS(x):
1299 * Low word has the following format:
1301 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - bit no
1303 * | | | | | | | +------- Per-Process Library Initialization
1304 * | | | | | | +--------- SystemDLL (internal fixups discarded)
1305 * | | | | | +----------- No Internal Fixups for Module in .EXE
1306 * | | | | +------------- No External Fixups for Module in .EXE
1307 * | | | +------------------- Incompatible with PM Windowing
1308 * | | +--------------------- Compatible with PM Windowing
1309 * | | Uses PM Windowing API
1310 * | +-------------------------------- Module not Loadable
1311 * +-------------------------------------- Library Module
1315 #define E32NOTP 0x8000L /* Library Module - used as NENOTP */
1316 #define E32NOLOAD 0x2000L /* Module not Loadable */
1317 #define E32PMAPI 0x0300L /* Uses PM Windowing API */
1318 #define E32PMW 0x0200L /* Compatible with PM Windowing */
1319 #define E32NOPMW 0x0100L /* Incompatible with PM Windowing */
1320 #define E32NOEXTFIX 0x0020L /* NO External Fixups in .EXE */
1321 #define E32NOINTFIX 0x0010L /* NO Internal Fixups in .EXE */
1322 #define E32SYSDLL 0x0008L /* System DLL, Internal Fixups discarded*/
1323 #define E32LIBINIT 0x0004L /* Per-Process Library Initialization */
1324 #define E32LIBTERM 0x40000000L /* Per-Process Library Termination */
1325 #define E32APPMASK 0x0300L /* Application Type Mask */
1329 * Format of E32_MFLAGS(x):
1331 * High word has the following format:
1333 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - bit no
1335 * | +--- Protected memory library module
1336 * +----- Device driver
1339 #define E32PROTDLL 0x10000L /* Protected memory library module */
1340 #define E32DEVICE 0x20000L /* Device driver */
1341 #define E32MODEXE 0x00000L /* .EXE module */
1342 #define E32MODDLL 0x08000L /* .DLL module */
1343 #define E32MODPROTDLL 0x18000L /* Protected memory library module */
1344 #define E32MODPDEV 0x20000L /* Physical device driver */
1345 #define E32MODVDEV 0x28000L /* Virtual device driver */
1346 #define E32MODMASK 0x38000L /* Module type mask */
1349 * RELOCATION DEFINITIONS - RUN-TIME FIXUPS
1352 typedef union _RELOC_OFS
1354 unsigned short offset16
;
1355 unsigned long offset32
;
1356 } RELOC_OFS
; /* 16-bit or 32-bit offset */
1359 /***ET+ r32_rlc - Relocation item */
1361 struct r32_rlc
/* Relocation item */
1363 unsigned char nr_stype
; /* Source type - field shared with new_rlc */
1364 unsigned char nr_flags
; /* Flag byte - field shared with new_rlc */
1365 short r32_soff
; /* Source offset */
1366 unsigned short r32_objmod
; /* Target object number or Module ordinal */
1370 RELOC_OFS intref
; /* Internal fixup */
1374 RELOC_OFS proc
; /* Procedure name offset */
1375 unsigned long ord
; /* Procedure odrinal */
1376 } extref
; /* External fixup */
1380 unsigned short entry
; /* Entry ordinal */
1381 RELOC_OFS addval
; /* Value added to the address */
1382 } addfix
; /* Additive fixup */
1384 r32_target
; /* Target data */
1385 unsigned short r32_srccount
; /* Number of chained fixup records */
1386 unsigned short r32_chain
; /* Chain head */
1390 * In 32-bit .EXE file run-time relocations are written as varying size
1391 * records, so we need many size definitions.
1394 #define RINTSIZE16 8
1395 #define RINTSIZE32 10
1397 #define RNAMSIZE16 8
1398 #define RNAMSIZE32 10
1399 #define RADDSIZE16 10
1400 #define RADDSIZE32 12
1404 * Access macros defined in NEWEXE.H !!!
1406 #define NR_STYPE(x) (x).nr_stype
1407 #define NR_FLAGS(x) (x).nr_flags
1410 #define R32_SOFF(x) (x).r32_soff
1411 #define R32_OBJNO(x) (x).r32_objmod
1412 #define R32_MODORD(x) (x).r32_objmod
1413 #define R32_OFFSET16(x) (x).r32_target.intref.offset16
1414 #define R32_OFFSET32(x) (x).r32_target.intref.offset32
1415 #define R32_PROCOFF16(x) (x).r32_target.extref.proc.offset16
1416 #define R32_PROCOFF32(x) (x).r32_target.extref.proc.offset32
1417 #define R32_PROCORD(x) (x).r32_target.extref.ord
1418 #define R32_ENTRY(x) (x).r32_target.addfix.entry
1419 #define R32_ADDVAL16(x) (x).r32_target.addfix.addval.offset16
1420 #define R32_ADDVAL32(x) (x).r32_target.addfix.addval.offset32
1421 #define R32_SRCCNT(x) (x).r32_srccount
1422 #define R32_CHAIN(x) (x).r32_chain
1427 * Format of NR_STYPE(x)
1429 * 7 6 5 4 3 2 1 0 - bit no
1431 * | | +-+-+-+--- Source type
1432 * | +----------- Fixup to 16:16 alias
1433 * +------------- List of source offset follows fixup record
1438 /* DEFINED in newexe.h !!! */
1440 #define NRSTYP 0x0f /* Source type mask */
1441 #define NRSBYT 0x00 /* lo byte (8-bits)*/
1442 #define NRSSEG 0x02 /* 16-bit segment (16-bits) */
1443 #define NRSPTR 0x03 /* 16:16 pointer (32-bits) */
1444 #define NRSOFF 0x05 /* 16-bit offset (16-bits) */
1445 #define NRPTR48 0x06 /* 16:32 pointer (48-bits) */
1446 #define NROFF32 0x07 /* 32-bit offset (32-bits) */
1447 #define NRSOFF32 0x08 /* 32-bit self-relative offset (32-bits) */
1451 #define NRSRCMASK 0x0f /* Source type mask */
1452 #define NRALIAS 0x10 /* Fixup to alias */
1453 #define NRCHAIN 0x20 /* List of source offset follows */
1454 /* fixup record, source offset field */
1455 /* in fixup record contains number */
1456 /* of elements in list */
1459 * Format of NR_FLAGS(x) and R32_FLAGS(x):
1461 * 7 6 5 4 3 2 1 0 - bit no
1463 * | | | | | +-+--- Reference type
1464 * | | | | +------- Additive fixup
1465 * | | | +----------- 32-bit Target Offset Flag (1 - 32-bit; 0 - 16-bit)
1466 * | | +------------- 32-bit Additive Flag (1 - 32-bit; 0 - 16-bit)
1467 * | +--------------- 16-bit Object/Module ordinal (1 - 16-bit; 0 - 8-bit)
1468 * +----------------- 8-bit import ordinal (1 - 8-bit;
1469 * 0 - NR32BITOFF toggles
1470 * between 16 and 32 bit
1474 #ifdef NEVER_INCLUDE_THE_FOLLWING
1475 /* DEFINED in newexe.h !!! */
1476 #define NRRTYP 0x03 /* Reference type mask */
1477 #define NRRINT 0x00 /* Internal reference */
1478 #define NRRORD 0x01 /* Import by ordinal */
1479 #define NRRNAM 0x02 /* Import by name */
1480 #define NRADD 0x04 /* Additive fixup */
1483 #define NRRENT 0x03 /* Internal entry table fixup */
1485 #define NR32BITOFF 0x10 /* 32-bit Target Offset */
1486 #define NR32BITADD 0x20 /* 32-bit Additive fixup */
1487 #define NR16OBJMOD 0x40 /* 16-bit Object/Module ordinal */
1488 #define NR8BITORD 0x80 /* 8-bit import ordinal */
1492 * Data structures for storing run-time fixups in linker virtual memory.
1494 * Each object has a list of Object Page Directories which specify
1495 * fixups for given page. Each page has its own hash table which is
1496 * used to detect fixups to the same target.
1499 #define PAGEPERDIR 62
1503 typedef struct _OBJPAGEDIR
1505 DWORD next
; /* Virtual pointer to next dir on list */
1506 WORD ht
[PAGEPERDIR
]; /* Pointers to individual hash tables */
1514 /***ET+ o32_obj Object Table Entry */
1516 struct o32_obj
/* Flat .EXE object table entry */
1518 unsigned long o32_size
; /* Object virtual size */
1519 unsigned long o32_base
; /* Object base virtual address */
1520 unsigned long o32_flags
; /* Attribute flags */
1521 unsigned long o32_pagemap
; /* Object page map index */
1522 unsigned long o32_mapsize
; /* Number of entries in object page map */
1523 unsigned long o32_reserved
; /* Reserved */
1527 #define O32_SIZE(x) (x).o32_size
1528 #define O32_BASE(x) (x).o32_base
1529 #define O32_FLAGS(x) (x).o32_flags
1530 #define O32_PAGEMAP(x) (x).o32_pagemap
1531 #define O32_MAPSIZE(x) (x).o32_mapsize
1532 #define O32_RESERVED(x) (x).o32_reserved
1535 * Format of O32_FLAGS(x)
1537 * High word of dword flag field is not used for now.
1538 * Low word has the following format:
1540 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - bit no
1541 * | | | | | | | | | | | | | | |
1542 * | | | | | | | | | | | | | | +--- Readable Object
1543 * | | | | | | | | | | | | | +----- Writeable Object
1544 * | | | | | | | | | | | | +------- Executable Object
1545 * | | | | | | | | | | | +--------- Resource Object
1546 * | | | | | | | | | | +----------- Object is Discardable
1547 * | | | | | | | | | +------------- Object is Shared
1548 * | | | | | | | | +--------------- Object has preload pages
1549 * | | | | | | | +----------------- Object has invalid pages
1550 * | | | | | | +------------------- Object is permanent and swappable
1551 * | | | | | +--------------------- Object is permanent and resident
1552 * | | | | +----------------------- Object is permanent and long lockable
1553 * | | | +----------------------------- 16:16 alias required (80x86 specific)
1554 * | | +-------------------------------- Big/Default bit setting (80x86 specific)
1555 * | +----------------------------------- Object is conforming for code (80x86 specific)
1556 * +-------------------------------------- Object I/O privilege level (80x86 specific)
1560 #define OBJREAD 0x0001L /* Readable Object */
1561 #define OBJWRITE 0x0002L /* Writeable Object */
1562 #define OBJRSRC 0x0008L /* Resource Object */
1563 #define OBJINVALID 0x0080L /* Object has invalid pages */
1564 #define LNKNONPERM 0x0600L /* Object is nonpermanent - should be */
1565 #define OBJNONPERM 0x0000L /* zero in the .EXE but LINK386 uses 6 */
1566 #define OBJPERM 0x0100L /* Object is permanent and swappable */
1567 #define OBJRESIDENT 0x0200L /* Object is permanent and resident */
1568 #define OBJCONTIG 0x0300L /* Object is resident and contiguous */
1569 #define OBJDYNAMIC 0x0400L /* Object is permanent and long locable */
1570 #define OBJTYPEMASK 0x0700L /* Object type mask */
1571 #define OBJALIAS16 0x1000L /* 16:16 alias required (80x86 specific) */
1572 #define OBJBIGDEF 0x2000L /* Big/Default bit setting (80x86 specific) */
1573 #define OBJIOPL 0x8000L /* Object I/O privilege level (80x86 specific) */
1576 * Name these flags differently for EXEHDR.EXE - avoid conflicts with 286 version
1578 #define OBJDISCARD 0x0010L /* Object is Discardable */
1579 #define OBJSHARED 0x0020L /* Object is Shared */
1580 #define OBJPRELOAD 0x0040L /* Object has preload pages */
1581 #define OBJEXEC 0x0004L /* Executable Object */
1582 #define OBJCONFORM 0x4000L /* Object is conforming for code (80x86 specific) */
1585 * Life will be easier, if we keep the same names for the following flags:
1588 #define NSDISCARD 0x0010L /* Object is Discardable */
1591 #define NSMOVE NSDISCARD /* Moveable object is for sure Discardable */
1594 #define NSSHARED 0x0020L /* Object is Shared */
1597 #define NSPRELOAD 0x0040L /* Object has preload pages */
1600 #define NSEXRD 0x0004L /* Executable Object */
1603 #define NSCONFORM 0x4000L /* Object is conforming for code (80x86 specific) */
1608 /***ET+ o32_map - Object Page Map entry */
1610 struct o32_map
/* Object Page Table entry */
1612 unsigned long o32_pagedataoffset
; /* file offset of page */
1613 unsigned short o32_pagesize
; /* # bytes of page data */
1614 unsigned short o32_pageflags
; /* Per-Page attributes */
1618 #define GETPAGEIDX(x) ((x).o32_pagedataoffset)
1620 #define PUTPAGEIDX(x,i) ((x).o32_pagedataoffset = ((unsigned long)(i)))
1622 #define PUTPAGESIZ(x,i) ((x).o32_pagesize = ((unsigned int)(i)))
1624 #define GETPAGESIZ(x) ((x).o32_pagesize)
1626 #define PAGEFLAGS(x) (x).o32_pageflags
1629 #define VALID 0x0000 /* Valid Physical Page in .EXE */
1630 #define ITERDATA 0x0001 /* Iterated Data Page */
1631 #define INVALID 0x0002 /* Invalid Page */
1632 #define ZEROED 0x0003 /* Zero Filled Page */
1633 #define RANGE 0x0004 /* Range of pages */
1634 #define ITERDATA2 0x0005 /* Iterated Data Page Type II */
1641 /***ET+ rsrc32 - Resource Table Entry */
1643 struct rsrc32
/* Resource Table Entry */
1645 unsigned short type
; /* Resource type */
1646 unsigned short name
; /* Resource name */
1647 unsigned long cb
; /* Resource size */
1648 unsigned short obj
; /* Object number */
1649 unsigned long offset
; /* Offset within object */
1655 * Iteration Record format for 'EXEPACK'ed pages.
1659 unsigned short LX_nIter
; /* number of iterations */
1660 unsigned short LX_nBytes
; /* number of bytes */
1661 unsigned char LX_Iterdata
; /* iterated data byte(s) */
1666 * ENTRY TABLE DEFINITIONS
1669 /***ET+ b32_bundle - Entry Table */
1673 unsigned char b32_cnt
; /* Number of entries in this bundle */
1674 unsigned char b32_type
; /* Bundle type */
1675 unsigned short b32_obj
; /* Object number */
1676 }; /* Follows entry types */
1680 unsigned char e32_flags
; /* Entry point flags */
1683 RELOC_OFS e32_offset
; /* 16-bit/32-bit offset entry */
1686 unsigned short offset
; /* Offset in segment */
1687 unsigned short callgate
; /* Callgate selector */
1689 e32_callgate
; /* 286 (16-bit) call gate */
1692 unsigned short modord
; /* Module ordinal number */
1693 unsigned long value
; /* Proc name offset or ordinal */
1695 e32_fwd
; /* Forwarder */
1697 e32_variant
; /* Entry variant */
1702 #define B32_CNT(x) (x).b32_cnt
1703 #define B32_TYPE(x) (x).b32_type
1704 #define B32_OBJ(x) (x).b32_obj
1706 #define E32_EFLAGS(x) (x).e32_flags
1707 #define E32_OFFSET16(x) (x).e32_variant.e32_offset.offset16
1708 #define E32_OFFSET32(x) (x).e32_variant.e32_offset.offset32
1709 #define E32_GATEOFF(x) (x).e32_variant.e32_callgate.offset
1710 #define E32_GATE(x) (x).e32_variant.e32_callgate.callgate
1711 #define E32_MODORD(x) (x).e32_variant.e32_fwd.modord
1712 #define E32_VALUE(x) (x).e32_variant.e32_fwd.value
1723 #define EMPTY 0x00 /* Empty bundle */
1724 #define ENTRY16 0x01 /* 16-bit offset entry point */
1725 #define GATE16 0x02 /* 286 call gate (16-bit IOPL) */
1726 #define ENTRY32 0x03 /* 32-bit offset entry point */
1727 #define ENTRYFWD 0x04 /* Forwarder entry point */
1728 #define TYPEINFO 0x80 /* Typing information present flag */
1732 * Format for E32_EFLAGS(x)
1734 * 7 6 5 4 3 2 1 0 - bit no
1736 * | | | | | | | +--- exported entry
1737 * | | | | | | +----- uses shared data
1738 * +-+-+-+-+-+------- parameter word count
1741 #define E32EXPORT 0x01 /* Exported entry */
1742 #define E32SHARED 0x02 /* Uses shared data */
1743 #define E32PARAMS 0xf8 /* Parameter word count mask */
1746 * Flags for forwarders only:
1749 #define FWD_ORDINAL 0x01 /* Imported by ordinal */
1752 #pragma pack() /* Restore default alignment */
1756 #endif /* __EXE386__ */