source: trunk/kLdr/kLdrModLX.h@ 3525

Last change on this file since 3525 was 3525, checked in by bird, 18 years ago

made the format headers usable externally.

  • Property svn:keywords set to Id
File size: 14.4 KB
Line 
1/* $Id $ */
2
3#ifndef __kLdrModLX_h__
4#define __kLdrModLX_h__
5
6#include "kLdrBase.h"
7
8
9#ifndef IMAGE_OS2_SIGNATURE_LX
10/** LX signature ("LX") */
11# define IMAGE_LX_SIGNATURE KLDR_LE2H_U16('L' | ('X' << 8))
12#endif
13
14#pragma pack(1)
15
16/**
17 * Linear eXecutable header.
18 * This structure is exactly 196 bytes long.
19 */
20struct e32_exe
21{
22 uint8_t e32_magic[2];
23 uint8_t e32_border;
24 uint8_t e32_worder;
25 uint32_t e32_level;
26 uint16_t e32_cpu;
27 uint16_t e32_os;
28 uint32_t e32_ver;
29 uint32_t e32_mflags;
30 uint32_t e32_mpages;
31 uint32_t e32_startobj;
32 uint32_t e32_eip;
33 uint32_t e32_stackobj;
34 uint32_t e32_esp;
35 uint32_t e32_pagesize;
36 uint32_t e32_pageshift;
37 /** The size of the fixup section.
38 * The fixup section consists of the fixup page table, the fixup record table,
39 * the import module table, and the import procedure name table.
40 */
41 uint32_t e32_fixupsize;
42 uint32_t e32_fixupsum;
43 /** The size of the resident loader section.
44 * This includes the object table, the object page map table, the resource table, the resident name table,
45 * the entry table, the module format directives table, and the page checksum table (?). */
46 uint32_t e32_ldrsize;
47 /** The checksum of the loader section. 0 if not calculated. */
48 uint32_t e32_ldrsum;
49 /** The offset of the object table relative to this structure. */
50 uint32_t e32_objtab;
51 /** Count of objects. */
52 uint32_t e32_objcnt;
53 /** The offset of the object page map table relative to this structure. */
54 uint32_t e32_objmap;
55 /** The offset of the object iterated pages (whatever this is used for) relative to the start of the file. */
56 uint32_t e32_itermap;
57 /** The offset of the resource table relative to this structure. */
58 uint32_t e32_rsrctab;
59 /** The number of entries in the resource table. */
60 uint32_t e32_rsrccnt;
61 /** The offset of the resident name table relative to this structure. */
62 uint32_t e32_restab;
63 /** The offset of the entry (export) table relative to this structure. */
64 uint32_t e32_enttab;
65 /** The offset of the module format directives table relative to this structure. */
66 uint32_t e32_dirtab;
67 /** The number of entries in the module format directives table. */
68 uint32_t e32_dircnt;
69 /** The offset of the fixup page table relative to this structure. */
70 uint32_t e32_fpagetab;
71 /** The offset of the fixup record table relative to this structure. */
72 uint32_t e32_frectab;
73 /** The offset of the import module name table relative to this structure. */
74 uint32_t e32_impmod;
75 /** The number of entries in the import module name table. */
76 uint32_t e32_impmodcnt;
77 /** The offset of the import procedure name table relative to this structure. */
78 uint32_t e32_impproc;
79 /** The offset of the page checksum table relative to this structure. */
80 uint32_t e32_pagesum;
81 /** The offset of the data pages relative to the start of the file. */
82 uint32_t e32_datapage;
83 /** The number of preload pages (ignored). */
84 uint32_t e32_preload;
85 /** The offset of the non-resident name table relative to the start of the file. */
86 uint32_t e32_nrestab;
87 /** The size of the non-resident name table. */
88 uint32_t e32_cbnrestab;
89 uint32_t e32_nressum;
90 uint32_t e32_autodata;
91 uint32_t e32_debuginfo;
92 uint32_t e32_debuglen;
93 uint32_t e32_instpreload;
94 uint32_t e32_instdemand;
95 uint32_t e32_heapsize;
96 uint32_t e32_stacksize;
97 uint8_t e32_res3[20];
98};
99
100/** e32_magic[0] */
101#define E32MAGIC1 'L'
102/** e32_magic[1] */
103#define E32MAGIC2 'X'
104/** MAKEWORD(e32_magic[0], e32_magic[1]) */
105#define E32MAGIC 0x584c
106/** e32_border - little endian */
107#define E32LEBO 0
108/** e32_border - big endian */
109#define E32BEBO 1
110/** e32_worder - little endian */
111#define E32LEWO 0
112/** e32_worder - big endian */
113#define E32BEWO 1
114/** e32_level */
115#define E32LEVEL UINT32_C(0)
116/** e32_cpu - 80286 */
117#define E32CPU286 1
118/** e32_cpu - 80386 */
119#define E32CPU386 2
120/** e32_cpu - 80486 */
121#define E32CPU486 3
122/** e32_pagesize */
123#define OBJPAGELEN UINT32_C(0x1000)
124
125
126/** @name e32_mflags
127 * @{ */
128/** App Type: Fullscreen only. */
129#define E32NOPMW UINT32_C(0x00000100)
130/** App Type: PM API. */
131#define E32PMAPI UINT32_C(0x00000300)
132/** App Type: PM VIO compatible. */
133#define E32PMW UINT32_C(0x00000200)
134/** Application type mask. */
135#define E32APPMASK UINT32_C(0x00000300)
136/** Executable module. */
137#define E32MODEXE UINT32_C(0x00000000)
138/** Dynamic link library (DLL / library) module. */
139#define E32MODDLL UINT32_C(0x00008000)
140/** Protected memory DLL. */
141#define E32PROTDLL UINT32_C(0x00010000)
142/** Physical Device Driver. */
143#define E32MODPDEV UINT32_C(0x00020000)
144/** Virtual Device Driver. */
145#define E32MODVDEV UINT32_C(0x00028000)
146/** Device driver */
147#define E32DEVICE E32MODPDEV
148/** Dynamic link library (DLL / library) module. */
149#define E32NOTP E32MODDLL
150/** Protected memory DLL. */
151#define E32MODPROTDLL (E32MODDLL | E32PROTDLL)
152/** Module Type mask. */
153#define E32MODMASK UINT32_C(0x00038000)
154/** Not loadable (linker error). */
155#define E32NOLOAD UINT32_C(0x00002000)
156/** No internal fixups. */
157#define E32NOINTFIX UINT32_C(0x00000010)
158/** No external fixups (i.e. imports). */
159#define E32NOEXTFIX UINT32_C(0x00000020)
160/** System DLL, no internal fixups. */
161#define E32SYSDLL UINT32_C(0x00000008)
162/** Global (set) or per instance (cleared) library initialization. */
163#define E32LIBINIT UINT32_C(0x00000004)
164/** Global (set) or per instance (cleared) library termination. */
165#define E32LIBTERM UINT32_C(0x40000000)
166/** Indicates when set in an executable that the process isn't SMP safe. */
167#define E32NOTMPSAFE UINT32_C(0x00080000)
168/** @} */
169
170/** @name Relocations (aka Fixups).
171 * @{ */
172typedef union _offset
173{
174 uint16_t offset16;
175 uint32_t offset32;
176} offset;
177
178/** A relocation.
179 * @remark this structure isn't very usable since LX relocations comes in too many size variations.
180 */
181struct r32_rlc
182{
183 uint8_t nr_stype;
184 uint8_t nr_flags;
185 int16_t r32_soff;
186 uint16_t r32_objmod;
187
188 union targetid
189 {
190 offset intref;
191 union extfixup
192 {
193 offset proc;
194 uint32_t ord;
195 } extref;
196 struct addfixup
197 {
198 uint16_t entry;
199 offset addval;
200 } addfix;
201 } r32_target;
202 uint16_t r32_srccount;
203 uint16_t r32_chain;
204};
205
206/** @name Some attempt at size constanstants.
207 * @{
208 */
209#define RINTSIZE16 8
210#define RINTSIZE32 10
211#define RORDSIZE 8
212#define RNAMSIZE16 8
213#define RNAMSIZE32 10
214#define RADDSIZE16 10
215#define RADDSIZE32 12
216/** @} */
217
218/** @name nr_stype (source flags)
219 * @{ */
220#define NRSBYT 0x00
221#define NRSSEG 0x02
222#define NRSPTR 0x03
223#define NRSOFF 0x05
224#define NRPTR48 0x06
225#define NROFF32 0x07
226#define NRSOFF32 0x08
227#define NRSTYP 0x0f
228#define NRSRCMASK 0x0f
229#define NRALIAS 0x10
230#define NRCHAIN 0x20
231/** @} */
232
233/** @name nr_flags (target flags)
234 * @{ */
235#define NRRINT 0x00
236#define NRRORD 0x01
237#define NRRNAM 0x02
238#define NRRENT 0x03
239#define NRRTYP 0x03
240#define NRADD 0x04
241#define NRICHAIN 0x08
242#define NR32BITOFF 0x10
243#define NR32BITADD 0x20
244#define NR16OBJMOD 0x40
245#define NR8BITORD 0x80
246/** @} */
247
248/** @} */
249
250
251/** @name The Object Table (aka segment table)
252 * @{ */
253
254/** The Object Table Entry. */
255struct o32_obj
256{
257 /** The size of the object. */
258 uint32_t o32_size;
259 /** The base address of the object. */
260 uint32_t o32_base;
261 /** Object flags. */
262 uint32_t o32_flags;
263 /** Page map index. */
264 uint32_t o32_pagemap;
265 /** Page map size. (doesn't need to be o32_size >> page shift). */
266 uint32_t o32_mapsize;
267 /** Reserved */
268 uint32_t o32_reserved;
269};
270
271/** @name o32_flags
272 * @{ */
273/** Read access. */
274#define OBJREAD UINT32_C(0x00000001)
275/** Write access. */
276#define OBJWRITE UINT32_C(0x00000002)
277/** Execute access. */
278#define OBJEXEC UINT32_C(0x00000004)
279/** Resource object. */
280#define OBJRSRC UINT32_C(0x00000008)
281/** The object is discarable (i.e. don't swap, just load in pages from the executable).
282 * This overlaps a bit with object type. */
283#define OBJDISCARD UINT32_C(0x00000010)
284/** The object is shared. */
285#define OBJSHARED UINT32_C(0x00000020)
286/** The object has preload pages. */
287#define OBJPRELOAD UINT32_C(0x00000040)
288/** The object has invalid pages. */
289#define OBJINVALID UINT32_C(0x00000080)
290/** Non-permanent, link386 bug. */
291#define LNKNONPERM UINT32_C(0x00000600)
292/** Non-permanent, correct 'value'. */
293#define OBJNONPERM UINT32_C(0x00000000)
294/** Obj Type: The object is permanent and swappable. */
295#define OBJPERM UINT32_C(0x00000100)
296/** Obj Type: The object is permanent and resident (i.e. not swappable). */
297#define OBJRESIDENT UINT32_C(0x00000200)
298/** Obj Type: The object is resident and contigious. */
299#define OBJCONTIG UINT32_C(0x00000300)
300/** Obj Type: The object is permanent and long locable. */
301#define OBJDYNAMIC UINT32_C(0x00000400)
302/** Object type mask. */
303#define OBJTYPEMASK UINT32_C(0x00000700)
304/** x86: The object require an 16:16 alias. */
305#define OBJALIAS16 UINT32_C(0x00001000)
306/** x86: Big/Default selector setting, i.e. toggle 32-bit or 16-bit. */
307#define OBJBIGDEF UINT32_C(0x00002000)
308/** x86: conforming selector setting (weird stuff). */
309#define OBJCONFORM UINT32_C(0x00004000)
310/** x86: IOPL. */
311#define OBJIOPL UINT32_C(0x00008000)
312/** @} */
313
314/** A Object Page Map Entry. */
315struct o32_map
316{
317 /** The file offset of the page. */
318 uint32_t o32_pagedataoffset;
319 /** The number of bytes of raw page data. */
320 uint16_t o32_pagesize;
321 /** Per page flags describing how the page is encoded in the file. */
322 uint16_t o32_pageflags;
323};
324
325/** @name o32 o32_pageflags
326 * @{
327 */
328/** Raw page (uncompressed) in the file. */
329#define VALID UINT16_C(0x0000)
330/** RLE encoded page in file. */
331#define ITERDATA UINT16_C(0x0001)
332/** Invalid page, nothing in the file. */
333#define INVALID UINT16_C(0x0002)
334/** Zero page, nothing in file. */
335#define ZEROED UINT16_C(0x0003)
336/** range of pages (what is this?) */
337#define RANGE UINT16_C(0x0004)
338/** Compressed page in file. */
339#define ITERDATA2 UINT16_C(0x0005)
340/** @} */
341
342
343/** Iteration Record format (RLE compressed page). */
344struct LX_Iter
345{
346 /** Number of iterations. */
347 uint16_t LX_nIter;
348 /** The number of bytes that's being iterated. */
349 uint16_t LX_nBytes;
350 /** The bytes. */
351 uint8_t LX_Iterdata;
352};
353
354/** @} */
355
356
357/** A Resource Table Entry */
358struct rsrc32
359{
360 /** Resource Type. */
361 uint16_t type;
362 /** Resource ID. */
363 uint16_t name;
364 /** Resource size in bytes. */
365 uint32_t cb;
366 /** The index of the object containing the resource. */
367 uint16_t obj;
368 /** Offset of the resource that within the object. */
369 uint32_t offset;
370};
371
372
373/** @name The Entry Table (aka Export Table)
374 * @{ */
375
376/** Entry bundle.
377 * Header descripting up to 255 entries that follows immediatly after this structure. */
378struct b32_bundle
379{
380 /** The number of entries. */
381 uint8_t b32_cnt;
382 /** The type of bundle. */
383 uint8_t b32_type;
384 /** The index of the object containing these entry points. */
385 uint16_t b32_obj;
386};
387
388/** @name b32_type
389 * @{ */
390/** Empty bundle, filling up unused ranges of ordinals. */
391#define EMPTY 0x00
392/** 16-bit offset entry point. */
393#define ENTRY16 0x01
394/** 16-bit callgate entry point. */
395#define GATE16 0x02
396/** 32-bit offset entry point. */
397#define ENTRY32 0x03
398/** Forwarder entry point. */
399#define ENTRYFWD 0x04
400/** Typing information present indicator. */
401#define TYPEINFO 0x80
402/** @} */
403
404
405/** Entry point. */
406struct e32_entry
407{
408 /** Entry point flags */
409 uint8_t e32_flags; /* Entry point flags */
410 union entrykind
411 {
412 /** ENTRY16 or ENTRY32. */
413 offset e32_offset;
414 /** GATE16 */
415 struct callgate
416 {
417 /** Offset into segment. */
418 uint16_t offset;
419 /** The callgate selector */
420 uint16_t callgate;
421 } e32_callgate;
422 /** ENTRYFWD */
423 struct fwd
424 {
425 /** Module ordinal number (i.e. into the import module table). */
426 uint16_t modord;
427 /** Procedure name or ordinal number. */
428 uint32_t value;
429 } e32_fwd;
430 } e32_variant;
431};
432
433/** @name e32_flags
434 * @{ */
435/** Exported entry (set) or private entry (clear). */
436#define E32EXPORT 0x01
437/** Uses shared data. */
438#define E32SHARED 0x02
439/** Parameter word count mask. */
440#define E32PARAMS 0xf8
441/** ENTRYFWD: Imported by ordinal (set) or by name (clear). */
442#define FWD_ORDINAL 0x01
443/** @} */
444
445/** @name dunno
446 * @{ */
447#define FIXENT16 3
448#define FIXENT32 5
449#define GATEENT16 5
450#define FWDENT 7
451/** @} */
452
453#pragma pack()
454
455#endif
456
Note: See TracBrowser for help on using the repository browser.