source: trunk/include/k/kLdrFmts/lx.h@ 2

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

Imported http://svn.netlabs.org/repos/libc/trunk/kStuff, revision 3612.

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