source: trunk/kLdr/kLdrModLX.h@ 2828

Last change on this file since 2828 was 2828, checked in by bird, 19 years ago

Lx header. renaming some helpers.

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