]> git.saurik.com Git - apple/bootx.git/blob - bootx.tproj/sl.subproj/GetSymbolFromPEF.h
78dcf24568dd032e1dd1c2b57fb41178a4d16e8b
[apple/bootx.git] / bootx.tproj / sl.subproj / GetSymbolFromPEF.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 File: GetSymbolFromPEF.h
24
25 Contains: xxx put contents here xxx
26
27 Written by: Jeffrey Robbin
28
29 Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
30
31 Change History (most recent first):
32
33 <2> 9/20/94 TS Dump the globals!
34 <1> 9/6/94 TS first checked in
35
36 */
37
38 #ifndef __GETSYMBOLFROMPEF__
39 #define __GETSYMBOLFROMPEF__
40
41 //#include <Types.h>
42
43 #pragma options align=mac68k
44
45 #include <libclite.h>
46
47 #define NewPtrSys(a) malloc(a)
48 #define DisposePtr(a) free(a)
49
50 /*
51 Container information
52 */
53
54 struct ContainerHeader { /* File/container header layout: */
55 unsigned long magicCookie; /* PEF container magic cookie */
56 unsigned long containerID; /* 'peff' */
57 unsigned long architectureID; /* 'pwpc' | 'm68k' */
58 unsigned long versionNumber; /* format version number */
59 unsigned long dateTimeStamp; /* date/time stamp (Mac format) */
60 unsigned long oldDefVersion; /* old definition version number */
61 unsigned long oldImpVersion; /* old implementation version number */
62 unsigned long currentVersion; /* current version number */
63 short nbrOfSections; /* nbr of sections (rel. 1) */
64 short loadableSections; /* nbr of loadable sectionsfor execution */
65 /* (= nbr of 1st non-loadable section) */
66 LogicalAddress memoryAddress; /* location this container was last loaded */
67 };
68 typedef struct ContainerHeader ContainerHeader, *ContainerHeaderPtr;
69
70 #define kMagic1 'joy!'
71 #define kMagic2 'peff'
72
73
74 /*
75 Section information
76 */
77
78 struct SectionHeader { /* Section header layout: */
79 long sectionName; /* section name (str tbl container offset) */
80 unsigned long sectionAddress; /* preferred base address for the section */
81 long execSize; /* execution (byte) size including 0 init) */
82 long initSize; /* init (byte) size before 0 init */
83 long rawSize; /* raw data size (bytes) */
84 long containerOffset; /* container offest to section's raw data */
85 unsigned char regionKind; /* section/region classification */
86 unsigned char shareKind; /* sharing classification */
87 unsigned char alignment; /* log 2 alignment */
88 unsigned char reserved; /* <reserved> */
89 };
90 typedef struct SectionHeader SectionHeader, *SectionHeaderPtr;
91
92 /* regionKind section classification: */
93 /* loadable sections */
94 #define kCodeSection 0U /* code section */
95 #define kDataSection 1U /* data section */
96 #define kPIDataSection 2U /* "pattern" initialized data */
97 #define kConstantSection 3U /* read-only data */
98 #define kExecDataSection 6U /* "self modifying" code (!?) */
99 /* non-loadable sections */
100 #define kLoaderSection 4U /* loader */
101 #define kDebugSection 5U /* debugging info */
102 #define kExceptionSection 7U /* exception data */
103 #define kTracebackSection 8U /* traceback data */
104
105
106 /*
107 Loader Information
108 */
109
110 struct LoaderHeader { /* Loader raw data section header layout: */
111 long entrySection; /* entry point section number */
112 long entryOffset; /* entry point descr. ldr section offset */
113 long initSection; /* init routine section number */
114 long initOffset; /* init routine descr. ldr section offset */
115 long termSection; /* term routine section number */
116 long termOffset; /* term routine descr. ldr section offset */
117 long nbrImportIDs; /* nbr of import container id entries */
118 long nbrImportSyms; /* nbr of import symbol table entries */
119 long nbrRelocSects; /* nbr of relocation sections (headers) */
120 long relocsOffset; /* reloc. instructions ldr section offset */
121 long strTblOffset; /* string table ldr section offset */
122 long slotTblOffset; /* hash slot table ldr section offset */
123 long hashSlotTblSz; /* log 2 of nbr of hash slot entries */
124 long nbrExportSyms; /* nbr of export symbol table entries */
125 };
126 typedef struct LoaderHeader LoaderHeader, *LoaderHeaderPtr;
127
128 struct LoaderHashSlotEntry { /* Loader export hash slot table entry layout: */
129 unsigned long slotEntry; /* chain count (0:13), chain index (14:31) */
130 };
131 typedef struct LoaderHashSlotEntry LoaderHashSlotEntry, *LoaderHashSlotEntryPtr;
132
133 struct LoaderExportChainEntry { /* Loader export hash chain tbl entry layout: */
134 union {
135 unsigned long _hashWord; /* name length and hash value */
136 struct {
137 unsigned short _nameLength; /* name length is top half of hash word */
138 unsigned short doNotUseThis; /* this field should never be accessed! */
139 } _h_h;
140 } _h;
141 };
142 typedef struct LoaderExportChainEntry LoaderExportChainEntry, *LoaderExportChainEntryPtr;
143
144 struct ExportSymbolEntry { /* Loader export symbol table entry layout: */
145 unsigned long class_and_name; /* symClass (0:7), nameOffset (8:31) */
146 long address; /* ldr section offset to exported symbol */
147 short sectionNumber; /* section nbr that this export belongs to */
148 };
149 typedef struct ExportSymbolEntry ExportSymbolEntry, *ExportSymbolEntryPtr;
150
151
152
153 /*
154 Unpacking Information
155 */
156
157 /* "pattern" initialized data opcodes: */
158 #define kZero 0U /* zero (clear) bytes */
159 #define kBlock 1U /* block transfer bytes */
160 #define kRepeat 2U /* repeat block xfer bytes */
161 #define kRepeatBlock 3U /* repeat block xfer with contant prefix */
162 #define kRepeatZero 4U /* repeat block xfer with contant prefix 0 */
163
164 #define kOpcodeShift 0x05U /* shift to access opcode */
165 #define kFirstOperandMask 0x1FU /* mask to access 1st operand (count) */
166
167 #define PIOP(x) (unsigned char)((x) >> kOpcodeShift) /* extract opcode */
168 #define PICNT(x) (long)((x) & kFirstOperandMask) /* extract 1st operand (count) */
169
170 /* The following macros are used for extracting count value operands from pidata... */
171
172 #define kCountShift 0x07UL /* value shift to concat count bytes */
173 #define kCountMask 0x7FUL /* mask to extract count bits from a byte */
174
175 #define IS_LAST_PICNT_BYTE(x) (((x) & 0x80U) == 0) /* true if last count byte */
176
177 #define CONCAT_PICNT(value, x) (((value)<<kCountShift) | ((x) & kCountMask))
178
179
180
181 /*
182 Function Prototypes
183 */
184
185 OSStatus GetSymbolFromPEF ( StringPtr theSymbolName,
186 LogicalAddress thePEFPtr,
187 LogicalAddress theSymbolPtr,
188 ByteCount theSymbolSize);
189
190 Boolean SymbolCompare ( StringPtr theLookedForSymbol,
191 StringPtr theExportSymbol,
192 unsigned long theExportSymbolLength);
193
194 OSErr UnpackPiData (LogicalAddress thePEFPtr,
195 SectionHeaderPtr sectionHeaderPtr,
196 LogicalAddress * theData);
197
198 unsigned char PEFGetNextByte (unsigned char** rawBuffer, long* rawBufferRemaining);
199
200 unsigned long PEFGetCount(unsigned char** rawBuffer, long* rawBufferRemaining);
201
202 void MemSet (unsigned char* theBuffer, long theValue, long theCount);
203
204
205 enum {
206 paramErr = -10000,
207 memFullErr = -10001,
208 cfragNoSectionErr = -10002,
209 cfragNoSymbolErr = -10003,
210 cfragFragmentFormatErr = -10004,
211 cfragFragmentCorruptErr = -10005
212 };
213
214 #pragma options align=reset
215
216 #endif